// Mock data + bilingual labels for SYK Document System
// Exported via window for cross-script access.

const COMPANY = {
  nameTH: "บริษัท เอสวายเค คอนสตรัคชั่น จำกัด",
  nameEN: "SYK Construction Co., Ltd.",
  shortName: "SYK",
  addressTH: "999/855 ซอย หมู่บ้านเศรษฐกิจ 31 แขวงบางแคเหนือ เขตบางแค กรุงเทพฯ 10160",
  phone: "0-2496-7190",
  mobile: "08-1312-8566",
  taxId: "0105544078733",
  vat: 0.07,
  wht: 0.03,
  retention: 0.05,
};

// Bilingual nav labels
const NAV = [
  { id: "architecture", th: "ภาพรวมระบบ",          en: "System Architecture", icon: "blueprint" },
  { id: "dashboard",    th: "แดชบอร์ด",             en: "Dashboard",           icon: "grid"      },
  { id: "boq",          th: "BOQ & ใบเสนอราคา",     en: "BOQ & Quotation",     icon: "doc"       },
  { id: "contracts",    th: "สัญญา",                en: "Contracts",           icon: "shield"    },
  { id: "procurement",  th: "จัดซื้อ (PR/PO)",      en: "Procurement",         icon: "cart"      },
  { id: "billing",      th: "วางบิล & ภาษี",         en: "Billing & Tax",       icon: "receipt"   },
  { id: "progress",     th: "งวดงาน & เงินประกัน",  en: "Progress & Retention", icon: "milestone"},
  { id: "inventory",    th: "คลังหน้างาน",          en: "Site Inventory",      icon: "box"       },
  { id: "subcontractor",th: "ผู้รับเหมาช่วง",        en: "Subcontractors",      icon: "people"    },
  { id: "drawings",     th: "แบบก่อสร้าง",          en: "Drawings",            icon: "blueprint2"},
];

// Sample drawings (PDFs uploaded by user appear here as object URLs)
const DRAWINGS = [
  { id: "DWG-014-A01", project: "PJ-2025-014", name: "แปลนสถาปัตยกรรม ชั้น 1-2",       discipline: "Architecture", scale: "1:100", revision: "B", date: "2025-08-10", size: "4.2 MB", pages: 8 },
  { id: "DWG-014-S01", project: "PJ-2025-014", name: "ฐานราก & เสาเข็ม",               discipline: "Structure",    scale: "1:75",  revision: "A", date: "2025-08-12", size: "2.8 MB", pages: 5 },
  { id: "DWG-014-S02", project: "PJ-2025-014", name: "โครงสร้าง ค.ส.ล. ชั้น 1-2",       discipline: "Structure",    scale: "1:75",  revision: "B", date: "2025-08-14", size: "3.4 MB", pages: 6 },
  { id: "DWG-014-E01", project: "PJ-2025-014", name: "ผังไฟฟ้า & ปลั๊ก",                discipline: "Electrical",   scale: "1:100", revision: "A", date: "2025-08-18", size: "1.6 MB", pages: 4 },
  { id: "DWG-014-P01", project: "PJ-2025-014", name: "ผังประปา-สุขาภิบาล",              discipline: "Plumbing",     scale: "1:100", revision: "A", date: "2025-08-18", size: "1.4 MB", pages: 3 },
  { id: "DWG-013-A01", project: "PJ-2025-013", name: "ผังโรงงาน + ส่วนต่อเติม",         discipline: "Architecture", scale: "1:200", revision: "C", date: "2025-09-02", size: "5.8 MB", pages: 12 },
  { id: "DWG-013-S01", project: "PJ-2025-013", name: "โครงเหล็กหลังคา",                  discipline: "Structure",    scale: "1:50",  revision: "B", date: "2025-09-05", size: "3.2 MB", pages: 6 },
  { id: "DWG-012-A01", project: "PJ-2025-012", name: "บ้าน 3 ชั้น – แปลน & รูปด้าน",      discipline: "Architecture", scale: "1:100", revision: "D", date: "2025-04-22", size: "6.4 MB", pages: 14 },
];

