import { defineComponent as d, ref as g, watch as _, resolveComponent as S, createBlock as T, openBlock as f, unref as y, computed as h } from "vue";
import { useI18n as m } from "@feedmepos/mf-common";
import { useDialogChild as w, useDialog as x, useSnackbar as C } from "@feedmepos/ui-library";
import { u as k, G as M } from "./index.vue_vue_type_script_setup_true_lang-BMVa5UfU.js";
const v = /* @__PURE__ */ d({
  __name: "AddPriceGroupDialog",
  setup(s) {
    const { t: e } = m(), o = g(""), { emitData: t } = w();
    return _(o, () => {
      t(o.value);
    }), (c, n) => {
      const r = S("FmTextField");
      return f(), T(r, {
        label: y(e)("menu.price_tier.group_title"),
        modelValue: o.value,
        "onUpdate:modelValue": n[0] || (n[0] = (i) => o.value = i)
      }, null, 8, ["label", "modelValue"]);
    };
  }
}), F = (s) => {
  const { t: e } = m(), o = x(), t = s || k(), c = C(), n = M(c), r = h(() => t.state.menu.priceTierSettings || []);
  function i() {
    o.open({
      title: e("menu.price_tier.add_price_group"),
      contentComponent: v,
      primaryActions: {
        text: e("menu.category.manager.dialog.add.action"),
        close: !1
      },
      secondaryActions: {
        text: e("menu.common.actions.cancel"),
        close: !0
      }
    }).onPrimary(async (a) => {
      a && await n.minor(
        async () => {
          await t.updateMenuSetting({
            lowStockThreshold: t.state.menu.lowStockThreshold,
            masterCatalogSetting: t.state.menu.masterCatalogSetting,
            priceTierSettings: [...t.state.menu.priceTierSettings || [], { key: a }]
          }), o.close();
        },
        {
          successMessage: e("menu.price_tier.add_price_group_success")
        }
      );
    });
  }
  function u(a) {
    o.open({
      title: e("menu.price_tier.delete_dialog.title"),
      message: e("menu.price_tier.delete_dialog.message", { name: a }),
      primaryActions: {
        text: e("menu.common.actions.remove"),
        close: !1
      },
      secondaryActions: {
        text: e("menu.common.actions.cancel"),
        close: !0
      }
    }).onPrimary(async () => {
      await n.minor(
        async () => {
          var l;
          await t.updateMenuSetting({
            lowStockThreshold: t.state.menu.lowStockThreshold,
            masterCatalogSetting: t.state.menu.masterCatalogSetting,
            priceTierSettings: (l = t.state.menu.priceTierSettings) == null ? void 0 : l.filter(
              (p) => p.key !== a
            )
          }), o.close();
        },
        {
          successMessage: e("menu.price_tier.delete_dialog.success")
        }
      );
    });
  }
  return {
    create: i,
    deletePriceTier: u,
    priceTiers: r
  };
};
export {
  F as u
};
