@feedmepos/mf-inventory-portal 0.0.19-dev.2 → 0.0.19-dev.3

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.
Files changed (53) hide show
  1. package/dist/{ApprovalView-DU7oB2Zk.js → ApprovalView-CS7NtcBA.js} +16 -17
  2. package/dist/{BindingsDialog-BgfV0G46.js → BindingsDialog-BA2w-qkY.js} +5 -6
  3. package/dist/{BindingsPicker-tUI5WYBk.js → BindingsPicker-wf7b30Bk.js} +6 -7
  4. package/dist/{BindingsTable-8G-Nc4pC.js → BindingsTable-mqqSPDbO.js} +14 -17
  5. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-DaHXKF1s.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CViUEhuw.js} +16 -17
  6. package/dist/IngredientsView-BVX31o67.js +1750 -0
  7. package/dist/IntegrationView-DFdl_238.js +1172 -0
  8. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-BKlWhMnB.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-BENFVQkL.js} +1 -1
  9. package/dist/{PurchaseOrderPrintPreview-YFcOtdfJ.js → PurchaseOrderPrintPreview-06PokYt4.js} +13 -13
  10. package/dist/{ReceiveRequestView-bIXyVVX9.js → ReceiveRequestView-ck-05Ly7.js} +165 -172
  11. package/dist/RecipeView-CiOb2lvU.js +572 -0
  12. package/dist/StockView-5LkTxYI2.js +1876 -0
  13. package/dist/{SupplierView-BiSqTXnz.js → SupplierView-BAfC5Wcw.js} +34 -37
  14. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-CvbKNb0C.js → TransferDetails.vue_vue_type_script_setup_true_lang-qZDMkkIZ.js} +34 -36
  15. package/dist/UnitView-wsbXOcbf.js +638 -0
  16. package/dist/{WarehouseView-B8UxxAL6.js → WarehouseView-DHhDNAk8.js} +49 -50
  17. package/dist/app-DNCC20Aq.js +66729 -0
  18. package/dist/app.d.ts +29 -0
  19. package/dist/app.js +4 -3
  20. package/dist/{decimal-BtIn4K57.js → decimal-DaXHxukU.js} +1 -1
  21. package/dist/{stock-estimate-C4PL0Fcz.js → id-to-date-XiomI6dP.js} +12 -13
  22. package/dist/{layout-ITqYtCVu.js → layout-DvgFrTEG.js} +14 -14
  23. package/dist/router/name.d.ts +1 -2
  24. package/dist/{supplier-CA0OR3DU.js → supplier-BepZrUgL.js} +3 -3
  25. package/dist/tsconfig.app.tsbuildinfo +1 -1
  26. package/dist/views/ingredients/composables/use-ingredient-form.d.ts +14 -2
  27. package/dist/views/ingredients/composables/use-ingredient-table.d.ts +1 -2
  28. package/dist/views/receive-request/composables/use-receive-request-table.d.ts +12 -12
  29. package/dist/views/recipe/composables/use-recipe-form.d.ts +14 -2
  30. package/dist/views/recipe/composables/use-recipe-table.d.ts +1 -2
  31. package/dist/views/stock/composables/use-stock-action.d.ts +26 -0
  32. package/dist/views/stock/composables/use-stock-table.d.ts +1 -8
  33. package/dist/views/unit/composables/use-unit-form.d.ts +14 -2
  34. package/dist/views/unit/composables/use-unit-table.d.ts +1 -2
  35. package/dist/{xlsx-DAVatAlv.js → xlsx-DaxqUL1h.js} +660 -660
  36. package/dist/{xlsx.util-BsZI2tNE.js → xlsx.util-Dwiw0sTo.js} +2 -2
  37. package/package.json +1 -1
  38. package/dist/FmMultiselectDialog.vue_vue_type_script_setup_true_lang-CxOk5ule.js +0 -143
  39. package/dist/FmUnitInput.vue_vue_type_script_setup_true_lang-D-vJDMKb.js +0 -236
  40. package/dist/IngredientsView-CAh7D4tL.js +0 -1760
  41. package/dist/IntegrationView-Bf7yHuS8.js +0 -1166
  42. package/dist/InventoryBindingForm.vue_vue_type_script_setup_true_lang-BdVrpR9J.js +0 -277
  43. package/dist/RecipeView-BD0mvxCg.js +0 -575
  44. package/dist/StockView-BCq37bGl.js +0 -1865
  45. package/dist/UnitView-DSdn__9m.js +0 -643
  46. package/dist/app-RVyC2D4O.js +0 -43892
  47. package/dist/date2-C2PfOqbB.js +0 -95
  48. package/dist/dayjs.min-0pzT_dbr.js +0 -282
  49. package/dist/fuzzy-yzIM5KUK.js +0 -41
  50. package/dist/index-l87_vggM.js +0 -21515
  51. package/dist/number-B5d98l0m.js +0 -97
  52. package/dist/rules-CCwuHe8Y.js +0 -85
  53. package/dist/use-inventory-binding-dialog-CTriImiV.js +0 -93
