import { a as A } from "./FmMultiselectDialog-D-38fV59.js";
import { u as S } from "./app-Bpb4394e.js";
import { useI18n as v, useCoreStore as d, useCustomAttributes as w } from "@feedmepos/mf-common";
import { useDialog as _, components as m } from "@feedmepos/ui-library";
import { computed as r, h as c } from "vue";
function F(a) {
  const p = _(), n = S(), { t: i } = v(), b = r(() => d().restaurants.value.reduce((e, o) => (e[o._id] = o.customAttributes || {}, e), {})), { attributes: f } = w({
    valueSource: d().restaurants,
    entity: "restaurant"
  });
  function y() {
    var u;
    const s = a.getLocations() ?? [], e = n.locationById, o = s.filter((t) => !e[t.doc._id]);
    p.open({
      title: "Select at least one location",
      contentComponent: c(
        A,
        {
          modelValue: ((u = L.value) == null ? void 0 : u.map((t) => t.doc._id)) ?? [],
          items: n.locations.map((t) => ({
            label: `${t.name}(${t.doc.profile.code ?? "--"})`,
            sublabel: t.type,
            value: t.doc._id,
            customAttributes: {
              ...b.value[t.doc._id],
              state: t.doc.profile.address.state
            }
          })),
          filterAttributes: [
            ...f.value,
            {
              type: "string",
              key: "state",
              entity: "location",
              values: [
                ...new Set(
                  n.locations.map((t) => t.doc.profile.address.state).filter(Boolean)
                )
              ]
            }
          ],
          attributeKey: "customAttributes"
        },
        {
          appendList() {
            return o.map(
              (t) => c(
                m.FmListItem,
                {
                  label: `${t.name}(${t.doc.profile.code ?? "--"})`,
                  sublabel: "This location is not manageable by your account.",
                  disabled: !0
                },
                {
                  prepend: c(m.FmCheckbox, {
                    modelValue: !0,
                    value: "",
                    disabled: !0
                  })
                }
              )
            );
          }
        }
      ),
      contentComponentProps: {},
      primaryActions: {
        text: i("common.confirm"),
        close: !0
      },
      secondaryActions: {
        text: i("common.close"),
        close: !0
      }
    }).onPrimary((t) => {
      const l = [...n.locations.filter((g) => t.includes(g.doc._id)), ...o];
      l.length ? a.setLocations(l) : a.setLocations(null);
    });
  }
  const L = r(() => {
    var e;
    const s = /* @__PURE__ */ new Set([...n.locations.map((o) => o.doc._id)]);
    return (e = a.getLocations()) == null ? void 0 : e.filter((o) => s.has(o.doc._id));
  }), h = r(() => {
    const s = a.getLocations();
    return s ? s.reduce(
      (e, o) => {
        switch (o.type) {
          case "restaurant": {
            e[0].restaurants += 1;
            break;
          }
          case "warehouse": {
            e[0].warehouses += 1;
            break;
          }
        }
        return e[0][o.type] += 1, e;
      },
      [
        {
          restaurants: 0,
          warehouses: 0
        }
      ]
    ) : [
      {
        restaurants: "All",
        warehouses: "All"
      }
    ];
  });
  return {
    promptSelectLocations: y,
    columnDefs: [
      {
        accessorKey: "restaurants",
        header: () => "Restaurants",
        enableSorting: !1
      },
      {
        accessorKey: "warehouses",
        header: () => "Warehouses",
        enableSorting: !1
      }
    ],
    rowData: h
  };
}
export {
  F as u
};
