import { defineComponent as ae, onMounted as Te, computed as B, ref as H, watch as Fe, inject as ot, resolveComponent as R, openBlock as O, createElementBlock as L, createElementVNode as t, createVNode as b, withCtx as N, renderSlot as Ue, withDirectives as Pe, normalizeClass as le, vModelText as Be, reactive as st, h as Q, toDisplayString as M, unref as e, createCommentVNode as oe, Fragment as pe, normalizeStyle as _e, renderList as Qe, createBlock as ne, mergeProps as Ye, createTextVNode as re, mergeModels as Le, useModel as nt, isRef as He, Teleport as lt, normalizeProps as rt, guardReactiveProps as at } from "vue";
import { u as it, _ as ut } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-sUxHOj47.js";
import { useI18n as me } from "@feedmepos/mf-common";
import { f as dt, t as mt, u as Ne, a as pt } from "./format-unit-display-CR_I8nfG.js";
import { R as Ee } from "./row-action.enum-DQ9bJ_uv.js";
import { a as We, q as ct, r as X, u as Ge, s as ft, j as ye } from "./app-Bpb4394e.js";
import { _ as yt } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-j3aDZ2cT.js";
import { components as ue, useSnackbar as vt, useProxiedModel as Ke, useBreakpoints as bt } from "@feedmepos/ui-library";
import { defineStore as ht, storeToRefs as ze } from "pinia";
import { F as de } from "./form-mode.enum-BKiNVH6A.js";
import { I as gt, a as xt, R as ke, A as we, M as _t } from "./rules-CoimOM7X.js";
import { u as ge, t as je, b as kt, n as wt, a as se, g as be, c as ve, d as Tt } from "./number-BVg7EKPV.js";
import { d as Ze } from "./defineDeepModel-BF0Cvhza.js";
import { _ as Ft, F as Ct, a as It, b as Mt } from "./FmUnitInput.vue_vue_type_script_setup_true_lang-Mic67Qjt.js";
import { u as he } from "./feature-Cz6F0_cm.js";
import { u as Je } from "./netsuite-BGUUAOqe.js";
import { F as xe } from "./inventory-core-dart.default-DanfWZQm.js";
import { u as St } from "./supplier-Bu6V24R6.js";
import { u as Ot } from "./use-ingredient-select-dialog-WYM92c37.js";
import { F as ee, _ as Xe } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-Ca_eYa8-.js";
import { u as $t } from "./use-template-enabled-locations-Puw8RG4I.js";
import { u as Dt } from "./use-transfer-locations-B0o32Kyf.js";
import { _ as Vt } from "./FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-CtFewq-W.js";
import { u as At } from "./purchase-order-template-BBNXnta7.js";
import { _ as Rt } from "./FmConfirmationButton.vue_vue_type_script_setup_true_lang-DLrMEGFR.js";
import { f as qt } from "./format-time-from-id-BvLCC6cK.js";
import { f as Ut } from "./date2-DpnYOzUg.js";
const Pt = { class: "flex flex-col" }, Bt = { class: "flex flex-col" }, Lt = { class: "flex-1" }, Nt = { class: "flex items-center" }, Et = { class: "flex-1" }, zt = { class: "flex-1" }, jt = /* @__PURE__ */ ae({
  __name: "FmMinMaxInput",
  props: {
    rules: {},
    label: {},
    minPlaceholder: {},
    maxPlaceholder: {},
    modelValue: {},
    precision: {},
    minLength: {},
    maxLength: {},
    inputmode: {},
    type: {},
    readonly: { type: Boolean },
    labelMark: {},
    prependIcon: {},
    appendIcon: {},
    showValidBorder: { type: Boolean },
    labelInfo: {},
    showWordCount: { type: Boolean },
    invalid: { type: Boolean },
    autofocus: { type: Boolean },
    formatter: { type: Function },
    decimal: {},
    datalist: {},
    shiftDatalist: { type: Boolean },
    datalistMaxHeight: {},
    datalistMinHeight: {},
    offsetDatalist: {},
    datalistPlacement: {},
    datalistZIndex: {},
    datalistWidth: {},
    disabled: { type: Boolean },
    focused: { type: Boolean },
    helperText: {},
    helperState: {}
  },
  setup(f) {
    const x = f, h = Ze("modelValue"), r = gt();
    Te(() => {
      const { min: p, max: c } = h ?? {};
      if (!(!p || !c) && p.precision !== c.precision) {
        const w = Math.max(p.precision, c.precision), a = ge(p, w), v = ge(c, w);
        h.min = a, h.max = v;
      }
    });
    const i = B(() => {
      const { min: p, max: c } = h ?? {};
      return Math.max((p == null ? void 0 : p.precision) ?? 0, (c == null ? void 0 : c.precision) ?? 0, x.precision ?? 0);
    }), s = (p) => {
      if (!p) return "";
      const c = kt(p), w = i.value, a = ge(c, w);
      return wt(
        +se(a),
        a.precision
      );
    }, u = H(s(h.min)), _ = H(s(h.max));
    Fe([u, _], ([p, c]) => {
      const w = h ?? {}, a = r(p), v = r(c), S = i.value;
      if (p !== "" && a === !0) {
        const I = je(+p, S);
        w.min = I;
      } else
        w.min = null;
      if (c !== "" && v === !0) {
        const I = je(+c, S);
        w.max = I;
      } else
        w.max = null;
      h.min = w.min, h.max = w.max;
    });
    const $ = Symbol.for("fm:form-state"), y = ot($, null), o = B(() => x.disabled ?? (y == null ? void 0 : y.getDisabled()) ?? !1), d = H(), m = H(), k = H(!1), T = H(!1), A = B(() => k.value || T.value), q = B(() => [...[
      function() {
        return typeof r(u.value) == "string" || typeof r(_.value) == "string" ? "Must be a number" : !0;
      },
      function(w) {
        return !w || !w.min || !w.max ? !0 : +se(w.min) > +se(w.max) ? "Min must be less than or equal to max" : !0;
      }
    ], ...x.rules ?? []]);
    return (p, c) => {
      const w = R("FmLabel"), a = R("FmField"), v = R("FmFormGroup");
      return O(), L("div", Pt, [
        t("div", Bt, [
          t("div", Lt, [
            b(w, {
              label: p.label,
              disabled: p.disabled,
              required: p.labelMark === "required",
              optional: p.labelMark === "optional"
            }, null, 8, ["label", "disabled", "required", "optional"])
          ]),
          b(a, { focused: A.value }, {
            default: N(() => [
              t("div", Nt, [
                Ue(p.$slots, "prepend"),
                c[6] || (c[6] = t("div", { class: "text-fm-color-typo-secondary fm-typo-en-body-lg-400 pr-4" }, "Min.", -1)),
                t("div", Et, [
                  Pe(t("input", {
                    type: "text",
                    ref_key: "minInputRef",
                    ref: d,
                    onFocus: c[0] || (c[0] = () => k.value = !0),
                    onBlur: c[1] || (c[1] = () => k.value = !1),
                    "onUpdate:modelValue": c[2] || (c[2] = (S) => u.value = S),
                    class: le({
                      "fm-text-field--input fm-typo-en-body-lg-400": !0,
                      "text-fm-color-typo-primary": !o.value,
                      "text-fm-color-typo-disabled": o.value
                    })
                  }, null, 34), [
                    [Be, u.value]
                  ])
                ]),
                c[7] || (c[7] = t("div", { class: "block h-32 mx-4 w-[1px] bg-fm-color-neutral-gray-200" }, null, -1)),
                c[8] || (c[8] = t("div", { class: "text-fm-color-typo-secondary fm-typo-en-body-lg-400 pr-4" }, "Max.", -1)),
                t("div", zt, [
                  Pe(t("input", {
                    type: "text",
                    ref_key: "maxInputRef",
                    ref: m,
                    onFocus: c[3] || (c[3] = () => T.value = !0),
                    onBlur: c[4] || (c[4] = () => T.value = !1),
                    "onUpdate:modelValue": c[5] || (c[5] = (S) => _.value = S),
                    class: le({
                      "fm-text-field--input fm-typo-en-body-lg-400": !0,
                      "text-fm-color-typo-primary": !o.value,
                      "text-fm-color-typo-disabled": o.value
                    })
                  }, null, 34), [
                    [Be, _.value]
                  ])
                ]),
                Ue(p.$slots, "append")
              ])
            ]),
            _: 3
          }, 8, ["focused"])
        ]),
        b(v, {
          class: "flex-1",
          "model-value": p.modelValue,
          info: p.labelInfo,
          rules: q.value,
          "helper-text": p.helperText,
          "helper-state": p.helperState
        }, null, 8, ["model-value", "info", "rules", "helper-text", "helper-state"])
      ]);
    };
  }
});
function Qt({ min: f, max: x } = { min: !0, max: !0 }) {
  return function(r) {
    return !r || !r.min && f != !1 || !r.max && x != !1 ? "Required" : !0;
  };
}
function Yt(f, x) {
  return function(r) {
    return !r || !r.min || !r.max ? !0 : +se(r.min) < f ? `Must be between ${f} and ${x}` : +se(r.max) > x ? `Must be between ${f} and ${x}` : !0;
  };
}
function Ht(f) {
  const x = xt(f), h = se(f);
  return function(i) {
    const s = !(i != null && i.min) || x(i.min) === !0, u = !(i != null && i.max) || x(i.max) === !0;
    return !s && !u ? `Min & max must be a multiple of ${h}` : s ? u ? !0 : `Max must be a multiple of ${h}` : `Min must be a multiple of ${h}`;
  };
}
const et = ht("netsuite-custom-field-helper", () => {
  const f = Je();
  function x(h, r, i, s, u) {
    var y, o, d;
    if (!i) {
      u == null || u("Unit is not valid");
      return;
    }
    let _ = h.code;
    if (((y = h.measurement) == null ? void 0 : y.id) !== ((o = i.measurement) == null ? void 0 : o.id) && f.isEnabled) {
      const m = f.getItemCustomCode(r, (d = i.measurement) == null ? void 0 : d.id);
      m && (_ = m);
    }
    s({
      ...h,
      quantity: i.amount,
      measurement: i.measurement ?? null,
      code: _
    });
  }
  return {
    validateUnitInput: x
  };
});
var Y = /* @__PURE__ */ ((f) => (f.Code = "Code", f.Name = "Name", f.DefaultAmount = "DefaultAmount", f.Limit = "Limit", f.Step = "Step", f.Cost = "Cost", f.Delete = "Delete", f))(Y || {});
function Wt(f, x = {}) {
  const { t: h } = me(), r = We(), i = he(), s = st({}), u = et();
  Te(() => {
    for (const y of f.items) {
      if (!y.totalCost)
        continue;
      const { cost: o } = xe.calculateDefaultCost({
        item: y.sku,
        amount: y.quantity,
        measurement: y.measurement,
        overrides: {
          supplier: f.supplier
        },
        defaultCurrency: ct()
      }), d = y.totalCost ?? xe.reset();
      o ? s[y.sku._id] = o.amount !== d.amount || o.precision !== d.precision : s[y.sku._id] = !0;
    }
  });
  const _ = [
    {
      id: "Code",
      header: () => Q("div", { class: "flex-col" }, [
        Q("div", h("inventory.transfer.form.items.table.Code")),
        Q(
          "div",
          { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" },
          "(original code)"
        )
      ]),
      accessorKey: "code",
      size: 180,
      cell(y) {
        const o = y.row.original;
        return Q("div", [
          Q(ue.FmTextField, {
            modelValue: o.code,
            "onUpdate:modelValue": (d) => {
              f.updateItem({
                ...o,
                code: d
              });
            },
            helperText: o.sku.code,
            key: o.sku._id,
            rules: [ke()],
            labelMark: "required"
          })
        ]);
      },
      enableSorting: !1
    },
    {
      id: "Name",
      header: () => Q("div", { class: "flex-col" }, [
        Q("div", h("inventory.transfer.form.items.table.Name")),
        Q(
          "div",
          { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" },
          "(original name)"
        )
      ]),
      minSize: 300,
      cell(y) {
        const o = y.row.original;
        return Q("div", [
          Q(ue.FmTextField, {
            modelValue: o.name,
            "onUpdate:modelValue": (d) => {
              f.updateItem({
                ...o,
                name: d
              });
            },
            helperText: o.sku.name,
            key: o.sku._id,
            rules: [ke()],
            labelMark: "required"
          })
        ]);
      },
      enableSorting: !1
    },
    {
      id: "DefaultAmount",
      header: () => h("inventory.transfer.form.items.table.DefaultAmount"),
      minSize: 200,
      cell(y) {
        var A;
        const o = y.row.original, d = r.skuById[o.sku._id], m = r.unitById[(A = d.unit) == null ? void 0 : A._id], k = m.measurements.find((q) => {
          var p;
          return ((p = o.measurement) == null ? void 0 : p.id) === q.id;
        }), T = o.sku.unit._id !== d.unit._id || !m || o.measurement && !k;
        return Q(Ft, {
          style: {
            flex: "1 1 0%"
          },
          modelValue: {
            amount: o.quantity ?? { amount: 1, precision: 0 },
            // NOTE: leave this reading from row.sku.unit and row.measurement instead,
            measurement: o.measurement ?? (o.sku.unit._id !== d.unit._id ? { ...o.sku.unit, id: "", conversion: { amount: 1, precision: 0 } } : null)
          },
          disabled: f.disabled,
          key: o.sku._id,
          unit: m,
          "onUpdate:modelValue": (q) => {
            u.validateUnitInput(
              o,
              d,
              q,
              (p) => {
                f.updateItem({
                  ...o,
                  code: p.code,
                  quantity: p.quantity,
                  measurement: p.measurement
                });
              }
            );
          },
          rules: [
            Ct(o.quantityStep),
            ...+se(o.quantity) ? [
              It(
                +se(
                  o.minimumQuantity ?? {
                    amount: 1,
                    // NOTE: leave this reading from row.sku.unit and row.measurement instead,
                    precision: be(o.sku.unit, o.measurement)
                  }
                )
              )
            ] : [],
            Mt(
              o.maximumQuantity ? +se(o.maximumQuantity) : 1 / 0
            ),
            function(p) {
              return T ? "This item is no longer valid due to change in unit. Please reapply unit." : !0;
            }
          ],
          applyDefaultRules: !0
        });
      },
      enableSorting: !1
    },
    {
      id: "Limit",
      header: () => "Limit",
      // TODO: i18n,
      minSize: 280,
      cell(y) {
        const o = y.row.original;
        return Q(jt, {
          style: {
            flex: "1 1 0%"
          },
          modelValue: {
            min: o.minimumQuantity,
            max: o.maximumQuantity
          },
          disabled: f.disabled,
          key: o.sku._id,
          unit: o.sku.unit,
          "onUpdate:modelValue": (d) => {
            const m = { ...o };
            d != null && d.min ? m.minimumQuantity = d.min : m.minimumQuantity = null, d != null && d.max ? m.maximumQuantity = d.max : m.maximumQuantity = null, f.updateItem(m);
          },
          rules: [
            Qt({ max: !1 }),
            Ht(o.quantityStep),
            Yt(
              +se({
                amount: 0,
                precision: be(o.sku.unit, o.measurement)
              }),
              1 / 0
            )
          ],
          disableUnit: !0,
          applyDefaultRules: !0
        });
      }
    },
    {
      id: "Step",
      header: () => h("inventory.transfer.form.items.table.Step"),
      minSize: 100,
      cell(y) {
        const o = y.row.original;
        return Q(ue.FmTextField, {
          modelValue: se(o.quantityStep ?? xe.reset(), !1),
          key: o.sku._id,
          "onUpdate:modelValue": (d) => {
            f.updateItem({
              ...o,
              quantityStep: ve(+d)
            });
          },
          rules: [
            we({
              amount: 1,
              precision: be(o.sku.unit, o.measurement)
            }),
            _t(o.sku.unit, o.measurement)
          ]
        });
      },
      enableSorting: !1
    },
    {
      id: "Delete",
      header: "",
      cell(y) {
        const o = y.row.original;
        return Q("div", { class: "flex items-center" }, [
          i.usePurchaseOrderV2 ? Q(
            ue.FmTooltip,
            {
              zIndex: 50,
              placement: "left"
            },
            {
              default() {
                return Q(ue.FmButton, {
                  key: o.sku._id,
                  type: "button",
                  icon: "add_circle",
                  variant: "tertiary",
                  size: "md",
                  disabled: f.disabled,
                  onClick: async () => {
                    const d = {
                      id: crypto.randomUUID(),
                      sku: o.sku,
                      code: o.sku.code,
                      name: o.sku.name,
                      quantity: ve(1),
                      quantityStep: ve(1),
                      minimumQuantity: ve(1)
                    };
                    u.validateUnitInput(
                      d,
                      o.sku,
                      {
                        amount: d.quantity,
                        measurement: null
                      },
                      (m) => {
                        d.code = m.code;
                      }
                    ), f.duplicateItem(d);
                  }
                });
              },
              content() {
                return "Duplicate entry";
              }
            }
          ) : null,
          Q(ue.FmButton, {
            class: "delete-button",
            key: o.sku._id,
            type: "button",
            icon: "delete",
            variant: "tertiary",
            size: "md",
            disabled: f.disabled,
            onClick: () => {
              f.deleteItem(o);
            }
          })
        ]);
      },
      enableSorting: !1,
      size: 40,
      meta: {
        cellClass: "",
        headerClass: ""
      }
    }
  ];
  return {
    columnDefs: B(() => {
      const y = he(), o = [..._];
      if (Object.keys(x).length > 0)
        for (const [d, m] of Object.entries(x))
          o.splice(Number(d), 0, {
            ...m,
            id: d
          });
      return y.enableTotalCost && f.transferType === X.enum.purchase ? o : o.filter((d) => d.id !== "Cost");
    })
  };
}
const Gt = { class: "flex flex-col gap-8 py-16" }, Kt = { class: "flex items-center" }, Zt = { class: "flex-1 flex gap-1 items-center" }, Jt = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, Xt = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, eo = { class: "flex gap-8 w-full" }, to = { class: "flex-1 flex flex-col gap-4" }, oo = { class: "flex-1 flex flex-col gap-4" }, so = {
  key: 0,
  class: "flex gap-8 w-full"
}, no = { class: "flex-1 flex flex-col gap-4" }, lo = { class: "flex-1 flex flex-col gap-4" }, ro = { class: "flex gap-8 w-full" }, ao = { class: "flex-1 flex flex-col gap-4" }, io = /* @__PURE__ */ ae({
  __name: "TransferTemplateItem",
  props: {
    cellByColId: {},
    row: {}
  },
  setup(f) {
    const { t: x } = me();
    function h(r) {
      return r;
    }
    return (r, i) => {
      var u, _, $, y, o, d, m, k, T, A, q, p, c, w, a, v, S, I, g, W, te, E, U, Z, n, l, F, P, z, G;
      const s = R("FmLabel");
      return O(), L("div", Gt, [
        t("div", Kt, [
          t("div", Zt, [
            t("span", Jt, " (" + M(r.row.original.sku.code) + ") ", 1),
            t("span", Xt, M(r.row.original.sku.name), 1)
          ]),
          t("div", null, [
            b(e(ee), {
              render: ($ = (_ = (u = r.cellByColId.Delete) == null ? void 0 : u.column) == null ? void 0 : _.columnDef) == null ? void 0 : $.cell,
              props: (o = (y = r.cellByColId.Delete) == null ? void 0 : y.getContext) == null ? void 0 : o.call(y)
            }, null, 8, ["render", "props"])
          ])
        ]),
        t("div", eo, [
          t("div", to, [
            b(s, {
              label: e(x)(`inventory.transfer.form.items.table.${e(Y).Code}`)
            }, null, 8, ["label"]),
            b(e(ee), {
              render: (k = (m = (d = r.cellByColId[e(Y).Code]) == null ? void 0 : d.column) == null ? void 0 : m.columnDef) == null ? void 0 : k.cell,
              props: (A = (T = r.cellByColId[e(Y).Code]) == null ? void 0 : T.getContext) == null ? void 0 : A.call(T)
            }, null, 8, ["render", "props"]),
            i[0] || (i[0] = t("div", { class: "fm-typo-en-body-md-600 text-fm-color-primary" }, null, -1))
          ]),
          t("div", oo, [
            b(s, {
              label: e(x)(`inventory.transfer.form.items.table.${e(Y).Name}`)
            }, null, 8, ["label"]),
            b(e(ee), {
              render: (c = (p = (q = r.cellByColId[e(Y).Name]) == null ? void 0 : q.column) == null ? void 0 : p.columnDef) == null ? void 0 : c.cell,
              props: (a = (w = r.cellByColId[e(Y).Name]) == null ? void 0 : w.getContext) == null ? void 0 : a.call(w)
            }, null, 8, ["render", "props"]),
            i[1] || (i[1] = t("div", { class: "fm-typo-en-body-md-600 text-fm-color-primary" }, null, -1))
          ])
        ]),
        r.row.original ? (O(), L("div", so, [
          t("div", no, [
            b(s, {
              label: e(x)(`inventory.transfer.form.items.table.${e(Y).DefaultAmount}`)
            }, null, 8, ["label"]),
            b(e(ee), {
              render: (I = (S = (v = r.cellByColId[e(Y).DefaultAmount]) == null ? void 0 : v.column) == null ? void 0 : S.columnDef) == null ? void 0 : I.cell,
              props: (W = (g = r.cellByColId[e(Y).DefaultAmount]) == null ? void 0 : g.getContext) == null ? void 0 : W.call(g)
            }, null, 8, ["render", "props"]),
            i[2] || (i[2] = t("div", { class: "fm-typo-en-body-md-600 text-fm-color-primary" }, null, -1))
          ]),
          t("div", lo, [
            b(s, {
              label: e(x)(`inventory.transfer.form.items.table.${e(Y).Step}`)
            }, null, 8, ["label"]),
            b(e(ee), {
              render: (U = (E = (te = r.cellByColId[e(Y).Step]) == null ? void 0 : te.column) == null ? void 0 : E.columnDef) == null ? void 0 : U.cell,
              props: (n = (Z = r.cellByColId[e(Y).Step]) == null ? void 0 : Z.getContext) == null ? void 0 : n.call(Z)
            }, null, 8, ["render", "props"]),
            i[3] || (i[3] = t("div", { class: "fm-typo-en-body-md-600 text-fm-color-primary" }, null, -1))
          ])
        ])) : oe("", !0),
        t("div", ro, [
          t("div", ao, [
            b(s, {
              label: e(x)(`inventory.transfer.form.items.table.${e(Y).Limit}`)
            }, null, 8, ["label"]),
            b(e(ee), {
              render: (P = (F = (l = r.cellByColId[e(Y).Limit]) == null ? void 0 : l.column) == null ? void 0 : F.columnDef) == null ? void 0 : P.cell,
              props: (G = (z = r.cellByColId[e(Y).Limit]) == null ? void 0 : z.getContext) == null ? void 0 : G.call(z)
            }, null, 8, ["render", "props"]),
            i[4] || (i[4] = t("div", { class: "fm-typo-en-body-md-600 text-fm-color-primary" }, null, -1))
          ])
        ])
      ]);
    };
  }
}), uo = { class: "fm-typo-en-body-md-400 line-clamp-2 w-full" }, mo = { key: 0 }, po = ["colspan"], co = /* @__PURE__ */ ae({
  __name: "TransferTemplateItemTable",
  props: {
    row: {},
    disabled: { type: Boolean },
    errorMessage: {}
  },
  emits: ["update:item"],
  setup(f) {
    function x(h) {
      return h.column.columnDef.meta;
    }
    return (h, r) => (O(), L(pe, null, [
      t("tr", {
        class: "hover:bg-fm-color-opacity-sm border-b border-fm-color-neutral-gray-100",
        style: _e({ backgroundColor: h.errorMessage ? "#ffd6d6" : void 0 })
      }, [
        (O(!0), L(pe, null, Qe(h.row.getVisibleCells(), (i) => {
          var s, u, _, $, y;
          return O(), L("td", {
            key: i.id,
            class: le(["text-fm-color-typo-primary", ((s = x(i)) == null ? void 0 : s.cellClass) ?? "px-16", "py-2"]),
            style: _e({
              width: (u = x(i)) != null && u.width ? (_ = x(i)) == null ? void 0 : _.width : i.column.getSize() !== 0 ? `${i.column.getSize()}px` : void 0,
              maxWidth: ($ = x(i)) == null ? void 0 : $.maxWidth,
              textAlign: ((y = x(i)) == null ? void 0 : y.textAlign) ?? "left"
            })
          }, [
            t("span", uo, [
              b(e(ee), {
                props: i.getContext(),
                render: i.column.columnDef.cell
              }, null, 8, ["props", "render"])
            ])
          ], 6);
        }), 128))
      ], 4),
      h.errorMessage ? (O(), L("tr", mo, [
        t("td", {
          colspan: h.row.getVisibleCells().length,
          class: "text-red-600 px-16 py-2"
        }, M(h.errorMessage), 9, po)
      ])) : oe("", !0)
    ], 64));
  }
}), fo = { class: "flex flex-col gap-16" }, yo = { class: "flex flex-col gap-24" }, vo = { class: "flex flex-col gap-16" }, bo = { class: "flex items-center" }, ho = { class: "flex flex-col" }, go = { class: "flex flex-col gap-16" }, xo = { class: "flex gap-3" }, _o = { class: "flex-1 gap-8 fm-typo-en-title-sm-600" }, ko = {
  key: 0,
  class: "border rounded-sm px-8 py-2 bg-fm-color-system-warning-100 fm-typo-en-body-lg-400"
}, wo = { class: "border rounded-sm px-8 py-2 bg-fm-color-system-info-100 fm-typo-en-body-lg-400" }, To = { class: "mb-2" }, Fo = /* @__PURE__ */ ae({
  __name: "TransferTemplateForm",
  props: {
    modelValue: {},
    disabled: { type: Boolean }
  },
  emits: ["update:disabled"],
  setup(f, { expose: x, emit: h }) {
    const r = f, i = h, s = Ze(), { t: u } = me(), _ = H({}), $ = Ge(), y = We(), o = St(), d = he(), m = Je(), k = et();
    Fe(
      () => s.purchaseOrder.items.length,
      () => {
        _.value = {};
      }
    ), $.watchLocation(async () => {
      location && (s.purchaseOrder.supplier || (s.purchaseOrder.supplier = o.suppliers.find((n) => n) ?? s.purchaseOrder.supplier));
    });
    const T = Dt(
      () => s.purchaseOrder,
      (n) => {
        s.purchaseOrder = {
          ...s.purchaseOrder,
          supplier: n.supplier ?? (s == null ? void 0 : s.purchaseOrder.supplier)
        };
      }
    ), A = B({
      get() {
        var n, l;
        return typeof ((l = (n = s.purchaseOrder) == null ? void 0 : n.supplier) == null ? void 0 : l.internal) == "string" ? X.enum.transfer : X.enum.purchase;
      },
      set(n) {
        var F, P;
        const l = typeof ((P = (F = s.purchaseOrder) == null ? void 0 : F.supplier) == null ? void 0 : P.internal) == "string" ? X.enum.transfer : X.enum.purchase;
        n !== l && (s.purchaseOrder.supplier = n === X.enum.purchase ? T.locationOptionsTypePurchase.value[0] : T.locationOptionsTypeTransfer.value[0]);
      }
    }), q = B(() => T.transferLocationOptions.value), p = B({
      get() {
        var n;
        return (n = s.purchaseOrder.supplier) == null ? void 0 : n._id;
      },
      set(n) {
        T.transferLocationModel.value = n;
      }
    });
    async function c() {
      const n = await m.checkCustomFieldCodes({
        beforeStart: async () => {
          i("update:disabled", !0);
        },
        templateItems: s.purchaseOrder.items
      });
      _.value = n, i("update:disabled", !1);
    }
    const {
      promptSelectLocations: w,
      columnDefs: a,
      rowData: v
    } = $t({
      getLocations() {
        return s.locations;
      },
      setLocations(n) {
        s.locations = n;
      }
    });
    function S() {
      var n, l;
      return (n = s.locations) != null && n.find((F) => {
        var P, z;
        return ((P = F.doc) == null ? void 0 : P._id) === ((z = s.purchaseOrder.supplier) == null ? void 0 : z._id);
      }) ? `Location ${(l = s.purchaseOrder.supplier) == null ? void 0 : l.name} must be removed because template cannot be used to transfer to itself.` : !0;
    }
    const I = B({
      get() {
        return s.purchaseOrder.remark ?? void 0;
      },
      set(n) {
        s.purchaseOrder.remark = n;
      }
    }), g = H();
    x({
      validateInputs: () => {
        var n, l;
        (l = (n = g.value) == null ? void 0 : n.validateInputs) == null || l.call(n);
      },
      resetInputsValidation: () => {
        var n, l;
        (l = (n = g.value) == null ? void 0 : n.resetInputsValidation) == null || l.call(n);
      },
      resetInputs: () => {
        var n, l;
        (l = (n = g.value) == null ? void 0 : n.resetInputs) == null || l.call(n);
      }
    });
    const W = B(() => ({
      duplicateItem: (n) => {
        s.purchaseOrder.items = [
          ...s.purchaseOrder.items,
          {
            ...n
          }
        ];
      },
      updateItem: (n) => {
        let l = [];
        n.id ? l = s.purchaseOrder.items.map((F) => F.id !== n.id ? F : n) : l = s.purchaseOrder.items.map((F) => F.sku._id !== n.sku._id ? F : n), s.purchaseOrder.items = l;
      },
      deleteItem: (n) => {
        console.log(n.id);
        let l = [];
        n.id ? l = s.purchaseOrder.items.filter((F) => F.id !== n.id) : l = s.purchaseOrder.items.filter((F) => F.sku._id !== n.sku._id), s.purchaseOrder.items = l;
      }
    })), te = Wt(
      {
        duplicateItem: W.value.duplicateItem,
        updateItem: W.value.updateItem,
        deleteItem: W.value.deleteItem,
        get supplier() {
          return s.purchaseOrder.supplier;
        },
        get items() {
          return s.purchaseOrder.items;
        },
        get transferType() {
          return X.enum.purchase;
        },
        get disabled() {
          return r.disabled;
        }
      },
      m.transferTemplateColumnDefs({
        onUpdate: (n, l, F, P) => {
          if (n < 0 || n >= s.purchaseOrder.items.length) return;
          const z = s.purchaseOrder.items[n];
          z && W.value.updateItem({
            ...z,
            sku: l,
            // Sku might be outdated, so we need to update it
            code: F,
            measurement: P
          });
        }
      })
    ), E = B(() => te.columnDefs.value), { promptSelectIngredients: U } = Ot();
    async function Z() {
      const l = y.skus.map((D) => ({
        label: D.name,
        sublabel: D.code,
        value: D
      })).filter((D) => {
        var V;
        return (V = s.purchaseOrder.items) == null ? void 0 : V.find((K) => K.sku._id === D.value._id);
      }).map((D) => D.value), F = s.purchaseOrder.items ?? [], P = await U(
        l.map((D) => D._id),
        (D) => {
          const V = y.skuById[D], K = F.find((j) => j.sku._id === V._id);
          if (K)
            return K;
          const J = { amount: 1, precision: be(V.unit) };
          let C = {
            id: d.usePurchaseOrderV2 ? crypto.randomUUID() : void 0,
            sku: V,
            code: V.code,
            name: V.name,
            quantity: J,
            minimumQuantity: J,
            // maximumQuantity: adjustmentAmountMultiplyDecimal(minimumQuantity, {
            //   amount: 100,
            //   precision: 0
            // }),
            quantityStep: J
          };
          return k.validateUnitInput(
            C,
            V,
            {
              amount: J,
              measurement: null
            },
            (j) => {
              C.code = j.code;
            }
          ), C;
        }
      );
      if (!P) return;
      const z = P.map((D) => D.sku._id), G = [];
      for (const D of z) {
        const V = F.filter((K) => K.sku._id === D);
        if (V.length > 0)
          G.push(...V);
        else {
          const K = P.find((J) => J.sku._id === D);
          K && G.push(K);
        }
      }
      G.sort((D, V) => D.sku.code.localeCompare(V.sku.code)), s.purchaseOrder.items = G;
    }
    return (n, l) => {
      const F = R("FmTextField"), P = R("FmSelect"), z = R("FmTextarea"), G = R("FmButton"), D = R("FmTable"), V = R("FmFormGroup"), K = R("FmForm");
      return O(), ne(K, {
        ref_key: "formRef",
        ref: g,
        class: "flex flex-col gap-32",
        disabled: n.disabled
      }, {
        default: N(() => {
          var J;
          return [
            t("div", fo, [
              t("div", yo, [
                b(F, {
                  label: e(u)("inventory.transfer.form.name"),
                  "label-mark": "required",
                  modelValue: e(s).name,
                  "onUpdate:modelValue": l[0] || (l[0] = (C) => e(s).name = C),
                  rules: [e(ke)()]
                }, null, 8, ["label", "modelValue", "rules"]),
                b(P, {
                  label: e(u)("inventory.transfer.form.type.title"),
                  "model-value": A.value,
                  "onUpdate:modelValue": l[1] || (l[1] = (C) => A.value = C),
                  items: [
                    {
                      label: e(u)("inventory.transfer.form.type.purchase"),
                      value: e(X).enum.purchase,
                      disabled: !e(T).locationOptionsTypePurchase.value.length,
                      sublabel: e(T).locationOptionsTypePurchase.value.length ? void 0 : e(u)("inventory.transfer.form.noSupplierAvailable")
                    },
                    {
                      label: e(u)("inventory.transfer.form.type.transfer"),
                      value: e(X).enum.transfer,
                      disabled: !e(T).locationOptionsTypeTransfer.value.length,
                      sublabel: e(T).locationOptionsTypeTransfer.value.length ? void 0 : e(u)("inventory.transfer.form.noLocationAvailable")
                    }
                  ],
                  rules: [e(we)(1)(q.value)]
                }, {
                  default: N(() => [
                    t("span", {
                      class: le([
                        "line-clamp-1 fm-typo-en-body-lg-400",
                        n.disabled ? "text-fm-color-typo-disabled" : "text-fm-color-typo-primary"
                      ])
                    }, M(e(ft)(A.value)), 3)
                  ]),
                  _: 1
                }, 8, ["label", "model-value", "items", "rules"]),
                b(P, {
                  label: A.value === e(X).enum.purchase ? e(u)("inventory.transfer.form.purchaseFrom") : e(u)("inventory.transfer.form.transferFrom"),
                  modelValue: p.value,
                  "onUpdate:modelValue": l[2] || (l[2] = (C) => p.value = C),
                  items: q.value
                }, {
                  "menu-wrapper": N((C) => {
                    var j;
                    return [
                      b(Vt, Ye(C, {
                        items: q.value,
                        "model-value": (j = n.modelValue.purchaseOrder.supplier) == null ? void 0 : j._id
                      }), null, 16, ["items", "model-value"])
                    ];
                  }),
                  default: N(() => {
                    var C;
                    return [
                      t("span", {
                        class: le([
                          "line-clamp-1 fm-typo-en-body-lg-400",
                          n.disabled ? "text-fm-color-typo-disabled" : "text-fm-color-typo-primary"
                        ])
                      }, M((C = q.value.find((j) => j.value === p.value)) == null ? void 0 : C.label), 3)
                    ];
                  }),
                  _: 1
                }, 8, ["label", "modelValue", "items"]),
                b(F, {
                  label: e(u)("inventory.transfer.form.reference"),
                  "label-mark": "optional",
                  modelValue: e(s).purchaseOrder.ref,
                  "onUpdate:modelValue": l[3] || (l[3] = (C) => e(s).purchaseOrder.ref = C)
                }, null, 8, ["label", "modelValue"]),
                b(z, {
                  label: e(u)("inventory.transfer.form.remark"),
                  "label-mark": "optional",
                  "max-length": 240,
                  modelValue: I.value,
                  "onUpdate:modelValue": l[4] || (l[4] = (C) => I.value = C),
                  class: le({ "text-fm-color-typo-disabled": n.disabled })
                }, null, 8, ["label", "modelValue", "class"])
              ])
            ]),
            t("div", vo, [
              t("div", bo, [
                l[8] || (l[8] = t("div", { class: "flex-1 fm-typo-en-title-sm-600" }, "Locations", -1)),
                b(G, {
                  disabled: n.disabled,
                  label: "Select location",
                  "prepend-icon": "add",
                  variant: "plain",
                  class: "border-2 rounded-lg border-fm-color-primary",
                  onClick: e(w)
                }, null, 8, ["disabled", "onClick"])
              ]),
              b(D, {
                "column-defs": e(a),
                "row-data": e(v),
                "shrink-at": 9999,
                onRowClick: e(w),
                "hide-footer": ""
              }, null, 8, ["column-defs", "row-data", "onRowClick"]),
              t("div", ho, [
                b(V, {
                  "model-value": [
                    (J = r.modelValue.purchaseOrder.supplier) == null ? void 0 : J._id,
                    ...r.modelValue.locations ?? []
                  ].join(","),
                  rules: [S]
                }, null, 8, ["model-value", "rules"])
              ])
            ]),
            t("div", go, [
              t("div", xo, [
                t("div", _o, M(e(u)("inventory.transfer.form.items.title")), 1),
                e(m).isEnabled ? (O(), ne(G, {
                  key: 0,
                  label: "Check NetSuite",
                  "prepend-icon": "troubleshoot",
                  variant: "secondary",
                  onClick: c,
                  size: "md"
                })) : oe("", !0),
                b(G, {
                  disabled: n.disabled,
                  label: e(u)("inventory.transfer.form.items.addItem"),
                  "prepend-icon": "add",
                  variant: "plain",
                  class: "border-2 rounded-lg border-fm-color-primary",
                  onClick: l[5] || (l[5] = (C) => Z()),
                  size: "md"
                }, null, 8, ["disabled", "label"])
              ]),
              e(m).isEnabled ? (O(), L("div", ko, l[9] || (l[9] = [
                re(" NetSuite is enabled. "),
                t("ul", { style: { "list-style": "initial", "margin-left": "20px" } }, [
                  t("li", null, ' When adding new item or changing UOM, the first match available custom code (if any) will be applied to "Code" for each item by default. '),
                  t("li", null, ' You can also choose to change the code by selecting from the "NetSuite" button in each row. ')
                ], -1),
                t("p", { class: "fm-typo-en-body-lg-600 mt-2" }, " If you use custom code for certain items, please make sure that the custom code is correct before saving the template. ", -1)
              ]))) : oe("", !0),
              t("div", wo, [
                t("p", To, [
                  re(' Set "' + M(e(u)("inventory.transfer.form.items.table.DefaultAmount")) + '" to "0" to mark the item as ', 1),
                  l[10] || (l[10] = t("b", null, "optional", -1)),
                  l[11] || (l[11] = re(" when creating an order request. "))
                ]),
                l[12] || (l[12] = t("p", null, ' You can leave "Max" empty to remove the limit on the maximum quantity of the item when creating an order request. ', -1))
              ]),
              (O(), ne(D, {
                "column-defs": E.value,
                "row-data": e(s).purchaseOrder.items,
                key: e(s).purchaseOrder.items.map((C) => C.sku._id).join("."),
                "hide-footer": "",
                "page-size": e(s).purchaseOrder.items.length
              }, {
                "table-row": N((C) => [
                  b(co, {
                    row: C,
                    errorMessage: _.value[C.index],
                    "onUpdate:item": l[6] || (l[6] = (j) => W.value.updateItem(j)),
                    disabled: n.disabled
                  }, null, 8, ["row", "errorMessage", "disabled"])
                ]),
                "list-row": N((C) => [
                  (O(), ne(Xe, {
                    row: C,
                    key: e(s).purchaseOrder.items.map((j) => j.sku._id).join(".")
                  }, {
                    default: N((j) => [
                      b(io, {
                        row: C,
                        "cell-by-col-id": j,
                        "onUpdate:item": l[7] || (l[7] = (ie) => W.value.updateItem(ie)),
                        disabled: n.disabled
                      }, null, 8, ["row", "cell-by-col-id", "disabled"])
                    ]),
                    _: 2
                  }, 1032, ["row"]))
                ]),
                _: 1
              }, 8, ["column-defs", "row-data", "page-size"])),
              b(V, {
                "model-value": e(s).purchaseOrder.items.length,
                rules: [e(we)(1)]
              }, null, 8, ["model-value", "rules"])
            ])
          ];
        }),
        _: 1
      }, 8, ["disabled"]);
    };
  }
}), Co = { class: "flex items-center" }, Io = { class: "fm-typo-en-title-md-800" }, Mo = { class: "flex gap-4" }, So = /* @__PURE__ */ ae({
  __name: "TransferTemplateDialog",
  props: /* @__PURE__ */ Le({
    mode: {},
    modelValue: {},
    show: { type: Boolean }
  }, {
    disabled: { type: Boolean },
    disabledModifiers: {}
  }),
  emits: /* @__PURE__ */ Le(["update:show", "submitted"], ["update:disabled"]),
  setup(f, { expose: x, emit: h }) {
    var w;
    const r = f, i = h, s = At(), u = vt(), { t: _ } = me(), $ = Ke(r, "show");
    function y() {
      return {
        _id: "",
        name: "",
        purchaseOrder: {
          remark: void 0,
          ref: void 0,
          items: [],
          supplier: {
            _rev: void 0,
            email: void 0,
            internal: void 0,
            contactName: void 0,
            phoneNumber: void 0,
            registrationNumber: void 0,
            supplyItems: void 0,
            _id: "",
            name: "",
            address: {
              line2: void 0,
              line1: "",
              state: "",
              city: "",
              postcode: "",
              country: ""
            }
          }
        }
      };
    }
    const o = H(r.modelValue ?? y()), d = H(((w = r.modelValue) == null ? void 0 : w._id) ?? `${Math.random()}`);
    Fe(
      () => r.show,
      (a) => {
        var v;
        a && (o.value = r.modelValue ?? y(), d.value = ((v = r.modelValue) == null ? void 0 : v._id) ?? `${Math.random()}`);
      }
    );
    const m = nt(f, "disabled"), k = B(() => {
      switch (r.mode) {
        case de.READ:
          return "";
        case de.CREATE:
          return _("inventory.transfer.template.create.title");
        case de.UPDATE:
          return _("inventory.transfer.template.update.title");
      }
      return "";
    }), T = H();
    x({
      validateInputs: () => {
        var a, v;
        (v = (a = T.value) == null ? void 0 : a.validateInputs) == null || v.call(a);
      },
      resetInputsValidation: () => {
        var a, v;
        (v = (a = T.value) == null ? void 0 : a.resetInputsValidation) == null || v.call(a);
      },
      resetInputs: () => {
        var a, v;
        (v = (a = T.value) == null ? void 0 : a.resetInputs) == null || v.call(a);
      }
    });
    async function A() {
      var v, S;
      const a = o.value;
      if (a) {
        m.value = !0, (((v = a.purchaseOrder.supplier) == null ? void 0 : v.internal) === ye.enum.warehouse || ((S = a.purchaseOrder.supplier) == null ? void 0 : S.internal) === ye.enum.restaurant) && (a.purchaseOrder.items = a.purchaseOrder.items.map(
          ({ totalCost: I, ...g }) => g
        ));
        try {
          await s.createTemplate(a), await new Promise((I) => setTimeout(I, 1e3)), u.open({
            title: _("inventory.transfer.template.create.success"),
            message: _("inventory.transfer.template.create.successMessage"),
            type: "success"
          }), i("update:show", !1), i("submitted");
        } catch (I) {
          u.open({
            title: _("inventory.transfer.template.create.error"),
            message: _("inventory.transfer.template.create.errorMessage"),
            type: "error"
          }), console.error("Error in creating transfer template", I);
        } finally {
          m.value = !1;
        }
      }
    }
    async function q() {
      var v, S;
      const a = o.value;
      if (a) {
        m.value = !0, (((v = a.purchaseOrder.supplier) == null ? void 0 : v.internal) === ye.enum.warehouse || ((S = a.purchaseOrder.supplier) == null ? void 0 : S.internal) === ye.enum.restaurant) && (a.purchaseOrder.items = a.purchaseOrder.items.map(
          ({ totalCost: I, ...g }) => g
        ));
        try {
          await s.updateTemplate(a), await new Promise((I) => setTimeout(I, 1e3)), u.open({
            title: _("inventory.transfer.template.update.success"),
            message: _("inventory.transfer.template.update.successMessage"),
            type: "success"
          }), i("update:show", !1), i("submitted");
        } catch (I) {
          u.open({
            title: _("inventory.transfer.template.update.error"),
            message: _("inventory.transfer.template.update.errorMessage"),
            type: "error"
          }), console.error("Error in updating transfer template", I);
        } finally {
          m.value = !1;
        }
      }
    }
    function p() {
      switch (r.mode) {
        case de.CREATE:
          return A();
        case de.UPDATE:
          return q();
      }
    }
    function c() {
      var a, v;
      (v = (a = T.value) == null ? void 0 : a.validateInputs) == null || v.call(a);
    }
    return (a, v) => {
      const S = R("FmButton"), I = R("FmSideSheet");
      return O(), ne(I, {
        modelValue: e($),
        "onUpdate:modelValue": v[3] || (v[3] = (g) => He($) ? $.value = g : null),
        "dismiss-away": "",
        "close-button": "",
        "max-width": 1600
      }, {
        "side-sheet-header": N(() => [
          t("div", Co, [
            t("div", Io, M(k.value), 1)
          ])
        ]),
        default: N(() => [
          (O(), ne(Fo, {
            class: "w-full",
            ref_key: "formRef",
            ref: T,
            onValidationSuccess: p,
            "model-value": o.value,
            "onUpdate:modelValue": v[0] || (v[0] = (g) => o.value = g),
            disabled: m.value,
            "onUpdate:disabled": v[1] || (v[1] = (g) => m.value = g),
            key: d.value
          }, null, 8, ["model-value", "disabled"]))
        ]),
        "side-sheet-footer": N(() => [
          t("div", Mo, [
            b(Rt, {
              loading: m.value,
              label: e(_)("common.save"),
              "confirm-title": `Save ${r.mode === e(de).CREATE ? "Template" : "Changes"}`,
              onConfirm: c
            }, {
              "dialog-content": N(() => v[4] || (v[4] = [
                t("div", { class: "fm-typo-en-body-md-400 bg-fm-color-primary-oats p-8 rounded" }, [
                  re(" Warning: This action "),
                  t("span", { class: "text-fm-color-system-error-300" }, "will not"),
                  re(" create or update any order request, but only a template. ")
                ], -1)
              ])),
              _: 1
            }, 8, ["loading", "label", "confirm-title"]),
            b(S, {
              disabled: m.value,
              variant: "tertiary",
              label: e(_)("common.close"),
              onClick: v[2] || (v[2] = (g) => i("update:show", !1))
            }, null, 8, ["disabled", "label"])
          ])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
}), Oo = { class: "flex flex-col gap-16 w-full h-full overflow-y-auto" }, $o = { class: "flex justify-between" }, Do = { class: "fm-typo-en-body-lg-600" }, Vo = { class: "fm-status-badge fm-status-badge-info-secondary" }, Ao = { class: "flex flex-col gap-8" }, Ro = { class: "flex flex-col gap-4" }, qo = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Uo = { class: "flex gap-1" }, Po = { class: "fm-typo-en-body-lg-600" }, Bo = {
  key: 0,
  class: "flex flex-col gap-4"
}, Lo = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, No = { class: "flex gap-1" }, Eo = { class: "fm-typo-en-body-lg-600" }, zo = {
  key: 1,
  class: "flex flex-col gap-4"
}, jo = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Qo = { class: "fm-typo-en-body-lg-600" }, Yo = {
  key: 2,
  class: "flex flex-col gap-4"
}, Ho = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Wo = { class: "fm-typo-en-body-lg-600" }, Go = {
  key: 3,
  class: "flex flex-col gap-4"
}, Ko = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Zo = { class: "fm-typo-en-body-lg-600" }, Jo = { class: "border border-fm-color-neutral-gray-200 fm-corner-radius-lg p-16" }, Xo = { class: "flex flex-col gap-8" }, es = { class: "fm-typo-en-body-lg-600" }, ts = { class: "flex w-full gap-4" }, os = { class: "grow fm-typo-en-body-lg-400 line-clamp-2" }, ss = { class: "fm-typo-en-body-lg-600 shrink-0" }, ns = { class: "flex w-full gap-4 fm-typo-en-body-sm-400" }, ls = { class: "grow fm-typo-en-body-lg-400 text-fm-color-typo-secondary line-clamp-2" }, rs = {
  key: 0,
  class: "shrink-0 fm-typo-en-body-lg-400 text-fm-color-typo-secondary"
}, as = {
  key: 0,
  class: "flex gap-4 items-center"
}, is = { class: "flex flex-col gap-12" }, us = { class: "flex flex-col gap-8" }, ds = { class: "flex gap-8 xs:flex-col" }, ms = /* @__PURE__ */ ae({
  __name: "TransferTemplateDetails",
  props: {
    template: {},
    show: { type: Boolean }
  },
  emits: ["update:show", "action:edit"],
  setup(f, { emit: x }) {
    const h = f, r = x, i = he(), { t: s } = me(), u = B(() => {
      var m;
      return (m = h.template) == null ? void 0 : m.purchaseOrder;
    }), _ = [
      { accessorKey: "name", header: () => "Name" },
      { accessorKey: "type", header: () => "Type" }
    ], $ = H(""), y = B(
      () => {
        var m, k, T, A;
        return ((k = (m = u.value) == null ? void 0 : m.supplier) == null ? void 0 : k.internal) === "restaurant" || ((A = (T = u.value) == null ? void 0 : T.supplier) == null ? void 0 : A.internal) === "warehouse" ? X.enum.transfer : X.enum.purchase;
      }
    ), o = H(!0), d = Ke(h, "show");
    return (m, k) => {
      var v;
      const T = R("FmMenuDivider"), A = R("FmCard"), q = R("FmIcon"), p = R("FmTextField"), c = R("FmTable"), w = R("FmButton"), a = R("FmSideSheet");
      return O(), ne(a, {
        header: e(s)("inventory.transfer.template.details.view", { template: (v = m.template) == null ? void 0 : v.name }),
        modelValue: e(d),
        "onUpdate:modelValue": k[2] || (k[2] = (S) => He(d) ? d.value = S : null),
        "dismiss-away": o.value,
        "close-button": "",
        "max-width": 1200
      }, {
        default: N(() => {
          var S, I;
          return [
            t("div", Oo, [
              t("div", null, [
                b(A, {
                  variant: "outlined",
                  class: "flex flex-col gap-8 px-12 py-16"
                }, {
                  default: N(() => {
                    var g, W, te, E, U, Z, n, l, F;
                    return [
                      t("div", $o, [
                        t("div", Do, M(e(s)("inventory.transfer.template.details.templateSummary")), 1),
                        t("div", Vo, M(e(s)(
                          `inventory.transfer.receiveRequest.details.type.${y.value.toLocaleLowerCase("en-US")}`
                        )), 1)
                      ]),
                      b(T),
                      t("div", Ao, [
                        t("div", Ro, [
                          t("div", qo, [
                            t("div", Uo, M(e(s)("inventory.transfer.receiveRequest.details.createdAt")), 1)
                          ]),
                          t("div", Po, M(e(qt)(((g = m.template) == null ? void 0 : g._id) ?? "")), 1)
                        ]),
                        (W = m.template) != null && W.updatedAt ? (O(), L("div", Bo, [
                          t("div", Lo, [
                            t("div", No, M(e(s)("inventory.transfer.receiveRequest.details.updatedAt")), 1)
                          ]),
                          t("div", Eo, [
                            re(M(e(Ut)(new Date(m.template.updatedAt))) + " ", 1),
                            (te = m.template.updatedBy) != null && te.name ? (O(), L(pe, { key: 0 }, [
                              re(" (" + M(m.template.updatedBy.name) + ") ", 1)
                            ], 64)) : oe("", !0)
                          ])
                        ])) : oe("", !0),
                        (U = (E = u.value) == null ? void 0 : E.supplier) != null && U.name ? (O(), L("div", zo, [
                          t("div", jo, M(e(s)("inventory.transfer.receiveRequest.details.from")), 1),
                          t("div", Qo, M((n = (Z = u.value) == null ? void 0 : Z.supplier) == null ? void 0 : n.name), 1)
                        ])) : oe("", !0),
                        (l = u.value) != null && l.ref ? (O(), L("div", Yo, [
                          t("div", Ho, M(e(s)("inventory.transfer.receiveRequest.details.reference")), 1),
                          t("div", Wo, M(u.value.ref), 1)
                        ])) : oe("", !0),
                        (F = u.value) != null && F.remark ? (O(), L("div", Go, [
                          t("div", Ko, M(e(s)("inventory.transfer.receiveRequest.details.remark")), 1),
                          t("div", Zo, M(u.value.remark), 1)
                        ])) : oe("", !0)
                      ])
                    ];
                  }),
                  _: 1
                })
              ]),
              t("div", Jo, [
                t("div", Xo, [
                  t("div", es, M(e(s)("inventory.transfer.receiveRequest.details.requestedItems")), 1),
                  (O(!0), L(pe, null, Qe(((S = u.value) == null ? void 0 : S.items) ?? [], (g) => (O(), L("div", {
                    key: g.code,
                    class: "flex flex-col"
                  }, [
                    t("div", ts, [
                      t("div", os, M(g.name), 1),
                      k[3] || (k[3] = t("div", { class: "flex-1 min-w-32" }, null, -1)),
                      t("div", ss, M(e(dt)(g.quantity, g.sku.unit, g.measurement)), 1)
                    ]),
                    t("div", ns, [
                      t("div", ls, M(g.code), 1),
                      g.totalCost && e(i).enableTotalCost ? (O(), L("div", rs, " (" + M(e(Tt)(g.totalCost)) + ") ", 1)) : oe("", !0)
                    ]),
                    e(mt)(g) ? (O(), L("div", as, [
                      b(q, {
                        name: "error",
                        color: "system-error-300",
                        size: "sm"
                      }),
                      k[4] || (k[4] = t("div", { class: "fm-typo-en-body-sm-400 text-fm-color-system-error-400" }, " This item has invalid unit configuration. Apply update on this item. ", -1))
                    ])) : oe("", !0)
                  ]))), 128))
                ])
              ]),
              k[6] || (k[6] = t("div", null, null, -1)),
              k[7] || (k[7] = t("div", null, null, -1)),
              t("div", is, [
                k[5] || (k[5] = t("div", { class: "flex flex-col" }, [
                  t("div", { class: "fm-typo-en-body-lg-600" }, "Enabled locations"),
                  t("div", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, " This template is only usable for the following locations. ")
                ], -1)),
                t("div", us, [
                  b(p, {
                    modelValue: $.value,
                    "onUpdate:modelValue": k[0] || (k[0] = (g) => $.value = g),
                    placeholder: "Filter locations",
                    "prepend-icon": "search"
                  }, null, 8, ["modelValue"]),
                  b(c, {
                    "hide-footer": "",
                    style: { height: "500px" },
                    "column-defs": _,
                    "search-value": $.value,
                    "row-data": ((I = h.template) == null ? void 0 : I.locations) ?? [{ name: "All locations" }]
                  }, null, 8, ["search-value", "row-data"])
                ])
              ])
            ])
          ];
        }),
        "side-sheet-footer": N(() => [
          t("div", ds, [
            b(w, {
              label: e(s)("common.edit"),
              onClick: k[1] || (k[1] = (S) => r("action:edit")),
              variant: "tertiary"
            }, null, 8, ["label"])
          ])
        ]),
        _: 1
      }, 8, ["header", "modelValue", "dismiss-away"]);
    };
  }
}), ps = { class: "flex-1 flex flex-col gap-8" }, cs = { class: "flex flex-col" }, fs = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, ys = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, vs = { class: "fm-typo-en-body-lg-400" }, bs = { class: "fm-typo-en-body-lg-400 line-clamp-1" }, hs = { class: "fm-typo-en-body-lg-400 line-clamp-2" }, Ys = /* @__PURE__ */ ae({
  __name: "TransferTemplateView",
  setup(f) {
    const { t: x } = me(), { createTemplate: h, viewTemplate: r, importTemplates: i, exportTemplates: s } = Ne(), { templateDialogProps: u, templateDetailsProps: _ } = ze(Ne()), $ = pt(), { loading: y, templates: o } = ze($), d = H(!1), m = it(), k = Ge(), { breakpoints: T } = bt();
    Te($.fetchTemplates);
    const A = B(
      () => d.value || y.value || !k._currentLocation
    ), q = B(() => o.value), p = H(""), c = B(() => T.value.xs || T.value.sm), w = B(() => c.value ? 10 : 20);
    function a(I) {
      switch (I) {
        case Ee.Add:
          return h();
        case "refresh":
          return $.fetchTemplates();
        case "import":
          return i();
        case "export":
          return s();
      }
    }
    function v(I) {
      return I;
    }
    const S = B(() => [
      {
        label: x("inventory.closing.template.create.title"),
        value: Ee.Add,
        isPrimary: !0,
        prependIcon: "add"
      },
      {
        label: x("inventory.common.refresh"),
        value: "refresh",
        isPrimary: !1
      },
      {
        label: x("inventory.common.import"),
        value: "import",
        isPrimary: !1
      },
      {
        label: x("inventory.common.export"),
        value: "export",
        isPrimary: !1
      }
    ]);
    return (I, g) => {
      const W = R("FmTable");
      return O(), L(pe, null, [
        b(ut, {
          title: e(x)("inventory.transfer.template.title2"),
          actions: S.value,
          "onClick:action": a
        }, {
          default: N(() => {
            var te;
            return [
              t("div", {
                class: le([
                  "flex flex-col gap-8 max-h-full",
                  {
                    "p-0": c.value,
                    "px-24 ": !c.value
                  }
                ])
              }, [
                b(yt, {
                  searchable: "",
                  search: p.value,
                  "onUpdate:search": g[0] || (g[0] = (E) => p.value = E)
                }, null, 8, ["search"]),
                (O(), ne(W, {
                  style: _e(e(m).tableHeight),
                  "column-defs": e($).columnDefs,
                  "row-data": q.value,
                  "search-value": p.value,
                  loading: A.value,
                  key: (te = e(k)._currentLocation) == null ? void 0 : te.dbName,
                  onRowClick: g[1] || (g[1] = (E) => e(r)(E.original)),
                  "page-size": w.value
                }, {
                  "list-row": N((E) => [
                    b(Xe, {
                      row: E,
                      onRowClick: (U) => e(r)(U)
                    }, {
                      default: N((U) => {
                        var Z, n, l, F, P, z, G, D, V, K, J, C, j, ie, Ce, Ie, Me, Se, Oe, $e, ce, De, Ve, Ae, Re, fe, qe;
                        return [
                          t("div", ps, [
                            t("div", cs, [
                              t("div", fs, [
                                b(e(ee), {
                                  render: (l = (n = (Z = U._id) == null ? void 0 : Z.column) == null ? void 0 : n.columnDef) == null ? void 0 : l.cell,
                                  props: (P = (F = U._id) == null ? void 0 : F.getContext) == null ? void 0 : P.call(F)
                                }, null, 8, ["render", "props"])
                              ]),
                              t("div", ys, [
                                b(e(ee), {
                                  render: (D = (G = (z = U.name) == null ? void 0 : z.column) == null ? void 0 : G.columnDef) == null ? void 0 : D.cell,
                                  props: (K = (V = U.name) == null ? void 0 : V.getContext) == null ? void 0 : K.call(V)
                                }, null, 8, ["render", "props"])
                              ]),
                              t("div", vs, [
                                b(e(ee), {
                                  render: (j = (C = (J = U.supplier) == null ? void 0 : J.column) == null ? void 0 : C.columnDef) == null ? void 0 : j.cell,
                                  props: (Ce = (ie = U.supplier) == null ? void 0 : ie.getContext) == null ? void 0 : Ce.call(ie)
                                }, null, 8, ["render", "props"])
                              ]),
                              t("div", null, M((Ie = E.original.locations) != null && Ie.length ? `Enabled for ${(Me = E.original.locations) == null ? void 0 : Me.length} outlets` : "Enabled for all outlets"), 1),
                              t("div", bs, M(E.original.purchaseOrder.items.length ? E.original.purchaseOrder.items.map((tt) => tt.name).join(", ") : "No items"), 1),
                              t("div", hs, [
                                b(e(ee), {
                                  render: ($e = (Oe = (Se = U.ref) == null ? void 0 : Se.column) == null ? void 0 : Oe.columnDef) == null ? void 0 : $e.cell,
                                  props: (De = (ce = U.ref) == null ? void 0 : ce.getContext) == null ? void 0 : De.call(ce)
                                }, null, 8, ["render", "props"])
                              ])
                            ]),
                            t("div", null, [
                              b(e(ee), {
                                render: (Re = (Ae = (Ve = U.type) == null ? void 0 : Ve.column) == null ? void 0 : Ae.columnDef) == null ? void 0 : Re.cell,
                                props: (qe = (fe = U.type) == null ? void 0 : fe.getContext) == null ? void 0 : qe.call(fe)
                              }, null, 8, ["render", "props"])
                            ])
                          ])
                        ];
                      }),
                      _: 2
                    }, 1032, ["row", "onRowClick"])
                  ]),
                  _: 1
                }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"]))
              ], 2)
            ];
          }),
          _: 1
        }, 8, ["title", "actions"]),
        (O(), ne(lt, { to: "body" }, [
          b(ms, rt(at(e(_))), null, 16),
          b(So, Ye(e(u), {
            onSubmitted: g[2] || (g[2] = (te) => e($).fetchTemplates())
          }), null, 16)
        ]))
      ], 64);
    };
  }
});
export {
  Ys as default
};
