import { defineComponent as ce, ref as y, watch as de, computed as c, resolveComponent as fe, openBlock as x, createBlock as Z, unref as a, withCtx as T, createElementVNode as p, normalizeClass as ve, createVNode as u, normalizeStyle as he, toDisplayString as _e, createElementBlock as De, createCommentVNode as ge, Teleport as ye, mergeProps as be, isRef as Re } from "vue";
import { u as Oe, V as b } from "./app-Bpb4394e.js";
import { a as Se, _ as Pe } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-j3aDZ2cT.js";
import { a as xe, P as w, b as Te, _ as we, c as ke } from "./TransferDetails.vue_vue_type_script_setup_true_lang-DtY8MWv5.js";
import { b as I } from "./date2-DpnYOzUg.js";
import { u as qe, _ as Ve } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-sUxHOj47.js";
import { _ as Ce, F as R } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-Ca_eYa8-.js";
import { useBreakpoints as Ne } from "@feedmepos/ui-library";
import { useI18n as Ae } from "@feedmepos/mf-common";
import { P as Me, J as Fe } from "./app-DiX-EfV6.js";
import { u as Le } from "./netsuite-BGUUAOqe.js";
import { f as $e } from "./predefined-templates-BAEoCP7i.js";
import "./inventory-core-dart.default-DanfWZQm.js";
const ze = { class: "flex flex-col py-8" }, Ee = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ue = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary line-clamp-1" }, Ye = { class: "fm-typo-en-body-md-400 text-fm-color-typo-primary line-clamp-1" }, He = {
  key: 0,
  class: "fm-typo-en-body-md-400 text-fm-color-typo-primary line-clamp-1"
}, je = { class: "pt-8" }, ot = /* @__PURE__ */ ce({
  __name: "ApprovalView",
  setup(Je) {
    const s = xe(w.APPROVAL), {
      columnDefs: B,
      showCustomPrintDialog: O,
      customPrintHtml: ee,
      customPrintTemplateName: te,
      customPrintIsDefault: ae
    } = Te(w.APPROVAL, s, s.shipments), re = Oe(), se = Le();
    $e().fetchTemplates(), b.object({
      name: b.string().optional().nullable(),
      start: b.date().optional().nullable(),
      end: b.date().optional().nullable()
    });
    const k = y({
      name: "",
      ...Se()
    }), l = y({
      startDate: I(k.value.start ?? /* @__PURE__ */ new Date()),
      endDate: I(k.value.end ?? /* @__PURE__ */ new Date())
    });
    de([() => l.value.startDate], () => {
      if (!l.value.startDate)
        return;
      if (!l.value.endDate) {
        l.value.endDate = l.value.startDate;
        return;
      }
      const i = new Date(l.value.startDate);
      if (new Date(l.value.endDate).getTime() < i.getTime()) {
        l.value.endDate = l.value.startDate;
        return;
      }
      s.updateDateRange(l.value.startDate, l.value.endDate);
    });
    const S = y(""), { breakpoints: q } = Ne(), P = c(() => q.value.xs || q.value.sm), ne = c(() => P.value ? 10 : 20), oe = qe(), { t: V } = Ae(), le = c(() => [
      {
        label: V("inventory.common.refresh"),
        value: "refresh"
      }
    ]);
    function ue(i) {
      switch (i) {
        case "refresh":
          return s.fetchData();
      }
    }
    const ie = c(() => {
      const i = [
        {
          type: "string",
          key: "status",
          entity: "purchaseOrderRequest",
          values: Array.from(
            new Set(
              s.purchaseRequests.value.map((e) => {
                var n;
                return ((n = e.purchaseOrder) == null ? void 0 : n.status) ?? "";
              }).filter((e) => e !== "")
            )
          )
        }
      ], r = [
        {
          type: "string",
          key: "netsuiteTransactionNumber",
          entity: "purchaseOrderRequest",
          values: s.purchaseRequests.value.map((e) => {
            var n, t;
            return (t = (n = e.netSuite) == null ? void 0 : n.additionalInfo) == null ? void 0 : t.transactionnumber;
          }).filter((e) => e != null)
        },
        {
          type: "string",
          key: "netsuiteOrderNo",
          entity: "purchaseOrderRequest",
          values: s.purchaseRequests.value.map((e) => {
            var n;
            return (n = e.netSuite) == null ? void 0 : n.refNo;
          }).filter((e) => e != null)
        },
        {
          type: "string",
          key: "netsuiteOrderId",
          entity: "purchaseOrderRequest",
          values: s.purchaseRequests.value.map((e) => {
            var n;
            return (n = e.netSuite) == null ? void 0 : n.id;
          }).filter((e) => e != null)
        }
      ];
      return [...i, ...se.isEnabled ? r : []];
    }), d = y(null), pe = c(() => {
      if (!d.value)
        return s.purchaseRequests.value;
      const i = Me.build(d.value);
      return s.purchaseRequests.value.filter((r) => {
        var e, n, t, o, m;
        return Fe(
          {
            netsuiteTransactionNumber: (n = (e = r.netSuite) == null ? void 0 : e.additionalInfo) == null ? void 0 : n.transactionnumber,
            netsuiteOrderNo: (t = r.netSuite) == null ? void 0 : t.refNo,
            netsuiteOrderId: (o = r.netSuite) == null ? void 0 : o.id,
            status: (m = r.purchaseOrder) == null ? void 0 : m.status
          },
          i
        );
      });
    });
    return (i, r) => {
      const e = fe("FmTable");
      return x(), Z(Ve, {
        title: a(V)("inventory.transfer.approval.title"),
        actions: le.value,
        "onClick:action": ue
      }, {
        default: T(() => {
          var n;
          return [
            p("div", {
              class: ve([
                "flex flex-col gap-8 max-h-full",
                {
                  "p-0": P.value,
                  "px-24 ": !P.value
                }
              ])
            }, [
              u(Pe, {
                "date-range-query": "",
                "date-range": l.value,
                "onUpdate:dateRange": r[0] || (r[0] = (t) => l.value = t),
                searchable: "",
                "change-location": "",
                search: S.value,
                "onUpdate:search": r[1] || (r[1] = (t) => S.value = t),
                filterable: "",
                "filter-attributes": ie.value,
                filter: d.value,
                "onUpdate:filter": r[2] || (r[2] = (t) => d.value = t)
              }, null, 8, ["date-range", "search", "filter-attributes", "filter"]),
              u(e, {
                style: he(a(oe).tableHeight),
                "column-defs": a(B),
                "row-data": pe.value,
                "search-value": S.value,
                loading: !a(re)._currentLocation || a(s).loading.value,
                onRowClick: r[3] || (r[3] = (t) => a(s).promptShowTransferDetails(
                  t.original.purchaseOrder,
                  t.original
                )),
                "page-size": ne.value
              }, {
                "list-row": T((t) => [
                  u(Ce, {
                    row: t,
                    onRowClick: (o) => a(s).promptShowTransferDetails(o.purchaseOrder, o)
                  }, {
                    default: T((o) => {
                      var m, C, N, f, A, M, F, L, v, $, z, h, E, _, U, Y, H, j, J, D, G, K, Q, W, g, X;
                      return [
                        p("div", ze, [
                          p("div", Ee, [
                            u(a(R), {
                              render: (N = (C = (m = o.purchaseOrder__id) == null ? void 0 : m.column) == null ? void 0 : C.columnDef) == null ? void 0 : N.cell,
                              props: (A = (f = o.purchaseOrder__id) == null ? void 0 : f.getContext) == null ? void 0 : A.call(f)
                            }, null, 8, ["render", "props"])
                          ]),
                          p("div", Ue, [
                            u(a(R), {
                              render: (L = (F = (M = o.to_name) == null ? void 0 : M.column) == null ? void 0 : F.columnDef) == null ? void 0 : L.cell,
                              props: ($ = (v = o.to_name) == null ? void 0 : v.getContext) == null ? void 0 : $.call(v)
                            }, null, 8, ["render", "props"])
                          ]),
                          p("div", Ye, _e((U = (_ = (E = (h = (z = t.original.purchaseOrder) == null ? void 0 : z.items) == null ? void 0 : h.map) == null ? void 0 : E.call(h, (me) => `${me.name}`)) == null ? void 0 : _.join) == null ? void 0 : U.call(_, ", ")), 1),
                          (Y = t.original.purchaseOrder) != null && Y.ref ? (x(), De("div", He, [
                            u(a(R), {
                              render: (J = (j = (H = o.purchaseOrder_ref) == null ? void 0 : H.column) == null ? void 0 : j.columnDef) == null ? void 0 : J.cell,
                              props: (G = (D = o.purchaseOrder_ref) == null ? void 0 : D.getContext) == null ? void 0 : G.call(D)
                            }, null, 8, ["render", "props"])
                          ])) : ge("", !0),
                          p("div", je, [
                            u(a(R), {
                              render: (W = (Q = (K = o.purchaseOrder_status) == null ? void 0 : K.column) == null ? void 0 : Q.columnDef) == null ? void 0 : W.cell,
                              props: (X = (g = o.purchaseOrder_status) == null ? void 0 : g.getContext) == null ? void 0 : X.call(g)
                            }, null, 8, ["render", "props"])
                          ])
                        ])
                      ];
                    }),
                    _: 2
                  }, 1032, ["row", "onRowClick"])
                ]),
                _: 1
              }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"])
            ], 2),
            (x(), Z(ye, { to: "body" }, [
              u(we, be({
                scope: a(w).APPROVAL
              }, {
                ...a(s).transferDetailsProps.value,
                receivedMap: ((n = a(s).transferDetailsProps.value) == null ? void 0 : n.receivedMap) ?? {},
                shipments: a(s).shipments.value ?? []
              }, {
                onSubmitted: a(s).fetchData
              }), null, 16, ["scope", "onSubmitted"]),
              u(ke, {
                modelValue: a(O),
                "onUpdate:modelValue": r[4] || (r[4] = (t) => Re(O) ? O.value = t : null),
                html: a(ee),
                "template-name": a(te),
                "is-default": a(ae)
              }, null, 8, ["modelValue", "html", "template-name", "is-default"])
            ]))
          ];
        }),
        _: 1
      }, 8, ["title", "actions"]);
    };
  }
});
export {
  ot as default
};
