/* ===========================================
   Mock data for the CRM
   Thai accounting-firm context
   =========================================== */

const SOURCES = ["Facebook", "Website", "Referral", "Walk-in", "Line OA"];

const TAGS = [
  { id: "register", label: "จดบริษัท", color: "blue" },
  { id: "monthly", label: "ทำบัญชี", color: "green" },
  { id: "tax", label: "วางระบบภาษี", color: "purple" },
  { id: "audit", label: "ตรวจสอบบัญชี", color: "amber" },
  { id: "payroll", label: "เงินเดือน/HR", color: "rose" },
];

const STAGES = [
  { id: "new", label: "Lead ใหม่", desc: "ยังไม่เคยติดต่อ", color: "slate", phase: "marketing", role: "Marketing" },
  { id: "contacted", label: "ติดต่อแล้ว", desc: "Initial contact", color: "marketing", phase: "marketing", role: "Sales" },
  { id: "qualified", label: "Qualified", desc: "คัดกรองผ่าน", color: "marketing", phase: "marketing", role: "Sales" },
  { id: "followup", label: "Follow-up", desc: "ตามไม่เกิน 5 ครั้ง · ปิดดีลได้ทันทีที่ลูกค้าตกลง", color: "sales", phase: "marketing", role: "Sales" },
  { id: "won", label: "Won", desc: "ลูกค้าตกลงซื้อ → ส่งต่อ AE", color: "service", phase: "handover", role: "Handover" },
  { id: "ae_proposal", label: "AE Proposal", desc: "AE ทำใบเสนอราคา + เก็บข้อมูลบริษัท", color: "sales", phase: "ae", role: "AE" },
  { id: "ae_meeting", label: "1st Meeting", desc: "AE ประชุมเก็บข้อมูล", color: "sales", phase: "ae", role: "AE" },
  { id: "ae_deposit", label: "รอมัดจำ", desc: "ลูกค้าวางมัดจำ 50% หรือ ≥ ฿5,000", color: "sales", phase: "ae", role: "AE" },
  { id: "ae_followup", label: "สร้างสัญญาและเปิดเคส", desc: "เก็บข้อมูลการเงิน · ทำสัญญา · เปิดเคส", color: "sales", phase: "ae", role: "AE" },
  { id: "ae_onboard", label: "Onboarding", desc: "บันทึก Insight · เลือกผู้ดูแลบัญชี", color: "sales", phase: "ae", role: "AE" },
  { id: "closed", label: "Closed", desc: "ปิดดีล → Customer สร้าง", color: "service", phase: "ae", role: "AE" },
];

// Required fields per AE stage — system blocks advancing until all are filled
const AE_STAGE_REQUIREMENTS = {
  ae_proposal: {
    title: "ข้อมูลบริษัท (สำหรับใบเสนอราคา)",
    fields: [
      { id: "registeredCapital",  label: "ทุนจดทะเบียน",        type: "number", unit: "บาท" },
      { id: "directors",          label: "จำนวนกรรมการ",         type: "number", unit: "ท่าน" },
      { id: "shareholders",       label: "จำนวนผู้ถือหุ้น",       type: "number", unit: "ท่าน" },
      { id: "businessType",       label: "ประเภทธุรกิจ",          type: "text" },
      { id: "hasBranches",        label: "มีสาขาไหม",             type: "yesno" },
      { id: "branchCount",        label: "จำนวนสาขา",             type: "number", unit: "สาขา", dependsOn: "hasBranches" },
      { id: "hasStamp",           label: "มีตราประทับไหม",        type: "yesno" },
      { id: "registrationNo",     label: "เลขทะเบียน",            type: "text" },
      { id: "registrationDate",   label: "วันที่จดทะเบียน",        type: "date" },
      { id: "closingDate",        label: "กำหนดวันปิดบัญชี",      type: "text", placeholder: "เช่น 31 ธันวาคม" },
    ],
  },
  ae_followup: {
    title: "ข้อมูลการเงิน · เปิดเคส (สร้างสัญญาและเปิดเคส)",
    fields: [
      { id: "ssoRegistered",       label: "จดประกันสังคมหรือยัง",  type: "yesno" },
      { id: "vatRegistered",       label: "จด VAT หรือยัง",         type: "yesno" },
      { id: "bankAccounts",        label: "บัญชีธนาคารกี่เล่ม",    type: "number", unit: "เล่ม" },
      { id: "annualRevenue",       label: "จำนวนรายได้",           type: "number", unit: "บาท/ปี" },
      { id: "annualExpense",       label: "จำนวนค่าใช้จ่าย",        type: "number", unit: "บาท/ปี" },
      { id: "netProfit",           label: "กำไรสุทธิ",              type: "number", unit: "บาท/ปี" },
      { id: "revenueDocCount",     label: "จำนวนเอกสารรายได้",      type: "number", unit: "ใบ/ปี" },
      { id: "expenseDocCount",     label: "จำนวนเอกสารรายจ่าย",     type: "number", unit: "ใบ/ปี" },
      { id: "hqRent",              label: "ค่าเช่าสำนักงานใหญ่",     type: "number", unit: "บาท/เดือน" },
      { id: "directorSalary",      label: "เงินเดือนกรรมการ",       type: "number", unit: "บาท/เดือน" },
      { id: "assets",              label: "จำนวนสินทรัพย์",         type: "number", unit: "บาท" },
      { id: "liabilities",         label: "จำนวนหนี้สิน",           type: "number", unit: "บาท" },
      { id: "equity",              label: "ส่วนของเจ้าของ",         type: "number", unit: "บาท" },
      { id: "totalEmployees",      label: "มีพนักงานกี่คน",         type: "number", unit: "คน" },
      { id: "permanentEmployees",  label: "พนักงานประจำกี่คน",      type: "number", unit: "คน" },
      { id: "tempEmployees",       label: "พนักงานชั่วคราวกี่คน",   type: "number", unit: "คน" },
      { id: "serviceStartDate",    label: "วันที่เริ่มใช้บริการ",   type: "date" },
    ],
  },
  ae_onboard: {
    title: "Onboarding Insight · เลือกผู้ดูแล",
    fields: [
      { id: "insightBehavior",  label: "Insight พฤติกรรมลูกค้า",                   type: "textarea", placeholder: "เช่น ลูกค้าชอบงานเร็ว · ตอบไลน์ดี · ต้องการรายงานทุกสัปดาห์" },
      { id: "specialNeeds",     label: "ความต้องการพิเศษของลูกค้า",                 type: "textarea", placeholder: "เช่น ต้องการรายงานภาษาอังกฤษ · ต้องการ Management Report" },
      { id: "preferredChannel", label: "ช่องทางสื่อสารที่ลูกค้าชอบ",                 type: "choices", options: [
        { v: "line",  l: "LINE",  i: "MessageCircle" },
        { v: "email", l: "Email", i: "Mail" },
        { v: "phone", l: "โทร",   i: "Phone" },
      ] },
      { id: "accountantInCharge", label: "ผู้ดูแลบัญชี (Accountant in charge)",     type: "person", options: ["อ้อม", "นิ้ง", "ฟ้า", "บอย", "เจน"] },
    ],
  },
};
const AE_TEAM = ["ขวัญ", "พีท", "เจน"];
const MK_TEAM = ["นิ้ง", "อ้อม"];
const REQUIRED_CALLS = 5; // Sales must call at least 5 times in Follow-up before Won

