@feedmepos/mf-inventory-portal 1.2.11-dev.2 → 1.2.12-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/{App-7THD1njR.js → App-DAWBJNxz.js} +44 -40
  2. package/dist/{ApprovalView-DMEJRr68.js → ApprovalView-B2WUwSN4.js} +30 -30
  3. package/dist/{BindingsDialog-BNzLPDnk.js → BindingsDialog-C3OOcB8g.js} +2 -2
  4. package/dist/{BindingsPicker-b6IVAFK_.js → BindingsPicker-R3Zz0fWB.js} +1 -1
  5. package/dist/{BindingsTable-C-4XGO_N.js → BindingsTable-B46C8p7M.js} +1 -1
  6. package/dist/{ClosingDraftView-DVTloUym.js → ClosingDraftView-a_QhmaM4.js} +180 -180
  7. package/dist/{ClosingTemplateView-C-eHKV0N.js → ClosingTemplateView-CEVmIsVw.js} +3 -3
  8. package/dist/{DeliveryOrderPrintPreview-ChIV_Wxd.js → DeliveryOrderPrintPreview-BeQFF6sn.js} +1 -1
  9. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-DPkGmSYU.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-DIG9NwPj.js} +3 -3
  10. package/dist/{FmMultiselectDialog-aRqxOX4h.js → FmMultiselectDialog-BunyF2O-.js} +1 -1
  11. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-_MPI8AAx.js → FmUnitInput.vue_vue_type_script_setup_true_lang-Bx0dzfHO.js} +39 -39
  12. package/dist/ImportView-CwBeBbXz.js +1220 -0
  13. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-BiHvGyAN.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-CfwprwJN.js} +1 -1
  14. package/dist/{IngredientGroupView-DtExVKaV.js → IngredientGroupView-CIPTj0hf.js} +16 -17
  15. package/dist/IngredientsView-BwBaeLtw.js +2240 -0
  16. package/dist/{IntegrationView-LnHPQMs8.js → IntegrationView-CvRD-5O6.js} +57 -57
  17. package/dist/{InventoryBindingForm-Cm9TOWWe.js → InventoryBindingForm-DLQTH1di.js} +1 -1
  18. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-DwGz8gLR.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-XvIklIYw.js} +31 -31
  19. package/dist/{InventoryBindingSummary-BQ6ysLf9.js → InventoryBindingSummary-BGFSPQIw.js} +1 -1
  20. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-B_ASTDtr.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-B3J0i5IU.js} +1 -1
  21. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-DdFHN7A8.js → PremiumBadge.vue_vue_type_script_setup_true_lang-CyMRTB5L.js} +1 -1
  22. package/dist/{PublishView-Dg_U3hW1.js → PublishView-7g0bx6KO.js} +16 -16
  23. package/dist/{PurchaseOrderPrintPreview-DnwHiTGF.js → PurchaseOrderPrintPreview-LEfLcjkd.js} +1 -1
  24. package/dist/{ReceiveRequestView-CIzZf6q8.js → ReceiveRequestView-DUNfHRGf.js} +193 -194
  25. package/dist/RecipeView-XzqGQg_a.js +636 -0
  26. package/dist/{StockView-D6RmCUZZ.js → StockView-vZr9etBj.js} +165 -166
  27. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-BAcaiBqq.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-3_csD6uU.js} +1 -1
  28. package/dist/{SupplierView-DmJXuznz.js → SupplierView-CUORFWJW.js} +52 -52
  29. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-9wk6mQHT.js → TransferDetails.vue_vue_type_script_setup_true_lang-DhXoNkss.js} +5 -5
  30. package/dist/{TransferTemplateView-wcXRmuoK.js → TransferTemplateView-DeliKkYY.js} +97 -97
  31. package/dist/UnitView-B4NCl6jJ.js +674 -0
  32. package/dist/{WarehouseView-643lOh1p.js → WarehouseView-jLGGlnwV.js} +32 -32
  33. package/dist/api/inventory.d.ts +306 -0
  34. package/dist/{app-CsyUwsea.js → app-DJcCTZjT.js} +7663 -7341
  35. package/dist/app.d.ts +169 -0
  36. package/dist/app.js +1 -1
  37. package/dist/{closing-template-DaHVCTUh.js → closing-template-hM43IpP-.js} +1 -1
  38. package/dist/{decimal-DveC9JMl.js → decimal-BVu2HlCS.js} +1 -1
  39. package/dist/{format-unit-display-_9FgoZom.js → format-unit-display-C-M_AirC.js} +25 -25
  40. package/dist/helper/number.d.ts +1 -0
  41. package/dist/import-export.helper-C05Vl6i-.js +243 -0
  42. package/dist/{index-ChAOZMz9.js → index-CNQtmSfJ.js} +1 -1
  43. package/dist/{index-CZmm0Xbi.js → index-v6hU4gAy.js} +1 -1
  44. package/dist/{purchase-order-template-D2kAwN4O.js → purchase-order-template-BBCEFnbo.js} +1 -1
  45. package/dist/router/name.d.ts +1 -0
  46. package/dist/{stock-CL0X5Bnh.js → stock-CK3LBQmj.js} +1 -1
  47. package/dist/stores/inventory.d.ts +26 -199
  48. package/dist/{supplier-D3mOSUzY.js → supplier-CoCAyG12.js} +1 -1
  49. package/dist/tsconfig.app.tsbuildinfo +1 -1
  50. package/dist/{use-ingredient-select-dialog-Ba-l0gZ1.js → use-ingredient-select-dialog-DYfpyC4u.js} +1 -1
  51. package/dist/{use-inventory-binding-dialog-CpaprD6M.js → use-inventory-binding-dialog-CDwm6TPx.js} +1 -1
  52. package/dist/views/import/ImportView.vue.d.ts +3 -0
  53. package/dist/views/import/components/ImportDialog.vue.d.ts +2 -0
  54. package/dist/views/import/helper/import-export.helper.d.ts +4 -0
  55. package/dist/views/ingredients/helper/import-export.helper.d.ts +3 -1
  56. package/dist/views/recipe/RecipeView.vue.d.ts +1 -0
  57. package/dist/views/recipe/components/import-recipes/ImportRecipeItem.vue.d.ts +16 -0
  58. package/dist/views/recipe/components/import-recipes/ImportRecipes.vue.d.ts +2 -0
  59. package/dist/views/recipe/helper/import-recipe.d.ts +48 -0
  60. package/dist/views/unit/UnitView.vue.d.ts +1 -0
  61. package/dist/views/unit/components/import-units/ImportUnitItem.vue.d.ts +12 -0
  62. package/dist/views/unit/components/import-units/ImportUnitItemProps.d.ts +6 -0
  63. package/dist/views/unit/components/import-units/ImportUnits.vue.d.ts +9 -0
  64. package/dist/views/unit/components/import-units/ImportUnitsProps.d.ts +5 -0
  65. package/dist/views/unit/helper/import-export.helper.d.ts +40 -0
  66. package/package.json +3 -3
  67. package/dist/IngredientsView-DQUK8EMq.js +0 -2475
  68. package/dist/RecipeView-BQeJBUvu.js +0 -621
  69. package/dist/UnitView-C1cxS42T.js +0 -667
  70. package/dist/array-Ca8T3f_G.js +0 -44
