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