// ==============================================
// Inter Supply (1992) - Mock data
// 30 Tools & Hardware products + users + sample quotations
// ==============================================

const I18N = {
  th: {
    home: "หน้าแรก",
    catalog: "สินค้า",
    deals: "ราคาพิเศษ",
    contact: "ติดต่อเรา",
    quotation: "ใบเสนอราคา",
    login: "เข้าสู่ระบบ",
    logout: "ออกจากระบบ",
    register: "สมัครสมาชิก",
    dealerPortal: "Dealer Portal",
    adminPanel: "Admin Panel",
    search: "ค้นหาสินค้า / SKU / รหัส...",
    addToQuote: "เพิ่มในใบเสนอราคา",
    addToQuoteShort: "ขอใบเสนอราคา",
    inQuote: "อยู่ในใบเสนอราคา",
    viewDetails: "ดูรายละเอียด",
    instock: "พร้อมส่ง",
    lowStock: "เหลือน้อย",
    outOfStock: "หมดชั่วคราว",
    each: "/ชิ้น",
    box: "/กล่อง",
    set: "/ชุด",
    pcs: "ชิ้น",
    categoryAll: "ทั้งหมด",
    sortBy: "เรียงโดย",
    relevance: "ความเกี่ยวข้อง",
    priceLow: "ราคาต่ำ → สูง",
    priceHigh: "ราคาสูง → ต่ำ",
    newest: "ใหม่ล่าสุด",
    popular: "ขายดี",
    quantity: "จำนวน",
    note: "หมายเหตุ / Spec เพิ่มเติม",
    delete: "ลบ",
    cart: "ตะกร้าใบเสนอราคา",
    emptyCart: "ยังไม่มีสินค้าในใบเสนอราคา",
    browseProducts: "เลือกสินค้า",
    subtotal: "ยอดรวม",
    discount: "ส่วนลด",
    dealerDiscount: "ส่วนลด Dealer",
    vat: "ภาษีมูลค่าเพิ่ม 7%",
    total: "รวมทั้งสิ้น",
    requestQuote: "สร้างใบเสนอราคา",
    customerInfo: "ข้อมูลลูกค้า",
    name: "ชื่อ-นามสกุล",
    company: "บริษัท / หน่วยงาน",
    phone: "เบอร์โทรศัพท์",
    email: "อีเมล",
    address: "ที่อยู่จัดส่ง",
    taxId: "เลขประจำตัวผู้เสียภาษี",
    generateQuote: "สร้างใบเสนอราคา PDF",
    download: "ดาวน์โหลด PDF",
    print: "พิมพ์",
    sendEmail: "ส่งอีเมล",
    quotationNumber: "เลขที่ใบเสนอราคา",
    date: "วันที่",
    validUntil: "ยืนยันราคาภายใน",
    customer: "Customer",
    dealer: "Dealer",
    admin: "Admin",
  },
};

// Simple translator - falls back to key
function t(key, en) {
  return I18N.th[key] || en || key;
}
const tt = (th, en) => ({ th, en });

const CATEGORIES = [
  { id: "power", th: "เครื่องมือไฟฟ้า", en: "Power Tools", count: 8 },
  { id: "hand", th: "เครื่องมือช่าง", en: "Hand Tools", count: 6 },
  { id: "measure", th: "เครื่องมือวัด", en: "Measuring", count: 4 },
  { id: "fasten", th: "อุปกรณ์ยึดติด", en: "Fasteners", count: 4 },
  { id: "safety", th: "อุปกรณ์เซฟตี้", en: "Safety", count: 4 },
  { id: "storage", th: "กล่องเก็บเครื่องมือ", en: "Storage", count: 4 },
];

const BRANDS = ["Makita", "Bosch", "DeWalt", "Stanley", "Milwaukee", "TOTAL", "INGCO"];