const LEADS = [
  {
    id: "L-1024",
    company: "ครัวคุณยาย เซ็นทรัล ปิ่นเกล้า",
    contact: "คุณนิภา ทองดี",
    nickname: "พี่เล็ก",
    phone: "081-234-5678",
    line: "@khrua-yai",
    email: "nipa@khrua-yai.co.th",
    source: "Facebook",
    tags: ["register", "monthly"],
    stage: "new",
    callsCount: 0,
    value: 18000,
    owner: "อ้อม",
    mkOwner: "อ้อม",
    aeOwner: null,
    createdAt: "2026-05-10",
    lastTouch: "—",
    note: "เปิดร้านอาหารใหม่ 3 สาขา ต้องการจดบริษัทพร้อมทำบัญชี",
  },
  {
    id: "L-1025",
    company: "บ้านสวนสุขใจ Shopee Mall",
    contact: "คุณวรพล ศรีสุข",
    nickname: "วิน",
    phone: "089-111-2233",
    line: "@bansuan",
    email: "won@bansuan.com",
    source: "Website",
    tags: ["monthly", "tax"],
    stage: "contacted",
    callsCount: 1,
    value: 24000,
    owner: "นิ้ง",
    mkOwner: "นิ้ง",
    aeOwner: null,
    createdAt: "2026-05-08",
    lastTouch: "2026-05-15 14:32",
    note: "ขายของออนไลน์ Shopee/Lazada รายได้ ~1.2M/เดือน ต้องการที่ปรึกษาภาษี",
  },
  {
    id: "L-1026",
    company: "สหกรณ์ผ้าไทยล้านนา",
    contact: "อ.สมพร นวลจันทร์",
    nickname: "อ.สมพร",
    phone: "053-456-789",
    line: "—",
    email: "somporn@thaisilk.co.th",
    source: "Referral",
    tags: ["monthly", "audit"],
    stage: "qualified",
    callsCount: 1,
    value: 36000,
    owner: "อ้อม",
    mkOwner: "อ้อม",
    aeOwner: "ขวัญ",
    createdAt: "2026-05-05",
    lastTouch: "2026-05-15 10:20",
    note: "Referral จากลูกค้าเก่า สนใจ Outsource บัญชีเต็มรูปแบบ + audit",
  },
  {
    id: "L-1027",
    company: "Cloud Studio Bangkok",
    contact: "คุณภัทร นาคะ",
    nickname: "ตอง",
    phone: "092-555-7788",
    line: "@cloudstudio",
    email: "patr@cloudstudio.io",
    source: "Website",
    tags: ["register", "tax"],
    stage: "ae_followup",
    callsCount: 5,
    aeFollowupReason: "contract",
    aeFollowupAttempts: 1,
    value: 45000,
    owner: "นิ้ง",
    mkOwner: "นิ้ง",
    aeOwner: "ขวัญ",
    createdAt: "2026-05-02",
    lastTouch: "2026-05-16 09:14",
    note: "Tech studio 12 คน ต้องการจดบริษัท + วาง BOI ภาษี",
  },
  {
    id: "L-1028",
    company: "เสริมศรี ก่อสร้าง 1999",
    contact: "คุณเสริมศรี ก่อสร้าง",
    nickname: "เฮีย",
    phone: "081-999-1111",
    line: "—",
    email: "—",
    source: "Walk-in",
    tags: ["monthly", "payroll"],
    stage: "followup",
    callsCount: 4,
    value: 32000,
    owner: "นิ้ง",
    mkOwner: "นิ้ง",
    aeOwner: "พีท",
    createdAt: "2026-04-28",
    lastTouch: "2026-05-14 16:00",
    note: "บริษัทรับเหมา 35 คน ส่ง proposal แล้ว รอคำตอบ",
  },
  {
    id: "L-1029",
    company: "Tasty Box Catering",
    contact: "คุณมณีรัตน์ พัฒนกุล",
    nickname: "พี่มณี",
    phone: "086-444-3322",
    line: "@tastybox",
    email: "manee@tastybox.co.th",
    source: "Line OA",
    tags: ["monthly"],
    stage: "followup",
    callsCount: 4,
    value: 15000,
    owner: "อ้อม",
    mkOwner: "อ้อม",
    aeOwner: "ขวัญ",
    createdAt: "2026-04-22",
    lastTouch: "2026-05-15 11:00",
    note: "ลูกค้าเก่าของบริษัทอื่น อยากย้ายเพราะตอบช้า ตามครั้งที่ 3",
  },
  {
    id: "L-1030",
    company: "Bee Honey Organic Farm",
    contact: "คุณภาณุพงศ์ ทรัพย์มี",
    nickname: "บี",
    phone: "095-222-1188",
    line: "@beehoney",
    email: "bee@beehoney.farm",
    source: "Facebook",
    tags: ["register", "monthly", "tax"],
    stage: "ae_deposit",
    callsCount: 5,
    aeFollowupReason: "payment",
    aeFollowupAttempts: 2,
    value: 28000,
    owner: "นิ้ง",
    mkOwner: "นิ้ง",
    aeOwner: "พีท",
    createdAt: "2026-04-15",
    lastTouch: "2026-05-12 13:20",
    note: "ปิดดีลแล้ว — เริ่ม onboard เดือนนี้",
  },
  {
    id: "L-1031",
    company: "Charoen Pharma Trading",
    contact: "คุณเจริญ ตั้งใจ",
    nickname: "พี่เจริญ",
    phone: "081-777-6655",
    line: "—",
    email: "charoen@cpharma.co.th",
    source: "Referral",
    tags: ["monthly", "audit", "payroll"],
    stage: "closed",
    callsCount: 5,
    value: 48000,
    owner: "อ้อม",
    mkOwner: "อ้อม",
    aeOwner: "ขวัญ",
    createdAt: "2026-04-10",
    lastTouch: "2026-05-10 09:00",
    note: "ปิดดีล Tier-3 / audit รายปี",
  },
  {
    id: "L-1032",
    company: "Saiyok Resort Kanchanaburi",
    contact: "คุณวันใส แสงทอง",
    nickname: "พี่ใส",
    phone: "034-555-444",
    line: "—",
    email: "sai@saiyokresort.com",
    source: "Walk-in",
    tags: ["monthly"],
    stage: "contacted",
    callsCount: 1,
    value: 22000,
    owner: "อ้อม",
    mkOwner: "อ้อม",
    aeOwner: null,
    createdAt: "2026-05-12",
    lastTouch: "2026-05-15 15:00",
    note: "Resort 24 ห้อง รับเงินสด/โอน ตรวจรายได้ครั้งแรก",
  },
  {
    id: "L-1033",
    company: "GreenLeaf Botanicals Co.",
    contact: "คุณกานต์ สวนสมบูรณ์",
    nickname: "กานต์",
    phone: "088-321-1122",
    line: "@greenleaf",
    email: "kan@greenleaf.co.th",
    source: "Website",
    tags: ["monthly", "tax"],
    stage: "won",
    callsCount: 5,
    value: 30000,
    owner: "นิ้ง",
    mkOwner: "นิ้ง",
    aeOwner: "เจน",
    createdAt: "2026-05-07",
    lastTouch: "2026-05-16 11:15",
    note: "ส่งเอกสาร KYC ครบแล้ว นัดส่ง proposal สัปดาห์หน้า",
  },
];

