import { ref as D, defineComponent as j, watch as ee, onMounted as te, onUnmounted as $e, openBlock as W, createElementBlock as q, toRaw as we, reactive as Se, createElementVNode as g, toDisplayString as E, unref as u, createVNode as k, resolveComponent as N, createSlots as Te, withCtx as I, createTextVNode as Me, renderSlot as De, createBlock as z, createCommentVNode as ae, computed as $, isRef as Ve, normalizeClass as We, normalizeStyle as Re } from "vue";
import { m as Pe, n as Ue, o as Ee, c as G, p as Ne, S as Le, u as Ie } from "./app-Bpb4394e.js";
import { useCoreStore as Fe, useI18n as O } from "@feedmepos/mf-common";
import { D as _e, R as J } from "./row-action.enum-DQ9bJ_uv.js";
import { c as Be } from "./component-kqxARxvM.js";
import { u as qe, _ as ze } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-sUxHOj47.js";
import { F as U } from "./form-mode.enum-BKiNVH6A.js";
import { useDialogChild as je, useDialog as Ce, useSnackbar as le, useProxiedModel as oe, useBreakpoints as Oe } from "@feedmepos/ui-library";
import { R as L } from "./rules-CoimOM7X.js";
import { c as se, u as re } from "./googlemap-BGi_aKUA.js";
import { d as Ge } from "./index-CH0wxGs4.js";
import { _ as Ke } from "./_plugin-vue_export-helper-CHgC5LLL.js";
import { _ as He } from "./FmCustomAttribute.vue_vue_type_script_setup_true_lang-D-IWRjRD.js";
import { u as Ye } from "./feature-Cz6F0_cm.js";
import { _ as Ze, F as Q } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-Ca_eYa8-.js";
import { _ as Je } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-j3aDZ2cT.js";
const X = Pe((v, h) => {
  const b = Fe();
  return {
    async readWarehouses() {
      var i;
      const a = ((i = b.currentBusiness.value) == null ? void 0 : i._id) ?? "", n = `${v.inventoryBackendUrl}/businesses/${a}/warehouses`;
      return await h.get(n);
    },
    async createWarehouse(a) {
      var r;
      const n = ((r = b.currentBusiness.value) == null ? void 0 : r._id) ?? "", i = `${v.inventoryBackendUrl}/businesses/${n}/warehouse`;
      return await h.post(i, a);
    },
    async updateWarehouse(a, n) {
      var l;
      const i = ((l = b.currentBusiness.value) == null ? void 0 : l._id) ?? "", r = `${v.inventoryBackendUrl}/businesses/${i}/warehouse/${a}`;
      return await h.put(r, n);
    },
    async deleteWarehouse(a) {
      var r;
      const n = ((r = b.currentBusiness.value) == null ? void 0 : r._id) ?? "", i = `${v.inventoryBackendUrl}/businesses/${n}/warehouse/${a}`;
      return await h.delete(i);
    }
  };
});
function Qe() {
  return {
    warehouses: []
  };
}
const ke = D(Qe());
function xe() {
  return {
    // state
    get warehouses() {
      return ke.value.warehouses;
    },
    set warehouses(v) {
      ke.value.warehouses = v;
    },
    // actions
    async readWarehouses() {
      const v = X();
      this.warehouses = await v.readWarehouses();
    },
    async createWarehouse(v) {
      await X().createWarehouse(v);
    },
    async updateWarehouse(v) {
      await X().updateWarehouse(v._id, {
        ...v.profile,
        preparationTime: v.preparationTime
      });
    },
    async deleteWarehouse(v) {
      await X().deleteWarehouse(v._id);
    },
    async init() {
      const v = Ue();
      try {
        await this.readWarehouses();
      } catch (h) {
        throw h instanceof Ee || v.error("Error at reading warehouses"), h;
      }
    }
  };
}
function Xe(v, h) {
  function b(r, l) {
    if (r === J.Edit) {
      v(G(l));
      return;
    }
    if (r === J.Delete) {
      h(G(l));
      return;
    }
  }
  const { t: a } = O(), n = [
    {
      accessorKey: "warehouse",
      header: () => a("inventory.warehouse.table.warehouse"),
      size: 200
    },
    {
      accessorKey: "contact",
      header: () => a("inventory.warehouse.table.contact"),
      size: 200
    },
    {
      accessorKey: "email",
      header: () => a("inventory.warehouse.table.email"),
      size: 200
    },
    {
      accessorKey: "address",
      header: () => a("inventory.warehouse.table.address"),
      size: "auto"
    },
    {
      id: "action",
      header: "",
      cell(r) {
        return Be(
          [_e[J.Edit], _e[J.Delete]],
          (l) => {
            b(l, r.row.original.original);
          }
        );
      },
      enableSorting: !1,
      size: 40,
      meta: {
        cellClass: "",
        headerClass: ""
      }
    }
  ];
  function i(r) {
    return r.map((l) => ({
      original: l,
      warehouse: l.profile.name,
      contact: l.profile.phoneNo,
      email: l.profile.email,
      get address() {
        const d = l.profile.address;
        return [
          d == null ? void 0 : d.line1,
          d == null ? void 0 : d.line2,
          d == null ? void 0 : d.city,
          d == null ? void 0 : d.postcode,
          d == null ? void 0 : d.state,
          d == null ? void 0 : d.country
        ].map((w) => w == null ? void 0 : w.trim()).filter((w) => w).join(", ");
      }
    }));
  }
  return { columnDefs: n, formatRowData: i };
}
const eo = /* @__PURE__ */ j({
  __name: "GoogleMap",
  props: {
    markers: {
      type: Array,
      default: () => []
    },
    polygons: {
      type: Array,
      default: () => []
    },
    zoom: {
      type: Number,
      default: 14
    },
    editable: {
      type: Boolean,
      default: !1
    },
    center: {
      type: Object,
      default: se.jb
    }
  },
  emits: ["map-click", "marker-change", "polygon-change", "polygon-right-click"],
  setup(v, { expose: h, emit: b }) {
    const a = v, n = b;
    h({
      setCenter: (s) => {
        var y, _;
        (y = l.value) == null || y.setCenter(s), (_ = l.value) == null || _.setZoom(18);
      }
    });
    const { googleMap: i } = re(), r = D(), l = D(null), d = [];
    function M(s) {
      return {
        lat: s.latLng.lat(),
        lng: s.latLng.lng()
      };
    }
    function w(s, y, _) {
      const p = i.maps.event.addListener(s, y, _);
      d.push(p);
    }
    const C = D([]);
    function T(s, y, _) {
      w(s, y, _);
    }
    function x(s) {
      P(null), C.value = s.map((y, _) => {
        const p = new i.maps.Marker({
          position: y,
          draggable: !0
        });
        return T(p, "dragend", (R) => {
          n("marker-change", { index: _, position: M(R) });
        }), p;
      }), P(l.value);
    }
    function P(s) {
      C.value.map((y) => we(y).setMap(s));
    }
    const c = D([]);
    function F(s, y, _) {
      w(s, y, _);
    }
    function S(s, y, _) {
      w(s, y, _);
    }
    function m(s) {
      return c.value[s].getPath().getArray().map(({ lat: _, lng: p }) => ({
        lat: _(),
        lng: p()
      }));
    }
    function f(s) {
      const y = m(s);
      n("polygon-change", { index: s, path: y });
    }
    function A(s, y) {
      const p = m(s).filter((R, K) => K !== y);
      n("polygon-change", { index: s, path: p });
    }
    function B(s, y) {
      y.vertex !== void 0 ? A(s, y.vertex) : n("polygon-right-click", s);
    }
    function V(s) {
      o(null), c.value = s.map((y, _) => {
        const p = new i.maps.Polygon({
          paths: y.paths,
          strokeColor: y.strokeColor,
          fillColor: y.fillColor,
          fillOpacity: 0.5,
          editable: a.editable
        });
        return F(p, "contextmenu", (R) => B(_, R)), p.getPaths().forEach((R) => {
          S(R, "insert_at", () => f(_)), S(R, "set_at", () => f(_));
        }), p;
      }), o(l.value);
    }
    function o(s) {
      c.value.map((y) => we(y).setMap(s));
    }
    function e(s, y, _) {
      w(s, y, _);
    }
    function t() {
      l.value = new i.maps.Map(r.value, {
        center: a.center,
        zoom: a.zoom,
        mapTypeControl: !1,
        streetViewControl: !1,
        draggable: !0,
        scrollwheel: !0
      }), e(l.value, "click", (s) => n("map-click", M(s)));
    }
    return ee(() => a.markers, x, { deep: !0 }), ee(() => a.polygons, V, { deep: !0 }), te(() => {
      !r.value || !i || (t(), x(a.markers), V(a.polygons));
    }), $e(() => {
      d.forEach((s) => s.remove());
    }), (s, y) => (W(), q("div", {
      ref_key: "mapRef",
      ref: r,
      class: "map app-map"
    }, null, 512));
  }
}), oo = { class: "flex flex-col gap-24" }, to = { class: "flex flex-col gap-8" }, ao = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, lo = { class: "fm-typo-en-body-lg-600" }, so = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, ro = { class: "fm-typo-en-body-lg-600" }, no = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, uo = { class: "fm-typo-en-body-lg-600" }, io = /* @__PURE__ */ j({
  __name: "CoordinateDialog",
  props: {
    address: {
      type: String,
      required: !0
    },
    coordinate: {
      type: Object,
      default: void 0
    }
  },
  setup(v) {
    const h = v, b = je(), a = re(), { t: n } = O(), i = Se(
      G(h.coordinate ? h.coordinate : se.jb)
    ), r = D(""), l = Ge(async function() {
      r.value = await a.getFirstMatchingAddress(
        i.lat,
        i.lng
      );
    }, 1e3);
    te(() => {
      b.emitData(G(i)), l();
    });
    function d({ position: w }) {
      i.lat = w.lat, i.lng = w.lng, b.emitData(G(i)), l();
    }
    const M = D();
    return (w, C) => (W(), q("div", oo, [
      g("div", to, [
        g("div", null, [
          g("span", ao, E(u(n)("inventory.formField.coordinate.address")) + ": ", 1),
          g("span", lo, E(r.value), 1)
        ]),
        g("div", null, [
          g("span", so, E(u(n)("inventory.formField.coordinate.longitude")) + ": ", 1),
          g("span", ro, E(i.lng), 1)
        ]),
        g("div", null, [
          g("span", no, E(u(n)("inventory.formField.coordinate.latitude")) + ": ", 1),
          g("span", uo, E(i.lat), 1)
        ])
      ]),
      k(eo, {
        ref_key: "gmapRef",
        ref: M,
        class: "h-[272px] sm:h-[240px] xs:h-[240px]",
        editable: "",
        center: i,
        markers: [i],
        onMarkerChange: d,
        onMapClick: C[0] || (C[0] = (T) => d({ position: T }))
      }, null, 8, ["center", "markers"])
    ]));
  }
}), co = /* @__PURE__ */ Ke(io, [["__scopeId", "data-v-272f5e8b"]]);
function Ae([v, h]) {
  return {
    lat: h,
    lng: v
  };
}
function po({ lng: v, lat: h }) {
  return [v, h];
}
const mo = { class: "flex gap-8 items-center" }, fo = { key: 0 }, yo = { key: 1 }, vo = /* @__PURE__ */ j({
  __name: "FmCoordinateInput",
  props: {
    address: {},
    modelValue: {},
    dialogTitle: {},
    label: {},
    helperText: {},
    helperState: {},
    labelMark: {},
    labelInfo: {},
    placeholder: {},
    disabled: { type: Boolean },
    rules: {}
  },
  emits: ["update:modelValue"],
  setup(v, { emit: h }) {
    const b = v, a = h, n = re(), i = Ce(), r = le(), l = oe(b, "modelValue"), d = D(!1), { t: M } = O();
    function w(c) {
      if (c != null && c[0] && (c != null && c[1]))
        return M("inventory.formField.coordinate.longLat", [c[0].toFixed(3), c[1].toFixed(3)]);
    }
    async function C(c) {
      var f, A;
      const F = b.modelValue, S = !F && ((f = b.address) != null && f.formatted) ? await n.getFirstMatchingCoordinate(b.address.formatted) : null, m = F ? Ae(F) : S ? Ae(S) : se.jb;
      i.open({
        title: b.dialogTitle ?? b.label ?? M("inventory.formField.coordinate.pinLocation"),
        closeButton: !0,
        contentComponent: co,
        contentComponentProps: {
          address: (A = b.address) == null ? void 0 : A.formatted,
          coordinate: m
        },
        primaryActions: {
          text: M("common.select"),
          close: !0
        },
        secondaryActions: {
          text: M("common.close"),
          close: !0
        }
      }).onPrimary(c);
    }
    const T = (c) => a("update:modelValue", c ? po(c) : null);
    async function x() {
      if (!b.disabled) {
        if (!n.isGoogleMapReady) {
          r.open({
            title: M("common.error"),
            message: M("inventory.formField.coordinate.error.loadMap"),
            type: "error"
          });
          return;
        }
        C(T);
      }
    }
    function P() {
      a("update:modelValue", null);
    }
    return (c, F) => {
      const S = N("FmField"), m = N("FmButton"), f = N("FmFormGroup");
      return W(), q("div", mo, [
        k(f, {
          class: "flex-1",
          "model-value": u(l),
          label: c.label,
          disabled: c.disabled,
          required: c.labelMark === "required",
          optional: c.labelMark === "optional",
          info: c.labelInfo,
          rules: c.rules,
          focused: d.value,
          "helper-text": c.helperText,
          "helper-state": c.helperState,
          onClick: F[0] || (F[0] = (A) => x())
        }, Te({
          default: I(({ invalid: A }) => [
            c.modelValue && c.modelValue[0] && c.modelValue[1] ? (W(), q("div", fo, [
              k(S, {
                invalid: A,
                class: "fm-typo-en-body-lg-400"
              }, {
                default: I(() => [
                  Me(E(w(c.modelValue)), 1)
                ]),
                _: 2
              }, 1032, ["invalid"])
            ])) : (W(), q("div", yo, [
              k(m, {
                label: u(M)("inventory.formField.coordinate.addCoordinate"),
                "prepend-icon": "add",
                variant: "plain"
              }, null, 8, ["label"])
            ]))
          ]),
          _: 2
        }, [
          c.$slots.label ? {
            name: "label",
            fn: I(() => [
              De(c.$slots, "label")
            ]),
            key: "0"
          } : void 0
        ]), 1032, ["model-value", "label", "disabled", "required", "optional", "info", "rules", "focused", "helper-text", "helper-state"]),
        c.modelValue && c.modelValue[0] && c.modelValue[1] ? (W(), z(m, {
          key: 0,
          "prepend-icon": "delete",
          variant: "tertiary",
          onClick: F[1] || (F[1] = (A) => P())
        })) : ae("", !0)
      ]);
    };
  }
}), ho = { class: "flex flex-col gap-40" }, bo = { class: "flex flex-col gap-16" }, go = { class: "flex flex-col gap-8" }, wo = { class: "fm-typo-en-title-sm-600" }, Vo = { class: "grid grid-cols-2 gap-24" }, _o = { class: "flex flex-col gap-8" }, ko = { class: "fm-typo-en-title-sm-600" }, Ao = {
  key: 0,
  class: "flex flex-col gap-8"
}, Mo = { class: "fm-typo-en-title-sm-600" }, Fo = { class: "flex flex-col gap-8" }, Co = { class: "fm-typo-en-title-sm-600" }, xo = { class: "flex flex-col gap-16" }, $o = /* @__PURE__ */ j({
  __name: "WarehouseForm",
  props: {
    modelValue: {},
    disabled: { type: Boolean }
  },
  emits: ["update:modelValue", "validation-success"],
  setup(v, { expose: h, emit: b }) {
    const a = v, n = b, i = Ye(), { t: r } = O(), l = $({
      get() {
        var o, e;
        return ((e = (o = a.modelValue) == null ? void 0 : o.profile) == null ? void 0 : e.name) ?? "";
      },
      set(o) {
        const e = a.modelValue ?? {};
        e.profile ?? (e.profile = {}), e.profile.name = o, n("update:modelValue", e);
      }
    }), d = $({
      get() {
        var o, e;
        return ((e = (o = a.modelValue) == null ? void 0 : o.profile) == null ? void 0 : e.regNo) ?? "";
      },
      set(o) {
        const e = a.modelValue ?? {};
        e.profile ?? (e.profile = {}), e.profile.regNo = o, n("update:modelValue", e);
      }
    }), M = $({
      get() {
        var o, e, t;
        return ((t = (e = (o = a.modelValue) == null ? void 0 : o.profile) == null ? void 0 : e.address) == null ? void 0 : t.line1) ?? "";
      },
      set(o) {
        var t;
        const e = a.modelValue ?? {};
        e.profile ?? (e.profile = {}), (t = e.profile).address ?? (t.address = {}), e.profile.address.line1 = o, n("update:modelValue", e);
      }
    }), w = $({
      get() {
        var o, e, t;
        return ((t = (e = (o = a.modelValue) == null ? void 0 : o.profile) == null ? void 0 : e.address) == null ? void 0 : t.line2) ?? "";
      },
      set(o) {
        var t;
        const e = a.modelValue ?? {};
        e.profile ?? (e.profile = {}), (t = e.profile).address ?? (t.address = {}), e.profile.address.line2 = o, n("update:modelValue", e);
      }
    }), C = $({
      get() {
        var o, e, t;
        return ((t = (e = (o = a.modelValue) == null ? void 0 : o.profile) == null ? void 0 : e.address) == null ? void 0 : t.city) ?? "";
      },
      set(o) {
        var t;
        const e = a.modelValue ?? {};
        e.profile ?? (e.profile = {}), (t = e.profile).address ?? (t.address = {}), e.profile.address.city = o, n("update:modelValue", e);
      }
    }), T = $({
      get() {
        var o, e, t;
        return ((t = (e = (o = a.modelValue) == null ? void 0 : o.profile) == null ? void 0 : e.address) == null ? void 0 : t.postcode) ?? "";
      },
      set(o) {
        var t;
        const e = a.modelValue ?? {};
        e.profile ?? (e.profile = {}), (t = e.profile).address ?? (t.address = {}), e.profile.address.postcode = o, n("update:modelValue", e);
      }
    }), x = $({
      get() {
        var o, e, t;
        return ((t = (e = (o = a.modelValue) == null ? void 0 : o.profile) == null ? void 0 : e.address) == null ? void 0 : t.state) ?? "";
      },
      set(o) {
        var t;
        const e = a.modelValue ?? {};
        e.profile ?? (e.profile = {}), (t = e.profile).address ?? (t.address = {}), e.profile.address.state = o, n("update:modelValue", e);
      }
    }), P = $({
      get() {
        var o, e, t;
        return ((t = (e = (o = a.modelValue) == null ? void 0 : o.profile) == null ? void 0 : e.address) == null ? void 0 : t.country) ?? "";
      },
      set(o) {
        var t;
        const e = a.modelValue ?? {};
        e.profile ?? (e.profile = {}), (t = e.profile).address ?? (t.address = {}), e.profile.address.country = o, n("update:modelValue", e);
      }
    }), c = $({
      get() {
        var e;
        const o = (e = a.modelValue) == null ? void 0 : e.preparationTime;
        return o && typeof o == "object" && "value" in o ? o.value.toString() : "";
      },
      set(o) {
        const e = a.modelValue ?? {};
        e.profile ?? (e.profile = {}), e.preparationTime = {
          value: parseInt(o),
          unit: Ne.Enum.day
        }, n("update:modelValue", e);
      }
    }), F = $({
      get() {
        var o, e, t;
        return ((t = (e = (o = a.modelValue) == null ? void 0 : o.profile) == null ? void 0 : e.address) == null ? void 0 : t.coordinates) ?? null;
      },
      set(o) {
        var t;
        const e = a.modelValue ?? {};
        e.profile ?? (e.profile = {}), (t = e.profile).address ?? (t.address = {}), e.profile.address.coordinates = o, n("update:modelValue", e);
      }
    }), S = $({
      get() {
        var o, e;
        return ((e = (o = a.modelValue) == null ? void 0 : o.profile) == null ? void 0 : e.phoneNo) ?? "";
      },
      set(o) {
        const e = a.modelValue ?? {};
        e.profile ?? (e.profile = {}), e.profile.phoneNo = o, n("update:modelValue", e);
      }
    }), { enabledCountries: m, currentCountry: f } = Fe(), A = $({
      get() {
        var o, e;
        return ((e = (o = a.modelValue) == null ? void 0 : o.profile) == null ? void 0 : e.email) ?? "";
      },
      set(o) {
        const e = a.modelValue ?? {};
        e.profile ?? (e.profile = {}), e.profile.email = o, n("update:modelValue", e);
      }
    }), B = $({
      get() {
        var o;
        return ((o = a.modelValue) == null ? void 0 : o.customAttributes) ?? {};
      },
      set(o) {
        const e = a.modelValue ? {
          ...a.modelValue
        } : {};
        e.customAttributes = o, n("update:modelValue", e);
      }
    }), V = D();
    return h({
      validateInputs: () => {
        var o, e;
        (e = (o = V.value) == null ? void 0 : o.validateInputs) == null || e.call(o);
      },
      resetInputsValidation: () => {
        var o, e;
        (e = (o = V.value) == null ? void 0 : o.resetInputsValidation) == null || e.call(o);
      },
      resetInputs: () => {
        var o, e;
        (e = (o = V.value) == null ? void 0 : o.resetInputs) == null || e.call(o);
      }
    }), (o, e) => {
      const t = N("FmTextField"), s = N("FmPill"), y = N("FmPhoneNumber"), _ = N("FmForm");
      return W(), z(_, {
        ref_key: "formRef",
        ref: V,
        onValidationSuccess: e[13] || (e[13] = (p) => n("validation-success"))
      }, {
        default: I(() => [
          g("div", ho, [
            g("div", bo, [
              k(t, {
                disabled: o.disabled,
                rules: [u(L)()],
                "label-mark": "required",
                label: u(r)("inventory.warehouse.companyName"),
                modelValue: l.value,
                "onUpdate:modelValue": e[0] || (e[0] = (p) => l.value = p)
              }, null, 8, ["disabled", "rules", "label", "modelValue"]),
              k(t, {
                disabled: o.disabled,
                rules: [u(L)()],
                "label-mark": "required",
                label: u(r)("inventory.warehouse.registrationNo"),
                modelValue: d.value,
                "onUpdate:modelValue": e[1] || (e[1] = (p) => d.value = p)
              }, null, 8, ["disabled", "rules", "label", "modelValue"])
            ]),
            g("div", go, [
              g("div", wo, E(u(r)("inventory.warehouse.address.title")), 1),
              g("div", Vo, [
                k(t, {
                  disabled: o.disabled,
                  rules: [u(L)()],
                  "label-mark": "required",
                  label: u(r)("inventory.warehouse.address.line1"),
                  modelValue: M.value,
                  "onUpdate:modelValue": e[2] || (e[2] = (p) => M.value = p)
                }, null, 8, ["disabled", "rules", "label", "modelValue"]),
                k(t, {
                  disabled: o.disabled,
                  "label-mark": "optional",
                  label: u(r)("inventory.warehouse.address.line2"),
                  modelValue: w.value,
                  "onUpdate:modelValue": e[3] || (e[3] = (p) => w.value = p)
                }, null, 8, ["disabled", "label", "modelValue"]),
                k(t, {
                  disabled: o.disabled,
                  rules: [u(L)()],
                  "label-mark": "required",
                  label: u(r)("inventory.warehouse.address.city"),
                  modelValue: C.value,
                  "onUpdate:modelValue": e[4] || (e[4] = (p) => C.value = p)
                }, null, 8, ["disabled", "rules", "label", "modelValue"]),
                k(t, {
                  disabled: o.disabled,
                  rules: [u(L)()],
                  "label-mark": "required",
                  label: u(r)("inventory.warehouse.address.postcode"),
                  modelValue: T.value,
                  "onUpdate:modelValue": e[5] || (e[5] = (p) => T.value = p)
                }, null, 8, ["disabled", "rules", "label", "modelValue"]),
                k(t, {
                  disabled: o.disabled,
                  rules: [u(L)()],
                  "label-mark": "required",
                  label: u(r)("inventory.warehouse.address.state"),
                  modelValue: x.value,
                  "onUpdate:modelValue": e[6] || (e[6] = (p) => x.value = p)
                }, null, 8, ["disabled", "rules", "label", "modelValue"]),
                k(t, {
                  disabled: o.disabled,
                  rules: [u(L)()],
                  "label-mark": "required",
                  label: u(r)("inventory.warehouse.address.country"),
                  modelValue: P.value,
                  "onUpdate:modelValue": e[7] || (e[7] = (p) => P.value = p)
                }, null, 8, ["disabled", "rules", "label", "modelValue"])
              ])
            ]),
            g("div", _o, [
              g("div", ko, E(u(r)("inventory.warehouse.coordinate.title")), 1),
              k(vo, {
                disabled: o.disabled,
                rules: [u(L)()],
                "label-mark": "required",
                modelValue: F.value,
                "onUpdate:modelValue": e[8] || (e[8] = (p) => F.value = p)
              }, null, 8, ["disabled", "rules", "modelValue"])
            ]),
            u(i).enableSupplierPreparationTime ? (W(), q("div", Ao, [
              g("div", Mo, [
                Me(E(u(r)("inventory.supplier.delivery.title")) + " ", 1),
                k(s, { variant: "beta" })
              ]),
              k(t, {
                disabled: o.disabled,
                label: u(r)("inventory.supplier.delivery.preparationTime"),
                modelValue: c.value,
                "onUpdate:modelValue": e[9] || (e[9] = (p) => c.value = p),
                type: "number"
              }, null, 8, ["disabled", "label", "modelValue"])
            ])) : ae("", !0),
            g("div", Fo, [
              g("div", Co, E(u(r)("inventory.warehouse.contact.title")), 1),
              g("div", xo, [
                k(y, {
                  disabled: o.disabled,
                  rules: [u(L)()],
                  "label-mark": "required",
                  label: u(r)("inventory.warehouse.contact.phoneNumber"),
                  modelValue: S.value,
                  "onUpdate:modelValue": e[10] || (e[10] = (p) => S.value = p),
                  "extra-country-codes": u(m),
                  "default-country": u(f)
                }, null, 8, ["disabled", "rules", "label", "modelValue", "extra-country-codes", "default-country"]),
                k(t, {
                  disabled: o.disabled,
                  "label-mark": "optional",
                  label: u(r)("inventory.warehouse.contact.email"),
                  modelValue: A.value,
                  "onUpdate:modelValue": e[11] || (e[11] = (p) => A.value = p)
                }, null, 8, ["disabled", "label", "modelValue"])
              ])
            ]),
            g("div", null, [
              k(He, {
                entity: "warehouse",
                modelValue: B.value,
                "onUpdate:modelValue": e[12] || (e[12] = (p) => B.value = p)
              }, null, 8, ["modelValue"])
            ])
          ])
        ]),
        _: 1
      }, 512);
    };
  }
}), So = { class: "flex gap-4" }, To = /* @__PURE__ */ j({
  __name: "WarehouseDialog",
  props: {
    mode: {},
    warehouse: {},
    show: { type: Boolean }
  },
  emits: ["update:show", "submitted"],
  setup(v, { expose: h, emit: b }) {
    const a = v, n = b, i = D(!1), r = le(), { t: l } = O(), d = xe(), M = $(() => {
      switch (a.mode) {
        case U.READ:
          return "";
        case U.UPDATE:
          return l("inventory.warehouse.update.title");
        case U.CREATE:
          return l("inventory.warehouse.create.title");
      }
      return "";
    }), w = $(() => {
      switch (a.mode) {
        case U.READ:
          return "";
        case U.UPDATE:
          return l("common.save");
        case U.CREATE:
          return l("common.add");
      }
      return "";
    }), C = D();
    h({
      validateInputs: () => {
        var m, f;
        (f = (m = C.value) == null ? void 0 : m.validateInputs) == null || f.call(m);
      },
      resetInputsValidation: () => {
        var m, f;
        (f = (m = C.value) == null ? void 0 : m.resetInputsValidation) == null || f.call(m);
      },
      resetInputs: () => {
        var m, f;
        (f = (m = C.value) == null ? void 0 : m.resetInputs) == null || f.call(m);
      }
    });
    const T = oe(a, "show"), x = oe(a, "warehouse");
    function P() {
      var m, f;
      (f = (m = C.value) == null ? void 0 : m.validateInputs) == null || f.call(m);
    }
    function c() {
      switch (a.mode) {
        case U.READ:
          return;
        case U.UPDATE:
          return S();
        case U.CREATE:
          return F();
      }
    }
    async function F() {
      var m, f;
      i.value = !0;
      try {
        await Promise.all([
          d.createWarehouse(x.value),
          new Promise((A) => setTimeout(A, 1e3))
        ]), r.open({
          title: l("inventory.common.success"),
          message: l("inventory.warehouse.create.success", { name: (f = (m = x.value) == null ? void 0 : m.profile) == null ? void 0 : f.name }),
          type: "success"
        }), n("update:show", !1), n("submitted");
      } catch (A) {
        r.open({
          title: l("inventory.warehouse.create.error.title"),
          message: A instanceof Le ? A.message : l("inventory.warehouse.create.error.message"),
          type: "error"
        }), console.error("cannot create warehouse", A);
      } finally {
        i.value = !1;
      }
    }
    async function S() {
      var m, f;
      if (x.value === null) {
        r.open({
          title: l("inventory.warehouse.update.error.title"),
          message: l("inventory.warehouse.update.error.emptyWarehouse"),
          type: "error"
        });
        return;
      }
      i.value = !0;
      try {
        await Promise.all([
          d.updateWarehouse(x.value),
          new Promise((A) => setTimeout(A, 1e3))
        ]), r.open({
          title: l("inventory.common.success"),
          message: l("inventory.warehouse.update.success", { name: (f = (m = x.value) == null ? void 0 : m.profile) == null ? void 0 : f.name }),
          type: "success"
        }), n("update:show", !1), n("submitted");
      } catch (A) {
        r.open({
          title: l("inventory.warehouse.update.error.title"),
          message: l("inventory.warehouse.update.error.message"),
          type: "error"
        }), console.error("cannot update warehouse", A);
      } finally {
        i.value = !1;
      }
    }
    return (m, f) => {
      const A = N("FmButton"), B = N("FmSideSheet");
      return W(), z(B, {
        header: M.value,
        modelValue: u(T),
        "onUpdate:modelValue": f[1] || (f[1] = (V) => Ve(T) ? T.value = V : null),
        "dismiss-away": !i.value,
        "close-button": "",
        "max-width": 500
      }, {
        default: I(() => {
          var V;
          return [
            (W(), z($o, {
              class: "w-full",
              ref_key: "formRef",
              ref: C,
              modelValue: u(x),
              "onUpdate:modelValue": f[0] || (f[0] = (o) => Ve(x) ? x.value = o : null),
              onValidationSuccess: c,
              key: ((V = m.warehouse) == null ? void 0 : V._id) ?? "",
              disabled: i.value
            }, null, 8, ["modelValue", "disabled"]))
          ];
        }),
        "side-sheet-footer": I(() => [
          g("div", So, [
            k(A, {
              loading: i.value,
              label: w.value,
              onClick: P
            }, null, 8, ["loading", "label"])
          ])
        ]),
        _: 1
      }, 8, ["header", "modelValue", "dismiss-away"]);
    };
  }
}), Do = { class: "flex flex-col py-8" }, Wo = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, Ro = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Po = {
  key: 0,
  class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
}, Uo = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary line-clamp-3" }, Xo = /* @__PURE__ */ j({
  __name: "WarehouseView",
  setup(v) {
    const h = xe(), b = Ie(), a = $(() => h.warehouses), n = Ce(), i = le(), r = D(!1), { t: l } = O();
    te(() => {
      b._currentLocation && S();
    }), ee([() => b._currentLocation], () => {
      b._currentLocation && S();
    });
    const d = D({});
    function M() {
      d.value.mode = U.CREATE, d.value.warehouse = {}, d.value.show = !0;
    }
    function w(V) {
      d.value.mode = U.UPDATE, d.value.warehouse = V, d.value.show = !0;
    }
    async function C(V) {
      n.open({
        title: l("inventory.warehouse.delete.confirm"),
        message: l("inventory.warehouse.delete.confirmMessage", { name: V.profile.name }),
        primaryActions: {
          text: "Delete",
          close: !0,
          variant: "destructive"
        },
        secondaryActions: {
          text: "Cancel",
          close: !0
        }
      }).onPrimary(() => T(V));
    }
    async function T(V) {
      n.open({
        title: l("inventory.warehouse.delete.deletingWarehouse"),
        closeButton: !1
      });
      try {
        await h.deleteWarehouse(V), i.open({
          title: l("inventory.warehouse.delete.success"),
          message: l("inventory.warehouse.delete.deletedWarehouse", { name: V.profile.name }),
          type: "success"
        }), await S(!0);
      } catch (o) {
        i.open({
          title: l("inventory.warehouse.delete.error"),
          message: l("inventory.warehouse.delete.errorMessage", { name: V.profile.name }),
          type: "error"
        }), console.error("failed to delete warehouse", o);
      } finally {
        n.close();
      }
    }
    const { columnDefs: x, formatRowData: P } = Xe(
      w,
      C
    );
    function c(V) {
      V === "create" && M();
    }
    const F = D("");
    async function S(V = !1) {
      r.value = !0;
      try {
        await h.readWarehouses(), V && await b.readLocations();
      } catch {
        i.open({
          title: "Cannot fetch warehouse list",
          type: "error"
        });
      } finally {
        r.value = !1;
      }
    }
    const { breakpoints: m } = Oe(), f = $(() => m.value.xs || m.value.sm), A = $(() => f.value ? 10 : 20), B = qe();
    return (V, o) => {
      const e = N("FmTable");
      return W(), z(ze, {
        title: u(l)("inventory.warehouse.title"),
        actions: [
          {
            label: u(l)("inventory.warehouse.create.title"),
            value: "create",
            isPrimary: !0,
            prependIcon: "add"
          }
        ],
        "onClick:action": c
      }, {
        default: I(() => [
          g("div", {
            class: We([
              "flex flex-col gap-8 max-h-full",
              {
                "p-0": f.value,
                "px-24 ": !f.value
              }
            ])
          }, [
            k(Je, {
              searchable: "",
              search: F.value,
              "onUpdate:search": o[0] || (o[0] = (t) => F.value = t)
            }, null, 8, ["search"]),
            (W(), z(e, {
              style: Re(u(B).tableHeight),
              "column-defs": u(x),
              "row-data": u(P)(a.value),
              "search-value": F.value,
              loading: !u(b)._currentLocation || r.value,
              onRowClick: o[1] || (o[1] = (t) => w(t.original.original)),
              key: a.value.length,
              "page-size": A.value
            }, {
              "list-row": I((t) => [
                k(Ze, {
                  row: t,
                  onRowClick: (s) => w(s.original)
                }, {
                  default: I((s) => {
                    var y, _, p, R, K, ne, ue, ie, H, de, ce, pe, me, fe, Y, ye, ve, he, be, Z, ge;
                    return [
                      g("div", Do, [
                        g("div", Wo, [
                          k(u(Q), {
                            render: (p = (_ = (y = s.warehouse) == null ? void 0 : y.column) == null ? void 0 : _.columnDef) == null ? void 0 : p.cell,
                            props: (K = (R = s.warehouse) == null ? void 0 : R.getContext) == null ? void 0 : K.call(R)
                          }, null, 8, ["render", "props"])
                        ]),
                        g("div", Ro, [
                          k(u(Q), {
                            render: (ie = (ue = (ne = s.contact) == null ? void 0 : ne.column) == null ? void 0 : ue.columnDef) == null ? void 0 : ie.cell,
                            props: (de = (H = s.contact) == null ? void 0 : H.getContext) == null ? void 0 : de.call(H)
                          }, null, 8, ["render", "props"])
                        ]),
                        (ce = t.original) != null && ce.email ? (W(), q("div", Po, [
                          k(u(Q), {
                            render: (fe = (me = (pe = s.email) == null ? void 0 : pe.column) == null ? void 0 : me.columnDef) == null ? void 0 : fe.cell,
                            props: (ye = (Y = s.email) == null ? void 0 : Y.getContext) == null ? void 0 : ye.call(Y)
                          }, null, 8, ["render", "props"])
                        ])) : ae("", !0),
                        g("div", Uo, [
                          k(u(Q), {
                            render: (be = (he = (ve = s.address) == null ? void 0 : ve.column) == null ? void 0 : he.columnDef) == null ? void 0 : be.cell,
                            props: (ge = (Z = s.address) == null ? void 0 : Z.getContext) == null ? void 0 : ge.call(Z)
                          }, null, 8, ["render", "props"])
                        ])
                      ])
                    ];
                  }),
                  _: 2
                }, 1032, ["row", "onRowClick"])
              ]),
              _: 1
            }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"]))
          ], 2),
          k(To, {
            show: d.value.show,
            "onUpdate:show": o[2] || (o[2] = (t) => d.value.show = t),
            warehouse: d.value.warehouse,
            mode: d.value.mode,
            onSubmitted: o[3] || (o[3] = (t) => S(!0))
          }, null, 8, ["show", "warehouse", "mode"])
        ]),
        _: 1
      }, 8, ["title", "actions"]);
    };
  }
});
export {
  Xo as default
};
