@feedmepos/mf-inventory-portal 0.0.17-dev.1 → 0.0.17-dev.10

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