const ACTIVITIES = [
  { id: "a1", leadId: "L-1027", type: "create", at: "2026-05-02 09:14", by: "นิ้ง", text: "สร้าง Lead จาก Website inquiry", icon: "Plus" },
  { id: "a2", leadId: "L-1027", type: "call", at: "2026-05-03 10:30", by: "นิ้ง", text: "โทรครั้งที่ 1 — คุยเรื่องโครงสร้างทีม 12 คน, รายได้ ~3M/ปี", duration: "12:34", icon: "Phone" },
  { id: "a3", leadId: "L-1027", type: "note", at: "2026-05-03 11:00", by: "นิ้ง", text: "Sales Note: ลูกค้าให้ความสำคัญกับ ความเร็ว + ความถูกต้องตามกฎหมาย BOI. กังวลเรื่องการประหยัดภาษี.", icon: "FileText" },
  { id: "a4", leadId: "L-1027", type: "stage", at: "2026-05-05 14:00", by: "นิ้ง", text: "ย้ายเข้าสถานะ Qualified", icon: "ArrowRight" },
  { id: "a5", leadId: "L-1027", type: "email", at: "2026-05-06 16:45", by: "นิ้ง", text: "ส่งอีเมล proposal draft v.1", icon: "Mail" },
  { id: "a6", leadId: "L-1027", type: "call", at: "2026-05-10 11:00", by: "นิ้ง", text: "โทรครั้งที่ 2 — รีวิว proposal, ลูกค้าขอปรับเงื่อนไขชำระ", duration: "08:12", icon: "Phone" },
  { id: "a7", leadId: "L-1027", type: "proposal", at: "2026-05-12 09:30", by: "นิ้ง", text: "ส่ง Proposal v.2 (PRP-0083) — 45,000 บาท/ปี", icon: "FileCheck2" },
  { id: "a8", leadId: "L-1027", type: "stage", at: "2026-05-12 09:31", by: "ระบบ", text: "ย้ายเข้าสถานะ ส่ง Proposal อัตโนมัติ", icon: "Sparkles" },
  { id: "a9", leadId: "L-1027", type: "followup", at: "2026-05-16 09:14", by: "นิ้ง", text: "Follow-up ครั้งที่ 1 — ลูกค้าขอคุยภายใน 3 วัน", icon: "Bell" },
];