const DISCIPLINE_META = {
  "Architecture": { color: "#6f86ff", icon: "🏛️" },
  "Structure":    { color: "#ffb84d", icon: "🏗️" },
  "Electrical":   { color: "#f6c97c", icon: "⚡" },
  "Plumbing":     { color: "#4ade80", icon: "💧" },
};

// ── Master data ──────────────────────────────────────────────
const PROJECTS = [
  { code: "PJ-2025-014", name: "บ้านพักอาศัย 2 ชั้น คุณวิชัย", site: "ลาดพร้าว 71", value: 4_850_000, progress: 0.62, status: "active",   start: "2025-08-12", due: "2026-02-28" },
  { code: "PJ-2025-013", name: "ต่อเติมโรงงาน บ.รุ่งเรืองพลาส", site: "บางบอน",     value: 8_200_000, progress: 0.38, status: "active",   start: "2025-09-04", due: "2026-04-15" },
  { code: "PJ-2025-012", name: "บ้าน 3 ชั้น คุณนงนุช",          site: "ราชพฤกษ์",   value: 6_400_000, progress: 0.94, status: "active",   start: "2025-04-20", due: "2025-12-30" },
  { code: "PJ-2025-011", name: "ต่อเติมห้องครัว+โรงรถ",          site: "บางแค",      value:   780_000, progress: 1.00, status: "done",     start: "2025-06-10", due: "2025-09-05" },
  { code: "PJ-2025-010", name: "ปรับปรุงสำนักงาน บ.พีทีพี",     site: "พระราม 2",   value: 2_150_000, progress: 0.18, status: "active",   start: "2025-10-22", due: "2026-03-30" },
];

const MATERIALS = [
  { code: "CM-001", name: "ปูนซีเมนต์ปอร์ตแลนด์ ตราช้าง", unit: "ถุง", price: 165, cat: "ปูน",     vendor: "SCG"      },
  { code: "CM-002", name: "ปูนซีเมนต์ผสมเสร็จ M250",     unit: "คิว", price: 2_180, cat: "ปูน",   vendor: "CPAC"     },
  { code: "ST-001", name: "เหล็กข้ออ้อย DB12 (SD40)",    unit: "เส้น", price: 285, cat: "เหล็ก",  vendor: "TSC"      },
  { code: "ST-002", name: "เหล็กข้ออ้อย DB16 (SD40)",    unit: "เส้น", price: 510, cat: "เหล็ก",  vendor: "TSC"      },
  { code: "ST-003", name: "เหล็กกล่อง 4×2 หนา 2.3mm",    unit: "เส้น", price: 685, cat: "เหล็ก",  vendor: "TATA"     },
  { code: "BR-001", name: "อิฐมอญ 3×6.5×14 ซม.",          unit: "ก้อน", price: 4.8, cat: "อิฐ",   vendor: "ทั่วไป"   },
  { code: "BR-002", name: "อิฐมวลเบา Q-Con 7.5cm",        unit: "ก้อน", price: 28,  cat: "อิฐ",   vendor: "Q-Con"    },
  { code: "TL-001", name: "กระเบื้องเซรามิค 60×60",       unit: "ตร.ม.", price: 320, cat: "กระเบื้อง", vendor: "Cotto"},
  { code: "RF-001", name: "กระเบื้องลอนคู่ 50×120",      unit: "แผ่น", price: 89,  cat: "หลังคา", vendor: "ตราเพชร"  },
  { code: "EL-001", name: "สายไฟ THW 2.5 sq.mm",          unit: "เมตร", price: 16,  cat: "ไฟฟ้า", vendor: "Bangkok"  },
  { code: "EL-002", name: "เบรกเกอร์ 32A",                unit: "ตัว",  price: 480, cat: "ไฟฟ้า", vendor: "Schneider"},
  { code: "PL-001", name: "ท่อ PVC 4 นิ้ว ชั้น 8.5",      unit: "เส้น", price: 235, cat: "ประปา", vendor: "ท่อน้ำไทย"},
  { code: "PT-001", name: "สีน้ำอะคริลิก TOA SuperShield", unit: "แกลลอน", price: 1_120, cat: "สี", vendor: "TOA"   },
];