// 30 products. Realistic Thai tools & hardware.
const PRODUCTS = [
  { id: 1, sku: "ISP-PWR-1001", th: "สว่านไร้สาย 18V 2 แบตเตอรี่", en: "Cordless Drill 18V 2 Batt", desc: "แรงบิด 60 N·m, รวมแบต 2 ก้อน + ที่ชาร์จ", category: "power", brand: "Makita", price: 4290, dealerPrice: 3590, oldPrice: 4990, stock: 24, tag: "hot", rating: 4.8, reviews: 142 },
  { id: 2, sku: "ISP-PWR-1002", th: "เครื่องเจียร 4 นิ้ว 720W", en: "Angle Grinder 4\" 720W", desc: "ตัด-เจียรเหล็ก ครอบกันสะเก็ดมาตรฐาน", category: "power", brand: "Bosch", price: 1890, dealerPrice: 1590, stock: 18, rating: 4.6, reviews: 88 },
  { id: 3, sku: "ISP-PWR-1003", th: "เครื่องเจียรไฟฟ้า 7 นิ้ว 2000W", en: "Angle Grinder 7\" 2000W", desc: "งานหนัก เหมาะกับงานก่อสร้าง / โรงงาน", category: "power", brand: "Makita", price: 4150, dealerPrice: 3520, stock: 9, tag: "new", rating: 4.7, reviews: 41 },
  { id: 4, sku: "ISP-PWR-1004", th: "เลื่อยวงเดือน 7 นิ้ว 1400W", en: "Circular Saw 7\" 1400W", desc: "ตัดไม้/อลูมิเนียม ปรับเอียงได้ 0-45°", category: "power", brand: "DeWalt", price: 5290, dealerPrice: 4490, stock: 12, rating: 4.7, reviews: 64 },
  { id: 5, sku: "ISP-PWR-1005", th: "ค้อนปอนด์ไฟฟ้า (Demolition Hammer) 1500W", en: "Demolition Hammer 1500W", desc: "สำหรับงานทุบ-สกัดคอนกรีต พร้อมดอกสกัด 2 ชิ้น", category: "power", brand: "Milwaukee", price: 7990, dealerPrice: 6890, stock: 6, tag: "sale", oldPrice: 9500, rating: 4.9, reviews: 27 },
  { id: 6, sku: "ISP-PWR-1006", th: "เครื่องเป่าลม 2.5 HP 50 ลิตร", en: "Air Compressor 2.5HP 50L", desc: "ปั๊มลม 50L แรงดันสูง สำหรับช่างยนต์/ช่างเฟอร์ฯ", category: "power", brand: "TOTAL", price: 8990, dealerPrice: 7790, stock: 4, rating: 4.5, reviews: 33 },
  { id: 7, sku: "ISP-PWR-1007", th: "ไขควงไฟฟ้าไร้สาย 12V", en: "Cordless Screwdriver 12V", desc: "น้ำหนักเบา 0.9 kg พร้อมหัวขัน 6 ขนาด", category: "power", brand: "Bosch", price: 1490, dealerPrice: 1190, stock: 32, rating: 4.4, reviews: 56 },
  { id: 8, sku: "ISP-PWR-1008", th: "เครื่องตัดเหล็กไฟเบอร์ 14 นิ้ว", en: "Cut-Off Saw 14\" Fiber", desc: "ใบตัดไฟเบอร์ 355mm สำหรับงานเหล็กหนา", category: "power", brand: "Makita", price: 5490, dealerPrice: 4690, stock: 7, rating: 4.6, reviews: 19 },

  { id: 9, sku: "ISP-HND-2001", th: "ชุดประแจแหวน-ปากตาย 8 ตัว/ชุด", en: "Combination Wrench Set 8pcs", desc: "ขนาด 8-19 mm เหล็กโครเมียมวาเนเดียม", category: "hand", brand: "Stanley", price: 890, dealerPrice: 720, stock: 45, rating: 4.7, reviews: 110 },
  { id: 10, sku: "ISP-HND-2002", th: "ค้อนหงอนหุ้มยาง 16 oz", en: "Claw Hammer 16oz", desc: "ด้ามจับยางลดแรงสะท้อน หัวค้อนเหล็กชุบ", category: "hand", brand: "Stanley", price: 290, dealerPrice: 220, stock: 80, rating: 4.5, reviews: 220 },
  { id: 11, sku: "ISP-HND-2003", th: "ชุดไขควงปากแฉก-แบน 6 ตัว", en: "Screwdriver Set 6pcs", desc: "ปลายแม่เหล็ก ด้ามจับยางกันลื่น", category: "hand", brand: "INGCO", price: 320, dealerPrice: 260, stock: 64, rating: 4.4, reviews: 88 },
  { id: 12, sku: "ISP-HND-2004", th: "คีมล็อค 10 นิ้ว", en: "Locking Pliers 10\"", desc: "ปรับล็อคได้ ฟันเหล็กชุบแข็งทนการกัดกร่อน", category: "hand", brand: "TOTAL", price: 280, dealerPrice: 210, stock: 38, rating: 4.5, reviews: 67 },
  { id: 13, sku: "ISP-HND-2005", th: "คัตเตอร์ใหญ่ 18mm พร้อมใบมีด 10 ชิ้น", en: "Utility Knife 18mm + 10 blades", desc: "ใบมีดสำรอง 10 ใบ กล่องเก็บใบมีดในตัว", category: "hand", brand: "INGCO", price: 145, dealerPrice: 110, stock: 120, rating: 4.6, reviews: 95 },
  { id: 14, sku: "ISP-HND-2006", th: "ประแจปอนด์ 1/2\" 28-210 N·m", en: "Torque Wrench 1/2\" 28-210Nm", desc: "เสียงดังคลิ๊กเมื่อถึงค่าที่ตั้ง พร้อมกล่อง", category: "hand", brand: "TOTAL", price: 1690, dealerPrice: 1390, stock: 14, tag: "new", rating: 4.8, reviews: 28 },

  { id: 15, sku: "ISP-MSR-3001", th: "ตลับเมตร 5 เมตร x 19mm", en: "Tape Measure 5m x 19mm", desc: "เคลือบไนลอน กันน้ำ-กันรอย คลิปยึดเข็มขัด", category: "measure", brand: "Stanley", price: 220, dealerPrice: 170, stock: 95, rating: 4.7, reviews: 180 },
  { id: 16, sku: "ISP-MSR-3002", th: "เลเซอร์วัดระดับ 2 เส้น Self-Leveling", en: "Cross Line Laser Level", desc: "ระดับน้ำเลเซอร์ตั้ง-นอน คลาด ±0.3mm/m", category: "measure", brand: "Bosch", price: 2890, dealerPrice: 2390, stock: 11, tag: "hot", rating: 4.8, reviews: 47 },
  { id: 17, sku: "ISP-MSR-3003", th: "เลเซอร์วัดระยะดิจิตอล 40m", en: "Laser Distance Meter 40m", desc: "ความแม่นยำ ±2mm แบตชาร์จในตัว USB", category: "measure", brand: "Bosch", price: 1690, dealerPrice: 1390, stock: 22, rating: 4.7, reviews: 73 },
  { id: 18, sku: "ISP-MSR-3004", th: "ไมโครมิเตอร์ดิจิตอล 0-25mm", en: "Digital Micrometer 0-25mm", desc: "ค่าละเอียด 0.001mm จอ LCD พร้อมกล่อง", category: "measure", brand: "Mitutoyo", price: 3290, dealerPrice: 2790, stock: 8, rating: 4.9, reviews: 22 },

  { id: 19, sku: "ISP-FST-4001", th: "สกรูเกลียวปล่อย กล่อง 500 ตัว", en: "Self-Tapping Screws 500pcs", desc: "หัวกลม ขนาด 6x40mm ชุบสังกะสีกันสนิม", category: "fasten", brand: "Generic", price: 180, dealerPrice: 130, stock: 200, rating: 4.4, reviews: 60 },
  { id: 20, sku: "ISP-FST-4002", th: "พุกพลาสติก สีเหลือง #8 (1000 ตัว)", en: "Plastic Anchors #8 1000pcs", desc: "พุกพลาสติกคุณภาพ กล่อง 1000 ตัว", category: "fasten", brand: "Generic", price: 240, dealerPrice: 180, stock: 150, rating: 4.5, reviews: 42 },
  { id: 21, sku: "ISP-FST-4003", th: "ตะปูตอกคอนกรีต กล่อง 1 kg", en: "Concrete Nails 1kg", desc: "เหล็กแข็งพิเศษ ขนาด 2.5\" สำหรับงานคอนกรีต", category: "fasten", brand: "Generic", price: 160, dealerPrice: 120, stock: 90, rating: 4.3, reviews: 28 },
  { id: 22, sku: "ISP-FST-4004", th: "เทปพันเกลียว PTFE 12mm 10 ม้วน", en: "PTFE Thread Tape 12mm x10", desc: "เทปพันเกลียวสีขาว ใช้กับท่อน้ำ-ลม", category: "fasten", brand: "Generic", price: 85, dealerPrice: 60, stock: 240, rating: 4.6, reviews: 73 },

  { id: 23, sku: "ISP-SFY-5001", th: "หมวกเซฟตี้ ABS ตามมาตรฐาน มอก.", en: "Safety Helmet TIS Std.", desc: "วัสดุ ABS รองในปรับขนาดได้ ผ่าน มอก.", category: "safety", brand: "TOTAL", price: 290, dealerPrice: 230, stock: 75, rating: 4.5, reviews: 51 },
  { id: 24, sku: "ISP-SFY-5002", th: "ถุงมือยางไนไตร์ 100 ชิ้น/กล่อง", en: "Nitrile Gloves 100pcs/box", desc: "เกรดอุตสาหกรรม ป้องกันน้ำมัน-สารเคมีอ่อน", category: "safety", brand: "Generic", price: 195, dealerPrice: 145, stock: 130, rating: 4.4, reviews: 89 },
  { id: 25, sku: "ISP-SFY-5003", th: "แว่นตาเซฟตี้ใส กันสะเก็ด", en: "Safety Glasses Clear", desc: "เลนส์ PC ป้องกันแสง UV กรอบโพลีคาร์บอเนต", category: "safety", brand: "TOTAL", price: 110, dealerPrice: 80, stock: 180, rating: 4.5, reviews: 64 },
  { id: 26, sku: "ISP-SFY-5004", th: "รองเท้าเซฟตี้หัวเหล็ก รุ่น Pro", en: "Safety Shoes Steel Toe Pro", desc: "หัวเหล็ก พื้นกันลื่น/กันน้ำมัน Size 39-46", category: "safety", brand: "King's", price: 1290, dealerPrice: 1050, stock: 24, tag: "hot", rating: 4.7, reviews: 102 },

  { id: 27, sku: "ISP-STO-6001", th: "กล่องเครื่องมือ 19 นิ้ว 2 ชั้น", en: "Tool Box 19\" Cantilever", desc: "ถาดยกได้ ล็อคเหล็ก ทนทาน รับน้ำหนัก 15 kg", category: "storage", brand: "Stanley", price: 590, dealerPrice: 470, stock: 28, rating: 4.6, reviews: 75 },
  { id: 28, sku: "ISP-STO-6002", th: "ตู้เครื่องมือ 5 ลิ้นชัก ล้อเลื่อน", en: "Rolling Tool Cabinet 5 Drawer", desc: "เหล็กหนา ล้อล็อค 4 ล้อ ลิ้นชักรางลูกปืน", category: "storage", brand: "Stanley", price: 8490, dealerPrice: 7290, stock: 5, tag: "new", rating: 4.8, reviews: 19 },
  { id: 29, sku: "ISP-STO-6003", th: "เป้สะพายเครื่องมือ Heavy Duty", en: "Heavy Duty Tool Backpack", desc: "ช่องเก็บ 28 ช่อง พื้นล่างทนทาน ใส่ปุ่ม", category: "storage", brand: "DeWalt", price: 2190, dealerPrice: 1790, stock: 16, rating: 4.7, reviews: 38 },
  { id: 30, sku: "ISP-STO-6004", th: "ชั้นวางเหล็ก 5 ชั้น 90x40x180cm", en: "Steel Shelving 5-Tier", desc: "รับน้ำหนัก 175 kg/ชั้น โครงเหล็กพ่นสี", category: "storage", brand: "Generic", price: 1490, dealerPrice: 1190, stock: 12, rating: 4.5, reviews: 54 },
];