const PROPOSALS = [
  { id: "PRP-0080", leadId: "L-1030", company: "Bee Honey Organic Farm", services: ["จดบริษัท", "บัญชีรายเดือน"], total: 138000, status: "Approved", createdAt: "2026-05-01", owner: "นิ้ง",
    tierId: "tier-1-2", monthlyPrice: 10000, billingMode: "monthly", annualDiscountPct: 0,
    addons: [{ id: "company_reg", label: "จดทะเบียนบริษัท / นิติบุคคล", price: 18000 }] },
  { id: "PRP-0081", leadId: "L-1031", company: "Charoen Pharma Trading", services: ["บัญชีรายเดือน", "ตรวจสอบบัญชี", "เงินเดือน"], total: 268000, status: "Approved", createdAt: "2026-04-25", owner: "อ้อม",
    tierId: "tier-1-2-3", monthlyPrice: 18000, billingMode: "annual", annualDiscountPct: 10,
    addons: [{ id: "annual_audit", label: "ตรวจสอบบัญชีรายปี (Audit)", price: 30000 }, { id: "vat_reg", label: "จดทะเบียนภาษีมูลค่าเพิ่ม (VAT)", price: 5500 }] },
  { id: "PRP-0082", leadId: "L-1028", company: "เสริมศรี ก่อสร้าง 1999", services: ["บัญชีรายเดือน", "เงินเดือน"], total: 144000, status: "Sent", createdAt: "2026-05-12", owner: "นิ้ง",
    tierId: "tier-1-2", monthlyPrice: 12000, billingMode: "monthly", annualDiscountPct: 0, addons: [] },
  { id: "PRP-0083", leadId: "L-1027", company: "Cloud Studio Bangkok", services: ["จดบริษัท", "วางระบบภาษี"], total: 144000, status: "Sent", createdAt: "2026-05-12", owner: "นิ้ง",
    tierId: "tier-1-2", monthlyPrice: 10500, billingMode: "annual", annualDiscountPct: 10,
    addons: [{ id: "company_reg", label: "จดทะเบียนบริษัท / นิติบุคคล", price: 18000 }, { id: "advisory", label: "ที่ปรึกษาด้านบัญชี/ภาษีอากร (ข้อ 7)", price: 12000 }] },
  { id: "PRP-0084", leadId: "L-1033", company: "GreenLeaf Botanicals Co.", services: ["บัญชีรายเดือน", "วางระบบภาษี"], total: 108000, status: "Draft", createdAt: "2026-05-16", owner: "นิ้ง",
    tierId: "tier-1", monthlyPrice: 8000, billingMode: "annual", annualDiscountPct: 10,
    addons: [{ id: "fs_analysis", label: "วิเคราะห์งบการเงิน + เสนอแนะข้อสังเกต (ข้อ 6)", price: 15000 }] },
  { id: "PRP-0085", leadId: "L-1029", company: "Tasty Box Catering", services: ["บัญชีรายเดือน"], total: 96000, status: "Rejected", createdAt: "2026-04-30", owner: "อ้อม",
    tierId: "tier-1", monthlyPrice: 8000, billingMode: "monthly", annualDiscountPct: 0, addons: [] },
];