const LABOR = [
  { code: "LB-FN", name: "ค่าแรงงานฐานราก",        unit: "ตร.ม.", price: 320 },
  { code: "LB-CL", name: "ค่าแรงงานเสา/คาน/พื้น",   unit: "ตร.ม.", price: 280 },
  { code: "LB-WL", name: "ค่าแรงก่ออิฐ-ฉาบ",         unit: "ตร.ม.", price: 240 },
  { code: "LB-TL", name: "ค่าแรงปูกระเบื้อง",       unit: "ตร.ม.", price: 220 },
  { code: "LB-PT", name: "ค่าแรงทาสี",              unit: "ตร.ม.", price:  85 },
  { code: "LB-EL", name: "ค่าแรงไฟฟ้า (เดินสาย)",   unit: "จุด",   price: 380 },
];

const BOQ_SAMPLE = {
  code: "QT-2025-038",
  project: "บ้านพักอาศัย 2 ชั้น คุณวิชัย",
  client: "คุณวิชัย ตั้งสกุล",
  date: "2025-11-18",
  validDays: 30,
  groups: [
    {
      name: "1. งานโครงสร้าง",
      items: [
        { no: "1.1", desc: "งานเสาเข็มเจาะ 0.35m",         qty: 24,  unit: "ต้น",   mat: 4_200, lab: 1_800 },
        { no: "1.2", desc: "งานฐานรากคอนกรีตเสริมเหล็ก",   qty: 24,  unit: "ฐาน",   mat: 5_800, lab: 2_400 },
        { no: "1.3", desc: "งานเสา ค.ส.ล. 0.25×0.25",       qty: 36,  unit: "ต้น",   mat: 3_400, lab: 1_900 },
        { no: "1.4", desc: "งานคาน-พื้น ค.ส.ล. ชั้น 1-2",   qty: 320, unit: "ตร.ม.", mat: 1_180, lab:   620 },
      ],
    },
    {
      name: "2. งานสถาปัตยกรรม",
      items: [
        { no: "2.1", desc: "ก่ออิฐมวลเบา ฉาบเรียบ 2 หน้า",   qty: 420, unit: "ตร.ม.", mat:   620, lab: 240 },
        { no: "2.2", desc: "ปูกระเบื้องเซรามิคพื้น",         qty: 220, unit: "ตร.ม.", mat:   420, lab: 220 },
        { no: "2.3", desc: "งานทาสีภายใน-ภายนอก",            qty: 680, unit: "ตร.ม.", mat:   115, lab:  85 },
        { no: "2.4", desc: "งานหลังคากระเบื้องลอนคู่",       qty: 180, unit: "ตร.ม.", mat:   420, lab: 280 },
      ],
    },
    {
      name: "3. งานระบบไฟฟ้า-ประปา",
      items: [
        { no: "3.1", desc: "เดินสายไฟ+ปลั๊ก-สวิตช์",         qty: 65, unit: "จุด", mat:  680, lab: 380 },
        { no: "3.2", desc: "ตู้เมน+เบรกเกอร์",                qty:  1, unit: "ชุด", mat: 22_000, lab: 8_500 },
        { no: "3.3", desc: "เดินท่อประปาน้ำดี-น้ำทิ้ง",       qty: 12, unit: "จุด", mat: 1_240, lab:  680 },
      ],
    },
  ],
};

