(function () {
  "use strict";

  const option = (id, label) => ({ id, label });
  const options = labels => labels.map((label, index) => option(String(index + 1), label));
  const single = (id, label, values, required = true) => ({ id, label, type: "single", required, options: options(values) });
  const multi = (id, label, values, required = false) => ({ id, label, type: "multi", required, options: options(values) });

  const commonServiceGroups = [
    multi("proofing", "打样与留样", ["数码打样", "白样确认", "翻单跟样", "客户自带样", "车间留样", "上机拍照确认"]),
    multi("delivery_service", "交付增值服务", ["拍成品照", "分款包装", "贴箱唛", "独立装袋", "代发客户", "质检报告"])
  ];

  const profiles = {
    paper_flat: {
      label: "纸张单页类",
      groups: [
        single("material", "材料", ["80g双胶纸", "105g铜版纸", "128g铜版纸", "157g铜版纸", "200g铜版纸", "250g铜版纸", "300g铜版纸", "250g白卡", "300g白卡", "350g白卡", "牛皮纸", "珠光纸", "特种纸"]),
        single("size", "成品尺寸（mm）", ["90×54", "100×100", "148×210", "210×285", "210×297", "285×420", "420×570", "自定义尺寸"]),
        single("print_side", "印刷面", ["单面", "双面"]),
        single("print_color", "印刷颜色", ["单黑", "四色彩印", "专色", "四色+专色"]),
        single("ink_coverage", "油墨覆盖", ["普通图文", "大面积深色", "满版实地", "自定义印刷要求"]),
        multi("required_process", "基础工艺", ["覆亮膜", "覆哑膜", "折页", "压线", "模切", "圆角", "打孔", "骑缝线"]),
        multi("finish_process", "精品工艺", ["烫金", "烫银", "局部UV", "击凸", "压凹", "压纹", "磨砂", "逆向UV"]),
        ...commonServiceGroups
      ],
      quantityPresets: [100, 200, 500, 1000, 2000, 5000, 10000]
    },
    card: {
      label: "卡片卡券类",
      groups: [
        single("material", "材料", ["250g铜版纸", "300g铜版纸", "350g铜版纸", "250g白卡", "300g白卡", "350g白卡", "荷兰白卡", "黑卡", "PVC", "透明PET", "特种纸"]),
        single("size", "成品尺寸（mm）", ["90×54", "85×54", "90×90", "100×70", "140×70", "148×100", "自定义尺寸"]),
        single("print_side", "印刷面", ["单面", "双面"]),
        single("print_color", "印刷颜色", ["单黑", "四色彩印", "专色", "四色+专色"]),
        multi("card_process", "卡片工艺", ["覆亮膜", "覆哑膜", "圆角", "打孔", "压痕", "可变数据", "签名条", "磁条"]),
        multi("finish_process", "精品工艺", ["烫金", "烫银", "局部UV", "击凸", "压凹", "镂空", "压纹"]),
        ...commonServiceGroups
      ],
      quantityPresets: [100, 200, 500, 1000, 2000, 5000]
    },
    book: {
      label: "书刊装订类",
      groups: [
        single("cover_material", "封面材料", ["200g铜版纸", "250g铜版纸", "300g铜版纸", "250g白卡", "300g白卡", "特种纸", "裱灰板"]),
        single("inner_material", "内页材料", ["70g双胶纸", "80g双胶纸", "100g双胶纸", "105g铜版纸", "128g铜版纸", "157g铜版纸", "100g轻型纸"]),
        single("size", "成品尺寸（mm）", ["130×185", "140×210", "185×260", "210×285", "210×297", "285×285", "自定义尺寸"]),
        single("page_count", "内页页数", ["8P", "12P", "16P", "20P", "24P", "32P", "48P", "64P", "自定义页数"]),
        single("print_color", "封面/内页印刷", ["单黑", "四色彩印", "专色", "四色+专色"]),
        single("binding", "装订方式", ["骑马钉", "无线胶装", "锁线胶装", "精装", "蝴蝶装", "活页装", "线圈装"]),
        multi("cover_process", "封面工艺", ["覆亮膜", "覆哑膜", "烫金", "烫银", "局部UV", "击凸", "压凹", "压纹", "模切"]),
        ...commonServiceGroups
      ],
      quantityPresets: [50, 100, 200, 500, 1000, 2000, 5000]
    },
    label: {
      label: "标签不干胶类",
      groups: [
        single("material", "面材", ["铜版纸不干胶", "书写纸不干胶", "牛皮纸不干胶", "透明PET", "哑银PET", "亮银PET", "合成纸", "珠光膜", "易碎纸", "热敏纸", "可移胶"]),
        single("size", "标签尺寸（mm）", ["20×20", "30×30", "40×30", "50×30", "50×50", "60×40", "80×50", "100×70", "自定义尺寸"]),
        single("delivery_form", "交付形式", ["单张", "卷筒", "折叠联", "模切散张"]),
        single("print_color", "印刷颜色", ["单黑", "四色彩印", "专色", "四色+白墨", "不印刷"]),
        multi("label_process", "标签工艺", ["覆亮膜", "覆哑膜", "上光油", "烫金", "烫银", "局部UV", "击凸", "流水号", "可变二维码", "排废"]),
        single("core_direction", "卷筒参数", ["无需卷筒", "内径25mm", "内径40mm", "内径76mm", "出标方向待确认"], false),
        ...commonServiceGroups
      ],
      quantityPresets: [500, 1000, 2000, 5000, 10000, 20000, 50000]
    },
    paper_box: {
      label: "彩盒精品盒类",
      groups: [
        single("material", "面纸/纸板", ["250g白卡", "300g白卡", "350g白卡", "400g白卡", "金银卡", "牛皮卡", "特种纸", "灰板裱纸", "微瓦楞裱纸"]),
        single("size", "成品尺寸（mm）", ["100×80×30", "150×100×40", "200×150×60", "250×180×80", "300×200×100", "360×260×80", "自定义尺寸"]),
        single("box_structure", "盒型结构", ["插口盒", "扣底盒", "天地盖", "抽屉盒", "书型盒", "飞机盒", "异型盒", "按刀线图"]),
        single("print_color", "印刷颜色/方式", ["四色彩印", "单黑", "专色", "四色+专色", "不印刷"]),
        single("ink_coverage", "油墨覆盖", ["普通图文", "大面积深色", "满版实地", "自定义印刷要求"]),
        multi("required_process", "必选工艺", ["覆亮膜", "覆哑膜", "过油", "模切", "压线", "糊盒", "裱卡", "裱瓦楞"], true),
        multi("finish_process", "精品工艺", ["烫金", "烫银", "局部UV", "击凸", "压凹", "浮雕烫", "压纹", "镂空", "贴窗"]),
        multi("insert_process", "内托与组装", ["纸卡内托", "吸塑内托", "EVA内托", "海绵内托", "丝带", "磁铁", "手工组装"]),
        ...commonServiceGroups
      ],
      quantityPresets: [100, 200, 500, 1000, 2000, 3000, 5000, 10000]
    },
    paper_bag: {
      label: "手提纸袋类",
      groups: [
        single("material", "材料", ["210g白卡", "250g白卡", "300g白卡", "牛皮纸", "金银卡", "特种纸"]),
        single("size", "成品尺寸（mm）", ["180×230×80", "220×280×100", "260×360×80", "300×400×90", "300×400×100", "360×260×80", "自定义尺寸"]),
        single("print_color", "印刷颜色/方式", ["四色彩印", "单黑", "专色", "四色+专色", "不印刷"]),
        single("ink_coverage", "油墨覆盖", ["普通图文", "大面积深色", "满版实地", "自定义印刷要求"]),
        multi("required_process", "必选工艺", ["单面覆亮膜", "单面覆哑膜", "提口留白", "模切", "压线", "糊袋"], true),
        single("handle", "提绳方式", ["棉绳", "三股绳", "丝带", "人字带", "纸绳", "打孔不要绳", "自备绳"]),
        single("handle_color", "提绳颜色", ["黑色", "白色", "红色", "金色", "同印刷色", "自定义颜色"], false),
        multi("hole_process", "打孔/穿绳", ["普通打孔", "打气眼", "铆钉", "自动穿绳", "手工穿绳"]),
        multi("finish_process", "精品工艺", ["烫金", "烫银", "局部UV", "击凸", "压凹", "浮雕烫", "压纹"]),
        ...commonServiceGroups
      ],
      quantityPresets: [100, 200, 500, 1000, 2000, 3000, 5000]
    },
    corrugated: {
      label: "瓦楞纸箱类",
      groups: [
        single("material", "楞型与材质", ["三层B楞", "三层E楞", "五层BC楞", "五层BE楞", "牛卡纸", "白面牛卡", "高强瓦楞"]),
        single("size", "内尺寸（mm）", ["200×150×100", "300×200×150", "400×300×200", "500×400×300", "600×400×400", "自定义尺寸"]),
        single("box_structure", "箱型", ["0201普通箱", "飞机盒", "天地盖箱", "邮政箱", "展示箱", "异型箱", "按刀线图"]),
        single("print_color", "印刷颜色", ["不印刷", "单色", "双色", "三色", "四色彩印裱面"]),
        multi("box_process", "纸箱工艺", ["开槽", "模切", "打钉", "粘箱", "提手孔", "透气孔", "防水处理", "护角"]),
        ...commonServiceGroups
      ],
      quantityPresets: [50, 100, 200, 500, 1000, 2000, 5000]
    },
    office: {
      label: "办公票据类",
      groups: [
        single("material", "材料", ["70g双胶纸", "80g双胶纸", "100g双胶纸", "无碳复写纸", "牛皮纸", "白卡", "PVC"]),
        single("size", "成品尺寸（mm）", ["90×54", "100×210", "140×210", "210×285", "210×297", "297×420", "自定义尺寸"]),
        single("copy_count", "联数/页数", ["单联", "二联", "三联", "四联", "五联", "自定义"]),
        single("print_color", "印刷颜色/方式", ["单色", "四色彩印", "专色", "不印刷"]),
        multi("office_process", "办公工艺", ["胶头", "打码", "流水号", "撕线", "打孔", "包本", "裱壳", "插袋", "烫金"]),
        ...commonServiceGroups
      ],
      quantityPresets: [50, 100, 200, 500, 1000, 2000, 5000]
    },
    office_folder: {
      label: "信封档案类",
      groups: [
        single("material", "材料", ["80g双胶纸", "100g双胶纸", "120g牛皮纸", "150g牛皮纸", "200g双胶纸", "250g白卡", "300g白卡", "PP塑料"]),
        single("size", "成品尺寸（mm）", ["110×220", "120×230", "176×125", "229×162", "230×330", "240×340", "310×220", "自定义尺寸"]),
        single("structure", "产品结构", ["中式信封", "西式信封", "档案袋", "文件夹", "插页袋", "按刀线图"]),
        single("print_color", "印刷颜色", ["不印刷", "单色", "双色", "四色彩印", "专色"]),
        multi("folder_process", "加工工艺", ["粘口", "窗口", "插舌", "绳扣", "鸡眼扣", "压线", "模切", "覆膜", "烫金", "流水号"]),
        ...commonServiceGroups
      ],
      quantityPresets: [100, 200, 500, 1000, 2000, 5000, 10000]
    },
    hang_tag: {
      label: "吊牌挂牌类",
      groups: [
        single("material", "材料", ["250g铜版纸", "300g铜版纸", "350g白卡", "黑卡", "牛皮卡", "特种纸", "PVC", "织唛"]),
        single("size", "成品尺寸（mm）", ["30×50", "40×70", "50×90", "54×90", "60×100", "自定义尺寸"]),
        single("shape", "外形", ["方形", "圆角", "圆形", "异形模切", "按刀线图"]),
        single("print_side", "印刷面", ["单面", "双面"]),
        single("print_color", "印刷颜色", ["单色", "四色彩印", "专色", "四色+专色"]),
        multi("hangtag_process", "吊牌工艺", ["覆亮膜", "覆哑膜", "烫金", "烫银", "局部UV", "击凸", "压凹", "打孔", "穿绳", "装别针", "可变条码"]),
        ...commonServiceGroups
      ],
      quantityPresets: [100, 200, 500, 1000, 2000, 5000, 10000]
    },
    instruction: {
      label: "折页说明书类",
      groups: [
        single("material", "材料", ["60g双胶纸", "70g双胶纸", "80g双胶纸", "100g双胶纸", "105g铜版纸", "128g铜版纸", "157g铜版纸"]),
        single("size", "成品尺寸（mm）", ["70×100", "90×120", "100×140", "105×148", "140×210", "210×285", "自定义尺寸"]),
        single("page_count", "页数/折数", ["单张", "二折", "三折", "4P", "8P", "12P", "16P", "自定义页数"]),
        single("binding", "折装方式", ["压线折页", "风琴折", "关门折", "骑马钉", "胶装", "散页"]),
        single("print_color", "印刷颜色", ["单黑", "双色", "四色彩印", "专色"]),
        multi("instruction_process", "后道工艺", ["折页", "骑马钉", "胶装", "模切", "打孔", "覆膜", "可变码"]),
        ...commonServiceGroups
      ],
      quantityPresets: [100, 200, 500, 1000, 2000, 5000, 10000]
    },
    calendar: {
      label: "台历日历类",
      groups: [
        single("material", "内页材料", ["128g铜版纸", "157g铜版纸", "200g铜版纸", "200g哑粉纸", "250g铜版纸", "特种纸"]),
        single("size", "成品尺寸（mm）", ["140×210", "210×140", "210×285", "285×210", "370×520", "自定义尺寸"]),
        single("page_count", "张数", ["7张", "13张", "14张", "25张", "32张", "自定义"]),
        single("binding", "装订/结构", ["双线圈台历", "单线圈挂历", "撕历", "卡片式", "活页式"]),
        single("print_color", "印刷颜色/方式", ["四色彩印", "单色", "专色", "四色+专色", "不印刷"]),
        multi("calendar_process", "配套工艺", ["台历架", "打孔", "穿绳", "金属挂钩", "覆膜", "烫金", "局部UV"]),
        ...commonServiceGroups
      ],
      quantityPresets: [50, 100, 200, 500, 1000, 2000]
    },
    display: {
      label: "广告展示类",
      groups: [
        single("material", "展示材料", ["PP背胶", "相纸", "车贴", "灯片", "油画布", "KT板", "PVC板", "亚克力板", "喷绘布", "刀刮布", "网格布", "反光膜"]),
        single("size", "成品尺寸（mm）", ["420×570", "600×900", "800×1200", "900×1200", "1000×2000", "1200×2400", "自定义尺寸"]),
        single("print_mode", "输出方式", ["户内写真", "户外写真", "UV卷材", "UV平板", "高清喷绘", "热转印"]),
        multi("display_process", "后道工艺", ["覆亮膜", "覆哑膜", "裁切", "裱板", "包边", "打孔", "穿绳", "装支架", "异形雕刻"]),
        ...commonServiceGroups
      ],
      quantityPresets: [1, 2, 5, 10, 20, 50, 100]
    },
    textile: {
      label: "布袋服装类",
      groups: [
        single("material", "面料", ["80g无纺布", "100g无纺布", "8安帆布", "10安帆布", "12安帆布", "涤纶布", "纯棉面料", "牛津布", "色丁布"]),
        single("size", "成品尺寸（mm）", ["250×300", "300×350", "350×400", "380×420", "400×450", "自定义尺寸"]),
        single("print_mode", "图案工艺", ["单色丝印", "多色丝印", "热转印", "数码直喷", "刺绣", "不印刷"]),
        multi("sewing_process", "车缝结构", ["平口", "有底有侧", "车提手", "冲孔提手", "加拉链", "加内袋", "包边", "锁边"]),
        multi("textile_service", "服装/布艺服务", ["分尺码", "分颜色", "水洗标", "领标", "吊牌", "独立包装", "色牢度测试"]),
        ...commonServiceGroups
      ],
      quantityPresets: [100, 200, 500, 1000, 2000, 5000, 10000]
    },
    plastic: {
      label: "塑料软包装类",
      groups: [
        single("material", "材料", ["PE", "PO", "PP", "OPP", "CPP", "PET/PE复合", "PA/PE复合", "镀铝复合", "食品级复合膜"]),
        single("size", "成品尺寸（mm）", ["100×150", "150×200", "180×260", "200×300", "250×350", "300×400", "自定义尺寸"]),
        single("bag_structure", "袋型", ["平口袋", "自封袋", "三边封", "中封袋", "自立袋", "八边封", "真空袋", "卷膜"]),
        single("thickness", "厚度", ["单面3丝", "单面5丝", "单面8丝", "双面10丝", "双面12丝", "自定义厚度"]),
        single("print_color", "印刷颜色", ["不印刷", "单色", "双色", "四色", "六色", "八色"]),
        multi("plastic_process", "制袋工艺", ["打孔", "易撕口", "拉链", "单向排气阀", "圆角", "局部哑光", "铝箔", "防雾"]),
        ...commonServiceGroups
      ],
      quantityPresets: [1000, 2000, 5000, 10000, 20000, 50000]
    },
    gift: {
      label: "文创礼品类",
      groups: [
        single("material", "主体材料", ["亚克力", "PVC", "马口铁", "木材", "竹材", "陶瓷", "玻璃", "不锈钢", "硅胶", "织物"]),
        single("size", "成品尺寸（mm）", ["30×30", "50×50", "70×70", "100×100", "150×150", "自定义尺寸"]),
        single("logo_process", "Logo工艺", ["丝印", "UV彩印", "激光雕刻", "热转印", "滴胶", "冲压", "不做Logo"]),
        multi("gift_process", "成品工艺", ["异形切割", "抛光", "打孔", "装扣件", "滴胶", "喷漆", "电镀", "手工组装"]),
        multi("gift_packaging", "礼品包装", ["OPP袋", "吸塑盒", "白盒", "彩盒", "礼盒", "说明卡", "条码贴"]),
        ...commonServiceGroups
      ],
      quantityPresets: [50, 100, 200, 500, 1000, 2000, 5000]
    },
    industrial: {
      label: "工业定制类",
      groups: [
        single("material", "材料", ["不锈钢", "铝材", "镀锌板", "冷轧板", "锌合金", "亚克力", "PC", "ABS", "硅胶", "木材"]),
        single("size", "成品尺寸（mm）", ["50×30", "80×50", "100×100", "200×150", "300×200", "自定义尺寸"]),
        single("drawing", "图纸/样品", ["有2D图纸", "有3D图纸", "有实物样品", "只有图片", "需要协助设计"]),
        multi("forming_process", "成型加工", ["激光切割", "冲压", "折弯", "CNC", "注塑", "硫化", "雕刻", "焊接", "组装"]),
        multi("surface_process", "表面处理", ["拉丝", "喷砂", "阳极氧化", "电镀", "烤漆", "喷粉", "丝印", "激光打标"]),
        single("tolerance", "公差要求", ["普通商业公差", "±0.5mm", "±0.2mm", "±0.1mm", "按图纸"]),
        ...commonServiceGroups
      ],
      quantityPresets: [10, 50, 100, 200, 500, 1000, 5000]
    },
    wood_box: {
      label: "木盒木制品类",
      groups: [
        single("material", "木材/板材", ["实木", "松木", "榉木", "橡胶木", "橡木", "胡桃木", "桐木", "竹材", "密度板贴木皮", "多层夹板", "自定义材料"]),
        single("size", "成品尺寸（mm）", ["100×100×50", "150×100×60", "180×120×70", "200×150×80", "250×180×100", "300×200×120", "自定义尺寸"]),
        single("box_structure", "盒型结构", ["天地盖", "翻盖盒", "抽屉盒", "书型盒", "卡扣盒", "带合页木盒", "异型盒", "按图纸/样品"]),
        single("surface_process", "表面处理", ["原木打磨", "清漆", "木蜡油", "喷漆", "染色", "烤漆", "仿古做旧", "不上漆"]),
        single("logo_process", "Logo/图文工艺", ["激光雕刻", "丝网印刷", "UV彩印", "烫金", "烫银", "热转印", "金属铭牌", "不做Logo"]),
        multi("insert_process", "内托与配件", ["EVA内托", "海绵内托", "植绒内托", "纸卡内托", "丝带", "磁铁", "合页", "五金锁扣", "手工组装"]),
        ...commonServiceGroups
      ],
      quantityPresets: [10, 50, 100, 200, 500, 1000, 2000]
    },
    custom_generic: {
      label: "本厂自定义产品",
      groups: [
        single("material", "材料", ["客户供料", "本厂常用材料", "通用材料", "自定义材料"]),
        single("size", "成品尺寸（mm）", ["按现有规格", "按客户样品", "按图纸", "自定义尺寸"]),
        single("specification", "规格依据", ["客户文字要求", "客户图片", "实物样品", "2D图纸", "3D图纸", "本厂常规规格"]),
        multi("required_process", "加工工艺", ["无需加工/仅供货", "印刷", "裁切", "覆膜", "模切", "雕刻", "表面处理", "组装", "独立包装", "自定义工艺"], true),
        ...commonServiceGroups
      ],
      quantityPresets: [10, 50, 100, 200, 500, 1000, 2000, 5000]
    },
    electronic: {
      label: "电子配件类",
      groups: [
        single("material", "主体/BOM", ["客户供料", "厂家代采BOM", "塑胶外壳", "金属外壳", "硅胶件", "线材组件"]),
        single("size", "外形尺寸（mm）", ["30×20×10", "50×30×15", "100×60×20", "150×100×30", "自定义尺寸"]),
        single("drawing", "资料完整度", ["BOM+Gerber齐全", "有BOM无Gerber", "有样品", "只有功能描述", "需要协助设计"]),
        multi("assembly_process", "装配工艺", ["SMT", "DIP", "手工焊接", "线束压接", "整机组装", "灌胶", "丝印Logo"]),
        multi("test_process", "测试要求", ["通电测试", "功能测试", "老化测试", "耐压测试", "安规测试", "抽检", "全检"]),
        multi("certification", "认证与包装", ["RoHS", "CE", "FCC", "说明书", "序列号", "独立包装", "防静电包装"]),
        ...commonServiceGroups
      ],
      quantityPresets: [10, 50, 100, 200, 500, 1000, 5000]
    }
  };

  const categoryDefinitions = [
    ["business_cards", "名片卡片", "名片、会员卡、门票、卡券", [["标准名片", "card"], ["特种纸名片", "card"], ["烫金名片", "card"], ["PVC名片", "card"], ["异形卡", "card"], ["会员卡", "card"], ["门票", "card"], ["优惠券", "card"], ["刮刮卡", "card"]]],
    ["flyers", "单张折页", "宣传单、海报、折页、菜单", [["宣传单", "paper_flat"], ["海报", "paper_flat"], ["二折页", "paper_flat"], ["三折页", "paper_flat"], ["四折页", "paper_flat"], ["腰封", "paper_flat"], ["插页", "paper_flat"], ["产品单页", "paper_flat"], ["招生简章", "paper_flat"]]],
    ["books", "书籍画册", "画册、说明书、书刊、本册", [["企业画册", "book"], ["产品目录", "book"], ["骑马钉画册", "book"], ["胶装书", "book"], ["精装书", "book"], ["说明书", "book"], ["菜谱", "book"], ["培训手册", "book"], ["笔记本", "book"], ["纪念册", "book"]]],
    ["labels", "标签不干胶", "纸质、膜类、卷筒及防伪标签", [["铜版纸标签", "label"], ["书写纸标签", "label"], ["牛皮纸标签", "label"], ["透明标签", "label"], ["哑银标签", "label"], ["合成纸标签", "label"], ["热敏标签", "label"], ["易碎标签", "label"], ["封口贴", "label"], ["卷筒标签", "label"], ["可变码标签", "label"]]],
    ["boxes", "包装彩盒", "卡盒、礼盒、套盒及内托", [["插口彩盒", "paper_box"], ["扣底彩盒", "paper_box"], ["天地盖礼盒", "paper_box"], ["抽屉盒", "paper_box"], ["书型礼盒", "paper_box"], ["飞机盒", "paper_box"], ["卡套盒", "paper_box"], ["食品包装盒", "paper_box"], ["化妆品盒", "paper_box"], ["电子产品盒", "paper_box"], ["异形包装盒", "paper_box"]]],
    ["paper_bags", "手提纸袋", "购物袋、礼品袋、外卖纸袋", [["白卡手提袋", "paper_bag"], ["牛皮纸袋", "paper_bag"], ["特种纸礼品袋", "paper_bag"], ["服装购物袋", "paper_bag"], ["餐饮外卖袋", "paper_bag"], ["酒水礼品袋", "paper_bag"], ["珠宝首饰袋", "paper_bag"], ["异形纸袋", "paper_bag"]]],
    ["corrugated", "纸箱瓦楞", "运输箱、邮政箱、展示箱", [["三层纸箱", "corrugated"], ["五层纸箱", "corrugated"], ["飞机纸箱", "corrugated"], ["邮政箱", "corrugated"], ["电商快递箱", "corrugated"], ["彩印瓦楞箱", "corrugated"], ["展示箱", "corrugated"], ["异形纸箱", "corrugated"]]],
    ["office", "办公票据", "信封、表单、档案与证卡", [["信封", "office_folder"], ["信纸", "paper_flat"], ["无碳联单", "office"], ["收据本", "office"], ["档案袋", "office_folder"], ["文件夹", "office_folder"], ["工作证", "card"], ["证书", "paper_flat"], ["便签本", "office"]]],
    ["calendar", "台历日历", "台历、挂历、日程与周边", [["横版台历", "calendar"], ["竖版台历", "calendar"], ["挂历", "calendar"], ["撕历", "calendar"], ["日程本", "book"], ["桌面计划卡", "card"], ["年历海报", "paper_flat"], ["台历礼盒套装", "calendar"]]],
    ["display", "广告展示", "展架、板材、灯箱及标识", [["易拉宝", "display"], ["X展架", "display"], ["门型展架", "display"], ["KT板", "display"], ["PVC展板", "display"], ["亚克力展板", "display"], ["灯箱片", "display"], ["车贴", "display"], ["地贴", "display"], ["标识标牌", "display"]]],
    ["photo", "写真喷绘", "喷绘布、旗帜、油画布及写真", [["户内写真", "display"], ["户外写真", "display"], ["喷绘布", "display"], ["刀刮布", "display"], ["网格布", "display"], ["油画布", "display"], ["旗帜条幅", "display"], ["反光喷绘", "display"], ["双喷布", "display"], ["墙贴壁画", "display"]]],
    ["food", "餐饮印品", "菜单、餐垫、杯套及食品包装", [["折页菜单", "paper_flat"], ["胶装菜单", "book"], ["餐垫纸", "paper_flat"], ["杯套", "paper_box"], ["汉堡盒", "paper_box"], ["炸鸡盒", "paper_box"], ["蛋糕盒", "paper_box"], ["外卖纸袋", "paper_bag"], ["食品标签", "label"]]],
    ["textile", "布袋服装", "无纺布袋、帆布袋及服装辅料", [["无纺布袋", "textile"], ["帆布袋", "textile"], ["棉布袋", "textile"], ["束口袋", "textile"], ["牛津布袋", "textile"], ["T恤", "textile"], ["工作服", "textile"], ["帽子", "textile"], ["服装吊牌套装", "hang_tag"]]],
    ["plastic", "塑料软包装", "塑料袋、复合袋、卷膜", [["PE平口袋", "plastic"], ["OPP自粘袋", "plastic"], ["自封袋", "plastic"], ["三边封袋", "plastic"], ["自立拉链袋", "plastic"], ["八边封袋", "plastic"], ["真空袋", "plastic"], ["快递袋", "plastic"], ["食品复合袋", "plastic"], ["包装卷膜", "plastic"]]],
    ["creative", "文创礼品", "徽章、立牌、钥匙扣与日用礼品", [["亚克力立牌", "gift"], ["亚克力钥匙扣", "gift"], ["马口铁徽章", "gift"], ["冰箱贴", "gift"], ["杯垫", "gift"], ["鼠标垫", "gift"], ["保温杯", "gift"], ["帆布周边", "textile"], ["木质礼品", "gift"], ["硅胶礼品", "gift"]]],
    ["industrial", "工业定制", "铭牌、钣金、塑胶及结构件", [["金属铭牌", "industrial"], ["设备标牌", "industrial"], ["钣金外壳", "industrial"], ["冲压件", "industrial"], ["亚克力展示架", "industrial"], ["注塑件", "industrial"], ["硅胶件", "industrial"], ["木制展示架", "industrial"], ["金属徽章", "industrial"], ["定制结构件", "industrial"]]],
    ["electronics", "电子配件", "线材、PCBA、小家电与配套包装", [["数据线", "electronic"], ["线束组件", "electronic"], ["PCBA加工", "electronic"], ["电子模块", "electronic"], ["小家电组装", "electronic"], ["塑胶外壳", "electronic"], ["电子说明书套装", "instruction"], ["电子产品包装套装", "paper_box"]]],
    ["ready_stock", "通版现货", "常用规格快速选择后按本厂库存核价", [["通版名片", "card"], ["通版宣传单", "paper_flat"], ["通版折页", "paper_flat"], ["通版画册", "book"], ["通版标签", "label"], ["通版手提袋", "paper_bag"], ["通版台历", "calendar"]]]
  ];

  const productAliasOverrides = Object.freeze({
    "插口彩盒": ["双插盒", "反插盒", "双插彩盒", "上下插盒", "插舌盒", "反插口盒"],
    "扣底彩盒": ["自动扣底盒", "锁底盒", "勾底盒"],
    "天地盖礼盒": ["天地盒", "上下盖盒"],
    "抽屉盒": ["抽拉盒", "火柴盒"],
    "书型礼盒": ["翻盖书型盒", "书本盒"],
    "飞机盒": ["邮寄盒", "披萨盒"]
  });

  const categories = categoryDefinitions.map(([id, name, description, products]) => ({
    id,
    name,
    description,
    products: products.map(([productName, profile], index) => ({
      id: `${id}-${String(index + 1).padStart(2, "0")}`,
      name: productName,
      profile,
      aliases: [
        productName.replace(/[（）()]/g, ""),
        productName.replace(/通版/g, ""),
        ...(productAliasOverrides[productName] || [])
      ].filter(Boolean)
    }))
  }));

  const labelProductRecommendations = Object.freeze({
    "铜版纸标签": { material: "铜版纸不干胶", delivery_form: "单张", print_color: "四色彩印", core_direction: "无需卷筒" },
    "书写纸标签": { material: "书写纸不干胶", delivery_form: "单张", print_color: "四色彩印", core_direction: "无需卷筒" },
    "牛皮纸标签": { material: "牛皮纸不干胶", delivery_form: "单张", print_color: "单黑", core_direction: "无需卷筒" },
    "透明标签": { material: "透明PET", delivery_form: "单张", print_color: "四色+白墨", core_direction: "无需卷筒" },
    "哑银标签": { material: "哑银PET", delivery_form: "单张", print_color: "四色+白墨", core_direction: "无需卷筒" },
    "合成纸标签": { material: "合成纸", delivery_form: "单张", print_color: "四色彩印", core_direction: "无需卷筒" },
    "热敏标签": { material: "热敏纸", delivery_form: "卷筒", print_color: "不印刷", core_direction: "出标方向待确认" },
    "易碎标签": { material: "易碎纸", delivery_form: "单张", print_color: "单黑", core_direction: "无需卷筒" },
    "封口贴": { material: "铜版纸不干胶", delivery_form: "模切散张", print_color: "四色彩印", core_direction: "无需卷筒" },
    "卷筒标签": { material: "铜版纸不干胶", delivery_form: "卷筒", print_color: "四色彩印", core_direction: "出标方向待确认" },
    "可变码标签": { material: "铜版纸不干胶", delivery_form: "卷筒", print_color: "单黑", core_direction: "出标方向待确认" },
    "食品标签": { material: "铜版纸不干胶", delivery_form: "卷筒", print_color: "四色彩印", core_direction: "出标方向待确认" },
    "通版标签": { material: "铜版纸不干胶", delivery_form: "单张", print_color: "四色彩印", core_direction: "无需卷筒" }
  });

  const paperBoxProductRecommendations = Object.freeze({
    "插口彩盒": { box_structure: "插口盒" },
    "扣底彩盒": { box_structure: "扣底盒" },
    "天地盖礼盒": { box_structure: "天地盖" },
    "抽屉盒": { box_structure: "抽屉盒" },
    "书型礼盒": { box_structure: "书型盒" },
    "飞机盒": { box_structure: "飞机盒" },
    "卡套盒": { box_structure: "插口盒" },
    "食品包装盒": { box_structure: "插口盒" },
    "化妆品盒": { box_structure: "插口盒" },
    "电子产品盒": { box_structure: "插口盒" },
    "异形包装盒": { box_structure: "按刀线图" },
    "杯套": { box_structure: "按刀线图" },
    "汉堡盒": { box_structure: "飞机盒" },
    "炸鸡盒": { box_structure: "飞机盒" },
    "蛋糕盒": { box_structure: "飞机盒" },
    "电子产品包装套装": { box_structure: "插口盒" }
  });

  function applyProductRecommendations({ product, profile, draft }) {
    if (!product || !profile || !draft) return draft;
    const recommendation = product.profile === "label"
      ? labelProductRecommendations[product.name] || {
        material: "铜版纸不干胶",
        delivery_form: "单张",
        print_color: "四色彩印",
        core_direction: "无需卷筒"
      }
      : product.profile === "paper_box"
        ? { print_color: "四色彩印", ...(paperBoxProductRecommendations[product.name] || { box_structure: "插口盒" }) }
        : product.profile === "paper_bag"
          ? { print_color: "四色彩印" }
          : product.profile === "office"
            ? { print_color: "单色" }
            : product.profile === "calendar"
              ? { print_color: "四色彩印" }
              : null;
    if (!recommendation) return draft;
    Object.entries(recommendation).forEach(([groupId, optionLabel]) => {
      if (draft.selections[groupId] && !(product.profile === "paper_box" && groupId === "box_structure")) return;
      const group = profile.groups.find(item => item.id === groupId);
      const selected = group?.options.find(item => item.label === optionLabel);
      if (selected) draft.selections[groupId] = selected.id;
    });
    return draft;
  }

  window.JIANGLAI_QUOTE_RECOMMENDER = Object.freeze({
    apply: applyProductRecommendations,
    labelRecommendations: labelProductRecommendations,
    paperBoxRecommendations: paperBoxProductRecommendations
  });

  window.QUOTE_PRODUCT_CATALOG = Object.freeze({
    schemaVersion: 2,
    catalogVersion: "2026.08.01.396",
    categories,
    profiles
  });
})();
