// Seed data — plausible printing-industry ERP tenant.
// Original company name; not derived from the reference product.

const COMPANIES = [
  { id: "std", name: "标准版 (Standard Edition) / 8s" },
  { id: "ent", name: "企业版 (Enterprise Edition) / 8s" },
  { id: "trial", name: "试用版 (Trial Edition) / 30d" },
];

// Sidebar tree — printing-industry processes
const NAV_TREE = [
  { id: "home", label: "首页", icon: "home", leaf: true },
  {
    id: "kpi", label: "KPI 流程作业单", icon: "doc",
    children: [
      {
        id: "quote", label: "估价管理流程",
        children: [
          { id: "quote-01", label: "01/04 【新增】新报价单", leaf: true, badge: "估价" },
          { id: "quote-02", label: "02/04 审核报价单->客户确认...", leaf: true },
          { id: "quote-03", label: "03/04 客户确认->二次确认", leaf: true },
          { id: "quote-04", label: "04/04 报价单->销售订单", leaf: true },
          { id: "quote-05", label: "04/04 报价单->转拼版单", leaf: true },
          { id: "quote-06", label: "04/07 主管审核报价单", leaf: true },
          { id: "quote-07", label: "05/07 业务确认报价单", leaf: true },
        ],
      },
      { id: "order", label: "订单生产流程" },
      { id: "panel", label: "自动拼版流程" },
      { id: "ship", label: "销售送货流程" },
      { id: "purch", label: "物料采购流程" },
      { id: "issue", label: "物料领用流程" },
      { id: "outproc", label: "发外加工流程" },
      { id: "qc", label: "质量管理流程" },
      { id: "fin", label: "财务收付款流程" },
    ],
  },
  { id: "crm", label: "CRM 管理", icon: "folder" },
  { id: "plm", label: "PLM 管理", icon: "folder" },
  { id: "prod", label: "产品管理", icon: "folder" },
  { id: "sales", label: "销售管理", icon: "folder" },
  { id: "mfg", label: "生产管理", icon: "folder" },
  { id: "exec", label: "生产执行", icon: "folder" },
  { id: "mold", label: "模具管理", icon: "folder" },
  {
    id: "sys", label: "系统管理", icon: "settings",
    children: [
      { id: "roles", label: "角色管理", leaf: true },
      { id: "menucfg", label: "菜单配置", leaf: true },
      { id: "log", label: "操作日志", leaf: true },
    ],
  },
];

// Permission-group rows (left column of permission tab)
const PERMISSION_GROUPS = [
  "权限分类", "默认显示(必选)", "禁止查看价格", "客服报单",
  "报价组员工", "物控组员工", "供应链 PMC", "允许查看订单价格",
  "储运员工", "外接供应商", "品质组员工", "技术中心员工",
  "机修组员工", "生产排计划员工", "外发组员工",
  "模切车间", "装订车间", "粘接工车间", "品质部管理", "精品车间",
  "人事组", "统计组", "机修主管", "样品开发员工", "设计开发", "总经办",
  "财务部", "销售员", "采购员", "仓库管理员",
];

const DEPARTMENTS = [
  "工艺技术", "印刷车间", "机修", "机务部", "财务部",
  "装订车间", "总经办公室", "总务部", "供应链", "质量管理部",
  "模切车间", "计划组", "样品开发", "设计部", "仓库",
];

const USER_TYPES = ["超级管理员", "高级管理员", "普通用户", "外部用户", "只读用户"];
const LANGUAGES = ["中文", "英文", "繁体"];

// Plausible Chinese-name pinyin pairs
const NAME_POOL = [
  ["管广飞", "ggf"], ["李斌", "lib"], ["系统管理员", "admin"], ["朱财喜", "zhucx"],
  ["林杰华", "ljh"], ["汪鑫", "wx"], ["钱昉", "qianb"], ["张冠飞", "zgf"],
  ["孟威", "mengw"], ["杭仁萍", "hangrp"], ["王月", "wy"], ["王宽明", "wkm"],
  ["潘强", "pq"], ["耿广东", "ggd"], ["余涛", "yt"], ["梁赵军", "lzj"],
  ["曹佳怡", "cjy"], ["陈思琪", "csq"], ["张红英", "zhy"], ["吕欣彦", "lxy"],
  ["陈雪婷", "cxt"], ["路鑫", "luxin"], ["陆鑫·储运部", "ZY0006"],
  ["朱晓兵", "zhuxb"], ["孟丽花", "menglh"], ["彭敏", "pengm"], ["顾鹏", "gp"],
  ["田雨", "ty"], ["黄文豪", "hwh"], ["邓佳", "dj"], ["孙浩然", "shr"],
  ["徐瑞", "xr"], ["许云", "xy"], ["何晨曦", "hcx"], ["林婉君", "lwj"],
  ["杨柳", "yl"], ["蒋婷", "jt"],
];

const seededRandom = (seed) => {
  let s = seed;
  return () => { s = (s * 9301 + 49297) % 233280; return s / 233280; };
};

