window.FB = window.FB || {};
FB.STRINGS = {
  en: {
    appName: "Fragile Burger · Central Kitchen", central: "Central Kitchen",
    who: "Who are you?", pin: "6-digit code", signIn: "Sign in",
    wrongPin: "Wrong name or code. Try again.", signOut: "Sign out",
    dashboard: "Dashboard", baseline: "Opening count", stock: "Stocktake",
    shipping: "Shipping", production: "Production", task: "Daily task", sop: "SOP",
    today: "Today", toHandle: "to handle", allClear: "All clear today",
    inventory: "Inventory", finishedGoods: "Finished goods", perPack: "cost/pack",
    orderSug: "Order suggestions", margin: "Margin",
    notLive: "Not live yet — needs a first full count to start.",
    count: "Count", theoretical: "Theoretical", variance: "Variance",
    total: "Total", safety: "Safety", unit: "Unit", loose: "loose", ctn: "ctn",
    submit: "Submit", submitting: "Submitting…", submitted: "Submitted", failed: "Failed, retry",
    store: "Store", qty: "Qty", loading: "Loading…", noData: "No data", search: "Search",
    belowSafety: "below safety line",
    A: "A · Mon/Wed/Fri", B: "B · Tue", C: "C · 1st", all: "All",
    photo: "Photo", noPhoto: "No photo yet",
    baselineWarn: "One-time: writes the inventory starting point for every item.",
    progress: "Progress", batch: "batch", yield: "Yield", ingredients: "Ingredients", steps: "Steps",
    addProd: "Add item", makeInvoice: "Generate slip", history: "History",
    invoice: "Delivery slip", prepared: "Prepared by", received: "Received by",
    editTask: "Edit tasks", addTask: "Add task", taskCn: "Task (CN)", taskVn: "Task (VN)",
    time: "Time", anytime: "anytime", freq: "Frequency", daily: "Daily", weekly: "Weekly", monthly1: "Monthly 1st",
    save: "Save", del: "Delete", done: "Done", recipe: "recipe",
  },
  zh: {
    appName: "Fragile Burger · 中央厨房", central: "中央厨房",
    who: "你是谁?", pin: "6位密码", signIn: "登录",
    wrongPin: "名字或密码错误,再试一次。", signOut: "退出",
    dashboard: "驾驶舱", baseline: "期初全盘", stock: "盘点",
    shipping: "出货", production: "生产", task: "每日任务", sop: "SOP",
    today: "今天", toHandle: "待处理", allClear: "今天没事",
    inventory: "库存", finishedGoods: "成品", perPack: "每包成本",
    orderSug: "订货建议", margin: "毛利",
    notLive: "未上线 — 做一次期初全盘即可启动。",
    count: "实数", theoretical: "理论", variance: "差异",
    total: "合计", safety: "安全线", unit: "单位", loose: "散", ctn: "箱",
    submit: "提交", submitting: "提交中…", submitted: "已提交", failed: "失败,重试",
    store: "门店", qty: "数量", loading: "加载中…", noData: "暂无数据", search: "搜索",
    belowSafety: "低于安全线",
    A: "A · 一三五", B: "B · 二", C: "C · 1号", all: "全部",
    photo: "照片", noPhoto: "暂无照片",
    baselineWarn: "一次性:写入每个品项的库存起点。",
    progress: "进度", batch: "批", yield: "产出", ingredients: "配料", steps: "步骤",
    addProd: "加一项", makeInvoice: "生成单据", history: "历史",
    invoice: "出货单", prepared: "出货人", received: "签收人",
    editTask: "编辑任务", addTask: "加任务", taskCn: "任务(中)", taskVn: "任务(越)",
    time: "时间", anytime: "不限时", freq: "频率", daily: "每天", weekly: "每周", monthly1: "每月1号",
    save: "保存", del: "删除", done: "完成", recipe: "配方",
  },
  vi: {
    appName: "Fragile Burger · Bếp trung tâm", central: "Bếp trung tâm",
    who: "Bạn là ai?", pin: "Mã 6 số", signIn: "Đăng nhập",
    wrongPin: "Sai tên hoặc mã. Thử lại.", signOut: "Đăng xuất",
    dashboard: "Bảng điều khiển", baseline: "Kiểm kho ban đầu", stock: "Kiểm kho",
    shipping: "Giao hàng", production: "Sản xuất", task: "Việc mỗi ngày", sop: "SOP",
    today: "Hôm nay", toHandle: "cần xử lý", allClear: "Hôm nay ổn",
    inventory: "Tồn kho", finishedGoods: "Thành phẩm", perPack: "giá/gói",
    orderSug: "Gợi ý đặt hàng", margin: "Lợi nhuận",
    notLive: "Chưa chạy — cần kiểm kho ban đầu để bắt đầu.",
    count: "Số đếm", theoretical: "Lý thuyết", variance: "Chênh lệch",
    total: "Tổng", safety: "Mức an toàn", unit: "Đơn vị", loose: "lẻ", ctn: "thùng",
    submit: "Gửi", submitting: "Đang gửi…", submitted: "Đã gửi", failed: "Lỗi, thử lại",
    store: "Cửa hàng", qty: "SL", loading: "Đang tải…", noData: "Không có", search: "Tìm",
    belowSafety: "dưới mức an toàn",
    A: "A · T2/T4/T6", B: "B · T3", C: "C · Ngày 1", all: "Tất cả",
    photo: "Hình", noPhoto: "Chưa có hình",
    baselineWarn: "Một lần: ghi mức tồn kho khởi đầu cho mọi mặt hàng.",
    progress: "Tiến độ", batch: "mẻ", yield: "Sản lượng", ingredients: "Nguyên liệu", steps: "Các bước",
    addProd: "Thêm mục", makeInvoice: "Tạo phiếu", history: "Lịch sử",
    invoice: "Phiếu giao hàng", prepared: "Người giao", received: "Người nhận",
    editTask: "Sửa việc", addTask: "Thêm việc", taskCn: "Việc (TQ)", taskVn: "Việc (VN)",
    time: "Giờ", anytime: "bất kỳ", freq: "Tần suất", daily: "Mỗi ngày", weekly: "Mỗi tuần", monthly1: "Ngày 1 hàng tháng",
    save: "Lưu", del: "Xóa", done: "Xong", recipe: "công thức",
  },
};
FB.makeT = (lang) => (k) => (FB.STRINGS[lang] && FB.STRINGS[lang][k]) || (FB.STRINGS.en[k]) || k;
// 品名按语言取
FB.nm = (i, lang) => lang === "zh" ? (i.name_cn || i.name_en)
  : lang === "vi" ? (i.name_vn || i.name_en || i.name_cn)
  : (i.name_en || i.name_cn);

