import { defineComponent as B, ref as H, useModel as J, resolveComponent as h, createElementBlock as k, openBlock as x, createBlock as P, createElementVNode as t, resolveDynamicComponent as ne, unref as e, withCtx as y, createVNode as a, normalizeClass as O, toDisplayString as s, Fragment as K, renderList as Q, withDirectives as M, createTextVNode as ie, vShow as j, watch as me, normalizeStyle as ue } from "vue";
import { _ as de } from "./Default.vue_vue_type_script_setup_true_lang-Eqkot8H6.js";
import { d as z, C as I, D as pe, a as ce } from "./app-AiSMEgJb.js";
import { components as A, useSnackbar as W, useBreakpoints as X, FmButtonColorThemeVariant as G } from "@feedmepos/ui-library";
import { t as N, j as fe } from "./BaseDialog.vue_vue_type_script_setup_true_lang-BQQb5IJd.js";
import { u as ve } from "./message-dialog-UoMWOnil.js";
import { u as U } from "./vue-i18n-DVWuTfed.js";
import { detectLocale as F } from "@feedmepos/mf-common";
import { a as Y } from "./SelectComponent.vue_vue_type_script_setup_true_lang-Df40itH5.js";
import { storeToRefs as _e } from "pinia";
const ge = { class: "px-5 py-2" }, ye = { class: "flex" }, he = { class: "flex px-5 gap-2" }, xe = { class: "flex flex-col gap-2" }, be = { class: "fm-typo-en-title-sm-600" }, Ce = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ve = { class: "w-full gap-[24px] flex flex-col pt-2" }, Te = { class: "flex items-center w-full gap-3" }, De = { class: "text-fm-color-typo-primary" }, $e = { class: "text-fm-color-typo-secondary" }, Se = { class: "flex items-center gap-2" }, ke = /* @__PURE__ */ B({
  __name: "ReportHour",
  props: {
    modelValue: {
      required: !0,
      default: () => []
    },
    modelModifiers: {}
  },
  emits: ["update:modelValue"],
  setup(T) {
    const o = H(!1), p = H(), l = {
      name: "",
      isDefault: !1,
      startTime: { hour: 0, minute: 0 },
      endTime: { hour: 0, minute: 0 }
    }, { FmForm: c } = A, n = H(), { promptMessage: D } = ve(), b = W(), r = H(JSON.parse(JSON.stringify(l))), i = J(T, "modelValue"), { t: m } = U(), d = () => {
      o.value = !1, r.value && p.value === void 0 ? i.value.push(r.value) : i.value[p.value] = r.value;
    }, R = () => {
      var v;
      (v = n.value) == null || v.validateInputs();
    }, L = () => {
      o.value = !1, r.value = l;
    }, Z = (v) => {
      p.value = v, r.value = JSON.parse(JSON.stringify(i.value[p.value])), o.value = !0;
    }, ee = () => {
      r.value = l, o.value = !0;
    }, te = async (v) => {
      const u = i.value.find((C, f) => f === v);
      if (!u) {
        b.open({ message: `index ${v} cannot be found`, type: "error" });
        return;
      }
      await D({
        title: m("report.setting.reportHour.deleteTitle"),
        message: m("report.setting.reportHour.deleteConfirm", { name: u.name })
      }) && (i.value = i.value.filter((f, E) => E !== v), i.value.find((f) => f.isDefault) || (i.value[0].isDefault = !0), r.value = l);
    }, oe = (v, u) => {
      v ? i.value = i.value.map(($, C) => ({
        ...$,
        isDefault: u === C
      })) : i.value = i.value.map(($, C) => ({
        ...$,
        isDefault: C === 0
      }));
    }, { breakpoints: w } = X(), { FmSideSheet: le, FmTopSheet: ae } = A;
    return (v, u) => {
      const $ = h("FmTextField"), C = h("FmTimePicker"), f = h("FmButton"), E = h("FmSwitch"), se = h("FmChip"), re = h("FmCard");
      return x(), k("div", null, [
        (x(), P(ne(e(w).lg || e(w).md ? e(le) : e(ae)), {
          modelValue: o.value,
          "onUpdate:modelValue": u[3] || (u[3] = (g) => o.value = g),
          "fullscreen-size": "sm",
          "dismiss-away": !0
        }, {
          "side-sheet-header": y(() => [
            t("p", null, s(e(m)("report.setting.reportHour.addTitle")), 1)
          ]),
          "top-sheet-header": y(() => [
            t("div", ge, [
              t("p", null, s(e(m)("report.setting.reportHour.addTitle")), 1)
            ])
          ]),
          "side-sheet-footer": y(() => [
            t("div", ye, [
              a(f, {
                label: "Save",
                variant: "primary",
                onClick: R
              }),
              a(f, {
                label: "Cancel",
                variant: "tertiary",
                onClick: L
              })
            ])
          ]),
          "top-sheet-footer": y(() => [
            t("div", he, [
              a(f, {
                label: "Save",
                variant: "primary",
                onClick: R
              }),
              a(f, {
                label: "Cancel",
                variant: "tertiary",
                onClick: L
              })
            ])
          ]),
          default: y(() => [
            a(e(c), {
              ref_key: "form",
              ref: n,
              class: O(["flex flex-col gap-2", `${e(w).sm || e(w).xs ? "px-24" : ""}`]),
              onValidationSuccess: d
            }, {
              default: y(() => {
                var g, V, S, q;
                return [
                  a($, {
                    modelValue: r.value.name,
                    "onUpdate:modelValue": u[0] || (u[0] = (_) => r.value.name = _),
                    label: e(m)("report.setting.reportHour.hourSetName"),
                    placeholder: e(m)("report.setting.reportHour.namePlaceholder"),
                    rules: [(_) => _ !== "" || e(m)("report.setting.reportHour.cannotBeEmpty")]
                  }, null, 8, ["modelValue", "label", "placeholder", "rules"]),
                  a(C, {
                    "model-value": e(z)().hour(((g = r.value.startTime) == null ? void 0 : g.hour) ?? 0).minute(((V = r.value.startTime) == null ? void 0 : V.minute) ?? 0).locale(e(F)()).format("HH:mm"),
                    class: "grow",
                    label: e(m)("report.setting.reportHour.startTime"),
                    "onUpdate:modelValue": u[1] || (u[1] = (_) => {
                      _ && (r.value.startTime.hour = Number(_.split(":")[0]), r.value.startTime.minute = Number(_.split(":")[1]));
                    })
                  }, null, 8, ["model-value", "label"]),
                  a(C, {
                    "model-value": e(z)().hour(((S = r.value.endTime) == null ? void 0 : S.hour) ?? 0).minute(((q = r.value.endTime) == null ? void 0 : q.minute) ?? 0).format("HH:mm"),
                    class: "grow",
                    label: e(m)("report.setting.reportHour.closeTime"),
                    "onUpdate:modelValue": u[2] || (u[2] = (_) => {
                      _ && (r.value.endTime.hour = Number(_.split(":")[0]), r.value.endTime.minute = Number(_.split(":")[1]));
                    })
                  }, null, 8, ["model-value", "label"])
                ];
              }),
              _: 1
            }, 8, ["class"])
          ]),
          _: 1
        }, 8, ["modelValue"])),
        t("div", xe, [
          t("p", be, s(e(m)("report.setting.reportHour.title")), 1),
          t("p", Ce, s(e(m)("report.setting.reportHour.description")), 1)
        ]),
        t("div", Ve, [
          (x(!0), k(K, null, Q(i.value, (g, V) => (x(), P(re, {
            key: `report_${V}`,
            class: "flex p-4",
            variant: "outlined"
          }, {
            default: y(() => [
              t("div", Te, [
                a(E, {
                  "model-value": g.isDefault,
                  "onUpdate:modelValue": (S) => oe(S, V)
                }, null, 8, ["model-value", "onUpdate:modelValue"]),
                t("div", null, [
                  t("p", De, [
                    ie(s(g.name) + " ", 1),
                    M(a(se, {
                      label: e(m)("report.common.default"),
                      class: "bg-fm-color-system-info-100 border-fm-color-typo-info text-fm-color-typo-info",
                      compact: ""
                    }, null, 8, ["label"]), [
                      [j, g.isDefault]
                    ])
                  ]),
                  t("p", $e, s(e(N)(g.startTime, e(F)())) + " - " + s(e(N)(g.endTime, e(F)())), 1)
                ]),
                u[4] || (u[4] = t("div", { class: "grow" }, null, -1)),
                M(t("div", Se, [
                  a(f, {
                    icon: "edit",
                    variant: "tertiary",
                    onClick: (S) => Z(V)
                  }, null, 8, ["onClick"]),
                  a(f, {
                    icon: "delete",
                    variant: "tertiary",
                    onClick: (S) => te(V)
                  }, null, 8, ["onClick"])
                ], 512), [
                  [j, V !== 0]
                ])
              ])
            ]),
            _: 2
          }, 1024))), 128)),
          t("div", null, [
            a(f, {
              label: e(m)("report.setting.reportHour.add"),
              variant: "secondary",
              icon: "add",
              "icon-position": "prepend",
              "border-color": e(G).ColorPrimary,
              "text-color": e(G).ColorPrimary,
              onClick: ee
            }, null, 8, ["label", "border-color", "text-color"])
          ])
        ])
      ]);
    };
  }
}), Fe = { class: "py-2 w-full gap-2 flex flex-col" }, Re = { class: "fm-typo-en-title-sm-600" }, we = /* @__PURE__ */ B({
  __name: "CompareRangeSetting",
  props: {
    modelValue: {
      required: !0,
      default: I.PRECEDING_PERIOD
    },
    modelModifiers: {}
  },
  emits: ["update:modelValue"],
  setup(T) {
    const { t: o } = U(), p = J(T, "modelValue"), l = Object.values(I).map((c) => ({
      label: o(`report.compare.${c}`),
      value: c
    })).slice(0, -1);
    return (c, n) => (x(), k("div", Fe, [
      t("p", Re, s(e(o)("report.setting.summary.comparisonDateRange")), 1),
      a(Y, {
        modelValue: p.value,
        "onUpdate:modelValue": n[0] || (n[0] = (D) => p.value = D),
        label: e(o)("report.setting.summary.comparisonDateRange"),
        items: e(l),
        "disable-search": !0
      }, null, 8, ["modelValue", "label", "items"])
    ]));
  }
}), He = { class: "py-2 w-full gap-2 flex flex-col" }, Oe = { class: "fm-typo-en-title-sm-600" }, Ne = /* @__PURE__ */ B({
  __name: "DateRangeSetting",
  props: {
    modelValue: { required: !0 },
    modelModifiers: {}
  },
  emits: ["update:modelValue"],
  setup(T) {
    const { t: o } = U(), p = J(T, "modelValue"), l = Object.values(pe).filter((c) => !["This month", "Last month"].includes(c)).map((c) => ({
      label: o(`report.date.${c}`),
      value: c
    }));
    return (c, n) => (x(), k("div", He, [
      t("p", Oe, s(e(o)("report.setting.summary.defaultDateRange")), 1),
      a(Y, {
        modelValue: p.value,
        "onUpdate:modelValue": n[0] || (n[0] = (D) => p.value = D),
        label: e(o)("report.setting.summary.defaultDateRange"),
        items: e(l),
        "disable-search": !0
      }, null, 8, ["modelValue", "label", "items"])
    ]));
  }
}), Be = { class: "w-2/4" }, Ue = { class: "fm-typo-en-title-sm-600" }, Ee = { class: "text-fm-color-typo-secondary" }, Pe = { class: "fm-typo-en-body-lg-600" }, Me = { class: "text-fm-color-typo-secondary" }, je = { class: "fm-typo-en-body-lg-600" }, Je = { class: "text-fm-color-typo-secondary" }, Le = { class: "fm-typo-en-body-lg-600" }, Ze = /* @__PURE__ */ B({
  __name: "Setting",
  setup(T) {
    const { breakpoints: o } = X(), p = ce(), { defaultDateSetting: l } = _e(p), c = W(), { t: n } = U();
    return me(
      [
        () => l.value.defaultCompareType,
        () => l.value.defaultDateRange,
        () => l.value.timeOptions
      ],
      () => {
        l.value.timeOptions.length === 0 ? c.open({ message: n("report.setting.reportHour.cannotBeEmptyError"), type: "error" }) : p.createOrUpdateBusinessSetting(l.value);
      },
      { deep: !0 }
    ), (D, b) => {
      const r = h("FmPageHead"), i = h("FmMenuDivider"), m = h("FmCard");
      return x(), P(de, null, {
        default: y(() => [
          a(r, {
            title: e(n)("report.view.setting.title")
          }, null, 8, ["title"]),
          t("div", {
            class: O(`${e(o).sm || e(o).xs ? "pb-20" : ""} overflow-y-auto flex`),
            style: ue({ height: `calc(100% - ${e(o).sm || e(o).xs ? 60 : 72}px)` })
          }, [
            t("div", {
              class: O(`${e(o).lg || e(o).md ? "px-24" : "px-3"} w-full flex flex-col gap-[40px]`)
            }, [
              a(ke, {
                modelValue: e(l).timeOptions,
                "onUpdate:modelValue": b[0] || (b[0] = (d) => e(l).timeOptions = d)
              }, null, 8, ["modelValue"]),
              a(Ne, {
                modelValue: e(l).defaultDateRange,
                "onUpdate:modelValue": b[1] || (b[1] = (d) => e(l).defaultDateRange = d)
              }, null, 8, ["modelValue"]),
              a(we, {
                modelValue: e(l).defaultCompareType,
                "onUpdate:modelValue": b[2] || (b[2] = (d) => e(l).defaultCompareType = d)
              }, null, 8, ["modelValue"])
            ], 2),
            M(t("div", Be, [
              a(m, {
                variant: "outlined",
                class: O(["flex flex-col gap-3", `${e(o).lg || e(o).md ? "mr-5 p-6" : ""}`])
              }, {
                default: y(() => [
                  t("p", Ue, s(e(n)("report.setting.summary.title")), 1),
                  a(i),
                  t("p", Ee, s(e(n)("report.setting.summary.reportHour")), 1),
                  (x(!0), k(K, null, Q(e(l).timeOptions, (d, R) => (x(), k("div", { key: R }, [
                    t("p", Pe, s(d.name) + s(d.isDefault ? `(${e(n)("report.setting.reportHour.default")})` : "") + " " + s(e(N)(d.startTime, e(F)())) + " " + s(e(N)(d.endTime, e(F)())) + " " + s(e(fe)(d.startTime, d.endTime)), 1)
                  ]))), 128)),
                  t("p", Me, s(e(n)("report.setting.summary.defaultDateRange")), 1),
                  t("p", je, s(e(n)(`report.date.${e(l).defaultDateRange}`)), 1),
                  t("p", Je, s(e(n)("report.setting.summary.comparisonDateRange")), 1),
                  t("p", Le, s(e(n)(`report.compare.${e(l).defaultCompareType}`)), 1)
                ]),
                _: 1
              }, 8, ["class"])
            ], 512), [
              [j, e(o).lg || e(o).md]
            ])
          ], 6)
        ]),
        _: 1
      });
    };
  }
});
export {
  Ze as default
};