// stable color seeds for product placeholders
const HUE = [212, 200, 220, 195, 230, 205, 215, 198];
function productImg(p, size = "lg") {
  // returns descriptor for placeholder. real images would be /img/...
  return null;
}

// users (Dealer pricing applies only when role=dealer)
const USERS = [
  { id: "u1", role: "customer", email: "customer@demo.com", password: "demo", name: "คุณสมชาย ใจดี", company: "ห้างหุ้นส่วนจำกัด สมชายการช่าง" },
  { id: "u2", role: "dealer", email: "dealer@demo.com", password: "demo", name: "บริษัท ช่างไทยซัพพลาย จำกัด", company: "ช่างไทยซัพพลาย จก.", tier: "Gold", discount: 15 },
  { id: "u3", role: "admin", email: "admin@intersupply.co.th", password: "admin", name: "ผู้ดูแลระบบ Inter Supply", company: "Inter Supply (1992) Co., Ltd." },
];

// sample dealer quotation history
const SAMPLE_QUOTATIONS = [
  { no: "QT-2026-0517", date: "14 พ.ค. 2026", customer: "บริษัท ABC Construction", items: 8, total: 48700, status: "approved" },
  { no: "QT-2026-0512", date: "10 พ.ค. 2026", customer: "โรงงานอุตสาหกรรม XYZ", items: 14, total: 124380, status: "approved" },
  { no: "QT-2026-0508", date: "06 พ.ค. 2026", customer: "ร้าน วัสดุก่อสร้าง บ้านสวน", items: 6, total: 22150, status: "pending" },
  { no: "QT-2026-0501", date: "30 เม.ย. 2026", customer: "บริษัท สหวิศวกรรม", items: 22, total: 198900, status: "expired" },
  { no: "QT-2026-0496", date: "27 เม.ย. 2026", customer: "หจก. อ.การช่าง", items: 4, total: 9450, status: "approved" },
  { no: "QT-2026-0489", date: "20 เม.ย. 2026", customer: "บริษัท ลายวิศวกรรม", items: 11, total: 67320, status: "approved" },
];