const PR_PO = [
  { id: "PR-2025-082", type: "PR", project: "PJ-2025-014", date: "2025-11-15", requester: "ช.วินัย", total:  72_400, status: "approved", items: 5 },
  { id: "PR-2025-081", type: "PR", project: "PJ-2025-013", date: "2025-11-14", requester: "ช.วินัย", total: 186_500, status: "pending",  items: 12 },
  { id: "PR-2025-080", type: "PR", project: "PJ-2025-010", date: "2025-11-13", requester: "ช.สมชาย", total:  24_800, status: "approved", items: 3 },
  { id: "PO-2025-064", type: "PO", project: "PJ-2025-014", date: "2025-11-16", requester: "คุณนภา",  total:  72_400, status: "received", items: 5, vendor: "SCG" },
  { id: "PO-2025-063", type: "PO", project: "PJ-2025-013", date: "2025-11-12", requester: "คุณนภา",  total: 245_000, status: "sent",     items: 8, vendor: "TSC" },
  { id: "PO-2025-062", type: "PO", project: "PJ-2025-012", date: "2025-11-08", requester: "คุณนภา",  total:  38_200, status: "received", items: 4, vendor: "ตราเพชร" },
];

const INVOICES = [
  { id: "INV-2025-041", project: "PJ-2025-014", period: "งวดที่ 3",  date: "2025-11-10", subtotal:  920_000, vat: 64_400, wht: 27_600, retention: 46_000, net: 910_800, status: "paid" },
  { id: "INV-2025-042", project: "PJ-2025-013", period: "งวดที่ 2",  date: "2025-11-12", subtotal: 1_560_000, vat: 109_200, wht: 46_800, retention: 78_000, net: 1_544_400, status: "issued" },
  { id: "INV-2025-043", project: "PJ-2025-012", period: "งวดที่ 5",  date: "2025-11-14", subtotal:   640_000, vat: 44_800, wht: 19_200, retention: 32_000, net:   633_600, status: "issued" },
  { id: "INV-2025-044", project: "PJ-2025-010", period: "งวดที่ 1",  date: "2025-11-15", subtotal:   315_000, vat: 22_050, wht:  9_450, retention: 15_750, net:   311_850, status: "draft" },
];

const PROGRESS_PERIODS = [
  { no: 1, name: "ลงเสาเข็ม + ฐานราก",         pct: 0.15, status: "paid",      date: "2025-09-05", value:   727_500 },
  { no: 2, name: "โครงสร้าง ค.ส.ล. ชั้น 1",     pct: 0.20, status: "paid",      date: "2025-10-02", value:   970_000 },
  { no: 3, name: "โครงสร้าง ค.ส.ล. ชั้น 2 + หลังคา", pct: 0.20, status: "billed", date: "2025-11-10", value: 970_000 },
  { no: 4, name: "งานก่อ-ฉาบ + ผนัง",           pct: 0.15, status: "ongoing",   date: "—",          value:   727_500 },
  { no: 5, name: "ระบบไฟฟ้า-ประปา + ฝ้าเพดาน",  pct: 0.15, status: "planned",   date: "—",          value:   727_500 },
  { no: 6, name: "ตกแต่ง + ส่งมอบ",             pct: 0.15, status: "planned",   date: "—",          value:   727_500 },
];

const INVENTORY = [
  { code: "CM-001", name: "ปูนซีเมนต์ตราช้าง",    site: "PJ-2025-014", qty: 48, unit: "ถุง",  reorder: 30, value:  7_920 },
  { code: "ST-001", name: "เหล็ก DB12",            site: "PJ-2025-014", qty: 32, unit: "เส้น", reorder: 50, value:  9_120 },
  { code: "ST-002", name: "เหล็ก DB16",            site: "PJ-2025-013", qty: 18, unit: "เส้น", reorder: 40, value:  9_180 },
  { code: "BR-002", name: "อิฐมวลเบา Q-Con",       site: "PJ-2025-014", qty: 220, unit: "ก้อน",reorder: 100, value: 6_160 },
  { code: "TL-001", name: "กระเบื้อง 60×60",       site: "PJ-2025-012", qty: 84, unit: "ตร.ม.",reorder: 30, value: 26_880 },
  { code: "PT-001", name: "สี TOA SuperShield",    site: "PJ-2025-014", qty:  4, unit: "แกลลอน", reorder: 6, value:  4_480 },
];