const CUSTOMERS = [
  {
    id: "C-0042",
    fromProposal: "PRP-0080",
    customerType: "active",
    contractSignedAt: "2026-04-20",
    serviceProvider: "นิติพัฒนา",
    mainCaretaker: "อ้อม",
    startDate: "2026-04-25",

    // Company
    company: "บริษัท เพอร์ร่า คลินิก พัทยา สาย3 จำกัด",
    taxId: "0205567055020",
    type: "กลุ่มธุรกิจบริการ",
    address: "245/150 หมู่ที่ 9 ตำบลหนองปรือ อำเภอบางละมุง จ.ชลบุรี 20150",
    registeredCapital: "1,000,000 บาท",
    directors: 4,
    closingDate: "31 ธันวาคม",
    registrationDate: "16 ม.ค. 2567",
    hasCert: true,
    hasStamp: true,
    ssoRegistered: true,
    vatRegistered: true,

    // Contact
    contact: "คุณต้า",
    nickname: "ต้า",
    phone: "093-919-7561",
    line: "@perra-pattaya",
    email: "ta@perra-clinic.co.th",
    secondaryContact: "คุณบิว",
    secondaryPhone: "096-739-5999",
    documentChannel: "ไลน์กลุ่ม",

    // Package
    package: "จัดทำบัญชีและนำส่งภาษีรายเดือน + จัดทำเงินเดือน",
    packageItems: [
      "1. จัดทำบัญชีและนำส่งภาษีรายเดือน",
      "2. จัดทำเงินเดือนและภาษีที่เกี่ยวข้อง",
    ],
    sinceMonth: "เม.ย. 2569",
    revenue: 240000,        // 20,000 × 12 months
    monthlyFee: 20000,

    // Financial snapshot
    financialDate: "31 ธ.ค. 2567",
    assets: 5200000,
    liabilities: 1800000,
    equity: 3400000,
    annualRevenue: 18500000,
    annualExpense: 15800000,
    netProfit: 2700000,

    // Employees
    permanentEmployees: 12,
    tempEmployees: 3,
    totalEmployees: 15,

    // Bank
    bankStatements: ["KBANK672"],

    // Payroll
    payrollSchedule: "ทุกสิ้นเดือน (30/31)",
    employerId: "(ดูในระบบ SSO)",
    specialConditions: "จ่ายเงินเดือนตรงเดือน เช่น ก.พ. จ่าย 28/02 มี.ค. จ่าย 31/03",

    tags: ["responsive", "pay-on-time", "easy-work"],
    insights: {
      pace: "เร็ว",
      lineResponse: "ตอบไลน์",
      callNeeded: "ไม่ต้องโทร",
      detail: "ปานกลาง",
      payment: "ตรงเวลา",
    },
    serviceCode: { revenue: "PRP3-REV", payroll: "PRP3-EMP", tax: "PRP3-TAX" },
  },
  {
    id: "C-0043",
    fromProposal: "PRP-0081",
    customerType: "active",
    contractSignedAt: "2026-04-18",
    serviceProvider: "นิติพัฒนา",
    mainCaretaker: "นิ้ง",
    startDate: "2026-04-22",

    company: "บริษัท เพอร์ร่า คลินิก บางแสน จำกัด",
    taxId: "0205567055097",
    type: "กลุ่มธุรกิจบริการ",
    address: "193/6-8 ถนนลงหาดบางแสน ตำบลแสนสุข อำเภอเมืองชลบุรี จ.ชลบุรี 20131",
    registeredCapital: "1,000,000 บาท",
    directors: 2,
    closingDate: "31 ธันวาคม",
    registrationDate: "20 ก.พ. 2567",
    hasCert: true,
    hasStamp: true,
    ssoRegistered: true,
    vatRegistered: false,

    contact: "คุณต้า",
    nickname: "ต้า",
    phone: "093-919-7561",
    line: "@perra-bangsaen",
    email: "ta@perra-clinic.co.th",
    secondaryContact: "คุณบิว",
    secondaryPhone: "096-739-5999",
    documentChannel: "ไลน์กลุ่ม",

    package: "จัดทำเงินเดือนและภาษีที่เกี่ยวข้อง",
    packageItems: [
      "1. จัดทำบัญชีและนำส่งภาษีรายเดือน",
      "2. จัดทำเงินเดือนและภาษีที่เกี่ยวข้อง",
    ],
    sinceMonth: "เม.ย. 2569",
    revenue: 180000,
    monthlyFee: 15000,

    financialDate: "31 ธ.ค. 2567",
    assets: 3800000,
    liabilities: 1200000,
    equity: 2600000,
    annualRevenue: 12400000,
    annualExpense: 10800000,
    netProfit: 1600000,

    permanentEmployees: 8,
    tempEmployees: 2,
    totalEmployees: 10,

    bankStatements: ["KBANK919"],

    payrollSchedule: "ทุกสิ้นเดือน (30/31)",
    employerId: "(ดูในระบบ SSO)",
    specialConditions: "—",

    tags: ["responsive", "pay-on-time"],
    insights: {
      pace: "ปกติ",
      lineResponse: "ตอบไลน์",
      callNeeded: "ไม่ต้องโทร",
      detail: "ปานกลาง",
      payment: "ตรงเวลา",
    },
    serviceCode: { revenue: "PRP-BS-REV", payroll: "PRP-BS-EMP", tax: "PRP-BS-TAX" },
  },
  // Prospects — created during lead/AE process, not yet active customers
  {
    id: "P-0044",
    fromProposal: "PRP-0083",
    customerType: "prospect",
    prospectStage: "AE Follow-up · รอเซ็นสัญญา",
    leadId: "L-1027",
    company: "Cloud Studio Bangkok Co., Ltd.",
    taxId: "(จะยืนยันหลังเซ็นสัญญา)",
    type: "นิติบุคคล / Tech Studio",
    address: "(จาก Lead — จะอัปเดตเมื่อเซ็นสัญญา)",
    contact: "คุณภัทร นาคะ (ตอง)",
    phone: "092-555-7788",
    line: "@cloudstudio",
    email: "patr@cloudstudio.io",
    package: "จดบริษัท + วางระบบภาษี",
    packageItems: ["1. จดทะเบียนบริษัท", "2. วางระบบบัญชี/ภาษี"],
    sinceMonth: "—",
    revenue: 45000,
    monthlyFee: 0,
    tags: [],
    insights: { pace: "เร็ว", lineResponse: "ตอบไลน์", callNeeded: "ไม่ต้องโทร", detail: "ปานกลาง", payment: "—" },
    serviceCode: { revenue: "—", payroll: "—", tax: "—" },
  },
  {
    id: "P-0045",
    fromProposal: "PRP-0084",
    customerType: "prospect",
    prospectStage: "AE Proposal · รอลูกค้าตอบ",
    leadId: "L-1033",
    company: "บริษัท กรีนลีฟ โบทานิคอลส์ จำกัด",
    taxId: "(จะยืนยันหลังเซ็นสัญญา)",
    type: "กลุ่มธุรกิจการเกษตร & สมุนไพร",
    address: "(จาก Lead — จะอัปเดตเมื่อเซ็นสัญญา)",
    contact: "คุณกานต์ สวนสมบูรณ์",
    phone: "088-321-1122",
    line: "@greenleaf",
    email: "kan@greenleaf.co.th",
    package: "จัดทำบัญชีรายเดือน + วางระบบภาษี",
    packageItems: ["1. จัดทำบัญชีและนำส่งภาษีรายเดือน", "2. วางระบบภาษี"],
    sinceMonth: "—",
    revenue: 30000,
    monthlyFee: 0,
    tags: [],
    insights: { pace: "ปกติ", lineResponse: "ตอบไลน์", callNeeded: "ไม่ต้องโทร", detail: "ปานกลาง", payment: "—" },
    serviceCode: { revenue: "—", payroll: "—", tax: "—" },
  },
];

// Package tiers — based on customer pricing spec
const PACKAGE_ITEMS = [
  { id: 1, label: "จัดทำบัญชีและนำส่งภาษีรายเดือน" },
  { id: 2, label: "จัดทำเงินเดือนและภาษีที่เกี่ยวข้อง" },
  { id: 3, label: "จัดทำทะเบียนคุมสินค้าคงเหลือและคำนวณต้นทุนขาย" },
  { id: 4, label: "จัดทำทะเบียนคุมสินทรัพย์และคำนวณค่าเสื่อม" },
  { id: 5, label: "จัดทำรายละเอียดประกอบงบการเงินรายเดือน" },
  { id: 6, label: "วิเคราะห์งบการเงินและเสนอแนะข้อสังเกตให้ผู้บริหาร", custom: true },
  { id: 7, label: "ที่ปรึกษาด้านบัญชีและภาษีอากรสำหรับธุรกิจ", custom: true },
];