// admin: incoming customer quotes
const INCOMING_QUOTES = [
  { no: "QT-2026-0521", date: "15 พ.ค. 2026 14:32", customer: "บมจ. ไทยพาราวู้ด", contact: "คุณวีระ 081-234-5678", items: 12, total: 89400, status: "new" },
  { no: "QT-2026-0520", date: "15 พ.ค. 2026 11:08", customer: "หจก. ช่างพรชัย", contact: "คุณพรชัย 089-789-1122", items: 5, total: 14290, status: "new" },
  { no: "QT-2026-0519", date: "15 พ.ค. 2026 09:14", customer: "บริษัท ก่อสร้างไทยรุ่งเรือง", contact: "ฝ่ายจัดซื้อ 02-555-1234", items: 18, total: 152000, status: "reviewed" },
  { no: "QT-2026-0518", date: "14 พ.ค. 2026 16:48", customer: "ร้าน วัสดุก่อสร้างนานา", contact: "คุณสมศักดิ์ 086-444-7890", items: 7, total: 31840, status: "contacted" },
  { no: "QT-2026-0517", date: "14 พ.ค. 2026 14:22", customer: "บริษัท ABC Construction", contact: "คุณแอน 081-999-1234", items: 8, total: 48700, status: "won" },
];

// admin: monthly revenue series (chart)
const REVENUE_SERIES = [
  { month: "ธ.ค.", value: 1240 },
  { month: "ม.ค.", value: 1380 },
  { month: "ก.พ.", value: 1320 },
  { month: "มี.ค.", value: 1560 },
  { month: "เม.ย.", value: 1820 },
  { month: "พ.ค.", value: 2140 },
];