const pad = (n) => String(n).padStart(2, "0");
const dt = (y, m, d, hh, mm, ss) =>
  `${y}-${pad(m)}-${pad(d)} ${pad(hh)}:${pad(mm)}:${pad(ss)}`;

const buildUsers = () => {
  const rand = seededRandom(7);
  return NAME_POOL.map((nm, i) => {
    const r = rand();
    return {
      id: i + 1,
      seq: i + 1,
      employee: nm[0],
      empNo: nm[1],
      account: nm[1],
      department: DEPARTMENTS[Math.floor(rand() * DEPARTMENTS.length)],
      type: USER_TYPES[Math.floor(rand() * USER_TYPES.length)],
      language: r < 0.15 ? "英文" : "中文",
      disabled: r < 0.08,
      lastLogin: dt(2026, 1 + Math.floor(rand() * 4), 1 + Math.floor(rand() * 27),
                    8 + Math.floor(rand() * 10), Math.floor(rand() * 60), Math.floor(rand() * 60)),
      createdBy: ["超级管理员", "机仁萍", "李丹", "YFZ", "LJH", "孟琰"][Math.floor(rand() * 6)],
      createdAt: dt(2023 + Math.floor(rand() * 3), 1 + Math.floor(rand() * 12),
                    1 + Math.floor(rand() * 27), 8 + Math.floor(rand() * 10),
                    Math.floor(rand() * 60), Math.floor(rand() * 60)),
      // Default: a small subset of permission groups checked
      permissions: PERMISSION_GROUPS.reduce((acc, g) => {
        acc[g] = rand() < 0.18; return acc;
      }, {}),
      tabPerms: { customer: rand() < 0.4, supplier: rand() < 0.3, staff: rand() < 0.3, process: rand() < 0.3, driver: rand() < 0.2 },
    };
  });
};

// Mega-nav grid: top-level sections (left rail) → category columns → leaf items
const MEGA_NAV = [
  { id: "sales-mgmt", icon: "folder", label: "销售管理" },
  { id: "dcs", icon: "folder", label: "DCS 系统" },
  { id: "prod-mgmt", icon: "folder", label: "产品管理" },
  { id: "prod-ops", icon: "folder", label: "生产运营" },
  { id: "prod-exec", icon: "folder", label: "生产执行" },
  { id: "mold", icon: "folder", label: "模具管理" },
  { id: "purch", icon: "folder", label: "采购管理" },
  { id: "matwh", icon: "folder", label: "材料库存" },
  { id: "fgwh", icon: "folder", label: "成品库存" },
  { id: "outsrc", icon: "folder", label: "外协管理" },
  { id: "logistics", icon: "folder", label: "物流管理" },
  { id: "qc", icon: "folder", label: "质量管理" },
  { id: "fin", icon: "folder", label: "财务管理" },
  { id: "cost-pro", icon: "folder", label: "成本管理(专)" },
  { id: "cost", icon: "folder", label: "成本管理" },
  { id: "equip", icon: "folder", label: "设备管理" },
  { id: "hr", icon: "folder", label: "人事行政" },
  { id: "oa", icon: "folder", label: "OA 系统" },
  { id: "base", icon: "folder", label: "基础设置" },
  { id: "sys", icon: "settings", label: "系统设置", active: true },
];

const MEGA_COLUMNS = {
  "sys": [
    { title: "期初设置", items: [
      { label: "客户期初" }, { label: "供应商期初" }, { label: "材料期初" }, { label: "产品期初" }, { label: "数据导入" }, { label: "离线导出下载" },
    ]},
    { title: "用户管理", items: [
      { label: "用户列表", screen: "userlist", featured: true },
      { label: "系统权限" }, { label: "系统权限程查表" }, { label: "权限组" },
    ]},
    { title: "系统参数", items: [
      { label: "系统参数" }, { label: "财务结准" }, { label: "系统常量配置" },
    ]},
    { title: "计算方案", items: [
      { label: "方案列表" }, { label: "计算参数" },
    ]},
    { title: "日志", items: [
      { label: "个性化模块" }, { label: "操作日志" }, { label: "异常清除KPI任务表" }, { label: "MYSQL监听器" },
    ]},
    { title: "开发平台", items: [
      { label: "自定义开发范例" }, { label: "系统功能模块设置" }, { label: "ERC流程清单" }, { label: "功能模块界面设置" }, { label: "模拟收付款业务处理" },
    ]},
    { title: "API 对接管理", items: [
      { label: "调用第三方接口(TOKEN配置)" }, { label: "调用第三方接口(接口定义)" }, { label: "被第三方调用(生成token)" }, { label: "数据同步" }, { label: "被第三方调用(API定义)" },
    ]},
    { title: "系统模块", items: [
      { label: "系统模块配置", screen: "module", featured: true },
      { label: "菜单配置" }, { label: "模块字段配置" },
    ]},
  ],
  // Fallback for other sections — show a placeholder column
};

window.XLY = {
  COMPANIES,
  NAV_TREE,
  MEGA_NAV,
  MEGA_COLUMNS,
  PERMISSION_GROUPS,
  DEPARTMENTS,
  USER_TYPES,
  LANGUAGES,
  buildUsers,
};