// ---- v12.1 追加 ----
(function () {
  var add = {
    en: {
      shipTitle: "Store shipping prep",
      shipHint: "Tick when packed. Use \u2212 / + to change the qty; the ordered qty stays as a hint.",
      ordered: "ordered", packed: "packed", pasteOrder: "Paste order", parse: "Fill in",
      pastePlaceholder: "Paste the WhatsApp order here", clear: "Clear",
      menu: "More", close: "Close", steps: "Steps", perPack: "cost / pack",
      packNote: "Packaging scales with output, not batches.",
      receive: "Receiving",
      review: "Review",
      clockin: "Clock in",
      settings: "Settings",
      attendance: "Attendance",
    },
    zh: {
      shipTitle: "\u95e8\u5e97\u51fa\u8d27\u5907\u8d27",
      shipHint: "\u5907\u597d\u4e86\u5c31\u6253\u52fe\u3002\u2212 / + \u6539\u51fa\u8d27\u91cf\uff0c\u539f\u8ba2\u91cf\u4f1a\u7559\u7740\u63d0\u9192\u3002",
      ordered: "\u539f\u8ba2", packed: "\u5df2\u5907", pasteOrder: "\u8d34\u8ba2\u8d27\u5355", parse: "\u81ea\u52a8\u586b\u5165",
      pastePlaceholder: "\u628a WhatsApp \u8ba2\u8d27\u5355\u8d34\u8fdb\u6765", clear: "\u6e05\u7a7a",
      menu: "\u66f4\u591a", close: "\u5173\u95ed", steps: "\u6b65\u9aa4", perPack: "\u6bcf\u5305\u6210\u672c",
      packNote: "\u5305\u88c5\u6309\u4ea7\u51fa\u91cf\u7b97\uff0c\u4e0d\u6309\u6279\u6570\u3002",
      receive: "\u6536\u8d27",
      review: "\u5ba1\u6838",
      clockin: "\u7b7e\u5230",
      settings: "\u8bbe\u7f6e",
      attendance: "\u8003\u52e4",
    },
    vi: {
      shipTitle: "Chu\u1ea9n b\u1ecb giao h\u00e0ng",
      shipHint: "\u0110\u00e1nh d\u1ea5u khi \u0111\u00e3 x\u1ebfp xong. D\u00f9ng \u2212 / + \u0111\u1ec3 \u0111\u1ed5i s\u1ed1 l\u01b0\u1ee3ng.",
      ordered: "\u0111\u1eb7t", packed: "\u0111\u00e3 x\u1ebfp", pasteOrder: "D\u00e1n \u0111\u01a1n", parse: "\u0110i\u1ec1n v\u00e0o",
      pastePlaceholder: "D\u00e1n \u0111\u01a1n WhatsApp v\u00e0o \u0111\u00e2y", clear: "X\u00f3a",
      menu: "Th\u00eam", close: "\u0110\u00f3ng", steps: "C\u00e1c b\u01b0\u1edbc", perPack: "gi\u00e1 / g\u00f3i",
      packNote: "Bao b\u00ec t\u00ednh theo s\u1ea3n l\u01b0\u1ee3ng, kh\u00f4ng theo m\u1ebb.",
      receive: "Nh\u1eadn h\u00e0ng",
      review: "Duy\u1ec7t",
      clockin: "Ch\u1ea5m c\u00f4ng",
      settings: "C\u00e0i \u0111\u1eb7t",
      attendance: "Ch\u1ea5m c\u00f4ng",
    },
  };
  Object.keys(add).forEach(function (l) { Object.assign(FB.STRINGS[l], add[l]); });
})();