const PACKAGE_TIERS = [
  { id: "tier-1",   label: "Tier 1 — Basic", items: [1],          priceMin: 5000,  priceMax: 8000,  desc: "ทำบัญชีและนำส่งภาษีรายเดือน" },
  { id: "tier-1-2", label: "Tier 2 — + Payroll", items: [1, 2],   priceMin: 8000,  priceMax: 12000, desc: "บัญชี + เงินเดือน" },
  { id: "tier-1-2-3", label: "Tier 3a — + Inventory", items: [1, 2, 3], priceMin: 12000, priceMax: 20000, desc: "บัญชี + เงินเดือน + สินค้าคงเหลือ" },
  { id: "tier-1-2-4", label: "Tier 3b — + Asset Register", items: [1, 2, 4], priceMin: 12000, priceMax: 20000, desc: "บัญชี + เงินเดือน + ทะเบียนคุมสินทรัพย์" },
  { id: "tier-full", label: "Tier 4 — Full Suite", items: [1, 2, 3, 4, 5], priceMin: 20000, priceMax: 30000, desc: "ครบทุกบริการรายเดือน" },
];

// One-time registration services (require their own รายครั้ง proposal)
const ONE_TIME_SERVICES = [
  { id: "company_reg",  label: "จดทะเบียนบริษัท / นิติบุคคล",   priceMin: 15000, priceMax: 20000, icon: "Building2", autoCreatesJob: true,  jobTemplate: "Company Registration", note: "ต้องทำก่อนไปซื้อ Package" },
  { id: "vat_reg",      label: "จดทะเบียนภาษีมูลค่าเพิ่ม (VAT)",   priceMin: 4500,  priceMax: 6000,  icon: "Receipt",    autoCreatesJob: false },
  { id: "sso_reg",      label: "จดทะเบียนประกันสังคม",             priceMin: 3000,  priceMax: 4500,  icon: "ShieldCheck", autoCreatesJob: false },
  { id: "annual_audit", label: "ตรวจสอบบัญชีรายปี (Audit)",         priceMin: 20000, priceMax: 35000, icon: "ClipboardCheck", autoCreatesJob: true,  jobTemplate: "Annual Audit" },
];

// Advisory add-ons that ATTACH to a Package proposal (not standalone)
const PACKAGE_ADDONS = [
  { id: "fs_analysis",  label: "วิเคราะห์งบการเงิน + เสนอแนะข้อสังเกต (ข้อ 6)", priceMin: 0, priceMax: 0, type: "advisory", custom: true, autoCreatesJob: false, note: "พิจารณาค่าบริการตามความเหมาะสม" },
  { id: "advisory",     label: "ที่ปรึกษาด้านบัญชี/ภาษีอากร (ข้อ 7)", priceMin: 0, priceMax: 0, type: "advisory", custom: true, autoCreatesJob: false, note: "พิจารณาค่าบริการตามความเหมาะสม" },
];

// Legacy combined alias (for any code still referring to ADDONS)
const ADDONS = [...ONE_TIME_SERVICES, ...PACKAGE_ADDONS];

// Legacy alias for code that still imports SERVICE_PACKAGES
const SERVICE_PACKAGES = [
  ...PACKAGE_ITEMS.map(p => ({ id: `monthly-${p.id}`, label: p.label, monthlyPrice: 0, oneTime: 0 })),
  ...ADDONS.map(a => ({ id: a.id, label: a.label, monthlyPrice: 0, oneTime: a.priceMin })),
];