const CATEGORY_REVENUE = [
  { cat: "Power Tools", value: 38, color: "#0a6e3d" },
  { cat: "Hand Tools", value: 22, color: "#16a34a" },
  { cat: "Measuring", value: 14, color: "#4ade80" },
  { cat: "Safety", value: 12, color: "#86efac" },
  { cat: "Fasteners", value: 8, color: "#bbf7d0" },
  { cat: "Storage", value: 6, color: "#dcfce7" },
];

const TOP_PRODUCTS = [
  { sku: "ISP-PWR-1001", name: "สว่านไร้สาย 18V Makita", sold: 142, revenue: 609180 },
  { sku: "ISP-PWR-1005", name: "ค้อนปอนด์ไฟฟ้า Milwaukee", sold: 89, revenue: 711110 },
  { sku: "ISP-MSR-3002", name: "เลเซอร์วัดระดับ Bosch", sold: 76, revenue: 219640 },
  { sku: "ISP-PWR-1004", name: "เลื่อยวงเดือน 7\" DeWalt", sold: 68, revenue: 359720 },
  { sku: "ISP-STO-6001", name: "กล่องเครื่องมือ 19\" Stanley", sold: 64, revenue: 37760 },
];

function fmtMoney(n) {
  return n.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
}
function fmtInt(n) {
  return n.toLocaleString("en-US");
}
function todayStr() {
  // 15 พ.ค. 2026
  return "15 พฤษภาคม 2026";
}
function todayEn() {
  return "15 May 2026";
}
function newQuoteNo() {
  const n = 522 + Math.floor(Math.random() * 8);
  return `QT-2026-0${n}`;
}

Object.assign(window, {
  I18N, t, tt,
  CATEGORIES, BRANDS, PRODUCTS, USERS,
  SAMPLE_QUOTATIONS, INCOMING_QUOTES, REVENUE_SERIES, CATEGORY_REVENUE, TOP_PRODUCTS,
  fmtMoney, fmtInt, todayStr, todayEn, newQuoteNo, productImg, HUE,
});
