import { defineComponent as De, ref as F, computed as J, watch as ze, resolveComponent as Y, openBlock as G, createElementBlock as D, createVNode as A, normalizeClass as ce, unref as i, createSlots as Ke, withCtx as Q, createElementVNode as n, createBlock as se, toDisplayString as a, createCommentVNode as Z, Fragment as Be, renderList as Pe, shallowRef as $e, h as Ie, createTextVNode as k } from "vue";
import { u as Ve, _ as ke } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-sUxHOj47.js";
import { useCoreStore as Re, useI18n as je } from "@feedmepos/mf-common";
import { useDialogChild as We, useSnackbar as Oe, useDialog as Le, useBreakpoints as Je } from "@feedmepos/ui-library";
import { u as Xe } from "./feature-Cz6F0_cm.js";
import { a as ie } from "./app-Bpb4394e.js";
import "./dayjs.min-D5mIeZ1x.js";
import "./app-DiX-EfV6.js";
import "./FmAdminBadge-DjnBAgyv.js";
import { s as He, a as qe, d as Qe, t as Ce, r as Ye } from "./xlsx.util-BPV2vsSD.js";
import { s as Ze, g as et, b as tt, d as Fe } from "./import-export.helper-BnI8EiMF.js";
import { r as nt } from "./random-CSbEbElR.js";
import { c as Ae, a as pe } from "./number-BVg7EKPV.js";
import { F as ot } from "./FmDroppableField-J0xUsOTV.js";
function Ee() {
  return `measurement_${(/* @__PURE__ */ new Date()).toISOString()}_${nt()}`;
}
function rt(U) {
  const [
    e,
    R,
    g,
    h,
    E,
    x,
    ...r
  ] = He(U);
  if (!e || !e.length || e.some((p) => p.length && !p.startsWith("system:")))
    throw new Error("Missing meta header. Excel file does not come from the template.");
  const l = e.map((p) => p.split(":")[1]), u = ["name", "symbol", "precision"].filter((p) => !l.includes(p));
  if (u.length)
    throw new Error(
      `Missing meta headers (${u.join()}). Excel file does not come from the template.`
    );
  return r.map((p, b) => {
    const f = {};
    for (const d in l) {
      const o = l[d];
      Object.assign(f, { [o]: p[d] });
    }
    return {
      index: b,
      data: f
    };
  });
}
function st(U) {
  try {
    const e = rt(U).filter((r) => {
      const { name: l, symbol: s, precision: u, measurement_name: v, measurement_symbol: p, measurement_conversion: b } = r.data;
      return l || s || u || v || p || b;
    }), g = ie().units, h = [], E = [], x = {};
    for (const r of e)
      if (r.data.name && r.data.symbol)
        x[r.data.name] = {
          unit: {
            name: r.data.name,
            abbrev: r.data.symbol,
            precision: Math.max(0, Math.min(10, Math.floor(r.data.precision || 2))),
            measurements: []
          },
          rowNumber: r.index
        }, r.data.measurement_name && r.data.measurement_symbol && r.data.measurement_conversion && x[r.data.name].unit.measurements.push({
          id: Ee(),
          name: r.data.measurement_name,
          abbrev: r.data.measurement_symbol,
          conversion: {
            amount: Math.round(r.data.measurement_conversion * Math.pow(10, x[r.data.name].unit.precision)),
            precision: x[r.data.name].unit.precision
          }
        });
      else {
        const l = Object.keys(x)[Object.keys(x).length - 1];
        l && x[l] && r.data.measurement_name && r.data.measurement_symbol && r.data.measurement_conversion && x[l].unit.measurements.push({
          id: Ee(),
          name: r.data.measurement_name,
          abbrev: r.data.measurement_symbol,
          conversion: {
            amount: Math.round(r.data.measurement_conversion * Math.pow(10, x[l].unit.precision)),
            precision: x[l].unit.precision
          }
        });
      }
    for (const [r, { unit: l, rowNumber: s }] of Object.entries(x)) {
      const u = g.find((v) => {
        var p, b;
        return v.abbrev === l.abbrev && ((p = v.name) == null ? void 0 : p.trim()) === ((b = l.name) == null ? void 0 : b.trim());
      });
      u ? E.push({
        type: "update",
        original: u,
        unit: {
          ...u,
          name: l.name || u.name,
          abbrev: l.abbrev || u.abbrev,
          precision: l.precision !== void 0 ? l.precision : u.precision,
          measurements: l.measurements.map((v) => {
            const p = u.measurements.find((b) => b.name === v.name && b.abbrev === v.abbrev);
            return p ? { ...p, ...v, id: p.id } : { ...v, id: Ee() };
          })
        },
        errors: [],
        excelRowNumber: s
      }) : h.push({
        type: "create",
        unit: {
          ...l,
          measurements: l.measurements.map((v) => ({ ...v, id: Ee() }))
        },
        errors: [],
        excelRowNumber: s
      });
    }
    return {
      invalidExcel: !1,
      importCreateResult: h,
      importUpdateResult: E
    };
  } catch (e) {
    return {
      invalidExcel: !0,
      invalidExcelMessage: (e == null ? void 0 : e.message) ?? "Invalid excel",
      importCreateResult: [],
      importUpdateResult: []
    };
  }
}
function it(U, { ignoreErrors: e = !1 } = {}) {
  var R;
  try {
    const g = ie(), h = g.skuByCode, E = g.recipeByName, x = g.skuGroupById, r = g.skuGroups, l = g.units, s = [], u = {};
    for (const o of U) {
      const y = [];
      let _ = "";
      if (o.data.type === "INGREDIENT") {
        const w = h[o.data.code];
        w ? _ = w._id : y.push(`Ingredient with code '${o.data.code}' not found`);
      } else if (o.data.type === "RECIPE") {
        const w = E[o.data.name];
        w ? _ = w._id : y.push(`Recipe with name '${o.data.name}' not found`);
      } else if (o.data.type === "SKU_GROUP") {
        const w = r.find((I) => I.ref === o.data.code || I.name === o.data.name);
        w ? _ = w._id : y.push(`SKU Group with ref '${o.data.code}' or name '${o.data.name}' not found`);
      } else
        y.push(`Invalid type '${o.data.type}'. Must be 'INGREDIENT', 'RECIPE', or 'SKU_GROUP'`);
      o.data.amount || y.push(`Invalid amount '${o.data.amount}'. Must be a valid number`);
      let N;
      if ((o.data.unit || o.data.baseUnit) && o.data.type !== "RECIPE" && o.data.type !== "SKU_GROUP" && (N = l.find((w) => {
        var I, ee;
        return w.abbrev === o.data.baseUnit && ((I = w.name) == null ? void 0 : I.trim()) === ((ee = o.data.unit) == null ? void 0 : ee.trim());
      }), N || (o.data.baseUnit && o.data.unit ? y.push(`Cannot find unit with symbol '${o.data.baseUnit}' and name '${o.data.unit}'`) : o.data.baseUnit ? y.push(`Cannot find unit with symbol '${o.data.baseUnit}'`) : o.data.unit && y.push(`Cannot find unit with name '${o.data.unit}'`))), y.length > 0 && s.push(`Row ${o.index + 6}: ${y.join(", ")}`), e || y.length === 0) {
        let w;
        if (o.data.type === "RECIPE" || o.data.type === "SKU_GROUP" ? w = void 0 : w = (R = N == null ? void 0 : N.measurements) == null ? void 0 : R.find((I) => I.abbrev === o.data.measurementName), o.data.recipeName)
          u[o.data.recipeName] = {
            name: o.data.recipeName,
            customAttributes: o.data.customAttributes ? Ze(o.data.customAttributes) : {},
            contains: [{
              type: o.data.type === "INGREDIENT" ? "SKU" : o.data.type,
              id: _,
              amount: Ae(+o.data.amount),
              measurement: w || void 0
            }]
          }, s[o.data.recipeName] = y.length > 0 ? `Row ${o.index + 6}: ${y.join(", ")}` : [];
        else {
          const I = Object.keys(u)[Object.keys(u).length - 1];
          I && u[I] && (u[I] = {
            ...u[I],
            contains: [
              ...u[I].contains,
              {
                type: o.data.type === "INGREDIENT" ? "SKU" : o.data.type,
                id: _,
                amount: Ae(+o.data.amount),
                measurement: w || void 0
              }
            ]
          }, s[I] = y.length > 0 ? s[I] ? `${s[I]}, Row ${o.index + 6}: ${y.join(", ")}` : `Row ${o.index + 6}: ${y.join(", ")}` : []);
        }
      }
    }
    const v = Object.values(u), p = v.filter((o) => !E[o.name]), b = v.filter((o) => E[o.name]), f = p.map((o, y) => ({
      type: "create",
      recipe: o,
      // Type assertion - _id will be assigned by backend
      errors: s[o.name],
      excelRowNumber: y + 6
      // Assuming header rows
    })), d = b.map((o, y) => {
      const _ = E[o.name];
      return {
        type: "update",
        original: _,
        recipe: {
          ..._,
          name: o.name || _.name,
          contains: o.contains.length > 0 ? o.contains : _.contains,
          customAttributes: o.customAttributes || _.customAttributes
        },
        errors: s[o.name],
        excelRowNumber: y + 6
      };
    });
    return {
      invalidExcel: s.length > 0,
      invalidExcelMessage: s.length > 0 ? `Import completed with ${s.length} error(s): ${s.join("; ")}` : void 0,
      importCreateResult: f,
      importUpdateResult: d
    };
  } catch (g) {
    return {
      invalidExcel: !0,
      invalidExcelMessage: g instanceof Error ? g.message : "Unknown error occurred",
      importCreateResult: [],
      importUpdateResult: []
    };
  }
}
function at(U) {
  const [
    e,
    R,
    g,
    h,
    E,
    x,
    ...r
  ] = He(U);
  if (!e || !e.length || e.some((p) => p.length && !p.startsWith("system:")))
    throw new Error("Missing meta header. Excel file does not come from the template.");
  const l = e.map((p) => p.split(":")[1]), u = ["code", "recipeName", "unit", "baseUnit", "type", "amount"].filter((p) => !l.includes(p));
  if (u.length)
    throw new Error(
      `Missing meta headers (${u.join()}). Excel file does not come from the template.`
    );
  return r.map((p, b) => {
    const f = {};
    for (const d in l) {
      const o = l[d];
      Object.assign(f, { [o]: p[d] });
    }
    return {
      index: b,
      data: f
    };
  }).filter((p) => {
    const { recipeName: b, type: f, code: d, name: o, amount: y, unit: _, baseUnit: N, measurementName: w, customAttributes: I } = p.data;
    return b || f || d || o || y || _ || N || w || I;
  });
}
function lt() {
  const e = Re().currentBusiness.value, R = ie(), g = [
    { id: "name", name: "Unit Name" },
    { id: "symbol", name: "Symbol" },
    { id: "precision", name: "Precision" },
    { id: "measurement_name", name: "Measurement Name" },
    { id: "measurement_symbol", name: "Measurement Symbol" },
    { id: "measurement_conversion", name: "Measurement Conversion" }
  ];
  let h = [];
  R.units.length > 0 ? R.units.forEach((r) => {
    if (r.measurements.length === 0)
      h.push([
        r.name,
        r.abbrev,
        r.precision,
        "",
        "",
        ""
      ]);
    else {
      h.push([
        r.name,
        r.abbrev,
        r.precision,
        r.measurements[0].name,
        r.measurements[0].abbrev,
        +pe(r.measurements[0].conversion)
      ]);
      for (let l = 1; l < r.measurements.length; l++)
        h.push([
          "",
          "",
          "",
          r.measurements[l].name,
          r.measurements[l].abbrev,
          +pe(r.measurements[l].conversion)
        ]);
    }
  }) : h = [
    ["Length", "m", 2, "Meter", "m", 1],
    ["", "", "", "Centimeter", "cm", 0.01],
    ["", "", "", "Millimeter", "mm", 1e-3],
    ["Weight", "kg", 3, "Kilogram", "kg", 1],
    ["", "", "", "Gram", "g", 1e-3],
    ["", "", "", "Pound", "lb", 0.453592]
  ];
  const E = [
    ["Business name:", e == null ? void 0 : e.name],
    ["Business ID:", e == null ? void 0 : e._id],
    ["Menu version", e == null ? void 0 : e.menuVersion],
    [],
    g.map((r) => r.name),
    ...h
  ], x = g.map((r) => `system:${r.id}`);
  return Ce(E, x);
}
function mt() {
  const e = Re().currentBusiness.value, R = ie(), g = tt();
  let h = [];
  R.skus.length > 0 ? h = R.skus.map((r) => {
    var l, s, u, v, p, b, f, d;
    return [
      r.code,
      r.name,
      ((l = r.unit) == null ? void 0 : l.name) || "",
      ((s = r.unit) == null ? void 0 : s.abbrev) || "",
      ((v = (u = r.unit) == null ? void 0 : u.measurements.find((o) => o.id === r.trackingMeasurement)) == null ? void 0 : v.abbrev) ?? r.unit.abbrev,
      r.valuation || "WAVG",
      (p = r.defaultCost) != null && p.costPerUnit ? +pe((b = r.defaultCost) == null ? void 0 : b.costPerUnit) : 0,
      ((f = r.thresholds) == null ? void 0 : f.low) ?? Fe().low,
      ((d = r.thresholds) == null ? void 0 : d.mid) ?? Fe().mid,
      r.customAttributes ? Object.entries(r.customAttributes).map(([o, y]) => `${o}:${y}`).join("|") : ""
    ];
  }) : h = [
    ["EXAMPLE_CODE", "Example Ingredient", "kg", "kg", "Unit Name", "WAVG", 10.5, 5, 10, ""]
  ];
  const E = [
    ["Business name:", e == null ? void 0 : e.name],
    ["Business ID:", e == null ? void 0 : e._id],
    ["Menu version", e == null ? void 0 : e.menuVersion],
    [],
    g.map((r) => r.name),
    ...h
  ], x = g.map((r) => `system:${r.id}`);
  return Ce(E, x);
}
function ut() {
  const e = Re().currentBusiness.value, R = ie(), g = [
    { id: "recipeName", name: "Recipe Name" },
    { id: "type", name: "Type" },
    { id: "code", name: "Code" },
    { id: "name", name: "Item Name" },
    { id: "amount", name: "Amount" },
    { id: "unit", name: "Unit" },
    { id: "baseUnit", name: "Base Unit" },
    { id: "measurementName", name: "Measurement Name" },
    { id: "customAttributes", name: "Custom Attributes" }
  ];
  let h = [];
  if (R.recipes.length > 0) {
    const r = R.recipeById, l = R.skuById, s = R.skuGroupById;
    h = R.recipes.flatMap((u) => {
      var p;
      const v = u.customAttributes ? Object.entries(u.customAttributes).map(([b, f]) => `${b}:${f}`).join("|") : "";
      if ((p = u.contains) != null && p.length) {
        const b = u.contains.filter((o) => o.type === "RECIPE"), f = u.contains.filter((o) => o.type === "SKU"), d = u.contains.filter((o) => o.type === "SKU_GROUP");
        return [
          ...b.map((o, y) => {
            var _;
            return [
              y === 0 ? u.name : "",
              "RECIPE",
              "",
              ((_ = r[o.id]) == null ? void 0 : _.name) || "",
              o.amount.amount,
              "",
              "unit",
              "Unit",
              y === 0 ? v : ""
            ];
          }),
          ...f.map((o, y) => {
            var _, N, w, I, ee, ve, ye, ge, fe, ae, be, le, he, xe, _e, we;
            return [
              !b.length && y === 0 ? u.name : "",
              "INGREDIENT",
              ((_ = l[o.id]) == null ? void 0 : _.code) || "",
              ((N = l[o.id]) == null ? void 0 : N.name) || "",
              +pe(o.amount),
              o.measurement ? ((I = (w = l[o.id]) == null ? void 0 : w.unit) == null ? void 0 : I.name) || "" : ((ve = (ee = l[o.id]) == null ? void 0 : ee.unit) == null ? void 0 : ve.name) || "",
              o.measurement ? ((ge = (ye = l[o.id]) == null ? void 0 : ye.unit) == null ? void 0 : ge.abbrev) || "" : ((ae = (fe = l[o.id]) == null ? void 0 : fe.unit) == null ? void 0 : ae.abbrev) || "",
              o.measurement ? o.measurement.abbrev : ((xe = (he = (le = (be = l[o.id]) == null ? void 0 : be.unit) == null ? void 0 : le.measurements) == null ? void 0 : he.find((Se) => {
                var m;
                return Se.id === ((m = l[o.id]) == null ? void 0 : m.trackingMeasurement);
              })) == null ? void 0 : xe.abbrev) || ((we = (_e = l[o.id]) == null ? void 0 : _e.unit) == null ? void 0 : we.abbrev) || "",
              !b.length && y === 0 ? v : ""
            ];
          }),
          ...d.map((o, y) => {
            var _, N;
            return [
              b.length === 0 && f.length === 0 && y === 0 ? u.name : "",
              "SKU_GROUP",
              ((_ = s[o.id]) == null ? void 0 : _.ref) || "",
              ((N = s[o.id]) == null ? void 0 : N.name) || "",
              +pe(o.amount),
              "",
              "unit",
              "Unit",
              b.length === 0 && f.length === 0 && y === 0 ? v : ""
            ];
          })
        ];
      }
      return [];
    });
  } else
    h = [
      ["Pizza Dough", "INGREDIENT", "FLOUR001", "Flour", "500", "Weight", "g", "Gram", "difficulty:easy, category:italian"],
      ["", "INGREDIENT", "WATER001", "Water", "300", "Volume", "ml", "Milliliter", ""],
      ["", "INGREDIENT", "SALT001", "Salt", "10", "Weight", "g", "Gram", ""]
    ];
  const E = [
    ["Business name:", e == null ? void 0 : e.name],
    ["Business ID:", e == null ? void 0 : e._id],
    ["Menu version", e == null ? void 0 : e.menuVersion],
    [],
    g.map((r) => r.name),
    ...h
  ], x = g.map((r) => `system:${r.id}`);
  return Ce(E, x);
}
function dt() {
  const U = qe({
    unit: lt(),
    ingredient: mt(),
    recipe: ut()
  }), e = "FeedMe comprehensive template.xlsx";
  return Qe(U, e), e;
}
async function ct(U) {
  if (!U) return null;
  try {
    return st(U);
  } catch (e) {
    throw console.error("Error in processUnitsSheet:", e), e;
  }
}
async function pt(U) {
  if (!U) return null;
  try {
    return et(U);
  } catch (e) {
    throw console.error("Error in processIngredientsSheet:", e), e;
  }
}
async function vt(U) {
  if (!U) return null;
  try {
    const e = at(U);
    return it(e, { ignoreErrors: !0 });
  } catch (e) {
    throw console.error("Error in processRecipesSheet:", e), e;
  }
}
const yt = { class: "flex flex-col gap-24" }, gt = { class: "flex flex-col gap-8" }, ft = { class: "flex flex-col flex-1 gap-4" }, bt = { class: "fm-typo-en-body-md-600" }, ht = {
  key: 2,
  class: "shrink-0"
}, xt = {
  key: 0,
  class: "flex flex-col"
}, _t = { class: "text-fm-color-system-error-300 fm-typo-en-body-sm-400" }, wt = {
  key: 0,
  class: "max-h-[200px] overflow-y-auto flex flex-col gap-8"
}, It = { class: "fm-typo-en-body-lg-600" }, Et = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, St = /* @__PURE__ */ De({
  __name: "ImportDialog",
  setup(U) {
    const e = F(null), R = We();
    Oe();
    const g = F(!1), h = F(new Array()), E = F(null), x = F([]), r = F([]), l = J(() => !!h.value.length), s = J(() => !!E.value && x.value.length > 0), { t: u } = je();
    async function v(f) {
      h.value = [], E.value = null, x.value = [], r.value = [];
      try {
        g.value = !0;
        const [d] = await Promise.all([
          Ye(f),
          // fake buffer for UX
          new Promise((o) => setTimeout(o, 1e3))
        ]);
        E.value = d, p();
      } catch (d) {
        console.error("Error parsing Excel file:", d), h.value.push((d == null ? void 0 : d.message) || "Unknown error occurred");
      } finally {
        g.value = !1;
      }
    }
    function p() {
      if (h.value = [], !E.value) return;
      const d = ["unit", "ingredient", "recipe"].filter((o) => E.value.Sheets[o]);
      if (d.length === 0) {
        h.value.push("No valid sheets found. Expected sheets: unit, ingredient, or recipe");
        return;
      }
      x.value = d, R.emitData({ availableSheets: d, workbook: E.value });
    }
    ze(e, (f) => {
      f && v(f);
    });
    function b() {
      if (!E.value || x.value.length === 0) return "";
      const f = [];
      return x.value.forEach((d) => {
        switch (d) {
          case "unit":
            f.push("Units sheet found");
            break;
          case "ingredient":
            f.push("Ingredients sheet found");
            break;
          case "recipe":
            f.push("Recipes sheet found");
            break;
        }
      }), f.length > 0 ? `Ready to process: ${f.join(", ")}. Processing will follow dependency order.` : "No valid sheets found";
    }
    return (f, d) => {
      const o = Y("FmCircularProgress"), y = Y("FmIcon"), _ = Y("FmButton");
      return G(), D("div", yt, [
        A(ot, {
          class: ce({
            "w-full": !0,
            "h-[200px]": !e.value
          }),
          accept: ".xlsx,.xls",
          onFileUpload: d[0] || (d[0] = (N) => e.value = N),
          label: i(u)("inventory.ingredient.import.uploadTemplate"),
          "button-label": i(u)("inventory.ingredient.import.selectFile")
        }, Ke({ _: 2 }, [
          e.value ? {
            name: "default",
            fn: Q(({ openFileDialog: N }) => [
              n("div", gt, [
                n("div", {
                  class: ce([
                    "fm-corner-radius-md p-16 flex items-center gap-16",
                    {
                      "border border-fm-color-neutral-gray-100": g.value,
                      "border border-fm-color-neutral-gray-200": !g.value && !l.value,
                      "border border-fm-color-system-error-200": l.value
                    }
                  ])
                }, [
                  g.value ? (G(), se(o, {
                    key: 0,
                    size: "md",
                    color: "neutral-gray-200"
                  })) : (G(), se(y, {
                    key: 1,
                    name: l.value ? "error" : "check_circle",
                    color: l.value ? "system-error-300" : "system-success-400",
                    size: "lg"
                  }, null, 8, ["name", "color"])),
                  n("div", ft, [
                    n("div", bt, a(e.value.name), 1),
                    n("div", {
                      class: ce([
                        "fm-typo-en-body-sm-400",
                        {
                          "text-fm-color-system-error-300": l.value,
                          "text-fm-color-typo-secondary": !l.value
                        }
                      ])
                    }, a(l.value ? i(u)("inventory.ingredient.import.error.invalidContent") : "File valid"), 3)
                  ]),
                  g.value ? Z("", !0) : (G(), D("div", ht, [
                    A(_, {
                      label: i(u)("inventory.ingredient.import.replaceFile"),
                      variant: l.value ? "destructive" : "secondary",
                      "prepend-icon": l.value ? void 0 : "autorenew",
                      onClick: N
                    }, null, 8, ["label", "variant", "prepend-icon", "onClick"])
                  ]))
                ], 2),
                h.value.length ? (G(), D("div", xt, [
                  (G(!0), D(Be, null, Pe(h.value, (w, I) => (G(), D("div", {
                    key: I,
                    class: "flex gap-8 items-center"
                  }, [
                    A(y, {
                      name: "error",
                      size: "sm",
                      color: "system-error-300"
                    }),
                    n("div", _t, a(w), 1)
                  ]))), 128))
                ])) : Z("", !0)
              ])
            ]),
            key: "0"
          } : void 0
        ]), 1032, ["class", "label", "button-label"]),
        s.value ? (G(), D("div", wt, [
          n("div", It, a(i(u)("inventory.ingredient.import.summary")), 1),
          n("div", Et, a(b()), 1)
        ])) : Z("", !0)
      ]);
    };
  }
}), kt = {
  key: 0,
  class: "bg-blue-50 border border-blue-200 rounded-lg p-16"
}, Rt = { class: "flex items-start gap-12" }, Ct = { class: "flex flex-col gap-8" }, Ut = { class: "fm-typo-en-body-md-400 text-blue-800" }, Nt = { class: "fm-typo-en-body-sm-400 text-blue-700" }, Gt = { class: "mb-8" }, Tt = ["innerHTML"], Mt = ["innerHTML"], $t = { class: "mb-8" }, Ft = { class: "mb-12" }, At = { class: "mb-12" }, Dt = { class: "mb-8" }, Bt = { class: "text-orange-600" }, Pt = {
  key: 1,
  class: "bg-white rounded-lg shadow"
}, jt = { class: "flex items-center justify-between p-16 border-b" }, Ot = { class: "fm-typo-en-title-md-600" }, Ht = { class: "fm-typo-en-body-sm-400 text-gray-600 mt-4" }, zt = {
  key: 0,
  class: "text-red-600"
}, Kt = {
  key: 1,
  class: "text-orange-600"
}, Vt = {
  key: 2,
  class: "text-green-600"
}, Wt = { class: "flex gap-8" }, Lt = { class: "p-16" }, Jt = {
  key: 2,
  class: "bg-white rounded-lg shadow"
}, Xt = { class: "flex items-center justify-between p-16 border-b" }, qt = { class: "fm-typo-en-title-md-600 text-red-800" }, Qt = { class: "fm-typo-en-body-sm-400 text-gray-600 mt-4" }, Yt = { class: "flex gap-8" }, Zt = { class: "p-16" }, en = {
  key: 0,
  class: "flex flex-col gap-16 p-16"
}, tn = { class: "fm-typo-en-title-sm-600 mb-12" }, nn = { class: "grid grid-cols-2 gap-12" }, on = { class: "fm-typo-en-body-sm-400 text-gray-600" }, rn = { class: "fm-typo-en-body-md-600" }, sn = { key: 0 }, an = { class: "fm-typo-en-body-sm-400 text-gray-600" }, ln = { class: "fm-typo-en-body-md-600" }, mn = { class: "fm-typo-en-body-sm-400 text-gray-600" }, un = { class: "fm-typo-en-body-md-600" }, dn = { class: "fm-typo-en-body-sm-400 text-gray-600" }, cn = { class: "fm-typo-en-body-md-600" }, pn = { class: "fm-typo-en-body-sm-400 text-gray-600" }, vn = { class: "fm-typo-en-title-sm-600 mb-12 text-red-800" }, yn = { class: "space-y-8" }, gn = { class: "fm-typo-en-body-md-400 text-red-800" }, fn = { class: "fm-typo-en-title-sm-600 mb-12" }, bn = { class: "bg-gray-50 p-12 rounded border overflow-auto" }, hn = { class: "text-sm" }, xn = { class: "flex gap-8" }, _n = { class: "flex flex-col items-center justify-center h-64 gap-16" }, wn = { class: "text-center" }, In = { class: "fm-typo-en-title-md-600 text-gray-600 mb-8" }, En = { class: "flex flex-col items-center justify-center h-64 gap-16" }, Sn = { class: "text-center" }, kn = { class: "fm-typo-en-title-md-600 text-gray-600 mb-8" }, Rn = { class: "fm-typo-en-body-md-400 text-gray-500" }, Hn = /* @__PURE__ */ De({
  __name: "ImportView",
  setup(U) {
    const { t: e } = je(), R = Le(), g = Oe();
    Ve();
    const h = Xe(), { breakpoints: E } = Je(), x = ie(), r = F("");
    F(!1);
    const l = F(!1), s = F(null), u = F(!1), v = F(null), p = F(!1), b = F([]), f = F(null), d = F([]), o = F(!1), y = J(() => E.value.xs || E.value.sm), _ = J(() => y.value ? 10 : 20), N = J(() => {
      const m = s.value;
      if (!m) return [];
      const t = [], { units: C, skus: B, recipes: W, _invalidExcel: z, _invalidExcelMessage: X } = m, q = (M) => {
        var j;
        return ((j = M.errors) == null ? void 0 : j.length) > 0 ? Array.isArray(M.errors) ? M.errors.join(", ") : M.errors || e("inventory.common.validationFailed") : z ? X || e("inventory.common.invalidExcelFormat") : e("inventory.common.readyToImport");
      }, H = (M, O) => {
        if (M)
          for (const j of ["create", "update"]) {
            const K = M[j];
            if (K)
              for (const P of K)
                t.push({
                  name: P.name || P.abbrev || P.code || e("inventory.common.unknown"),
                  type: O,
                  operation: e(j === "create" ? "inventory.common.create" : "inventory.common.update"),
                  status: q(P),
                  errors: P.errors || [],
                  details: P
                });
          }
      };
      return H(C, e("inventory.common.unit")), H(B, e("inventory.common.ingredient")), H(W, e("inventory.common.recipe")), t;
    }), w = J(() => N.value.some(
      (m) => m.errors && m.errors.length > 0
    )), I = J(() => N.value.some(
      (m) => m.status && m.status.includes("Invalid Excel")
    )), ee = J(() => {
      const m = N.value.find(
        (t) => t.status && t.status.includes("Invalid Excel")
      );
      return (m == null ? void 0 : m.status) || e("inventory.common.invalidExcelFormatDetected");
    }), ve = J(() => !d.value || d.value.length === 0 ? [] : d.value.map((m, t) => {
      var C, B;
      return {
        id: t + 1,
        name: ((C = m.error.data) == null ? void 0 : C.name) || e("inventory.common.unknown"),
        type: m.type || e("inventory.common.general"),
        message: ((B = m.error) == null ? void 0 : B.message) || JSON.stringify(m.error)
      };
    }));
    function ye(m) {
      switch (m) {
        case "import":
          return ge();
      }
    }
    function ge() {
      R.open({
        title: e("inventory.common.import"),
        contentComponent: St,
        overlay: !0,
        closeButton: !0,
        primaryActions: {
          text: e("inventory.common.next"),
          close: !1
        },
        secondaryActions: {
          text: e("inventory.common.close"),
          close: !0
        },
        tertiaryActions: {
          text: e("inventory.ingredient.import.actions.downloadTemplate"),
          close: !1,
          variant: "plain"
        }
      }).onPrimary(async (m) => {
        m && m.workbook && m.availableSheets && (await fe(m), R.close()), b.value.length === 0 && R.close();
      }).onTertiary(() => {
        try {
          const m = dt();
          g.open({
            title: e("inventory.common.export") + " " + e("inventory.ingredient.import.actions.downloadTemplate"),
            message: e("inventory.common.templateDownloaded", [m]),
            type: "success"
          });
        } catch (m) {
          g.open({
            title: e("inventory.common.downloadFailed"),
            message: e("inventory.common.failedDownloadTemplate"),
            type: "error"
          }), console.error("Error downloading template:", m);
        }
      });
    }
    async function fe(m) {
      f.value = m.workbook, b.value = [...m.availableSheets], s.value = {}, d.value = [], await ae();
    }
    async function ae() {
      var t, C, B, W, z, X, q, H, M, O, j, K, P, me, ue;
      if (!f.value || b.value.length === 0) {
        u.value = !0;
        return;
      }
      const m = b.value[0];
      try {
        switch (m) {
          case "unit": {
            const L = f.value.Sheets.unit, S = await ct(L);
            S && (s.value = {
              ...s.value,
              _invalidExcel: S.invalidExcel || ((t = s.value) == null ? void 0 : t._invalidExcel),
              _invalidExcelMessage: S.invalidExcelMessage || ((C = s.value) == null ? void 0 : C._invalidExcelMessage) || e("inventory.common.invalidExcelFormat") + " for Units sheet",
              units: S.importCreateResult || S.importUpdateResult ? {
                create: ((B = S.importCreateResult) == null ? void 0 : B.map(($) => ({
                  ...$.unit,
                  errors: $.errors
                }))) || [],
                update: ((W = S.importUpdateResult) == null ? void 0 : W.map(($) => ({
                  ...$.unit,
                  errors: $.errors
                }))) || []
              } : (z = s.value) == null ? void 0 : z.units
            });
            break;
          }
          case "ingredient": {
            const L = f.value.Sheets.ingredient, S = await pt(L);
            S && (s.value = {
              ...s.value,
              _invalidExcel: S.invalidExcel || ((X = s.value) == null ? void 0 : X._invalidExcel),
              _invalidExcelMessage: S.invalidExcelMessage || ((q = s.value) == null ? void 0 : q._invalidExcelMessage) || e("inventory.common.invalidExcelFormat") + " for Ingredients sheet",
              skus: S.importCreateResult || S.importUpdateResult ? {
                create: ((H = S.importCreateResult) == null ? void 0 : H.map(($) => ({
                  ...$.sku,
                  errors: $.errors
                }))) || [],
                update: ((M = S.importUpdateResult) == null ? void 0 : M.map(($) => ({
                  ...$.sku,
                  errors: $.errors
                }))) || []
              } : (O = s.value) == null ? void 0 : O.skus
            });
            break;
          }
          case "recipe": {
            const L = f.value.Sheets.recipe, S = await vt(L);
            S && (s.value = {
              ...s.value,
              _invalidExcel: S.invalidExcel || ((j = s.value) == null ? void 0 : j._invalidExcel),
              _invalidExcelMessage: S.invalidExcelMessage || ((K = s.value) == null ? void 0 : K._invalidExcelMessage) || e("inventory.common.invalidExcelFormat") + " for Recipes sheet",
              recipes: S.importCreateResult || S.importUpdateResult ? {
                create: ((P = S.importCreateResult) == null ? void 0 : P.map(($) => ({
                  ...$.recipe,
                  errors: $.errors
                }))) || [],
                update: ((me = S.importUpdateResult) == null ? void 0 : me.map(($) => ({
                  ...$.recipe,
                  errors: $.errors
                }))) || []
              } : (ue = s.value) == null ? void 0 : ue.recipes
            });
            break;
          }
        }
        b.value.shift(), u.value = !0;
      } catch (L) {
        console.error(`Error processing ${m} sheet:`, L), g.open({
          title: e("inventory.common.processingError"),
          message: e("inventory.common.failedToProcessSheet", [m]),
          type: "error"
        });
      }
    }
    async function be() {
      var m, t, C, B, W, z, X, q, H, M, O, j, K, P, me, ue, L, S, $, Ue, Ne, Ge, Te, Me;
      if (s.value) {
        if (I.value) {
          g.open({
            title: e("inventory.common.invalidExcelFormatTitle"),
            message: ee.value,
            type: "error"
          });
          return;
        }
        if (w.value) {
          g.open({
            title: e("inventory.ingredient.import.error.invalidContent"),
            message: e("inventory.ingredient.import.error.hasErrors"),
            type: "error"
          });
          return;
        }
        l.value = !0;
        try {
          let V = 0, oe = "";
          if (s.value.units && ((m = s.value.units.create) != null && m.length || (t = s.value.units.update) != null && t.length)) {
            const T = {
              create: ((C = s.value.units.create) == null ? void 0 : C.filter((c) => !c.errors || c.errors.length === 0)) || [],
              update: ((B = s.value.units.update) == null ? void 0 : B.filter((c) => !c.errors || c.errors.length === 0)) || []
            };
            if (T.create.length || T.update.length) {
              const c = await x.importUnits(T);
              ((W = c == null ? void 0 : c.errors) == null ? void 0 : W.length) > 0 && d.value.push(...c.errors.map((re) => ({
                type: "units",
                error: re
              })));
              const te = T.create.length + T.update.length, ne = ((z = c == null ? void 0 : c.errors) == null ? void 0 : z.length) || 0;
              V = te - ne, oe = "units", s.value = {
                ...s.value,
                units: null
              };
            }
          } else if (s.value.skus && ((X = s.value.skus.create) != null && X.length || (q = s.value.skus.update) != null && q.length)) {
            const T = {
              create: ((H = s.value.skus.create) == null ? void 0 : H.filter((c) => !c.errors || c.errors.length === 0)) || [],
              update: ((M = s.value.skus.update) == null ? void 0 : M.filter((c) => !c.errors || c.errors.length === 0)) || []
            };
            if (T.create.length || T.update.length) {
              const c = await x.importSkus(T);
              ((O = c == null ? void 0 : c.errors) == null ? void 0 : O.length) > 0 && d.value.push(...c.errors.map((re) => ({
                type: "ingredients",
                error: re
              })));
              const te = T.create.length + T.update.length, ne = ((j = c == null ? void 0 : c.errors) == null ? void 0 : j.length) || 0;
              V = te - ne, oe = "ingredients", s.value = {
                ...s.value,
                skus: null
              };
            }
          } else if (s.value.recipes && ((K = s.value.recipes.create) != null && K.length || (P = s.value.recipes.update) != null && P.length)) {
            const T = {
              create: ((me = s.value.recipes.create) == null ? void 0 : me.filter((c) => !c.errors || c.errors.length === 0)) || [],
              update: ((ue = s.value.recipes.update) == null ? void 0 : ue.filter((c) => !c.errors || c.errors.length === 0)) || []
            };
            if (T.create.length || T.update.length) {
              const c = await x.importRecipes(T);
              ((L = c == null ? void 0 : c.errors) == null ? void 0 : L.length) > 0 && d.value.push(...c.errors.map((re) => ({
                type: "recipes",
                error: re
              })));
              const te = T.create.length + T.update.length, ne = ((S = c == null ? void 0 : c.errors) == null ? void 0 : S.length) || 0;
              V = te - ne, oe = "recipes", s.value = {
                ...s.value,
                recipes: null
              };
            }
          }
          if (V > 0) {
            const T = d.value.filter((c) => c.type === oe);
            T.length > 0 ? g.open({
              title: e("inventory.common.importCompletedWithIssues"),
              message: e("inventory.common.successfullyImported", [V, oe, T.length, oe]),
              type: "warning"
            }) : g.open({
              title: e("inventory.ingredient.import.success"),
              message: e("inventory.common.successfullyImported", [V, oe, "0", ""]),
              type: "success"
            });
          }
          if (b.value.length > 0)
            await ae();
          else if (!(s.value.units && ((($ = s.value.units.create) == null ? void 0 : $.length) || ((Ue = s.value.units.update) == null ? void 0 : Ue.length)) || s.value.skus && (((Ne = s.value.skus.create) == null ? void 0 : Ne.length) || ((Ge = s.value.skus.update) == null ? void 0 : Ge.length)) || s.value.recipes && (((Te = s.value.recipes.create) == null ? void 0 : Te.length) || ((Me = s.value.recipes.update) == null ? void 0 : Me.length))))
            if (le(), d.value.length > 0) {
              const c = d.value.filter((de) => de.type === "units").length, te = d.value.filter((de) => de.type === "ingredients").length, ne = d.value.filter((de) => de.type === "recipes").length, re = c + te + ne;
              o.value = !0, g.open({
                title: e("inventory.common.importCompletedWithIssues"),
                message: e("inventory.common.importFinishedWithFailedItems", [re, c, te, ne]),
                type: "warning"
              }), console.error("Import errors:", d.value);
            } else
              g.open({
                title: e("inventory.common.importComplete"),
                message: e("inventory.common.allDataSuccessfullyImported"),
                type: "success"
              });
        } catch (V) {
          g.open({
            title: e("inventory.ingredient.import.error.failed"),
            message: (V == null ? void 0 : V.message) || e("inventory.common.unknownErrorOccurred"),
            type: "error"
          }), console.error("Error during import:", V);
        } finally {
          l.value = !1;
        }
      }
    }
    function le() {
      u.value = !1, o.value = !1, s.value = null, b.value = [], f.value = null;
    }
    function he() {
      o.value = !1, d.value = [];
    }
    function xe() {
      p.value = !1, v.value = null;
    }
    const _e = J(() => [
      {
        label: e("inventory.common.import"),
        value: "import",
        isPrimary: !1,
        prependIcon: "upload"
      }
    ]), we = $e([
      {
        id: "name",
        accessorKey: "name",
        header: () => e("inventory.common.name"),
        size: 200
      },
      {
        id: "type",
        accessorKey: "type",
        header: () => e("inventory.common.type"),
        size: 120
      },
      {
        id: "operation",
        accessorKey: "operation",
        header: () => e("inventory.common.operation"),
        size: 100
      },
      {
        id: "status",
        accessorKey: "status",
        header: () => e("inventory.common.status"),
        size: 120,
        cell: (m) => {
          const t = m.row.original.status;
          let C = "px-8 py-4 rounded";
          return t === e("inventory.common.readyToImport") ? C += " bg-blue-100 text-blue-800 border border-blue-200" : t === "Imported" || t === "Successfully Imported" ? C += " bg-green-100 text-green-800 border border-green-200" : t === "Failed" ? C += " bg-red-100 text-red-800 border border-red-200" : t === e("inventory.common.validationFailed") ? C += " bg-orange-100 text-orange-800 border border-orange-200" : (t.includes("Invalid Excel"), C += " bg-red-100 text-red-800 border border-red-200"), Ie("div", { class: C, title: t }, t);
        }
      }
    ]), Se = $e([
      {
        id: "name",
        accessorKey: "name",
        header: () => e("inventory.common.name"),
        cell: (m) => Ie("div", { class: "text-gray-800 text-sm py-2" }, m.row.original.name || e("inventory.common.unknown"))
      },
      {
        id: "type",
        accessorKey: "type",
        header: () => e("inventory.common.errorType"),
        cell: (m) => {
          const t = m.row.original.type, C = e(t === "units" ? "inventory.common.unit" : t === "ingredients" ? "inventory.common.ingredient" : t === "recipes" ? "inventory.common.recipe" : "inventory.common.unknown");
          return Ie("div", { class: "text-gray-800 text-sm py-2" }, C);
        }
      },
      {
        id: "message",
        accessorKey: "message",
        header: () => e("inventory.common.errorMessage"),
        cell: (m) => Ie(
          "div",
          { class: "text-red-800 text-sm py-2", title: m.row.original.message },
          m.row.original.message
        )
      }
    ]);
    return (m, t) => {
      const C = Y("FmIcon"), B = Y("FmButton"), W = Y("FmTable"), z = Y("FmCard"), X = Y("FmSideSheet"), q = Y("FmSpinner");
      return i(h).isLoaded && i(h).enableBulkImport ? (G(), se(ke, {
        key: 0,
        title: i(e)("inventory.common.import"),
        actions: _e.value,
        "onClick:action": ye
      }, {
        default: Q(() => {
          var H;
          return [
            n("div", {
              class: ce([
                "flex flex-col gap-8 max-h-full",
                {
                  "p-0": y.value,
                  "px-24": !y.value
                }
              ])
            }, [
              u.value ? Z("", !0) : (G(), D("div", kt, [
                n("div", Rt, [
                  A(C, {
                    name: "info",
                    class: "text-blue-600 mt-2"
                  }),
                  n("div", Ct, [
                    n("div", Ut, a(i(e)("inventory.ingredient.import.multiUploadTemplateInstruction")), 1),
                    n("div", Nt, [
                      n("div", Gt, [
                        n("strong", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.title")), 1)
                      ]),
                      t[39] || (t[39] = k(" 1. ")),
                      n("span", {
                        innerHTML: i(e)("inventory.ingredient.import.importInstructions.step1")
                      }, null, 8, Tt),
                      t[40] || (t[40] = n("br", null, null, -1)),
                      t[41] || (t[41] = k(" 2. ")),
                      n("span", {
                        innerHTML: i(e)("inventory.ingredient.import.importInstructions.step2")
                      }, null, 8, Mt),
                      t[42] || (t[42] = n("br", null, null, -1)),
                      k(" 3. " + a(i(e)("inventory.ingredient.import.importInstructions.step3")), 1),
                      t[43] || (t[43] = n("br", null, null, -1)),
                      k(" 4. " + a(i(e)("inventory.ingredient.import.importInstructions.step4")), 1),
                      t[44] || (t[44] = n("br", null, null, -1)),
                      t[45] || (t[45] = n("br", null, null, -1)),
                      n("div", $t, [
                        n("strong", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.title")), 1)
                      ]),
                      n("div", Ft, [
                        n("strong", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.title")), 1),
                        k(" " + a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.description")), 1),
                        t[1] || (t[1] = n("br", null, null, -1)),
                        t[2] || (t[2] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.col1")), 1),
                        t[3] || (t[3] = n("br", null, null, -1)),
                        t[4] || (t[4] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.col2")), 1),
                        t[5] || (t[5] = n("br", null, null, -1)),
                        t[6] || (t[6] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.col3")), 1),
                        t[7] || (t[7] = n("br", null, null, -1)),
                        t[8] || (t[8] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.col4")), 1),
                        t[9] || (t[9] = n("br", null, null, -1)),
                        t[10] || (t[10] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.col5")), 1),
                        t[11] || (t[11] = n("br", null, null, -1)),
                        t[12] || (t[12] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.col6")), 1)
                      ]),
                      n("div", At, [
                        n("strong", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.title")), 1),
                        k(" " + a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.description")), 1),
                        t[13] || (t[13] = n("br", null, null, -1)),
                        t[14] || (t[14] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.col1")), 1),
                        t[15] || (t[15] = n("br", null, null, -1)),
                        t[16] || (t[16] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.col2")), 1),
                        t[17] || (t[17] = n("br", null, null, -1)),
                        t[18] || (t[18] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.col3")), 1),
                        t[19] || (t[19] = n("br", null, null, -1)),
                        t[20] || (t[20] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.col4")), 1),
                        t[21] || (t[21] = n("br", null, null, -1)),
                        t[22] || (t[22] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.col5")), 1)
                      ]),
                      n("div", Dt, [
                        n("strong", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.title")), 1),
                        k(" " + a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.description")), 1),
                        t[23] || (t[23] = n("br", null, null, -1)),
                        t[24] || (t[24] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col1")), 1),
                        t[25] || (t[25] = n("br", null, null, -1)),
                        t[26] || (t[26] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col2")), 1),
                        t[27] || (t[27] = n("br", null, null, -1)),
                        t[28] || (t[28] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col3")), 1),
                        t[29] || (t[29] = n("br", null, null, -1)),
                        t[30] || (t[30] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col4")), 1),
                        t[31] || (t[31] = n("br", null, null, -1)),
                        t[32] || (t[32] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col5")), 1),
                        t[33] || (t[33] = n("br", null, null, -1)),
                        t[34] || (t[34] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col6")), 1),
                        t[35] || (t[35] = n("br", null, null, -1)),
                        t[36] || (t[36] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col7")), 1),
                        t[37] || (t[37] = n("br", null, null, -1)),
                        t[38] || (t[38] = k(" • ")),
                        n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col8")), 1)
                      ]),
                      n("div", Bt, [
                        n("strong", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.warning")), 1)
                      ])
                    ])
                  ])
                ])
              ])),
              u.value ? (G(), D("div", Pt, [
                n("div", jt, [
                  n("div", null, [
                    n("div", Ot, a(i(e)("inventory.common.importPreview")), 1),
                    n("div", Ht, [
                      I.value ? (G(), D("span", zt, a(i(e)("inventory.common.errorExist")) + ": " + a(ee.value), 1)) : w.value ? (G(), D("span", Kt, a(i(e)("inventory.common.someItemsValidationErrors")), 1)) : (G(), D("span", Vt, a(i(e)("inventory.common.allItemsValidReadyImport")), 1))
                    ])
                  ]),
                  n("div", Wt, [
                    A(B, {
                      variant: "secondary",
                      onClick: le,
                      label: i(e)("inventory.common.cancel")
                    }, null, 8, ["label"]),
                    A(B, {
                      variant: "primary",
                      onClick: be,
                      loading: l.value,
                      disabled: l.value || w.value || I.value,
                      label: i(e)("inventory.common.import")
                    }, null, 8, ["loading", "disabled", "label"])
                  ])
                ]),
                n("div", Lt, [
                  A(W, {
                    "column-defs": we.value,
                    "row-data": N.value,
                    "page-size": _.value,
                    "search-value": r.value,
                    loading: !1,
                    "row-hover": ""
                  }, null, 8, ["column-defs", "row-data", "page-size", "search-value"])
                ])
              ])) : Z("", !0),
              o.value && d.value.length > 0 ? (G(), D("div", Jt, [
                n("div", Xt, [
                  n("div", null, [
                    n("div", qt, a(i(e)("inventory.common.importErrors")), 1),
                    n("div", Qt, a(d.value.length) + " " + a(i(e)("inventory.common.itemsFailedImport")), 1)
                  ]),
                  n("div", Yt, [
                    A(B, {
                      variant: "secondary",
                      onClick: he,
                      label: i(e)("inventory.common.close")
                    }, null, 8, ["label"])
                  ])
                ]),
                n("div", Zt, [
                  A(W, {
                    "column-defs": Se.value,
                    "row-data": ve.value,
                    "page-size": _.value,
                    "search-value": r.value,
                    loading: !1,
                    "row-hover": ""
                  }, null, 8, ["column-defs", "row-data", "page-size", "search-value"])
                ])
              ])) : Z("", !0)
            ], 2),
            A(X, {
              "model-value": p.value,
              "onUpdate:modelValue": t[0] || (t[0] = (M) => p.value = M),
              header: `${(H = v.value) == null ? void 0 : H.type} Details`,
              "max-width": 600,
              "dismiss-away": ""
            }, {
              "side-sheet-footer": Q(() => [
                n("div", xn, [
                  A(B, {
                    label: i(e)("inventory.common.close"),
                    variant: "tertiary",
                    onClick: xe
                  }, null, 8, ["label"])
                ])
              ]),
              default: Q(() => [
                v.value != null ? (G(), D("div", en, [
                  A(z, {
                    variant: "outlined",
                    class: "p-16"
                  }, {
                    default: Q(() => {
                      var M, O, j, K, P;
                      return [
                        n("div", tn, a(i(e)("inventory.common.basicInformation")), 1),
                        n("div", nn, [
                          n("div", null, [
                            n("div", on, a(i(e)("inventory.common.name")), 1),
                            n("div", rn, a(((O = (M = v.value) == null ? void 0 : M.details) == null ? void 0 : O.name) || ((j = v.value) == null ? void 0 : j.name)), 1)
                          ]),
                          (P = (K = v.value) == null ? void 0 : K.details) != null && P.code ? (G(), D("div", sn, [
                            n("div", an, a(i(e)("inventory.common.code")), 1),
                            n("div", ln, a(v.value.details.code), 1)
                          ])) : Z("", !0),
                          n("div", null, [
                            n("div", mn, a(i(e)("inventory.common.type")), 1),
                            n("div", un, a(v.value.type), 1)
                          ]),
                          n("div", null, [
                            n("div", dn, a(i(e)("inventory.common.operation")), 1),
                            n("div", cn, a(v.value.operation), 1)
                          ]),
                          n("div", null, [
                            n("div", pn, a(i(e)("inventory.common.status")), 1),
                            n("div", {
                              class: ce([
                                "inline-block px-8 py-4 rounded text-sm",
                                v.value.status !== i(e)("inventory.common.readyToImport") ? "bg-red-100 text-red-800 border border-red-200" : "bg-green-100 text-green-800 border border-green-200"
                              ])
                            }, a(v.value.status), 3)
                          ])
                        ])
                      ];
                    }),
                    _: 1
                  }),
                  v.value.errors && v.value.errors.length > 0 ? (G(), se(z, {
                    key: 0,
                    variant: "outlined",
                    class: "p-16"
                  }, {
                    default: Q(() => [
                      n("div", vn, a(i(e)("inventory.common.validationErrors")), 1),
                      n("div", yn, [
                        (G(!0), D(Be, null, Pe(v.value.errors, (M, O) => (G(), D("div", {
                          key: O,
                          class: "flex items-start gap-8 p-12 bg-red-50 border border-red-200 rounded"
                        }, [
                          A(C, {
                            name: "error",
                            class: "text-red-600 mt-2",
                            size: "sm"
                          }),
                          n("div", gn, a(M), 1)
                        ]))), 128))
                      ])
                    ]),
                    _: 1
                  })) : Z("", !0),
                  A(z, {
                    variant: "outlined",
                    class: "p-16"
                  }, {
                    default: Q(() => [
                      n("div", fn, a(i(e)("inventory.common.rawData")), 1),
                      n("div", bn, [
                        n("pre", hn, a(JSON.stringify(v.value.details, null, 2)), 1)
                      ])
                    ]),
                    _: 1
                  })
                ])) : Z("", !0)
              ]),
              _: 1
            }, 8, ["model-value", "header"])
          ];
        }),
        _: 1
      }, 8, ["title", "actions"])) : i(h).isLoaded ? (G(), se(ke, {
        key: 2,
        title: i(e)("inventory.common.import")
      }, {
        default: Q(() => [
          n("div", En, [
            A(C, {
              name: "block",
              class: "text-gray-400",
              size: "xl"
            }),
            n("div", Sn, [
              n("div", kn, a(i(e)("inventory.common.featureNotAvailable")), 1),
              n("div", Rn, a(i(e)("inventory.common.bulkImportNotEnabled")), 1)
            ])
          ])
        ]),
        _: 1
      }, 8, ["title"])) : (G(), se(ke, {
        key: 1,
        title: i(e)("inventory.common.import")
      }, {
        default: Q(() => [
          n("div", _n, [
            A(q, { size: "lg" }),
            n("div", wn, [
              n("div", In, a(i(e)("inventory.common.loading")), 1)
            ])
          ])
        ]),
        _: 1
      }, 8, ["title"]));
    };
  }
});
export {
  Hn as default
};