@@ -0,0 +1,1750 @@
1
+ import { ref as z, defineComponent as le, computed as C, resolveComponent as R, openBlock as y, createBlock as B, withCtx as $, createVNode as f, unref as d, createElementBlock as U, Fragment as Q, createElementVNode as c, createCommentVNode as O, onMounted as nt, watch as je, normalizeClass as X, createTextVNode as He, toDisplayString as L, renderList as oe, isRef as Ee, renderSlot as ge, createSlots as Oe, normalizeStyle as ot, Teleport as De, normalizeProps as lt, guardReactiveProps as at } from "vue";
2
+ import { u as ae, c as Ye, S as rt, _ as st, a as Ge, g as _e, t as qe, F as ve, R as be, U as it, A as ke, M as ut, d as Ae, b as We, C as Ce, e as Te, f as dt, h as ct, I as mt, i as pt, j as vt } from "./app-DNCC20Aq.js";
3
+ import { useDialog as Ke, useSnackbar as xe, useProxiedModel as Pe, useDialogChild as ft, useBreakpoints as yt } from "@feedmepos/ui-library";
4
+ import { i as gt, _ as bt } from "./is-linked-ingredient-error-C6AghEwR.js";
5
+ import { F as K, D as Be, R as he } from "./row-action.enum-BwQbURNh.js";
6
+ import { useI18n as re, useCoreStore as fe } from "@feedmepos/mf-common";
7
+ import { defineStore as ht, storeToRefs as _t } from "pinia";
8
+ import { c as xt, _ as Vt, F as ze, u as kt } from "./layout-DvgFrTEG.js";
9
+ import { _ as Ct, a as Ft } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CViUEhuw.js";
10
+ import { g as St, _ as Fe, S as Se } from "./StockForecast.vue_vue_type_style_index_0_lang-KLXSWvo5.js";
11
+ import { _ as we, t as Je, d as Qe, s as wt, r as Mt } from "./xlsx.util-Dwiw0sTo.js";
12
+ import { _ as Me } from "./PreviewBadge.vue_vue_type_script_setup_true_lang-BvadeWUz.js";
13
+ import "./array-AvWd53LI.js";
14
+ const $e = ht("ingredientForm", function() {
15
+ const i = Ke(), m = xe(), r = ae(), t = z(!1), { t: l } = re(), o = z();
16
+ function p() {
17
+ const h = {
18
+ unit: {},
19
+ mode: K.CREATE,
20
+ show: !0,
21
+ "onUpdate:show"(u) {
22
+ o.value.show = u;
23
+ }
24
+ };
25
+ o.value = h;
26
+ }
27
+ async function b(h) {
28
+ const u = {
29
+ unit: Ye(h),
30
+ mode: K.UPDATE,
31
+ show: !0,
32
+ "onUpdate:show"(x) {
33
+ o.value.show = x;
34
+ }
35
+ };
36
+ o.value = u;
37
+ }
38
+ async function _(h) {
39
+ t.value = !0;
40
+ try {
41
+ await r.deleteSku(h), m.open({
42
+ title: "Success",
43
+ message: `Deleted ${h.name}`,
44
+ type: "success"
45
+ });
46
+ } catch (u) {
47
+ u instanceof rt && gt(u) ? i.open({
48
+ title: "Cannot delete ingredient",
49
+ contentComponent: bt,
50
+ contentComponentProps: {
51
+ subject: (h == null ? void 0 : h.name) ?? "",
52
+ items: u.errorResponse.message
53
+ },
54
+ secondaryActions: {
55
+ text: "Close",
56
+ close: !0
57
+ }
58
+ }) : console.log("unable to delete ingredient", u), m.open({
59
+ title: `Cannot delete ${h.name}`,
60
+ message: "Please try again.",
61
+ type: "error"
62
+ }), console.error("failed to delete ingredient", u);
63
+ } finally {
64
+ t.value = !1;
65
+ }
66
+ }
67
+ function g(h) {
68
+ i.open({
69
+ title: l("inventory.ingredient.delete.title", [(h == null ? void 0 : h.name) ?? ""]),
70
+ closeButton: !1,
71
+ message: l("inventory.ingredient.delete.message"),
72
+ primaryActions: {
73
+ text: l("common.delete"),
74
+ close: !0,
75
+ variant: "destructive"
76
+ },
77
+ secondaryActions: {
78
+ text: l("common.cancel"),
79
+ close: !0
80
+ }
81
+ }).onPrimary(() => _(h));
82
+ }
83
+ return {
84
+ createIngredient: p,
85
+ updateIngredient: b,
86
+ deleteIngredient: g,
87
+ ingredientDialogProps: o,
88
+ ingredientViewLoading: t
89
+ };
90
+ });
91
+ function $t() {
92
+ const { updateIngredient: s, deleteIngredient: i } = $e(), { t: m } = re();
93
+ async function r(l, o) {
94
+ const p = Ye(o);
95
+ if (l === he.Edit) {
96
+ await s(p);
97
+ return;
98
+ }
99
+ if (l === he.Delete) {
100
+ await i(p);
101
+ return;
102
+ }
103
+ }
104
+ return { columnDefs: [
105
+ {
106
+ accessorKey: "code",
107
+ header: () => m("inventory.ingredient.code"),
108
+ enableSorting: !0,
109
+ size: 300
110
+ },
111
+ {
112
+ accessorKey: "name",
113
+ header: () => m("inventory.ingredient.name"),
114
+ enableSorting: !0,
115
+ size: 300
116
+ },
117
+ {
118
+ id: "unit",
119
+ header: () => m("inventory.ingredient.unit"),
120
+ cell(l) {
121
+ var p;
122
+ const o = l.row.original;
123
+ if (o.trackingMeasurement) {
124
+ const b = (p = o.unit.measurements) == null ? void 0 : p.find(
125
+ (_) => _.id === o.trackingMeasurement
126
+ );
127
+ if (b)
128
+ return `${b.name} (${b.abbrev})`;
129
+ }
130
+ return `${o.unit.name} (${o.unit.abbrev})`;
131
+ },
132
+ enableSorting: !1,
133
+ size: "auto"
134
+ },
135
+ {
136
+ id: "action",
137
+ header: "",
138
+ cell(l) {
139
+ return xt(
140
+ [Be[he.Edit], Be[he.Delete]],
141
+ (o) => {
142
+ r(o, l.row.original);
143
+ }
144
+ );
145
+ },
146
+ enableSorting: !1,
147
+ size: 40,
148
+ meta: {
149
+ cellClass: "",
150
+ headerClass: ""
151
+ }
152
+ }
153
+ ] };
154
+ }
155
+ const It = /* @__PURE__ */ le({
156
+ __name: "ConvertForm",
157
+ props: {
158
+ modelValue: {},
159
+ rootValue: {},
160
+ disabled: { type: Boolean }
161
+ },
162
+ emits: ["update:modelValue"],
163
+ setup(s, { emit: i }) {
164
+ const m = s, r = C(() => {
165
+ var u;
166
+ return (u = m.rootValue) == null ? void 0 : u.unit;
167
+ }), t = C(() => {
168
+ var u;
169
+ return (u = m.rootValue) == null ? void 0 : u._id;
170
+ }), l = i, { t: o } = re(), p = C({
171
+ get() {
172
+ return !!m.modelValue;
173
+ },
174
+ set(u) {
175
+ u ? l("update:modelValue", {
176
+ measurement: null,
177
+ inventoryBindings: []
178
+ }) : l("update:modelValue", null);
179
+ }
180
+ }), b = C(() => St(r.value));
181
+ function _(u) {
182
+ const x = m.modelValue ?? {};
183
+ x.measurement = u ? `${u}` : null, l("update:modelValue", x);
184
+ }
185
+ function g(u) {
186
+ const x = m.modelValue ?? {};
187
+ x.inventoryBindings = u, l("update:modelValue", x);
188
+ }
189
+ const h = C(() => {
190
+ if (!m.modelValue) return null;
191
+ const u = m.modelValue;
192
+ return u.measurement ? b.value.find((x) => x.value === u.measurement) ?? null : b.value.find((x) => x.value === null) ?? null;
193
+ });
194
+ return (u, x) => {
195
+ const D = R("FmSwitch"), S = R("FmSelect"), w = R("FmCard");
196
+ return y(), B(w, {
197
+ variant: "outlined",
198
+ class: "p-16 flex flex-col gap-16"
199
+ }, {
200
+ default: $(() => {
201
+ var M, V;
202
+ return [
203
+ f(D, {
204
+ value: "",
205
+ "model-value": p.value,
206
+ "onUpdate:modelValue": x[0] || (x[0] = (H) => p.value = H),
207
+ label: d(o)("inventory.ingredient.convertible.title"),
208
+ sublabel: d(o)("inventory.ingredient.convertible.subtitle"),
209
+ labelPlacement: "right"
210
+ }, null, 8, ["model-value", "label", "sublabel"]),
211
+ p.value ? (y(), U(Q, { key: 0 }, [
212
+ c("div", null, [
213
+ f(S, {
214
+ label: d(o)("inventory.ingredient.convertible.convertTo"),
215
+ modelValue: (M = h.value) == null ? void 0 : M.value,
216
+ "onUpdate:modelValue": _,
217
+ items: b.value
218
+ }, null, 8, ["label", "modelValue", "items"])
219
+ ]),
220
+ f(st, {
221
+ id: t.value,
222
+ "model-value": ((V = u.modelValue) == null ? void 0 : V.inventoryBindings) ?? [],
223
+ "onUpdate:modelValue": g,
224
+ "exclude-binding-id": t.value
225
+ }, null, 8, ["id", "model-value", "exclude-binding-id"])
226
+ ], 64)) : O("", !0)
227
+ ];
228
+ }),
229
+ _: 1
230
+ });
231
+ };
232
+ }
233
+ });
234
+ function ue() {
235
+ return {
236
+ low: 6,
237
+ mid: 14
238
+ };
239
+ }
240
+ const Rt = { class: "text-fm-color-typo-secondary" }, Ut = { class: "text-fm-color-typo-secondary whitespace-nowrap" }, Et = { class: "col-span-2 mt-16" }, Dt = { class: "col-span-2 mt-16 border-1 border-fm-color-neutral-gray-200 fm-corner-radius-lg flex flex-col p-16 gap-16" }, At = { class: "w-full" }, Tt = {
241
+ key: 0,
242
+ class: "flex flex-col gap-8"
243
+ }, Pt = {
244
+ type: "button",
245
+ class: "inline-flex h-32 items-center"
246
+ }, Bt = {
247
+ key: 2,
248
+ class: "col-span-2 mt-16 border-1 border-fm-color-neutral-gray-200 fm-corner-radius-lg flex flex-col p-16 gap-16"
249
+ }, zt = { class: "col-span-2 flex flex-col gap-12" }, Lt = { class: "flex flex-col gap-4" }, Nt = { class: "fm-typo-en-title-sm-800" }, jt = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Ht = { class: "col-span-2 flex flex-col gap-4" }, Ot = { class: "flex fm-corner-radius-md border-1 border-fm-color-neutral-gray-200" }, Yt = { class: "flex-1 p-12 flex flex-col gap-8" }, Gt = { class: "mx-auto" }, qt = { class: "flex flex-col" }, Wt = { class: "fm-typo-en-body-sm-600 translate-y-4" }, Kt = /* @__PURE__ */ c("div", {
250
+ class: "text-fm-color-typo-secondary",
251
+ style: { "padding-right": "32px" }
252
+ }, "days", -1), Jt = /* @__PURE__ */ c("div", {
253
+ class: "h-full bg-fm-color-neutral-gray-200 relative",
254
+ style: { width: "1px" }
255
+ }, [
256
+ /* @__PURE__ */ c("div", {
257
+ class: "absolute bg-white",
258
+ style: { transform: "translate(-50%, -50%)", left: "50%", top: "20%" }
259
+ }, " < ")
260
+ ], -1), Qt = { class: "flex-1 p-12 flex flex-col gap-8" }, Xt = { class: "mx-auto" }, Zt = { class: "flex flex-col" }, en = { class: "fm-typo-en-body-sm-600 translate-y-4" }, tn = /* @__PURE__ */ c("div", {
261
+ class: "text-fm-color-typo-secondary",
262
+ style: { "padding-right": "32px" }
263
+ }, "days", -1), nn = /* @__PURE__ */ c("div", {
264
+ class: "h-full bg-fm-color-neutral-gray-200 relative",
265
+ style: { width: "1px" }
266
+ }, [
267
+ /* @__PURE__ */ c("div", {
268
+ class: "absolute bg-white",
269
+ style: { transform: "translate(-50%, -50%)", left: "50%", top: "20%" }
270
+ }, " < ")
271
+ ], -1), on = { class: "flex-1 p-12 flex flex-col gap-8" }, ln = { class: "mx-auto" }, an = { class: "flex flex-col" }, rn = { class: "fm-typo-en-body-sm-600 translate-y-4" };
272
+ var Ie = /* @__PURE__ */ ((s) => (s.Daily = "Daily", s.Consumables = "Consumables", s.ShortTerm = "Short term", s.Kitchen = "Kitchen", s))(Ie || {});
273
+ const sn = /* @__PURE__ */ le({
274
+ __name: "IngredientForm",
275
+ props: {
276
+ mode: {},
277
+ modelValue: {},
278
+ disabled: { type: Boolean }
279
+ },
280
+ emits: ["update:modelValue", "click:submit"],
281
+ setup(s, { expose: i, emit: m }) {
282
+ var pe;
283
+ const { t: r } = re(), t = s, l = m, o = ae(), p = fe(), b = We();
284
+ function _(e) {
285
+ if (e.length === 0) return;
286
+ const n = e[0], v = t.modelValue ?? {
287
+ unit: o.units.find((k) => k)
288
+ };
289
+ v.unit || (v.unit = n, l("update:modelValue", v));
290
+ }
291
+ nt(() => {
292
+ _(o.units);
293
+ }), je([() => o.units], ([e]) => {
294
+ _(e);
295
+ });
296
+ function g() {
297
+ l("click:submit");
298
+ }
299
+ const h = C({
300
+ get() {
301
+ var e;
302
+ return ((e = t.modelValue) == null ? void 0 : e.code) ?? "";
303
+ },
304
+ set(e) {
305
+ const n = t.modelValue ? {
306
+ ...t.modelValue
307
+ } : {};
308
+ n.code = e, l("update:modelValue", n);
309
+ }
310
+ }), u = C({
311
+ get() {
312
+ var e;
313
+ return ((e = t.modelValue) == null ? void 0 : e.name) ?? "";
314
+ },
315
+ set(e) {
316
+ const n = t.modelValue ? {
317
+ ...t.modelValue
318
+ } : {};
319
+ n.name = e, l("update:modelValue", n);
320
+ }
321
+ }), x = C({
322
+ get() {
323
+ var n, v;
324
+ const e = (v = (n = t.modelValue) == null ? void 0 : n.defaultCost) == null ? void 0 : v.costPerUnit;
325
+ return e ? +Ge(e) : 0;
326
+ },
327
+ set(e) {
328
+ var v, k, T, I;
329
+ const n = t.modelValue ? {
330
+ ...t.modelValue
331
+ } : {};
332
+ n.defaultCost ?? (n.defaultCost = {
333
+ costPerUnit: {
334
+ amount: 0,
335
+ precision: 2,
336
+ currency: ((v = _e(p.currentCountry.value)) == null ? void 0 : v.currency) ?? "MYR"
337
+ },
338
+ measurement: (I = (T = (k = t.modelValue) == null ? void 0 : k.unit) == null ? void 0 : T.measurements) == null ? void 0 : I.find(
339
+ (Y) => {
340
+ var G;
341
+ return Y.id === ((G = t.modelValue) == null ? void 0 : G.trackingMeasurement);
342
+ }
343
+ )
344
+ }), n.defaultCost.costPerUnit = {
345
+ ...n.defaultCost.costPerUnit,
346
+ ...qe(+e, 4)
347
+ }, l("update:modelValue", n);
348
+ }
349
+ }), D = C(() => {
350
+ var n, v, k;
351
+ const e = ((n = t.modelValue) == null ? void 0 : n.unit) ?? o.units.find((T) => T);
352
+ return e ? {
353
+ _id: e._id,
354
+ measurement: (v = t.modelValue) == null ? void 0 : v.trackingMeasurement,
355
+ name: ((k = e.measurements.find((T) => {
356
+ var I;
357
+ return T.id === ((I = t.modelValue) == null ? void 0 : I.trackingMeasurement);
358
+ })) == null ? void 0 : k.name) ?? e.name
359
+ } : null;
360
+ }), S = C(
361
+ () => o.units.flatMap(({ name: e, _id: n, abbrev: v, measurements: k }) => [
362
+ {
363
+ label: `${e}`,
364
+ value: null,
365
+ displayAsSection: !0
366
+ },
367
+ {
368
+ label: `${e} (${v})`,
369
+ value: { _id: n },
370
+ displayAsSection: !1
371
+ },
372
+ ...k.map(({ id: T, name: I, abbrev: Y }) => ({
373
+ label: `${I} (${Y})`,
374
+ value: { _id: n, measurement: T },
375
+ displayAsSection: !1
376
+ }))
377
+ ])
378
+ );
379
+ function w(e) {
380
+ var n, v, k, T, I;
381
+ return ((v = (n = t.modelValue) == null ? void 0 : n.unit) == null ? void 0 : v._id) === ((k = e.value) == null ? void 0 : k._id) && ((T = t.modelValue) == null ? void 0 : T.trackingMeasurement) === ((I = e.value) == null ? void 0 : I.measurement);
382
+ }
383
+ function M(e) {
384
+ var Y, G;
385
+ if (!e) return;
386
+ const { _id: n, measurement: v } = e, k = v || void 0, T = o.units.find((ie) => ie._id === n);
387
+ if (!T)
388
+ return;
389
+ const I = t.modelValue ?? {};
390
+ I.unit = T, I.trackingMeasurement = k, I.convert && (I.convert.measurement = k || null), b.enableTotalCost && (I.defaultCost = {
391
+ measurement: T.measurements.find((ie) => ie.id === k),
392
+ costPerUnit: {
393
+ ...((Y = I.defaultCost) == null ? void 0 : Y.costPerUnit) ?? {
394
+ amount: 0,
395
+ precision: 2,
396
+ currency: ((G = _e(p.currentCountry.value)) == null ? void 0 : G.currency) ?? "MYR"
397
+ }
398
+ }
399
+ }), l("update:modelValue", I);
400
+ }
401
+ const V = C({
402
+ get() {
403
+ var e;
404
+ return ((e = t.modelValue) == null ? void 0 : e.operationalGroup) ?? null;
405
+ },
406
+ set(e) {
407
+ const n = t.modelValue ? {
408
+ ...t.modelValue
409
+ } : {};
410
+ n.operationalGroup = e, l("update:modelValue", n);
411
+ }
412
+ }), H = C(
413
+ () => [
414
+ ...new Set(
415
+ o.skus.map((e) => e.operationalGroup ?? "").filter((e) => e && !Object.values(Ie).includes(e))
416
+ )
417
+ ].sort()
418
+ ), J = C({
419
+ get() {
420
+ return V.value !== null;
421
+ },
422
+ set(e) {
423
+ e ? V.value = "" : V.value = null;
424
+ }
425
+ }), ee = C({
426
+ get() {
427
+ var e;
428
+ return ((e = t.modelValue) == null ? void 0 : e.convert) ?? null;
429
+ },
430
+ set(e) {
431
+ const n = t.modelValue ? {
432
+ ...t.modelValue
433
+ } : {};
434
+ e ? n.convert = e : n.convert = null, l("update:modelValue", n);
435
+ }
436
+ }), de = C(() => ve.options.filter(
437
+ (e) => e === ve.enum.FIFO || e === ve.enum.WAVG
438
+ ).map((e) => ({
439
+ label: r(`inventory.ingredient.valuationMethod.${e}`),
440
+ value: e
441
+ }))), Z = C({
442
+ get() {
443
+ var e;
444
+ return ((e = t.modelValue) == null ? void 0 : e.valuation) ?? "WAVG";
445
+ },
446
+ set(e) {
447
+ const n = t.modelValue ? {
448
+ ...t.modelValue
449
+ } : {};
450
+ n.valuation = e, l("update:modelValue", n);
451
+ }
452
+ }), a = z();
453
+ i({
454
+ validateInputs: () => {
455
+ var e, n;
456
+ (n = (e = a.value) == null ? void 0 : e.validateInputs) == null || n.call(e);
457
+ },
458
+ resetInputsValidation: () => {
459
+ var e, n;
460
+ (n = (e = a.value) == null ? void 0 : e.resetInputsValidation) == null || n.call(e);
461
+ },
462
+ resetInputs: () => {
463
+ var e, n;
464
+ (n = (e = a.value) == null ? void 0 : e.resetInputs) == null || n.call(e);
465
+ }
466
+ });
467
+ const N = z(!1), W = C(
468
+ () => {
469
+ var e, n, v;
470
+ return (e = t.modelValue) != null && e._id ? ((v = o.menu.bindedBySkuId[(n = t.modelValue) == null ? void 0 : n._id]) == null ? void 0 : v.filter(
471
+ (k) => k.from === "INGREDIENT"
472
+ )) ?? [] : [];
473
+ }
474
+ ), se = C(
475
+ () => {
476
+ var e, n, v;
477
+ return (e = t.modelValue) != null && e._id ? ((v = o.menu.bindedBySkuId[(n = t.modelValue) == null ? void 0 : n._id]) == null ? void 0 : v.filter(
478
+ (k) => k.from === "RECIPE"
479
+ )) ?? [] : [];
480
+ }
481
+ ), te = C(
482
+ () => {
483
+ var e, n, v;
484
+ return (e = t.modelValue) != null && e._id ? ((v = o.menu.bindedBySkuId[(n = t.modelValue) == null ? void 0 : n._id]) == null ? void 0 : v.filter((k) => k.from === "MENU")) ?? [] : [];
485
+ }
486
+ ), A = C(
487
+ () => o.skus.map((e) => ({ label: e.name, value: e.code }))
488
+ ), E = z((pe = t.modelValue) == null ? void 0 : pe.code);
489
+ function ce(e) {
490
+ var v;
491
+ const n = e.el;
492
+ n && ((v = n.querySelector("[x-should-scroll-into=true]")) == null || v.scrollIntoView());
493
+ }
494
+ function ne(e) {
495
+ switch (e) {
496
+ case Ce.MY:
497
+ return "MYR";
498
+ case Ce.SG:
499
+ return "SGD";
500
+ case Ce.ID:
501
+ return "IDR";
502
+ default:
503
+ return "MYR";
504
+ }
505
+ }
506
+ const me = C(
507
+ () => {
508
+ var e, n, v, k, T, I;
509
+ return ((k = (v = (n = (e = t.modelValue) == null ? void 0 : e.unit) == null ? void 0 : n.measurements) == null ? void 0 : v.find(
510
+ (Y) => {
511
+ var G;
512
+ return Y.id === ((G = t.modelValue) == null ? void 0 : G.trackingMeasurement);
513
+ }
514
+ )) == null ? void 0 : k.abbrev) ?? ((I = (T = t.modelValue) == null ? void 0 : T.unit) == null ? void 0 : I.abbrev);
515
+ }
516
+ ), P = C({
517
+ get() {
518
+ var e, n;
519
+ return ((n = (e = t.modelValue) == null ? void 0 : e.thresholds) == null ? void 0 : n.low) ?? ue().low;
520
+ },
521
+ set(e) {
522
+ var k;
523
+ const n = ((k = t.modelValue) == null ? void 0 : k.thresholds) ?? ue();
524
+ n.low = e;
525
+ const v = t.modelValue ? {
526
+ ...t.modelValue
527
+ } : {};
528
+ v.thresholds = n, l("update:modelValue", v);
529
+ }
530
+ }), j = C({
531
+ get() {
532
+ var e, n;
533
+ return ((n = (e = t.modelValue) == null ? void 0 : e.thresholds) == null ? void 0 : n.mid) ?? ue().mid;
534
+ },
535
+ set(e) {
536
+ var k;
537
+ const n = ((k = t.modelValue) == null ? void 0 : k.thresholds) ?? ue();
538
+ n.mid = e;
539
+ const v = t.modelValue ? {
540
+ ...t.modelValue
541
+ } : {};
542
+ v.thresholds = n, l("update:modelValue", v);
543
+ }
544
+ });
545
+ function ye() {
546
+ return function(n) {
547
+ return typeof (n == null ? void 0 : n.low) != "number" || typeof (n == null ? void 0 : n.mid) != "number" ? "Required" : n.low >= n.mid ? "Days for red indicator should be less than yellow indicator." : !0;
548
+ };
549
+ }
550
+ return (e, n) => {
551
+ const v = R("FmTextField"), k = R("FmLabel"), T = R("FmField"), I = R("FmMenuHeader"), Y = R("FmMenuDivider"), G = R("FmMenuItem"), ie = R("FmMenu"), Ve = R("FmFormGroup"), Ze = R("FmSelect"), Re = R("FmSwitch"), et = R("FmIcon"), Ue = R("FmStepperField"), tt = R("FmForm");
552
+ return y(), B(tt, {
553
+ disabled: e.disabled,
554
+ ref_key: "formRef",
555
+ ref: a,
556
+ class: "grid grid-cols-2 gap-24",
557
+ onValidationSuccess: g
558
+ }, {
559
+ default: $(() => [
560
+ f(v, {
561
+ label: d(r)("inventory.ingredient.code"),
562
+ "model-value": h.value,
563
+ "onUpdate:modelValue": n[0] || (n[0] = (F) => h.value = F),
564
+ rules: [d(be)(), d(it)(A.value, E.value)],
565
+ "label-mark": "required"
566
+ }, null, 8, ["label", "model-value", "rules"]),
567
+ f(v, {
568
+ label: d(r)("inventory.ingredient.name"),
569
+ "model-value": u.value,
570
+ "onUpdate:modelValue": n[1] || (n[1] = (F) => u.value = F),
571
+ rules: [d(be)()],
572
+ "label-mark": "required"
573
+ }, null, 8, ["label", "model-value", "rules"]),
574
+ f(Ve, {
575
+ class: "col-span-2",
576
+ "model-value": D.value,
577
+ rules: [d(be)()],
578
+ "label-mark": "required"
579
+ }, {
580
+ label: $(() => [
581
+ f(k, {
582
+ label: d(r)("inventory.ingredient.unit")
583
+ }, null, 8, ["label"])
584
+ ]),
585
+ default: $(({ invalid: F }) => [
586
+ f(ie, null, {
587
+ "menu-button": $(() => [
588
+ f(T, {
589
+ class: X([
590
+ "fm-typo-en-body-lg-400",
591
+ {
592
+ "text-fm-color-typo-primary": !e.disabled,
593
+ "text-fm-color-typo-disabled": e.disabled
594
+ }
595
+ ]),
596
+ invalid: F,
597
+ "append-icon": "expand_more"
598
+ }, {
599
+ default: $(() => {
600
+ var q;
601
+ return [
602
+ He(L((q = D.value) == null ? void 0 : q.name), 1)
603
+ ];
604
+ }),
605
+ _: 2
606
+ }, 1032, ["class", "invalid"])
607
+ ]),
608
+ default: $(() => [
609
+ c("div", {
610
+ class: "overflow-x-hidden overflow-y-auto max-h-[300px]",
611
+ onVnodeMounted: ce
612
+ }, [
613
+ (y(!0), U(Q, null, oe(S.value, (q) => (y(), U(Q, {
614
+ key: q.label
615
+ }, [
616
+ q.displayAsSection ? (y(), U(Q, { key: 0 }, [
617
+ f(I, {
618
+ label: q.label
619
+ }, null, 8, ["label"]),
620
+ f(Y)
621
+ ], 64)) : (y(), B(G, {
622
+ key: 1,
623
+ label: q.label,
624
+ "model-value": w(q),
625
+ onClick: (Gn) => M(q.value),
626
+ "x-should-scroll-into": `${w(q)}`
627
+ }, null, 8, ["label", "model-value", "onClick", "x-should-scroll-into"]))
628
+ ], 64))), 128))
629
+ ], 512)
630
+ ]),
631
+ _: 2
632
+ }, 1024)
633
+ ]),
634
+ _: 1
635
+ }, 8, ["model-value", "rules"]),
636
+ d(b).enableTotalCost ? (y(), B(Ze, {
637
+ key: 0,
638
+ class: "col-span-1",
639
+ "model-value": Z.value,
640
+ "onUpdate:modelValue": n[2] || (n[2] = (F) => Z.value = F),
641
+ items: de.value
642
+ }, {
643
+ label: $(() => [
644
+ f(Me, { "z-index": 50 }, {
645
+ default: $(() => [
646
+ f(k, {
647
+ label: d(r)("inventory.ingredient.valuationMethod.title")
648
+ }, null, 8, ["label"])
649
+ ]),
650
+ _: 1
651
+ })
652
+ ]),
653
+ _: 1
654
+ }, 8, ["model-value", "items"])) : O("", !0),
655
+ d(b).enableTotalCost ? (y(), B(v, {
656
+ key: 1,
657
+ "model-value": x.value,
658
+ "onUpdate:modelValue": n[3] || (n[3] = (F) => x.value = F),
659
+ rules: [d(ke)(0), d(ut)(2)]
660
+ }, {
661
+ label: $(() => [
662
+ f(Me, { "z-index": 50 }, {
663
+ default: $(() => [
664
+ f(k, {
665
+ label: d(r)("inventory.ingredient.pricePerUnit")
666
+ }, null, 8, ["label"])
667
+ ]),
668
+ _: 1
669
+ })
670
+ ]),
671
+ prepend: $(() => {
672
+ var F, q;
673
+ return [
674
+ c("div", Rt, L(ne(((F = d(p).currentCountry) == null ? void 0 : F.value) ?? d(Ae)) === "MYR" ? "RM" : ne(((q = d(p).currentCountry) == null ? void 0 : q.value) ?? d(Ae))), 1)
675
+ ];
676
+ }),
677
+ append: $(() => [
678
+ c("div", Ut, " / " + L(me.value), 1)
679
+ ]),
680
+ _: 1
681
+ }, 8, ["model-value", "rules"])) : O("", !0),
682
+ c("div", Et, [
683
+ f(It, {
684
+ "model-value": ee.value,
685
+ "onUpdate:modelValue": n[4] || (n[4] = (F) => ee.value = F),
686
+ "root-value": e.modelValue
687
+ }, null, 8, ["model-value", "root-value"])
688
+ ]),
689
+ c("div", Dt, [
690
+ c("div", At, [
691
+ f(Re, {
692
+ label: d(r)("inventory.ingredient.operational.applyOperationalGroup"),
693
+ sublabel: d(r)("inventory.ingredient.operational.subtitle"),
694
+ modelValue: J.value,
695
+ "onUpdate:modelValue": n[5] || (n[5] = (F) => J.value = F),
696
+ "label-placement": "right"
697
+ }, null, 8, ["label", "sublabel", "modelValue"])
698
+ ]),
699
+ J.value ? (y(), U("div", Tt, [
700
+ f(ie, null, {
701
+ "menu-button": $(() => [
702
+ f(v, {
703
+ label: d(r)("inventory.ingredient.operational.operationalLabel"),
704
+ modelValue: V.value,
705
+ "onUpdate:modelValue": n[6] || (n[6] = (F) => V.value = F),
706
+ placeholder: d(r)("inventory.ingredient.operational.operationalLabelHint")
707
+ }, {
708
+ append: $(() => [
709
+ c("button", Pt, [
710
+ f(et, { name: "expand_more" })
711
+ ])
712
+ ]),
713
+ _: 1
714
+ }, 8, ["label", "modelValue", "placeholder"])
715
+ ]),
716
+ default: $(() => [
717
+ f(I, {
718
+ label: d(r)("inventory.ingredient.operational.preset")
719
+ }, null, 8, ["label"]),
720
+ (y(!0), U(Q, null, oe(Object.values(Ie), (F) => (y(), B(G, {
721
+ key: F,
722
+ label: F,
723
+ "model-value": V.value === F,
724
+ onClick: (q) => V.value = F
725
+ }, null, 8, ["label", "model-value", "onClick"]))), 128)),
726
+ H.value.length ? (y(), B(I, {
727
+ key: 0,
728
+ label: d(r)("inventory.ingredient.operational.custom")
729
+ }, null, 8, ["label"])) : O("", !0),
730
+ (y(!0), U(Q, null, oe(H.value, (F) => (y(), B(G, {
731
+ key: F,
732
+ label: F,
733
+ "model-value": V.value === F,
734
+ onClick: (q) => V.value = F
735
+ }, null, 8, ["label", "model-value", "onClick"]))), 128))
736
+ ]),
737
+ _: 1
738
+ }),
739
+ f(Ve, {
740
+ "model-value": V.value,
741
+ rules: [d(be)()]
742
+ }, null, 8, ["model-value", "rules"])
743
+ ])) : O("", !0)
744
+ ]),
745
+ e.mode !== d(K).CREATE ? (y(), U("div", Bt, [
746
+ c("div", null, [
747
+ f(Re, {
748
+ label: d(r)("inventory.ingredient.bindedItems.title"),
749
+ modelValue: N.value,
750
+ "onUpdate:modelValue": n[7] || (n[7] = (F) => N.value = F),
751
+ "label-placement": "right"
752
+ }, null, 8, ["label", "modelValue"])
753
+ ]),
754
+ N.value && W.value.length ? (y(), B(we, {
755
+ key: 0,
756
+ name: d(r)("inventory.ingredient.bindedItems.ingredient"),
757
+ bindings: W.value
758
+ }, null, 8, ["name", "bindings"])) : O("", !0),
759
+ N.value && se.value.length ? (y(), B(we, {
760
+ key: 1,
761
+ name: d(r)("inventory.ingredient.bindedItems.recipe"),
762
+ bindings: se.value
763
+ }, null, 8, ["name", "bindings"])) : O("", !0),
764
+ N.value && te.value.length ? (y(), B(we, {
765
+ key: 2,
766
+ name: d(r)("inventory.ingredient.bindedItems.menu"),
767
+ bindings: te.value
768
+ }, null, 8, ["name", "bindings"])) : O("", !0)
769
+ ])) : O("", !0),
770
+ c("div", zt, [
771
+ c("div", Lt, [
772
+ f(Me, null, {
773
+ default: $(() => [
774
+ c("div", Nt, L(d(r)("inventory.ingredient.threshold.title")), 1)
775
+ ]),
776
+ _: 1
777
+ }),
778
+ c("div", jt, L(d(r)("inventory.ingredient.threshold.subtitle")), 1)
779
+ ]),
780
+ c("div", Ht, [
781
+ f(Ve, {
782
+ "model-value": { low: P.value, mid: j.value },
783
+ rules: [ye()]
784
+ }, null, 8, ["model-value", "rules"]),
785
+ c("div", Ot, [
786
+ c("div", Yt, [
787
+ c("div", Gt, [
788
+ f(Fe, {
789
+ days: P.value,
790
+ level: d(Se).low
791
+ }, null, 8, ["days", "level"])
792
+ ]),
793
+ c("div", qt, [
794
+ c("div", Wt, L(d(r)("inventory.ingredient.threshold.whenRemaining")), 1),
795
+ f(Ue, {
796
+ modelValue: P.value,
797
+ "onUpdate:modelValue": n[8] || (n[8] = (F) => P.value = F),
798
+ rules: [d(ke)(0)]
799
+ }, {
800
+ append: $(() => [
801
+ Kt
802
+ ]),
803
+ _: 1
804
+ }, 8, ["modelValue", "rules"])
805
+ ])
806
+ ]),
807
+ Jt,
808
+ c("div", Qt, [
809
+ c("div", Xt, [
810
+ f(Fe, {
811
+ days: j.value,
812
+ level: d(Se).mid
813
+ }, null, 8, ["days", "level"])
814
+ ]),
815
+ c("div", Zt, [
816
+ c("div", en, L(d(r)("inventory.ingredient.threshold.whenRemaining")), 1),
817
+ f(Ue, {
818
+ modelValue: j.value,
819
+ "onUpdate:modelValue": n[9] || (n[9] = (F) => j.value = F),
820
+ rules: [d(ke)(0)]
821
+ }, {
822
+ append: $(() => [
823
+ tn
824
+ ]),
825
+ _: 1
826
+ }, 8, ["modelValue", "rules"])
827
+ ])
828
+ ]),
829
+ nn,
830
+ c("div", on, [
831
+ c("div", ln, [
832
+ f(Fe, {
833
+ days: j.value + 1,
834
+ level: d(Se).high
835
+ }, null, 8, ["days", "level"])
836
+ ]),
837
+ c("div", an, [
838
+ c("div", rn, L(d(r)("inventory.ingredient.threshold.stockIsStaple")), 1)
839
+ ])
840
+ ])
841
+ ])
842
+ ])
843
+ ])
844
+ ]),
845
+ _: 1
846
+ }, 8, ["disabled"]);
847
+ };
848
+ }
849
+ }), un = { class: "flex gap-4" }, dn = /* @__PURE__ */ le({
850
+ __name: "IngredientDialog",
851
+ props: {
852
+ show: { type: Boolean },
853
+ unit: {},
854
+ mode: { default: K.READ }
855
+ },
856
+ emits: ["update:show"],
857
+ setup(s) {
858
+ const i = s, m = ae(), r = xe(), { t } = re(), l = Pe(i, "show"), o = Pe(i, "unit"), p = C(() => {
859
+ switch (i.mode) {
860
+ case K.READ:
861
+ return "";
862
+ case K.UPDATE:
863
+ return t("inventory.ingredient.update.title");
864
+ case K.CREATE:
865
+ return t("inventory.ingredient.create.title");
866
+ }
867
+ return "";
868
+ }), b = C(() => {
869
+ switch (i.mode) {
870
+ case K.READ:
871
+ return "";
872
+ case K.UPDATE:
873
+ return t("common.save");
874
+ case K.CREATE:
875
+ return t("common.add");
876
+ }
877
+ return "";
878
+ }), _ = z(), g = z(!1);
879
+ async function h() {
880
+ g.value = !0;
881
+ try {
882
+ await m.createSku(o.value), l.value = !1, r.open({
883
+ title: t("common.success"),
884
+ message: t("inventory.ingredient.create.success", { name: o.value.name }),
885
+ type: "success"
886
+ });
887
+ } catch (S) {
888
+ S instanceof Te || r.open({
889
+ title: t("inventory.ingredient.create.error.title"),
890
+ message: t("inventory.ingredient.create.error.message"),
891
+ type: "error"
892
+ });
893
+ } finally {
894
+ g.value = !1;
895
+ }
896
+ }
897
+ async function u() {
898
+ g.value = !0;
899
+ try {
900
+ await m.updateSku(o.value), g.value = !1, l.value = !1, r.open({
901
+ title: t("common.success"),
902
+ message: t("inventory.ingredient.update.success", { name: o.value.name }),
903
+ type: "success"
904
+ });
905
+ } catch (S) {
906
+ S instanceof Te || r.open({
907
+ title: t("inventory.ingredient.update.error.title"),
908
+ message: t("inventory.ingredient.update.error.message"),
909
+ type: "error"
910
+ });
911
+ } finally {
912
+ g.value = !1;
913
+ }
914
+ }
915
+ function x() {
916
+ var S, w;
917
+ (w = (S = _.value) == null ? void 0 : S.validateInputs) == null || w.call(S);
918
+ }
919
+ function D() {
920
+ switch (i.mode) {
921
+ case K.READ:
922
+ return;
923
+ case K.UPDATE:
924
+ return u();
925
+ case K.CREATE:
926
+ return h();
927
+ }
928
+ }
929
+ return (S, w) => {
930
+ const M = R("FmButton"), V = R("FmSideSheet");
931
+ return y(), B(V, {
932
+ "model-value": d(l),
933
+ "onUpdate:modelValue": w[3] || (w[3] = (H) => Ee(l) ? l.value = H : null),
934
+ header: p.value,
935
+ "close-button": "",
936
+ "dismiss-away": "",
937
+ "max-width": 500
938
+ }, {
939
+ "side-sheet-footer": $(() => [
940
+ c("div", un, [
941
+ f(M, {
942
+ loading: g.value,
943
+ label: b.value,
944
+ onClick: x
945
+ }, null, 8, ["loading", "label"]),
946
+ f(M, {
947
+ disabled: g.value,
948
+ label: d(t)("common.close"),
949
+ variant: "tertiary",
950
+ onClick: w[2] || (w[2] = (H) => l.value = !1)
951
+ }, null, 8, ["disabled", "label"])
952
+ ])
953
+ ]),
954
+ default: $(() => [
955
+ f(sn, {
956
+ class: "w-full",
957
+ ref_key: "hasValidationExpose",
958
+ ref: _,
959
+ modelValue: d(o),
960
+ "onUpdate:modelValue": w[0] || (w[0] = (H) => Ee(o) ? o.value = H : null),
961
+ mode: S.mode,
962
+ disabled: g.value,
963
+ "onClick:submit": w[1] || (w[1] = (H) => D())
964
+ }, null, 8, ["modelValue", "mode", "disabled"])
965
+ ]),
966
+ _: 1
967
+ }, 8, ["model-value", "header"]);
968
+ };
969
+ }
970
+ });
971
+ function* cn(s) {
972
+ for (; ; )
973
+ yield s[Math.floor(Math.random() * s.length)];
974
+ }
975
+ function mn(s = 4, i = cn("qwertyuiopasdfghjklzxcvbnm".split(""))) {
976
+ return Array.from({ length: s }).map(() => i.next().value).join("");
977
+ }
978
+ function pn() {
979
+ return `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${mn()}`;
980
+ }
981
+ const vn = {
982
+ _id: "",
983
+ name: "",
984
+ abbrev: "",
985
+ precision: 0,
986
+ measurements: []
987
+ };
988
+ function fn(s) {
989
+ var m, r, t, l, o;
990
+ return {
991
+ code: s.code,
992
+ name: s.name,
993
+ unit: ((m = s.unit.measurements.find((p) => p.id === s.trackingMeasurement)) == null ? void 0 : m.abbrev) ?? s.unit.abbrev,
994
+ baseUnit: s.unit.abbrev,
995
+ valuationMethod: s.valuation ?? "WAVG",
996
+ pricePerUnit: (r = s.defaultCost) != null && r.costPerUnit ? +Ge((t = s.defaultCost) == null ? void 0 : t.costPerUnit) : 0,
997
+ thresholdLow: ((l = s.thresholds) == null ? void 0 : l.low) ?? ue().low,
998
+ thresholdMid: ((o = s.thresholds) == null ? void 0 : o.mid) ?? ue().mid
999
+ };
1000
+ }
1001
+ function Xe() {
1002
+ var t;
1003
+ const s = [
1004
+ {
1005
+ id: "code",
1006
+ name: "Code"
1007
+ },
1008
+ {
1009
+ id: "name",
1010
+ name: "Name"
1011
+ },
1012
+ {
1013
+ id: "unit",
1014
+ name: "Unit"
1015
+ },
1016
+ {
1017
+ id: "baseUnit",
1018
+ name: "Base unit"
1019
+ }
1020
+ ], i = We(), m = fe(), r = _e(m.currentCountry.value);
1021
+ return i.enableTotalCost && s.push(
1022
+ {
1023
+ id: "valuationMethod",
1024
+ name: "Valuation method"
1025
+ },
1026
+ {
1027
+ id: "pricePerUnit",
1028
+ name: `Price per unit (${r == null ? void 0 : r.currency})`
1029
+ }
1030
+ ), ((t = m.currentBusiness.value) == null ? void 0 : t.menuVersion) === "v4" && s.push(
1031
+ {
1032
+ id: "thresholdLow",
1033
+ name: "Show RED when remaining"
1034
+ },
1035
+ {
1036
+ id: "thresholdMid",
1037
+ name: "Show YELLOW when remaining"
1038
+ }
1039
+ ), s;
1040
+ }
1041
+ function yn() {
1042
+ const i = ae().skus.map(fn), r = fe().currentBusiness.value, t = Xe(), l = [
1043
+ ["Business name:", r == null ? void 0 : r.name],
1044
+ ["Business ID:", r == null ? void 0 : r._id],
1045
+ ["Menu version", r == null ? void 0 : r.menuVersion],
1046
+ [],
1047
+ t.map((_) => _.name),
1048
+ ...i.map((_) => t.map((g) => _[g.id]))
1049
+ ], o = t.map((_) => `system:${_.id}`), p = Je(l, o), b = `${r == null ? void 0 : r.name} ingredients (${dt(/* @__PURE__ */ new Date())}).xlsx`;
1050
+ return Qe(p, b), b;
1051
+ }
1052
+ function gn() {
1053
+ const i = fe().currentBusiness.value, m = Xe(), r = [
1054
+ ["Business name:", i == null ? void 0 : i.name],
1055
+ ["Business ID:", i == null ? void 0 : i._id],
1056
+ ["Menu version", i == null ? void 0 : i.menuVersion],
1057
+ [],
1058
+ m.map((p) => p.name)
1059
+ ], t = m.map((p) => `system:${p.id}`), l = Je(r, t), o = "FeedMe ingredients template.xlsx";
1060
+ return Qe(l, o), o;
1061
+ }
1062
+ function bn(s) {
1063
+ const [
1064
+ i,
1065
+ m,
1066
+ r,
1067
+ t,
1068
+ l,
1069
+ o,
1070
+ ...p
1071
+ ] = wt(s);
1072
+ if (!i || !i.length || i.some((u) => u.length && !u.startsWith("system:")))
1073
+ throw new Error("Missing meta header. Excel file does not come from the template.");
1074
+ const b = i.map((u) => u.split(":")[1]), g = ["code", "name", "unit", "baseUnit"].filter((u) => !b.includes(u));
1075
+ if (g.length)
1076
+ throw new Error(
1077
+ `Missing meta headers (${g.join()}). Excel file does not come from the template.`
1078
+ );
1079
+ return p.map((u, x) => {
1080
+ const D = {};
1081
+ for (const S in b) {
1082
+ const w = b[S];
1083
+ Object.assign(D, { [w]: u[S] });
1084
+ }
1085
+ return {
1086
+ index: x,
1087
+ data: D
1088
+ };
1089
+ });
1090
+ }
1091
+ function Le(s, i, m) {
1092
+ var M;
1093
+ const t = ae().units, l = new Array(), o = m.filter((V) => V.data.code === s.code);
1094
+ o.length > 1 && l.push(
1095
+ `Code ${s.code} is already used in row ${o.map((V) => V.index + 6).join()}.`
1096
+ );
1097
+ const p = t.find((V) => V.abbrev === s.baseUnit), b = p == null ? void 0 : p.measurements.find((V) => V.abbrev === s.unit);
1098
+ if (!p)
1099
+ l.push(`Cannot find base unit of symbol ${s.baseUnit}.`);
1100
+ else if (s.baseUnit !== s.unit && !b) {
1101
+ const V = `Cannot find unit conversion for ${s.baseUnit} with symbol ${s.unit || "[empty]"}.`;
1102
+ l.push(V);
1103
+ }
1104
+ const _ = ve.options.find(
1105
+ (V) => V === s.valuationMethod
1106
+ );
1107
+ s.valuationMethod && !_ && l.push(
1108
+ `Expected valuation method to be one of ${ve.options.join()} but got ${s.valuationMethod} instead.`
1109
+ );
1110
+ const h = fe().currentCountry.value, u = (V) => `${V}`.length && mt()(V) === !0, x = u(`${s.pricePerUnit}`) === !0 ? {
1111
+ costPerUnit: {
1112
+ ...qe(Number(s.pricePerUnit) || 0),
1113
+ currency: ((M = _e(h)) == null ? void 0 : M.currency) ?? "MYR"
1114
+ },
1115
+ measurement: b
1116
+ } : void 0, D = u(`${s.thresholdLow}`) && u(`${s.thresholdMid}`) ? {
1117
+ low: Number(s.thresholdLow) || 0,
1118
+ mid: Number(s.thresholdMid) || 0
1119
+ } : void 0;
1120
+ return {
1121
+ type: "create",
1122
+ sku: {
1123
+ _id: pn(),
1124
+ code: s.code,
1125
+ name: s.name,
1126
+ unit: p ?? t.find((V) => V) ?? vn,
1127
+ trackingMeasurement: b == null ? void 0 : b.id,
1128
+ valuation: _,
1129
+ defaultCost: x,
1130
+ thresholds: D
1131
+ },
1132
+ errors: l,
1133
+ excelRowNumber: i + 6
1134
+ };
1135
+ }
1136
+ function hn(s) {
1137
+ try {
1138
+ const i = bn(s).filter((_) => _.data.code), r = ae().skus, t = ct(r, "code"), l = i.filter((_) => !t[_.data.code]), o = i.filter((_) => t[_.data.code]), p = l.map(
1139
+ (_) => Le(_.data, _.index, i)
1140
+ ), b = o.map((_) => {
1141
+ const g = Le(_.data, _.index, i), h = t[_.data.code];
1142
+ return {
1143
+ ...g,
1144
+ type: "update",
1145
+ original: h,
1146
+ sku: {
1147
+ // to maintain original props not in the import excel, e.g. inventory binding, etc...
1148
+ ...h,
1149
+ code: g.sku.code || h.code,
1150
+ name: g.sku.name || h.name,
1151
+ unit: g.sku.unit || h.unit,
1152
+ trackingMeasurement: g.sku.trackingMeasurement || h.trackingMeasurement,
1153
+ valuation: g.sku.valuation || h.valuation,
1154
+ defaultCost: g.sku.defaultCost || h.defaultCost,
1155
+ thresholds: g.sku.thresholds || h.thresholds
1156
+ }
1157
+ };
1158
+ });
1159
+ return {
1160
+ invalidExcel: !1,
1161
+ importCreateResult: p,
1162
+ importUpdateResult: b
1163
+ };
1164
+ } catch (i) {
1165
+ return {
1166
+ invalidExcel: !0,
1167
+ invalidExcelMessage: (i == null ? void 0 : i.message) ?? "Invalid excel",
1168
+ importCreateResult: [],
1169
+ importUpdateResult: []
1170
+ };
1171
+ }
1172
+ }
1173
+ const _n = {
1174
+ key: 0,
1175
+ class: "relative"
1176
+ }, xn = ["accept", "disabled"], Vn = { class: "flex flex-col gap-8" }, kn = ["accept", "disabled"], Cn = /* @__PURE__ */ le({
1177
+ __name: "FmDroppableField",
1178
+ props: {
1179
+ buttonLabel: {},
1180
+ label: { default: "" },
1181
+ disabled: { type: Boolean, default: !1 },
1182
+ accept: { default: "" },
1183
+ maxFileSize: { default: 8e6 },
1184
+ contentClass: {}
1185
+ },
1186
+ emits: ["file-upload", "file-rejected"],
1187
+ setup(s, { emit: i }) {
1188
+ const m = s, r = i, t = z(!1), l = z(null), o = z(null), p = z(), b = (a) => {
1189
+ m.disabled || (a.stopPropagation(), a.preventDefault());
1190
+ }, _ = (a) => {
1191
+ m.disabled || (a.stopPropagation(), a.preventDefault(), t.value = !0);
1192
+ }, g = (a) => {
1193
+ m.disabled || (a.stopPropagation(), a.preventDefault(), t.value = !1);
1194
+ }, h = (a) => {
1195
+ var N;
1196
+ m.disabled || (a.stopPropagation(), a.preventDefault(), t.value = !1, u((N = a.dataTransfer) == null ? void 0 : N.files));
1197
+ };
1198
+ function u(a) {
1199
+ if (a)
1200
+ if (p.value = a, l.value = D(a[0]), o.value = S(a[0]), l.value && o.value)
1201
+ r("file-upload", a[0]);
1202
+ else {
1203
+ const N = x();
1204
+ r("file-rejected", [
1205
+ {
1206
+ file: a[0],
1207
+ reason: N
1208
+ }
1209
+ ]);
1210
+ }
1211
+ }
1212
+ const x = () => {
1213
+ const a = new Array();
1214
+ return l.value || a.push("invalid-type"), o.value || a.push("invalid-size"), a;
1215
+ }, D = (a) => {
1216
+ if (!m.accept) return !0;
1217
+ const N = m.accept.split(",").map((W) => W.trim());
1218
+ for (const W of N)
1219
+ if (w(W)) {
1220
+ if (V(W) === V(a.type)) return !0;
1221
+ } else if (M(a) === W || a.type === W) return !0;
1222
+ return !1;
1223
+ }, S = (a) => a.size <= m.maxFileSize, w = (a) => a.indexOf("*") !== -1, M = (a) => "." + a.name.split(".").pop(), V = (a) => a.substring(0, a.indexOf("/")), H = C(() => {
1224
+ if (t.value) return "Drop file to upload";
1225
+ if (l.value) {
1226
+ if (!o.value) return `File size exceeds ${m.maxFileSize * 1e-6}mb`;
1227
+ } else return "File type is not valid";
1228
+ return "";
1229
+ }), J = C(() => p.value ? !l.value || !o.value : !1), ee = (a) => {
1230
+ const N = a.target;
1231
+ u(N.files);
1232
+ }, de = C(() => {
1233
+ var a;
1234
+ return (a = p.value) == null ? void 0 : a.item(0);
1235
+ }), Z = z();
1236
+ return (a, N) => {
1237
+ const W = R("FmLabel"), se = R("FmButton");
1238
+ return y(), U("label", {
1239
+ class: "fm-droppable-field",
1240
+ ref_key: "fmButtonRef",
1241
+ ref: Z
1242
+ }, [
1243
+ a.$slots.default ? (y(), U("div", _n, [
1244
+ c("input", {
1245
+ accept: a.accept,
1246
+ disabled: a.disabled,
1247
+ class: "fm-droppable-field__input",
1248
+ type: "file",
1249
+ onChange: ee
1250
+ }, null, 40, xn)
1251
+ ])) : O("", !0),
1252
+ ge(a.$slots, "default", {
1253
+ isDragging: t.value,
1254
+ isValidFileType: l.value,
1255
+ isValidFileSize: o.value,
1256
+ singleValidFile: de.value,
1257
+ openFileDialog: () => {
1258
+ var te;
1259
+ return console.log("click", Z.value), (te = Z.value) == null ? void 0 : te.click();
1260
+ }
1261
+ }, () => [
1262
+ c("div", Vn, [
1263
+ a.$slots.label ? ge(a.$slots, "label", { key: 0 }, void 0, !0) : (y(), B(W, {
1264
+ key: 1,
1265
+ label: a.label
1266
+ }, null, 8, ["label"]))
1267
+ ]),
1268
+ c("div", {
1269
+ class: X([[
1270
+ a.contentClass ? a.contentClass : "w-full h-full",
1271
+ {
1272
+ "fm-droppable-field__container--dragging": t.value,
1273
+ "fm-droppable-field__container--invalid": J.value && !a.disabled,
1274
+ "fm-droppable-field__container--disabled": a.disabled
1275
+ }
1276
+ ], "fm-droppable-field__container"]),
1277
+ onDragenter: b,
1278
+ onDragleave: g,
1279
+ onDragover: _,
1280
+ onDrop: h
1281
+ }, [
1282
+ (t.value || J.value) && !a.disabled ? (y(), U("div", {
1283
+ key: 0,
1284
+ class: X({
1285
+ "fm-typo-en-body-lg-600": !0,
1286
+ "text-fm-color-primary": t.value,
1287
+ "text-fm-color-typo-error": J.value
1288
+ })
1289
+ }, L(H.value), 3)) : (y(), B(se, {
1290
+ key: 1,
1291
+ disabled: a.disabled,
1292
+ label: a.buttonLabel ?? "Add files",
1293
+ size: "md",
1294
+ variant: "secondary"
1295
+ }, null, 8, ["disabled", "label"])),
1296
+ ge(a.$slots, "accept-text", {}, () => [
1297
+ m.accept ? (y(), U("div", {
1298
+ key: 0,
1299
+ class: X([[a.disabled ? "text-fm-color-typo-disabled" : "text-fm-color-typo-secondary"], "fm-typo-en-body-md-400"])
1300
+ }, L(`Accepts ${m.accept}`), 3)) : O("", !0)
1301
+ ], !0),
1302
+ c("input", {
1303
+ accept: a.accept,
1304
+ disabled: a.disabled,
1305
+ class: "fm-droppable-field__input",
1306
+ type: "file",
1307
+ onChange: ee
1308
+ }, null, 40, kn)
1309
+ ], 34),
1310
+ ge(a.$slots, "helper-text", {}, () => [
1311
+ c("div", {
1312
+ class: X([[a.disabled ? "text-fm-color-typo-disabled" : "text-fm-color-typo-secondary"], "fm-typo-en-body-sm-400"])
1313
+ }, L(`Max size ${m.maxFileSize * 1e-6}mb`), 3)
1314
+ ], !0)
1315
+ ], !0)
1316
+ ], 512);
1317
+ };
1318
+ }
1319
+ }), Fn = /* @__PURE__ */ pt(Cn, [["__scopeId", "data-v-311b22a0"]]), Sn = { class: "flex items-center gap-12 pl-8" }, wn = /* @__PURE__ */ c("div", null, "•", -1), Mn = { class: "flex flex-col" }, $n = { class: "fm-typo-en-body-md-400 text-fm-color-typo-primary flex items-center gap-4" }, In = {
1320
+ key: 0,
1321
+ class: "text-fm-color-typo-secondary fm-typo-en-body-sm-400"
1322
+ }, Rn = { key: 0 }, Ne = /* @__PURE__ */ le({
1323
+ __name: "ImportIngredientItem",
1324
+ props: {
1325
+ type: {},
1326
+ code: {},
1327
+ name: {},
1328
+ errors: {}
1329
+ },
1330
+ setup(s) {
1331
+ return (i, m) => {
1332
+ const r = R("FmIcon"), t = R("FmTooltip");
1333
+ return y(), U("div", Sn, [
1334
+ wn,
1335
+ c("div", Mn, [
1336
+ c("div", $n, [
1337
+ c("div", {
1338
+ class: X({
1339
+ "text-fm-color-system-error-300": i.errors.length
1340
+ })
1341
+ }, [
1342
+ He(L(i.name) + " ", 1),
1343
+ i.type === "create" ? (y(), U("span", In, "(new)")) : O("", !0)
1344
+ ], 2),
1345
+ i.errors.length ? (y(), U("div", Rn, [
1346
+ f(t, { "z-index": 50 }, {
1347
+ content: $(() => [
1348
+ c("ol", null, [
1349
+ (y(!0), U(Q, null, oe(i.errors, (l, o) => (y(), U("li", { key: o }, L(l), 1))), 128))
1350
+ ])
1351
+ ]),
1352
+ default: $(() => [
1353
+ f(r, {
1354
+ name: "error",
1355
+ size: "sm",
1356
+ color: "system-error-300"
1357
+ })
1358
+ ]),
1359
+ _: 1
1360
+ })
1361
+ ])) : O("", !0)
1362
+ ]),
1363
+ c("div", {
1364
+ class: X([
1365
+ "fm-typo-en-body-sm-400",
1366
+ {
1367
+ "text-fm-color-system-error-200": i.errors.length,
1368
+ "text-fm-color-typo-secondary": !i.errors.length
1369
+ }
1370
+ ])
1371
+ }, L(i.code), 3)
1372
+ ])
1373
+ ]);
1374
+ };
1375
+ }
1376
+ }), Un = { class: "flex flex-col gap-24" }, En = { class: "fm-typo-en-body-md-400" }, Dn = { class: "flex flex-col gap-8" }, An = { class: "line-clamp-2 text-ellipsis break-all" }, Tn = {
1377
+ key: 2,
1378
+ class: "shrink-0"
1379
+ }, Pn = {
1380
+ key: 0,
1381
+ class: "flex flex-col"
1382
+ }, Bn = { class: "text-fm-color-system-error-300 fm-typo-en-body-sm-400" }, zn = {
1383
+ key: 0,
1384
+ class: "max-h-[200px] overflow-y-auto flex flex-col gap-8"
1385
+ }, Ln = { class: "fm-typo-en-body-lg-600" }, Nn = /* @__PURE__ */ le({
1386
+ __name: "ImportIngredients",
1387
+ setup(s) {
1388
+ const i = z(null), m = ft(), r = xe(), t = z(!1), l = z(new Array()), o = z([]), p = z([]), b = C(
1389
+ () => !!l.value.length || o.value.some((u) => u.errors.length) || p.value.some((u) => u.errors.length)
1390
+ ), _ = C(
1391
+ () => !!o.value.length || !!p.value.length
1392
+ ), { t: g } = re();
1393
+ async function h(u) {
1394
+ l.value = [], o.value = [], p.value = [];
1395
+ try {
1396
+ t.value = !0;
1397
+ const [x] = await Promise.all([
1398
+ Mt(u),
1399
+ // fake buffer
1400
+ new Promise((w) => setTimeout(w, 1e3))
1401
+ ]), D = x.SheetNames.find((w) => w);
1402
+ if (!D) {
1403
+ l.value.push(g("inventory.ingredient.import.fileError.noSheet"));
1404
+ return;
1405
+ }
1406
+ const S = hn(x.Sheets[D]);
1407
+ if (S.invalidExcel) {
1408
+ l.value.push(S.invalidExcelMessage ?? g("inventory.ingredient.import.fileError.invalidExcel"));
1409
+ return;
1410
+ }
1411
+ if (o.value = S.importCreateResult, p.value = S.importUpdateResult, !o.value.length && !p.value.length) {
1412
+ l.value.push(g("inventory.ingredient.import.fileError.noData"));
1413
+ return;
1414
+ }
1415
+ m.emitData(S);
1416
+ } catch (x) {
1417
+ r.open({
1418
+ title: g("inventory.ingredient.import.fileError.unableToRead"),
1419
+ message: x == null ? void 0 : x.message,
1420
+ type: "error"
1421
+ }), console.error("Error in reading file", x);
1422
+ } finally {
1423
+ l.value.length && r.open({
1424
+ title: g("inventory.ingredient.import.fileError.invalidExcel"),
1425
+ type: "error"
1426
+ }), t.value = !1;
1427
+ }
1428
+ }
1429
+ return je(i, (u) => {
1430
+ u && h(u);
1431
+ }), (u, x) => {
1432
+ const D = R("FmCircularProgress"), S = R("FmIcon"), w = R("FmButton");
1433
+ return y(), U("div", Un, [
1434
+ c("div", En, L(d(g)("inventory.ingredient.import.uploadDescription")), 1),
1435
+ f(Fn, {
1436
+ class: X({
1437
+ "w-full": !0,
1438
+ "h-[200px]": !i.value
1439
+ }),
1440
+ accept: ".xlsx",
1441
+ onFileUpload: x[0] || (x[0] = (M) => i.value = M),
1442
+ label: d(g)("inventory.ingredient.import.uploadTemplate"),
1443
+ "button-label": d(g)("inventory.ingredient.import.selectFile")
1444
+ }, Oe({ _: 2 }, [
1445
+ i.value ? {
1446
+ name: "default",
1447
+ fn: $(({ openFileDialog: M }) => [
1448
+ c("div", Dn, [
1449
+ c("div", {
1450
+ class: X([
1451
+ "fm-corner-radius-md p-16 flex items-center gap-16",
1452
+ {
1453
+ "border border-fm-color-neutral-gray-100": t.value,
1454
+ "border border-fm-color-neutral-gray-200": !t.value && !b.value,
1455
+ "border border-fm-color-system-error-200": b.value
1456
+ }
1457
+ ])
1458
+ }, [
1459
+ t.value ? (y(), B(D, {
1460
+ key: 0,
1461
+ size: "md",
1462
+ color: "neutral-gray-200"
1463
+ })) : (y(), B(S, {
1464
+ key: 1,
1465
+ name: b.value ? "error" : "attach_file",
1466
+ outline: "",
1467
+ color: b.value ? "system-error-300" : void 0
1468
+ }, null, 8, ["name", "color"])),
1469
+ c("div", {
1470
+ class: X([
1471
+ "fm-typo-en-body-md-400 flex-1 h-[36px] flex items-center",
1472
+ {
1473
+ "text-fm-color-typo-disabled": t.value,
1474
+ "text-fm-color-typo-primary": !t.value
1475
+ }
1476
+ ])
1477
+ }, [
1478
+ c("div", An, L(i.value.name), 1)
1479
+ ], 2),
1480
+ t.value ? O("", !0) : (y(), U("div", Tn, [
1481
+ f(w, {
1482
+ label: d(g)("inventory.ingredient.import.replaceFile"),
1483
+ variant: b.value ? "destructive" : "secondary",
1484
+ "prepend-icon": b.value ? void 0 : "autorenew",
1485
+ onClick: M
1486
+ }, null, 8, ["label", "variant", "prepend-icon", "onClick"])
1487
+ ]))
1488
+ ], 2),
1489
+ l.value.length ? (y(), U("div", Pn, [
1490
+ (y(!0), U(Q, null, oe(l.value, (V, H) => (y(), U("div", {
1491
+ key: H,
1492
+ class: "flex gap-8 items-center"
1493
+ }, [
1494
+ f(S, {
1495
+ name: "error",
1496
+ size: "sm",
1497
+ color: "system-error-300"
1498
+ }),
1499
+ c("div", Bn, L(V), 1)
1500
+ ]))), 128))
1501
+ ])) : O("", !0)
1502
+ ])
1503
+ ]),
1504
+ key: "0"
1505
+ } : void 0
1506
+ ]), 1032, ["class", "label", "button-label"]),
1507
+ _.value ? (y(), U("div", zn, [
1508
+ c("div", Ln, L(d(g)("inventory.ingredient.import.summary")), 1),
1509
+ (y(!0), U(Q, null, oe(o.value, (M) => (y(), B(Ne, {
1510
+ key: M.sku._id,
1511
+ code: M.sku.code,
1512
+ name: M.sku.name,
1513
+ errors: M.errors,
1514
+ type: "create"
1515
+ }, null, 8, ["code", "name", "errors"]))), 128)),
1516
+ (y(!0), U(Q, null, oe(p.value, (M) => (y(), B(Ne, {
1517
+ key: M.sku._id,
1518
+ code: M.sku.code,
1519
+ name: M.sku.name,
1520
+ errors: M.errors,
1521
+ type: "update"
1522
+ }, null, 8, ["code", "name", "errors"]))), 128))
1523
+ ])) : O("", !0)
1524
+ ]);
1525
+ };
1526
+ }
1527
+ }), jn = { class: "px-24 xs:p-0 sm:p-0 flex flex-col gap-8 max-h-full" }, Hn = { class: "flex flex-col py-8" }, On = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Yn = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, ro = /* @__PURE__ */ le({
1528
+ __name: "IngredientsView",
1529
+ setup(s) {
1530
+ const i = ae(), m = C(() => i.skus), r = vt(), t = Ke(), l = xe(), { t: o } = re(), { createIngredient: p, updateIngredient: b } = $e(), { ingredientDialogProps: _, ingredientViewLoading: g } = _t($e()), { columnDefs: h } = $t();
1531
+ function u(A) {
1532
+ switch (A) {
1533
+ case "add":
1534
+ return p();
1535
+ case "import":
1536
+ return W();
1537
+ }
1538
+ }
1539
+ const x = z(""), D = z(!1), S = C(() => D.value || g), { breakpoints: w } = yt(), M = C(() => w.value.xs || w.value.sm), V = C(() => M.value ? 10 : 20), H = kt(), J = z(!1), ee = [
1540
+ {
1541
+ value: "import",
1542
+ label: o("common.import")
1543
+ },
1544
+ {
1545
+ value: "export",
1546
+ label: o("common.export")
1547
+ }
1548
+ ];
1549
+ function de(A) {
1550
+ switch (J.value = !1, A) {
1551
+ case "import":
1552
+ return W();
1553
+ case "export":
1554
+ return N();
1555
+ }
1556
+ }
1557
+ const Z = C(() => M.value ? [{ icon: "more_vert", onClick: te }] : [{ icon: "ios_share", onClick: N }]), a = C(() => {
1558
+ const A = [
1559
+ {
1560
+ label: o("inventory.ingredient.create.title"),
1561
+ value: "add",
1562
+ isPrimary: !0,
1563
+ prependIcon: "add"
1564
+ }
1565
+ ];
1566
+ return M.value ? A : [...A, { label: o("inventory.ingredient.import.title"), value: "import" }];
1567
+ });
1568
+ function N() {
1569
+ const A = yn();
1570
+ l.open({
1571
+ title: o("inventory.ingredient.export.success"),
1572
+ message: o("inventory.ingredient.export.filename", [A]),
1573
+ type: "success"
1574
+ });
1575
+ }
1576
+ function W() {
1577
+ t.open({
1578
+ title: o("inventory.ingredient.import.title"),
1579
+ contentComponent: Nn,
1580
+ overlay: !0,
1581
+ closeButton: !0,
1582
+ primaryActions: {
1583
+ text: o("common.import"),
1584
+ close: !1
1585
+ },
1586
+ secondaryActions: {
1587
+ text: o("common.close"),
1588
+ close: !0
1589
+ },
1590
+ tertiaryActions: {
1591
+ text: o("inventory.ingredient.import.actions.downloadTemplate"),
1592
+ close: !1,
1593
+ variant: "plain"
1594
+ }
1595
+ }).onPrimary((A) => {
1596
+ if (!A) {
1597
+ l.open({
1598
+ title: o("inventory.ingredient.import.error.noData"),
1599
+ type: "error"
1600
+ });
1601
+ return;
1602
+ }
1603
+ if (!A.importCreateResult.length && !A.importUpdateResult.length) {
1604
+ l.open({
1605
+ title: o("inventory.ingredient.import.error.invalidContent"),
1606
+ message: o("inventory.ingredient.import.error.noImportData"),
1607
+ type: "error"
1608
+ });
1609
+ return;
1610
+ }
1611
+ if (A.importCreateResult.some((E) => E.errors.length) || A.importUpdateResult.some((E) => E.errors.length)) {
1612
+ l.open({
1613
+ title: o("inventory.ingredient.import.error.invalidContent"),
1614
+ message: o("inventory.ingredient.import.error.hasErrors"),
1615
+ type: "error"
1616
+ });
1617
+ return;
1618
+ }
1619
+ t.close(), se(A);
1620
+ }).onTertiary(gn);
1621
+ }
1622
+ async function se(A) {
1623
+ D.value = !0;
1624
+ try {
1625
+ const E = [
1626
+ ...A.importCreateResult.map(({ sku: P }) => ({ type: "create", sku: P })),
1627
+ ...A.importUpdateResult.map(({ sku: P }) => ({ type: "update", sku: P }))
1628
+ ], ce = 100;
1629
+ let ne = 0;
1630
+ const me = () => {
1631
+ ne += ce, l.open({
1632
+ title: o("inventory.ingredient.import.progress", [
1633
+ Math.min(ne, E.length),
1634
+ E.length
1635
+ ])
1636
+ });
1637
+ };
1638
+ for (const P of E.chunk(100))
1639
+ me(), await i.importSkus({
1640
+ create: P.filter((j) => j.type === "create").map((j) => j.sku),
1641
+ update: P.filter((j) => j.type === "update").map((j) => j.sku)
1642
+ });
1643
+ l.open({
1644
+ title: o("inventory.ingredient.import.success"),
1645
+ type: "success"
1646
+ });
1647
+ } catch (E) {
1648
+ l.open({
1649
+ title: o("inventory.ingredient.import.error.failed"),
1650
+ message: o("inventory.ingredient.import.error.systemMessage", [E == null ? void 0 : E.message]),
1651
+ type: "error"
1652
+ }), console.error("Error in importing skus", A, E);
1653
+ } finally {
1654
+ D.value = !1;
1655
+ }
1656
+ }
1657
+ function te() {
1658
+ J.value = !0;
1659
+ }
1660
+ return (A, E) => {
1661
+ const ce = R("FmTable"), ne = R("FmCollapsibleTabs"), me = R("FmBottomSheet");
1662
+ return y(), B(Ct, {
1663
+ title: d(o)("inventory.ingredient.title"),
1664
+ actions: a.value,
1665
+ "onClick:action": u
1666
+ }, {
1667
+ default: $(() => [
1668
+ c("div", jn, [
1669
+ f(Ft, {
1670
+ searchable: "",
1671
+ search: x.value,
1672
+ "onUpdate:search": E[0] || (E[0] = (P) => x.value = P),
1673
+ actions: Z.value
1674
+ }, null, 8, ["search", "actions"]),
1675
+ f(ce, {
1676
+ style: ot(d(H).tableHeight),
1677
+ "column-defs": d(h),
1678
+ "row-data": m.value,
1679
+ "search-value": x.value,
1680
+ loading: !d(r)._currentLocation || S.value,
1681
+ "loading-text": "Loading",
1682
+ onRowClick: E[1] || (E[1] = (P) => d(b)(P.original)),
1683
+ "page-size": V.value
1684
+ }, {
1685
+ "list-row": $((P) => [
1686
+ f(Vt, {
1687
+ row: P,
1688
+ onRowClick: d(b)
1689
+ }, Oe({
1690
+ default: $((j) => {
1691
+ var ye, pe, e, n, v, k, T, I, Y, G;
1692
+ return [
1693
+ c("div", Hn, [
1694
+ c("div", On, [
1695
+ f(d(ze), {
1696
+ render: (e = (pe = (ye = j.code) == null ? void 0 : ye.column) == null ? void 0 : pe.columnDef) == null ? void 0 : e.cell,
1697
+ props: (v = (n = j.code) == null ? void 0 : n.getContext) == null ? void 0 : v.call(n)
1698
+ }, null, 8, ["render", "props"])
1699
+ ]),
1700
+ c("div", Yn, [
1701
+ f(d(ze), {
1702
+ render: (I = (T = (k = j.name) == null ? void 0 : k.column) == null ? void 0 : T.columnDef) == null ? void 0 : I.cell,
1703
+ props: (G = (Y = j.name) == null ? void 0 : Y.getContext) == null ? void 0 : G.call(Y)
1704
+ }, null, 8, ["render", "props"])
1705
+ ])
1706
+ ])
1707
+ ];
1708
+ }),
1709
+ _: 2
1710
+ }, [
1711
+ D.value ? {
1712
+ name: "loading-text",
1713
+ fn: $(() => [
1714
+ c("div", null, L(d(o)("inventory.ingredient.table.importing")), 1)
1715
+ ]),
1716
+ key: "0"
1717
+ } : void 0
1718
+ ]), 1032, ["row", "onRowClick"])
1719
+ ]),
1720
+ _: 1
1721
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"])
1722
+ ]),
1723
+ (y(), B(De, { to: "body" }, [
1724
+ f(dn, lt(at(d(_))), null, 16)
1725
+ ])),
1726
+ (y(), B(De, { to: "body" }, [
1727
+ f(me, {
1728
+ "dismiss-away": "",
1729
+ modelValue: J.value,
1730
+ "onUpdate:modelValue": E[3] || (E[3] = (P) => J.value = P)
1731
+ }, {
1732
+ default: $(() => [
1733
+ f(ne, {
1734
+ class: "pb-8",
1735
+ items: ee,
1736
+ "onUpdate:modelValue": E[2] || (E[2] = (P) => de(P))
1737
+ })
1738
+ ]),
1739
+ _: 1
1740
+ }, 8, ["modelValue"])
1741
+ ]))
1742
+ ]),
1743
+ _: 1
1744
+ }, 8, ["title", "actions"]);
1745
+ };
1746
+ }
1747
+ });
1748
+ export {
1749
+ ro as default
1750
+ };