@@ -0,0 +1,1220 @@
1
+ import { defineComponent as _e, ref as M, computed as z, watch as Te, resolveComponent as X, openBlock as N, createElementBlock as B, createVNode as G, normalizeClass as ie, unref as P, createSlots as Fe, withCtx as se, createElementVNode as o, createBlock as ce, toDisplayString as F, createCommentVNode as W, Fragment as Ee, renderList as we, createTextVNode as le, h as ue } from "vue";
2
+ import { a as ne, aq as Ie, b5 as he, ao as Be, V as De, an as de, l as Ae, z as Ge, B as Pe, C as He, E as Oe } from "./app-DJcCTZjT.js";
3
+ import { useCoreStore as me, useI18n as ke } from "@feedmepos/mf-common";
4
+ import { useDialogChild as Ve, useSnackbar as Re, useDialog as je, useBreakpoints as Ke } from "@feedmepos/ui-library";
5
+ import { s as ze, g as We, b as Le, d as be } from "./import-export.helper-C05Vl6i-.js";
6
+ import { r as pe } from "./random-CSbEbElR.js";
7
+ function Je() {
8
+ return `unit_${(/* @__PURE__ */ new Date()).toISOString()}_${pe()}`;
9
+ }
10
+ function xe() {
11
+ return `measurement_${(/* @__PURE__ */ new Date()).toISOString()}_${pe()}`;
12
+ }
13
+ function qe(E) {
14
+ const [
15
+ r,
16
+ _,
17
+ g,
18
+ y,
19
+ h,
20
+ x,
21
+ ...s
22
+ ] = Ie(E);
23
+ if (!r || !r.length || r.some((a) => a.length && !a.startsWith("system:")))
24
+ throw new Error("Missing meta header. Excel file does not come from the template.");
25
+ const e = r.map((a) => a.split(":")[1]), i = ["name", "symbol", "precision"].filter((a) => !e.includes(a));
26
+ if (i.length)
27
+ throw new Error(
28
+ `Missing meta headers (${i.join()}). Excel file does not come from the template.`
29
+ );
30
+ return s.map((a, p) => {
31
+ const l = {};
32
+ for (const f in e) {
33
+ const u = e[f];
34
+ Object.assign(l, { [u]: a[f] });
35
+ }
36
+ return {
37
+ index: p,
38
+ data: l
39
+ };
40
+ });
41
+ }
42
+ function Xe(E) {
43
+ try {
44
+ const r = qe(E).filter((s) => {
45
+ const { name: e, symbol: w, precision: i, measurement_name: m, measurement_symbol: a, measurement_conversion: p } = s.data;
46
+ return e || w || i || m || a || p;
47
+ }), g = ne().units, y = [], h = [];
48
+ let x = {};
49
+ for (const s of r)
50
+ if (s.data.name && s.data.symbol)
51
+ x[s.data.name] = {
52
+ unit: {
53
+ _id: Je(),
54
+ name: s.data.name,
55
+ abbrev: s.data.symbol,
56
+ precision: Math.max(0, Math.min(10, Math.floor(s.data.precision || 2))),
57
+ measurements: []
58
+ },
59
+ rowNumber: s.index
60
+ }, s.data.measurement_name && s.data.measurement_symbol && s.data.measurement_conversion && x[s.data.name].unit.measurements.push({
61
+ id: xe(),
62
+ name: s.data.measurement_name,
63
+ abbrev: s.data.measurement_symbol,
64
+ conversion: {
65
+ amount: Math.round(s.data.measurement_conversion * Math.pow(10, x[s.data.name].unit.precision)),
66
+ precision: x[s.data.name].unit.precision
67
+ }
68
+ });
69
+ else {
70
+ const e = Object.keys(x)[Object.keys(x).length - 1];
71
+ e && x[e] && s.data.measurement_name && s.data.measurement_symbol && s.data.measurement_conversion && x[e].unit.measurements.push({
72
+ id: xe(),
73
+ name: s.data.measurement_name,
74
+ abbrev: s.data.measurement_symbol,
75
+ conversion: {
76
+ amount: Math.round(s.data.measurement_conversion * Math.pow(10, x[e].unit.precision)),
77
+ precision: x[e].unit.precision
78
+ }
79
+ });
80
+ }
81
+ for (const [s, { unit: e, rowNumber: w }] of Object.entries(x)) {
82
+ const i = g.find((m) => {
83
+ var a, p;
84
+ return m.abbrev === e.abbrev && ((a = m.name) == null ? void 0 : a.trim()) === ((p = e.name) == null ? void 0 : p.trim());
85
+ });
86
+ i ? h.push({
87
+ type: "update",
88
+ original: i,
89
+ unit: {
90
+ ...i,
91
+ name: e.name || i.name,
92
+ abbrev: e.abbrev || i.abbrev,
93
+ precision: e.precision !== void 0 ? e.precision : i.precision,
94
+ measurements: e.measurements.map((m) => {
95
+ const a = i.measurements.find((p) => p.name === m.name && p.abbrev === m.abbrev);
96
+ return a ? { ...a, ...m, id: a.id } : m;
97
+ })
98
+ },
99
+ errors: [],
100
+ excelRowNumber: w
101
+ }) : y.push({
102
+ type: "create",
103
+ unit: e,
104
+ errors: [],
105
+ excelRowNumber: w
106
+ });
107
+ }
108
+ return {
109
+ invalidExcel: !1,
110
+ importCreateResult: y,
111
+ importUpdateResult: h
112
+ };
113
+ } catch (r) {
114
+ return {
115
+ invalidExcel: !0,
116
+ invalidExcelMessage: (r == null ? void 0 : r.message) ?? "Invalid excel",
117
+ importCreateResult: [],
118
+ importUpdateResult: []
119
+ };
120
+ }
121
+ }
122
+ function Qe() {
123
+ return `recipe_${(/* @__PURE__ */ new Date()).toISOString()}_${pe()}`;
124
+ }
125
+ function Ye(E, { ignoreErrors: r = !1 } = {}) {
126
+ var _, g, y;
127
+ try {
128
+ const h = ne(), x = h.skuByCode, s = h.recipeByName, e = h.skuGroupById, w = h.skuGroups, i = h.units, m = [];
129
+ let a = {};
130
+ for (const n of E) {
131
+ const v = [];
132
+ let U = "";
133
+ if (n.data.type === "INGREDIENT") {
134
+ const k = x[n.data.code];
135
+ k ? U = k._id : v.push(`Ingredient with code '${n.data.code}' not found`);
136
+ } else if (n.data.type === "RECIPE") {
137
+ const k = s[n.data.name];
138
+ k ? U = k._id : v.push(`Recipe with name '${n.data.name}' not found`);
139
+ } else if (n.data.type === "SKU_GROUP") {
140
+ const k = w.find((R) => R.ref === n.data.code || R.name === n.data.name);
141
+ k ? U = k._id : v.push(`SKU Group with ref '${n.data.code}' or name '${n.data.name}' not found`);
142
+ } else
143
+ v.push(`Invalid type '${n.data.type}'. Must be 'INGREDIENT', 'RECIPE', or 'SKU_GROUP'`);
144
+ (!n.data.amount || isNaN(parseFloat(n.data.amount))) && v.push(`Invalid amount '${n.data.amount}'. Must be a valid number`);
145
+ let A;
146
+ if ((n.data.unit || n.data.baseUnit) && n.data.type !== "RECIPE" && n.data.type !== "SKU_GROUP" && (A = i.find((k) => {
147
+ var R, Q;
148
+ return k.abbrev === n.data.baseUnit && ((R = k.name) == null ? void 0 : R.trim()) === ((Q = n.data.unit) == null ? void 0 : Q.trim());
149
+ }), A || (n.data.baseUnit && n.data.unit ? v.push(`Cannot find unit with symbol '${n.data.baseUnit}' and name '${n.data.unit}'`) : n.data.baseUnit ? v.push(`Cannot find unit with symbol '${n.data.baseUnit}'`) : n.data.unit && v.push(`Cannot find unit with name '${n.data.unit}'`))), v.length > 0 && m.push(`Row ${n.index + 6}: ${v.join(", ")}`), r || v.length === 0) {
150
+ let k;
151
+ if (n.data.type === "RECIPE" || n.data.type === "SKU_GROUP" ? k = void 0 : k = (_ = A == null ? void 0 : A.measurements) == null ? void 0 : _.find((R) => R.abbrev === n.data.measurementName), n.data.recipeName)
152
+ a[n.data.recipeName] = {
153
+ _id: Qe(),
154
+ name: n.data.recipeName,
155
+ customAttributes: n.data.customAttributes ? ze(n.data.customAttributes) : {},
156
+ contains: [{
157
+ type: n.data.type === "INGREDIENT" ? "SKU" : n.data.type,
158
+ id: U,
159
+ amount: {
160
+ amount: parseFloat(n.data.amount) || 0,
161
+ precision: he(n.data.amount) === !0 && ((g = n.data.amount.split(".")[1]) == null ? void 0 : g.length) || 0
162
+ },
163
+ measurement: k || void 0
164
+ }]
165
+ }, m[n.data.recipeName] = v.length > 0 ? `Row ${n.index + 6}: ${v.join(", ")}` : [];
166
+ else {
167
+ const R = Object.keys(a)[Object.keys(a).length - 1];
168
+ R && a[R] && (a[R] = {
169
+ ...a[R],
170
+ contains: [
171
+ ...a[R].contains,
172
+ {
173
+ type: n.data.type === "INGREDIENT" ? "SKU" : n.data.type,
174
+ id: U,
175
+ amount: {
176
+ amount: parseFloat(n.data.amount) || 0,
177
+ precision: he(n.data.amount) === !0 && ((y = n.data.amount.split(".")[1]) == null ? void 0 : y.length) || 0
178
+ },
179
+ measurement: k || void 0
180
+ }
181
+ ]
182
+ }, m[R] = v.length > 0 ? m[R] ? `${m[R]}, Row ${n.index + 6}: ${v.join(", ")}` : `Row ${n.index + 6}: ${v.join(", ")}` : []);
183
+ }
184
+ }
185
+ }
186
+ const p = Object.values(a), l = p.filter((n) => !s[n.name]), f = p.filter((n) => s[n.name]), u = l.map((n, v) => ({
187
+ type: "create",
188
+ recipe: n,
189
+ errors: m[n.name],
190
+ excelRowNumber: v + 6
191
+ // Assuming header rows
192
+ })), C = f.map((n, v) => {
193
+ const U = s[n.name];
194
+ return {
195
+ type: "update",
196
+ original: U,
197
+ recipe: {
198
+ ...U,
199
+ name: n.name || U.name,
200
+ contains: n.contains.length > 0 ? n.contains : U.contains,
201
+ customAttributes: n.customAttributes || U.customAttributes
202
+ },
203
+ errors: m[n.name],
204
+ excelRowNumber: v + 6
205
+ };
206
+ });
207
+ return {
208
+ invalidExcel: m.length > 0,
209
+ invalidExcelMessage: m.length > 0 ? `Import completed with ${m.length} error(s): ${m.join("; ")}` : void 0,
210
+ importCreateResult: u,
211
+ importUpdateResult: C
212
+ };
213
+ } catch (h) {
214
+ return {
215
+ invalidExcel: !0,
216
+ invalidExcelMessage: h instanceof Error ? h.message : "Unknown error occurred",
217
+ importCreateResult: [],
218
+ importUpdateResult: []
219
+ };
220
+ }
221
+ }
222
+ function Ze(E) {
223
+ const [
224
+ r,
225
+ _,
226
+ g,
227
+ y,
228
+ h,
229
+ x,
230
+ ...s
231
+ ] = Ie(E);
232
+ if (!r || !r.length || r.some((a) => a.length && !a.startsWith("system:")))
233
+ throw new Error("Missing meta header. Excel file does not come from the template.");
234
+ const e = r.map((a) => a.split(":")[1]), i = ["code", "recipeName", "unit", "baseUnit", "type", "amount"].filter((a) => !e.includes(a));
235
+ if (i.length)
236
+ throw new Error(
237
+ `Missing meta headers (${i.join()}). Excel file does not come from the template.`
238
+ );
239
+ return s.map((a, p) => {
240
+ const l = {};
241
+ for (const f in e) {
242
+ const u = e[f];
243
+ Object.assign(l, { [u]: a[f] });
244
+ }
245
+ return {
246
+ index: p,
247
+ data: l
248
+ };
249
+ }).filter((a) => {
250
+ const { recipeName: p, type: l, code: f, name: u, amount: C, unit: n, baseUnit: v, measurementName: U, customAttributes: A } = a.data;
251
+ return p || l || f || u || C || n || v || U || A;
252
+ });
253
+ }
254
+ function et() {
255
+ const r = me().currentBusiness.value, _ = ne(), g = [
256
+ { id: "name", name: "Unit Name" },
257
+ { id: "symbol", name: "Symbol" },
258
+ { id: "precision", name: "Precision" },
259
+ { id: "measurement_name", name: "Measurement Name" },
260
+ { id: "measurement_symbol", name: "Measurement Symbol" },
261
+ { id: "measurement_conversion", name: "Measurement Conversion" }
262
+ ];
263
+ let y = [];
264
+ _.units.length > 0 ? _.units.forEach((s) => {
265
+ if (s.measurements.length === 0)
266
+ y.push([
267
+ s.name,
268
+ s.abbrev,
269
+ s.precision,
270
+ "",
271
+ "",
272
+ ""
273
+ ]);
274
+ else {
275
+ y.push([
276
+ s.name,
277
+ s.abbrev,
278
+ s.precision,
279
+ s.measurements[0].name,
280
+ s.measurements[0].abbrev,
281
+ s.measurements[0].conversion.amount
282
+ ]);
283
+ for (let e = 1; e < s.measurements.length; e++)
284
+ y.push([
285
+ "",
286
+ "",
287
+ "",
288
+ s.measurements[e].name,
289
+ s.measurements[e].abbrev,
290
+ s.measurements[e].conversion.amount
291
+ ]);
292
+ }
293
+ }) : y = [
294
+ ["Length", "m", 2, "Meter", "m", 1],
295
+ ["", "", "", "Centimeter", "cm", 0.01],
296
+ ["", "", "", "Millimeter", "mm", 1e-3],
297
+ ["Weight", "kg", 3, "Kilogram", "kg", 1],
298
+ ["", "", "", "Gram", "g", 1e-3],
299
+ ["", "", "", "Pound", "lb", 0.453592]
300
+ ];
301
+ const h = [
302
+ ["Business name:", r == null ? void 0 : r.name],
303
+ ["Business ID:", r == null ? void 0 : r._id],
304
+ ["Menu version", r == null ? void 0 : r.menuVersion],
305
+ [],
306
+ g.map((s) => s.name),
307
+ ...y
308
+ ], x = g.map((s) => `system:${s.id}`);
309
+ return de(h, x);
310
+ }
311
+ function tt() {
312
+ const r = me().currentBusiness.value, _ = ne(), g = Le();
313
+ let y = [];
314
+ _.skus.length > 0 ? y = _.skus.map((s) => {
315
+ var e, w, i, m, a, p, l, f;
316
+ return [
317
+ s.code,
318
+ s.name,
319
+ ((e = s.unit) == null ? void 0 : e.name) || "",
320
+ ((w = s.unit) == null ? void 0 : w.abbrev) || "",
321
+ ((m = (i = s.unit) == null ? void 0 : i.measurements.find((u) => u.id === s.trackingMeasurement)) == null ? void 0 : m.abbrev) ?? s.unit.abbrev,
322
+ s.valuation || "WAVG",
323
+ (a = s.defaultCost) != null && a.costPerUnit ? +Ae((p = s.defaultCost) == null ? void 0 : p.costPerUnit) : 0,
324
+ ((l = s.thresholds) == null ? void 0 : l.low) ?? be().low,
325
+ ((f = s.thresholds) == null ? void 0 : f.mid) ?? be().mid,
326
+ s.customAttributes ? Object.entries(s.customAttributes).map(([u, C]) => `${u}:${C}`).join("|") : ""
327
+ ];
328
+ }) : y = [
329
+ ["EXAMPLE_CODE", "Example Ingredient", "kg", "kg", "Unit Name", "WAVG", 10.5, 5, 10, ""]
330
+ ];
331
+ const h = [
332
+ ["Business name:", r == null ? void 0 : r.name],
333
+ ["Business ID:", r == null ? void 0 : r._id],
334
+ ["Menu version", r == null ? void 0 : r.menuVersion],
335
+ [],
336
+ g.map((s) => s.name),
337
+ ...y
338
+ ], x = g.map((s) => `system:${s.id}`);
339
+ return de(h, x);
340
+ }
341
+ function rt() {
342
+ const r = me().currentBusiness.value, _ = ne(), g = [
343
+ { id: "recipeName", name: "Recipe Name" },
344
+ { id: "type", name: "Type" },
345
+ { id: "code", name: "Code" },
346
+ { id: "name", name: "Item Name" },
347
+ { id: "amount", name: "Amount" },
348
+ { id: "unit", name: "Unit" },
349
+ { id: "baseUnit", name: "Base Unit" },
350
+ { id: "measurementName", name: "Measurement Name" },
351
+ { id: "customAttributes", name: "Custom Attributes" }
352
+ ];
353
+ let y = [];
354
+ if (_.recipes.length > 0) {
355
+ const s = _.recipeById, e = _.skuById, w = _.skuGroupById;
356
+ y = _.recipes.flatMap((i) => {
357
+ var a;
358
+ const m = i.customAttributes ? Object.entries(i.customAttributes).map(([p, l]) => `${p}:${l}`).join("|") : "";
359
+ if ((a = i.contains) != null && a.length) {
360
+ const p = i.contains.filter((u) => u.type === "RECIPE"), l = i.contains.filter((u) => u.type === "SKU"), f = i.contains.filter((u) => u.type === "SKU_GROUP");
361
+ return [
362
+ ...p.map((u, C) => {
363
+ var n;
364
+ return [
365
+ C === 0 ? i.name : "",
366
+ "RECIPE",
367
+ "",
368
+ ((n = s[u.id]) == null ? void 0 : n.name) || "",
369
+ u.amount.amount,
370
+ "",
371
+ "unit",
372
+ "Unit",
373
+ C === 0 ? m : ""
374
+ ];
375
+ }),
376
+ ...l.map((u, C) => {
377
+ var n, v, U, A, k, R, Q, ae;
378
+ return [
379
+ !p.length && C === 0 ? i.name : "",
380
+ "INGREDIENT",
381
+ ((n = e[u.id]) == null ? void 0 : n.code) || "",
382
+ ((v = e[u.id]) == null ? void 0 : v.name) || "",
383
+ u.amount.amount,
384
+ u.measurement ? u.measurement.name : ((A = (U = e[u.id]) == null ? void 0 : U.unit) == null ? void 0 : A.name) || "",
385
+ u.measurement ? u.measurement.abbrev : ((R = (k = e[u.id]) == null ? void 0 : k.unit) == null ? void 0 : R.abbrev) || "",
386
+ u.measurement ? u.measurement.name : ((ae = (Q = e[u.id]) == null ? void 0 : Q.unit) == null ? void 0 : ae.name) || "",
387
+ !p.length && C === 0 ? m : ""
388
+ ];
389
+ }),
390
+ ...f.map((u, C) => {
391
+ var n, v;
392
+ return [
393
+ p.length === 0 && l.length === 0 && C === 0 ? i.name : "",
394
+ "SKU_GROUP",
395
+ ((n = w[u.id]) == null ? void 0 : n.ref) || "",
396
+ ((v = w[u.id]) == null ? void 0 : v.name) || "",
397
+ u.amount.amount,
398
+ "",
399
+ "unit",
400
+ "Unit",
401
+ p.length === 0 && l.length === 0 && C === 0 ? m : ""
402
+ ];
403
+ })
404
+ ];
405
+ }
406
+ return [];
407
+ });
408
+ } else
409
+ y = [
410
+ ["Pizza Dough", "INGREDIENT", "FLOUR001", "Flour", "500", "Weight", "g", "Gram", "difficulty:easy, category:italian"],
411
+ ["", "INGREDIENT", "WATER001", "Water", "300", "Volume", "ml", "Milliliter", ""],
412
+ ["", "INGREDIENT", "SALT001", "Salt", "10", "Weight", "g", "Gram", ""]
413
+ ];
414
+ const h = [
415
+ ["Business name:", r == null ? void 0 : r.name],
416
+ ["Business ID:", r == null ? void 0 : r._id],
417
+ ["Menu version", r == null ? void 0 : r.menuVersion],
418
+ [],
419
+ g.map((s) => s.name),
420
+ ...y
421
+ ], x = g.map((s) => `system:${s.id}`);
422
+ return de(h, x);
423
+ }
424
+ function st() {
425
+ const E = Be({
426
+ unit: et(),
427
+ ingredient: tt(),
428
+ recipe: rt()
429
+ }), r = "FeedMe comprehensive template.xlsx";
430
+ return De(E, r), r;
431
+ }
432
+ async function nt(E) {
433
+ if (!E) return null;
434
+ try {
435
+ return Xe(E);
436
+ } catch (r) {
437
+ throw console.error("Error in processUnitsSheet:", r), r;
438
+ }
439
+ }
440
+ async function at(E) {
441
+ if (!E) return null;
442
+ try {
443
+ return We(E);
444
+ } catch (r) {
445
+ throw console.error("Error in processIngredientsSheet:", r), r;
446
+ }
447
+ }
448
+ async function ot(E) {
449
+ if (!E) return null;
450
+ try {
451
+ const r = Ze(E);
452
+ return Ye(r, { ignoreErrors: !0 });
453
+ } catch (r) {
454
+ throw console.error("Error in processRecipesSheet:", r), r;
455
+ }
456
+ }
457
+ const it = { class: "flex flex-col gap-24" }, lt = { class: "flex flex-col gap-8" }, ut = { class: "flex flex-col flex-1 gap-4" }, ct = { class: "fm-typo-en-body-md-600" }, dt = {
458
+ key: 2,
459
+ class: "shrink-0"
460
+ }, mt = {
461
+ key: 0,
462
+ class: "flex flex-col"
463
+ }, pt = { class: "text-fm-color-system-error-300 fm-typo-en-body-sm-400" }, vt = {
464
+ key: 0,
465
+ class: "max-h-[200px] overflow-y-auto flex flex-col gap-8"
466
+ }, ft = { class: "fm-typo-en-body-lg-600" }, gt = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, yt = /* @__PURE__ */ _e({
467
+ __name: "ImportDialog",
468
+ setup(E) {
469
+ const r = M(null), _ = Ve();
470
+ Re();
471
+ const g = M(!1), y = M(new Array()), h = M(null), x = M([]), s = M([]), e = z(() => !!y.value.length), w = z(() => !!h.value && x.value.length > 0), { t: i } = ke();
472
+ async function m(l) {
473
+ y.value = [], h.value = null, x.value = [], s.value = [];
474
+ try {
475
+ g.value = !0;
476
+ const [f] = await Promise.all([
477
+ Pe(l),
478
+ // fake buffer for UX
479
+ new Promise((u) => setTimeout(u, 1e3))
480
+ ]);
481
+ h.value = f, a();
482
+ } catch (f) {
483
+ console.error("Error parsing Excel file:", f), y.value.push((f == null ? void 0 : f.message) || "Unknown error occurred");
484
+ } finally {
485
+ g.value = !1;
486
+ }
487
+ }
488
+ function a() {
489
+ if (y.value = [], !h.value) return;
490
+ const f = ["unit", "ingredient", "recipe"].filter((u) => h.value.Sheets[u]);
491
+ if (f.length === 0) {
492
+ y.value.push("No valid sheets found. Expected sheets: unit, ingredient, or recipe");
493
+ return;
494
+ }
495
+ x.value = f, _.emitData({ availableSheets: f, workbook: h.value });
496
+ }
497
+ Te(r, (l) => {
498
+ l && m(l);
499
+ });
500
+ function p() {
501
+ if (!h.value || x.value.length === 0) return "";
502
+ const l = [];
503
+ return x.value.forEach((f) => {
504
+ switch (f) {
505
+ case "unit":
506
+ l.push("Units sheet found");
507
+ break;
508
+ case "ingredient":
509
+ l.push("Ingredients sheet found");
510
+ break;
511
+ case "recipe":
512
+ l.push("Recipes sheet found");
513
+ break;
514
+ }
515
+ }), l.length > 0 ? `Ready to process: ${l.join(", ")}. Processing will follow dependency order.` : "No valid sheets found";
516
+ }
517
+ return (l, f) => {
518
+ const u = X("FmCircularProgress"), C = X("FmIcon"), n = X("FmButton");
519
+ return N(), B("div", it, [
520
+ G(Ge, {
521
+ class: ie({
522
+ "w-full": !0,
523
+ "h-[200px]": !r.value
524
+ }),
525
+ accept: ".xlsx,.xls",
526
+ onFileUpload: f[0] || (f[0] = (v) => r.value = v),
527
+ label: P(i)("inventory.ingredient.import.uploadTemplate"),
528
+ "button-label": P(i)("inventory.ingredient.import.selectFile")
529
+ }, Fe({ _: 2 }, [
530
+ r.value ? {
531
+ name: "default",
532
+ fn: se(({ openFileDialog: v }) => [
533
+ o("div", lt, [
534
+ o("div", {
535
+ class: ie([
536
+ "fm-corner-radius-md p-16 flex items-center gap-16",
537
+ {
538
+ "border border-fm-color-neutral-gray-100": g.value,
539
+ "border border-fm-color-neutral-gray-200": !g.value && !e.value,
540
+ "border border-fm-color-system-error-200": e.value
541
+ }
542
+ ])
543
+ }, [
544
+ g.value ? (N(), ce(u, {
545
+ key: 0,
546
+ size: "md",
547
+ color: "neutral-gray-200"
548
+ })) : (N(), ce(C, {
549
+ key: 1,
550
+ name: e.value ? "error" : "check_circle",
551
+ color: e.value ? "system-error-300" : "system-success-400",
552
+ size: "lg"
553
+ }, null, 8, ["name", "color"])),
554
+ o("div", ut, [
555
+ o("div", ct, F(r.value.name), 1),
556
+ o("div", {
557
+ class: ie([
558
+ "fm-typo-en-body-sm-400",
559
+ {
560
+ "text-fm-color-system-error-300": e.value,
561
+ "text-fm-color-typo-secondary": !e.value
562
+ }
563
+ ])
564
+ }, F(e.value ? P(i)("inventory.ingredient.import.error.invalidContent") : "File valid"), 3)
565
+ ]),
566
+ g.value ? W("", !0) : (N(), B("div", dt, [
567
+ G(n, {
568
+ label: P(i)("inventory.ingredient.import.replaceFile"),
569
+ variant: e.value ? "destructive" : "secondary",
570
+ "prepend-icon": e.value ? void 0 : "autorenew",
571
+ onClick: v
572
+ }, null, 8, ["label", "variant", "prepend-icon", "onClick"])
573
+ ]))
574
+ ], 2),
575
+ y.value.length ? (N(), B("div", mt, [
576
+ (N(!0), B(Ee, null, we(y.value, (U, A) => (N(), B("div", {
577
+ key: A,
578
+ class: "flex gap-8 items-center"
579
+ }, [
580
+ G(C, {
581
+ name: "error",
582
+ size: "sm",
583
+ color: "system-error-300"
584
+ }),
585
+ o("div", pt, F(U), 1)
586
+ ]))), 128))
587
+ ])) : W("", !0)
588
+ ])
589
+ ]),
590
+ key: "0"
591
+ } : void 0
592
+ ]), 1032, ["class", "label", "button-label"]),
593
+ w.value ? (N(), B("div", vt, [
594
+ o("div", ft, F(P(i)("inventory.ingredient.import.summary")), 1),
595
+ o("div", gt, F(p()), 1)
596
+ ])) : W("", !0)
597
+ ]);
598
+ };
599
+ }
600
+ }), ht = {
601
+ key: 0,
602
+ class: "bg-blue-50 border border-blue-200 rounded-lg p-16"
603
+ }, bt = { class: "flex items-start gap-12" }, xt = { class: "flex flex-col gap-8" }, _t = { class: "fm-typo-en-body-md-400 text-blue-800" }, Et = { class: "fm-typo-en-body-sm-400 text-blue-700" }, wt = ["innerHTML"], It = ["innerHTML"], kt = {
604
+ key: 1,
605
+ class: "bg-white rounded-lg shadow"
606
+ }, Rt = { class: "flex items-center justify-between p-16 border-b" }, St = { class: "fm-typo-en-body-sm-400 text-gray-600 mt-4" }, Ct = {
607
+ key: 0,
608
+ class: "text-red-600"
609
+ }, Ut = {
610
+ key: 1,
611
+ class: "text-orange-600"
612
+ }, $t = {
613
+ key: 2,
614
+ class: "text-green-600"
615
+ }, Nt = { class: "flex gap-8" }, Mt = { class: "p-16" }, Tt = {
616
+ key: 2,
617
+ class: "bg-white rounded-lg shadow"
618
+ }, Ft = { class: "flex items-center justify-between p-16 border-b" }, Bt = { class: "fm-typo-en-body-sm-400 text-gray-600 mt-4" }, Dt = { class: "flex gap-8" }, At = { class: "p-16" }, Gt = {
619
+ key: 0,
620
+ class: "flex flex-col gap-16 p-16"
621
+ }, Pt = { class: "grid grid-cols-2 gap-12" }, Ht = { class: "fm-typo-en-body-md-600" }, Ot = { key: 0 }, Vt = { class: "fm-typo-en-body-md-600" }, jt = { class: "fm-typo-en-body-md-600" }, Kt = { class: "fm-typo-en-body-md-600" }, zt = { class: "space-y-8" }, Wt = { class: "fm-typo-en-body-md-400 text-red-800" }, Lt = { class: "bg-gray-50 p-12 rounded border overflow-auto" }, Jt = { class: "text-sm" }, qt = { class: "flex gap-8" }, rr = /* @__PURE__ */ _e({
622
+ __name: "ImportView",
623
+ setup(E) {
624
+ const { t: r } = ke(), _ = je(), g = Re();
625
+ He();
626
+ const { breakpoints: y } = Ke(), h = ne(), x = M("");
627
+ M(!1);
628
+ const s = M(!1), e = M(null), w = M(!1), i = M(null), m = M(!1), a = M([]), p = M(null), l = M([]), f = M(!1), u = z(() => y.value.xs || y.value.sm), C = z(() => u.value ? 10 : 20), n = z(() => e.value ? !!(e.value.units && [
629
+ ...e.value.units.create || [],
630
+ ...e.value.units.update || []
631
+ ].some((t) => t.errors && t.errors.length > 0) || e.value.skus && [
632
+ ...e.value.skus.create || [],
633
+ ...e.value.skus.update || []
634
+ ].some((t) => t.errors && t.errors.length > 0) || e.value.recipes && [
635
+ ...e.value.recipes.create || [],
636
+ ...e.value.recipes.update || []
637
+ ].some((t) => t.errors && t.errors.length > 0)) : !1), v = z(() => e.value ? !!e.value._invalidExcel : !1), U = z(() => {
638
+ if (!e.value) return [];
639
+ const d = [];
640
+ if (e.value.units) {
641
+ if (e.value.units.create)
642
+ for (const t of e.value.units.create) {
643
+ const I = t.errors && t.errors.length > 0 ? t.errors || "Validation Failed" : e.value._invalidExcel ? e.value._invalidExcelMessage || "Invalid Excel format" : "Ready to Import";
644
+ d.push({
645
+ name: t.name || t.abbrev || "Unknown",
646
+ type: "Unit",
647
+ operation: "Create",
648
+ status: I,
649
+ errors: t.errors || [],
650
+ details: t
651
+ });
652
+ }
653
+ if (e.value.units.update)
654
+ for (const t of e.value.units.update) {
655
+ const I = t.errors && t.errors.length > 0 ? t.errors || "Validation Failed" : e.value._invalidExcel ? e.value._invalidExcelMessage || "Invalid Excel format" : "Ready to Import";
656
+ d.push({
657
+ name: t.name || t.abbrev || "Unknown",
658
+ type: "Unit",
659
+ operation: "Update",
660
+ status: I,
661
+ errors: t.errors || [],
662
+ details: t
663
+ });
664
+ }
665
+ }
666
+ if (e.value.skus) {
667
+ if (e.value.skus.create)
668
+ for (const t of e.value.skus.create) {
669
+ const I = t.errors && t.errors.length > 0 ? t.errors || "Validation Failed" : e.value._invalidExcel ? e.value._invalidExcelMessage || "Invalid Excel format" : "Ready to Import";
670
+ d.push({
671
+ name: t.name || t.code || "Unknown",
672
+ type: "Ingredient",
673
+ operation: "Create",
674
+ status: I,
675
+ errors: t.errors || [],
676
+ details: t
677
+ });
678
+ }
679
+ if (e.value.skus.update)
680
+ for (const t of e.value.skus.update) {
681
+ const I = t.errors && t.errors.length > 0 ? t.errors || "Validation Failed" : e.value._invalidExcel ? e.value._invalidExcelMessage || "Invalid Excel format" : "Ready to Import";
682
+ d.push({
683
+ name: t.name || t.code || "Unknown",
684
+ type: "Ingredient",
685
+ operation: "Update",
686
+ status: I,
687
+ errors: t.errors || [],
688
+ details: t
689
+ });
690
+ }
691
+ }
692
+ if (e.value.recipes) {
693
+ if (e.value.recipes.create)
694
+ for (const t of e.value.recipes.create) {
695
+ const I = t.errors && t.errors.length > 0 ? t.errors || "Validation Failed" : e.value._invalidExcel ? e.value._invalidExcelMessage || "Invalid Excel format" : "Ready to Import";
696
+ d.push({
697
+ name: t.name || t.code || "Unknown",
698
+ type: "Recipe",
699
+ operation: "Create",
700
+ status: I,
701
+ errors: t.errors || [],
702
+ details: t
703
+ });
704
+ }
705
+ if (e.value.recipes.update)
706
+ for (const t of e.value.recipes.update) {
707
+ const I = t.errors && t.errors.length > 0 ? t.errors || "Validation Failed" : e.value._invalidExcel ? e.value._invalidExcelMessage || "Invalid Excel format" : "Ready to Import";
708
+ d.push({
709
+ name: t.name || t.code || "Unknown",
710
+ type: "Recipe",
711
+ operation: "Update",
712
+ status: I,
713
+ errors: t.errors || [],
714
+ details: t
715
+ });
716
+ }
717
+ }
718
+ return d;
719
+ }), A = z(() => !l.value || l.value.length === 0 ? [] : l.value.map((d, t) => {
720
+ var b;
721
+ return {
722
+ id: t + 1,
723
+ name: d.error.data.name || "Unknown",
724
+ type: d.type || "General",
725
+ message: ((b = d.error) == null ? void 0 : b.message) || JSON.stringify(d.error)
726
+ };
727
+ }));
728
+ function k(d) {
729
+ switch (d) {
730
+ case "import":
731
+ return R();
732
+ }
733
+ }
734
+ M(null);
735
+ function R() {
736
+ _.open({
737
+ title: r("common.import"),
738
+ contentComponent: yt,
739
+ overlay: !0,
740
+ closeButton: !0,
741
+ primaryActions: {
742
+ text: r("common.next"),
743
+ close: !1
744
+ },
745
+ secondaryActions: {
746
+ text: r("common.close"),
747
+ close: !0
748
+ },
749
+ tertiaryActions: {
750
+ text: r("inventory.ingredient.import.actions.downloadTemplate"),
751
+ close: !1,
752
+ variant: "plain"
753
+ }
754
+ }).onPrimary(async (d) => {
755
+ d && d.workbook && d.availableSheets && (await Q(d), _.close()), a.value.length === 0 && _.close();
756
+ }).onTertiary(() => {
757
+ try {
758
+ const d = st();
759
+ g.open({
760
+ title: r("common.export") + " " + r("inventory.ingredient.import.actions.downloadTemplate"),
761
+ message: `Template downloaded: ${d}`,
762
+ type: "success"
763
+ });
764
+ } catch (d) {
765
+ g.open({
766
+ title: "Download Failed",
767
+ message: "Failed to download template. Please try again.",
768
+ type: "error"
769
+ }), console.error("Error downloading template:", d);
770
+ }
771
+ });
772
+ }
773
+ async function Q(d) {
774
+ e.value || (e.value = {}), p.value = d.workbook, a.value = [...d.availableSheets], await ae();
775
+ }
776
+ async function ae() {
777
+ var t, b, I, L, K, Y;
778
+ if (!p.value || a.value.length === 0) {
779
+ w.value = !0;
780
+ return;
781
+ }
782
+ const d = a.value[0];
783
+ try {
784
+ e.value || (e.value = {});
785
+ const T = e.value;
786
+ switch (d) {
787
+ case "unit":
788
+ const O = p.value.Sheets.unit, D = await nt(O);
789
+ D && (D.invalidExcel && (T._invalidExcel = !0, T._invalidExcelMessage = D.invalidExcelMessage || "Invalid Excel format for Units sheet"), (D.importCreateResult || D.importUpdateResult) && (T.units = {
790
+ create: ((t = D.importCreateResult) == null ? void 0 : t.map(($) => ({ ...$.unit, errors: $.errors }))) || [],
791
+ update: ((b = D.importUpdateResult) == null ? void 0 : b.map(($) => ({ ...$.unit, errors: $.errors }))) || []
792
+ }));
793
+ break;
794
+ case "ingredient":
795
+ const Z = p.value.Sheets.ingredient, H = await at(Z);
796
+ H && (H.invalidExcel && (T._invalidExcel = !0, T._invalidExcelMessage = H.invalidExcelMessage || "Invalid Excel format for Ingredients sheet"), (H.importCreateResult || H.importUpdateResult) && (T.skus = {
797
+ create: ((I = H.importCreateResult) == null ? void 0 : I.map(($) => ({ ...$.sku, errors: $.errors }))) || [],
798
+ update: ((L = H.importUpdateResult) == null ? void 0 : L.map(($) => ({ ...$.sku, errors: $.errors }))) || []
799
+ }));
800
+ break;
801
+ case "recipe":
802
+ const ee = p.value.Sheets.recipe, j = await ot(ee);
803
+ j && (j.invalidExcel && (T._invalidExcel = !0, T._invalidExcelMessage = j.invalidExcelMessage || "Invalid Excel format for Recipes sheet"), (j.importCreateResult || j.importUpdateResult) && (T.recipes = {
804
+ create: ((K = j.importCreateResult) == null ? void 0 : K.map(($) => ({ ...$.recipe, errors: $.errors }))) || [],
805
+ update: ((Y = j.importUpdateResult) == null ? void 0 : Y.map(($) => ({ ...$.recipe, errors: $.errors }))) || []
806
+ }));
807
+ break;
808
+ }
809
+ a.value.shift(), w.value = !0;
810
+ } catch (T) {
811
+ console.error(`Error processing ${d} sheet:`, T), g.open({
812
+ title: "Processing Error",
813
+ message: `Failed to process ${d} sheet`,
814
+ type: "error"
815
+ });
816
+ }
817
+ }
818
+ async function Se() {
819
+ var d, t, b, I, L, K, Y, T, O, D, Z, H, ee, j, $, fe, ge, ye;
820
+ if (e.value) {
821
+ if (v.value) {
822
+ g.open({
823
+ title: "Invalid Excel Format",
824
+ message: e.value._invalidExcelMessage || "Invalid Excel format detected",
825
+ type: "error"
826
+ });
827
+ return;
828
+ }
829
+ if (n.value) {
830
+ g.open({
831
+ title: r("inventory.import.error.invalidContent"),
832
+ message: r("inventory.ingredient.import.error.hasErrors"),
833
+ type: "error"
834
+ });
835
+ return;
836
+ }
837
+ s.value = !0;
838
+ try {
839
+ let V = 0, te = "";
840
+ if (e.value.units && ((d = e.value.units.create) != null && d.length || (t = e.value.units.update) != null && t.length)) {
841
+ const S = {
842
+ create: ((b = e.value.units.create) == null ? void 0 : b.filter((c) => !c.errors || c.errors.length === 0)) || [],
843
+ update: ((I = e.value.units.update) == null ? void 0 : I.filter((c) => !c.errors || c.errors.length === 0)) || []
844
+ };
845
+ if (S.create.length || S.update.length) {
846
+ const c = await h.importUnits(S);
847
+ c && c.errors && c.errors.length > 0 && l.value.push(...c.errors.map((re) => ({
848
+ type: "units",
849
+ error: re
850
+ })));
851
+ const J = S.create.length + S.update.length, q = c && c.errors ? c.errors.length : 0;
852
+ V = J - q, te = "units", e.value.units = null;
853
+ }
854
+ } else if (e.value.skus && ((L = e.value.skus.create) != null && L.length || (K = e.value.skus.update) != null && K.length)) {
855
+ const S = {
856
+ create: ((Y = e.value.skus.create) == null ? void 0 : Y.filter((c) => !c.errors || c.errors.length === 0)) || [],
857
+ update: ((T = e.value.skus.update) == null ? void 0 : T.filter((c) => !c.errors || c.errors.length === 0)) || []
858
+ };
859
+ if (S.create.length || S.update.length) {
860
+ const c = await h.importSkus(S);
861
+ c && c.errors && c.errors.length > 0 && l.value.push(...c.errors.map((re) => ({
862
+ type: "ingredients",
863
+ error: re
864
+ })));
865
+ const J = S.create.length + S.update.length, q = c && c.errors ? c.errors.length : 0;
866
+ V = J - q, te = "ingredients", e.value.skus = null;
867
+ }
868
+ } else if (e.value.recipes && ((O = e.value.recipes.create) != null && O.length || (D = e.value.recipes.update) != null && D.length)) {
869
+ const S = {
870
+ create: ((Z = e.value.recipes.create) == null ? void 0 : Z.filter((c) => !c.errors || c.errors.length === 0)) || [],
871
+ update: ((H = e.value.recipes.update) == null ? void 0 : H.filter((c) => !c.errors || c.errors.length === 0)) || []
872
+ };
873
+ if (S.create.length || S.update.length) {
874
+ const c = await h.importRecipes(S);
875
+ c && c.errors && c.errors.length > 0 && l.value.push(...c.errors.map((re) => ({
876
+ type: "recipes",
877
+ error: re
878
+ })));
879
+ const J = S.create.length + S.update.length, q = c && c.errors ? c.errors.length : 0;
880
+ V = J - q, te = "recipes", e.value.recipes = null;
881
+ }
882
+ }
883
+ if (V > 0) {
884
+ const S = l.value.filter((c) => c.type === te);
885
+ S.length > 0 ? g.open({
886
+ title: "Import Completed with Issues",
887
+ message: `Successfully imported ${V} ${te}, failed ${S.length} ${te}`,
888
+ type: "warning"
889
+ }) : g.open({
890
+ title: r("inventory.ingredient.import.success"),
891
+ message: `Successfully imported ${V} ${te}`,
892
+ type: "success"
893
+ });
894
+ }
895
+ if (a.value.length > 0)
896
+ await ae();
897
+ else if (!(e.value.units && (((ee = e.value.units.create) == null ? void 0 : ee.length) || ((j = e.value.units.update) == null ? void 0 : j.length)) || e.value.skus && ((($ = e.value.skus.create) == null ? void 0 : $.length) || ((fe = e.value.skus.update) == null ? void 0 : fe.length)) || e.value.recipes && (((ge = e.value.recipes.create) == null ? void 0 : ge.length) || ((ye = e.value.recipes.update) == null ? void 0 : ye.length))))
898
+ if (ve(), l.value.length > 0) {
899
+ const c = l.value.filter((oe) => oe.type === "units").length, J = l.value.filter((oe) => oe.type === "ingredients").length, q = l.value.filter((oe) => oe.type === "recipes").length, re = c + J + q;
900
+ f.value = !0, g.open({
901
+ title: "Import Completed with Issues",
902
+ message: `Import finished with ${re} failed items (${c} units, ${J} ingredients, ${q} recipes failed). Check the error details below.`,
903
+ type: "warning"
904
+ }), console.error("Import errors:", l.value);
905
+ } else
906
+ g.open({
907
+ title: "Import Complete",
908
+ message: "All data has been successfully imported!",
909
+ type: "success"
910
+ });
911
+ } catch (V) {
912
+ g.open({
913
+ title: r("inventory.ingredient.import.error.failed"),
914
+ message: (V == null ? void 0 : V.message) || "Unknown error occurred",
915
+ type: "error"
916
+ }), console.error("Error during import:", V);
917
+ } finally {
918
+ s.value = !1;
919
+ }
920
+ }
921
+ }
922
+ function ve() {
923
+ w.value = !1, f.value = !1, e.value = null, a.value = [], p.value = null;
924
+ }
925
+ function Ce() {
926
+ f.value = !1, l.value = [];
927
+ }
928
+ function Ue() {
929
+ m.value = !1, i.value = null;
930
+ }
931
+ const $e = z(() => [
932
+ {
933
+ label: r("common.import"),
934
+ value: "import",
935
+ isPrimary: !1,
936
+ prependIcon: "upload"
937
+ }
938
+ ]), Ne = [
939
+ {
940
+ id: "name",
941
+ accessorKey: "name",
942
+ header: () => "Name",
943
+ size: 200
944
+ },
945
+ {
946
+ id: "type",
947
+ accessorKey: "type",
948
+ header: () => "Type",
949
+ size: 120
950
+ },
951
+ {
952
+ id: "operation",
953
+ accessorKey: "operation",
954
+ header: () => "Operation",
955
+ size: 100
956
+ },
957
+ {
958
+ id: "status",
959
+ accessorKey: "status",
960
+ header: () => "Status",
961
+ size: 120,
962
+ cell: (d) => {
963
+ const t = d.row.original.status;
964
+ let b = "px-8 py-4 rounded";
965
+ return t === "Ready to Import" ? b += " bg-blue-100 text-blue-800 border border-blue-200" : t === "Imported" || t === "Successfully Imported" ? b += " bg-green-100 text-green-800 border border-green-200" : t === "Failed" ? b += " bg-red-100 text-red-800 border border-red-200" : t === "Validation Failed" ? b += " bg-orange-100 text-orange-800 border border-orange-200" : (t.includes("Invalid Excel"), b += " bg-red-100 text-red-800 border border-red-200"), ue("div", {
966
+ class: b,
967
+ title: t
968
+ // Add title attribute for hover tooltip
969
+ }, t);
970
+ }
971
+ }
972
+ ], Me = [
973
+ {
974
+ id: "name",
975
+ accessorKey: "name",
976
+ header: () => "Name",
977
+ cell: (d) => {
978
+ const t = d.row.original.name || "Unknown";
979
+ return ue("div", {
980
+ class: "text-gray-800 text-sm py-2"
981
+ }, t);
982
+ }
983
+ },
984
+ {
985
+ id: "type",
986
+ accessorKey: "type",
987
+ header: () => "Error Type",
988
+ cell: (d) => {
989
+ const t = d.row.original.type;
990
+ let b = "";
991
+ return t === "units" ? b = "Unit" : t === "ingredients" ? b = "Ingredient" : t === "recipes" ? b = "Recipe" : b = "Unknown", ue("div", {
992
+ class: "text-gray-800 text-sm py-2"
993
+ }, b);
994
+ }
995
+ },
996
+ {
997
+ id: "message",
998
+ accessorKey: "message",
999
+ header: () => "Error Message",
1000
+ cell: (d) => {
1001
+ const t = d.row.original.message;
1002
+ return ue("div", {
1003
+ class: "text-red-800 text-sm py-2",
1004
+ title: t
1005
+ // Add tooltip for long messages
1006
+ }, t);
1007
+ }
1008
+ }
1009
+ ];
1010
+ return (d, t) => {
1011
+ const b = X("FmIcon"), I = X("FmButton"), L = X("FmTable"), K = X("FmCard"), Y = X("FmSideSheet");
1012
+ return N(), ce(Oe, {
1013
+ title: P(r)("inventory.common.import"),
1014
+ actions: $e.value,
1015
+ "onClick:action": k
1016
+ }, {
1017
+ default: se(() => {
1018
+ var T;
1019
+ return [
1020
+ o("div", {
1021
+ class: ie([
1022
+ "flex flex-col gap-8 max-h-full",
1023
+ {
1024
+ "p-0": u.value,
1025
+ "px-24": !u.value
1026
+ }
1027
+ ])
1028
+ }, [
1029
+ w.value ? W("", !0) : (N(), B("div", ht, [
1030
+ o("div", bt, [
1031
+ G(b, {
1032
+ name: "info",
1033
+ class: "text-blue-600 mt-2"
1034
+ }),
1035
+ o("div", xt, [
1036
+ o("div", _t, F(P(r)("inventory.ingredient.import.multiUploadTemplateInstruction")), 1),
1037
+ o("div", Et, [
1038
+ t[1] || (t[1] = le(" 1. ")),
1039
+ o("span", {
1040
+ innerHTML: P(r)("inventory.ingredient.import.importInstructions.step1")
1041
+ }, null, 8, wt),
1042
+ t[2] || (t[2] = o("br", null, null, -1)),
1043
+ t[3] || (t[3] = le(" 2. ")),
1044
+ o("span", {
1045
+ innerHTML: P(r)("inventory.ingredient.import.importInstructions.step2")
1046
+ }, null, 8, It),
1047
+ t[4] || (t[4] = o("br", null, null, -1)),
1048
+ le(" 3. " + F(P(r)("inventory.ingredient.import.importInstructions.step3")), 1),
1049
+ t[5] || (t[5] = o("br", null, null, -1)),
1050
+ le(" 4. " + F(P(r)("inventory.ingredient.import.importInstructions.step4")), 1)
1051
+ ])
1052
+ ])
1053
+ ])
1054
+ ])),
1055
+ w.value ? (N(), B("div", kt, [
1056
+ o("div", Rt, [
1057
+ o("div", null, [
1058
+ t[6] || (t[6] = o("div", { class: "fm-typo-en-title-md-600" }, "Import Preview", -1)),
1059
+ o("div", St, [
1060
+ v.value ? (N(), B("span", Ct, " Error exist: " + F(e.value._invalidExcelMessage), 1)) : n.value ? (N(), B("span", Ut, " Some items have validation errors. Only valid items will be imported. ")) : (N(), B("span", $t, " All items are valid and ready to import. "))
1061
+ ])
1062
+ ]),
1063
+ o("div", Nt, [
1064
+ G(I, {
1065
+ variant: "secondary",
1066
+ onClick: ve,
1067
+ label: P(r)("common.cancel")
1068
+ }, null, 8, ["label"]),
1069
+ G(I, {
1070
+ variant: "primary",
1071
+ onClick: Se,
1072
+ loading: s.value,
1073
+ disabled: s.value || n.value || v.value,
1074
+ label: P(r)("common.import")
1075
+ }, null, 8, ["loading", "disabled", "label"])
1076
+ ])
1077
+ ]),
1078
+ o("div", Mt, [
1079
+ G(L, {
1080
+ "column-defs": Ne,
1081
+ "row-data": U.value,
1082
+ "page-size": C.value,
1083
+ "search-value": x.value,
1084
+ loading: !1,
1085
+ "row-hover": ""
1086
+ }, null, 8, ["row-data", "page-size", "search-value"])
1087
+ ])
1088
+ ])) : W("", !0),
1089
+ f.value && l.value.length > 0 ? (N(), B("div", Tt, [
1090
+ o("div", Ft, [
1091
+ o("div", null, [
1092
+ t[7] || (t[7] = o("div", { class: "fm-typo-en-title-md-600 text-red-800" }, "Import Errors", -1)),
1093
+ o("div", Bt, F(l.value.length) + " items failed to import. Review the errors below: ", 1)
1094
+ ]),
1095
+ o("div", Dt, [
1096
+ G(I, {
1097
+ variant: "secondary",
1098
+ onClick: Ce,
1099
+ label: P(r)("common.close")
1100
+ }, null, 8, ["label"])
1101
+ ])
1102
+ ]),
1103
+ o("div", At, [
1104
+ G(L, {
1105
+ "column-defs": Me,
1106
+ "row-data": A.value,
1107
+ "page-size": C.value,
1108
+ "search-value": x.value,
1109
+ loading: !1,
1110
+ "row-hover": ""
1111
+ }, null, 8, ["row-data", "page-size", "search-value"])
1112
+ ])
1113
+ ])) : W("", !0)
1114
+ ], 2),
1115
+ G(Y, {
1116
+ "model-value": m.value,
1117
+ "onUpdate:modelValue": t[0] || (t[0] = (O) => m.value = O),
1118
+ header: `${(T = i.value) == null ? void 0 : T.type} Details`,
1119
+ "max-width": 600,
1120
+ "dismiss-away": ""
1121
+ }, {
1122
+ "side-sheet-footer": se(() => [
1123
+ o("div", qt, [
1124
+ G(I, {
1125
+ label: "Close",
1126
+ variant: "tertiary",
1127
+ onClick: Ue
1128
+ })
1129
+ ])
1130
+ ]),
1131
+ default: se(() => [
1132
+ i.value != null ? (N(), B("div", Gt, [
1133
+ G(K, {
1134
+ variant: "outlined",
1135
+ class: "p-16"
1136
+ }, {
1137
+ default: se(() => {
1138
+ var O, D, Z, H, ee;
1139
+ return [
1140
+ t[13] || (t[13] = o("div", { class: "fm-typo-en-title-sm-600 mb-12" }, "Basic Information", -1)),
1141
+ o("div", Pt, [
1142
+ o("div", null, [
1143
+ t[8] || (t[8] = o("div", { class: "fm-typo-en-body-sm-400 text-gray-600" }, "Name", -1)),
1144
+ o("div", Ht, F(((D = (O = i.value) == null ? void 0 : O.details) == null ? void 0 : D.name) || ((Z = i.value) == null ? void 0 : Z.name)), 1)
1145
+ ]),
1146
+ (ee = (H = i.value) == null ? void 0 : H.details) != null && ee.code ? (N(), B("div", Ot, [
1147
+ t[9] || (t[9] = o("div", { class: "fm-typo-en-body-sm-400 text-gray-600" }, "Code", -1)),
1148
+ o("div", Vt, F(i.value.details.code), 1)
1149
+ ])) : W("", !0),
1150
+ o("div", null, [
1151
+ t[10] || (t[10] = o("div", { class: "fm-typo-en-body-sm-400 text-gray-600" }, "Type", -1)),
1152
+ o("div", jt, F(i.value.type), 1)
1153
+ ]),
1154
+ o("div", null, [
1155
+ t[11] || (t[11] = o("div", { class: "fm-typo-en-body-sm-400 text-gray-600" }, "Operation", -1)),
1156
+ o("div", Kt, F(i.value.operation), 1)
1157
+ ]),
1158
+ o("div", null, [
1159
+ t[12] || (t[12] = o("div", { class: "fm-typo-en-body-sm-400 text-gray-600" }, "Status", -1)),
1160
+ o("div", {
1161
+ class: ie([
1162
+ "inline-block px-8 py-4 rounded text-sm",
1163
+ i.value.status !== "Ready to Import" ? "bg-red-100 text-red-800 border border-red-200" : "bg-green-100 text-green-800 border border-green-200"
1164
+ ])
1165
+ }, F(i.value.status), 3)
1166
+ ])
1167
+ ])
1168
+ ];
1169
+ }),
1170
+ _: 1
1171
+ }),
1172
+ i.value.errors && i.value.errors.length > 0 ? (N(), ce(K, {
1173
+ key: 0,
1174
+ variant: "outlined",
1175
+ class: "p-16"
1176
+ }, {
1177
+ default: se(() => [
1178
+ t[14] || (t[14] = o("div", { class: "fm-typo-en-title-sm-600 mb-12 text-red-800" }, "Validation Errors", -1)),
1179
+ o("div", zt, [
1180
+ (N(!0), B(Ee, null, we(i.value.errors, (O, D) => (N(), B("div", {
1181
+ key: D,
1182
+ class: "flex items-start gap-8 p-12 bg-red-50 border border-red-200 rounded"
1183
+ }, [
1184
+ G(b, {
1185
+ name: "error",
1186
+ class: "text-red-600 mt-2",
1187
+ size: "sm"
1188
+ }),
1189
+ o("div", Wt, F(O), 1)
1190
+ ]))), 128))
1191
+ ])
1192
+ ]),
1193
+ _: 1
1194
+ })) : W("", !0),
1195
+ G(K, {
1196
+ variant: "outlined",
1197
+ class: "p-16"
1198
+ }, {
1199
+ default: se(() => [
1200
+ t[15] || (t[15] = o("div", { class: "fm-typo-en-title-sm-600 mb-12" }, "Raw Data", -1)),
1201
+ o("div", Lt, [
1202
+ o("pre", Jt, F(JSON.stringify(i.value.details, null, 2)), 1)
1203
+ ])
1204
+ ]),
1205
+ _: 1
1206
+ })
1207
+ ])) : W("", !0)
1208
+ ]),
1209
+ _: 1
1210
+ }, 8, ["model-value", "header"])
1211
+ ];
1212
+ }),
1213
+ _: 1
1214
+ }, 8, ["title", "actions"]);
1215
+ };
1216
+ }
1217
+ });
1218
+ export {
1219
+ rr as default
1220
+ };