@edutalk/promo-tool 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,51 +1,351 @@
1
1
  import { createElementBlock as e, defineComponent as t, onBeforeUnmount as n, onMounted as r, openBlock as i, ref as a, watch as o } from "vue";
2
- // src/engine/pricing.js
3
- var s = (e) => String(e ?? "").trim().toLowerCase(), c = (e, t) => s(e) === s(t), l = (e) => Math.round(Number(e) || 0), u = "OK";
4
- function d(e, t) {
5
- return e.settings.programs.find((e) => c(e.name, t));
2
+ // src/data/doc-defaults.js
3
+ var s = {
4
+ "IELTS Mentor|Module A|Online": {
5
+ sessions: "5 buổi",
6
+ classSize: "10-12 học viên"
7
+ },
8
+ "IELTS Mentor|Module B|Online": {
9
+ sessions: "5 buổi",
10
+ classSize: "10-12 học viên"
11
+ },
12
+ "IELTS Mentor|BS|Offline": {
13
+ sessions: "20 buổi",
14
+ classSize: "≥ 20 học viên"
15
+ },
16
+ "IELTS Mentor|BS|Online": {
17
+ sessions: "20 buổi",
18
+ classSize: "6-8 học viên"
19
+ },
20
+ "IELTS Mentor|PRE|Offline": {
21
+ sessions: "26 buổi",
22
+ classSize: "≥ 18 học viên"
23
+ },
24
+ "IELTS Mentor|PRE|Online": {
25
+ sessions: "26 buổi",
26
+ classSize: "6-8 học viên"
27
+ },
28
+ "IELTS Mentor|IE4.5|Offline": {
29
+ sessions: "26 buổi",
30
+ classSize: "≥ 18 học viên"
31
+ },
32
+ "IELTS Mentor|IE4.5|Online": {
33
+ sessions: "26 buổi",
34
+ classSize: "6-8 học viên"
35
+ },
36
+ "IELTS Mentor|IE6.5(M1)|Offline": {
37
+ sessions: "36 buổi",
38
+ classSize: "≥ 18 học viên"
39
+ },
40
+ "IELTS Mentor|IE6.5(M1)|Online": {
41
+ sessions: "36 buổi",
42
+ classSize: "6-8 học viên"
43
+ },
44
+ "IELTS Mentor|IE6.5(M2)|Offline": {
45
+ sessions: "38 buổi",
46
+ classSize: "≥ 18 học viên"
47
+ },
48
+ "IELTS Mentor|IE6.5(M2)|Online": {
49
+ sessions: "38 buổi",
50
+ classSize: "6-8 học viên"
51
+ },
52
+ "IELTS Mentor|IE7.0|Online": {
53
+ sessions: "32 buổi",
54
+ classSize: "6-8 học viên"
55
+ },
56
+ "IELTS Mentor|BT5.5|Online": {
57
+ sessions: "6 buổi",
58
+ classSize: "18-20 học viên"
59
+ },
60
+ "IELTS Mentor|Ready|Offline": {
61
+ sessions: "16 buổi",
62
+ classSize: "18-20 học viên"
63
+ },
64
+ "IELTS Mentor|Ready|Online": {
65
+ sessions: "16 buổi",
66
+ classSize: "20 - 22 học viên"
67
+ }
68
+ }, c = {
69
+ brands: [
70
+ {
71
+ label: "IELTS Mentor",
72
+ brandName: "IELTS Mentor",
73
+ bg: "#FFD602",
74
+ bg2: "#FFFFFF",
75
+ ink: "#000000",
76
+ accent: "#01518E",
77
+ neutral: "#E1DEE5",
78
+ slate: "#44525E",
79
+ gradient: "",
80
+ onMain: "",
81
+ font: "Be Vietnam Pro",
82
+ motif: "",
83
+ logoUrl: "",
84
+ logoLight: "",
85
+ footer: "Áp dụng cho toàn bộ khách hàng\nÁp dụng toàn bộ hệ thống IELTS MENTOR"
86
+ },
87
+ {
88
+ label: "CLASSUP 1-8",
89
+ brandName: "ClassUp",
90
+ bg: "#FF8B06",
91
+ bg2: "#FFFFFF",
92
+ ink: "#111960",
93
+ accent: "#111960",
94
+ neutral: "#EEEFF7",
95
+ slate: "#5C6190",
96
+ gradient: "#FFCE1C,#FB732F",
97
+ onMain: "#FFFFFF",
98
+ font: "Nunito",
99
+ motif: "wave",
100
+ logoUrl: "classup/ngang-am-ban",
101
+ logoLight: "classup/ngang-mau",
102
+ footer: "Áp dụng cho toàn bộ khách hàng\nÁp dụng toàn bộ hệ thống ClassUp"
103
+ },
104
+ {
105
+ label: "CLASSUP 1-1",
106
+ brandName: "ClassUp",
107
+ bg: "#FF8B06",
108
+ bg2: "#FFFFFF",
109
+ ink: "#111960",
110
+ accent: "#111960",
111
+ neutral: "#EEEFF7",
112
+ slate: "#5C6190",
113
+ gradient: "#FFCE1C,#FB732F",
114
+ onMain: "#FFFFFF",
115
+ font: "Nunito",
116
+ motif: "wave",
117
+ logoUrl: "classup/ngang-am-ban",
118
+ logoLight: "classup/ngang-mau",
119
+ footer: "Áp dụng cho toàn bộ khách hàng\nÁp dụng toàn bộ hệ thống ClassUp"
120
+ }
121
+ ],
122
+ services: [
123
+ {
124
+ label: "IELTS Mentor",
125
+ name: "Workshop về phương pháp học",
126
+ duration: "1 buổi",
127
+ mode: "Online",
128
+ price: 3e5
129
+ },
130
+ {
131
+ label: "IELTS Mentor",
132
+ name: "Cố vấn học tập",
133
+ duration: "1 buổi",
134
+ mode: "Online/Offline",
135
+ price: 4e5
136
+ },
137
+ {
138
+ label: "IELTS Mentor",
139
+ name: "Gia sư học tập theo năng lực cá nhân hóa",
140
+ duration: "1 buổi",
141
+ mode: "Online",
142
+ price: 2e5
143
+ },
144
+ {
145
+ label: "IELTS Mentor",
146
+ name: "Thi lại (khi không đạt đủ điều kiện học tập)",
147
+ duration: "1 buổi",
148
+ mode: "Online/Offline",
149
+ price: 1e5
150
+ },
151
+ {
152
+ label: "IELTS Mentor",
153
+ name: "Chương trình duy trì năng lực sau khóa học",
154
+ duration: "1 buổi",
155
+ mode: "Online",
156
+ price: 3e5
157
+ },
158
+ {
159
+ label: "IELTS Mentor",
160
+ name: "Thi thử online",
161
+ duration: "1 buổi",
162
+ mode: "Online",
163
+ price: 1e5
164
+ },
165
+ {
166
+ label: "IELTS Mentor",
167
+ name: "Thi thử offline",
168
+ duration: "1 buổi",
169
+ mode: "Offline",
170
+ price: 3e5
171
+ }
172
+ ],
173
+ giftSets: [
174
+ {
175
+ label: "IELTS Mentor",
176
+ value: 175e4,
177
+ items: "1 Đèn thông minh chữ G N69\n1 Loa bluetooth mini\n1 Áo mưa IELTS MENTOR"
178
+ },
179
+ {
180
+ label: "IELTS Mentor",
181
+ value: 197e4,
182
+ items: "1 Đồng hồ thông minh AMOLED HK85\n1 Tai nghe không dây ZTC Air A501\n1 Gấu bông IELTS MENTOR"
183
+ },
184
+ {
185
+ label: "IELTS Mentor",
186
+ value: 253e4,
187
+ items: "1 Đèn thông minh chữ G N69\n1 Tai nghe không dây ZTC Air A501\n1 Pin Dự Phòng USAMS 10000mAh"
188
+ },
189
+ {
190
+ label: "IELTS Mentor",
191
+ value: 326e4,
192
+ items: "1 Đèn thông minh chữ G N69\n1 Đồng hồ thông minh AMOLED HK85\n1 Tai nghe không dây ZTC Air A501"
193
+ },
194
+ {
195
+ label: "IELTS Mentor",
196
+ value: 538e4,
197
+ items: "1 Máy tính bảng IvyPad Smart 5\n1 Tai nghe không dây ZTC Air A501"
198
+ },
199
+ {
200
+ label: "IELTS Mentor",
201
+ value: 618e4,
202
+ items: "1 Máy tính bảng IvyPad Smart 5\n1 Đèn thông minh chữ G N69\n1 Bình nước IELTS MENTOR"
203
+ },
204
+ {
205
+ label: "IELTS Mentor",
206
+ value: 677e4,
207
+ items: "1 Máy tính bảng IvyPad Smart 5\n1 Đèn thông minh chữ G N69\n1 Tai nghe không dây ZTC Air A501"
208
+ }
209
+ ],
210
+ programRules: [{
211
+ label: "IELTS Mentor",
212
+ program: "Định kỳ đặc biệt",
213
+ rules: "Chương trình không áp dụng đồng thời với các chương trình khuyến mại khác trong tháng.\nChương trình chỉ áp dụng với lộ trình IELTS (không áp dụng với lộ trình Mentor English Mastery).\nQuà tặng khóa học đặc biệt áp dụng cho các khóa học đặc biệt theo danh sách có trong lộ trình khóa học khách hàng đăng ký.\nSố lượng voucher giảm học phí được áp dụng tương ứng với số khóa học đặc biệt có trong lộ trình mà khách hàng đăng ký.\nVoucher giảm học phí được trừ trực tiếp vào học phí khi đăng ký học. Áp dụng đồng thời với các mức giảm giá."
214
+ }],
215
+ docTexts: {
216
+ cashbackLabel: "Đăng ký trong 48h",
217
+ warrantyDuration: "Theo lộ trình khoá học đăng ký",
218
+ warrantyForm: "Theo dịch vụ bảo hành",
219
+ routeNote: "Bảng giá được tính dựa trên thông tin CTKM với các khoá học Offline (nếu có). Trường hợp khách hàng lựa chọn các khoá học theo hình thức Online hoặc các combo khác, TVV vui lòng tự tính giá theo CTKM hiện hành.",
220
+ citimeNote: "Với combo có các khóa Module A, Module B, BT5.5 khi xác định thời hạn trả góp không tính 3 khoá đó, chỉ xác định với các khoá còn lại đối chiếu với bảng trên. (Khoá BT5.5 có kèm khóa Ready đối chiếu thời gian với bảng trên)"
221
+ }
222
+ }, l = {
223
+ Full: {
224
+ promoLabel: "Hoàn thành toàn bộ trong tháng",
225
+ docLabel: "Đăng ký Full học phí",
226
+ docShort: "Đóng Full",
227
+ giftCondition: ""
228
+ },
229
+ "Giai đoạn": {
230
+ promoLabel: "Chia giai đoạn",
231
+ docLabel: "Đăng ký trả theo giai đoạn",
232
+ docShort: "Trả giai đoạn\n(Đóng 40% học phí lần đầu)",
233
+ giftCondition: "Hoàn thành tối thiểu 40% học phí trong tháng"
234
+ },
235
+ Sacombank: {
236
+ promoLabel: "Trả góp ngân hàng",
237
+ docLabel: "Đăng ký trả góp qua ngân hàng",
238
+ docShort: "Trả góp ngân hàng",
239
+ giftCondition: ""
240
+ },
241
+ Citime: {
242
+ promoLabel: "Trả góp Citime",
243
+ docLabel: "Đăng ký trả góp qua Citime",
244
+ docShort: "Trả góp Citime",
245
+ giftCondition: ""
246
+ }
247
+ }, u = [
248
+ {
249
+ bg: "#4B2A9B",
250
+ bg2: "#6A45C9"
251
+ },
252
+ {
253
+ bg: "#4B2A9B",
254
+ bg2: "#FBFAFF"
255
+ },
256
+ {
257
+ bg: "#FBDE44",
258
+ bg2: "#FFFBE8"
259
+ },
260
+ {
261
+ bg: "#FFD21F",
262
+ bg2: "#FFE45C"
263
+ },
264
+ {
265
+ bg: "#F0C030",
266
+ bg2: "#FFFCF2"
267
+ }
268
+ ], d = (e) => String(e ?? "").trim().toLowerCase(), f = (e, t) => d(e) === d(t), p = (e) => Math.round(Number(e) || 0), m = "OK";
269
+ function h(e, t) {
270
+ return e.settings.programs.find((e) => f(e.name, t));
6
271
  }
7
- function f(e, t) {
8
- return e.settings.paymentMethods.find((e) => c(e.name, t));
272
+ function g(e, t) {
273
+ return e.settings.paymentMethods.find((e) => f(e.name, t));
9
274
  }
10
- function p(e, t) {
11
- return f(e, t)?.terms ?? [0];
275
+ function _(e, t) {
276
+ return g(e, t)?.terms ?? [0];
12
277
  }
13
- function m(e, t) {
14
- let n = p(e, t);
278
+ function ee(e, t) {
279
+ let n = _(e, t);
15
280
  return n.length === 1 && Number(n[0]) === 0;
16
281
  }
17
- function h(e, t) {
18
- return e.settings.courseCodes.slice().sort((e, t) => e.order - t.order).filter((n) => e.courses.some((e) => c(e.label, t) && c(e.code, n.code))).map((n) => ({
282
+ function v(e, t) {
283
+ return e.settings.courseCodes.slice().sort((e, t) => e.order - t.order).filter((n) => e.courses.some((e) => f(e.label, t) && f(e.code, n.code))).map((n) => ({
19
284
  ...n,
20
- name: e.courses.find((e) => c(e.label, t) && c(e.code, n.code))?.name ?? n.code,
21
- modes: e.courses.filter((e) => c(e.label, t) && c(e.code, n.code)).map((e) => e.mode)
285
+ name: e.courses.find((e) => f(e.label, t) && f(e.code, n.code))?.name ?? n.code,
286
+ modes: e.courses.filter((e) => f(e.label, t) && f(e.code, n.code)).map((e) => e.mode)
22
287
  }));
23
288
  }
24
- function g(e, t) {
25
- return e.settings.courseCodes.slice().sort((e, t) => e.order - t.order).filter((e) => t.some((t) => c(t.code, e.code))).map((e) => e.short).join("_");
289
+ function y(e, t) {
290
+ return e.settings.courseCodes.slice().sort((e, t) => e.order - t.order).filter((e) => t.some((t) => f(t.code, e.code))).map((e) => e.short).join("_");
26
291
  }
27
- function _(e, t) {
28
- return e.settings.lktGroups?.find((e) => c(e.name, t));
292
+ function b(e, t) {
293
+ return e.settings.lktGroups?.find((e) => f(e.name, t));
29
294
  }
30
- function v(e, t, n) {
31
- return e.lkt.filter((e) => c(e.label, t) && c(e.group, n));
295
+ function x(e, t, n) {
296
+ return e.lkt.filter((e) => f(e.label, t) && f(e.group, n));
32
297
  }
33
- function y(e, t) {
34
- return (e.settings.lktGroups ?? []).filter((n) => e.lkt.some((e) => c(e.label, t) && c(e.group, n.name)));
298
+ function S(e, t) {
299
+ return (e.settings.lktGroups ?? []).filter((n) => e.lkt.some((e) => f(e.label, t) && f(e.group, n.name)));
35
300
  }
36
- function b(e) {
301
+ function C(e) {
37
302
  let t = e.settings;
38
- return Array.isArray(t.lktGroups) && t.lktGroups.length || (t.lktGroups = [{
303
+ Array.isArray(t.lktGroups) && t.lktGroups.length || (t.lktGroups = [{
39
304
  name: "LKT Toàn hệ thống",
40
305
  baseProgram: "Định kỳ đặc biệt"
41
306
  }]), e.lkt.forEach((e) => {
42
307
  e.group ||= t.lktGroups[0].name;
308
+ }), e.courses.forEach((e) => {
309
+ let t = s[`${e.label}|${e.code}|${e.mode}`];
310
+ e.sessions ??= t?.sessions ?? "", e.classSize ??= t?.classSize ?? "";
311
+ });
312
+ for (let [e, n] of Object.entries(c)) t[e] ?? (t[e] = JSON.parse(JSON.stringify(n)));
313
+ for (let [e, n] of Object.entries(c.docTexts)) t.docTexts[e] ?? (t.docTexts[e] = n);
314
+ for (let e of t.brands) {
315
+ let t = c.brands.find((t) => t.label === e.label), n = u.some((t) => String(t.bg).toLowerCase() === String(e.bg).toLowerCase() && String(t.bg2).toLowerCase() === String(e.bg2).toLowerCase());
316
+ if (t && n) {
317
+ let { label: n, logoUrl: r, footer: i, ...a } = t;
318
+ Object.assign(e, a);
319
+ }
320
+ for (let n of [
321
+ "gradient",
322
+ "onMain",
323
+ "font",
324
+ "motif",
325
+ "neutral",
326
+ "slate"
327
+ ]) e[n] ?? (e[n] = t?.[n] ?? "");
328
+ e.logoLight ?? (e.logoLight = t?.logoLight ?? "", e.logoUrl ||= t?.logoUrl ?? "");
329
+ }
330
+ return t.paymentMethods.forEach((e) => {
331
+ let t = l[e.name] ?? {
332
+ promoLabel: e.name,
333
+ docLabel: e.name,
334
+ docShort: e.name,
335
+ giftCondition: ""
336
+ };
337
+ for (let n of [
338
+ "promoLabel",
339
+ "docLabel",
340
+ "docShort",
341
+ "giftCondition"
342
+ ]) e[n] ?? (e[n] = t[n]);
43
343
  }), e;
44
344
  }
45
- function x(e, { label: t, program: n, method: r, keyTerm: i, count: a, lktGroup: o, lktFormat: s }) {
46
- switch (d(e, n)?.type) {
345
+ function w(e, { label: t, program: n, method: r, keyTerm: i, count: a, lktGroup: o, lktFormat: s }) {
346
+ switch (h(e, n)?.type) {
47
347
  case "DINH_KY": {
48
- let n = e.periodic.filter((e) => c(e.label, t) && e.from <= a && e.to >= a);
348
+ let n = e.periodic.filter((e) => f(e.label, t) && e.from <= a && e.to >= a);
49
349
  return {
50
350
  pct: n.reduce((e, t) => e + t.pct, 0),
51
351
  cashback: n.reduce((e, t) => e + t.cashback, 0),
@@ -53,7 +353,7 @@ function x(e, { label: t, program: n, method: r, keyTerm: i, count: a, lktGroup:
53
353
  };
54
354
  }
55
355
  case "DAC_BIET": {
56
- let n = e.special.find((e) => c(e.label, t) && c(e.method, r) && Number(e.term) === i);
356
+ let n = e.special.find((e) => f(e.label, t) && f(e.method, r) && Number(e.term) === i);
57
357
  return {
58
358
  pct: n?.pct ?? 0,
59
359
  cashback: 0,
@@ -61,9 +361,9 @@ function x(e, { label: t, program: n, method: r, keyTerm: i, count: a, lktGroup:
61
361
  };
62
362
  }
63
363
  case "LKT": {
64
- let n = _(e, o), l = n && s ? e.lkt.find((e) => c(e.label, t) && c(e.group, n.name) && c(e.format, s)) : null, u = d(e, n?.baseProgram), f = u && u.type !== "LKT" ? x(e, {
364
+ let n = b(e, o), c = n && s ? e.lkt.find((e) => f(e.label, t) && f(e.group, n.name) && f(e.format, s)) : null, l = h(e, n?.baseProgram), u = l && l.type !== "LKT" ? w(e, {
65
365
  label: t,
66
- program: u.name,
366
+ program: l.name,
67
367
  method: r,
68
368
  keyTerm: i,
69
369
  count: a
@@ -72,21 +372,21 @@ function x(e, { label: t, program: n, method: r, keyTerm: i, count: a, lktGroup:
72
372
  found: !1
73
373
  };
74
374
  return {
75
- pct: f.found && l ? f.pct - l.cut : 0,
375
+ pct: u.found && c ? u.pct - c.cut : 0,
76
376
  cashback: 0,
77
- found: f.found && !!l,
377
+ found: u.found && !!c,
78
378
  lkt: {
79
379
  group: n?.name ?? "",
80
- baseProgram: u?.name ?? "",
81
- baseType: u?.type ?? "",
82
- basePct: f.pct,
83
- baseFound: f.found,
84
- cut: l ? l.cut : null
380
+ baseProgram: l?.name ?? "",
381
+ baseType: l?.type ?? "",
382
+ basePct: u.pct,
383
+ baseFound: u.found,
384
+ cut: c ? c.cut : null
85
385
  }
86
386
  };
87
387
  }
88
388
  case "MO_RONG": {
89
- let a = e.extended.find((e) => c(e.label, t) && c(e.program, n) && c(e.method, r) && Number(e.term) === i);
389
+ let a = e.extended.find((e) => f(e.label, t) && f(e.program, n) && f(e.method, r) && Number(e.term) === i);
90
390
  return {
91
391
  pct: a?.pct ?? 0,
92
392
  cashback: 0,
@@ -100,23 +400,23 @@ function x(e, { label: t, program: n, method: r, keyTerm: i, count: a, lktGroup:
100
400
  };
101
401
  }
102
402
  }
103
- function S(e, { label: t, program: n, method: r, count: i }) {
104
- let a = f(e, r)?.giftGroup ?? r, o = e.gifts.filter((e) => c(e.label, t) && c(e.program, n) && c(e.method, a));
403
+ function T(e, { label: t, program: n, method: r, count: i }) {
404
+ let a = g(e, r)?.giftGroup ?? r, o = e.gifts.filter((e) => f(e.label, t) && f(e.program, n) && f(e.method, a));
105
405
  if (!o.length) return null;
106
- let s = Math.max(...e.gifts.filter((e) => c(e.label, t) && c(e.program, n)).map((e) => e.milestone)), l = o.find((e) => Number(e.milestone) === Math.min(i, s));
107
- return l ? {
108
- content: l.content,
109
- value: l.value
406
+ let s = Math.max(...e.gifts.filter((e) => f(e.label, t) && f(e.program, n)).map((e) => e.milestone)), c = o.find((e) => Number(e.milestone) === Math.min(i, s));
407
+ return c ? {
408
+ content: c.content,
409
+ value: c.value
110
410
  } : null;
111
411
  }
112
- function C(e, t) {
113
- let { label: n, program: r, method: i, warranty: a, lktGroup: o, lktFormat: s } = t, u = Number(t.term) || 0, p = (t.items ?? []).filter((e) => e && e.code), h = d(e, r), v = f(e, i), y = m(e, i), b = y ? 0 : u, C = h?.type === "LKT" ? _(e, o)?.baseProgram : r, T = d(e, C)?.type === "MO_RONG", E = p.map((t) => {
114
- let r = e.courses.find((e) => c(e.label, n) && c(e.code, t.code) && c(e.mode, t.mode)), i = r?.voucher ?? 0;
115
- if (T) {
116
- let r = e.programVouchers.find((e) => c(e.label, n) && c(e.program, C) && c(e.code, t.code) && c(e.mode, t.mode));
412
+ function E(e, t) {
413
+ let { label: n, program: r, method: i, warranty: a, lktGroup: o, lktFormat: s } = t, c = Number(t.term) || 0, l = (t.items ?? []).filter((e) => e && e.code), u = h(e, r), d = g(e, i), m = ee(e, i), _ = m ? 0 : c, v = u?.type === "LKT" ? b(e, o)?.baseProgram : r, x = h(e, v)?.type === "MO_RONG", S = l.map((t) => {
414
+ let r = e.courses.find((e) => f(e.label, n) && f(e.code, t.code) && f(e.mode, t.mode)), i = r?.voucher ?? 0;
415
+ if (x) {
416
+ let r = e.programVouchers.find((e) => f(e.label, n) && f(e.program, v) && f(e.code, t.code) && f(e.mode, t.mode));
117
417
  r && (i = r.voucher);
118
418
  }
119
- let a = e.settings.courseCodes.find((e) => c(e.code, t.code));
419
+ let a = e.settings.courseCodes.find((e) => f(e.code, t.code));
120
420
  return {
121
421
  code: t.code,
122
422
  mode: t.mode,
@@ -126,64 +426,64 @@ function C(e, t) {
126
426
  found: !!r,
127
427
  warranty: a?.warranty !== !1
128
428
  };
129
- }), D = E.length, O = E.reduce((e, t) => e + t.price, 0), k = E.reduce((e, t) => e + t.voucher, 0), A = E.filter((e) => e.warranty).reduce((e, t) => e + t.price, 0), j = g(e, p), M = j ? e.citimeRoutes.find((e) => c(e.label, n) && c(e.code, j)) : null, N = M ? M.status : j ? "KHÔNG CÓ" : "", P = M?.maxTerm ?? null, F = x(e, {
429
+ }), C = S.length, E = S.reduce((e, t) => e + t.price, 0), te = S.reduce((e, t) => e + t.voucher, 0), ne = S.filter((e) => e.warranty).reduce((e, t) => e + t.price, 0), O = y(e, l), k = O ? e.citimeRoutes.find((e) => f(e.label, n) && f(e.code, O)) : null, A = k ? k.status : O ? "KHÔNG CÓ" : "", re = k?.maxTerm ?? null, j = w(e, {
130
430
  label: n,
131
431
  program: r,
132
432
  method: i,
133
- keyTerm: b,
134
- count: D,
433
+ keyTerm: _,
434
+ count: C,
135
435
  lktGroup: o,
136
436
  lktFormat: s
137
- }), I = O * F.pct, L = O - I - F.cashback - k, R = e.warranty.find((e) => c(e.name, a))?.rate ?? 0, z = A * R, B = {
138
- lines: E,
139
- count: D,
140
- gross: l(O),
141
- voucherTotal: l(k),
142
- pct: F.pct,
143
- cashback: l(F.cashback),
144
- discountAmt: l(I),
145
- afterPromo: l(L),
146
- warrantyRate: R,
147
- warrantyBase: l(A),
148
- warrantyFee: l(z),
149
- final: l(L + z),
150
- gift: S(e, {
437
+ }), ie = E * j.pct, M = E - ie - j.cashback - te, ae = e.warranty.find((e) => f(e.name, a))?.rate ?? 0, oe = ne * ae, N = {
438
+ lines: S,
439
+ count: C,
440
+ gross: p(E),
441
+ voucherTotal: p(te),
442
+ pct: j.pct,
443
+ cashback: p(j.cashback),
444
+ discountAmt: p(ie),
445
+ afterPromo: p(M),
446
+ warrantyRate: ae,
447
+ warrantyBase: p(ne),
448
+ warrantyFee: p(oe),
449
+ final: p(M + oe),
450
+ gift: T(e, {
151
451
  label: n,
152
452
  program: r,
153
453
  method: i,
154
- count: D
454
+ count: C
155
455
  }),
156
- lkt: F.lkt ?? null,
456
+ lkt: j.lkt ?? null,
157
457
  combo: {
158
- code: j,
159
- routeName: M?.name ?? "",
160
- group: M?.group ?? "",
161
- citimeStatus: N,
162
- citimeMax: P
458
+ code: O,
459
+ routeName: k?.name ?? "",
460
+ group: k?.group ?? "",
461
+ citimeStatus: A,
462
+ citimeMax: re
163
463
  }
164
464
  };
165
- return B.status = w(e, {
465
+ return N.status = D(e, {
166
466
  input: t,
167
- term: u,
168
- prog: h,
169
- pm: v,
170
- fixedTerm: y,
171
- count: D,
172
- lines: E,
173
- combo: j,
174
- citimeStatus: N,
175
- citimeMax: P,
176
- d: F,
177
- result: B
178
- }), B.ok = B.status === "OK", B;
467
+ term: c,
468
+ prog: u,
469
+ pm: d,
470
+ fixedTerm: m,
471
+ count: C,
472
+ lines: S,
473
+ combo: O,
474
+ citimeStatus: A,
475
+ citimeMax: re,
476
+ d: j,
477
+ result: N
478
+ }), N.ok = N.status === "OK", N;
179
479
  }
180
- function w(e, t) {
181
- let { input: n, term: r, prog: i, pm: a, fixedTerm: o, count: s, lines: l, combo: u, citimeStatus: d, citimeMax: f, d: p, result: m } = t, h = String(a?.name ?? n.method ?? "").toUpperCase(), g = e.settings.labels.find((e) => c(e.name, n.label));
480
+ function D(e, t) {
481
+ let { input: n, term: r, prog: i, pm: a, fixedTerm: o, count: s, lines: c, combo: l, citimeStatus: u, citimeMax: d, d: p, result: m } = t, h = String(a?.name ?? n.method ?? "").toUpperCase(), g = e.settings.labels.find((e) => f(e.name, n.label));
182
482
  if (!n.label) return "CHƯA CHỌN NHÃN";
183
483
  if (!n.program) return "CHƯA CHỌN CHƯƠNG TRÌNH";
184
484
  if (!n.method) return "CHƯA CHỌN HÌNH THỨC THANH TOÁN";
185
485
  if (s === 0) return "CHƯA CHỌN KHÓA HỌC";
186
- let _ = l.find((e) => !e.found);
486
+ let _ = c.find((e) => !e.found);
187
487
  if (_) return `KHÔNG CÓ KHÓA ${_.code} - ${_.mode || "?"}`;
188
488
  if (i?.type === "LKT") {
189
489
  if (!n.lktGroup) return "CHƯA CHỌN NHÓM LIÊN KẾT TRƯỜNG";
@@ -194,20 +494,20 @@ function w(e, t) {
194
494
  if (i?.type === "LKT" && p.lkt?.baseType === "MO_RONG" && !p.lkt.baseFound) return "KHÔNG ÁP DỤNG HTTT CHO NHÓM LKT";
195
495
  if (s === 1 && a && !a.allowSingle) return "KHÓA LẺ CHỈ ÁP DỤNG ĐÓNG FULL";
196
496
  if (o && r !== 0) return `${h} PHẢI CÓ KỲ HẠN = 0`;
197
- if (g?.blockedMethods?.some((e) => c(e, n.method))) return `${String(n.label).toUpperCase()} KHÔNG ÁP DỤNG HTTT NÀY`;
198
- if (s >= 2 && !u) return "KHÔNG TÌM THẤY LỘ TRÌNH";
497
+ if (g?.blockedMethods?.some((e) => f(e, n.method))) return `${String(n.label).toUpperCase()} KHÔNG ÁP DỤNG HTTT NÀY`;
498
+ if (s >= 2 && !l) return "KHÔNG TÌM THẤY LỘ TRÌNH";
199
499
  if (a && !a.citime && !o && !a.terms.map(Number).includes(r)) return `KỲ HẠN ${h} KHÔNG HỢP LỆ`;
200
500
  if (a?.citime) {
201
- if (!c(d, "Áp dụng")) return `KHÔNG ÁP DỤNG ${h}`;
501
+ if (!f(u, "Áp dụng")) return `KHÔNG ÁP DỤNG ${h}`;
202
502
  if (!a.terms.map(Number).includes(r)) return `KỲ HẠN ${h} KHÔNG HỢP LỆ`;
203
- if (f != null && r > f) return `VƯỢT KỲ HẠN ${h} TỐI ĐA`;
503
+ if (d != null && r > d) return `VƯỢT KỲ HẠN ${h} TỐI ĐA`;
204
504
  }
205
505
  return p.found ? m.afterPromo < 0 ? "LỖI GIÁ" : "OK" : "KHÔNG ÁP DỤNG CHƯƠNG TRÌNH";
206
506
  }
207
- function T(e, { label: t, program: n, method: r, term: i, warranty: a, lktGroup: o, lktFormat: s, output: l }) {
208
- return e.routes.filter((e) => c(e.label, t) && (!l || c(e.output, l))).map((c) => ({
507
+ function te(e, { label: t, program: n, method: r, term: i, warranty: a, lktGroup: o, lktFormat: s, output: c }) {
508
+ return e.routes.filter((e) => f(e.label, t) && (!c || f(e.output, c))).map((c) => ({
209
509
  route: c,
210
- quote: C(e, {
510
+ quote: E(e, {
211
511
  label: t,
212
512
  program: n,
213
513
  method: r,
@@ -219,7 +519,7 @@ function T(e, { label: t, program: n, method: r, term: i, warranty: a, lktGroup:
219
519
  })
220
520
  }));
221
521
  }
222
- function E(e) {
522
+ function ne(e) {
223
523
  let t = [], n = (e, n, r) => {
224
524
  let i = /* @__PURE__ */ new Map();
225
525
  e.forEach((e, a) => {
@@ -231,13 +531,13 @@ function E(e) {
231
531
  }) : i.set(o, a);
232
532
  });
233
533
  };
234
- n(e.courses, (e) => s(`${e.label}|${e.code}|${e.mode}`), "courses"), n(e.programVouchers, (e) => s(`${e.label}|${e.program}|${e.code}|${e.mode}`), "programVouchers"), n(e.special, (e) => s(`${e.label}|${e.method}|${e.term}`), "special"), n(e.extended, (e) => s(`${e.label}|${e.program}|${e.method}|${e.term}`), "extended"), n(e.lkt, (e) => s(`${e.label}|${e.group}|${e.format}`), "lkt"), e.lkt.forEach((n, r) => {
235
- _(e, n.group) || t.push({
534
+ n(e.courses, (e) => d(`${e.label}|${e.code}|${e.mode}`), "courses"), n(e.programVouchers, (e) => d(`${e.label}|${e.program}|${e.code}|${e.mode}`), "programVouchers"), n(e.special, (e) => d(`${e.label}|${e.method}|${e.term}`), "special"), n(e.extended, (e) => d(`${e.label}|${e.program}|${e.method}|${e.term}`), "extended"), n(e.lkt, (e) => d(`${e.label}|${e.group}|${e.format}`), "lkt"), e.lkt.forEach((n, r) => {
535
+ b(e, n.group) || t.push({
236
536
  table: "lkt",
237
537
  row: r,
238
538
  message: `Nhóm "${n.group}" chưa khai báo ở mục Nhóm LKT`
239
539
  });
240
- }), n(e.citimeRoutes, (e) => s(`${e.label}|${e.code}`), "citimeRoutes"), n(e.gifts, (e) => s(`${e.label}|${e.program}|${e.milestone}|${e.method}`), "gifts"), e.courses.forEach((e, n) => {
540
+ }), n(e.citimeRoutes, (e) => d(`${e.label}|${e.code}`), "citimeRoutes"), n(e.gifts, (e) => d(`${e.label}|${e.program}|${e.milestone}|${e.method}`), "gifts"), e.courses.forEach((e, n) => {
241
541
  e.price > 0 || t.push({
242
542
  table: "courses",
243
543
  row: n,
@@ -262,7 +562,7 @@ function E(e) {
262
562
  return t;
263
563
  }
264
564
  // src/ui/icons.js
265
- var D = {
565
+ var O = {
266
566
  calc: "<rect x=\"4\" y=\"2\" width=\"16\" height=\"20\" rx=\"2\"/><path d=\"M8 6h8M16 14v4M8 10h.01M12 10h.01M16 10h.01M8 14h.01M12 14h.01M8 18h.01M12 18h.01\"/>",
267
567
  table: "<rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"2\"/><path d=\"M3 9h18M3 15h18M9 3v18\"/>",
268
568
  db: "<ellipse cx=\"12\" cy=\"5\" rx=\"9\" ry=\"3\"/><path d=\"M3 5v14a9 3 0 0 0 18 0V5\"/><path d=\"M3 12a9 3 0 0 0 18 0\"/>",
@@ -295,9 +595,72 @@ var D = {
295
595
  sparkle: "<path d=\"M12 3l1.9 5.8L20 10l-6.1 1.2L12 17l-1.9-5.8L4 10l6.1-1.2z\"/>",
296
596
  user: "<circle cx=\"12\" cy=\"8\" r=\"4\"/><path d=\"M4 21a8 8 0 0 1 16 0\"/>",
297
597
  sheet: "<path d=\"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z\"/><path d=\"M14 2v5h5M8 13h8M8 17h8M8 9h2\"/>"
298
- }, O = (e, t = 18) => `<svg width="${t}" height="${t}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${D[e] ?? ""}</svg>`, k = (e) => [...new Set(e.filter((e) => e !== "" && e != null))], A = ["Online", "Offline"];
299
- function j(e) {
300
- let t = e.settings, n = t.labels.map((e) => e.name), r = t.programs.map((e) => e.name), i = t.programs.filter((e) => e.type === "MO_RONG").map((e) => e.name), a = t.paymentMethods.map((e) => e.name), o = k(t.paymentMethods.map((e) => e.giftGroup)), s = t.courseCodes.map((e) => e.code), c = (t.lktGroups ?? []).map((e) => e.name), l = t.programs.filter((e) => e.type !== "LKT").map((e) => e.name);
598
+ }, k = (e, t = 18) => `<svg width="${t}" height="${t}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${O[e] ?? ""}</svg>`, A = {
599
+ "classup/ngang-am-ban": {
600
+ name: "ClassUp · ngang · âm bản (chữ trắng, biểu tượng cam)",
601
+ file: "classup/ngang-am-ban.png"
602
+ },
603
+ "classup/ngang-mau": {
604
+ name: "ClassUp · ngang · màu (chữ xanh, biểu tượng cam)",
605
+ file: "classup/ngang-mau.png"
606
+ },
607
+ "classup/ngang-trang": {
608
+ name: "ClassUp · ngang · trắng",
609
+ file: "classup/ngang-trang.png"
610
+ },
611
+ "classup/doc-am-ban": {
612
+ name: "ClassUp · dọc · âm bản",
613
+ file: "classup/doc-am-ban.png"
614
+ },
615
+ "classup/doc-mau": {
616
+ name: "ClassUp · dọc · màu",
617
+ file: "classup/doc-mau.png"
618
+ },
619
+ "classup/doc-trang": {
620
+ name: "ClassUp · dọc · trắng",
621
+ file: "classup/doc-trang.png"
622
+ },
623
+ "classup/ecoach-am-ban": {
624
+ name: "ClassUp Powered by ECoach · âm bản",
625
+ file: "classup/ecoach-am-ban.webp"
626
+ },
627
+ "classup/ecoach-mau": {
628
+ name: "ClassUp Powered by ECoach · màu",
629
+ file: "classup/ecoach-mau.webp"
630
+ },
631
+ "classup/ecoach-trang": {
632
+ name: "ClassUp Powered by ECoach · trắng",
633
+ file: "classup/ecoach-trang.webp"
634
+ },
635
+ "classup/bieu-tuong-cam": {
636
+ name: "ClassUp · biểu tượng cam",
637
+ file: "classup/bieu-tuong-cam.png"
638
+ },
639
+ "classup/bieu-tuong-xanh": {
640
+ name: "ClassUp · biểu tượng xanh",
641
+ file: "classup/bieu-tuong-xanh.png"
642
+ },
643
+ "classup/bieu-tuong-trang": {
644
+ name: "ClassUp · biểu tượng trắng",
645
+ file: "classup/bieu-tuong-trang.png"
646
+ },
647
+ "classup/bieu-tuong-den": {
648
+ name: "ClassUp · biểu tượng đen",
649
+ file: "classup/bieu-tuong-den.png"
650
+ },
651
+ "classup/bieu-tuong-xam": {
652
+ name: "ClassUp · biểu tượng xám",
653
+ file: "classup/bieu-tuong-xam.png"
654
+ }
655
+ };
656
+ function re(e) {
657
+ let t = String(e ?? "").trim(), n = A[t];
658
+ return n ? new URL((/* #__PURE__ */ Object.assign({}))[`../assets/brand/${n.file}`], import.meta.url).href : t;
659
+ }
660
+ // src/ui/admin-tables.js
661
+ var j = (e) => [...new Set(e.filter((e) => e !== "" && e != null))], ie = ["Online", "Offline"];
662
+ function M(e) {
663
+ let t = e.settings, n = t.labels.map((e) => e.name), r = t.programs.map((e) => e.name), i = t.programs.filter((e) => e.type === "MO_RONG").map((e) => e.name), a = t.paymentMethods.map((e) => e.name), o = j(t.paymentMethods.map((e) => e.giftGroup)), s = t.courseCodes.map((e) => e.code), c = (t.lktGroups ?? []).map((e) => e.name), l = t.programs.filter((e) => e.type !== "LKT").map((e) => e.name);
301
664
  return [
302
665
  {
303
666
  id: "courses",
@@ -331,7 +694,7 @@ function j(e) {
331
694
  key: "mode",
332
695
  label: "Hình thức",
333
696
  type: "select",
334
- options: A
697
+ options: ie
335
698
  },
336
699
  {
337
700
  key: "price",
@@ -342,6 +705,16 @@ function j(e) {
342
705
  key: "voucher",
343
706
  label: "Voucher đặc biệt",
344
707
  type: "money"
708
+ },
709
+ {
710
+ key: "sessions",
711
+ label: "Thời lượng (PDF)",
712
+ type: "text"
713
+ },
714
+ {
715
+ key: "classSize",
716
+ label: "Sĩ số (PDF)",
717
+ type: "text"
345
718
  }
346
719
  ],
347
720
  blank: (e) => ({
@@ -350,7 +723,9 @@ function j(e) {
350
723
  name: "",
351
724
  mode: "Online",
352
725
  price: 0,
353
- voucher: 0
726
+ voucher: 0,
727
+ sessions: "",
728
+ classSize: ""
354
729
  })
355
730
  },
356
731
  {
@@ -672,7 +1047,7 @@ function j(e) {
672
1047
  key: "mode",
673
1048
  label: "Hình thức",
674
1049
  type: "select",
675
- options: A
1050
+ options: ie
676
1051
  },
677
1052
  {
678
1053
  key: "voucher",
@@ -884,6 +1259,27 @@ function j(e) {
884
1259
  key: "allowSingle",
885
1260
  label: "Cho khóa lẻ",
886
1261
  type: "bool"
1262
+ },
1263
+ {
1264
+ key: "promoLabel",
1265
+ label: "Tên trên bảng ưu đãi (PDF)",
1266
+ type: "text"
1267
+ },
1268
+ {
1269
+ key: "docLabel",
1270
+ label: "Cột bảng quà (PDF)",
1271
+ type: "text"
1272
+ },
1273
+ {
1274
+ key: "docShort",
1275
+ label: "Cột bảng lộ trình (PDF)",
1276
+ type: "multiline"
1277
+ },
1278
+ {
1279
+ key: "giftCondition",
1280
+ label: "Điều kiện nhận quà (PDF)",
1281
+ type: "text",
1282
+ wide: !0
887
1283
  }
888
1284
  ],
889
1285
  blank: () => ({
@@ -891,7 +1287,11 @@ function j(e) {
891
1287
  terms: [0],
892
1288
  giftGroup: "",
893
1289
  citime: !1,
894
- allowSingle: !1
1290
+ allowSingle: !1,
1291
+ promoLabel: "",
1292
+ docLabel: "",
1293
+ docShort: "",
1294
+ giftCondition: ""
895
1295
  })
896
1296
  },
897
1297
  {
@@ -951,777 +1351,1232 @@ function j(e) {
951
1351
  short: "",
952
1352
  warranty: !0
953
1353
  })
954
- }
955
- ];
956
- }
957
- function M(e, t) {
958
- switch (e.type) {
959
- case "money": return t === "" || t == null ? "" : Number(t).toLocaleString("vi-VN");
960
- case "pct": return t === "" || t == null ? "" : String(+(Number(t) * 100).toFixed(4));
961
- case "numlist":
962
- case "strlist": return (t ?? []).join(", ");
963
- case "items": return (t ?? []).map((e) => `${e.code}/${e.mode}`).join(" + ");
964
- default: return t ?? "";
965
- }
966
- }
967
- function N(e, t) {
968
- let n = String(t ?? "").trim();
969
- switch (e.type) {
970
- case "money": {
971
- let e = Number(n.replace(/[^\d-]/g, ""));
972
- return Number.isFinite(e) ? e : 0;
973
- }
974
- case "pct": {
975
- let e = Number(n.replace(",", ".").replace("%", ""));
976
- return Number.isFinite(e) ? +(e / 100).toFixed(6) : 0;
977
- }
978
- case "int": {
979
- let e = Number(n.replace(",", "."));
980
- return Number.isFinite(e) ? e : 0;
981
- }
982
- case "numlist": return n.split(/[,;\s]+/).filter(Boolean).map(Number).filter(Number.isFinite);
983
- case "strlist": return n.split(",").map((e) => e.trim()).filter(Boolean);
984
- case "items": return n.split("+").map((e) => e.trim()).filter(Boolean).map((e) => {
985
- let t = e.lastIndexOf("/");
986
- return t > 0 ? {
987
- code: e.slice(0, t).trim(),
988
- mode: e.slice(t + 1).trim()
989
- } : {
990
- code: e,
991
- mode: "Online"
992
- };
993
- });
994
- default: return n;
995
- }
996
- }
997
- // src/ui/excel-import.js
998
- var P = "https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js";
999
- function F() {
1000
- return window.XLSX ? Promise.resolve(window.XLSX) : new Promise((e, t) => {
1001
- let n = document.createElement("script");
1002
- n.src = P, n.onload = () => e(window.XLSX), n.onerror = () => t(/* @__PURE__ */ Error("Không tải được thư viện đọc Excel")), document.head.appendChild(n);
1003
- });
1004
- }
1005
- var I = (e, t = 0) => e === "" || e == null || Number.isNaN(Number(e)) ? t : Number(e), L = (e) => e == null ? "" : String(e).trim();
1006
- async function R(e, t) {
1007
- let n = await F(), r = n.read(await e.arrayBuffer(), { type: "array" }), i = (e, t) => {
1008
- let i = r.Sheets[e];
1009
- if (!i) throw Error(`File thiếu sheet "${e}"`);
1010
- return n.utils.sheet_to_json(i, {
1011
- header: 1,
1012
- defval: ""
1013
- }).slice(1).map((e) => Array.from({ length: t }, (t, n) => e[n] ?? "")).filter((e) => L(e[0]) !== "");
1014
- }, a = JSON.parse(JSON.stringify(t));
1015
- a.courses = i("01_DM_KHOA_HOC", 6).map((e) => ({
1016
- label: L(e[0]),
1017
- code: L(e[1]),
1018
- name: L(e[2]),
1019
- mode: L(e[3]),
1020
- price: I(e[4]),
1021
- voucher: I(e[5])
1022
- })), a.programVouchers = i("01B_VOUCHER_CTKM", 5).map((e) => ({
1023
- label: L(e[0]),
1024
- program: L(e[1]),
1025
- code: L(e[2]),
1026
- mode: L(e[3]),
1027
- voucher: I(e[4])
1028
- })), a.warranty = i("02_DM_BAO_HANH", 2).map((e) => ({
1029
- name: L(e[0]),
1030
- rate: I(e[1])
1031
- })), a.periodic = i("03_CTKM_DINH_KY", 5).map((e) => ({
1032
- label: L(e[0]),
1033
- from: I(e[1]),
1034
- to: I(e[2]),
1035
- pct: I(e[3]),
1036
- cashback: I(e[4])
1037
- })), a.special = i("04_CTKM_DAC_BIET", 7).map((e) => ({
1038
- label: L(e[0]),
1039
- method: L(e[1]),
1040
- term: I(e[2]),
1041
- pct: I(e[3]),
1042
- applyType: L(e[4]),
1043
- minCourses: I(e[5], 1),
1044
- note: L(e[6])
1045
- })), a.lkt = (n.utils.sheet_to_json(r.Sheets["04B_CTKM_LKT"] ?? {}, { header: 1 })[0] ?? []).some((e) => /nhóm/i.test(L(e))) ? i("04B_CTKM_LKT", 4).map((e) => ({
1046
- label: L(e[0]),
1047
- group: L(e[1]),
1048
- format: L(e[2]),
1049
- cut: I(e[3])
1050
- })) : i("04B_CTKM_LKT", 3).map((e) => ({
1051
- label: L(e[0]),
1052
- group: "LKT Toàn hệ thống",
1053
- format: L(e[1]),
1054
- cut: I(e[2])
1055
- }));
1056
- let o = a.settings.lktGroups ??= [];
1057
- for (let e of new Set(a.lkt.map((e) => e.group))) {
1058
- if (o.some((t) => t.name.toLowerCase() === e.toLowerCase())) continue;
1059
- let t = e.replace(/^LKT\s+/i, "").toLowerCase(), n = a.settings.programs.find((e) => e.type !== "LKT" && e.name.toLowerCase() === t);
1060
- o.push({
1061
- name: e,
1062
- baseProgram: n?.name ?? "Định kỳ đặc biệt"
1063
- });
1064
- }
1065
- a.extended = i("04C_CTKM_MO_RONG", 8).map((e) => ({
1066
- label: L(e[0]),
1067
- program: L(e[1]),
1068
- method: L(e[2]),
1069
- term: I(e[3]),
1070
- pct: I(e[4]),
1071
- applyType: L(e[5]),
1072
- minCourses: I(e[6], 1),
1073
- note: L(e[7])
1074
- })), a.citimeRoutes = i("05_CITIME_LO_TRINH", 7).map((e) => ({
1075
- label: L(e[0]),
1076
- group: L(e[1]),
1077
- count: I(e[2]),
1078
- code: L(e[3]),
1079
- name: L(e[4]),
1080
- status: L(e[5]),
1081
- maxTerm: I(e[6])
1082
- })), a.gifts = i("07_QUA_TANG", 6).map((e) => ({
1083
- label: L(e[0]),
1084
- program: L(e[1]),
1085
- milestone: I(e[2]),
1086
- method: L(e[3]),
1087
- content: L(e[4]),
1088
- value: I(e[5])
1089
- })), a.routes = i("08_LO_TRINH", 20).map((e) => {
1090
- let t = [];
1091
- for (let n = 4; n < 20; n += 2) L(e[n]) && t.push({
1092
- code: L(e[n]),
1093
- mode: L(e[n + 1])
1094
- });
1095
- return {
1096
- label: L(e[0]),
1097
- output: L(e[1]),
1098
- code: L(e[2]),
1099
- name: L(e[3]),
1100
- items: t
1101
- };
1102
- });
1103
- let s = r.Sheets["06_DM_KY_HAN_CITIME"] ? i("06_DM_KY_HAN_CITIME", 1).map((e) => I(e[0])) : null;
1104
- return s?.length && a.settings.paymentMethods.filter((e) => e.citime).forEach((e) => e.terms = s), a;
1105
- }
1106
- // src/ui/app.js
1107
- var z = (e) => JSON.parse(JSON.stringify(e)), B = (e) => String(e ?? "").replace(/[&<>"']/g, (e) => ({
1108
- "&": "&amp;",
1109
- "<": "&lt;",
1110
- ">": "&gt;",
1111
- "\"": "&quot;",
1112
- "'": "&#39;"
1113
- })[e]), V = (e) => `${Math.round(Number(e) || 0).toLocaleString("vi-VN")}đ`, H = (e) => `${+(Number(e || 0) * 100).toFixed(2)}%`, U = (e) => e ? e.split("-").reverse().join("/") : "", W = (e, t) => String(e ?? "").trim().toLowerCase() === String(t ?? "").trim().toLowerCase();
1114
- async function G(e, t = {}) {
1115
- let { store: n, allowRoleSwitch: r = !1, user: i = null } = t, a = {
1116
- role: t.role === "admin" ? "admin" : "sale",
1117
- view: "calc",
1118
- data: b(await n.load()),
1119
- calc: null,
1120
- table: null,
1121
- admin: {
1122
- tab: "courses",
1123
- label: "",
1124
- q: "",
1125
- draft: null,
1126
- dirty: !1,
1127
- issues: []
1128
- }
1129
- };
1130
- a.calc = l(a.data), a.table = {
1131
- ...l(a.data),
1132
- output: ""
1133
- }, e.classList.add("pt-root"), e.innerHTML = "";
1134
- let o = document.createElement("div"), s = document.createElement("div");
1135
- s.className = "pt-body", e.append(o, s);
1136
- function c() {
1137
- let e = [
1138
- [
1139
- "calc",
1140
- "calc",
1141
- "Tính giá"
1142
- ],
1143
- [
1144
- "table",
1145
- "table",
1146
- "Bảng giá lộ trình"
1147
- ],
1148
- ...a.role === "admin" ? [[
1149
- "admin",
1150
- "db",
1151
- "Quản trị dữ liệu gốc"
1152
- ]] : []
1153
- ];
1154
- a.view === "admin" && a.role !== "admin" && (a.view = "calc"), o.className = "pt-band", o.innerHTML = e.map(([e, t, n]) => `<button class="pt-tab ${a.view === e ? "is-active" : ""}" data-act="view" data-v="${e}">${O(t)}${n}</button>`).join("") + "<span class=\"pt-band-spacer\"></span>" + (r ? `<div class="pt-role" title="Chỉ có ở bản demo — trên portal vai trò lấy từ tài khoản đăng nhập">
1155
- <button class="${a.role === "sale" ? "is-active" : ""}" data-act="role" data-v="sale">Sale / TVV</button>
1156
- <button class="${a.role === "admin" ? "is-active" : ""}" data-act="role" data-v="admin">Admin</button></div>` : ""), s.innerHTML = `<div class="pt-container">${a.view === "calc" ? S() : a.view === "table" ? k() : F()}</div>`, a.view === "admin" && K();
1157
- }
1158
- function l(e) {
1159
- return {
1160
- label: e.settings.labels[0]?.name ?? "",
1161
- program: e.settings.programs[0]?.name ?? "",
1162
- method: e.settings.paymentMethods[0]?.name ?? "",
1163
- term: 0,
1164
- warranty: e.warranty[0]?.name ?? "",
1165
- lktGroup: "",
1166
- lktFormat: "",
1167
- selected: {}
1168
- };
1169
- }
1170
- let u = (e) => ({
1171
- ...e,
1172
- items: a.data.settings.courseCodes.slice().sort((e, t) => e.order - t.order).filter((t) => e.selected[t.code]).map((t) => ({
1173
- code: t.code,
1174
- mode: e.selected[t.code]
1175
- }))
1176
- });
1177
- function g({ ic: e, title: t, sub: n, actions: r = "", stats: i = "" }) {
1178
- return `<div class="pt-page-head">
1179
- <div class="pt-title-row">
1180
- <div class="pt-title-icon">${O(e, 20)}</div>
1181
- <div><h2 class="pt-title">${t}</h2><p class="pt-sub">${n}</p></div>
1182
- <div class="pt-title-actions">${r}</div>
1183
- </div>
1184
- ${i ? `<div class="pt-stats">${i}</div>` : ""}
1185
- </div>`;
1186
- }
1187
- let _ = (e, t, n, r, i = !1) => `<div class="pt-stat pt-stat--${e}"><div style="min-width:0"><div class="pt-stat-label">${t}</div>
1188
- <div class="pt-stat-value ${i ? "is-small" : ""}">${n}</div></div><div class="pt-stat-icon">${O(r)}</div></div>`, x = (e, t, n, { disabled: r = () => !1, hint: i = () => "", fmt: a = (e) => e } = {}) => `<div class="pt-chips">${t.map((t) => {
1189
- let o = r(t), s = i(t);
1190
- return `<button class="pt-chip ${W(t, n) ? "is-active" : ""}" data-act="calc" data-f="${e}" data-v="${B(t)}" ${o ? "disabled" : ""}
1191
- ${o && typeof o == "string" ? `title="${B(o)}"` : ""}>${B(a(t))}${s ? ` <small>${B(s)}</small>` : ""}</button>`;
1192
- }).join("")}</div>`;
1193
- function S() {
1194
- let e = a.data, t = a.calc, n = C(e, u(t)), r = e.settings, i = d(e, t.program), o = r.labels.find((e) => W(e.name, t.label)), s = p(e, t.method), c = m(e, t.method), l = f(e, t.method), b = n.discountAmt + n.cashback + n.voucherTotal, S = h(e, t.label), w = e.routes.filter((e) => W(e.label, t.label)), T = _("grey", "Tổng giá gốc", V(n.gross), "tag") + _("white", `Tổng ưu đãi ${n.pct ? `(${H(n.pct)})` : ""}`, b ? `-${V(b)}` : "0đ", "percent") + _(n.ok ? "green" : "purple", "Học phí cuối cùng", n.count ? V(n.final) : "—", "wallet") + _(n.ok ? "green" : "red", "Trạng thái", n.ok ? "Hợp lệ" : B(n.status), n.ok ? "checkCircle" : "alert", !n.ok), E = `<div class="pt-form">
1195
- <div class="pt-form-row"><div class="pt-label">Nhãn</div>${x("label", r.labels.map((e) => e.name), t.label)}</div>
1196
- <div class="pt-form-row"><div class="pt-label">Chương trình</div>${x("program", r.programs.map((e) => e.name), t.program)}</div>
1197
- ${i?.type === "LKT" ? `<div class="pt-form-row"><div class="pt-label">Nhóm LKT<small>${n.lkt?.baseProgram ? `Theo chương trình ${B(n.lkt.baseProgram)}` : ""}</small></div>${y(e, t.label).length ? x("lktGroup", y(e, t.label).map((e) => e.name), t.lktGroup) : "<span class=\"pt-section-sub\">Nhãn này chưa có chính sách liên kết trường</span>"}</div>
1198
- ${t.lktGroup ? `<div class="pt-form-row"><div class="pt-label">Format LKT</div>${x("lktFormat", v(e, t.label, t.lktGroup).map((e) => e.format), t.lktFormat, { hint: (n) => {
1199
- let r = v(e, t.label, t.lktGroup).find((e) => W(e.format, n))?.cut;
1200
- return r ? `-${H(r)}` : "";
1201
- } })}</div>` : ""}` : ""}
1202
- <div class="pt-form-row"><div class="pt-label">Hình thức thanh toán</div>${x("method", r.paymentMethods.map((e) => e.name), t.method, { disabled: (e) => o?.blockedMethods?.some((t) => W(t, e)) ? `${t.label} không áp dụng ${e}` : !1 })}</div>
1203
- <div class="pt-form-row"><div class="pt-label">Kỳ hạn<small>${l?.citime && n.combo.citimeMax ? `Tối đa ${n.combo.citimeMax} tháng` : ""}</small></div>${c ? "<div class=\"pt-chips\"><span class=\"pt-chip is-active\">Không kỳ hạn</span></div>" : x("term", s.map(String), String(t.term), {
1204
- fmt: (e) => `${e} tháng`,
1205
- disabled: (e) => l?.citime && n.combo.citimeMax != null && Number(e) > n.combo.citimeMax ? "Vượt kỳ hạn Citime tối đa của lộ trình" : !1
1206
- })}</div>
1207
- <div class="pt-form-row"><div class="pt-label">Gói bảo hành</div>${x("warranty", e.warranty.map((e) => e.name), t.warranty, { hint: (t) => {
1208
- let n = e.warranty.find((e) => W(e.name, t))?.rate;
1209
- return n ? `+${H(n)}` : "";
1210
- } })}</div>
1211
- </div>`, D = S.map((n) => {
1212
- let r = !!t.selected[n.code], i = t.selected[n.code] ?? n.modes[0], a = C(e, {
1213
- ...t,
1214
- items: [{
1215
- code: n.code,
1216
- mode: i
1217
- }]
1218
- }).lines[0];
1219
- return `<div class="pt-course ${r ? "is-on" : ""}" data-act="toggle" data-code="${B(n.code)}" role="checkbox" aria-checked="${r}" tabindex="0">
1220
- <div class="pt-course-top"><span class="pt-check">${r ? O("check", 14) : ""}</span>
1221
- <div style="min-width:0"><div class="pt-course-name">${B(n.name)}</div><div class="pt-course-code">${B(n.code)}</div></div></div>
1222
- ${n.modes.length > 1 ? `<div class="pt-seg">${n.modes.map((e) => `<button class="${W(e, i) ? "is-active" : ""}" data-act="mode" data-code="${B(n.code)}" data-v="${B(e)}">${B(e)}</button>`).join("")}</div>` : `<span class="pt-seg-single">${B(n.modes[0])}</span>`}
1223
- <div class="pt-course-price"><span>Giá gốc <b>${V(a?.price)}</b></span>${a?.voucher ? `<span>VC -${V(a.voucher)}</span>` : ""}</div>
1224
- </div>`;
1225
- }).join(""), k = n.lines.map((e) => `<tr><td>${B(e.name)} <span style="color:var(--pt-faint)">· ${B(e.mode)}</span></td><td>${V(e.price)}</td></tr>`).join(""), A = `<div class="pt-section pt-result">
1226
- <div class="pt-section-head"><div class="pt-section-icon">${O("calc", 16)}</div>
1227
- <div><div class="pt-section-title">Kết quả báo giá</div><div class="pt-section-sub">${n.count} khóa · ${B(t.program)} · ${B(t.method)}${t.term ? ` ${t.term} tháng` : ""}</div></div></div>
1228
- <div class="pt-section-body">
1229
- <div class="pt-status ${n.ok ? "is-ok" : "is-bad"}">${O(n.ok ? "checkCircle" : "alert", 16)}${n.ok ? "Báo giá hợp lệ" : B(n.status)}</div>
1230
- ${k ? `<table class="pt-lines">${k}</table>` : ""}
1231
- <ul class="pt-rows">
1232
- <li><span>Tổng giá gốc</span><b>${V(n.gross)}</b></li>
1233
- <li class="is-minus"><span>Ưu đãi ${H(n.pct)}${n.lkt?.cut != null && n.lkt.baseFound ? `<br><small style="color:var(--pt-faint)">${B(n.lkt.baseProgram)} ${H(n.lkt.basePct)} − cắt ${B(t.lktFormat)} ${H(n.lkt.cut)}</small>` : ""}</span><b>-${V(n.discountAmt)}</b></li>
1234
- ${n.cashback ? `<li class="is-minus"><span>Hoàn tiền (Định kỳ)</span><b>-${V(n.cashback)}</b></li>` : ""}
1235
- <li class="is-minus"><span>Voucher đặc biệt</span><b>-${V(n.voucherTotal)}</b></li>
1236
- <li><span>Giá sau khuyến mại</span><b>${V(n.afterPromo)}</b></li>
1237
- <li class="is-plus"><span>Bảo hành ${B(t.warranty)} (${H(n.warrantyRate)} × ${V(n.warrantyBase)})</span><b>+${V(n.warrantyFee)}</b></li>
1238
- </ul>
1239
- <div class="pt-final ${n.ok ? "" : "is-dim"}"><small>HỌC PHÍ CUỐI CÙNG</small><div>${n.count ? V(n.final) : "—"}</div></div>
1240
- ${n.gift ? `<div class="pt-gift">${O("gift", 18)}<div><b>Quà tặng:</b> ${B(n.gift.content)}</div></div>` : ""}
1241
- ${n.combo.code ? `<div class="pt-combo">Mã lộ trình: <b>${B(n.combo.code)}</b>${n.combo.routeName ? ` · ${B(n.combo.group)}` : ""}<br>
1242
- Citime: <b>${B(n.combo.citimeStatus)}</b>${n.combo.citimeMax ? ` · tối đa ${n.combo.citimeMax} tháng` : ""}</div>` : ""}
1243
- <div style="display:flex;gap:8px;margin-top:14px">
1244
- <button class="pt-btn pt-btn--primary" style="flex:1;justify-content:center" data-act="copy" ${n.count ? "" : "disabled"}>${O("copy", 16)}Sao chép báo giá</button>
1245
- <button class="pt-btn pt-btn--ghost" data-act="reset-calc" title="Làm mới">${O("refresh", 16)}</button>
1246
- </div>
1247
- </div></div>`;
1248
- return g({
1249
- ic: "calc",
1250
- title: "Tính giá khuyến mại",
1251
- sub: `${B(r.campaignName)} · Áp dụng ${U(r.validFrom)} – ${U(r.validTo)}`,
1252
- stats: T
1253
- }) + `<div class="pt-grid pt-grid-calc" style="margin-top:14px">
1254
- <div>
1255
- <div class="pt-section" style="margin-top:0">
1256
- <div class="pt-section-head"><div class="pt-section-icon">${O("filter", 16)}</div>
1257
- <div><div class="pt-section-title">Thông tin chung</div><div class="pt-section-sub">Bấm chọn — kết quả tự cập nhật</div></div></div>
1258
- <div class="pt-section-body">${E}</div>
1259
- </div>
1260
- <div class="pt-section">
1261
- <div class="pt-section-head"><div class="pt-section-icon">${O("book", 16)}</div>
1262
- <div><div class="pt-section-title">Khóa học đăng ký</div><div class="pt-section-sub">Tích chọn khóa và hình thức học · ${B(r.note ?? "")}</div></div>
1263
- <div class="pt-section-actions">
1264
- <select class="pt-select" style="height:34px;max-width:260px" data-act="pick-route">
1265
- <option value="">Chọn nhanh theo lộ trình…</option>
1266
- ${w.map((e) => `<option value="${B(e.code)}">${B(e.output ? `[${e.output}] ` : "")}${B(e.name)}</option>`).join("")}
1267
- </select>
1268
- <button class="pt-btn pt-btn--link" data-act="clear-courses">Bỏ chọn</button>
1269
- </div></div>
1270
- <div class="pt-section-body"><div class="pt-courses">${D || "<div class=\"pt-empty\">Nhãn này chưa có khóa học</div>"}</div></div>
1271
- </div>
1272
- </div>
1273
- ${A}
1274
- </div>`;
1354
+ },
1355
+ {
1356
+ id: "brands",
1357
+ group: "Ấn phẩm PDF",
1358
+ icon: "sparkle",
1359
+ title: "Nhận diện nhãn",
1360
+ path: ["settings", "brands"],
1361
+ desc: "Ấn phẩm PDF theo phong cách catalogue của nhãn: màu chủ đạo (sọc, thẻ, cột giá), màu nền giấy, màu tối (bìa, tiêu đề bảng), màu phụ (nhãn mục, gạch dưới tiêu đề, lưu ý), xám nhạt (thẻ, dòng xen kẽ), xám đậm (chữ phụ), logo (link ảnh, để trống thì in tên nhãn) và dòng chân trang.",
1362
+ columns: [
1363
+ {
1364
+ key: "label",
1365
+ label: "Nhãn",
1366
+ type: "select",
1367
+ options: n
1368
+ },
1369
+ {
1370
+ key: "brandName",
1371
+ label: "Tên hiển thị",
1372
+ type: "text"
1373
+ },
1374
+ {
1375
+ key: "bg",
1376
+ label: "Màu chủ đạo",
1377
+ type: "color"
1378
+ },
1379
+ {
1380
+ key: "bg2",
1381
+ label: "Nền giấy",
1382
+ type: "color"
1383
+ },
1384
+ {
1385
+ key: "ink",
1386
+ label: "Màu tối",
1387
+ type: "color"
1388
+ },
1389
+ {
1390
+ key: "accent",
1391
+ label: "Màu phụ (xanh)",
1392
+ type: "color"
1393
+ },
1394
+ {
1395
+ key: "neutral",
1396
+ label: "Xám nhạt",
1397
+ type: "color"
1398
+ },
1399
+ {
1400
+ key: "slate",
1401
+ label: "Xám đậm (chữ phụ)",
1402
+ type: "color"
1403
+ },
1404
+ {
1405
+ key: "gradient",
1406
+ label: "Gradient (màu đầu,màu cuối)",
1407
+ type: "text"
1408
+ },
1409
+ {
1410
+ key: "onMain",
1411
+ label: "Chữ trên màu chủ đạo",
1412
+ type: "color"
1413
+ },
1414
+ {
1415
+ key: "font",
1416
+ label: "Font (Google Font)",
1417
+ type: "text"
1418
+ },
1419
+ {
1420
+ key: "motif",
1421
+ label: "Họa tiết",
1422
+ type: "select",
1423
+ options: ["", "wave"]
1424
+ },
1425
+ {
1426
+ key: "logoUrl",
1427
+ label: "Logo trên nền tối (bìa)",
1428
+ type: "combo",
1429
+ options: Object.keys(A),
1430
+ wide: !0
1431
+ },
1432
+ {
1433
+ key: "logoLight",
1434
+ label: "Logo trên nền sáng (chân trang)",
1435
+ type: "combo",
1436
+ options: Object.keys(A),
1437
+ wide: !0
1438
+ },
1439
+ {
1440
+ key: "footer",
1441
+ label: "Chân trang",
1442
+ type: "multiline",
1443
+ wide: !0
1444
+ }
1445
+ ],
1446
+ blank: (e) => ({
1447
+ label: e,
1448
+ brandName: String(e).toUpperCase(),
1449
+ bg: "#FFD602",
1450
+ bg2: "#FFFFFF",
1451
+ ink: "#000000",
1452
+ accent: "#01518E",
1453
+ neutral: "#E1DEE5",
1454
+ slate: "#44525E",
1455
+ logoUrl: "",
1456
+ logoLight: "",
1457
+ footer: ""
1458
+ })
1459
+ },
1460
+ {
1461
+ id: "programRules",
1462
+ group: "Ấn phẩm PDF",
1463
+ icon: "sheet",
1464
+ title: "Quy định chương trình",
1465
+ path: ["settings", "programRules"],
1466
+ desc: "Khối \"Quy định tham gia chương trình\" in dưới bảng ưu đãi. Mỗi dòng là một quy định. Cập nhật theo từng tháng.",
1467
+ byLabel: !0,
1468
+ columns: [
1469
+ {
1470
+ key: "label",
1471
+ label: "Nhãn",
1472
+ type: "select",
1473
+ options: n
1474
+ },
1475
+ {
1476
+ key: "program",
1477
+ label: "Chương trình",
1478
+ type: "select",
1479
+ options: r
1480
+ },
1481
+ {
1482
+ key: "rules",
1483
+ label: "Quy định (mỗi dòng 1 ý)",
1484
+ type: "multiline",
1485
+ wide: !0
1486
+ }
1487
+ ],
1488
+ blank: (e) => ({
1489
+ label: e,
1490
+ program: r[0],
1491
+ rules: ""
1492
+ })
1493
+ },
1494
+ {
1495
+ id: "giftSets",
1496
+ group: "Ấn phẩm PDF",
1497
+ icon: "gift",
1498
+ title: "Bộ quà tặng",
1499
+ path: ["settings", "giftSets"],
1500
+ desc: "Bảng \"Bộ quà tặng giá trị dành cho học viên\". Giá trị nên khớp với cột Giá trị ở bảng Quà tặng. Mỗi món một dòng.",
1501
+ byLabel: !0,
1502
+ columns: [
1503
+ {
1504
+ key: "label",
1505
+ label: "Nhãn",
1506
+ type: "select",
1507
+ options: n
1508
+ },
1509
+ {
1510
+ key: "value",
1511
+ label: "Giá trị bộ quà",
1512
+ type: "money"
1513
+ },
1514
+ {
1515
+ key: "items",
1516
+ label: "Quà tặng bao gồm",
1517
+ type: "multiline",
1518
+ wide: !0
1519
+ }
1520
+ ],
1521
+ blank: (e) => ({
1522
+ label: e,
1523
+ value: 0,
1524
+ items: ""
1525
+ })
1526
+ },
1527
+ {
1528
+ id: "services",
1529
+ group: "Ấn phẩm PDF",
1530
+ icon: "school",
1531
+ title: "Dịch vụ học tập",
1532
+ path: ["settings", "services"],
1533
+ desc: "Bảng \"Dịch vụ học tập\" ở trang giá khóa học.",
1534
+ byLabel: !0,
1535
+ columns: [
1536
+ {
1537
+ key: "label",
1538
+ label: "Nhãn",
1539
+ type: "select",
1540
+ options: n
1541
+ },
1542
+ {
1543
+ key: "name",
1544
+ label: "Sản phẩm",
1545
+ type: "text",
1546
+ wide: !0
1547
+ },
1548
+ {
1549
+ key: "duration",
1550
+ label: "Thời lượng",
1551
+ type: "text"
1552
+ },
1553
+ {
1554
+ key: "mode",
1555
+ label: "Hình thức",
1556
+ type: "text"
1557
+ },
1558
+ {
1559
+ key: "price",
1560
+ label: "Giá gốc",
1561
+ type: "money"
1562
+ }
1563
+ ],
1564
+ blank: (e) => ({
1565
+ label: e,
1566
+ name: "",
1567
+ duration: "1 buổi",
1568
+ mode: "Online",
1569
+ price: 0
1570
+ })
1571
+ }
1572
+ ];
1573
+ }
1574
+ function ae(e, t) {
1575
+ switch (e.type) {
1576
+ case "money": return t === "" || t == null ? "" : Number(t).toLocaleString("vi-VN");
1577
+ case "pct": return t === "" || t == null ? "" : String(+(Number(t) * 100).toFixed(4));
1578
+ case "numlist":
1579
+ case "strlist": return (t ?? []).join(", ");
1580
+ case "items": return (t ?? []).map((e) => `${e.code}/${e.mode}`).join(" + ");
1581
+ default: return t ?? "";
1275
1582
  }
1276
- function w(e, t, n) {
1277
- let r = a.data;
1278
- if (t === "term" && (n = Number(n)), e[t] = n, t === "label") {
1279
- let t = h(r, n);
1280
- for (let n of Object.keys(e.selected)) {
1281
- let r = t.find((e) => W(e.code, n));
1282
- r ? r.modes.some((t) => W(t, e.selected[n])) || (e.selected[n] = r.modes[0]) : delete e.selected[n];
1283
- }
1284
- let i = r.settings.labels.find((e) => W(e.name, n))?.blockedMethods ?? [];
1285
- i.some((t) => W(t, e.method)) && (e.method = r.settings.paymentMethods.find((e) => !i.some((t) => W(t, e.name)))?.name ?? "");
1583
+ }
1584
+ function oe(e, t) {
1585
+ let n = String(t ?? "").trim();
1586
+ switch (e.type) {
1587
+ case "money": {
1588
+ let e = Number(n.replace(/[^\d-]/g, ""));
1589
+ return Number.isFinite(e) ? e : 0;
1286
1590
  }
1287
- if (t === "method" || t === "label") {
1288
- let t = p(r, e.method).map(Number);
1289
- t.includes(Number(e.term)) || (e.term = t[0] ?? 0);
1591
+ case "pct": {
1592
+ let e = Number(n.replace(",", ".").replace("%", ""));
1593
+ return Number.isFinite(e) ? +(e / 100).toFixed(6) : 0;
1290
1594
  }
1291
- if ([
1292
- "label",
1293
- "program",
1294
- "lktGroup"
1295
- ].includes(t) && d(r, e.program)?.type === "LKT") {
1296
- let t = y(r, e.label);
1297
- t.some((t) => W(t.name, e.lktGroup)) || (e.lktGroup = t[0]?.name ?? "");
1298
- let n = v(r, e.label, e.lktGroup);
1299
- n.some((t) => W(t.format, e.lktFormat)) || (e.lktFormat = n[0]?.format ?? "");
1595
+ case "int": {
1596
+ let e = Number(n.replace(",", "."));
1597
+ return Number.isFinite(e) ? e : 0;
1300
1598
  }
1599
+ case "numlist": return n.split(/[,;\s]+/).filter(Boolean).map(Number).filter(Number.isFinite);
1600
+ case "strlist": return n.split(",").map((e) => e.trim()).filter(Boolean);
1601
+ case "items": return n.split("+").map((e) => e.trim()).filter(Boolean).map((e) => {
1602
+ let t = e.lastIndexOf("/");
1603
+ return t > 0 ? {
1604
+ code: e.slice(0, t).trim(),
1605
+ mode: e.slice(t + 1).trim()
1606
+ } : {
1607
+ code: e,
1608
+ mode: "Online"
1609
+ };
1610
+ });
1611
+ default: return n;
1301
1612
  }
1302
- function D() {
1303
- let e = a.calc, t = C(a.data, u(e)), n = [
1304
- `BÁO GIÁ HỌC PHÍ – ${e.label.toUpperCase()}`,
1305
- `Chương trình: ${e.program}${d(a.data, e.program)?.type === "LKT" ? ` (${[e.lktGroup, e.lktFormat].filter(Boolean).join(" – ")})` : ""}`,
1306
- `Thanh toán: ${e.method}${e.term ? ` – ${e.term} tháng` : ""}`,
1307
- "Khóa học:",
1308
- ...t.lines.map((e) => ` • ${e.name} (${e.mode}): ${V(e.price)}`),
1309
- `Tổng giá gốc: ${V(t.gross)}`,
1310
- `Ưu đãi ${H(t.pct)}: -${V(t.discountAmt)}`,
1311
- ...t.cashback ? [`Hoàn tiền: -${V(t.cashback)}`] : [],
1312
- ...t.voucherTotal ? [`Voucher: -${V(t.voucherTotal)}`] : [],
1313
- ...t.warrantyFee ? [`Bảo hành ${e.warranty}: +${V(t.warrantyFee)}`] : [],
1314
- `HỌC PHÍ CUỐI CÙNG: ${V(t.final)}`,
1315
- ...t.gift ? [`Quà tặng: ${t.gift.content}`] : [],
1316
- `(${a.data.settings.campaignName}, áp dụng đến ${U(a.data.settings.validTo)})`
1317
- ];
1318
- return t.ok || n.unshift(`⚠ CHƯA HỢP LỆ: ${t.status}`), n.join("\n");
1613
+ }
1614
+ // src/ui/excel-import.js
1615
+ var N = "https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js";
1616
+ function P() {
1617
+ return window.XLSX ? Promise.resolve(window.XLSX) : new Promise((e, t) => {
1618
+ let n = document.createElement("script");
1619
+ n.src = N, n.onload = () => e(window.XLSX), n.onerror = () => t(/* @__PURE__ */ Error("Không tải được thư viện đọc Excel")), document.head.appendChild(n);
1620
+ });
1621
+ }
1622
+ var F = (e, t = 0) => e === "" || e == null || Number.isNaN(Number(e)) ? t : Number(e), I = (e) => e == null ? "" : String(e).trim();
1623
+ async function se(e, t) {
1624
+ let n = await P(), r = n.read(await e.arrayBuffer(), { type: "array" }), i = (e, t) => {
1625
+ let i = r.Sheets[e];
1626
+ if (!i) throw Error(`File thiếu sheet "${e}"`);
1627
+ return n.utils.sheet_to_json(i, {
1628
+ header: 1,
1629
+ defval: ""
1630
+ }).slice(1).map((e) => Array.from({ length: t }, (t, n) => e[n] ?? "")).filter((e) => I(e[0]) !== "");
1631
+ }, a = JSON.parse(JSON.stringify(t)), o = new Map((t.courses ?? []).map((e) => [`${e.label}|${e.code}|${e.mode}`.toLowerCase(), e]));
1632
+ a.courses = i("01_DM_KHOA_HOC", 6).map((e) => {
1633
+ let t = o.get(`${I(e[0])}|${I(e[1])}|${I(e[3])}`.toLowerCase());
1634
+ return {
1635
+ label: I(e[0]),
1636
+ code: I(e[1]),
1637
+ name: I(e[2]),
1638
+ mode: I(e[3]),
1639
+ price: F(e[4]),
1640
+ voucher: F(e[5]),
1641
+ sessions: t?.sessions ?? "",
1642
+ classSize: t?.classSize ?? ""
1643
+ };
1644
+ }), a.programVouchers = i("01B_VOUCHER_CTKM", 5).map((e) => ({
1645
+ label: I(e[0]),
1646
+ program: I(e[1]),
1647
+ code: I(e[2]),
1648
+ mode: I(e[3]),
1649
+ voucher: F(e[4])
1650
+ })), a.warranty = i("02_DM_BAO_HANH", 2).map((e) => ({
1651
+ name: I(e[0]),
1652
+ rate: F(e[1])
1653
+ })), a.periodic = i("03_CTKM_DINH_KY", 5).map((e) => ({
1654
+ label: I(e[0]),
1655
+ from: F(e[1]),
1656
+ to: F(e[2]),
1657
+ pct: F(e[3]),
1658
+ cashback: F(e[4])
1659
+ })), a.special = i("04_CTKM_DAC_BIET", 7).map((e) => ({
1660
+ label: I(e[0]),
1661
+ method: I(e[1]),
1662
+ term: F(e[2]),
1663
+ pct: F(e[3]),
1664
+ applyType: I(e[4]),
1665
+ minCourses: F(e[5], 1),
1666
+ note: I(e[6])
1667
+ })), a.lkt = (n.utils.sheet_to_json(r.Sheets["04B_CTKM_LKT"] ?? {}, { header: 1 })[0] ?? []).some((e) => /nhóm/i.test(I(e))) ? i("04B_CTKM_LKT", 4).map((e) => ({
1668
+ label: I(e[0]),
1669
+ group: I(e[1]),
1670
+ format: I(e[2]),
1671
+ cut: F(e[3])
1672
+ })) : i("04B_CTKM_LKT", 3).map((e) => ({
1673
+ label: I(e[0]),
1674
+ group: "LKT Toàn hệ thống",
1675
+ format: I(e[1]),
1676
+ cut: F(e[2])
1677
+ }));
1678
+ let s = a.settings.lktGroups ??= [];
1679
+ for (let e of new Set(a.lkt.map((e) => e.group))) {
1680
+ if (s.some((t) => t.name.toLowerCase() === e.toLowerCase())) continue;
1681
+ let t = e.replace(/^LKT\s+/i, "").toLowerCase(), n = a.settings.programs.find((e) => e.type !== "LKT" && e.name.toLowerCase() === t);
1682
+ s.push({
1683
+ name: e,
1684
+ baseProgram: n?.name ?? "Định kỳ đặc biệt"
1685
+ });
1319
1686
  }
1320
- function k() {
1321
- let e = a.data, t = a.table, n = [...new Set(e.routes.filter((e) => W(e.label, t.label)).map((e) => e.output).filter(Boolean))], r = T(e, t), i = r.filter((e) => e.quote.ok), o = i.length ? i.reduce((e, t) => e + t.quote.pct, 0) / i.length : 0, s = d(e, t.program), c = (e, t, n, r = (e) => e, i = null) => `<select class="pt-select" data-act="tbl" data-f="${e}">${i == null ? "" : `<option value="">${i}</option>`}${t.map((e) => `<option value="${B(e)}" ${W(e, n) ? "selected" : ""}>${B(r(e))}</option>`).join("")}</select>`, l = `<div class="pt-section">
1322
- <div class="pt-section-head no-line"><div class="pt-section-icon">${O("filter", 16)}</div>
1323
- <div><div class="pt-section-title">Bộ lọc thông minh</div><div class="pt-section-sub">Bảng giá tự tính lại từ dữ liệu gốc khi đổi bộ lọc</div></div>
1324
- <div class="pt-section-actions"><button class="pt-btn pt-btn--link" data-act="tbl-reset">${O("filter", 14)}Xóa bộ lọc</button></div></div>
1325
- <div class="pt-section-body"><div class="pt-grid pt-grid-3">
1326
- <div class="pt-field"><label>Nhãn</label>${c("label", e.settings.labels.map((e) => e.name), t.label)}</div>
1327
- <div class="pt-field"><label>Đầu ra</label>${c("output", n, t.output, (e) => e, "Tất cả đầu ra")}</div>
1328
- <div class="pt-field"><label>Chương trình</label>${c("program", e.settings.programs.map((e) => e.name), t.program)}</div>
1329
- ${s?.type === "LKT" ? `<div class="pt-field"><label>Nhóm LKT</label>${c("lktGroup", y(e, t.label).map((e) => e.name), t.lktGroup, (e) => e, "Chọn nhóm")}</div>
1330
- <div class="pt-field"><label>Format LKT</label>${c("lktFormat", v(e, t.label, t.lktGroup).map((e) => e.format), t.lktFormat, (e) => e, "Chọn format")}</div>` : ""}
1331
- <div class="pt-field"><label>Hình thức thanh toán</label>${c("method", e.settings.paymentMethods.map((e) => e.name), t.method)}</div>
1332
- <div class="pt-field"><label>Kỳ hạn</label>${c("term", p(e, t.method).map(String), String(t.term), (e) => Number(e) ? `${e} tháng` : "Không kỳ hạn")}</div>
1333
- <div class="pt-field"><label>Gói bảo hành</label>${c("warranty", e.warranty.map((e) => e.name), t.warranty)}</div>
1334
- </div></div></div>`, u = r.map(({ route: e, quote: t }) => `<tr>
1335
- <td><div style="font-weight:500">${B(e.name)}</div><div class="muted">${B(e.code)}</div></td>
1336
- <td>${e.output ? `<span class="pt-pill pt-pill--purple">${B(e.output)}</span>` : ""}</td>
1337
- <td class="num">${t.count}</td>
1338
- <td class="num">${V(t.gross)}</td>
1339
- <td class="num">${t.ok ? `<span class="pt-pill pt-pill--orange">-${H(t.pct)}</span>` : "—"}</td>
1340
- <td class="num">${t.ok ? V(t.afterPromo) : "—"}</td>
1341
- <td class="num"><b>${t.ok ? V(t.final) : "—"}</b></td>
1342
- <td class="muted">${t.ok && t.gift ? B(t.gift.content) : ""}</td>
1343
- <td>${t.ok ? "<span class=\"pt-pill pt-pill--green\"><span class=\"pt-dot\"></span>Hợp lệ</span>" : `<span class="pt-pill pt-pill--red"><span class="pt-dot"></span>${B(t.status)}</span>`}</td>
1344
- <td><button class="pt-icon-btn" title="Mở trong công cụ tính giá" data-act="open-route" data-code="${B(e.code)}">${O("eye", 16)}</button></td>
1345
- </tr>`).join("");
1346
- return g({
1347
- ic: "table",
1348
- title: "Bảng giá lộ trình gợi ý",
1349
- sub: `Học phí đã gồm ưu đãi theo bộ lọc · ${B(e.settings.campaignName)}`,
1350
- stats: _("grey", "Tổng lộ trình", r.length, "route") + _("white", "Mức giảm trung bình", i.length ? H(o) : "—", "percent") + _("green", "Hợp lệ", i.length, "checkCircle") + _("red", "Không áp dụng", r.length - i.length, "xCircle")
1351
- }) + l + `<div class="pt-section">
1352
- <div class="pt-section-head"><div><div class="pt-section-title">Danh sách lộ trình</div>
1353
- <div class="pt-section-sub">Tổng <b style="color:var(--pt-purple)">${r.length}</b> lộ trình · Bấm biểu tượng mắt để xem chi tiết & sao chép báo giá</div></div></div>
1354
- <div class="pt-table-wrap"><table class="pt-table">
1355
- <thead><tr><th>Lộ trình</th><th>Đầu ra</th><th class="num">Số khóa</th><th class="num">Giá gốc</th><th class="num">Ưu đãi</th>
1356
- <th class="num">Giá sau KM</th><th class="num">Học phí cuối</th><th>Quà tặng</th><th>Trạng thái</th><th>Thao tác</th></tr></thead>
1357
- <tbody>${u || "<tr><td colspan=\"10\" class=\"pt-empty\">Không có lộ trình phù hợp</td></tr>"}</tbody>
1358
- </table></div>
1359
- </div>`;
1360
- }
1361
- let A = () => a.admin.draft ??= z(a.data), P = (e) => e.path.reduce((e, t) => e[t], A());
1362
- function F() {
1363
- let e = A(), t = a.admin, n = j(e), r = n.find((e) => e.id === t.tab), i = [...new Set(n.map((e) => e.group))].map((e) => `<div class="pt-menu-group">${e}</div>` + n.filter((t) => t.group === e).map((e) => `<button class="${e.id === t.tab ? "is-active" : ""}" data-act="admin-tab" data-v="${e.id}">
1364
- <span class="pt-menu-ic">${O(e.icon, 15)}</span>${e.title}<span class="pt-count">${P(e).length}</span></button>`).join("")).join("") + `<div class="pt-menu-group">Chung</div>
1365
- <button class="${t.tab === "general" ? "is-active" : ""}" data-act="admin-tab" data-v="general"><span class="pt-menu-ic">${O("settings", 15)}</span>Thông tin chương trình</button>`, o = e.periodic.length + e.special.length + e.extended.length + e.lkt.length, s = E(e).length, c = _("grey", "Khóa học", e.courses.length, "book") + _("white", "Dòng CTKM", o, "percent") + _("green", "Lộ trình gợi ý", e.routes.length, "route") + _(s ? "red" : "green", "Cảnh báo dữ liệu", s, s ? "alert" : "checkCircle"), l = t.tab === "general" ? G(e) : `<div class="pt-section" style="margin-top:0">
1366
- <div class="pt-section-head"><div class="pt-section-icon">${O(r.icon, 16)}</div>
1367
- <div><div class="pt-section-title">${r.title}</div><div class="pt-section-sub">${r.sheet ? `Thay cho sheet ${r.sheet}` : "Cấu hình chung"}</div></div>
1368
- <div class="pt-section-actions">
1369
- ${r.byLabel ? `<select class="pt-select" style="height:36px;width:170px" data-act="admin-label"><option value="">Tất cả nhãn</option>${e.settings.labels.map((e) => `<option ${W(e.name, t.label) ? "selected" : ""}>${B(e.name)}</option>`).join("")}</select>` : ""}
1370
- <input class="pt-input" style="height:36px;width:180px" placeholder="Tìm…" value="${B(t.q)}" data-act="admin-q">
1371
- <button class="pt-btn pt-btn--primary" data-act="row-add">${O("plus", 16)}Thêm mới</button>
1372
- </div></div>
1373
- <p class="pt-help" style="margin-top:14px">${B(r.desc)}</p>
1374
- <div id="pt-issues"></div>
1375
- <div class="pt-table-wrap" id="pt-admin-table"></div>
1376
- </div>`;
1377
- return g({
1378
- ic: "db",
1379
- title: "Quản trị dữ liệu gốc",
1380
- sub: "Nhập giá gốc, CTKM, quà tặng… Sale chỉ xem kết quả tính theo dữ liệu này.",
1381
- actions: `
1382
- <label class="pt-btn pt-btn--ghost pt-btn--sm" style="cursor:pointer">${O("sheet", 15)}Nhập từ Excel<input type="file" accept=".xlsx" hidden data-act="import-xlsx"></label>
1383
- <label class="pt-btn pt-btn--ghost pt-btn--sm" style="cursor:pointer">${O("upload", 15)}Nhập JSON<input type="file" accept=".json" hidden data-act="import-json"></label>
1384
- <button class="pt-btn pt-btn--ghost pt-btn--sm" data-act="export-json">${O("download", 15)}Xuất JSON</button>`,
1385
- stats: c
1386
- }) + `<div class="pt-admin"><nav class="pt-menu">${i}</nav><div>${l}</div></div>
1387
- <div class="pt-savebar" id="pt-savebar" ${t.dirty ? "" : "hidden"}>${I()}</div>`;
1687
+ a.extended = i("04C_CTKM_MO_RONG", 8).map((e) => ({
1688
+ label: I(e[0]),
1689
+ program: I(e[1]),
1690
+ method: I(e[2]),
1691
+ term: F(e[3]),
1692
+ pct: F(e[4]),
1693
+ applyType: I(e[5]),
1694
+ minCourses: F(e[6], 1),
1695
+ note: I(e[7])
1696
+ })), a.citimeRoutes = i("05_CITIME_LO_TRINH", 7).map((e) => ({
1697
+ label: I(e[0]),
1698
+ group: I(e[1]),
1699
+ count: F(e[2]),
1700
+ code: I(e[3]),
1701
+ name: I(e[4]),
1702
+ status: I(e[5]),
1703
+ maxTerm: F(e[6])
1704
+ })), a.gifts = i("07_QUA_TANG", 6).map((e) => ({
1705
+ label: I(e[0]),
1706
+ program: I(e[1]),
1707
+ milestone: F(e[2]),
1708
+ method: I(e[3]),
1709
+ content: I(e[4]),
1710
+ value: F(e[5])
1711
+ })), a.routes = i("08_LO_TRINH", 20).map((e) => {
1712
+ let t = [];
1713
+ for (let n = 4; n < 20; n += 2) I(e[n]) && t.push({
1714
+ code: I(e[n]),
1715
+ mode: I(e[n + 1])
1716
+ });
1717
+ return {
1718
+ label: I(e[0]),
1719
+ output: I(e[1]),
1720
+ code: I(e[2]),
1721
+ name: I(e[3]),
1722
+ items: t
1723
+ };
1724
+ });
1725
+ let c = r.Sheets["06_DM_KY_HAN_CITIME"] ? i("06_DM_KY_HAN_CITIME", 1).map((e) => F(e[0])) : null;
1726
+ return c?.length && a.settings.paymentMethods.filter((e) => e.citime).forEach((e) => e.terms = c), a;
1727
+ }
1728
+ // src/doc/promo-doc.js
1729
+ var L = (e, t) => String(e ?? "").trim().toLowerCase() === String(t ?? "").trim().toLowerCase(), R = (e) => String(e ?? "").replace(/[&<>"']/g, (e) => ({
1730
+ "&": "&amp;",
1731
+ "<": "&lt;",
1732
+ ">": "&gt;",
1733
+ "\"": "&quot;",
1734
+ "'": "&#39;"
1735
+ })[e]), z = (e) => Math.round(Number(e) || 0).toLocaleString("vi-VN"), B = (e) => `${+(Number(e || 0) * 100).toFixed(2)}%`, ce = (e) => R(e).replace(/\n/g, "<br>"), V = (e) => String(e).padStart(2, "0"), le = [
1736
+ {
1737
+ id: "cover",
1738
+ title: "Trang bìa + điểm nổi bật"
1739
+ },
1740
+ {
1741
+ id: "courses",
1742
+ title: "Bảng giá khóa học"
1743
+ },
1744
+ {
1745
+ id: "promo",
1746
+ title: "Chương trình khuyến mại & voucher"
1747
+ },
1748
+ {
1749
+ id: "gifts",
1750
+ title: "Quà tặng theo hình thức thanh toán"
1751
+ },
1752
+ {
1753
+ id: "giftSets",
1754
+ title: "Bộ quà tặng"
1755
+ },
1756
+ {
1757
+ id: "services",
1758
+ title: "Gói bảo hành & dịch vụ học tập"
1759
+ },
1760
+ {
1761
+ id: "routes",
1762
+ title: "Bảng giá lộ trình gợi ý (theo đầu ra)"
1763
+ },
1764
+ {
1765
+ id: "citime",
1766
+ title: "Phụ lục thời hạn trả góp Citime"
1388
1767
  }
1389
- let I = () => `${O("alert", 18)}<span>Có thay đổi chưa lưu — sale vẫn đang dùng dữ liệu cũ.</span>
1390
- <span class="pt-band-spacer"></span>
1391
- <button class="pt-btn pt-btn--ghost pt-btn--sm" data-act="discard">Hủy thay đổi</button>
1392
- <button class="pt-btn pt-btn--primary pt-btn--sm" data-act="save" style="background:#fff;color:var(--pt-purple)">${O("save", 15)}Lưu & áp dụng</button>`;
1393
- function L() {
1394
- a.admin.dirty = !0;
1395
- let e = s.querySelector("#pt-savebar");
1396
- e && (e.hidden = !1);
1768
+ ];
1769
+ function ue(e, t) {
1770
+ let n = t || String(e?.settings?.validFrom ?? "").slice(0, 7), [r, i] = String(n ?? "").split("-");
1771
+ return r && i ? `${Number(i)}/${r}` : "";
1772
+ }
1773
+ var de = (e) => {
1774
+ if (!e || !/^\d{4}-\d{2}$/.test(e)) return ["", ""];
1775
+ let [t, n] = e.split("-").map(Number);
1776
+ return [`${e}-01`, `${e}-${String(new Date(t, n, 0).getDate()).padStart(2, "0")}`];
1777
+ }, H = (e) => {
1778
+ let [t, n, r] = String(e ?? "").split("-");
1779
+ return t ? `${Number(r)}/${Number(n)}/${t}` : "";
1780
+ };
1781
+ function fe(e, t, n) {
1782
+ return `CHƯƠNG TRÌNH KHUYẾN MÃI ${String(t).toUpperCase()} - THÁNG ${ue(e, n)}`;
1783
+ }
1784
+ function pe(e, t) {
1785
+ return e.settings.brands?.find((e) => L(e.label, t)) ?? {
1786
+ label: t,
1787
+ brandName: String(t),
1788
+ bg: "#F0C030",
1789
+ bg2: "#FFFCF2",
1790
+ ink: "#161513",
1791
+ accent: "#C8102E",
1792
+ logoUrl: "",
1793
+ footer: ""
1794
+ };
1795
+ }
1796
+ function me(e, t) {
1797
+ return [...new Set(e.routes.filter((e) => L(e.label, t)).map((e) => e.output).filter(Boolean))];
1798
+ }
1799
+ var U = (e, t) => e === 1 ? "Khóa lẻ" : `Combo ${e} khóa${t && e >= t ? " trở lên" : ""}`;
1800
+ function W({ head: e, rows: t, merge: n = [], cls: r = "" }) {
1801
+ let i = e.at(-1).reduce((e, t) => e + (t.colspan ?? 1), 0) + (e.length > 1 ? e[0].filter((e) => e.rowspan > 1).length : 0), a = t.map((e) => e.group == null ? e.map((e) => typeof e == "object" && e ? { ...e } : { html: String(e ?? "") }) : e);
1802
+ for (let e of n) {
1803
+ let t = -1;
1804
+ for (let n = 0; n <= a.length; n++) {
1805
+ let r = a[n], i = r && r.group == null ? r[e].key ?? r[e].html : null, o = t >= 0 ? a[t][e].key ?? a[t][e].html : null;
1806
+ t >= 0 && i != null && i === o ? (a[t][e].rowspan = (a[t][e].rowspan ?? 1) + 1, r[e].skip = !0) : t = i == null ? -1 : n;
1807
+ }
1397
1808
  }
1398
- function G(e) {
1399
- let t = e.settings, n = (e, n, r = "text") => `<div class="pt-field"><label>${n}</label><input class="pt-input" type="${r}" value="${B(t[e])}" data-act="setting" data-k="${e}"></div>`;
1400
- return `<div class="pt-section" style="margin-top:0">
1401
- <div class="pt-section-head"><div class="pt-section-icon">${O("settings", 16)}</div>
1402
- <div><div class="pt-section-title">Thông tin chương trình</div><div class="pt-section-sub">Hiển thị trên trang Tính giá và trong báo giá sao chép</div></div></div>
1403
- <div class="pt-section-body"><div class="pt-grid pt-grid-3">
1404
- ${n("campaignName", "Tên đợt khuyến mại")}${n("validFrom", "Áp dụng từ ngày", "date")}${n("validTo", "Đến ngày", "date")}
1405
- </div><div class="pt-field" style="margin-top:14px"><label>Lưu ý hiển thị cho sale</label>
1406
- <input class="pt-input" value="${B(t.note)}" data-act="setting" data-k="note"></div>
1407
- <div style="display:flex;gap:8px;margin-top:20px;flex-wrap:wrap">
1408
- <button class="pt-btn pt-btn--ghost pt-btn--sm" data-act="reset-seed">${O("refresh", 15)}Khôi phục dữ liệu gốc từ file Excel ban đầu</button>
1409
- </div></div></div>`;
1809
+ return `<table class="t ${r}"><thead>${e.map((e) => `<tr>${e.map((e) => `<th${e.colspan ? ` colspan="${e.colspan}"` : ""}${e.rowspan ? ` rowspan="${e.rowspan}"` : ""}${e.cls ? ` class="${e.cls}"` : ""}>${e.html}</th>`).join("")}</tr>`).join("")}</thead><tbody>${a.map((e) => e.group == null ? `<tr>${e.filter((e) => !e.skip).map((e) => `<td${e.rowspan > 1 ? ` rowspan="${e.rowspan}"` : ""}${e.cls ? ` class="${e.cls}"` : ""}>${e.html}</td>`).join("")}</tr>` : `<tr class="grp"><td colspan="${i}">${R(e.group)}</td></tr>`).join("")}</tbody></table>`;
1810
+ }
1811
+ var G = (...e) => e.map((e) => typeof e == "string" ? { html: e } : e);
1812
+ function K(e, t) {
1813
+ let n = h(e, t.program), r = n?.type === "DINH_KY", i = e.settings.paymentMethods, a = (i.find((e) => e.allowSingle) ?? i[0]).name;
1814
+ return {
1815
+ label: t.label,
1816
+ program: t.program,
1817
+ month: t.month,
1818
+ prog: n,
1819
+ periodic: r,
1820
+ lktGroup: t.lktGroup,
1821
+ lktFormat: t.lktFormat,
1822
+ single: a,
1823
+ q(n, r = {}) {
1824
+ return E(e, {
1825
+ label: t.label,
1826
+ program: t.program,
1827
+ lktGroup: t.lktGroup,
1828
+ lktFormat: t.lktFormat,
1829
+ method: a,
1830
+ term: 0,
1831
+ warranty: "",
1832
+ items: n,
1833
+ ...r
1834
+ });
1835
+ }
1836
+ };
1837
+ }
1838
+ function he(e, t) {
1839
+ let n = h(e, t.program);
1840
+ if (!n || n.type === "DINH_KY") return [];
1841
+ let r = n.type === "LKT" ? h(e, b(e, t.lktGroup)?.baseProgram) : n, i = n.type === "LKT" ? x(e, t.label, t.lktGroup).find((e) => L(e.format, t.lktFormat))?.cut ?? 0 : 0, a = e.settings.labels.find((e) => L(e.name, t.label))?.blockedMethods ?? [], o = q(e, t.label, r), s = [];
1842
+ for (let t of e.settings.paymentMethods) {
1843
+ if (a.some((e) => L(e, t.name))) continue;
1844
+ let e = o.filter((e) => L(e.method, t.name)).sort((e, t) => e.term - t.term);
1845
+ for (let n of e) {
1846
+ let e = s.at(-1);
1847
+ e && e.method === t.name && Math.abs(e.basePct - n.pct) < 1e-9 ? e.terms.push(Number(n.term)) : s.push({
1848
+ method: t.name,
1849
+ terms: [Number(n.term)],
1850
+ basePct: n.pct,
1851
+ pm: t
1852
+ });
1853
+ }
1410
1854
  }
1411
- function K() {
1412
- let e = s.querySelector("#pt-admin-table");
1413
- if (!e) return;
1414
- let t = a.admin, n = j(A()).find((e) => e.id === t.tab), r = P(n), i = t.q.trim().toLowerCase(), o = t.issues.filter((e) => e.table === n.id), c = new Set(o.map((e) => e.row)), l = r.map((e, t) => ({
1415
- r: e,
1416
- i: t
1417
- })).filter(({ r: e }) => !n.byLabel || !t.label || W(e.label, t.label)).filter(({ r: e }) => !i || n.columns.some((t) => String(M(t, e[t.key])).toLowerCase().includes(i))), u = (e, t, n) => {
1418
- let r = t[e.key], i = `data-edit="${n}" data-k="${e.key}"`;
1419
- if (e.type === "bool") return `<input type="checkbox" ${r ? "checked" : ""} ${i} style="width:18px;height:18px;accent-color:var(--pt-purple)">`;
1420
- if (e.type === "select") return `<select class="pt-select" ${i}>${(e.options.includes(r) || r === "" ? e.options : [r, ...e.options]).map((e) => `<option ${e === r ? "selected" : ""}>${B(e)}</option>`).join("")}</select>`;
1421
- let a = [
1422
- "money",
1423
- "pct",
1424
- "int"
1425
- ].includes(e.type);
1426
- return `<input class="pt-input ${a ? "num" : ""} ${e.wide ? "w-wide" : ""}" ${a ? "inputmode=\"decimal\"" : ""} value="${B(M(e, r))}" ${i}>`;
1855
+ return s.map((e) => {
1856
+ let t = e.terms.filter(Boolean), n = e.pm.allowSingle ? "Đóng Full" : t.length ? `Trả góp ${e.method}` : e.pm.promoLabel || e.method;
1857
+ return {
1858
+ id: `${e.method}|${e.terms.join("-")}`,
1859
+ method: e.method,
1860
+ term: Math.min(...e.terms),
1861
+ pct: e.basePct - i,
1862
+ title: `${n}${t.length ? ` ${t.join(" & ")} tháng` : ""}`
1427
1863
  };
1428
- s.querySelector("#pt-issues").innerHTML = o.length ? `<ul class="pt-issues">${o.map((e) => `<li>Dòng ${e.row + 1}: ${B(e.message)}</li>`).join("")}</ul>` : "", e.innerHTML = `<table class="pt-table pt-table--edit">
1429
- <thead><tr><th class="pt-rowno">#</th>${n.columns.map((e) => `<th class="${[
1430
- "money",
1431
- "pct",
1432
- "int"
1433
- ].includes(e.type) ? "num" : ""}">${e.label}</th>`).join("")}<th></th></tr></thead>
1434
- <tbody>${l.map(({ r: e, i: t }) => `<tr class="${c.has(t) ? "has-issue" : ""}"><td class="pt-rowno">${t + 1}</td>${n.columns.map((n) => `<td>${u(n, e, t)}</td>`).join("")}
1435
- <td><button class="pt-icon-btn is-danger" title="Xóa dòng" data-act="row-del" data-i="${t}">${O("trash", 15)}</button></td></tr>`).join("") || `<tr><td colspan="${n.columns.length + 2}" class="pt-empty">Chưa có dữ liệu</td></tr>`}</tbody></table>`;
1864
+ });
1865
+ }
1866
+ function ge(e, t) {
1867
+ let n = he(e, t), r = [];
1868
+ for (let t of [...new Set(n.map((e) => e.method))]) {
1869
+ let i = n.filter((e) => e.method === t), a = g(e, t);
1870
+ a?.allowSingle ? r.push(...i) : i.some((e) => e.term > 0) && r.push(...i.slice(a?.citime ? -2 : -1));
1436
1871
  }
1437
- async function q() {
1438
- let e = A(), t = E(e);
1439
- if (a.admin.issues = t, t.length && !confirm(`Có ${t.length} cảnh báo dữ liệu (trùng khóa, giá ≤ 0...). Vẫn lưu?`)) {
1440
- let e = t[0];
1441
- a.admin.tab = e.table, c();
1442
- } else try {
1443
- e.updatedAt = (/* @__PURE__ */ new Date()).toISOString(), i && (e.updatedBy = i.email ?? i.name ?? ""), await n.save(e), a.data = b(z(e)), a.admin.draft = null, a.admin.dirty = !1, a.admin.issues = [], Y("Đã lưu — sale sẽ thấy giá mới ngay"), c();
1444
- } catch (e) {
1445
- Y(`Lưu thất bại: ${e.message}`);
1446
- }
1872
+ return r.map((e) => e.id);
1873
+ }
1874
+ function _e(e, t, n, r) {
1875
+ let i = g(e, n), a = e.gifts.filter((e) => L(e.label, t.label) && L(e.program, t.program) && L(e.method, i?.giftGroup ?? n)), o = Math.max(0, ...e.gifts.filter((e) => L(e.label, t.label) && L(e.program, t.program)).map((e) => e.milestone));
1876
+ return a.find((e) => Number(e.milestone) === Math.min(r, o)) ?? null;
1877
+ }
1878
+ function ve(e, t) {
1879
+ let n = e.settings.labels.find((e) => L(e.name, t.label))?.blockedMethods ?? [], r = e.settings.paymentMethods.filter((e) => !n.some((t) => L(t, e.name)));
1880
+ return [...r.filter((e) => !e.giftCondition), ...r.filter((e) => e.giftCondition)];
1881
+ }
1882
+ function q(e, t, n) {
1883
+ return n ? (n.type === "DAC_BIET" ? e.special : n.type === "MO_RONG" ? e.extended.filter((e) => L(e.program, n.name)) : []).filter((e) => L(e.label, t)) : [];
1884
+ }
1885
+ function ye(e, t) {
1886
+ let n = [], r = t.prog?.type, i = 0;
1887
+ if (r === "DINH_KY") i = Math.max(0, ...e.periodic.filter((e) => L(e.label, t.label)).map((e) => e.pct));
1888
+ else if (r === "LKT") {
1889
+ let n = h(e, b(e, t.lktGroup)?.baseProgram), r = x(e, t.label, t.lktGroup).map((e) => e.cut);
1890
+ r.length && (i = Math.max(0, ...q(e, t.label, n).map((e) => e.pct)) - Math.min(...r));
1891
+ } else i = Math.max(0, ...q(e, t.label, t.prog).map((e) => e.pct));
1892
+ if (i > 0 && n.push({
1893
+ big: B(i),
1894
+ text: "mức giảm học phí cao nhất"
1895
+ }), r === "DINH_KY") {
1896
+ let r = Math.max(0, ...e.periodic.filter((e) => L(e.label, t.label)).map((e) => e.cashback));
1897
+ r && n.push({
1898
+ big: z(r),
1899
+ text: `đồng hoàn tiền — ${String(e.settings.docTexts?.cashbackLabel ?? "").toLowerCase()}`
1900
+ });
1447
1901
  }
1448
- let J;
1449
- function Y(t) {
1450
- let n = document.querySelector(".pt-root .pt-toast");
1451
- n || (n = document.createElement("div"), n.className = "pt-toast", e.appendChild(n)), n.textContent = t, clearTimeout(J), J = setTimeout(() => n.remove(), 2600);
1902
+ let a = Math.max(0, ...e.gifts.filter((e) => L(e.label, t.label) && L(e.program, t.program)).map((e) => e.value));
1903
+ a && n.push({
1904
+ big: z(a),
1905
+ text: "đồng — bộ quà tặng giá trị nhất"
1906
+ });
1907
+ let o = 0;
1908
+ for (let n of v(e, t.label)) for (let e of n.modes) o = Math.max(o, t.q([{
1909
+ code: n.code,
1910
+ mode: e
1911
+ }]).lines[0]?.voucher ?? 0);
1912
+ return o && n.length < 3 && n.push({
1913
+ big: z(o),
1914
+ text: "đồng voucher khóa học đặc biệt"
1915
+ }), n.slice(0, 3);
1916
+ }
1917
+ function be(e, t, n, r) {
1918
+ let i = e.settings, a = t?.month || String(i.validFrom ?? "").slice(0, 7), o = String(i.validFrom ?? "").slice(0, 7), s = !!(a && o && a !== o), [c, l] = s ? de(a) : [i.validFrom, i.validTo], u = s ? c : i.validFrom, d = s ? l : i.validTo, f = i.campaignName || "";
1919
+ s && f && (f = f.replace(/tháng\s*\d+(\/\d+)?/gi, `tháng ${ue(e, a)}`));
1920
+ let p = ye(e, t), m = he(e, t).length;
1921
+ return {
1922
+ cls: "cover",
1923
+ html: `<div class="cv-l">
1924
+ <div class="kick">Chương trình khuyến mãi · Tháng ${ue(e, a)}</div>
1925
+ <div class="cv-main">
1926
+ ${n.logoUrl ? `<img class="cv-logo" src="${R(re(n.logoUrl))}" alt="${R(n.brandName)}">` : `<div class="cv-brand">${R(n.brandName)}</div>`}
1927
+ <div class="cv-title">${R(r)}</div>
1928
+ <div class="cv-date">Áp dụng từ ${H(u)} đến ${H(d)}</div>
1929
+ </div>
1930
+ </div>
1931
+ <div class="cv-r">
1932
+ ${f ? `<div class="cv-theme">${R(f)}</div>` : ""}
1933
+ <div class="cv-prog">${R(t.program)}</div>
1934
+ <div class="cv-scope">${t.periodic ? "Áp dụng cho toàn bộ hình thức thanh toán" : m ? `${m} mức ưu đãi theo tiến độ thanh toán` : ""}</div>
1935
+ <div class="cv-hl">${p.map((e) => `<div><b>${R(e.big)}</b><span>${R(e.text)}</span></div>`).join("")}</div>
1936
+ </div>`
1937
+ };
1938
+ }
1939
+ function xe(e, t) {
1940
+ let n = v(e, t.label);
1941
+ if (!n.length) return null;
1942
+ let r = n.map((n) => {
1943
+ let r = e.courses.find((e) => L(e.label, t.label) && L(e.code, n.code) && L(e.mode, "Offline")), i = e.courses.find((e) => L(e.label, t.label) && L(e.code, n.code) && L(e.mode, "Online")), a = r ?? i, o = t.q([{
1944
+ code: n.code,
1945
+ mode: a.mode
1946
+ }]);
1947
+ return [
1948
+ {
1949
+ html: `<b>${R(n.name)}</b>`,
1950
+ cls: "left"
1951
+ },
1952
+ R(n.code),
1953
+ R(a.sessions || i?.sessions || ""),
1954
+ R(r?.classSize || "—"),
1955
+ R(i?.classSize || "—"),
1956
+ z(a.price),
1957
+ o.lines[0]?.voucher ? `-${z(o.lines[0].voucher)}` : "—",
1958
+ {
1959
+ html: o.ok ? z(o.afterPromo) : "Không áp dụng",
1960
+ cls: "hot"
1961
+ }
1962
+ ];
1963
+ });
1964
+ return {
1965
+ kick: "Bảng giá",
1966
+ h: "Học phí từng khóa học",
1967
+ sub: `${t.program} · giá đăng ký 1 khóa, đóng full học phí, tính theo lớp Offline nếu có`,
1968
+ html: W({
1969
+ head: [G({
1970
+ html: "Khóa học",
1971
+ cls: "left"
1972
+ }, "Mã khóa", "Thời lượng", "Sĩ số Offline", "Sĩ số Online", "Giá gốc", "Voucher", {
1973
+ html: "Giá sau khuyến mại",
1974
+ cls: "hot"
1975
+ })],
1976
+ rows: r,
1977
+ merge: [3, 4]
1978
+ })
1979
+ };
1980
+ }
1981
+ function Se(e) {
1982
+ return e.applyType === "TOAN_BO" ? "Toàn bộ các khóa học" : e.applyType === "LO_TRINH_CU_THE" ? "Theo từng combo có bảng thông tin kèm theo (phụ lục Citime)" : `Combo từ ${Number(e.minCourses) || 2} khoá trở lên`;
1983
+ }
1984
+ function Ce(e, t, n) {
1985
+ let r = [];
1986
+ for (let n of v(e, t.label)) for (let e of n.modes) {
1987
+ let i = t.q([{
1988
+ code: n.code,
1989
+ mode: e
1990
+ }]).lines[0]?.voucher ?? 0;
1991
+ i > 0 && r.push([{
1992
+ html: `${R(n.name)}${n.modes.length > 1 ? ` <span class="muted">${R(e)}</span>` : ""}`,
1993
+ cls: "left"
1994
+ }, {
1995
+ html: `${z(i)}đ`,
1996
+ cls: "hot"
1997
+ }]);
1452
1998
  }
1453
- async function X(e) {
1454
- try {
1455
- await navigator.clipboard.writeText(e);
1456
- } catch {
1457
- let t = Object.assign(document.createElement("textarea"), { value: e });
1458
- document.body.appendChild(t), t.select(), document.execCommand("copy"), t.remove();
1999
+ if (!r.length) return "";
2000
+ let i = (e) => W({
2001
+ head: [G({
2002
+ html: "Khóa học",
2003
+ cls: "left"
2004
+ }, {
2005
+ html: "Voucher giảm thêm",
2006
+ cls: "hot"
2007
+ })],
2008
+ rows: e,
2009
+ cls: "t-tight"
2010
+ }), a = Math.ceil(r.length / 2);
2011
+ return `<div class="sec">Quà tặng khóa học đặc biệt</div>${n ? `<div class="cols2">${i(r.slice(0, a))}${i(r.slice(a))}</div>` : i(r)}`;
2012
+ }
2013
+ function we(e, t) {
2014
+ let n = (e.settings.programRules ?? []).find((e) => L(e.label, t.label) && L(e.program, t.program)), r = String(n?.rules ?? "").split("\n").map((e) => e.trim()).filter(Boolean);
2015
+ return r.length ? `<div class="rules"><div class="rules-h">Quy định tham gia chương trình</div><ol>${r.map((e) => `<li>${R(e)}</li>`).join("")}</ol></div>` : "";
2016
+ }
2017
+ function Te(e, t) {
2018
+ let n = t.prog?.type;
2019
+ if (n === "DINH_KY") {
2020
+ let n = e.periodic.filter((e) => L(e.label, t.label)).sort((e, t) => e.from - t.from), r = "";
2021
+ if (n.length) {
2022
+ let t = Math.max(...n.map((e) => e.from)), i = [];
2023
+ for (let e = 1; e <= t; e++) {
2024
+ let r = n.find((t) => t.from <= e && t.to >= e), a = e === t ? "k" : e > t / 2 ? "y" : "";
2025
+ i.push(`<div class="card ${a}"><div class="no">${V(e)}</div><div class="nm">${U(e, r?.to >= 99 ? e : null)}</div>
2026
+ <div class="big">${r ? B(r.pct) : "—"}</div><div class="sm">${r?.cashback ? `Hoàn tiền ${z(r.cashback)}đ` : "Giảm trực tiếp học phí"}</div></div>`);
2027
+ }
2028
+ r = `<div class="cards" style="grid-template-columns:repeat(${t},1fr)">${i.join("")}</div>`, n.some((e) => e.cashback) && (r += `<p class="note">Hoàn tiền: ${R(e.settings.docTexts?.cashbackLabel ?? "")}.</p>`);
1459
2029
  }
2030
+ let i = Ce(e, t, !0), a = we(e, t);
2031
+ return !r && !i ? null : {
2032
+ kick: "Chương trình khuyến mại",
2033
+ h: "Ưu đãi Định kỳ theo số khóa đăng ký",
2034
+ sub: "Áp dụng cho toàn bộ hình thức thanh toán",
2035
+ html: r + i + a
2036
+ };
1460
2037
  }
1461
- function Z(e, t) {
1462
- let n = Object.assign(document.createElement("a"), {
1463
- href: URL.createObjectURL(new Blob([t], { type: "application/json" })),
1464
- download: e
2038
+ let r = "", i = "";
2039
+ if (n === "LKT") {
2040
+ let n = b(e, t.lktGroup), a = h(e, n?.baseProgram), o = x(e, t.label, t.lktGroup), s = q(e, t.label, a);
2041
+ n && o.length && s.length && (r = W({
2042
+ head: [G("Hình thức thanh toán", "Tiến độ", `% ${R(a.name)}`, ...o.map((e) => ({
2043
+ html: `${R(e.format)}<br><small>cắt ${B(e.cut)}</small>`,
2044
+ cls: "hot"
2045
+ })))],
2046
+ rows: s.map((t) => [
2047
+ R(g(e, t.method)?.promoLabel || t.method),
2048
+ Number(t.term) ? `${t.term} tháng` : "—",
2049
+ B(t.pct),
2050
+ ...o.map((e) => ({
2051
+ html: B(t.pct - e.cut),
2052
+ cls: "hot"
2053
+ }))
2054
+ ]),
2055
+ merge: [0],
2056
+ cls: "t-tight"
2057
+ }), i = `${R(n.name)}: % giảm = % chương trình ${R(a.name)} trừ mức cắt của format liên kết trường.`);
2058
+ } else {
2059
+ let n = e.settings.labels.find((e) => L(e.name, t.label))?.blockedMethods ?? [], i = e.settings.paymentMethods.map((e) => e.name), a = q(e, t.label, t.prog).filter((e) => !n.some((t) => L(t, e.method))).sort((e, t) => i.indexOf(e.method) - i.indexOf(t.method) || e.term - t.term);
2060
+ a.length && (r = W({
2061
+ head: [G("STT", "Hình thức thanh toán", "Tiến độ", {
2062
+ html: "Mức ưu đãi",
2063
+ cls: "hot"
2064
+ }, "Khóa học áp dụng")],
2065
+ rows: a.map((t, n) => [
2066
+ String(n + 1),
2067
+ R(g(e, t.method)?.promoLabel || t.method),
2068
+ {
2069
+ html: Number(t.term) ? `${t.term} tháng` : "—",
2070
+ cls: "nw"
2071
+ },
2072
+ {
2073
+ html: B(t.pct),
2074
+ cls: "hot"
2075
+ },
2076
+ R(Se(t))
2077
+ ]),
2078
+ merge: [
2079
+ 1,
2080
+ 3,
2081
+ 4
2082
+ ],
2083
+ cls: "t-promo"
2084
+ }));
2085
+ }
2086
+ let a = Ce(e, t, !1);
2087
+ return !r && !a ? null : {
2088
+ kick: "Chương trình khuyến mại",
2089
+ h: `Ưu đãi ${t.program} theo tiến độ thanh toán`,
2090
+ sub: "Áp dụng cho toàn bộ khách hàng",
2091
+ html: `<div class="cols2 top" style="grid-template-columns:1.35fr 1fr"><div><div class="sec">Mức ưu đãi</div>${r}${i ? `<p class="note">${i}</p>` : ""}</div><div>${a}</div></div>${we(e, t)}`
2092
+ };
2093
+ }
2094
+ function Ee(e, t) {
2095
+ let n = e.gifts.filter((e) => L(e.label, t.label) && L(e.program, t.program));
2096
+ if (!n.length) return null;
2097
+ let r = Math.max(...n.map((e) => e.milestone)), i = ve(e, t), a = [{
2098
+ html: "Khóa học",
2099
+ rowspan: 2,
2100
+ cls: "left"
2101
+ }], o = [];
2102
+ i.forEach((e) => {
2103
+ e.giftCondition ? (a.push({
2104
+ html: R(e.docLabel),
2105
+ colspan: 2
2106
+ }), o.push({ html: "Quà tặng" }, { html: "Điều kiện" })) : a.push({
2107
+ html: R(e.docLabel),
2108
+ rowspan: 2
1465
2109
  });
1466
- n.click(), setTimeout(() => URL.revokeObjectURL(n.href), 1e3);
2110
+ });
2111
+ let s = [];
2112
+ for (let n = 1; n <= r; n++) {
2113
+ let a = [{
2114
+ html: `<b>${U(n, r)}</b>`,
2115
+ cls: "left"
2116
+ }];
2117
+ for (let r of i) {
2118
+ let i = _e(e, t, r.name, n);
2119
+ a.push(n === 1 && !r.allowSingle ? {
2120
+ html: "Không áp dụng",
2121
+ cls: "muted"
2122
+ } : i ? R(i.content) : {
2123
+ html: "—",
2124
+ cls: "muted"
2125
+ }), r.giftCondition && a.push(i ? R(r.giftCondition) : {
2126
+ html: "—",
2127
+ cls: "muted"
2128
+ });
2129
+ }
2130
+ s.push(a);
1467
2131
  }
1468
- e.addEventListener("click", async (t) => {
1469
- let r = t.target.closest("[data-act]");
1470
- if (!r || !e.contains(r) || r.disabled) return;
1471
- let i = r.dataset.act, o = a.admin;
1472
- switch (i) {
1473
- case "view":
1474
- a.view = r.dataset.v;
1475
- break;
1476
- case "role":
1477
- a.role = r.dataset.v;
1478
- break;
1479
- case "calc":
1480
- w(a.calc, r.dataset.f, r.dataset.v);
1481
- break;
1482
- case "toggle": {
1483
- let e = r.dataset.code;
1484
- a.calc.selected[e] ? delete a.calc.selected[e] : a.calc.selected[e] = h(a.data, a.calc.label).find((t) => W(t.code, e))?.modes[0];
1485
- break;
1486
- }
1487
- case "mode":
1488
- t.stopPropagation(), a.calc.selected[r.dataset.code] = r.dataset.v;
1489
- break;
1490
- case "clear-courses":
1491
- a.calc.selected = {};
1492
- break;
1493
- case "reset-calc":
1494
- a.calc = l(a.data);
1495
- break;
1496
- case "copy":
1497
- await X(D()), Y("Đã sao chép báo giá — dán vào Zalo/Messenger để gửi khách");
1498
- return;
1499
- case "tbl-reset":
1500
- a.table = {
1501
- ...l(a.data),
1502
- output: ""
1503
- };
1504
- break;
1505
- case "open-route": {
1506
- let e = a.table, t = a.data.routes.find((t) => W(t.label, e.label) && W(t.code, r.dataset.code));
1507
- a.calc = {
1508
- ...e,
1509
- selected: Object.fromEntries(t.items.map((e) => [e.code, e.mode]))
1510
- }, delete a.calc.output, a.view = "calc";
1511
- break;
1512
- }
1513
- case "admin-tab":
1514
- o.tab = r.dataset.v, o.q = "";
1515
- break;
1516
- case "row-add": {
1517
- let e = j(A()).find((e) => e.id === o.tab);
1518
- P(e).push(e.blank(o.label || A().settings.labels[0]?.name || "")), o.q = "", L(), K();
1519
- let t = s.querySelector("#pt-admin-table tbody tr:last-child");
1520
- t?.scrollIntoView({
1521
- block: "center",
1522
- behavior: "smooth"
1523
- }), t?.querySelector("input,select")?.focus();
1524
- return;
1525
- }
1526
- case "row-del": {
1527
- let e = j(A()).find((e) => e.id === o.tab);
1528
- P(e).splice(Number(r.dataset.i), 1), o.issues = [], L(), K();
1529
- return;
2132
+ return {
2133
+ kick: "Quà tặng",
2134
+ h: "Quà tặng theo hình thức thanh toán",
2135
+ sub: `${t.program} · quà theo số khóa đăng ký`,
2136
+ html: W({
2137
+ head: o.length ? [a, o] : [a],
2138
+ rows: s,
2139
+ merge: s[0].map((e, t) => t).slice(1),
2140
+ cls: "t-tall"
2141
+ })
2142
+ };
2143
+ }
2144
+ function De(e, t) {
2145
+ let n = new Set(e.gifts.filter((e) => L(e.label, t.label) && L(e.program, t.program)).map((e) => Number(e.value))), r = (e.settings.giftSets ?? []).filter((e) => L(e.label, t.label) && (!n.size || n.has(Number(e.value))));
2146
+ return !r.length || !n.size ? null : (r.sort((e, t) => e.value - t.value), {
2147
+ kick: "Quà tặng",
2148
+ h: "Bộ quà tặng giá trị dành cho học viên",
2149
+ sub: "Nội dung từng bộ quà trong bảng quà tặng theo hình thức thanh toán",
2150
+ html: `<div class="cards sets" style="grid-template-columns:repeat(${r.length > 6 ? 4 : 3},1fr)">${r.map((e, t) => `<div class="card ${t === r.length - 1 ? "k" : t % 3 == 1 ? "y" : ""}"><div class="no">Bộ quà ${V(t + 1)}</div>
2151
+ <div class="big sm2">${z(e.value)}đ</div><ul>${String(e.items).split("\n").filter(Boolean).map((e) => `<li>${R(e)}</li>`).join("")}</ul></div>`).join("")}</div>`
2152
+ });
2153
+ }
2154
+ function Oe(e, t) {
2155
+ let n = e.settings.docTexts ?? {}, r = e.warranty.filter((e) => e.rate > 0), i = (e.settings.services ?? []).filter((e) => L(e.label, t.label));
2156
+ if (!r.length && !i.length) return null;
2157
+ let a = v(e, t.label).filter((e) => e.warranty === !1).map((e) => e.name);
2158
+ return {
2159
+ kick: "Dịch vụ cộng thêm",
2160
+ h: "Gói bảo hành & dịch vụ học tập",
2161
+ sub: "Bán kèm lộ trình khi khách có nhu cầu",
2162
+ html: `<div class="cols2 top"><div>${r.length ? `<div class="sec">Gói bảo hành</div>
2163
+ <div class="cards" style="grid-template-columns:repeat(${r.length},1fr)">${r.map((e, t) => `<div class="card ${t === r.length - 1 ? "k" : t ? "y" : ""}"><div class="no">Bảo hành</div><div class="nm">${R(e.name)}</div>
2164
+ <div class="big">${B(e.rate)}</div><div class="sm">giá gốc khóa học / combo</div></div>`).join("")}</div>
2165
+ <p class="note">Thời lượng: ${R(n.warrantyDuration)} · Hình thức: ${R(n.warrantyForm)}.${a.length ? `<br>Không tính phí bảo hành với các khóa ${R(a.join(", "))}.` : ""}</p>` : ""}</div><div>${i.length ? `<div class="sec">Dịch vụ học tập</div>${W({
2166
+ head: [G({
2167
+ html: "Sản phẩm",
2168
+ cls: "left"
2169
+ }, "Thời lượng", "Hình thức", {
2170
+ html: "Giá gốc",
2171
+ cls: "hot"
2172
+ })],
2173
+ rows: i.map((e) => [
2174
+ {
2175
+ html: R(e.name),
2176
+ cls: "left"
2177
+ },
2178
+ R(e.duration),
2179
+ R(e.mode),
2180
+ {
2181
+ html: z(e.price),
2182
+ cls: "hot"
2183
+ }
2184
+ ])
2185
+ })}` : ""}</div></div>`
2186
+ };
2187
+ }
2188
+ function ke(e, t, n, r) {
2189
+ let i = e.routes.filter((e) => L(e.label, t.label) && L(e.output, n));
2190
+ if (!i.length) return [];
2191
+ let a = e.warranty.filter((e) => e.rate > 0), o = e.warranty.find((e) => !(e.rate > 0)), s = [...new Set(i.map((e) => e.items.length))].sort((e, t) => e - t), c = e.settings.docTexts?.routeNote ? `<p class="note">* ${R(e.settings.docTexts.routeNote)}</p>` : "", l = (e, t) => ({
2192
+ kick: `Lộ trình gợi ý · Đầu ra ${n}`,
2193
+ h: `Bảng giá lộ trình đầu ra IELTS ${n}`,
2194
+ sub: e,
2195
+ html: t + c
2196
+ });
2197
+ if (t.periodic) {
2198
+ let n = ve(e, t).filter((e) => !e.citime), r = n.some((n) => i.some((r) => _e(e, t, n.name, r.items.length))), o = [G({
2199
+ html: "Lộ trình",
2200
+ cls: "left"
2201
+ }, "Giá gốc", {
2202
+ html: "Giá sau ưu đãi",
2203
+ cls: "hot"
2204
+ }, ...a.map((e) => `+ BH ${R(e.name)}<br><small>${B(e.rate)}</small>`), ...r ? n.map((e) => `Quà ${ce(e.docShort.replace(/^Đóng |^Trả /, (e) => e.toLowerCase()))}`) : [])], c = [];
2205
+ for (let o of s) {
2206
+ c.push({ group: U(o) });
2207
+ for (let s of i.filter((e) => e.items.length === o)) {
2208
+ let i = t.q(s.items);
2209
+ c.push([
2210
+ {
2211
+ html: R(s.name),
2212
+ cls: "left"
2213
+ },
2214
+ z(i.gross),
2215
+ i.ok ? {
2216
+ html: z(i.afterPromo),
2217
+ cls: "hot"
2218
+ } : {
2219
+ html: "Không áp dụng",
2220
+ cls: "muted"
2221
+ },
2222
+ ...a.map((e) => i.ok ? z(t.q(s.items, { warranty: e.name }).final) : "—"),
2223
+ ...r ? n.map((n) => {
2224
+ let r = _e(e, t, n.name, o);
2225
+ return r ? {
2226
+ html: R(r.content),
2227
+ key: `${o}|${n.name}|${r.content}`,
2228
+ cls: "gift"
2229
+ } : {
2230
+ html: "—",
2231
+ key: `${o}|${n.name}|-`,
2232
+ cls: "muted"
2233
+ };
2234
+ }) : []
2235
+ ]);
1530
2236
  }
1531
- case "save":
1532
- await q();
1533
- return;
1534
- case "discard":
1535
- o.draft = null, o.dirty = !1, o.issues = [];
1536
- break;
1537
- case "export-json":
1538
- Z(`du-lieu-khuyen-mai-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.json`, JSON.stringify(A(), null, 1));
1539
- return;
1540
- case "reset-seed":
1541
- if (!confirm("Thay toàn bộ dữ liệu bằng bản gốc nhập từ file Excel ban đầu? (chưa lưu cho tới khi bấm Lưu)")) return;
1542
- o.draft = await n.reset(), L(), o.dirty = !0;
1543
- break;
1544
- default: return;
1545
2237
  }
1546
- c();
1547
- }), e.addEventListener("keydown", (e) => {
1548
- let t = e.target.closest("[data-act=\"toggle\"]");
1549
- t && (e.key === " " || e.key === "Enter") && e.target === t && (e.preventDefault(), t.click());
1550
- }), e.addEventListener("change", async (e) => {
1551
- let t = e.target, n = a.admin;
1552
- if (t.dataset.edit != null) {
1553
- let e = j(A()).find((e) => e.id === n.tab), r = e.columns.find((e) => e.key === t.dataset.k);
1554
- P(e)[Number(t.dataset.edit)][r.key] = r.type === "bool" ? t.checked : N(r, t.value), r.type !== "bool" && r.type !== "select" && (t.value = M(r, P(e)[Number(t.dataset.edit)][r.key])), L();
1555
- } else {
1556
- switch (t.dataset.act) {
1557
- case "setting":
1558
- A().settings[t.dataset.k] = t.value, L();
1559
- return;
1560
- case "tbl":
1561
- w(a.table, t.dataset.f, t.value), t.dataset.f === "label" && (a.table.output = "");
1562
- break;
1563
- case "pick-route": {
1564
- let e = a.data.routes.find((e) => W(e.label, a.calc.label) && W(e.code, t.value));
1565
- e && (a.calc.selected = Object.fromEntries(e.items.map((e) => [e.code, e.mode])));
1566
- break;
1567
- }
1568
- case "admin-label":
1569
- n.label = t.value, K();
1570
- return;
1571
- case "import-json":
1572
- case "import-xlsx": {
1573
- let e = t.files?.[0];
1574
- if (!e) return;
1575
- try {
1576
- let r = t.dataset.act === "import-json" ? JSON.parse(await e.text()) : await R(e, A());
1577
- if (!r?.settings || !Array.isArray(r.courses)) throw Error("File không đúng cấu trúc");
1578
- n.draft = b(r), n.issues = E(r), L(), n.dirty = !0, Y(`Đã nạp ${e.name} — kiểm tra rồi bấm Lưu & áp dụng`);
1579
- } catch (e) {
1580
- Y(`Không nhập được: ${e.message}`);
1581
- }
1582
- break;
2238
+ return [l(`${t.program} · áp dụng cho toàn bộ hình thức thanh toán`, W({
2239
+ head: o,
2240
+ rows: c,
2241
+ merge: r ? n.map((e, t) => 3 + a.length + t) : [],
2242
+ cls: "t-routes"
2243
+ }))];
2244
+ }
2245
+ let u = he(e, t), d = r?.length ? u.filter((e) => r.includes(e.id)) : u.filter((n) => ge(e, t).includes(n.id)), f = [];
2246
+ for (let e = 0; e < d.length; e += 2) {
2247
+ let n = d.slice(e, e + 2), r = [[
2248
+ {
2249
+ html: "Lộ trình",
2250
+ rowspan: 2,
2251
+ cls: "left"
2252
+ },
2253
+ {
2254
+ html: "Giá gốc",
2255
+ rowspan: 2
2256
+ },
2257
+ ...n.map((e) => ({
2258
+ html: `${R(e.title)} · Giảm ${B(e.pct)}`,
2259
+ colspan: 1 + a.length,
2260
+ cls: "hot"
2261
+ }))
2262
+ ], n.flatMap(() => [{
2263
+ html: `BH ${R(o?.name ?? "tiêu chuẩn")}`,
2264
+ cls: "hot"
2265
+ }, ...a.map((e) => ({ html: `+ BH ${R(e.name)}<br><small>${B(e.rate)}</small>` }))])], c = [];
2266
+ for (let e of s) {
2267
+ c.push({ group: U(e) });
2268
+ for (let r of i.filter((t) => t.items.length === e)) {
2269
+ let e = [{
2270
+ html: R(r.name),
2271
+ cls: "left"
2272
+ }, z(t.q(r.items).gross)];
2273
+ for (let i of n) {
2274
+ let n = t.q(r.items, {
2275
+ method: i.method,
2276
+ term: i.term
2277
+ });
2278
+ n.ok ? e.push({
2279
+ html: z(n.afterPromo),
2280
+ cls: "hot"
2281
+ }, ...a.map((e) => z(t.q(r.items, {
2282
+ method: i.method,
2283
+ term: i.term,
2284
+ warranty: e.name
2285
+ }).final))) : e.push(...Array(1 + a.length).fill(0).map(() => ({
2286
+ html: "x",
2287
+ cls: "muted"
2288
+ })));
1583
2289
  }
1584
- default: return;
2290
+ c.push(e);
1585
2291
  }
1586
- c();
1587
2292
  }
1588
- }), e.addEventListener("input", (e) => {
1589
- e.target.dataset.act === "admin-q" && (a.admin.q = e.target.value, K());
2293
+ f.push(l(`${t.program} · ${n.map((e) => e.title).join(" và ")} · "x" = lộ trình không áp dụng hình thức này`, W({
2294
+ head: r,
2295
+ rows: c,
2296
+ cls: "t-routes"
2297
+ })));
2298
+ }
2299
+ return f;
2300
+ }
2301
+ function Ae(e, t) {
2302
+ let n = e.settings.paymentMethods.find((e) => e.citime), r = e.settings.labels.find((e) => L(e.name, t.label))?.blockedMethods ?? [];
2303
+ if (!n || r.some((e) => L(e, n.name))) return null;
2304
+ let i = new Set(e.settings.courseCodes.filter((e) => /^M[AB]$/.test(e.short)).map((e) => e.short)), a = e.citimeRoutes.filter((e) => L(e.label, t.label) && L(e.status, "Áp dụng") && !String(e.code).split("_").some((e) => i.has(e)));
2305
+ if (!a.length) return null;
2306
+ let o = [...new Set(a.map((e) => e.group))], s = o.map((e) => {
2307
+ let t = [], n = a.filter((t) => t.group === e);
2308
+ for (let e of [...new Set(n.map((e) => e.count))].sort((e, t) => e - t)) t.push({ group: U(e) }), n.filter((t) => t.count === e).forEach((e) => t.push([{
2309
+ html: R(e.name),
2310
+ cls: "left"
2311
+ }, {
2312
+ html: `${e.maxTerm} tháng`,
2313
+ cls: "hot"
2314
+ }]));
2315
+ return `<div><div class="sec">${R(e)}</div>${W({
2316
+ head: [G({
2317
+ html: "Lộ trình",
2318
+ cls: "left"
2319
+ }, {
2320
+ html: "Kỳ hạn tối đa",
2321
+ cls: "hot"
2322
+ })],
2323
+ rows: t,
2324
+ cls: "t-tight"
2325
+ })}</div>`;
1590
2326
  });
1591
- let Q = (e) => {
1592
- a.admin.dirty && e.preventDefault();
2327
+ return {
2328
+ kick: "Phụ lục",
2329
+ h: "Thời hạn trả góp Citime tối đa theo lộ trình",
2330
+ sub: `Kỳ hạn Citime: ${n.terms.join(" / ")} tháng`,
2331
+ html: `<div class="cols2 top" style="grid-template-columns:repeat(${Math.min(o.length, 3)},1fr)">${s.join("")}</div>${e.settings.docTexts?.citimeNote ? `<p class="note warn">Lưu ý: ${R(e.settings.docTexts.citimeNote)}</p>` : ""}`
1593
2332
  };
1594
- return window.addEventListener("beforeunload", Q), c(), {
1595
- setRole(e) {
1596
- a.role = e, c();
2333
+ }
2334
+ function je(e, t = {}) {
2335
+ let n = K(e, t), r = pe(e, t.label), i = new Set(t.sections ?? le.map((e) => e.id)), a = t.title || fe(e, t.label, t.month), o = [], s = (e, t) => i.has(e) && t && o.push(t);
2336
+ if (s("cover", be(e, n, r, a)), s("courses", xe(e, n)), s("promo", Te(e, n)), s("gifts", Ee(e, n)), s("giftSets", De(e, n)), s("services", Oe(e, n)), i.has("routes")) for (let r of t.outputs?.length ? t.outputs : me(e, t.label)) for (let i of ke(e, n, r, t.scenarios)) s("routes", i);
2337
+ return s("citime", Ae(e, n)), {
2338
+ html: Ie({
2339
+ data: e,
2340
+ brand: r,
2341
+ title: a,
2342
+ pages: o,
2343
+ ctx: n
2344
+ }),
2345
+ pages: o.length,
2346
+ title: a
2347
+ };
2348
+ }
2349
+ var Me = (e) => String(e || "#000").replace("#", "").padEnd(6, "0"), Ne = (e) => [
2350
+ 0,
2351
+ 2,
2352
+ 4
2353
+ ].map((t) => parseInt(Me(e).slice(t, t + 2), 16)), J = (e) => {
2354
+ let [t, n, r] = Ne(e).map((e) => e / 255);
2355
+ return .2126 * t + .7152 * n + .0722 * r;
2356
+ }, Pe = (e, t, n) => `#${Ne(e).map((e, r) => Math.round(e + (Ne(t)[r] - e) * n).toString(16).padStart(2, "0")).join("")}`, Fe = (e) => `<svg class="${e}" viewBox="0 0 400 220" preserveAspectRatio="none" aria-hidden="true">
2357
+ <path d="M10 170 C 70 60, 130 60, 170 120 S 260 200, 300 110 S 370 20, 395 40" fill="none" stroke="currentColor" stroke-width="26" stroke-linecap="round"/></svg>`;
2358
+ function Ie({ data: e, brand: t, title: n, pages: r, ctx: i }) {
2359
+ let a = e.settings, o = i?.month || String(a.validFrom ?? "").slice(0, 7), s = String(a.validFrom ?? "").slice(0, 7), c = !!(o && s && o !== s), [l, u] = c ? de(o) : [a.validFrom, a.validTo], d = c ? l : a.validFrom, f = c ? u : a.validTo, p = t.bg || "#F0C030", m = t.bg2 && J(t.bg2) > .9 ? t.bg2 : "#FFFCF2", h = t.ink || "#161513", g = t.onMain || (J(p) > .55 ? h : "#FFFFFF"), _ = String(t.gradient || "").split(",").map((e) => e.trim()).filter(Boolean), ee = _.length >= 2 ? `linear-gradient(165deg, ${[..._].reverse().join(", ")})` : p, v = String(t.font || "Be Vietnam Pro").trim(), y = `https://fonts.googleapis.com/css2?family=${encodeURIComponent(v).replace(/%20/g, "+")}:wght@400;500;600;700;800;900&display=swap`, b = t.accent && J(t.accent) < .35 ? t.accent : J(p) > .55 ? Pe(p, "#000000", .5) : p, x = t.neutral || Pe(m, "#8a7f5c", .1), S = t.slate || "#8a8577", C = t.motif === "wave", w = `${R(t.brandName)} · Chương trình khuyến mãi ${ue(e, o)} · ${H(d)} – ${H(f)}`, T = r.map((e, n) => e.cls === "cover" ? `<section class="page cover">${e.html}${C ? Fe("wave wave-cover") : ""}</section>` : `<section class="page">${C ? Fe("wave wave-page") : ""}<div class="inner">
2360
+ <div class="kick">${V(n)} · ${R(e.kick)}</div>
2361
+ <h2>${R(e.h)}</h2>${e.sub ? `<div class="sub">${R(e.sub)}</div>` : ""}
2362
+ <main>${e.html}</main></div>
2363
+ <footer>${t.logoLight ? `<img src="${R(re(t.logoLight))}" alt="">` : ""}<span>${w}</span><span>${String(t.footer || "").split("\n").map(R).join(" · ")}</span><b>${n + 1}</b></footer></section>`).join("");
2364
+ return `<!doctype html><html lang="vi"><head><meta charset="utf-8"><title>${R(n)}</title>
2365
+ <link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
2366
+ <link href="${R(y)}" rel="stylesheet">
2367
+ <style>
2368
+ @page { size: A4 landscape; margin: 0; }
2369
+ :root { --main-fill: ${ee}; --main: ${p}; --paper: ${m}; --ink: ${h}; --on-main: ${g}; --kick: ${b}; --accent: ${t.accent || "#C8102E"};
2370
+ --card: ${x}; --beige: ${Pe(x, "#FFFFFF", .55)}; --line: ${Pe(x, "#000000", .12)}; --tint: ${Pe(p, "#FFFFFF", .75)};
2371
+ --main2: ${Pe(p, "#FFFFFF", .3)}; --muted: ${S}; }
2372
+ * { box-sizing: border-box; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
2373
+ html, body { margin: 0; }
2374
+ body { font-family: '${R(v)}', 'Be Vietnam Pro', system-ui, sans-serif; color: var(--ink); background: #77746c; }
2375
+ .page { width: 297mm; height: 210mm; margin: 0 auto 14px; position: relative; overflow: hidden; background: var(--paper);
2376
+ break-after: page; page-break-after: always; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
2377
+ .page:last-child { break-after: auto; page-break-after: auto; }
2378
+ .page:not(.cover)::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5mm; background: var(--main-fill); }
2379
+ .inner { padding: 13mm 16mm 16mm 22mm; height: 100%; display: flex; flex-direction: column; }
2380
+ h2::after { content: ''; display: block; width: 46px; height: 4px; background: var(--kick); margin-top: 6px; border-radius: 2px; }
2381
+ .kick { font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--kick); }
2382
+ h2 { font-size: 30px; font-weight: 800; letter-spacing: -.015em; margin: 4px 0 2px; line-height: 1.15; }
2383
+ .sub { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
2384
+ main { flex: 1; }
2385
+ .sec { font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--kick); margin: 16px 0 7px; }
2386
+ main > .sec:first-child, .cols2 > div > .sec:first-child { margin-top: 2px; }
2387
+ .note { font-size: 11px; color: var(--muted); margin: 9px 0 0; line-height: 1.5; }
2388
+ .note.warn { color: var(--accent); }
2389
+ .muted { color: var(--muted); }
2390
+ .cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
2391
+ .cols2.top { align-items: start; gap: 22px; }
2392
+
2393
+ /* Bảng: tiêu đề nền tối, dòng xen kẽ, cột nhấn màu nhãn */
2394
+ .t { width: 100%; border-collapse: collapse; font-size: 11.5px; line-height: 1.35; background: #fff; }
2395
+ .t th { background: var(--ink); color: #fff; font-weight: 700; padding: 7px 9px; text-align: center; border: 1px solid var(--ink); }
2396
+ .t th.hot { color: var(--main); }
2397
+ .t th small { font-weight: 500; opacity: .8; }
2398
+ .t td { padding: 6px 9px; border: 1px solid var(--line); text-align: center; vertical-align: middle; }
2399
+ .t tbody tr:nth-child(even) td { background: var(--beige); }
2400
+ .t .left { text-align: left; }
2401
+ .t td.hot { background: var(--tint) !important; font-weight: 800; }
2402
+ .t td.gift { font-size: 10.5px; }
2403
+ .t tr.grp td { background: var(--ink) !important; color: var(--main); font-weight: 800; text-align: left; font-size: 10.5px;
2404
+ letter-spacing: .06em; text-transform: uppercase; padding: 4px 9px; }
2405
+ .t-routes { font-size: 10.5px; }
2406
+ .t-routes td, .t-routes th { padding: 4px 7px; }
2407
+ .t-tight td { padding: 4px 8px; }
2408
+ .t-tall td { padding: 11px 9px; }
2409
+ .t-promo td { padding: 5px 8px; }
2410
+ .t td.nw, .t-promo th { white-space: nowrap; }
2411
+ .rules { margin-top: 14px; background: var(--ink); color: #fff; padding: 12px 16px 12px; border-left: 6px solid var(--main); }
2412
+ .rules-h { font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--main); }
2413
+ .rules ol { margin: 6px 0 0; padding-left: 18px; font-size: 11.5px; line-height: 1.55; columns: 2; column-gap: 28px; }
2414
+ .rules li { break-inside: avoid; }
2415
+
2416
+ /* Thẻ: be viền trên tối · màu nhãn · tối */
2417
+ .cards { display: grid; gap: 10px; }
2418
+ .card { background: var(--card); border-top: 4px solid var(--ink); padding: 12px 13px 13px; min-height: 120px; display: flex; flex-direction: column; }
2419
+ .card.y { background: var(--main); border-top-color: var(--main); color: var(--on-main); }
2420
+ .card.k { background: var(--ink); border-top-color: var(--ink); color: #fff; }
2421
+ .card .no { font-size: 11px; font-weight: 800; color: var(--kick); letter-spacing: .04em; }
2422
+ .card.y .no { color: var(--on-main); opacity: .65; }
2423
+ .card.k .no, .card.k .nm { color: var(--main); }
2424
+ .card .nm { font-size: 15px; font-weight: 800; margin-top: 4px; }
2425
+ .card .big { font-size: 38px; font-weight: 900; letter-spacing: -.02em; margin-top: auto; line-height: 1.05; }
2426
+ .card .big.sm2 { font-size: 24px; margin-top: 6px; }
2427
+ .card .sm { font-size: 11.5px; margin-top: 4px; opacity: .9; font-weight: 600; }
2428
+ .card ul { margin: 8px 0 0; padding-left: 16px; font-size: 11.5px; line-height: 1.55; }
2429
+ .sets .card { min-height: 0; }
2430
+
2431
+ /* Bìa: mảng tối + mảng màu nhãn */
2432
+ .cover { display: grid; grid-template-columns: 68% 32%; }
2433
+ .cv-l { background: var(--ink); color: var(--paper); padding: 20mm 18mm 18mm 20mm; display: flex; flex-direction: column; }
2434
+ .cv-l .kick { color: var(--main); font-size: 13px; letter-spacing: .2em; }
2435
+ .cv-logo { height: 20mm; max-width: 150mm; object-fit: contain; object-position: left; display: block; }
2436
+ .cv-main { margin-top: auto; }
2437
+ .cv-brand { font-size: 64px; font-weight: 900; letter-spacing: -.02em; line-height: 1; }
2438
+ .cv-title { font-size: 19px; font-weight: 700; margin-top: 16px; color: var(--main); text-transform: uppercase; line-height: 1.3; }
2439
+ .cv-date { font-size: 15px; margin-top: 8px; opacity: .8; }
2440
+ .cv-r { background: var(--main-fill); color: var(--on-main); padding: 20mm 14mm 18mm; display: flex; flex-direction: column; }
2441
+ .cv-theme { font-size: 13px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 10px; opacity: .75; }
2442
+ .cv-prog { font-size: 34px; font-weight: 900; line-height: 1.05; letter-spacing: -.02em; }
2443
+ .cv-scope { font-size: 12.5px; font-weight: 600; margin-top: 8px; opacity: .8; }
2444
+ .cv-hl { margin-top: auto; display: grid; gap: 14px; }
2445
+ .cv-hl div { border-top: 3px solid ${J(g) > .6 ? "var(--main)" : "var(--ink)"}; padding: 8px 10px 9px;
2446
+ background: ${J(g) > .6 ? "var(--ink)" : "rgba(255,255,255,.55)"}; }
2447
+ .wave { position: absolute; pointer-events: none; color: var(--main); }
2448
+ .wave-cover { width: 118mm; height: 58mm; left: 96mm; top: 62mm; opacity: .95; }
2449
+ .wave-page { width: 72mm; height: 36mm; right: -16mm; top: -12mm; opacity: .9; }
2450
+ .cover { position: relative; }
2451
+ .inner { position: relative; z-index: 1; }
2452
+ .cv-hl b { display: block; font-size: 30px; font-weight: 900; letter-spacing: -.02em; }
2453
+ .cv-hl span { font-size: 12px; font-weight: 600; }
2454
+
2455
+ footer { position: absolute; left: 22mm; right: 16mm; bottom: 7mm; display: flex; gap: 18px; font-size: 10px; color: var(--muted); }
2456
+ footer { align-items: center; }
2457
+ footer img { height: 4.2mm; margin: -1mm 0; }
2458
+ footer span:nth-last-of-type(1) { flex: 1; text-align: right; }
2459
+ footer b { color: var(--ink); }
2460
+ @media print { body { background: none; } .page { margin: 0; box-shadow: none; } }
2461
+ </style>
2462
+ <script>
2463
+ // Trang nhiều dòng hơn khổ giấy (VD admin thêm lộ trình) → tự co nội dung cho vừa 1 trang thay vì tràn sang trang mới
2464
+ function fitPages() {
2465
+ document.querySelectorAll('.page .inner').forEach(function (inner) {
2466
+ inner.style.transform = ''; inner.style.width = ''; inner.style.height = '';
2467
+ var r = inner.clientHeight / inner.scrollHeight;
2468
+ if (r < 1) {
2469
+ inner.style.transformOrigin = '0 0'; inner.style.transform = 'scale(' + r + ')';
2470
+ inner.style.width = (100 / r) + '%'; inner.style.height = (100 / r) + '%';
2471
+ inner.dataset.fit = r.toFixed(3);
2472
+ }
2473
+ });
2474
+ }
2475
+ window.addEventListener('load', function () { (document.fonts ? document.fonts.ready : Promise.resolve()).then(fitPages); });
2476
+ <\/script></head><body>${T}</body></html>`;
2477
+ }
2478
+ // src/store.js
2479
+ var Le = (e) => JSON.parse(JSON.stringify(e)), Re = /^\d{4}-\d{2}$/, ze = (e) => [...new Set(e)].filter((e) => Re.test(e)).sort().reverse(), Be = (e) => String(e?.settings?.validFrom ?? "").slice(0, 7);
2480
+ function Ve(e) {
2481
+ let t = (e) => `edutalk-promo-tool:month:${e}`, n = "edutalk-promo-tool:months", r = (e) => {
2482
+ try {
2483
+ let t = localStorage.getItem(e);
2484
+ return t ? JSON.parse(t) : null;
2485
+ } catch {
2486
+ return null;
2487
+ }
2488
+ }, i = (e, t) => {
2489
+ try {
2490
+ localStorage.setItem(e, JSON.stringify(t));
2491
+ } catch {}
2492
+ }, a = () => ze(r(n) ?? []);
2493
+ if (!a().length) {
2494
+ let a = r("edutalk-promo-tool:data") ?? Le(e), o = Be(a);
2495
+ Re.test(o) && (i(t(o), a), i(n, [o]));
2496
+ }
2497
+ return {
2498
+ kind: "local",
2499
+ async listMonths() {
2500
+ return a();
1597
2501
  },
1598
- async reload() {
1599
- a.data = b(await n.load()), c();
2502
+ async load(e) {
2503
+ return r(t(e));
1600
2504
  },
1601
- destroy() {
1602
- window.removeEventListener("beforeunload", Q), e.innerHTML = "";
2505
+ async save(e, r) {
2506
+ i(t(e), r), i(n, ze([...a(), e]));
1603
2507
  },
1604
- unmount() {
1605
- this.destroy();
2508
+ async seed() {
2509
+ return Le(e);
1606
2510
  }
1607
2511
  };
1608
2512
  }
1609
- // src/vue/PromoTool.vue
1610
- var K = /* @__PURE__ */ t({
1611
- __name: "PromoTool",
1612
- props: {
1613
- role: { default: "sale" },
1614
- store: {},
1615
- user: { default: null },
1616
- allowRoleSwitch: {
1617
- type: Boolean,
1618
- default: !1
1619
- }
1620
- },
1621
- emits: ["ready"],
1622
- setup(t, { expose: s, emit: c }) {
1623
- let l = t, u = c, d = a(null), f = null;
1624
- return r(async () => {
1625
- d.value && (f = await G(d.value, {
1626
- role: l.role,
1627
- store: l.store,
1628
- user: l.user,
1629
- allowRoleSwitch: l.allowRoleSwitch
1630
- }), u("ready", f));
1631
- }), n(() => {
1632
- f && typeof f.destroy == "function" && f.destroy();
1633
- }), o(() => l.role, (e) => {
1634
- f && e && f.setRole(e);
1635
- }), s({
1636
- getInstance: () => f,
1637
- setRole: (e) => f?.setRole(e),
1638
- reload: () => f?.reload()
1639
- }), (t, n) => (i(), e("div", {
1640
- ref_key: "containerRef",
1641
- ref: d,
1642
- class: "pt-vue-container"
1643
- }, null, 512));
1644
- }
1645
- }), q = (e) => JSON.parse(JSON.stringify(e)), J = "edutalk-promo-tool:data";
1646
- function Y(e) {
1647
- return {
1648
- kind: "local",
1649
- async load() {
1650
- try {
1651
- let e = localStorage.getItem(J);
1652
- if (e) return JSON.parse(e);
1653
- } catch {}
1654
- return q(e);
1655
- },
1656
- async save(e) {
1657
- try {
1658
- localStorage.setItem(J, JSON.stringify(e));
1659
- } catch {}
1660
- },
1661
- async reset() {
1662
- try {
1663
- localStorage.removeItem(J);
1664
- } catch {}
1665
- return q(e);
1666
- }
1667
- };
1668
- }
1669
- function X(e, t, { key: n = "current" } = {}) {
2513
+ function He(e, t) {
1670
2514
  return {
1671
2515
  kind: "supabase",
1672
- async load() {
1673
- let { data: r, error: i } = await e.from("promo_config").select("data").eq("key", n).maybeSingle();
1674
- if (i) throw i;
1675
- return r?.data ?? q(t);
2516
+ async listMonths() {
2517
+ let { data: t, error: n } = await e.from("promo_config").select("key");
2518
+ if (n) throw n;
2519
+ return ze((t ?? []).map((e) => e.key));
1676
2520
  },
1677
- async save(t) {
2521
+ async load(t) {
2522
+ let { data: n, error: r } = await e.from("promo_config").select("data").eq("key", t).maybeSingle();
2523
+ if (r) throw r;
2524
+ return n?.data ?? null;
2525
+ },
2526
+ async save(t, n) {
1678
2527
  let { error: r } = await e.from("promo_config").upsert({
1679
- key: n,
1680
- data: t
2528
+ key: t,
2529
+ data: n
1681
2530
  });
1682
2531
  if (r) throw r;
1683
2532
  },
1684
- async reset() {
1685
- return q(t);
2533
+ async seed() {
2534
+ return Le(t);
1686
2535
  }
1687
2536
  };
1688
2537
  }
1689
- function Z(e, t, { headers: n = {} } = {}) {
2538
+ function Ue(e, t, { headers: n = {} } = {}) {
2539
+ let r = async (t, r = {}) => fetch(`${e}${t}`, {
2540
+ credentials: "include",
2541
+ ...r,
2542
+ headers: {
2543
+ ...n,
2544
+ ...r.headers
2545
+ }
2546
+ });
1690
2547
  return {
1691
2548
  kind: "rest",
1692
- async load() {
1693
- let r = await fetch(e, {
1694
- headers: n,
1695
- credentials: "include"
1696
- });
1697
- if (r.status === 404) return q(t);
1698
- if (!r.ok) throw Error(`Tải dữ liệu lỗi ${r.status}`);
1699
- return r.json();
1700
- },
1701
- async save(t) {
1702
- let r = await fetch(e, {
2549
+ async listMonths() {
2550
+ let e = await r("");
2551
+ if (!e.ok) throw Error(`Tải danh sách tháng lỗi ${e.status}`);
2552
+ return ze(await e.json());
2553
+ },
2554
+ async load(e) {
2555
+ let t = await r(`/${e}`);
2556
+ if (t.status === 404) return null;
2557
+ if (!t.ok) throw Error(`Tải dữ liệu lỗi ${t.status}`);
2558
+ return t.json();
2559
+ },
2560
+ async save(e, t) {
2561
+ let n = await r(`/${e}`, {
1703
2562
  method: "PUT",
1704
- headers: {
1705
- "Content-Type": "application/json",
1706
- ...n
1707
- },
1708
- credentials: "include",
2563
+ headers: { "Content-Type": "application/json" },
1709
2564
  body: JSON.stringify(t)
1710
2565
  });
1711
- if (!r.ok) throw Error(`Lưu dữ liệu lỗi ${r.status}`);
2566
+ if (!n.ok) throw Error(`Lưu dữ liệu lỗi ${n.status}`);
1712
2567
  },
1713
- async reset() {
1714
- return q(t);
2568
+ async seed() {
2569
+ return Le(t);
1715
2570
  }
1716
2571
  };
1717
2572
  }
1718
2573
  // src/data/seed.js
1719
- var Q = {
2574
+ var We = {
1720
2575
  version: 1,
1721
2576
  settings: {
1722
- campaignName: "Chương trình khuyến mại tháng 10/2026",
1723
- validFrom: "2026-10-01",
1724
- validTo: "2026-10-31",
2577
+ campaignName: "Mừng ngày Nhà giáo Việt Nam",
2578
+ validFrom: "2026-11-01",
2579
+ validTo: "2026-11-30",
1725
2580
  labels: [
1726
2581
  {
1727
2582
  name: "IELTS Mentor",
@@ -6635,198 +7490,1001 @@ var Q = {
6635
7490
  code: "IE6.5(M2)",
6636
7491
  mode: "Online"
6637
7492
  }
6638
- ]
6639
- },
6640
- {
6641
- label: "CLASSUP 1-1",
6642
- output: "6.5+",
6643
- code: "IE45_M1_M2_READY",
6644
- name: "IE4.5 + IE6.5(M1) + IE6.5(M2) + Ready",
6645
- items: [
6646
- {
6647
- code: "IE4.5",
6648
- mode: "Online"
6649
- },
6650
- {
6651
- code: "IE6.5(M1)",
6652
- mode: "Online"
6653
- },
6654
- {
6655
- code: "IE6.5(M2)",
6656
- mode: "Online"
6657
- },
6658
- {
6659
- code: "Ready",
6660
- mode: "Online"
7493
+ ]
7494
+ },
7495
+ {
7496
+ label: "CLASSUP 1-1",
7497
+ output: "6.5+",
7498
+ code: "IE45_M1_M2_READY",
7499
+ name: "IE4.5 + IE6.5(M1) + IE6.5(M2) + Ready",
7500
+ items: [
7501
+ {
7502
+ code: "IE4.5",
7503
+ mode: "Online"
7504
+ },
7505
+ {
7506
+ code: "IE6.5(M1)",
7507
+ mode: "Online"
7508
+ },
7509
+ {
7510
+ code: "IE6.5(M2)",
7511
+ mode: "Online"
7512
+ },
7513
+ {
7514
+ code: "Ready",
7515
+ mode: "Online"
7516
+ }
7517
+ ]
7518
+ },
7519
+ {
7520
+ label: "CLASSUP 1-1",
7521
+ output: "6.5+",
7522
+ code: "BS_PRE_IE45_M1_M2",
7523
+ name: "BS + PRE + IE4.5 + IE6.5(M1) + IE6.5(M2)",
7524
+ items: [
7525
+ {
7526
+ code: "BS",
7527
+ mode: "Online"
7528
+ },
7529
+ {
7530
+ code: "PRE",
7531
+ mode: "Online"
7532
+ },
7533
+ {
7534
+ code: "IE4.5",
7535
+ mode: "Online"
7536
+ },
7537
+ {
7538
+ code: "IE6.5(M1)",
7539
+ mode: "Online"
7540
+ },
7541
+ {
7542
+ code: "IE6.5(M2)",
7543
+ mode: "Online"
7544
+ }
7545
+ ]
7546
+ },
7547
+ {
7548
+ label: "CLASSUP 1-1",
7549
+ output: "6.5+",
7550
+ code: "PRE_IE45_M1_M2_READY",
7551
+ name: "PRE + IE4.5 + IE6.5(M1) + IE6.5(M2) + Ready",
7552
+ items: [
7553
+ {
7554
+ code: "PRE",
7555
+ mode: "Online"
7556
+ },
7557
+ {
7558
+ code: "IE4.5",
7559
+ mode: "Online"
7560
+ },
7561
+ {
7562
+ code: "IE6.5(M1)",
7563
+ mode: "Online"
7564
+ },
7565
+ {
7566
+ code: "IE6.5(M2)",
7567
+ mode: "Online"
7568
+ },
7569
+ {
7570
+ code: "Ready",
7571
+ mode: "Online"
7572
+ }
7573
+ ]
7574
+ },
7575
+ {
7576
+ label: "CLASSUP 1-1",
7577
+ output: "6.5+",
7578
+ code: "BS_PRE_IE45_M1_M2_READY",
7579
+ name: "BS + PRE + IE4.5 + IE6.5(M1) + IE6.5(M2) + Ready",
7580
+ items: [
7581
+ {
7582
+ code: "BS",
7583
+ mode: "Online"
7584
+ },
7585
+ {
7586
+ code: "PRE",
7587
+ mode: "Online"
7588
+ },
7589
+ {
7590
+ code: "IE4.5",
7591
+ mode: "Online"
7592
+ },
7593
+ {
7594
+ code: "IE6.5(M1)",
7595
+ mode: "Online"
7596
+ },
7597
+ {
7598
+ code: "IE6.5(M2)",
7599
+ mode: "Online"
7600
+ },
7601
+ {
7602
+ code: "Ready",
7603
+ mode: "Online"
7604
+ }
7605
+ ]
7606
+ },
7607
+ {
7608
+ label: "CLASSUP 1-1",
7609
+ output: "6.5+",
7610
+ code: "MA_MB_BS_PRE_IE45_M1_M2",
7611
+ name: "Module A + Module B + BS + PRE + IE4.5 + IE6.5(M1) + IE6.5(M2)",
7612
+ items: [
7613
+ {
7614
+ code: "Module A",
7615
+ mode: "Online"
7616
+ },
7617
+ {
7618
+ code: "Module B",
7619
+ mode: "Online"
7620
+ },
7621
+ {
7622
+ code: "BS",
7623
+ mode: "Online"
7624
+ },
7625
+ {
7626
+ code: "PRE",
7627
+ mode: "Online"
7628
+ },
7629
+ {
7630
+ code: "IE4.5",
7631
+ mode: "Online"
7632
+ },
7633
+ {
7634
+ code: "IE6.5(M1)",
7635
+ mode: "Online"
7636
+ },
7637
+ {
7638
+ code: "IE6.5(M2)",
7639
+ mode: "Online"
7640
+ }
7641
+ ]
7642
+ },
7643
+ {
7644
+ label: "CLASSUP 1-1",
7645
+ output: "6.5+",
7646
+ code: "MA_MB_BS_PRE_IE45_M1_M2_READY",
7647
+ name: "Module A + Module B + BS + PRE + IE4.5 + IE6.5(M1) + IE6.5(M2) + Ready",
7648
+ items: [
7649
+ {
7650
+ code: "Module A",
7651
+ mode: "Online"
7652
+ },
7653
+ {
7654
+ code: "Module B",
7655
+ mode: "Online"
7656
+ },
7657
+ {
7658
+ code: "BS",
7659
+ mode: "Online"
7660
+ },
7661
+ {
7662
+ code: "PRE",
7663
+ mode: "Online"
7664
+ },
7665
+ {
7666
+ code: "IE4.5",
7667
+ mode: "Online"
7668
+ },
7669
+ {
7670
+ code: "IE6.5(M1)",
7671
+ mode: "Online"
7672
+ },
7673
+ {
7674
+ code: "IE6.5(M2)",
7675
+ mode: "Online"
7676
+ },
7677
+ {
7678
+ code: "Ready",
7679
+ mode: "Online"
7680
+ }
7681
+ ]
7682
+ }
7683
+ ]
7684
+ }, Ge = (e) => JSON.parse(JSON.stringify(e)), Y = (e) => String(e ?? "").replace(/[&<>"']/g, (e) => ({
7685
+ "&": "&amp;",
7686
+ "<": "&lt;",
7687
+ ">": "&gt;",
7688
+ "\"": "&quot;",
7689
+ "'": "&#39;"
7690
+ })[e]), X = (e) => `${Math.round(Number(e) || 0).toLocaleString("vi-VN")}đ`, Z = (e) => `${+(Number(e || 0) * 100).toFixed(2)}%`, Ke = (e) => e ? e.split("-").reverse().join("/") : "", Q = (e, t) => String(e ?? "").trim().toLowerCase() === String(t ?? "").trim().toLowerCase(), qe = () => {
7691
+ let e = /* @__PURE__ */ new Date();
7692
+ return `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}`;
7693
+ }, $ = (e) => {
7694
+ let [t, n] = String(e).split("-");
7695
+ return `Tháng ${Number(n)}/${t}`;
7696
+ }, Je = (e) => {
7697
+ let [t, n] = e.split("-").map(Number);
7698
+ return [`${e}-01`, `${e}-${String(new Date(t, n, 0).getDate()).padStart(2, "0")}`];
7699
+ };
7700
+ function Ye(e) {
7701
+ if (!e) throw Error("Cần truyền lớp lưu trữ dữ liệu (store)");
7702
+ return {
7703
+ ...e,
7704
+ async listMonths() {
7705
+ if (typeof e.listMonths == "function") {
7706
+ let t = await e.listMonths();
7707
+ if (Array.isArray(t) && t.length) return t;
7708
+ }
7709
+ return [qe()];
7710
+ },
7711
+ async load(t) {
7712
+ if (typeof e.load == "function") {
7713
+ let n = await e.load(t);
7714
+ if (n != null) return n;
7715
+ if (e.load.length === 0) return await e.load();
7716
+ }
7717
+ return null;
7718
+ },
7719
+ async save(t, n) {
7720
+ if (typeof e.save == "function") return e.save.length === 1 ? await e.save(n) : await e.save(t, n);
7721
+ },
7722
+ async seed() {
7723
+ return typeof e.seed == "function" ? await e.seed() : typeof e.reset == "function" ? await e.reset() : Ge(We);
7724
+ }
7725
+ };
7726
+ }
7727
+ async function Xe(e, t = {}) {
7728
+ if (!e) throw Error("Cần truyền phần tử DOM để gắn công cụ");
7729
+ let n = Ye(t.store), { allowRoleSwitch: r = !1, user: i = null, preview: a = !1 } = t, o = !!a, s = (e) => o ? !0 : confirm(e), c = /* @__PURE__ */ new Map();
7730
+ async function l(e) {
7731
+ if (!c.has(e)) {
7732
+ let t = await n.load(e);
7733
+ c.set(e, t ? C(t) : null);
7734
+ }
7735
+ return c.get(e);
7736
+ }
7737
+ let u = {
7738
+ role: t.role === "admin" ? "admin" : "sale",
7739
+ view: "calc",
7740
+ months: await n.listMonths(),
7741
+ month: qe(),
7742
+ data: null,
7743
+ calc: null,
7744
+ table: null,
7745
+ pdf: null,
7746
+ admin: {
7747
+ tab: "courses",
7748
+ label: "",
7749
+ q: "",
7750
+ draft: null,
7751
+ dirty: !1,
7752
+ issues: [],
7753
+ month: "",
7754
+ newMonth: "",
7755
+ copyFrom: ""
7756
+ }
7757
+ };
7758
+ u.data = await l(u.month), u.admin.month = u.months.includes(u.month) ? u.month : u.months[0] ?? u.month, await l(u.admin.month);
7759
+ let d = () => {
7760
+ u.calc = y(u.data), u.table = {
7761
+ ...y(u.data),
7762
+ output: ""
7763
+ };
7764
+ };
7765
+ d(), u.pdf = {
7766
+ ...y(u.data),
7767
+ month: u.month,
7768
+ title: "",
7769
+ sections: le.map((e) => e.id),
7770
+ outputs: [],
7771
+ scenarios: []
7772
+ }, e.classList.add("pt-root"), e.innerHTML = "";
7773
+ let f = document.createElement("div"), p = document.createElement("div");
7774
+ p.className = "pt-body", e.append(f, p);
7775
+ function m() {
7776
+ let e = [
7777
+ [
7778
+ "calc",
7779
+ "calc",
7780
+ "Tính giá"
7781
+ ],
7782
+ [
7783
+ "table",
7784
+ "table",
7785
+ "Bảng giá lộ trình"
7786
+ ],
7787
+ [
7788
+ "pdf",
7789
+ "download",
7790
+ "Xuất PDF"
7791
+ ],
7792
+ ...u.role === "admin" ? [[
7793
+ "admin",
7794
+ "db",
7795
+ "Quản trị dữ liệu gốc"
7796
+ ]] : []
7797
+ ];
7798
+ u.view === "admin" && u.role !== "admin" && (u.view = "calc"), f.className = "pt-band", f.innerHTML = e.map(([e, t, n]) => `<button class="pt-tab ${u.view === e ? "is-active" : ""}" data-act="view" data-v="${e}">${k(t)}${n}</button>`).join("") + "<span class=\"pt-band-spacer\"></span>" + (r ? `<div class="pt-role" title="Chỉ có ở bản demo — trên portal vai trò lấy từ tài khoản đăng nhập">
7799
+ <button class="${u.role === "sale" ? "is-active" : ""}" data-act="role" data-v="sale">Sale / TVV</button>
7800
+ <button class="${u.role === "admin" ? "is-active" : ""}" data-act="role" data-v="admin">Admin</button></div>` : ""), p.innerHTML = `<div class="pt-container">${u.view === "pdf" ? F() : u.view === "admin" ? ue() : u.data ? u.view === "calc" ? re() : N() : A()}</div>`, u.view === "admin" && U(), u.view === "pdf" && L();
7801
+ }
7802
+ function y(e) {
7803
+ return e ? {
7804
+ label: e.settings.labels[0]?.name ?? "",
7805
+ program: e.settings.programs[0]?.name ?? "",
7806
+ method: e.settings.paymentMethods[0]?.name ?? "",
7807
+ term: 0,
7808
+ warranty: e.warranty[0]?.name ?? "",
7809
+ lktGroup: "",
7810
+ lktFormat: "",
7811
+ selected: {}
7812
+ } : {
7813
+ label: "",
7814
+ program: "",
7815
+ method: "",
7816
+ term: 0,
7817
+ warranty: "",
7818
+ lktGroup: "",
7819
+ lktFormat: "",
7820
+ selected: {}
7821
+ };
7822
+ }
7823
+ let b = (e) => ({
7824
+ ...e,
7825
+ items: u.data.settings.courseCodes.slice().sort((e, t) => e.order - t.order).filter((t) => e.selected[t.code]).map((t) => ({
7826
+ code: t.code,
7827
+ mode: e.selected[t.code]
7828
+ }))
7829
+ });
7830
+ function w({ ic: e, title: t, sub: n, actions: r = "", stats: i = "" }) {
7831
+ return `<div class="pt-page-head">
7832
+ <div class="pt-title-row">
7833
+ <div class="pt-title-icon">${k(e, 20)}</div>
7834
+ <div><h2 class="pt-title">${t}</h2><p class="pt-sub">${n}</p></div>
7835
+ <div class="pt-title-actions">${r}</div>
7836
+ </div>
7837
+ ${i ? `<div class="pt-stats">${i}</div>` : ""}
7838
+ </div>`;
7839
+ }
7840
+ let T = (e, t, n, r, i = !1) => `<div class="pt-stat pt-stat--${e}"><div style="min-width:0"><div class="pt-stat-label">${t}</div>
7841
+ <div class="pt-stat-value ${i ? "is-small" : ""}">${n}</div></div><div class="pt-stat-icon">${k(r)}</div></div>`, D = (e, t, n, { disabled: r = () => !1, hint: i = () => "", fmt: a = (e) => e } = {}) => `<div class="pt-chips">${t.map((t) => {
7842
+ let o = r(t), s = i(t);
7843
+ return `<button class="pt-chip ${Q(t, n) ? "is-active" : ""}" data-act="calc" data-f="${e}" data-v="${Y(t)}" ${o ? "disabled" : ""}
7844
+ ${o && typeof o == "string" ? `title="${Y(o)}"` : ""}>${Y(a(t))}${s ? ` <small>${Y(s)}</small>` : ""}</button>`;
7845
+ }).join("")}</div>`;
7846
+ function O() {
7847
+ return `<select class="pt-select" style="height:36px;width:150px" data-act="view-month" title="Tháng chương trình">${[.../* @__PURE__ */ new Set([qe(), ...u.months])].sort().reverse().map((e) => `<option value="${e}" ${e === u.month ? "selected" : ""}>${$(e)}${u.months.includes(e) ? "" : " (trống)"}</option>`).join("")}</select>`;
7848
+ }
7849
+ function A() {
7850
+ return w({
7851
+ ic: "calendar",
7852
+ title: `Chương trình khuyến mại ${$(u.month).toLowerCase()}`,
7853
+ sub: "Chưa có dữ liệu",
7854
+ actions: O()
7855
+ }) + `<div class="pt-section"><div class="pt-empty" style="padding:56px 24px">
7856
+ <div style="font-size:16px;font-weight:600;color:var(--pt-ink);margin-bottom:6px">Chưa có chương trình khuyến mại ${$(u.month).toLowerCase()}</div>
7857
+ Admin chưa cập nhật chương trình cho tháng này. Bạn có thể chọn xem lại các tháng trước ở ô chọn tháng phía trên.
7858
+ ${u.role === "admin" ? `<div style="margin-top:16px"><button class="pt-btn pt-btn--primary" data-act="goto-create" data-v="${u.month}">${k("plus", 16)}Tạo chương trình ${$(u.month).toLowerCase()}</button></div>` : ""}
7859
+ </div></div>`;
7860
+ }
7861
+ function re() {
7862
+ let e = u.data, t = u.calc, n = E(e, b(t)), r = e.settings, i = h(e, t.program), a = r.labels.find((e) => Q(e.name, t.label)), o = _(e, t.method), s = ee(e, t.method), c = g(e, t.method), l = n.discountAmt + n.cashback + n.voucherTotal, d = v(e, t.label), f = e.routes.filter((e) => Q(e.label, t.label)), p = T("grey", "Tổng giá gốc", X(n.gross), "tag") + T("white", `Tổng ưu đãi ${n.pct ? `(${Z(n.pct)})` : ""}`, l ? `-${X(l)}` : "0đ", "percent") + T(n.ok ? "green" : "purple", "Học phí cuối cùng", n.count ? X(n.final) : "—", "wallet") + T(n.ok ? "green" : "red", "Trạng thái", n.ok ? "Hợp lệ" : Y(n.status), n.ok ? "checkCircle" : "alert", !n.ok), m = `<div class="pt-form">
7863
+ <div class="pt-form-row"><div class="pt-label">Nhãn</div>${D("label", r.labels.map((e) => e.name), t.label)}</div>
7864
+ <div class="pt-form-row"><div class="pt-label">Chương trình</div>${D("program", r.programs.map((e) => e.name), t.program)}</div>
7865
+ ${i?.type === "LKT" ? `<div class="pt-form-row"><div class="pt-label">Nhóm LKT<small>${n.lkt?.baseProgram ? `Theo chương trình ${Y(n.lkt.baseProgram)}` : ""}</small></div>${S(e, t.label).length ? D("lktGroup", S(e, t.label).map((e) => e.name), t.lktGroup) : "<span class=\"pt-section-sub\">Nhãn này chưa có chính sách liên kết trường</span>"}</div>
7866
+ ${t.lktGroup ? `<div class="pt-form-row"><div class="pt-label">Format LKT</div>${D("lktFormat", x(e, t.label, t.lktGroup).map((e) => e.format), t.lktFormat, { hint: (n) => {
7867
+ let r = x(e, t.label, t.lktGroup).find((e) => Q(e.format, n))?.cut;
7868
+ return r ? `-${Z(r)}` : "";
7869
+ } })}</div>` : ""}` : ""}
7870
+ <div class="pt-form-row"><div class="pt-label">Hình thức thanh toán</div>${D("method", r.paymentMethods.map((e) => e.name), t.method, { disabled: (e) => a?.blockedMethods?.some((t) => Q(t, e)) ? `${t.label} không áp dụng ${e}` : !1 })}</div>
7871
+ <div class="pt-form-row"><div class="pt-label">Kỳ hạn<small>${c?.citime && n.combo.citimeMax ? `Tối đa ${n.combo.citimeMax} tháng` : ""}</small></div>${s ? "<div class=\"pt-chips\"><span class=\"pt-chip is-active\">Không kỳ hạn</span></div>" : D("term", o.map(String), String(t.term), {
7872
+ fmt: (e) => `${e} tháng`,
7873
+ disabled: (e) => c?.citime && n.combo.citimeMax != null && Number(e) > n.combo.citimeMax ? "Vượt kỳ hạn Citime tối đa của lộ trình" : !1
7874
+ })}</div>
7875
+ <div class="pt-form-row"><div class="pt-label">Gói bảo hành</div>${D("warranty", e.warranty.map((e) => e.name), t.warranty, { hint: (t) => {
7876
+ let n = e.warranty.find((e) => Q(e.name, t))?.rate;
7877
+ return n ? `+${Z(n)}` : "";
7878
+ } })}</div>
7879
+ </div>`, y = d.map((n) => {
7880
+ let r = !!t.selected[n.code], i = t.selected[n.code] ?? n.modes[0], a = E(e, {
7881
+ ...t,
7882
+ items: [{
7883
+ code: n.code,
7884
+ mode: i
7885
+ }]
7886
+ }).lines[0];
7887
+ return `<div class="pt-course ${r ? "is-on" : ""}" data-act="toggle" data-code="${Y(n.code)}" role="checkbox" aria-checked="${r}" tabindex="0">
7888
+ <div class="pt-course-top"><span class="pt-check">${r ? k("check", 14) : ""}</span>
7889
+ <div style="min-width:0"><div class="pt-course-name">${Y(n.name)}</div><div class="pt-course-code">${Y(n.code)}</div></div></div>
7890
+ ${n.modes.length > 1 ? `<div class="pt-seg">${n.modes.map((e) => `<button class="${Q(e, i) ? "is-active" : ""}" data-act="mode" data-code="${Y(n.code)}" data-v="${Y(e)}">${Y(e)}</button>`).join("")}</div>` : `<span class="pt-seg-single">${Y(n.modes[0])}</span>`}
7891
+ <div class="pt-course-price"><span>Giá gốc <b>${X(a?.price)}</b></span>${a?.voucher ? `<span>VC -${X(a.voucher)}</span>` : ""}</div>
7892
+ </div>`;
7893
+ }).join(""), C = n.lines.map((e) => `<tr><td>${Y(e.name)} <span style="color:var(--pt-faint)">· ${Y(e.mode)}</span></td><td>${X(e.price)}</td></tr>`).join(""), te = `<div class="pt-section pt-result">
7894
+ <div class="pt-section-head"><div class="pt-section-icon">${k("calc", 16)}</div>
7895
+ <div><div class="pt-section-title">Kết quả báo giá</div><div class="pt-section-sub">${n.count} khóa · ${Y(t.program)} · ${Y(t.method)}${t.term ? ` ${t.term} tháng` : ""}</div></div></div>
7896
+ <div class="pt-section-body">
7897
+ <div class="pt-status ${n.ok ? "is-ok" : "is-bad"}">${k(n.ok ? "checkCircle" : "alert", 16)}${n.ok ? "Báo giá hợp lệ" : Y(n.status)}</div>
7898
+ ${C ? `<table class="pt-lines">${C}</table>` : ""}
7899
+ <ul class="pt-rows">
7900
+ <li><span>Tổng giá gốc</span><b>${X(n.gross)}</b></li>
7901
+ <li class="is-minus"><span>Ưu đãi ${Z(n.pct)}${n.lkt?.cut != null && n.lkt.baseFound ? `<br><small style="color:var(--pt-faint)">${Y(n.lkt.baseProgram)} ${Z(n.lkt.basePct)} − cắt ${Y(t.lktFormat)} ${Z(n.lkt.cut)}</small>` : ""}</span><b>-${X(n.discountAmt)}</b></li>
7902
+ ${n.cashback ? `<li class="is-minus"><span>Hoàn tiền (Định kỳ)</span><b>-${X(n.cashback)}</b></li>` : ""}
7903
+ <li class="is-minus"><span>Voucher đặc biệt</span><b>-${X(n.voucherTotal)}</b></li>
7904
+ <li><span>Giá sau khuyến mại</span><b>${X(n.afterPromo)}</b></li>
7905
+ <li class="is-plus"><span>Bảo hành ${Y(t.warranty)} (${Z(n.warrantyRate)} × ${X(n.warrantyBase)})</span><b>+${X(n.warrantyFee)}</b></li>
7906
+ </ul>
7907
+ <div class="pt-final ${n.ok ? "" : "is-dim"}"><small>HỌC PHÍ CUỐI CÙNG</small><div>${n.count ? X(n.final) : "—"}</div></div>
7908
+ ${n.gift ? `<div class="pt-gift">${k("gift", 18)}<div><b>Quà tặng:</b> ${Y(n.gift.content)}</div></div>` : ""}
7909
+ ${n.combo.code ? `<div class="pt-combo">Mã lộ trình: <b>${Y(n.combo.code)}</b>${n.combo.routeName ? ` · ${Y(n.combo.group)}` : ""}<br>
7910
+ Citime: <b>${Y(n.combo.citimeStatus)}</b>${n.combo.citimeMax ? ` · tối đa ${n.combo.citimeMax} tháng` : ""}</div>` : ""}
7911
+ <div style="display:flex;gap:8px;margin-top:14px">
7912
+ <button class="pt-btn pt-btn--primary" style="flex:1;justify-content:center" data-act="copy" ${n.count ? "" : "disabled"}>${k("copy", 16)}Sao chép báo giá</button>
7913
+ <button class="pt-btn pt-btn--ghost" data-act="reset-calc" title="Làm mới">${k("refresh", 16)}</button>
7914
+ </div>
7915
+ </div></div>`;
7916
+ return w({
7917
+ ic: "calc",
7918
+ title: "Tính giá khuyến mại",
7919
+ actions: O(),
7920
+ sub: `${Y(r.campaignName)} · Áp dụng ${Ke(r.validFrom)} – ${Ke(r.validTo)}`,
7921
+ stats: p
7922
+ }) + `<div class="pt-grid pt-grid-calc" style="margin-top:14px">
7923
+ <div>
7924
+ <div class="pt-section" style="margin-top:0">
7925
+ <div class="pt-section-head"><div class="pt-section-icon">${k("filter", 16)}</div>
7926
+ <div><div class="pt-section-title">Thông tin chung</div><div class="pt-section-sub">Bấm chọn — kết quả tự cập nhật</div></div></div>
7927
+ <div class="pt-section-body">${m}</div>
7928
+ </div>
7929
+ <div class="pt-section">
7930
+ <div class="pt-section-head"><div class="pt-section-icon">${k("book", 16)}</div>
7931
+ <div><div class="pt-section-title">Khóa học đăng ký</div><div class="pt-section-sub">Tích chọn khóa và hình thức học · ${Y(r.note ?? "")}</div></div>
7932
+ <div class="pt-section-actions">
7933
+ <select class="pt-select" style="height:34px;max-width:260px" data-act="pick-route">
7934
+ <option value="">Chọn nhanh theo lộ trình…</option>
7935
+ ${f.map((e) => `<option value="${Y(e.code)}">${Y(e.output ? `[${e.output}] ` : "")}${Y(e.name)}</option>`).join("")}
7936
+ </select>
7937
+ <button class="pt-btn pt-btn--link" data-act="clear-courses">Bỏ chọn</button>
7938
+ </div></div>
7939
+ <div class="pt-section-body"><div class="pt-courses">${y || "<div class=\"pt-empty\">Nhãn này chưa có khóa học</div>"}</div></div>
7940
+ </div>
7941
+ </div>
7942
+ ${te}
7943
+ </div>`;
7944
+ }
7945
+ function j(e, t, n, r = u.data) {
7946
+ if (t === "term" && (n = Number(n)), e[t] = n, t === "label") {
7947
+ let t = v(r, n);
7948
+ for (let n of Object.keys(e.selected)) {
7949
+ let r = t.find((e) => Q(e.code, n));
7950
+ r ? r.modes.some((t) => Q(t, e.selected[n])) || (e.selected[n] = r.modes[0]) : delete e.selected[n];
7951
+ }
7952
+ let i = r.settings.labels.find((e) => Q(e.name, n))?.blockedMethods ?? [];
7953
+ i.some((t) => Q(t, e.method)) && (e.method = r.settings.paymentMethods.find((e) => !i.some((t) => Q(t, e.name)))?.name ?? "");
7954
+ }
7955
+ if (t === "method" || t === "label") {
7956
+ let t = _(r, e.method).map(Number);
7957
+ t.includes(Number(e.term)) || (e.term = t[0] ?? 0);
7958
+ }
7959
+ if ([
7960
+ "label",
7961
+ "program",
7962
+ "lktGroup"
7963
+ ].includes(t) && h(r, e.program)?.type === "LKT") {
7964
+ let t = S(r, e.label);
7965
+ t.some((t) => Q(t.name, e.lktGroup)) || (e.lktGroup = t[0]?.name ?? "");
7966
+ let n = x(r, e.label, e.lktGroup);
7967
+ n.some((t) => Q(t.format, e.lktFormat)) || (e.lktFormat = n[0]?.format ?? "");
7968
+ }
7969
+ }
7970
+ function ie() {
7971
+ let e = u.calc, t = E(u.data, b(e)), n = [
7972
+ `BÁO GIÁ HỌC PHÍ – ${e.label.toUpperCase()}`,
7973
+ `Chương trình: ${e.program}${h(u.data, e.program)?.type === "LKT" ? ` (${[e.lktGroup, e.lktFormat].filter(Boolean).join(" – ")})` : ""}`,
7974
+ `Thanh toán: ${e.method}${e.term ? ` – ${e.term} tháng` : ""}`,
7975
+ "Khóa học:",
7976
+ ...t.lines.map((e) => ` • ${e.name} (${e.mode}): ${X(e.price)}`),
7977
+ `Tổng giá gốc: ${X(t.gross)}`,
7978
+ `Ưu đãi ${Z(t.pct)}: -${X(t.discountAmt)}`,
7979
+ ...t.cashback ? [`Hoàn tiền: -${X(t.cashback)}`] : [],
7980
+ ...t.voucherTotal ? [`Voucher: -${X(t.voucherTotal)}`] : [],
7981
+ ...t.warrantyFee ? [`Bảo hành ${e.warranty}: +${X(t.warrantyFee)}`] : [],
7982
+ `HỌC PHÍ CUỐI CÙNG: ${X(t.final)}`,
7983
+ ...t.gift ? [`Quà tặng: ${t.gift.content}`] : [],
7984
+ `(${u.data.settings.campaignName}, áp dụng đến ${Ke(u.data.settings.validTo)})`
7985
+ ];
7986
+ return t.ok || n.unshift(`⚠ CHƯA HỢP LỆ: ${t.status}`), n.join("\n");
7987
+ }
7988
+ function N() {
7989
+ let e = u.data, t = u.table, n = [...new Set(e.routes.filter((e) => Q(e.label, t.label)).map((e) => e.output).filter(Boolean))], r = te(e, t), i = r.filter((e) => e.quote.ok), a = i.length ? i.reduce((e, t) => e + t.quote.pct, 0) / i.length : 0, o = h(e, t.program), s = (e, t, n, r = (e) => e, i = null) => `<select class="pt-select" data-act="tbl" data-f="${e}">${i == null ? "" : `<option value="">${i}</option>`}${t.map((e) => `<option value="${Y(e)}" ${Q(e, n) ? "selected" : ""}>${Y(r(e))}</option>`).join("")}</select>`, c = `<div class="pt-section">
7990
+ <div class="pt-section-head no-line"><div class="pt-section-icon">${k("filter", 16)}</div>
7991
+ <div><div class="pt-section-title">Bộ lọc thông minh</div><div class="pt-section-sub">Bảng giá tự tính lại từ dữ liệu gốc khi đổi bộ lọc</div></div>
7992
+ <div class="pt-section-actions"><button class="pt-btn pt-btn--link" data-act="tbl-reset">${k("filter", 14)}Xóa bộ lọc</button></div></div>
7993
+ <div class="pt-section-body"><div class="pt-grid pt-grid-3">
7994
+ <div class="pt-field"><label>Nhãn</label>${s("label", e.settings.labels.map((e) => e.name), t.label)}</div>
7995
+ <div class="pt-field"><label>Đầu ra</label>${s("output", n, t.output, (e) => e, "Tất cả đầu ra")}</div>
7996
+ <div class="pt-field"><label>Chương trình</label>${s("program", e.settings.programs.map((e) => e.name), t.program)}</div>
7997
+ ${o?.type === "LKT" ? `<div class="pt-field"><label>Nhóm LKT</label>${s("lktGroup", S(e, t.label).map((e) => e.name), t.lktGroup, (e) => e, "Chọn nhóm")}</div>
7998
+ <div class="pt-field"><label>Format LKT</label>${s("lktFormat", x(e, t.label, t.lktGroup).map((e) => e.format), t.lktFormat, (e) => e, "Chọn format")}</div>` : ""}
7999
+ <div class="pt-field"><label>Hình thức thanh toán</label>${s("method", e.settings.paymentMethods.map((e) => e.name), t.method)}</div>
8000
+ <div class="pt-field"><label>Kỳ hạn</label>${s("term", _(e, t.method).map(String), String(t.term), (e) => Number(e) ? `${e} tháng` : "Không kỳ hạn")}</div>
8001
+ <div class="pt-field"><label>Gói bảo hành</label>${s("warranty", e.warranty.map((e) => e.name), t.warranty)}</div>
8002
+ </div></div></div>`, l = r.map(({ route: e, quote: t }) => `<tr>
8003
+ <td><div style="font-weight:500">${Y(e.name)}</div><div class="muted">${Y(e.code)}</div></td>
8004
+ <td>${e.output ? `<span class="pt-pill pt-pill--purple">${Y(e.output)}</span>` : ""}</td>
8005
+ <td class="num">${t.count}</td>
8006
+ <td class="num">${X(t.gross)}</td>
8007
+ <td class="num">${t.ok ? `<span class="pt-pill pt-pill--orange">-${Z(t.pct)}</span>` : "—"}</td>
8008
+ <td class="num">${t.ok ? X(t.afterPromo) : "—"}</td>
8009
+ <td class="num"><b>${t.ok ? X(t.final) : "—"}</b></td>
8010
+ <td class="muted">${t.ok && t.gift ? Y(t.gift.content) : ""}</td>
8011
+ <td>${t.ok ? "<span class=\"pt-pill pt-pill--green\"><span class=\"pt-dot\"></span>Hợp lệ</span>" : `<span class="pt-pill pt-pill--red"><span class="pt-dot"></span>${Y(t.status)}</span>`}</td>
8012
+ <td><button class="pt-icon-btn" title="Mở trong công cụ tính giá" data-act="open-route" data-code="${Y(e.code)}">${k("eye", 16)}</button></td>
8013
+ </tr>`).join("");
8014
+ return w({
8015
+ ic: "table",
8016
+ title: "Bảng giá lộ trình gợi ý",
8017
+ actions: O(),
8018
+ sub: `Học phí đã gồm ưu đãi theo bộ lọc · ${Y(e.settings.campaignName)}`,
8019
+ stats: T("grey", "Tổng lộ trình", r.length, "route") + T("white", "Mức giảm trung bình", i.length ? Z(a) : "—", "percent") + T("green", "Hợp lệ", i.length, "checkCircle") + T("red", "Không áp dụng", r.length - i.length, "xCircle")
8020
+ }) + c + `<div class="pt-section">
8021
+ <div class="pt-section-head"><div><div class="pt-section-title">Danh sách lộ trình</div>
8022
+ <div class="pt-section-sub">Tổng <b style="color:var(--pt-purple)">${r.length}</b> lộ trình · Bấm biểu tượng mắt để xem chi tiết & sao chép báo giá</div></div></div>
8023
+ <div class="pt-table-wrap"><table class="pt-table">
8024
+ <thead><tr><th>Lộ trình</th><th>Đầu ra</th><th class="num">Số khóa</th><th class="num">Giá gốc</th><th class="num">Ưu đãi</th>
8025
+ <th class="num">Giá sau KM</th><th class="num">Học phí cuối</th><th>Quà tặng</th><th>Trạng thái</th><th>Thao tác</th></tr></thead>
8026
+ <tbody>${l || "<tr><td colspan=\"10\" class=\"pt-empty\">Không có lộ trình phù hợp</td></tr>"}</tbody>
8027
+ </table></div>
8028
+ </div>`;
8029
+ }
8030
+ let P = null;
8031
+ function F() {
8032
+ let e = u.pdf, t = c.get(e.month) ?? null, [n, r] = e.month.split("-"), i = [.../* @__PURE__ */ new Set([
8033
+ ...u.months.map((e) => e.slice(0, 4)),
8034
+ n,
8035
+ String((/* @__PURE__ */ new Date()).getFullYear() + 1)
8036
+ ])].sort(), a = `<div class="pt-grid" style="grid-template-columns:1fr 1fr;gap:8px">
8037
+ <select class="pt-select" data-act="pdf-month" data-part="m">${Array.from({ length: 12 }, (e, t) => String(t + 1).padStart(2, "0")).map((e) => `<option value="${e}" ${e === r ? "selected" : ""}>Tháng ${Number(e)}${u.months.includes(`${n}-${e}`) ? "" : " · trống"}</option>`).join("")}</select>
8038
+ <select class="pt-select" data-act="pdf-month" data-part="y">${i.map((e) => `<option ${e === n ? "selected" : ""}>${e}</option>`).join("")}</select></div>`;
8039
+ P = t ? je(t, e) : null;
8040
+ let s = t ? h(t, e.program) : null, l = (e, t, n, r = (e) => e) => `<select class="pt-select" data-act="pdf" data-f="${e}">${t.map((e) => `<option value="${Y(e)}" ${Q(e, n) ? "selected" : ""}>${Y(r(e))}</option>`).join("")}</select>`, d = (e, t, n, r) => `<label style="display:flex;gap:8px;align-items:center;cursor:pointer;font-size:13px">
8041
+ <input type="checkbox" data-act="${e}" value="${Y(t)}" ${n ? "checked" : ""} style="width:16px;height:16px;accent-color:var(--pt-purple)">${r}</label>`, f = t ? me(t, e.label) : [], p = t && s?.type !== "DINH_KY" ? he(t, e) : [], m = e.scenarios.length ? e.scenarios : t ? ge(t, e) : [], g = `<div class="pt-section" style="margin-top:0">
8042
+ <div class="pt-section-head"><div class="pt-section-icon">${k("settings", 16)}</div>
8043
+ <div><div class="pt-section-title">Tùy chọn ấn phẩm</div><div class="pt-section-sub">Khổ A4 ngang · số liệu lấy từ dữ liệu gốc của tháng đã chọn</div></div></div>
8044
+ <div class="pt-section-body"><div class="pt-form" style="gap:12px">
8045
+ <div class="pt-field"><label>Thời gian (tháng + năm)</label>${a}</div>
8046
+ ${t ? `<div class="pt-field"><label>Nhãn</label>${l("label", t.settings.labels.map((e) => e.name), e.label)}</div>
8047
+ <div class="pt-field"><label>Chương trình khuyến mại</label>${l("program", t.settings.programs.map((e) => e.name), e.program)}</div>
8048
+ ${s?.type === "LKT" ? `<div class="pt-field"><label>Nhóm LKT</label>${l("lktGroup", S(t, e.label).map((e) => e.name), e.lktGroup)}</div>
8049
+ <div class="pt-field"><label>Format LKT (cho bảng giá)</label>${l("lktFormat", x(t, e.label, e.lktGroup).map((e) => e.format), e.lktFormat)}</div>` : ""}
8050
+ <div class="pt-field"><label>Tên chương trình (tiêu đề)</label>
8051
+ <input class="pt-input" data-act="pdf-title" value="${Y(e.title)}" placeholder="${Y(fe(t, e.label, e.month))}"></div>
8052
+ <div class="pt-field"><label>Nội dung xuất</label><div style="display:grid;gap:7px">${le.map((t) => d("pdf-sec", t.id, e.sections.includes(t.id), Y(t.title))).join("")}</div></div>
8053
+ ${e.sections.includes("routes") && f.length > 1 ? `<div class="pt-field"><label>Đầu ra trong bảng giá lộ trình</label><div class="pt-chips">${f.map((t) => d("pdf-out", t, !e.outputs.length || e.outputs.includes(t), Y(t))).join("")}</div></div>` : ""}
8054
+ ${e.sections.includes("routes") && p.length ? `<div class="pt-field"><label>Kịch bản thanh toán trong bảng giá lộ trình <small>(2 kịch bản / trang)</small></label><div style="display:grid;gap:7px">${p.map((e) => d("pdf-scen", e.id, m.includes(e.id), `${Y(e.title)} · <b>${+(e.pct * 100).toFixed(2)}%</b>`)).join("")}</div></div>` : ""}` : ""}
8055
+ </div></div></div>`, _ = t ? P.pages ? "<iframe id=\"pt-pdf-frame\" title=\"Xem trước ấn phẩm\" style=\"width:100%;height:78vh;border:0;border-radius:0 0 14px 14px;background:#8a8a8a;display:block\"></iframe>" : "<div class=\"pt-empty\">Chưa chọn nội dung nào hoặc chương trình chưa có dữ liệu</div>" : `<div class="pt-empty" style="padding:56px 24px"><div style="font-size:16px;font-weight:600;color:var(--pt-ink);margin-bottom:6px">${$(e.month)} chưa có chương trình khuyến mại</div>
8056
+ Admin chưa tạo / cập nhật chương trình cho tháng này nên chưa có ấn phẩm để xuất.</div>`, ee = o ? `<span class="pt-pill pt-pill--purple" style="padding:8px 14px">${k("eye", 14)}Bản xem thử: chỉ xem trước ấn phẩm, xuất PDF trên portal</span>` : `<button class="pt-btn pt-btn--primary" data-act="pdf-print" ${P?.pages ? "" : "disabled"}>${k("download", 16)}Xuất PDF</button>`;
8057
+ return `<div class="pt-grid" style="grid-template-columns:320px minmax(0,1fr);align-items:start" id="pt-pdf-grid">
8058
+ ${g}
8059
+ <div class="pt-section" style="margin-top:0">
8060
+ <div class="pt-section-head">
8061
+ <div class="pt-section-icon">${k("eye", 16)}</div>
8062
+ <div>
8063
+ <div class="pt-section-title">Xem trước</div>
8064
+ <div class="pt-section-sub">${P ? `${P.pages} trang A4 ngang · ${Y(P.title)}` : $(e.month)}</div>
8065
+ </div>
8066
+ <div class="pt-section-actions">${ee}</div>
8067
+ </div>
8068
+ ${_}
8069
+ </div>
8070
+ </div>`;
8071
+ }
8072
+ async function I(e) {
8073
+ let t = await l(e), n = t && t.settings.labels.some((e) => Q(e.name, u.pdf.label)) && t.settings.programs.some((e) => Q(e.name, u.pdf.program));
8074
+ u.pdf = {
8075
+ ...n ? u.pdf : {
8076
+ ...u.pdf,
8077
+ ...y(t)
8078
+ },
8079
+ month: e,
8080
+ outputs: [],
8081
+ scenarios: []
8082
+ };
8083
+ }
8084
+ function L() {
8085
+ let e = p.querySelector("#pt-pdf-frame");
8086
+ e && P && (e.addEventListener("load", () => {
8087
+ let t = e.contentDocument, n = Math.min(1, (e.clientWidth - 28) / 1123), r = t.createElement("style");
8088
+ r.textContent = `@media screen { body { zoom: ${n}; padding: 14px 0; } }`, t.head.appendChild(r);
8089
+ }, { once: !0 }), e.srcdoc = P.html);
8090
+ }
8091
+ async function R() {
8092
+ let e = p.querySelector("#pt-pdf-frame");
8093
+ if (e?.contentWindow) {
8094
+ try {
8095
+ await e.contentDocument.fonts?.ready;
8096
+ } catch {}
8097
+ e.contentWindow.focus(), e.contentWindow.print();
8098
+ }
8099
+ }
8100
+ let z = () => u.admin.draft ??= Ge(c.get(u.admin.month));
8101
+ function B() {
8102
+ let e = u.admin, t = [.../* @__PURE__ */ new Set([...u.months, ...e.draft ? [e.month] : []])].sort().reverse(), n = u.months[0], r = (() => {
8103
+ let [e, t] = (n ?? qe()).split("-").map(Number);
8104
+ return n ? `${t === 12 ? e + 1 : e}-${String(t === 12 ? 1 : t + 1).padStart(2, "0")}` : qe();
8105
+ })();
8106
+ return `<div class="pt-section" style="margin-top:14px"><div class="pt-section-head" style="flex-wrap:wrap">
8107
+ <div class="pt-section-icon">${k("calendar", 16)}</div>
8108
+ <div><div class="pt-section-title">Chương trình theo tháng</div><div class="pt-section-sub">Mỗi tháng lưu riêng — tháng cũ giữ nguyên làm lưu trữ, tháng chưa tạo thì sale thấy trống</div></div>
8109
+ <div class="pt-section-actions">
8110
+ <label class="pt-label" style="margin-right:2px">Đang sửa</label>
8111
+ <select class="pt-select" style="height:36px;width:190px" data-act="admin-month">${t.length ? t.map((t) => `<option value="${t}" ${t === e.month ? "selected" : ""}>${$(t)}${u.months.includes(t) ? "" : " (chưa lưu)"}</option>`).join("") : "<option>Chưa có tháng nào</option>"}</select>
8112
+ <span style="width:1px;height:26px;background:var(--pt-line);margin:0 4px"></span>
8113
+ <input class="pt-input" type="month" style="height:36px;width:160px" value="${Y(e.newMonth || r)}" data-act="new-month" title="Tháng cần tạo">
8114
+ <select class="pt-select" style="height:36px;width:220px" data-act="copy-from" title="Dữ liệu ban đầu">
8115
+ ${u.months.map((t) => `<option value="${t}" ${t === (e.copyFrom || n) ? "selected" : ""}>Sao chép từ ${$(t).toLowerCase()}</option>`).join("")}
8116
+ <option value="seed" ${e.copyFrom === "seed" || !n ? "selected" : ""}>Từ dữ liệu Excel gốc</option></select>
8117
+ <button class="pt-btn pt-btn--primary pt-btn--sm" data-act="create-month">${k("plus", 15)}Tạo tháng mới</button>
8118
+ </div></div></div>`;
8119
+ }
8120
+ async function ce() {
8121
+ let e = u.admin, t = (p.querySelector("[data-act=\"new-month\"]")?.value || e.newMonth || "").slice(0, 7);
8122
+ if (!/^\d{4}-\d{2}$/.test(t)) return K("Chọn tháng cần tạo");
8123
+ if (u.months.includes(t)) {
8124
+ e.month = t, e.draft = null, K(`${$(t)} đã có — chuyển sang sửa tháng này`);
8125
+ return;
8126
+ }
8127
+ if (e.dirty && !s("Đang có thay đổi chưa lưu. Bỏ thay đổi để tạo tháng mới?")) return;
8128
+ let r = e.copyFrom || u.months[0] || "seed", i = C(r === "seed" ? await n.seed() : Ge(await l(r)));
8129
+ [i.settings.validFrom, i.settings.validTo] = Je(t), i.settings.campaignName = "", e.month = t, e.draft = i, e.dirty = !0, e.issues = [], K(`Đã tạo ${$(t).toLowerCase()} (chưa lưu) — cập nhật giá, CTKM rồi bấm Lưu & áp dụng`);
8130
+ }
8131
+ let V = (e) => e.path.reduce((e, t) => e[t], z());
8132
+ function ue() {
8133
+ let e = u.admin;
8134
+ if (!c.get(e.month) && !e.draft) return w({
8135
+ ic: "db",
8136
+ title: "Quản trị dữ liệu gốc",
8137
+ sub: "Chưa có chương trình nào — tạo tháng đầu tiên để bắt đầu."
8138
+ }) + B() + `<div class="pt-section"><div class="pt-empty" style="padding:48px 24px">${$(e.month)} chưa có chương trình. Chọn tháng và nguồn dữ liệu ở trên rồi bấm <b>Tạo tháng mới</b>.</div></div>`;
8139
+ let t = z(), n = M(t), r = n.find((t) => t.id === e.tab), i = [...new Set(n.map((e) => e.group))].map((t) => `<div class="pt-menu-group">${t}</div>` + n.filter((e) => e.group === t).map((t) => `<button class="${t.id === e.tab ? "is-active" : ""}" data-act="admin-tab" data-v="${t.id}">
8140
+ <span class="pt-menu-ic">${k(t.icon, 15)}</span>${t.title}<span class="pt-count">${V(t).length}</span></button>`).join("")).join("") + `<div class="pt-menu-group">Chung</div>
8141
+ <button class="${e.tab === "general" ? "is-active" : ""}" data-act="admin-tab" data-v="general"><span class="pt-menu-ic">${k("settings", 15)}</span>Thông tin chương trình</button>`, a = t.periodic.length + t.special.length + t.extended.length + t.lkt.length, s = ne(t).length, l = T("grey", "Khóa học", t.courses.length, "book") + T("white", "Dòng CTKM", a, "percent") + T("green", "Lộ trình gợi ý", t.routes.length, "route") + T(s ? "red" : "green", "Cảnh báo dữ liệu", s, s ? "alert" : "checkCircle"), d = e.tab === "general" ? pe(t) : `<div class="pt-section" style="margin-top:0">
8142
+ <div class="pt-section-head"><div class="pt-section-icon">${k(r.icon, 16)}</div>
8143
+ <div><div class="pt-section-title">${r.title}</div><div class="pt-section-sub">${r.sheet ? `Thay cho sheet ${r.sheet}` : "Cấu hình chung"}</div></div>
8144
+ <div class="pt-section-actions">
8145
+ ${r.byLabel ? `<select class="pt-select" style="height:36px;width:170px" data-act="admin-label"><option value="">Tất cả nhãn</option>${t.settings.labels.map((t) => `<option ${Q(t.name, e.label) ? "selected" : ""}>${Y(t.name)}</option>`).join("")}</select>` : ""}
8146
+ <input class="pt-input" style="height:36px;width:180px" placeholder="Tìm…" value="${Y(e.q)}" data-act="admin-q">
8147
+ <button class="pt-btn pt-btn--primary" data-act="row-add">${k("plus", 16)}Thêm mới</button>
8148
+ </div></div>
8149
+ <p class="pt-help" style="margin-top:14px">${Y(r.desc)}</p>
8150
+ <div id="pt-issues"></div>
8151
+ <div class="pt-table-wrap" id="pt-admin-table"></div>
8152
+ </div>`;
8153
+ return w({
8154
+ ic: "db",
8155
+ title: "Quản trị dữ liệu gốc",
8156
+ sub: `Đang sửa chương trình ${$(e.month).toLowerCase()} (${Ke(t.settings.validFrom)} – ${Ke(t.settings.validTo)}). Sale chỉ xem kết quả tính theo dữ liệu này.`,
8157
+ actions: `
8158
+ <label class="pt-btn pt-btn--ghost pt-btn--sm" style="cursor:pointer">${k("sheet", 15)}Nhập từ Excel<input type="file" accept=".xlsx" hidden data-act="import-xlsx"></label>
8159
+ <label class="pt-btn pt-btn--ghost pt-btn--sm" style="cursor:pointer">${k("upload", 15)}Nhập JSON<input type="file" accept=".json" hidden data-act="import-json"></label>
8160
+ ${o ? "" : `<button class="pt-btn pt-btn--ghost pt-btn--sm" data-act="export-json">${k("download", 15)}Xuất JSON</button>`}`,
8161
+ stats: l
8162
+ }) + B() + `<div class="pt-admin"><nav class="pt-menu">${i}</nav><div>${d}</div></div>
8163
+ <div class="pt-savebar" id="pt-savebar" ${e.dirty ? "" : "hidden"}>${de()}</div>`;
8164
+ }
8165
+ let de = () => `${k("alert", 18)}<span>Có thay đổi chưa lưu cho ${$(u.admin.month).toLowerCase()} — sale vẫn đang dùng dữ liệu cũ.</span>
8166
+ <span class="pt-band-spacer"></span>
8167
+ <button class="pt-btn pt-btn--ghost pt-btn--sm" data-act="discard">Hủy thay đổi</button>
8168
+ <button class="pt-btn pt-btn--primary pt-btn--sm" data-act="save" style="background:#fff;color:var(--pt-purple)">${k("save", 15)}Lưu & áp dụng</button>`;
8169
+ function H() {
8170
+ u.admin.dirty = !0;
8171
+ let e = p.querySelector("#pt-savebar");
8172
+ e && (e.hidden = !1);
8173
+ }
8174
+ function pe(e) {
8175
+ let t = e.settings, n = (e, n, r = "text") => `<div class="pt-field"><label>${n}</label><input class="pt-input" type="${r}" value="${Y(t[e])}" data-act="setting" data-k="${e}"></div>`;
8176
+ return `<div class="pt-section" style="margin-top:0">
8177
+ <div class="pt-section-head"><div class="pt-section-icon">${k("settings", 16)}</div>
8178
+ <div><div class="pt-section-title">Thông tin chương trình</div><div class="pt-section-sub">Hiển thị trên trang Tính giá và trong báo giá sao chép</div></div></div>
8179
+ <div class="pt-section-body"><div class="pt-grid pt-grid-3">
8180
+ ${n("campaignName", "Tên đợt khuyến mại")}${n("validFrom", "Áp dụng từ ngày", "date")}${n("validTo", "Đến ngày", "date")}
8181
+ </div><div class="pt-field" style="margin-top:14px"><label>Lưu ý hiển thị cho sale</label>
8182
+ <input class="pt-input" value="${Y(t.note)}" data-act="setting" data-k="note"></div>
8183
+ <div class="pt-section-title" style="margin-top:22px">Câu chữ trên ấn phẩm PDF</div>
8184
+ ${[
8185
+ ["cashbackLabel", "Tiêu đề cột hoàn tiền (CTKM định kỳ)"],
8186
+ ["warrantyDuration", "Thời lượng gói bảo hành"],
8187
+ ["warrantyForm", "Hình thức gói bảo hành"],
8188
+ ["routeNote", "Lưu ý dưới bảng giá lộ trình"],
8189
+ ["citimeNote", "Lưu ý phụ lục Citime"]
8190
+ ].map(([e, n]) => `<div class="pt-field" style="margin-top:12px"><label>${n}</label>
8191
+ <textarea class="pt-input" rows="2" style="height:auto;padding:8px 12px;resize:vertical" data-act="doc-text" data-k="${e}">${Y(t.docTexts?.[e])}</textarea></div>`).join("")}
8192
+ <div style="display:flex;gap:8px;margin-top:20px;flex-wrap:wrap">
8193
+ <button class="pt-btn pt-btn--ghost pt-btn--sm" data-act="reset-seed">${k("refresh", 15)}Khôi phục dữ liệu gốc từ file Excel ban đầu</button>
8194
+ </div></div></div>`;
8195
+ }
8196
+ function U() {
8197
+ let e = p.querySelector("#pt-admin-table");
8198
+ if (!e) return;
8199
+ let t = u.admin, n = M(z()).find((e) => e.id === t.tab), r = V(n), i = t.q.trim().toLowerCase(), a = t.issues.filter((e) => e.table === n.id), o = new Set(a.map((e) => e.row)), s = r.map((e, t) => ({
8200
+ r: e,
8201
+ i: t
8202
+ })).filter(({ r: e }) => !n.byLabel || !t.label || Q(e.label, t.label)).filter(({ r: e }) => !i || n.columns.some((t) => String(ae(t, e[t.key])).toLowerCase().includes(i))), c = (e, t, n) => {
8203
+ let r = t[e.key], i = `data-edit="${n}" data-k="${e.key}"`;
8204
+ if (e.type === "bool") return `<input type="checkbox" ${r ? "checked" : ""} ${i} style="width:18px;height:18px;accent-color:var(--pt-purple)">`;
8205
+ if (e.type === "select") return `<select class="pt-select" ${i}>${(e.options.includes(r) || r === "" ? e.options : [r, ...e.options]).map((e) => `<option ${e === r ? "selected" : ""}>${Y(e)}</option>`).join("")}</select>`;
8206
+ if (e.type === "combo") return `<input class="pt-input w-wide" list="pt-dl-${e.key}" value="${Y(r)}" ${i} placeholder="Chọn logo có sẵn hoặc dán link ảnh">
8207
+ <datalist id="pt-dl-${e.key}">${e.options.map((e) => `<option value="${Y(e)}"></option>`).join("")}</datalist>`;
8208
+ if (e.type === "color") return `<input type="color" value="${Y(r || "#000000")}" ${i} style="width:44px;height:30px;border:0;background:none;cursor:pointer">`;
8209
+ if (e.type === "multiline") return `<textarea class="pt-input w-wide" rows="${Math.max(2, Math.min(4, String(r ?? "").split("\n").length))}" ${i}
8210
+ style="height:auto;padding:6px 8px;resize:vertical;line-height:1.4">${Y(r)}</textarea>`;
8211
+ let a = [
8212
+ "money",
8213
+ "pct",
8214
+ "int"
8215
+ ].includes(e.type);
8216
+ return `<input class="pt-input ${a ? "num" : ""} ${e.wide ? "w-wide" : ""}" ${a ? "inputmode=\"decimal\"" : ""} value="${Y(ae(e, r))}" ${i}>`;
8217
+ };
8218
+ p.querySelector("#pt-issues").innerHTML = a.length ? `<ul class="pt-issues">${a.map((e) => `<li>Dòng ${e.row + 1}: ${Y(e.message)}</li>`).join("")}</ul>` : "", e.innerHTML = `<table class="pt-table pt-table--edit">
8219
+ <thead><tr><th class="pt-rowno">#</th>${n.columns.map((e) => `<th class="${[
8220
+ "money",
8221
+ "pct",
8222
+ "int"
8223
+ ].includes(e.type) ? "num" : ""}">${e.label}</th>`).join("")}<th></th></tr></thead>
8224
+ <tbody>${s.map(({ r: e, i: t }) => `<tr class="${o.has(t) ? "has-issue" : ""}"><td class="pt-rowno">${t + 1}</td>${n.columns.map((n) => `<td>${c(n, e, t)}</td>`).join("")}
8225
+ <td><button class="pt-icon-btn is-danger" title="Xóa dòng" data-act="row-del" data-i="${t}">${k("trash", 15)}</button></td></tr>`).join("") || `<tr><td colspan="${n.columns.length + 2}" class="pt-empty">Chưa có dữ liệu</td></tr>`}</tbody></table>`;
8226
+ }
8227
+ async function W() {
8228
+ let e = z(), t = ne(e);
8229
+ if (u.admin.issues = t, t.length && !s(`Có ${t.length} cảnh báo dữ liệu (trùng khóa, giá ≤ 0...). Vẫn lưu?`)) {
8230
+ let e = t[0];
8231
+ u.admin.tab = e.table, m();
8232
+ } else try {
8233
+ e.updatedAt = (/* @__PURE__ */ new Date()).toISOString(), i && (e.updatedBy = i.email ?? i.name ?? "");
8234
+ let t = u.admin.month;
8235
+ await n.save(t, e), c.set(t, C(Ge(e))), u.months = [.../* @__PURE__ */ new Set([...u.months, t])].sort().reverse(), t === u.month && (u.data = c.get(t), d()), u.admin.draft = null, u.admin.dirty = !1, u.admin.issues = [], K(`Đã lưu ${$(t).toLowerCase()}${t === u.month ? " — sale thấy giá mới ngay" : ""}`), m();
8236
+ } catch (e) {
8237
+ K(`Lưu thất bại: ${e.message}`);
8238
+ }
8239
+ }
8240
+ let G;
8241
+ function K(t) {
8242
+ let n = document.querySelector(".pt-root .pt-toast");
8243
+ n || (n = document.createElement("div"), n.className = "pt-toast", e.appendChild(n)), n.textContent = t, clearTimeout(G), G = setTimeout(() => n.remove(), 2600);
8244
+ }
8245
+ async function _e(e) {
8246
+ try {
8247
+ await navigator.clipboard.writeText(e);
8248
+ } catch {
8249
+ let t = Object.assign(document.createElement("textarea"), { value: e });
8250
+ document.body.appendChild(t), t.select(), document.execCommand("copy"), t.remove();
8251
+ }
8252
+ }
8253
+ function ve(e, t) {
8254
+ let n = Object.assign(document.createElement("a"), {
8255
+ href: URL.createObjectURL(new Blob([t], { type: "application/json" })),
8256
+ download: e
8257
+ });
8258
+ n.click(), setTimeout(() => URL.revokeObjectURL(n.href), 1e3);
8259
+ }
8260
+ e.addEventListener("click", async (t) => {
8261
+ let r = t.target.closest("[data-act]");
8262
+ if (!r || !e.contains(r) || r.disabled) return;
8263
+ let i = r.dataset.act, a = u.admin;
8264
+ switch (i) {
8265
+ case "pdf-print":
8266
+ await R();
8267
+ return;
8268
+ case "view":
8269
+ u.view = r.dataset.v;
8270
+ break;
8271
+ case "role":
8272
+ u.role = r.dataset.v;
8273
+ break;
8274
+ case "calc":
8275
+ j(u.calc, r.dataset.f, r.dataset.v);
8276
+ break;
8277
+ case "toggle": {
8278
+ let e = r.dataset.code;
8279
+ u.calc.selected[e] ? delete u.calc.selected[e] : u.calc.selected[e] = v(u.data, u.calc.label).find((t) => Q(t.code, e))?.modes[0];
8280
+ break;
8281
+ }
8282
+ case "mode":
8283
+ t.stopPropagation(), u.calc.selected[r.dataset.code] = r.dataset.v;
8284
+ break;
8285
+ case "clear-courses":
8286
+ u.calc.selected = {};
8287
+ break;
8288
+ case "reset-calc":
8289
+ u.calc = y(u.data);
8290
+ break;
8291
+ case "copy":
8292
+ await _e(ie()), K("Đã sao chép báo giá — dán vào Zalo/Messenger để gửi khách");
8293
+ return;
8294
+ case "tbl-reset":
8295
+ u.table = {
8296
+ ...y(u.data),
8297
+ output: ""
8298
+ };
8299
+ break;
8300
+ case "open-route": {
8301
+ let e = u.table, t = u.data.routes.find((t) => Q(t.label, e.label) && Q(t.code, r.dataset.code));
8302
+ u.calc = {
8303
+ ...e,
8304
+ selected: Object.fromEntries(t.items.map((e) => [e.code, e.mode]))
8305
+ }, delete u.calc.output, u.view = "calc";
8306
+ break;
8307
+ }
8308
+ case "admin-tab":
8309
+ a.tab = r.dataset.v, a.q = "";
8310
+ break;
8311
+ case "row-add": {
8312
+ let e = M(z()).find((e) => e.id === a.tab);
8313
+ V(e).push(e.blank(a.label || z().settings.labels[0]?.name || "")), a.q = "", H(), U();
8314
+ let t = p.querySelector("#pt-admin-table tbody tr:last-child");
8315
+ t?.scrollIntoView({
8316
+ block: "center",
8317
+ behavior: "smooth"
8318
+ }), t?.querySelector("input,select")?.focus();
8319
+ return;
8320
+ }
8321
+ case "row-del": {
8322
+ let e = M(z()).find((e) => e.id === a.tab);
8323
+ V(e).splice(Number(r.dataset.i), 1), a.issues = [], H(), U();
8324
+ return;
8325
+ }
8326
+ case "save":
8327
+ await W();
8328
+ return;
8329
+ case "discard":
8330
+ a.draft = null, a.dirty = !1, a.issues = [], u.months.includes(a.month) || (a.month = u.months[0] ?? u.month);
8331
+ break;
8332
+ case "create-month":
8333
+ await ce();
8334
+ break;
8335
+ case "goto-create":
8336
+ u.view = "admin", a.newMonth = r.dataset.v, u.months.length || (a.month = r.dataset.v);
8337
+ break;
8338
+ case "export-json":
8339
+ ve(`du-lieu-khuyen-mai-${a.month}.json`, JSON.stringify(z(), null, 1));
8340
+ return;
8341
+ case "reset-seed":
8342
+ if (!s(`Thay dữ liệu ${$(a.month).toLowerCase()} bằng bản gốc nhập từ file Excel ban đầu? (chưa lưu cho tới khi bấm Lưu)`)) return;
8343
+ a.draft = C(await n.seed()), [a.draft.settings.validFrom, a.draft.settings.validTo] = Je(a.month), H(), a.dirty = !0;
8344
+ break;
8345
+ default: return;
8346
+ }
8347
+ m();
8348
+ }), e.addEventListener("keydown", (e) => {
8349
+ let t = e.target.closest("[data-act=\"toggle\"]");
8350
+ t && (e.key === " " || e.key === "Enter") && e.target === t && (e.preventDefault(), t.click());
8351
+ }), e.addEventListener("change", async (e) => {
8352
+ let t = e.target, n = u.admin;
8353
+ if (t.dataset.edit != null) {
8354
+ let e = M(z()).find((e) => e.id === n.tab), r = e.columns.find((e) => e.key === t.dataset.k);
8355
+ V(e)[Number(t.dataset.edit)][r.key] = r.type === "bool" ? t.checked : oe(r, t.value), r.type !== "bool" && r.type !== "select" && (t.value = ae(r, V(e)[Number(t.dataset.edit)][r.key])), H();
8356
+ } else {
8357
+ switch (t.dataset.act) {
8358
+ case "setting":
8359
+ z().settings[t.dataset.k] = t.value, H();
8360
+ return;
8361
+ case "doc-text":
8362
+ (z().settings.docTexts ??= {})[t.dataset.k] = t.value, H();
8363
+ return;
8364
+ case "pdf":
8365
+ j(u.pdf, t.dataset.f, t.value, c.get(u.pdf.month)), t.dataset.f === "label" && (u.pdf.outputs = []), u.pdf.scenarios = [];
8366
+ break;
8367
+ case "pdf-month": {
8368
+ let [e, n] = u.pdf.month.split("-");
8369
+ await I(t.dataset.part === "y" ? `${t.value}-${n}` : `${e}-${t.value}`);
8370
+ break;
8371
+ }
8372
+ case "pdf-scen": {
8373
+ let e = c.get(u.pdf.month), n = he(e, u.pdf).map((e) => e.id), r = new Set(u.pdf.scenarios.length ? u.pdf.scenarios : ge(e, u.pdf));
8374
+ t.checked ? r.add(t.value) : r.delete(t.value), u.pdf.scenarios = n.filter((e) => r.has(e)), u.pdf.scenarios.length || (u.pdf.scenarios = [n[0]]);
8375
+ break;
6661
8376
  }
6662
- ]
6663
- },
6664
- {
6665
- label: "CLASSUP 1-1",
6666
- output: "6.5+",
6667
- code: "BS_PRE_IE45_M1_M2",
6668
- name: "BS + PRE + IE4.5 + IE6.5(M1) + IE6.5(M2)",
6669
- items: [
6670
- {
6671
- code: "BS",
6672
- mode: "Online"
6673
- },
6674
- {
6675
- code: "PRE",
6676
- mode: "Online"
6677
- },
6678
- {
6679
- code: "IE4.5",
6680
- mode: "Online"
6681
- },
6682
- {
6683
- code: "IE6.5(M1)",
6684
- mode: "Online"
6685
- },
6686
- {
6687
- code: "IE6.5(M2)",
6688
- mode: "Online"
8377
+ case "view-month":
8378
+ u.month = t.value, u.data = await l(u.month), d();
8379
+ break;
8380
+ case "admin-month":
8381
+ if (u.admin.dirty && !s("Đang có thay đổi chưa lưu. Bỏ thay đổi để chuyển tháng?")) {
8382
+ t.value = u.admin.month;
8383
+ return;
8384
+ }
8385
+ u.admin.month = t.value, u.admin.draft = null, u.admin.dirty = !1, u.admin.issues = [], await l(t.value);
8386
+ break;
8387
+ case "new-month":
8388
+ u.admin.newMonth = t.value;
8389
+ return;
8390
+ case "copy-from":
8391
+ u.admin.copyFrom = t.value;
8392
+ return;
8393
+ case "pdf-title":
8394
+ u.pdf.title = t.value.trim();
8395
+ break;
8396
+ case "pdf-sec":
8397
+ case "pdf-out": {
8398
+ let e = t.dataset.act === "pdf-sec" ? "sections" : "outputs", n = e === "sections" ? le.map((e) => e.id) : me(c.get(u.pdf.month), u.pdf.label), r = new Set(u.pdf[e].length || e === "sections" ? u.pdf[e] : n);
8399
+ t.checked ? r.add(t.value) : r.delete(t.value), u.pdf[e] = n.filter((e) => r.has(e));
8400
+ break;
6689
8401
  }
6690
- ]
6691
- },
6692
- {
6693
- label: "CLASSUP 1-1",
6694
- output: "6.5+",
6695
- code: "PRE_IE45_M1_M2_READY",
6696
- name: "PRE + IE4.5 + IE6.5(M1) + IE6.5(M2) + Ready",
6697
- items: [
6698
- {
6699
- code: "PRE",
6700
- mode: "Online"
6701
- },
6702
- {
6703
- code: "IE4.5",
6704
- mode: "Online"
6705
- },
6706
- {
6707
- code: "IE6.5(M1)",
6708
- mode: "Online"
6709
- },
6710
- {
6711
- code: "IE6.5(M2)",
6712
- mode: "Online"
6713
- },
6714
- {
6715
- code: "Ready",
6716
- mode: "Online"
8402
+ case "tbl":
8403
+ j(u.table, t.dataset.f, t.value), t.dataset.f === "label" && (u.table.output = "");
8404
+ break;
8405
+ case "pick-route": {
8406
+ let e = u.data.routes.find((e) => Q(e.label, u.calc.label) && Q(e.code, t.value));
8407
+ e && (u.calc.selected = Object.fromEntries(e.items.map((e) => [e.code, e.mode])));
8408
+ break;
6717
8409
  }
6718
- ]
6719
- },
6720
- {
6721
- label: "CLASSUP 1-1",
6722
- output: "6.5+",
6723
- code: "BS_PRE_IE45_M1_M2_READY",
6724
- name: "BS + PRE + IE4.5 + IE6.5(M1) + IE6.5(M2) + Ready",
6725
- items: [
6726
- {
6727
- code: "BS",
6728
- mode: "Online"
6729
- },
6730
- {
6731
- code: "PRE",
6732
- mode: "Online"
6733
- },
6734
- {
6735
- code: "IE4.5",
6736
- mode: "Online"
6737
- },
6738
- {
6739
- code: "IE6.5(M1)",
6740
- mode: "Online"
6741
- },
6742
- {
6743
- code: "IE6.5(M2)",
6744
- mode: "Online"
6745
- },
6746
- {
6747
- code: "Ready",
6748
- mode: "Online"
8410
+ case "admin-label":
8411
+ n.label = t.value, U();
8412
+ return;
8413
+ case "import-json":
8414
+ case "import-xlsx": {
8415
+ let e = t.files?.[0];
8416
+ if (!e) return;
8417
+ try {
8418
+ let r = t.dataset.act === "import-json" ? JSON.parse(await e.text()) : await se(e, z());
8419
+ if (!r?.settings || !Array.isArray(r.courses)) throw Error("File không đúng cấu trúc");
8420
+ Be(r) !== n.month && ([r.settings.validFrom, r.settings.validTo] = Je(n.month)), n.draft = C(r), n.issues = ne(r), H(), n.dirty = !0, K(`Đã nạp ${e.name} — kiểm tra rồi bấm Lưu & áp dụng`);
8421
+ } catch (e) {
8422
+ K(`Không nhập được: ${e.message}`);
8423
+ }
8424
+ break;
6749
8425
  }
6750
- ]
8426
+ default: return;
8427
+ }
8428
+ m();
8429
+ }
8430
+ }), e.addEventListener("input", (e) => {
8431
+ e.target.dataset.act === "admin-q" && (u.admin.q = e.target.value, U());
8432
+ });
8433
+ let q = (e) => {
8434
+ u.admin.dirty && e.preventDefault();
8435
+ };
8436
+ return window.addEventListener("beforeunload", q), m(), {
8437
+ setRole(e) {
8438
+ u.role = e, m();
6751
8439
  },
6752
- {
6753
- label: "CLASSUP 1-1",
6754
- output: "6.5+",
6755
- code: "MA_MB_BS_PRE_IE45_M1_M2",
6756
- name: "Module A + Module B + BS + PRE + IE4.5 + IE6.5(M1) + IE6.5(M2)",
6757
- items: [
6758
- {
6759
- code: "Module A",
6760
- mode: "Online"
6761
- },
6762
- {
6763
- code: "Module B",
6764
- mode: "Online"
6765
- },
6766
- {
6767
- code: "BS",
6768
- mode: "Online"
6769
- },
6770
- {
6771
- code: "PRE",
6772
- mode: "Online"
6773
- },
6774
- {
6775
- code: "IE4.5",
6776
- mode: "Online"
6777
- },
6778
- {
6779
- code: "IE6.5(M1)",
6780
- mode: "Online"
6781
- },
6782
- {
6783
- code: "IE6.5(M2)",
6784
- mode: "Online"
6785
- }
6786
- ]
8440
+ async reload() {
8441
+ c.clear(), u.months = await n.listMonths(), u.data = await l(u.month), await l(u.admin.month), await l(u.pdf.month), d(), m();
6787
8442
  },
6788
- {
6789
- label: "CLASSUP 1-1",
6790
- output: "6.5+",
6791
- code: "MA_MB_BS_PRE_IE45_M1_M2_READY",
6792
- name: "Module A + Module B + BS + PRE + IE4.5 + IE6.5(M1) + IE6.5(M2) + Ready",
6793
- items: [
6794
- {
6795
- code: "Module A",
6796
- mode: "Online"
6797
- },
6798
- {
6799
- code: "Module B",
6800
- mode: "Online"
6801
- },
6802
- {
6803
- code: "BS",
6804
- mode: "Online"
6805
- },
6806
- {
6807
- code: "PRE",
6808
- mode: "Online"
6809
- },
6810
- {
6811
- code: "IE4.5",
6812
- mode: "Online"
6813
- },
6814
- {
6815
- code: "IE6.5(M1)",
6816
- mode: "Online"
6817
- },
6818
- {
6819
- code: "IE6.5(M2)",
6820
- mode: "Online"
6821
- },
6822
- {
6823
- code: "Ready",
6824
- mode: "Online"
6825
- }
6826
- ]
8443
+ destroy() {
8444
+ window.removeEventListener("beforeunload", q), e.innerHTML = "";
8445
+ },
8446
+ unmount() {
8447
+ this.destroy();
6827
8448
  }
6828
- ]
6829
- }, $ = { install(e) {
6830
- e.component("PromoTool", K);
8449
+ };
8450
+ }
8451
+ // src/vue/PromoTool.vue
8452
+ var Ze = /* @__PURE__ */ t({
8453
+ __name: "PromoTool",
8454
+ props: {
8455
+ role: { default: "sale" },
8456
+ store: {},
8457
+ user: { default: null },
8458
+ allowRoleSwitch: {
8459
+ type: Boolean,
8460
+ default: !1
8461
+ }
8462
+ },
8463
+ emits: ["ready"],
8464
+ setup(t, { expose: s, emit: c }) {
8465
+ let l = t, u = c, d = a(null), f = null;
8466
+ return r(async () => {
8467
+ d.value && (f = await Xe(d.value, {
8468
+ role: l.role,
8469
+ store: l.store,
8470
+ user: l.user,
8471
+ allowRoleSwitch: l.allowRoleSwitch
8472
+ }), u("ready", f));
8473
+ }), n(() => {
8474
+ f && typeof f.destroy == "function" && f.destroy();
8475
+ }), o(() => l.role, (e) => {
8476
+ f && e && f.setRole(e);
8477
+ }), s({
8478
+ getInstance: () => f,
8479
+ setRole: (e) => f?.setRole(e),
8480
+ reload: () => f?.reload()
8481
+ }), (t, n) => (i(), e("div", {
8482
+ ref_key: "containerRef",
8483
+ ref: d,
8484
+ class: "pt-vue-container"
8485
+ }, null, 512));
8486
+ }
8487
+ }), Qe = { install(e) {
8488
+ e.component("PromoTool", Ze);
6831
8489
  } };
6832
- export { K as PromoTool, u as STATUS_OK, h as coursesForLabel, $ as default, f as findMethod, d as findProgram, m as isFixedTerm, v as lktFormatsFor, y as lktGroupsFor, Y as localStore, G as mountPromoTool, b as normalizeData, C as quote, Z as restStore, T as routeTable, Q as seed, X as supabaseStore, p as termsFor, E as validateData };
8490
+ export { Ze as PromoTool, m as STATUS_OK, v as coursesForLabel, Qe as default, g as findMethod, h as findProgram, ee as isFixedTerm, x as lktFormatsFor, S as lktGroupsFor, Ve as localStore, Xe as mountPromoTool, C as normalizeData, E as quote, Ue as restStore, te as routeTable, We as seed, He as supabaseStore, _ as termsFor, ne as validateData };