const JOBS = [
  {
    id: "J-2031",
    code: "CASE-2026-0231",
    customerId: "C-0042",
    customer: "Bee Honey Organic Farm",
    title: "จดทะเบียนบริษัทใหม่ — Bee Honey Organic Farm Co., Ltd.",
    docType: "งานจดบริษัท",
    type: "งานจดบริษัท",
    template: "Company Registration v3",
    priority: "High",
    status: "In Progress",
    progress: 0.7,
    dueAt: "2026-05-25",
    createdAt: "2026-05-10",
    owner: "ทีมจดทะเบียน",
    assignees: [{ name: "นิ้ง", role: "Lead" }, { name: "อ้อม", role: "Co" }],
    description: "ลูกค้า Bee Honey ต้องการจดบริษัทพร้อม 3 หุ้นส่วน · เริ่มต้น พ.ค. 2569",
    attachments: 4,
    commentsCount: 6,
    steps: [
      { id: "s1", name: "เตรียมเอกสารผู้ก่อตั้ง", done: true },
      { id: "s2", name: "จองชื่อบริษัท (DBD)", done: true },
      { id: "s3", name: "ยื่นจดทะเบียนหนังสือบริคณห์ฯ", done: true },
      { id: "s4", name: "ประชุมผู้ถือหุ้น", done: true },
      { id: "s5", name: "รับใบสำคัญแสดงการจดทะเบียน", done: false, active: true },
      { id: "s6", name: "ขอเลขประจำตัวผู้เสียภาษี (RD)", done: false },
      { id: "s7", name: "แต่งตั้งเป็นตัวแทนหัก ณ ที่จ่าย", done: false },
    ],
  },
  {
    id: "J-2032",
    code: "CASE-2026-0232",
    customerId: "C-0042",
    customer: "Bee Honey Organic Farm",
    title: "ปิดบัญชีรายเดือน — เม.ย. 2569",
    docType: "บัญชีรายเดือน",
    type: "งานบัญชีรายเดือน",
    template: "Monthly Bookkeeping Standard",
    priority: "Medium",
    status: "Waiting Document",
    progress: 0.25,
    dueAt: "2026-06-15",
    createdAt: "2026-05-01",
    owner: "อ้อม + ทีม",
    assignees: [{ name: "อ้อม", role: "Lead" }],
    description: "ปิดบัญชีประจำเดือน เม.ย. รวม VAT report",
    attachments: 12,
    commentsCount: 3,
    steps: [
      { id: "s1", name: "รับเอกสารรายได้ผ่าน Line", done: true },
      { id: "s2", name: "ตรวจสอบใบกำกับภาษีซื้อ-ขาย", done: false, active: true },
      { id: "s3", name: "บันทึกบัญชี", done: false },
      { id: "s4", name: "ยื่น ภพ.30", done: false },
      { id: "s5", name: "ยื่น ภงด.1, 3, 53", done: false },
      { id: "s6", name: "ส่งรายงานสรุปให้ลูกค้า", done: false },
    ],
  },
  {
    id: "J-2033",
    code: "CASE-2026-0233",
    customerId: "C-0043",
    customer: "Charoen Pharma Trading",
    title: "ปิดบัญชีรายเดือน — เม.ย. 2569 (Enterprise)",
    docType: "บัญชีรายเดือน",
    type: "งานบัญชีรายเดือน",
    template: "Enterprise Monthly + High-Detail",
    priority: "High",
    status: "In Progress",
    progress: 0.5,
    dueAt: "2026-06-15",
    createdAt: "2026-04-28",
    owner: "นิ้ง + ทีม",
    assignees: [{ name: "นิ้ง", role: "Lead" }, { name: "บอย", role: "Co" }, { name: "ฟ้า", role: "Co" }],
    description: "Reconcile Bank statement กับ Invoice นำเข้า — ลูกค้า high-detail",
    attachments: 28,
    commentsCount: 11,
    steps: [
      { id: "s1", name: "รับเอกสารต้นฉบับ (ไปรับที่ออฟฟิศ)", done: true },
      { id: "s2", name: "ตรวจ Invoice นำเข้า", done: true },
      { id: "s3", name: "Reconcile กับ Bank Statement", done: true },
      { id: "s4", name: "บันทึกบัญชี", done: false, active: true },
      { id: "s5", name: "ยื่น ภพ.30", done: false },
      { id: "s6", name: "ส่งสรุป Management Report", done: false },
    ],
  },
  {
    id: "J-2034",
    code: "CASE-2026-0234",
    customerId: "C-0043",
    customer: "Charoen Pharma Trading",
    title: "ระบบเงินเดือน — ตั้งค่าครั้งแรก",
    docType: "เงินเดือน / HR",
    type: "งานเงินเดือน",
    template: "Payroll Setup",
    priority: "Medium",
    status: "Waiting Customer",
    progress: 0.33,
    dueAt: "2026-05-30",
    createdAt: "2026-05-05",
    owner: "ทีม HR",
    assignees: [{ name: "ฟ้า", role: "Lead" }],
    description: "รอลูกค้าส่งข้อมูลพนักงาน 28 คน",
    attachments: 2,
    commentsCount: 4,
    steps: [
      { id: "s1", name: "รับข้อมูลพนักงาน HR", done: true, active: false },
      { id: "s2", name: "ตั้งระบบประกันสังคม", done: false, active: true },
      { id: "s3", name: "Run payroll เดือนแรก", done: false },
    ],
  },
  {
    id: "J-2035",
    code: "CASE-2026-0228",
    customerId: "C-0042",
    customer: "Bee Honey Organic Farm",
    title: "ยื่น ภงด.50 ปี 2568",
    docType: "ภาษีนิติบุคคล",
    type: "งานภาษี",
    template: "Annual Tax Filing",
    priority: "Low",
    status: "Done",
    progress: 1,
    dueAt: "2026-05-10",
    createdAt: "2026-04-01",
    owner: "อ้อม",
    assignees: [{ name: "อ้อม", role: "Lead" }],
    description: "ยื่นเสร็จเรียบร้อยเมื่อ 5 พ.ค.",
    attachments: 6,
    commentsCount: 2,
    steps: [
      { id: "s1", name: "เตรียมงบ", done: true },
      { id: "s2", name: "คำนวณภาษี", done: true },
      { id: "s3", name: "ยื่น ภงด.50", done: true },
    ],
  },
  {
    id: "J-2036",
    code: "CASE-2026-0235",
    customerId: "C-0043",
    customer: "Charoen Pharma Trading",
    title: "ตรวจสอบบัญชี — ปีงบ 2568",
    docType: "ตรวจสอบบัญชี",
    type: "งานตรวจสอบ",
    template: "Annual Audit",
    priority: "High",
    status: "Waiting Document",
    progress: 0.15,
    dueAt: "2026-07-31",
    createdAt: "2026-05-12",
    owner: "ทีม Audit",
    assignees: [{ name: "บอย", role: "Lead" }, { name: "นิ้ง", role: "Co" }],
    description: "Sample testing งบ 12 เดือน + Management Letter",
    attachments: 3,
    commentsCount: 1,
    steps: [
      { id: "s1", name: "รับเอกสาร", done: true, active: false },
      { id: "s2", name: "Sample testing", done: false, active: true },
      { id: "s3", name: "ออก Management Letter", done: false },
      { id: "s4", name: "ออกรายงานผู้สอบ", done: false },
    ],
  },
];

const JOB_COMMENTS = [
  { id: "cm1", jobId: "J-2031", at: "2026-05-15 14:30", by: "นิ้ง", text: "ยื่นจดทะเบียนเข้าระบบ DBD แล้ว — รอใบสำคัญฯ 3-5 วันทำการ", type: "update" },
  { id: "cm2", jobId: "J-2031", at: "2026-05-14 11:00", by: "อ้อม", text: "ส่งสำเนาบัตรประชาชนผู้ก่อตั้งทั้ง 3 คนแล้ว", type: "comment" },
  { id: "cm3", jobId: "J-2031", at: "2026-05-12 09:15", by: "ระบบ", text: "ลูกค้าอัปโหลดเอกสารจาก Line OA", type: "system" },
  { id: "cm4", jobId: "J-2032", at: "2026-05-16 10:00", by: "อ้อม", text: "ตามใบเสร็จค่าน้ำมันเพิ่ม 6 ใบจากลูกค้า", type: "comment" },
  { id: "cm5", jobId: "J-2033", at: "2026-05-16 13:45", by: "นิ้ง", text: "Reconcile กับ Bank Statement ครบแล้ว — ยอดต่างเหลือ 1,250 บาท", type: "update" },
  { id: "cm6", jobId: "J-2033", at: "2026-05-14 09:00", by: "บอย", text: "ตรวจ Invoice นำเข้า 47 ใบ ครบทั้งหมด", type: "update" },
];