const SUBCONTRACTORS = [
  { code: "SC-001", name: "ทีมช่างวินัย",            type: "โครงสร้าง",   rating: 4.7, projects: 8, open: 2, contract: 1_240_000, paid: 920_000 },
  { code: "SC-002", name: "หจก. ไฟฟ้าครบวงจร",        type: "ไฟฟ้า",       rating: 4.5, projects: 5, open: 1, contract:   480_000, paid: 320_000 },
  { code: "SC-003", name: "ช่างสมชาย ประปา",          type: "ประปา",       rating: 4.2, projects: 6, open: 1, contract:   220_000, paid:  88_000 },
  { code: "SC-004", name: "ทีมก่อ-ฉาบ คุณบุญมา",      type: "ก่ออิฐ-ฉาบ",   rating: 4.8, projects: 12, open: 3, contract:   680_000, paid: 410_000 },
  { code: "SC-005", name: "ปูกระเบื้อง คุณประยูร",    type: "กระเบื้อง",   rating: 4.3, projects: 4, open: 0, contract:   180_000, paid: 180_000 },
];

const CONTRACTS = [
  { id: "CT-2025-014", party: "คุณวิชัย ตั้งสกุล",         kind: "Owner-Contractor", value: 4_850_000, signed: "2025-08-05", end: "2026-02-28", retention: 0.05, status: "active" },
  { id: "CT-2025-013", party: "บ.รุ่งเรืองพลาส จำกัด",      kind: "Owner-Contractor", value: 8_200_000, signed: "2025-08-28", end: "2026-04-15", retention: 0.05, status: "active" },
  { id: "CT-2025-S04", party: "หจก. ไฟฟ้าครบวงจร",          kind: "Subcontract",      value:   480_000, signed: "2025-09-15", end: "2026-02-10", retention: 0.10, status: "active" },
  { id: "CT-2025-S03", party: "ทีมช่างวินัย",                kind: "Subcontract",      value: 1_240_000, signed: "2025-08-20", end: "2026-02-28", retention: 0.10, status: "active" },
  { id: "CT-2025-012", party: "คุณนงนุช อินทรกุล",          kind: "Owner-Contractor", value: 6_400_000, signed: "2025-04-12", end: "2025-12-30", retention: 0.05, status: "closing" },
];

// Recent BOQ history (from "Google Drive")
const DRIVE_BOQ = [
  { name: "QT-2024-022 บ้าน 2 ชั้น คุณสมศักดิ์.xlsx",    size: "184 KB",  modified: "2024-08-12", area: 220, value: 4_120_000, kind: "บ้าน 2 ชั้น" },
  { name: "QT-2024-031 ต่อเติมโรงงาน บ.ABC.xlsx",          size: "256 KB", modified: "2024-09-04", area: 480, value: 5_640_000, kind: "โรงงาน" },
  { name: "QT-2024-040 บ้าน 3 ชั้น คุณวรรณา.xlsx",         size: "302 KB", modified: "2024-10-18", area: 340, value: 7_800_000, kind: "บ้าน 3 ชั้น" },
  { name: "QT-2025-005 ต่อเติมห้องครัว+โรงรถ.xlsx",         size: "92 KB",  modified: "2025-01-22", area: 60,  value:   720_000, kind: "ต่อเติม" },
  { name: "QT-2025-018 ปรับปรุงสำนักงาน.xlsx",              size: "148 KB", modified: "2025-05-30", area: 120, value: 1_980_000, kind: "ปรับปรุง" },
];

// Helpers
const fmtTHB = (n) => "฿" + Number(n).toLocaleString("th-TH", { maximumFractionDigits: 0 });
const fmtTHBd = (n) => "฿" + Number(n).toLocaleString("th-TH", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
const fmtPct = (n) => (Number(n) * 100).toFixed(0) + "%";
const fmtDate = (s) => s;

Object.assign(window, {
  COMPANY, NAV, PROJECTS, MATERIALS, LABOR, BOQ_SAMPLE,
  PR_PO, INVOICES, PROGRESS_PERIODS, INVENTORY, SUBCONTRACTORS, CONTRACTS, DRIVE_BOQ,
  DRAWINGS, DISCIPLINE_META,
  fmtTHB, fmtTHBd, fmtPct, fmtDate,
});