// ---- v20.1 订货页 + v20.2 今天做什么/快断分线 ----
(function () {
  var add = {
    en: { ordering: "Ordering", today: "Today",
          gBuy2: "Order it", gBuy2Sub: "buy before it runs out" },
    zh: { ordering: "订货", today: "今天做什么",
          gBuy2: "要订", gBuy2Sub: "断之前买回来" },
    vi: { ordering: "Đặt hàng", today: "Hôm nay làm gì",
          gBuy2: "Cần đặt", gBuy2Sub: "mua trước khi hết" },
  };
  Object.keys(add).forEach(function (l) { Object.assign(FB.STRINGS[l], add[l]); });
})();

// ---- v19 驾驶舱改版 (admin 只有 zh/en, vi 走 en 兜底) ----
(function () {
  var add = {
    en: {
      toProcess: "to handle today", nothingToday: "Nothing to handle today",
      secOut: "Out of stock", secOutSub: "theoretical stock ≤ 0",
      secSoon: "Running out", secSoonSub: "won't last to next count",
      secOrder: "Order today", secMargin: "Margin check", secExc: "Other exceptions",
      gMake: "Make today", gMakeSub: "CK produces it",
      gBuy: "Buy today", gBuySub: "one trip and it's here",
      gWait: "Just wait", gWaitSub: "8 days minimum",
      gWatch: "Watch", gOrder: "Order today", gOrderSub: "longer edge = order sooner",
      lgBroke: "already out", lgWait: "still waiting",
      brokeD: "out", waitD: "wait", dayU: "d", dailyUse: "daily",
      canLast: "lasts", countIn: "count in",
      expandDetail: "Show items", copyOrderBtn: "Copy order", copiedTxt: "Copied",
      fastestIn: "fastest", itemU: "items", supU: "suppliers", ctnU: "ctn", alreadyOut: "out",
      mRaise: "Raise price", mRaiseSub: "below target",
      mLower: "Lower price", mLowerSub: "over the cap",
      mNoCost: "No cost", mNoCostSub: "margin can't be computed",
      mOk: "On target", mOkSub: "nothing to do", mMuted: "Snoozed",
      targetIs: "target", pctLow: "low by", pctHigh: "high by", pointsU: "pts",
      closeEnough: "close enough", notNow: "Not now", restoreBtn: "Restore",
      costIs: "cost", suggestNote: "Suggested price = cost × (1 + target%). Lowering cost is the other route.",
      backWhen: "comes back when margin moves over", pointsBack: "pts",
      needTable: "Snoozing needs the margin_snooze table — not created yet.",
      thresholdLb: "Comes back after a move of",
      allMutedTxt: "All snoozed", noneMuted: "Nothing snoozed yet",
      catFinished: "Finished / semi", catBuy: "Resold raw", catPkg: "Packaging", catDcs: "Consumables",
      resolvedBtn: "Resolved", reasonTitle: "Add a short reason", reasonPh: "e.g. sourced locally",
      cancelBtn: "Cancel", confirmClose: "Confirm",
      selfMade: "in-house", saveFail: "Save failed, retry",
    },
    zh: {
      toProcess: "项今天要处理", nothingToday: "今天没事",
      secOut: "已经断了", secOutSub: "理论库存 ≤ 0",
      secSoon: "快断了", secSoonSub: "撑不到下次盘点",
      secOrder: "今天要订", secMargin: "毛利检查", secExc: "其他异常",
      gMake: "今天做", gMakeSub: "CK 自己产",
      gBuy: "今天买", gBuySub: "跑一趟就有",
      gWait: "只能等", gWaitSub: "最快 8 天到",
      gWatch: "盯着", gOrder: "今天订", gOrderSub: "底边越长越该下单",
      lgBroke: "已经断了", lgWait: "到货还要等",
      brokeD: "断", waitD: "等", dayU: "天", dailyUse: "日用",
      canLast: "还能撑", countIn: "盘点还有",
      expandDetail: "展开明细", copyOrderBtn: "复制订单", copiedTxt: "已复制",
      fastestIn: "最快", itemU: "项", supU: "家", ctnU: "ctn", alreadyOut: "项已断",
      mRaise: "调高售价", mRaiseSub: "低于目标",
      mLower: "调低售价", mLowerSub: "超出上限",
      mNoCost: "缺成本", mNoCostSub: "算不出 margin",
      mOk: "达标", mOkSub: "不用管", mMuted: "已忽略",
      targetIs: "目标", pctLow: "低", pctHigh: "高", pointsU: "个点",
      closeEnough: "差不多了", notNow: "先不管", restoreBtn: "恢复",
      costIs: "成本", suggestNote: "建议价 ＝ 成本 × (1 + 目标%)。另一条路是降成本。",
      backWhen: "margin 动超过", pointsBack: "个点才回来",
      needTable: "忽略功能要先建 margin_snooze 表 — 还没建。",
      thresholdLb: "动多少才回来",
      allMutedTxt: "全部先不管了", noneMuted: "还没有忽略任何一项",
      catFinished: "成品 / 半成品", catBuy: "代购原料", catPkg: "包装", catDcs: "耗材",
      resolvedBtn: "已解决", reasonTitle: "写一句原因，以后回头看得懂",
      reasonPh: "例：已本地应急采购", cancelBtn: "取消", confirmClose: "确认关闭",
      selfMade: "自制", saveFail: "保存失败，重试",
    },
  };
  Object.keys(add).forEach(function (l) { Object.assign(FB.STRINGS[l], add[l]); });
})();