const STATUS_OPTS = [
  { value: "All", label: "สถานะทั้งหมด" },
  { value: "Waiting Document", label: "รอเอกสาร", color: "amber" },
  { value: "In Progress", label: "กำลังดำเนินการ", color: "marketing" },
  { value: "Waiting Customer", label: "รอลูกค้า / รอทีมงาน", color: "purple" },
  { value: "Done", label: "เสร็จแล้ว", color: "service" },
  { value: "Cancel", label: "ยกเลิก", color: "slate" },
];

const PRIORITY_OPTS = [
  { value: "All", label: "ทั้งหมด" },
  { value: "High", label: "ด่วน", color: "rose" },
  { value: "Medium", label: "รอได้", color: "amber" },
  { value: "Low", label: "ไม่รีบ", color: "service" },
];

const COMM_LOG = [
  { id: "cl1", customerId: "C-0042", at: "2026-05-15 14:20", channel: "Line", by: "อ้อม", text: "ลูกค้าส่งใบเสร็จค่าน้ำมัน 6 ใบ ผ่าน Line OA", tag: "เอกสาร" },
  { id: "cl2", customerId: "C-0042", at: "2026-05-14 09:10", channel: "Email", by: "ระบบ", text: "ส่ง Statement ของเดือน เม.ย. ให้ลูกค้า", tag: "รายงาน" },
  { id: "cl3", customerId: "C-0042", at: "2026-05-12 13:20", channel: "Call", by: "นิ้ง", text: "โทรแจ้งเริ่มงาน onboarding 4:30", tag: "Onboarding" },
  { id: "cl4", customerId: "C-0043", at: "2026-05-16 10:00", channel: "Call", by: "นิ้ง", text: "ตามเอกสาร invoice นำเข้าเดือน เม.ย. — โทร 3 ครั้ง", tag: "ตามเอกสาร" },
  { id: "cl5", customerId: "C-0043", at: "2026-05-13 09:00", channel: "Line", by: "อ้อม", text: "ลูกค้าตอบช้า → ส่งเตือน auto-reminder", tag: "Reminder" },
];

const FOLLOWUPS = [
  { id: "f1", leadId: "L-1027", company: "Cloud Studio Bangkok", at: "2026-05-18 10:30", type: "Call", by: "นิ้ง", attempts: 3, status: "scheduled" },
  { id: "f2", leadId: "L-1028", company: "เสริมศรี ก่อสร้าง 1999", at: "2026-05-17 14:00", type: "Call", by: "นิ้ง", attempts: 2, status: "scheduled" },
  { id: "f3", leadId: "L-1029", company: "Tasty Box Catering", at: "2026-05-17 11:00", type: "Line", by: "อ้อม", attempts: 4, status: "scheduled" },
  { id: "f4", leadId: "L-1033", company: "GreenLeaf Botanicals Co.", at: "2026-05-19 15:30", type: "Email", by: "นิ้ง", attempts: 1, status: "scheduled" },
  { id: "f5", leadId: "L-1026", company: "สหกรณ์ผ้าไทยล้านนา", at: "2026-05-17 09:30", type: "Call", by: "อ้อม", attempts: 2, status: "scheduled" },
];

const CALLS = [
  { id: "c1", leadId: "L-1027", company: "Cloud Studio Bangkok", at: "2026-05-16 09:14", duration: "00:08:12", result: "ตอบรับ", note: "ลูกค้าขอเวลาคิด 3 วัน", by: "นิ้ง" },
  { id: "c2", leadId: "L-1028", company: "เสริมศรี ก่อสร้าง 1999", at: "2026-05-15 16:00", duration: "00:04:55", result: "ตอบรับ", note: "สนใจแพ็คเกจ Mid", by: "นิ้ง" },
  { id: "c3", leadId: "L-1029", company: "Tasty Box Catering", at: "2026-05-15 11:00", duration: "00:00:42", result: "ไม่รับ", note: "ฝากข้อความใน Line", by: "อ้อม" },
  { id: "c4", leadId: "L-1026", company: "สหกรณ์ผ้าไทยล้านนา", at: "2026-05-15 10:20", duration: "00:14:30", result: "ตอบรับ", note: "ส่งสรุปข้อมูล KYC ทาง email", by: "อ้อม" },
  { id: "c5", leadId: "L-1025", company: "บ้านสวนสุขใจ Shopee Mall", at: "2026-05-15 14:32", duration: "00:11:18", result: "ตอบรับ", note: "ตอบคำถามเรื่อง VAT จ้างฟรีแลนซ์", by: "นิ้ง" },
];

window.CRM_DATA = {
  SOURCES, TAGS, STAGES, LEADS, ACTIVITIES,
  PROPOSALS, CUSTOMERS, SERVICE_PACKAGES, PACKAGE_ITEMS, PACKAGE_TIERS,
  ADDONS, ONE_TIME_SERVICES, PACKAGE_ADDONS,
  JOBS, JOB_COMMENTS, COMM_LOG, FOLLOWUPS, CALLS,
  STATUS_OPTS, PRIORITY_OPTS,
  AE_TEAM, MK_TEAM, REQUIRED_CALLS, AE_STAGE_REQUIREMENTS,
};
