import { defineComponent as he, mergeModels as be, useModel as ye, ref as R, computed as N, resolveComponent as h, createBlock as T, openBlock as r, withCtx as p, createElementVNode as y, createVNode as a, unref as t, normalizeClass as ke, createTextVNode as Le, toDisplayString as X, createElementBlock as C, Fragment as ee, renderSlot as Xe, createCommentVNode as A, watch as ge, renderList as ce, resolveDynamicComponent as sl, isRef as Ye, normalizeStyle as He, onMounted as ul } from "vue";
import { W as ml, g as dl, _ as cl, a as pl, i as vl, S as Ae, d as Ge, T as fl, b as gl } from "./TransitionFade-C7Fleu7I.js";
import { C as fe, D as Q, b as Ve, u as Ze, a as bl, v as Oe } from "./BaseDialog.vue_vue_type_script_setup_true_lang-BQQb5IJd.js";
import { storeToRefs as Re } from "pinia";
import { useRouter as el, useRoute as ll } from "vue-router";
import { useBreakpoints as Ie, useSnackbar as tl, FmButtonColorThemeVariant as xe } from "@feedmepos/ui-library";
import { u as ol } from "./message-dialog-UoMWOnil.js";
import { u as Ne, a as yl } from "./vue-i18n-DVWuTfed.js";
import { r as $e } from "./i18n-CI_sQ5d_.js";
import { g as hl, a as Ke, _ as ze } from "./FilterSelector.vue_vue_type_script_setup_true_lang-DcMvhw0u.js";
import { _ as Ee } from "./NoData.vue_vue_type_script_setup_true_lang-CDKHIlF2.js";
import { a as Pe } from "./SelectComponent.vue_vue_type_script_setup_true_lang-Df40itH5.js";
import { a as _l, i as Je } from "./app-AiSMEgJb.js";
import { useCoreStore as wl } from "@feedmepos/mf-common";
const Fl = /* @__PURE__ */ he({
  __name: "WidgetDialog",
  props: /* @__PURE__ */ be({
    isOpen: { type: Boolean }
  }, {
    modelValue: {},
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ be(["update:isOpen"], ["update:modelValue"]),
  setup(M, { emit: n }) {
    const { t: i } = Ne(), { breakpoints: u } = Ie(), x = ye(M, "modelValue"), v = M, S = n;
    function z() {
      S("update:isOpen", !1);
    }
    function F() {
      s.value && (x.value = s.value, s.value = void 0, S("update:isOpen", !1));
    }
    const s = R(), B = N(() => !s.value);
    return (Y, D) => {
      const E = h("FmButton"), w = h("FmDialog");
      return r(), T(w, {
        "model-value": v.isOpen
      }, {
        "dialog-header": p(() => [
          Le(X(t(i)("report.widget.type")), 1)
        ]),
        default: p(() => [
          a(ml, {
            modelValue: s.value,
            "onUpdate:modelValue": D[0] || (D[0] = (V) => s.value = V),
            class: ke(`grid ${t(u).lg || t(u).md ? "grid-cols-3 gap-3" : "grid-cols-2 gap-3"}`),
            "child-class": "p-[8px] flex flex-col"
          }, null, 8, ["modelValue", "class"])
        ]),
        "dialog-footer": p(() => [
          D[1] || (D[1] = y("div", { class: "grow" }, null, -1)),
          a(E, {
            label: t(i)("report.common.cancel"),
            variant: "tertiary",
            onClick: z
          }, null, 8, ["label"]),
          a(E, {
            label: t(i)("report.common.confirm"),
            disabled: B.value,
            onClick: F
          }, null, 8, ["label", "disabled"])
        ]),
        _: 1
      }, 8, ["model-value"]);
    };
  }
}), Vl = { class: "fm-typo-en-body-lg-600" }, je = /* @__PURE__ */ he({
  __name: "ReportEditorTabHeader",
  props: /* @__PURE__ */ be({
    icon: {
      type: String,
      required: !0
    }
  }, {
    modelValue: { type: Boolean, required: !0, default: !1 },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(M) {
    const { t: n } = Ne(), i = ye(M, "modelValue"), u = M;
    return (x, v) => {
      const S = h("FmIcon");
      return r(), C("div", {
        class: "px-6 py-16 flex items-center gap-2 bg-fm-color-neutral-white border cursor-pointer",
        onClick: v[0] || (v[0] = (z) => i.value = !i.value)
      }, [
        y("p", Vl, X(t(n)("report.editor.customizeReport")), 1),
        v[1] || (v[1] = y("div", { class: "grow" }, null, -1)),
        a(S, {
          name: u.icon
        }, null, 8, ["name"])
      ]);
    };
  }
}), xl = /* @__PURE__ */ he({
  __name: "ReportEditorTabDesktop",
  props: {
    modelValue: { required: !0, default: !1 },
    modelModifiers: {}
  },
  emits: ["update:modelValue"],
  setup(M) {
    const n = ye(M, "modelValue");
    return (i, u) => (r(), C(ee, null, [
      a(je, {
        modelValue: n.value,
        "onUpdate:modelValue": u[0] || (u[0] = (x) => n.value = x),
        icon: "keyboard_double_arrow_left"
      }, null, 8, ["modelValue"]),
      Xe(i.$slots, "default")
    ], 64));
  }
}), kl = /* @__PURE__ */ he({
  __name: "ReportEditorTabMobile",
  props: {
    modelValue: { required: !0, default: !1 },
    modelModifiers: {}
  },
  emits: ["update:modelValue"],
  setup(M) {
    const n = ye(M, "modelValue");
    return (i, u) => {
      const x = h("FmTopSheet"), v = h("FmCard");
      return r(), T(v, { class: "fixed bottom-0 w-full" }, {
        default: p(() => [
          a(je, {
            modelValue: n.value,
            "onUpdate:modelValue": u[0] || (u[0] = (S) => n.value = S),
            icon: "keyboard_double_arrow_up"
          }, null, 8, ["modelValue"]),
          a(x, {
            modelValue: n.value,
            "onUpdate:modelValue": u[2] || (u[2] = (S) => n.value = S),
            "fullscreen-size": "sm"
          }, {
            default: p(() => [
              a(je, {
                modelValue: n.value,
                "onUpdate:modelValue": u[1] || (u[1] = (S) => n.value = S),
                icon: "keyboard_double_arrow_down"
              }, null, 8, ["modelValue"]),
              n.value ? Xe(i.$slots, "default", { key: 0 }) : A("", !0)
            ]),
            _: 3
          }, 8, ["modelValue"])
        ]),
        _: 3
      });
    };
  }
}), Cl = {
  key: 2,
  class: "flex flex-col gap-3 mt-2 border border-neutral-300 p-3"
}, Tl = { class: "grid grid-cols-1 gap-2 rounded-md border border-neutral-300 p-2 sm:grid-cols-[1.3fr_1fr_1fr_auto] sm:items-end" }, Sl = {
  key: 0,
  class: "flex justify-end sm:pb-[2px]"
}, Ol = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, $l = { class: "pl-1" }, Nl = {
  key: 0,
  class: "flex justify-end sm:pb-[2px]"
}, Ul = {
  key: 4,
  class: "flex flex-col gap-2"
}, Ml = /* @__PURE__ */ he({
  __name: "GlobalFilterDialog",
  props: /* @__PURE__ */ be({
    schemas: {
      type: Array,
      default: () => []
    },
    tiles: {
      type: Array,
      required: !0
    }
  }, {
    globalFilter: {
      default: () => null
    },
    globalFilterModifiers: {},
    isOpen: { type: Boolean, default: () => !1, required: !0 },
    isOpenModifiers: {}
  }),
  emits: ["update:globalFilter", "update:isOpen"],
  setup(M) {
    const { t: n, te: i } = Ne(), u = ye(M, "globalFilter"), x = ye(M, "isOpen"), v = tl(), S = M, z = R(""), F = R(), s = R(), B = R(), Y = R([]), D = R([]), E = R(""), w = R(!1), V = R(!1), O = R([]), U = R([]), L = R(fe.Equal);
    function oe(l) {
      return JSON.parse(JSON.stringify(l));
    }
    function f(l, e) {
      return { hour: l, minute: e };
    }
    function le(l) {
      return l ? `${String(l.hour).padStart(2, "0")}:${String(l.minute).padStart(2, "0")}` : null;
    }
    function _e(l) {
      if (!l) return null;
      const [e, c] = l.split(":").map(Number);
      return Number.isNaN(e) || Number.isNaN(c) ? null : { hour: e, minute: c };
    }
    const Z = N(() => s.value ? !(s.value.type === Q.Timestamp && B.value === Ve.DateTime) : !1), G = N(
      () => {
        var l;
        return ((l = s.value) == null ? void 0 : l.type) === Q.Timestamp && B.value === Ve.TimeOfDay;
      }
    ), ie = N(() => {
      var l;
      return (((l = s.value) == null ? void 0 : l.filterOperators) ?? []).filter((e) => e !== fe.And && e !== fe.Or).map((e) => ({
        label: n(`report.section.comparisonOperator.${e}`),
        value: e
      }));
    });
    function se() {
      var e;
      const l = (e = ie.value[0]) == null ? void 0 : e.value;
      return l || (s.value ? ve(s.value.type, B.value ?? null) : fe.Equal);
    }
    function pe(l) {
      if (s.value)
        return hl({
          operator: l ?? se(),
          dataType: s.value.type,
          dimensionOption: s.value.type === Q.Timestamp ? B.value ?? null : null,
          t: n
        });
    }
    function $(l, e) {
      if (typeof (e == null ? void 0 : e.default) == "boolean" || l.length > 0 && l.every((b) => typeof b == "boolean")) {
        const b = l.reduce((k, W) => (typeof W == "boolean" && k.push(W), k), []);
        if (e)
          for (e.fixed && b.splice(e.count); b.length < e.count; )
            b.push(typeof e.default == "boolean" ? e.default : !1);
        return b;
      }
      const d = l.reduce((b, k) => (typeof k == "string" && b.push(k), b), []);
      if (e)
        for (e.fixed && d.splice(e.count); d.length < e.count; )
          d.push(typeof e.default == "string" ? e.default : "");
      return d;
    }
    function I(l = L.value) {
      const e = pe(l), c = $(
        e ? Array(e.count).fill(e.default) : [],
        e
      );
      return {
        label: "",
        operator: l,
        values: c
      };
    }
    function P() {
      return {
        name: "",
        startTime: f(0, 0),
        endTime: f(23, 59)
      };
    }
    function ae() {
      if (!(!Z.value || !V.value)) {
        if (G.value) {
          U.value.length === 0 && (U.value = [P()]);
          return;
        }
        O.value.length === 0 && (O.value = [I()]);
      }
    }
    function Ce() {
      var c, d, b;
      const l = oe(((c = u.value) == null ? void 0 : c.customOptions) ?? []), e = oe(((d = u.value) == null ? void 0 : d.customTimeRanges) ?? []);
      L.value = ((b = l[0]) == null ? void 0 : b.operator) ?? se(), V.value = l.length > 0 || e.length > 0, O.value = l, U.value = e, ae();
    }
    function J(l) {
      L.value = l, O.value = O.value.map((e, c) => {
        const d = O.value[c];
        if (!d)
          return I(l);
        const b = pe(l), k = $(
          Array.isArray(d.values) ? [...d.values] : [],
          b
        );
        return {
          ...d,
          operator: l,
          values: k
        };
      });
    }
    function m() {
      O.value = [...O.value, I()];
    }
    function o(l) {
      O.value.length <= 1 || (O.value = O.value.filter((e, c) => c !== l));
    }
    function K() {
      U.value = [...U.value, P()];
    }
    function q(l) {
      U.value.length <= 1 || (U.value = U.value.filter(
        (e, c) => c !== l
      ));
    }
    function H(l, e, c) {
      const d = U.value[l];
      d && (U.value[l] = {
        ...d,
        [e]: _e(c)
      });
    }
    function ne(l) {
      return l.length === 0 || l.some((e) => e == null || e === "");
    }
    function Fe() {
      if (!V.value) return !0;
      if (G.value) {
        const c = U.value.map((b) => b.name.trim()).filter(Boolean);
        return U.value.some(
          (b) => !b.name.trim() || !b.startTime || !b.endTime
        ) ? (v.open({
          message: n("report.section.filter.invalidCustomTimeRange"),
          type: "error"
        }), !1) : new Set(c).size !== c.length ? (v.open({
          message: n("report.section.filter.customTimeRangeNamesMustBeUnique"),
          type: "error"
        }), !1) : !0;
      }
      const l = O.value.map((c) => c.label.trim()).filter(Boolean);
      return O.value.some(
        (c) => !c.label.trim() || ne(c.values)
      ) ? (v.open({ message: n("report.section.filter.invalidCustomOption"), type: "error" }), !1) : new Set(l).size !== l.length ? (v.open({
        message: n("report.section.filter.customOptionLabelsMustBeUnique"),
        type: "error"
      }), !1) : !0;
    }
    ge(x, (l) => {
      var e, c, d, b, k, W, me;
      l && (z.value = ((e = u.value) == null ? void 0 : e.label) || "", F.value = S.schemas.find(
        (de) => {
          var j;
          return de.name === ((j = u.value) == null ? void 0 : j.schemaName);
        }
      ), s.value = (c = Te.value.find(
        (de) => {
          var j;
          return de.value.name === ((j = u.value) == null ? void 0 : j.name);
        }
      )) == null ? void 0 : c.value, B.value = (d = u.value) == null ? void 0 : d.option, Y.value = ((b = u.value) == null ? void 0 : b.tileIds) || [], D.value = ((k = u.value) == null ? void 0 : k.filters) || [], w.value = !!((W = u.value) != null && W.dataFormula), E.value = ((me = u.value) == null ? void 0 : me.dataFormula) || "", Ce());
    }), ge(V, (l) => {
      var e;
      l && (L.value = ((e = O.value[0]) == null ? void 0 : e.operator) ?? se(), ae());
    }), ge(Z, (l) => {
      if (!l) {
        V.value = !1, O.value = [], U.value = [];
        return;
      }
      ae();
    }), ge(G, () => {
      ae();
    }), ge(ie, (l) => {
      var c;
      const e = (c = l[0]) == null ? void 0 : c.value;
      e && (l.some((d) => d.value === L.value) || J(e));
    });
    const we = N(
      () => S.schemas.map((l) => ({
        label: l.label || l.name,
        value: l
      }))
    ), Te = N(() => {
      var l;
      return (((l = F.value) == null ? void 0 : l.fields) || []).filter((e) => e.type !== Q.Numeric).map((e) => ({
        label: e.label || e.name,
        value: e
      }));
    }), Ue = N(() => {
      var l;
      return ((l = s.value) == null ? void 0 : l.type) !== Q.Timestamp ? [] : dl(n);
    }), Me = N(() => S.tiles.reduce((l, e, c) => {
      var k, W;
      const d = e.widget.config.schemaNames ?? [], b = (e.widget.config.joinDatasources ?? []).flatMap(
        (me) => me.schemaNames ?? []
      );
      return [...d, ...b].includes(((k = F.value) == null ? void 0 : k.name) || "") && l.push({
        label: (W = e == null ? void 0 : e.widget.title) != null && W.trim() ? e.widget.title : `Widget ${c + 1}`,
        value: e.id
      }), l;
    }, [])), Be = N(
      () => S.schemas.flatMap(
        (l) => (l.fields ?? []).map((e) => ({
          ...e,
          labels: [
            $e(n, i, l.label, "schema"),
            $e(n, i, e.label || e.name, "other")
          ]
        }))
      )
    );
    function qe(l) {
      var e;
      l.name !== ((e = F.value) == null ? void 0 : e.name) && (F.value = l, s.value = void 0, L.value = fe.Equal, V.value = !1, O.value = [], U.value = []);
    }
    function _(l) {
      s.value = l, B.value = l.type === Q.Timestamp ? Ve.DateTime : void 0, L.value = se(), V.value = !1, O.value = [], U.value = [];
    }
    function ve(l, e) {
      switch (l) {
        case Q.Timestamp:
          return e === Ve.DateTime || e === Ve.TimeOfDay ? fe.Between : fe.Equal;
        case Q.Bool:
        case Q.String:
        case Q.Numeric:
          return fe.Equal;
        default:
          throw new Error(`Unsupported data type: ${l}`);
      }
    }
    function ue() {
      if (!F.value) {
        v.open({ message: n("report.section.filter.invalidSchema"), type: "error" });
        return;
      }
      if (!s.value) {
        v.open({ message: n("report.section.filter.invalidDimension"), type: "error" });
        return;
      }
      const l = D.value.filter((d) => d ? !we.value.some((k) => k.value.name === d.schemaName) : !0);
      if (l.length > 0) {
        const d = l.filter((k) => !!k).map((k) => k.schemaName), b = l.some((k) => !k) ? `, ${n("report.section.filter.unknownFilters")}` : "";
        v.open({
          message: n("report.section.filter.invalidFiltersSchemaNotFound", {
            schemas: d.join(", "),
            unknownFiltersSuffix: b
          }),
          type: "error"
        });
        return;
      }
      if (!Fe())
        return;
      const e = V.value && !G.value ? O.value.map((d) => ({
        label: d.label.trim(),
        operator: d.operator ?? se(),
        values: $(
          [...d.values],
          pe(d.operator)
        )
      })) : void 0, c = V.value && G.value ? U.value.map((d) => ({
        name: d.name.trim(),
        startTime: d.startTime,
        endTime: d.endTime
      })) : void 0;
      u.value = {
        schemaName: F.value.name,
        name: s.value.name,
        label: z.value,
        operator: ve(
          s.value.type,
          s.value.type === Q.Timestamp ? B.value ?? Ve.DateTime : null
        ),
        option: s.value.type === Q.Timestamp ? B.value : null,
        values: [],
        tileIds: [...Y.value],
        filters: oe(D.value),
        dataFormula: w.value ? E.value : void 0,
        customOptions: e,
        customTimeRanges: c
      }, x.value = !1;
    }
    function Se() {
      x.value = !1;
    }
    const We = N(() => {
      var l;
      return [
        (l = F.value) == null ? void 0 : l.name,
        ...D.value.map((e) => e.schemaName)
      ];
    });
    function al(l) {
      var k, W, me, de;
      const e = S.tiles.find((j) => j.id === l.value), c = ((W = (k = e == null ? void 0 : e.widget) == null ? void 0 : k.config) == null ? void 0 : W.schemaNames) ?? [], d = (((de = (me = e == null ? void 0 : e.widget) == null ? void 0 : me.config) == null ? void 0 : de.joinDatasources) ?? []).flatMap(
        (j) => j.schemaNames ?? []
      ), b = [...c, ...d];
      return We.value.filter((j) => !!j).some((j) => !b.includes(j));
    }
    return (l, e) => {
      const c = h("FmTextField"), d = h("FmSelect"), b = h("FmCheckbox"), k = h("FmTimePicker"), W = h("FmButton"), me = h("FmTextarea"), de = h("FmLabel"), j = h("FmIcon"), nl = h("FmTooltip"), rl = h("FmForm"), il = h("FmDialog");
      return r(), T(il, {
        modelValue: x.value,
        "onUpdate:modelValue": e[11] || (e[11] = (De) => x.value = De),
        overlay: !0,
        "z-index": 10
      }, {
        "dialog-header": p(() => [
          Le(X(t(n)("report.section.filter.globalFilter")), 1)
        ]),
        default: p(() => [
          a(rl, {
            ref: "form",
            class: "flex flex-col gap-2 w-[490px]"
          }, {
            default: p(() => {
              var De;
              return [
                a(c, {
                  modelValue: z.value,
                  "onUpdate:modelValue": e[0] || (e[0] = (g) => z.value = g),
                  placeholder: t(n)("report.section.filter.displayName"),
                  label: t(n)("report.section.filter.displayName"),
                  class: "mb-2"
                }, null, 8, ["modelValue", "placeholder", "label"]),
                a(Pe, {
                  "model-value": F.value,
                  items: we.value,
                  placeholder: t(n)("report.section.schema.title"),
                  label: t(n)("report.section.schema.title"),
                  "onUpdate:modelValue": e[1] || (e[1] = (g) => qe(g))
                }, null, 8, ["model-value", "items", "placeholder", "label"]),
                a(Pe, {
                  "model-value": s.value,
                  items: Te.value,
                  placeholder: t(n)("report.section.dimension.title"),
                  label: t(n)("report.section.dimension.title"),
                  "onUpdate:modelValue": e[2] || (e[2] = (g) => _(g))
                }, null, 8, ["model-value", "items", "placeholder", "label"]),
                ((De = s.value) == null ? void 0 : De.type) === t(Q).Timestamp ? (r(), T(d, {
                  key: 0,
                  modelValue: B.value,
                  "onUpdate:modelValue": e[3] || (e[3] = (g) => B.value = g),
                  items: Ue.value,
                  placeholder: t(n)("report.section.filter.timeFormatter"),
                  label: t(n)("report.section.filter.timeFormatter")
                }, null, 8, ["modelValue", "items", "placeholder", "label"])) : A("", !0),
                Z.value ? (r(), T(b, {
                  key: 1,
                  modelValue: V.value,
                  "onUpdate:modelValue": e[4] || (e[4] = (g) => V.value = g),
                  label: t(n)("report.section.filter.customOptions"),
                  value: !0
                }, null, 8, ["modelValue", "label"])) : A("", !0),
                Z.value && V.value ? (r(), C("div", Cl, [
                  G.value ? (r(!0), C(ee, { key: 0 }, ce(U.value, (g, re) => (r(), C("div", {
                    key: `custom-time-range-${re}`,
                    class: "flex flex-col gap-2"
                  }, [
                    y("div", Tl, [
                      a(c, {
                        modelValue: g.name,
                        "onUpdate:modelValue": (te) => g.name = te,
                        label: t(n)("report.section.filter.label")
                      }, null, 8, ["modelValue", "onUpdate:modelValue", "label"]),
                      a(k, {
                        "model-value": le(g.startTime),
                        label: t(n)("report.date.startingTime"),
                        "onUpdate:modelValue": (te) => H(re, "startTime", te)
                      }, null, 8, ["model-value", "label", "onUpdate:modelValue"]),
                      a(k, {
                        "model-value": le(g.endTime),
                        label: t(n)("report.date.endingTime"),
                        "onUpdate:modelValue": (te) => H(re, "endTime", te)
                      }, null, 8, ["model-value", "label", "onUpdate:modelValue"]),
                      U.value.length > 1 ? (r(), C("div", Sl, [
                        a(W, {
                          icon: "delete",
                          variant: "tertiary",
                          onClick: (te) => q(re)
                        }, null, 8, ["onClick"])
                      ])) : A("", !0)
                    ])
                  ]))), 128)) : (r(), C(ee, { key: 1 }, [
                    y("p", Ol, X(t(n)("report.section.filter.operator")), 1),
                    ie.value.length > 0 ? (r(), T(Pe, {
                      key: 0,
                      "model-value": L.value,
                      items: ie.value,
                      placeholder: t(n)("report.section.filter.operator"),
                      "onUpdate:modelValue": e[5] || (e[5] = (g) => J(g))
                    }, null, 8, ["model-value", "items", "placeholder"])) : A("", !0),
                    (r(!0), C(ee, null, ce(O.value, (g, re) => (r(), C("div", {
                      key: `custom-option-${re}`,
                      class: "flex flex-col gap-2"
                    }, [
                      y("div", {
                        class: ke([
                          "grid grid-cols-1 gap-2 p-2 sm:items-end text-fm-color-typo-primary fm-typo-en-body-lg-600 border-neutral-300 rounded-md border",
                          "sm:grid-cols-[1fr_1.6fr_auto]"
                        ])
                      }, [
                        y("span", $l, X(t(n)("report.section.filter.label")), 1),
                        a(c, {
                          modelValue: g.label,
                          "onUpdate:modelValue": (te) => g.label = te
                        }, null, 8, ["modelValue", "onUpdate:modelValue"]),
                        (r(), T(cl, {
                          key: `custom-option-value-${re}-${g.operator ?? ""}-${B.value ?? ""}`,
                          modelValue: g.values,
                          "onUpdate:modelValue": (te) => g.values = te,
                          config: pe(g.operator),
                          option: B.value
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "config", "option"])),
                        O.value.length > 1 ? (r(), C("div", Nl, [
                          a(W, {
                            icon: "delete",
                            variant: "tertiary",
                            onClick: (te) => o(re)
                          }, null, 8, ["onClick"])
                        ])) : A("", !0)
                      ])
                    ]))), 128))
                  ], 64)),
                  a(W, {
                    class: "w-full",
                    variant: "primary",
                    icon: "add",
                    "icon-position": "prepend",
                    onClick: e[6] || (e[6] = (g) => G.value ? K() : m())
                  })
                ])) : A("", !0),
                a(b, {
                  modelValue: w.value,
                  "onUpdate:modelValue": e[7] || (e[7] = (g) => w.value = g),
                  label: t(n)("report.section.filter.advance"),
                  value: !0
                }, null, 8, ["modelValue", "label"]),
                w.value ? (r(), T(me, {
                  key: 3,
                  modelValue: E.value,
                  "onUpdate:modelValue": e[8] || (e[8] = (g) => E.value = g),
                  placeholder: t(n)("report.section.filter.dataFormula")
                }, null, 8, ["modelValue", "placeholder"])) : A("", !0),
                a(pl, {
                  modelValue: D.value,
                  "onUpdate:modelValue": e[9] || (e[9] = (g) => D.value = g),
                  options: Be.value
                }, null, 8, ["modelValue", "options"]),
                a(de, { class: "mt-2 fm-typo-en-body-lg-600" }, {
                  default: p(() => [
                    Le(X(t(n)("report.section.filter.applyWidget")), 1)
                  ]),
                  _: 1
                }),
                M.tiles.length > 0 ? (r(), C("div", Ul, [
                  (r(!0), C(ee, null, ce(Me.value, (g) => (r(), C("div", {
                    key: g.value,
                    class: "flex items-center"
                  }, [
                    a(b, {
                      modelValue: Y.value,
                      "onUpdate:modelValue": e[10] || (e[10] = (re) => Y.value = re),
                      label: g.label,
                      value: g.value
                    }, null, 8, ["modelValue", "label", "value"]),
                    al(g) ? (r(), T(nl, {
                      key: 0,
                      content: t(n)("report.section.filter.missingFilterSchema"),
                      "z-index": 99,
                      class: "ml-2"
                    }, {
                      default: p(() => [
                        a(j, {
                          name: "warning",
                          class: "text-fm-color-system-error-300"
                        })
                      ]),
                      _: 1
                    }, 8, ["content"])) : A("", !0)
                  ]))), 128))
                ])) : (r(), T(de, {
                  key: 5,
                  class: "fm-typo-en-body-lg-400",
                  label: t(n)("report.section.filter.noWidget")
                }, null, 8, ["label"]))
              ];
            }),
            _: 1
          }, 512)
        ]),
        "dialog-footer": p(() => [
          e[12] || (e[12] = y("div", { class: "grow" }, null, -1)),
          a(W, {
            label: t(n)("report.common.cancel"),
            variant: "tertiary",
            onClick: Se
          }, null, 8, ["label"]),
          a(W, {
            label: t(n)("report.common.confirm"),
            onClick: ue
          }, null, 8, ["label"])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
}), Bl = { class: "flex flex-col gap-24 top-0 bg-fm-color-neutral-white z-10" }, Dl = { class: "flex items-center gap-8" }, Rl = { class: "flex flex-col gap-24 top-0 bg-fm-color-neutral-white z-10" }, Il = { class: "flex items-center gap-1 max-w-[195px] w-[195px]" }, ql = { class: "line-clamp-2 overflow-hidden max-w-[195px] w-[195px]" }, Wl = { class: "flex flex-col gap-24" }, zl = { class: "line-clamp-2 overflow-hidden max-w-[195px] w-[195px]" }, Qe = /* @__PURE__ */ he({
  __name: "ReportEditorTab",
  props: /* @__PURE__ */ be({
    hideConfiguration: {
      type: Boolean,
      default: !1
    }
  }, {
    modelValue: { required: !0 },
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ be(["hideConfiguration"], ["update:modelValue"]),
  setup(M, { emit: n }) {
    const i = ye(M, "modelValue"), { breakpoints: u } = Ie(), x = M, v = n, S = el(), z = ll(), F = R(), {
      currentSelectWidgetType: s,
      categories: B,
      editingTile: Y,
      editingTileIndex: D,
      editingGlobalFilter: E,
      editingGlobalFilterIndex: w
    } = Re(Ze()), { schemas: V } = Re(bl()), { globalFilters: O } = Re(_l()), { promptMessage: U } = ol(), L = R(!1), oe = R(!1), { t: f, te: le, locale: _e } = Ne(), Z = R(void 0), G = N(() => {
      const m = i.value.tiles.flatMap((o) => {
        var H;
        const K = o.widget.config.schemaNames ?? [], q = ((H = o.widget.config.joinDatasources) == null ? void 0 : H.flatMap((ne) => ne.schemaNames ?? [])) ?? [];
        return [...K, ...q];
      });
      return [...new Set(m)].reduce((o, K) => {
        const q = V.value.find((H) => H.name === K);
        return q && o.push(q), o;
      }, []);
    });
    function ie(m) {
      if (!m) return "";
      const o = `report.widget.types.${m.toLowerCase()}`;
      return le(o) ? f(o) : $e(f, le, m, "other");
    }
    ge(
      () => s.value,
      () => {
        s.value !== void 0 && (Z.value = vl(s.value), Y.value = Z.value, D.value = -1, S.push({
          name: "tileEditor",
          query: z.query
        }));
      },
      { immediate: !0 }
    ), ge(
      () => i.value.tiles,
      (m) => {
        m.forEach((o) => {
          o.id || (o.id = Oe());
        });
      },
      { immediate: !0, deep: !0 }
    );
    const se = [
      {
        label: "report.common.edit",
        selected: !1,
        variant: "tertiary",
        onClick: (m) => {
          D.value = m, Y.value = JSON.parse(JSON.stringify(i.value.tiles[m])), S.push({
            name: "tileEditor",
            query: z.query
          });
        }
      },
      {
        label: "report.common.duplicate",
        selected: !1,
        variant: "tertiary",
        onClick: (m) => {
          const o = {
            ...JSON.parse(JSON.stringify(i.value.tiles[m])),
            id: Oe()
          };
          i.value.tiles.push(o);
        }
      },
      {
        label: "report.common.remove",
        selected: !1,
        variant: "destructive",
        onClick: async (m) => {
          if (await U({
            title: f("report.editor.deleteWidget"),
            message: f("report.editor.deleteWidgetConfirm", {
              title: i.value.tiles[m].widget.title
            })
          })) {
            const K = i.value.tiles[m].id;
            i.value.tiles.splice(m, 1), i.value.globalFilters && i.value.globalFilters.forEach((q) => {
              var H;
              q.tileIds = (H = q.tileIds) == null ? void 0 : H.filter((ne) => ne !== K);
            });
          }
        }
      }
    ], pe = [
      {
        label: "report.common.edit",
        selected: !1,
        variant: "tertiary",
        onClick: (m) => {
          var o;
          w.value = m, E.value = JSON.parse(JSON.stringify((o = i.value.globalFilters) == null ? void 0 : o[m])), L.value = !0;
        }
      },
      {
        label: "report.common.duplicate",
        selected: !1,
        variant: "tertiary",
        onClick: (m) => {
          var q;
          const o = (q = i.value.globalFilters) == null ? void 0 : q[m];
          if (!o) return;
          const K = JSON.parse(JSON.stringify(o));
          i.value.globalFilters || (i.value.globalFilters = []), i.value.globalFilters.push(K);
        }
      },
      {
        label: "report.common.remove",
        selected: !1,
        variant: "destructive",
        onClick: async (m) => {
          var q, H;
          const o = (q = i.value.globalFilters) == null ? void 0 : q[m];
          if (!o) return;
          await U({
            title: f("report.editor.deleteWidget"),
            message: f("report.editor.deleteWidgetConfirm", {
              title: Je(o)
            })
          }) && ((H = i.value.globalFilters) == null || H.splice(m, 1));
        }
      }
    ], $ = N(() => B.value.map((m) => ({
      label: f(`report.category.${m.name}`),
      value: m.id
    }))), { sessionUser: I } = wl(), P = N({
      get: () => i.value.queryVersion === "v2",
      set: (m) => {
        i.value.queryVersion = m ? "v2" : "v1";
      }
    }), ae = N({
      get: () => $e(f, le, i.value.name, "other"),
      set: (m) => {
        i.value.name = m;
      }
    });
    function Ce(m) {
      var o;
      return !((o = m.tileIds) != null && o.length);
    }
    function J(m) {
      return !G.value.find((o) => o.name === m.schemaName);
    }
    return ge(
      () => i.value.globalFilters,
      (m) => {
        O.value = JSON.parse(JSON.stringify(m || []));
      },
      { deep: !0, immediate: !0 }
    ), (m, o) => {
      const K = h("FmTextField"), q = h("FmSelect"), H = h("FmSwitch"), ne = h("FmButton"), Fe = h("FmIcon"), we = h("FmTooltip"), Te = h("FmMenuItem"), Ue = h("FmMenu"), Me = h("FmListItem"), Be = h("FmList"), qe = h("FmForm");
      return r(), T(sl(t(u).lg || t(u).md ? xl : kl), {
        "model-value": x.hideConfiguration,
        "onUpdate:modelValue": o[10] || (o[10] = (_) => v("hideConfiguration", _))
      }, {
        default: p(() => [
          a(Ml, {
            "is-open": L.value,
            "onUpdate:isOpen": o[0] || (o[0] = (_) => L.value = _),
            "global-filter": t(E),
            tiles: i.value.tiles,
            schemas: G.value,
            "onUpdate:globalFilter": o[1] || (o[1] = (_) => {
              _ && (i.value.globalFilters || (i.value.globalFilters = []), typeof t(w) == "number" && t(w) >= 0 ? i.value.globalFilters[t(w)] = _ : i.value.globalFilters.push(_));
            })
          }, null, 8, ["is-open", "global-filter", "tiles", "schemas"]),
          a(Fl, {
            modelValue: t(s),
            "onUpdate:modelValue": o[2] || (o[2] = (_) => Ye(s) ? s.value = _ : null),
            "is-open": oe.value,
            "onUpdate:isOpen": o[3] || (o[3] = (_) => oe.value = _)
          }, null, 8, ["modelValue", "is-open"]),
          a(qe, {
            ref_key: "form",
            ref: F,
            class: "px-6 py-16 flex flex-col gap-24 overflow-y-auto overflow-x-hidden"
          }, {
            default: p(() => [
              a(Ae, { class: "border-solid" }, {
                header: p(() => [
                  y("p", null, X(t(f)("report.editor.reportInfo")), 1),
                  o[11] || (o[11] = y("div", { class: "grow" }, null, -1))
                ]),
                content: p(() => [
                  y("div", Bl, [
                    a(K, {
                      modelValue: ae.value,
                      "onUpdate:modelValue": o[4] || (o[4] = (_) => ae.value = _),
                      label: t(f)("report.common.name"),
                      placeholder: t(f)("report.common.name")
                    }, null, 8, ["modelValue", "label", "placeholder"]),
                    (r(), T(q, {
                      modelValue: i.value.category,
                      "onUpdate:modelValue": o[5] || (o[5] = (_) => i.value.category = _),
                      label: t(f)("report.common.category"),
                      items: $.value,
                      key: `category-${t(_e)}`
                    }, null, 8, ["modelValue", "label", "items"])),
                    a(K, {
                      modelValue: i.value.description,
                      "onUpdate:modelValue": o[6] || (o[6] = (_) => i.value.description = _),
                      label: t(f)("report.common.description"),
                      placeholder: t(f)("report.common.description")
                    }, null, 8, ["modelValue", "label", "placeholder"]),
                    y("div", Dl, [
                      o[12] || (o[12] = y("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, "V2", -1)),
                      a(H, {
                        modelValue: P.value,
                        "onUpdate:modelValue": o[7] || (o[7] = (_) => P.value = _)
                      }, null, 8, ["modelValue"])
                    ])
                  ])
                ]),
                _: 1
              }),
              a(Ae, {
                class: "border-solid",
                "is-open": !1
              }, {
                header: p(() => [
                  y("p", null, X(t(f)("report.section.filter.globalFilter")), 1),
                  o[13] || (o[13] = y("div", { class: "grow" }, null, -1))
                ]),
                content: p(() => [
                  y("div", Rl, [
                    a(ne, {
                      label: t(f)("report.section.filter.addGlobalFilter"),
                      variant: "secondary",
                      icon: "add",
                      "icon-position": "prepend",
                      "border-color": t(xe).ColorPrimary,
                      "text-color": t(xe).ColorPrimary,
                      onClick: o[8] || (o[8] = () => {
                        w.value = null, E.value = null, L.value = !0;
                      })
                    }, null, 8, ["label", "border-color", "text-color"]),
                    a(Be, null, {
                      default: p(() => [
                        a(t(Ge), {
                          list: i.value.globalFilters,
                          "item-key": "`${element.schemaName}-${element.name}`",
                          class: "flex flex-col gap-2 cursor-grab",
                          handle: ".handle"
                        }, {
                          item: p(({ element: _, index: ve }) => [
                            a(Me, { class: "!cursor-grab border rounded-md border-neutral-300" }, {
                              default: p(() => [
                                a(Fe, {
                                  name: "drag_handle",
                                  class: "handle"
                                }),
                                y("div", Il, [
                                  a(we, {
                                    "z-index": 99,
                                    content: t(Je)(_),
                                    class: "handle"
                                  }, {
                                    default: p(() => [
                                      y("p", ql, X(t(Je)(_)), 1)
                                    ]),
                                    _: 2
                                  }, 1032, ["content"]),
                                  J(_) ? (r(), T(we, {
                                    key: 0,
                                    content: t(f)("report.section.filter.missingSchema"),
                                    "z-index": 99
                                  }, {
                                    default: p(() => [
                                      a(Fe, {
                                        name: "warning",
                                        class: "text-fm-color-system-error-300"
                                      })
                                    ]),
                                    _: 1
                                  }, 8, ["content"])) : Ce(_) ? (r(), T(we, {
                                    key: 1,
                                    content: t(f)("report.section.filter.missingTileIds"),
                                    "z-index": 99
                                  }, {
                                    default: p(() => [
                                      a(Fe, {
                                        name: "warning",
                                        class: "text-fm-color-system-warning-300"
                                      })
                                    ]),
                                    _: 1
                                  }, 8, ["content"])) : A("", !0)
                                ]),
                                o[14] || (o[14] = y("div", { class: "grow" }, null, -1)),
                                a(Ue, {
                                  trigger: "click",
                                  shift: !0,
                                  "stop-click-propagation": !0
                                }, {
                                  "menu-button": p(() => [
                                    a(ne, {
                                      "append-icon": "more_vert",
                                      variant: "tertiary"
                                    })
                                  ]),
                                  default: p(() => [
                                    (r(), C(ee, null, ce(pe, (ue, Se) => a(Te, {
                                      key: Se,
                                      onClick: (We) => ue.onClick(ve)
                                    }, {
                                      label: p(() => [
                                        y("p", {
                                          class: ke(
                                            ue.variant === "destructive" ? " text-fm-color-system-error-300" : ""
                                          )
                                        }, X(t(f)(ue.label)), 3)
                                      ]),
                                      _: 2
                                    }, 1032, ["onClick"])), 64))
                                  ]),
                                  _: 2
                                }, 1024)
                              ]),
                              _: 2
                            }, 1024)
                          ]),
                          _: 1
                        }, 8, ["list"])
                      ]),
                      _: 1
                    })
                  ])
                ]),
                _: 1
              }),
              y("div", Wl, [
                a(ne, {
                  label: t(f)("report.editor.addWidget"),
                  variant: "secondary",
                  icon: "add",
                  "icon-position": "prepend",
                  "border-color": t(xe).ColorPrimary,
                  "text-color": t(xe).ColorPrimary,
                  onClick: o[9] || (o[9] = (_) => oe.value = !0)
                }, null, 8, ["label", "border-color", "text-color"]),
                a(Be, null, {
                  default: p(() => [
                    a(t(Ge), {
                      list: i.value.tiles,
                      "item-key": "id",
                      class: "flex flex-col gap-2 cursor-grab",
                      handle: ".handle"
                    }, {
                      item: p(({ element: _, index: ve }) => [
                        a(Me, { class: "!cursor-grab border rounded-md border-neutral-300" }, {
                          default: p(() => [
                            a(Fe, {
                              name: "drag_handle",
                              class: "handle"
                            }),
                            a(we, {
                              content: _.widget.title ? ie(_.widget.title) : t(f)("report.editor.widget", { index: ve + 1 }),
                              class: "handle"
                            }, {
                              default: p(() => [
                                y("p", zl, X(_.widget.title ? ie(_.widget.title) : t(f)("report.editor.widget", { index: ve + 1 })), 1)
                              ]),
                              _: 2
                            }, 1032, ["content"]),
                            o[15] || (o[15] = y("div", { class: "grow" }, null, -1)),
                            a(Ue, {
                              trigger: "click",
                              shift: !0,
                              "stop-click-propagation": !0
                            }, {
                              "menu-button": p(() => [
                                a(ne, {
                                  "append-icon": "more_vert",
                                  variant: "tertiary"
                                })
                              ]),
                              default: p(() => [
                                (r(), C(ee, null, ce(se, (ue, Se) => a(Te, {
                                  key: Se,
                                  onClick: (We) => ue.onClick(ve)
                                }, {
                                  label: p(() => [
                                    y("p", {
                                      class: ke(
                                        ue.variant === "destructive" ? " text-fm-color-system-error-300" : ""
                                      )
                                    }, X(t(f)(ue.label)), 3)
                                  ]),
                                  _: 2
                                }, 1032, ["onClick"])), 64))
                              ]),
                              _: 2
                            }, 1024)
                          ]),
                          _: 2
                        }, 1024)
                      ]),
                      _: 1
                    }, 8, ["list"])
                  ]),
                  _: 1
                })
              ])
            ]),
            _: 1
          }, 512)
        ]),
        _: 1
      }, 8, ["model-value"]);
    };
  }
}), El = { class: "h-full w-full overflow-x-hidden" }, Pl = { class: "flex flex-col bg-fm-color-neutral-white w-[400px]" }, Jl = { class: "flex bg-fm-color-neutral-white w-[88px]" }, Ll = {
  key: 1,
  class: "w-full overflow-y-auto"
}, Hl = {
  key: 0,
  class: "w-full grid grid-cols-12 gap-[24px] p-24"
}, jl = { class: "col-span-12 mb-4 flex flex-wrap gap-2 pb-2" }, Al = { key: 2 }, Gl = {
  key: 0,
  class: "grid grid-cols-12 gap-[16px]"
}, Kl = { class: "col-span-12 mb-4 flex flex-wrap gap-2 pb-2" }, Ql = {
  key: 3,
  class: "h-full w-full flex items-start justify-center bg-fm-color-neutral-white py-24",
  style: { backgroundColor: "#F6F8FC" }
}, Xl = {
  key: 0,
  class: "w-full grid grid-cols-12 gap-[24px] p-24"
}, Yl = /* @__PURE__ */ he({
  __name: "ReportEditorViewport",
  props: /* @__PURE__ */ be({
    hideConfiguration: { type: Boolean, required: !1, default: !1 },
    previewWidth: { type: Number, required: !0 },
    previewHeight: { type: Number, required: !0 },
    previewScale: { type: Number, required: !0 }
  }, {
    modelValue: { required: !0, default: () => {
    } },
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ be(["hideConfiguration"], ["update:modelValue"]),
  setup(M, { emit: n }) {
    const { breakpoints: i } = Ie(), u = ye(M, "modelValue"), x = M, v = N(() => x.previewWidth > 0 && x.previewHeight > 0), S = N(() => i.value.sm || i.value.xs), z = n;
    return (F, s) => {
      const B = h("FmCircularProgress"), Y = h("FmButton"), D = h("FmMenuDivider"), E = h("FmCard");
      return r(), C("div", El, [
        u.value ? (r(), C(ee, { key: 1 }, [
          v.value ? A("", !0) : (r(), T(fl, {
            key: 0,
            "model-value": !x.hideConfiguration
          }, {
            right: p(() => [
              y("div", Pl, [
                u.value ? (r(), T(Qe, {
                  key: 0,
                  modelValue: u.value,
                  "onUpdate:modelValue": s[0] || (s[0] = (w) => u.value = w),
                  "hide-configuration": x.hideConfiguration,
                  onHideConfiguration: s[1] || (s[1] = (w) => z("hideConfiguration", w))
                }, null, 8, ["modelValue", "hide-configuration"])) : A("", !0)
              ])
            ]),
            left: p(() => [
              y("div", Jl, [
                a(Y, {
                  variant: "secondary",
                  icon: "keyboard_double_arrow_right",
                  "border-color": t(xe).ColorPrimary,
                  "text-color": t(xe).ColorPrimary,
                  class: "m-24 my-16",
                  size: "md",
                  onClick: s[2] || (s[2] = (w) => z("hideConfiguration", !x.hideConfiguration))
                }, null, 8, ["border-color", "text-color"])
              ])
            ]),
            _: 1
          }, 8, ["model-value"])),
          a(D, {
            vertical: "",
            style: { margin: "0px" }
          }),
          !S.value && !v.value ? (r(), C("div", Ll, [
            u.value.tiles.length > 0 ? (r(), C("div", Hl, [
              y("div", jl, [
                a(Ke)
              ]),
              (r(!0), C(ee, null, ce(u.value.tiles, (w, V) => (r(), T(ze, {
                key: `${t(Oe)()}_${V}`,
                "model-value": w,
                index: V,
                "hide-export": !0
              }, null, 8, ["model-value", "index"]))), 128))
            ])) : (r(), T(Ee, { key: 1 }))
          ])) : S.value && !v.value ? (r(), C("div", Al, [
            a(E, { class: "px-5 pb-28" }, {
              default: p(() => [
                u.value.tiles.length > 0 ? (r(), C("div", Gl, [
                  y("div", Kl, [
                    a(Ke)
                  ]),
                  (r(!0), C(ee, null, ce(u.value.tiles, (w, V) => (r(), T(ze, {
                    key: `${t(Oe)()}_${V}`,
                    "model-value": w,
                    index: V,
                    "hide-export": !0
                  }, null, 8, ["model-value", "index"]))), 128))
                ])) : (r(), T(Ee, { key: 1 }))
              ]),
              _: 1
            }),
            u.value ? (r(), T(Qe, {
              key: 0,
              modelValue: u.value,
              "onUpdate:modelValue": s[3] || (s[3] = (w) => u.value = w),
              "hide-configuration": x.hideConfiguration,
              onHideConfiguration: s[4] || (s[4] = (w) => {
                z("hideConfiguration", w);
              })
            }, null, 8, ["modelValue", "hide-configuration"])) : A("", !0)
          ])) : (r(), C("div", Ql, [
            y("div", {
              style: He({
                transformOrigin: "top center",
                transform: `scale(${x.previewScale})`
              })
            }, [
              y("div", {
                class: "overflow-y-auto bg-white rounded-lg",
                style: He({
                  width: x.previewWidth + "px",
                  height: x.previewHeight + "px"
                })
              }, [
                u.value.tiles.length > 0 ? (r(), C("div", Xl, [
                  (r(!0), C(ee, null, ce(u.value.tiles, (w, V) => (r(), T(ze, {
                    key: `${t(Oe)()}_${V}`,
                    "model-value": w,
                    index: V,
                    "hide-export": !0,
                    "custom-screen-width": x.previewWidth
                  }, null, 8, ["model-value", "index", "custom-screen-width"]))), 128))
                ])) : (r(), T(Ee, { key: 1 }))
              ], 4)
            ], 4)
          ]))
        ], 64)) : (r(), T(B, { key: 0 }))
      ]);
    };
  }
}), Zl = { class: "flex items-center gap-4" }, et = { class: "flex justify-center items-center gap-2 w-full" }, lt = { class: "flex gap-4" }, gt = /* @__PURE__ */ he({
  __name: "ReportEditor",
  setup(M) {
    const n = el(), i = ll(), u = Ze(), { promptLoader: x } = yl(), { t: v, te: S } = Ne(), { currentReport: z, editingReport: F } = Re(u), { breakpoints: s } = Ie(), B = N(() => {
      var $;
      return !(($ = F.value) != null && $.editable);
    }), Y = N(() => {
      var $;
      return (($ = F.value) == null ? void 0 : $.name) ?? v("report.editor.newReport");
    }), D = N(() => $e(v, S, Y.value, "other")), E = tl(), { promptMessage: w } = ol(), V = R(!1), O = N(() => [
      { label: v("report.common.cancel"), value: "cancel", isPrimary: !1 },
      { label: v("report.common.save"), value: "save", isPrimary: !0, prependIcon: "download" }
    ]);
    async function U() {
      if (!F.value || F.value.tiles.length === 0) {
        E.open({ message: v("report.messages.noWidget"), type: "error" });
        return;
      }
      const $ = B.value ? v("report.common.clone") : v("report.common.save");
      if (await w({
        title: `${v("report.messages.saveReport")}`,
        message: v("report.messages.confirmAction", { action: $, name: D.value })
      }))
        try {
          await x(async () => {
            if (B.value) {
              const P = JSON.parse(JSON.stringify(F.value));
              P.editable = !0, P.id = "", P.name = `${P.name} ${v("report.common.duplicate")}`, P.isDefault = !1, await u.createOrUpdateReport(P);
            } else
              F.value && await u.createOrUpdateReport(F.value);
            n.push({
              name: "reportView",
              query: i.query
            });
          });
        } catch (P) {
          console.log(P), E.open({
            message: v("report.messages.failedToAction", { action: $ }),
            type: "error"
          });
        }
    }
    async function L() {
      var I;
      if (!F.value) return;
      await w({
        title: v("report.common.report", 1),
        message: v("report.editor.notSaved", { name: (I = F.value) == null ? void 0 : I.name })
      }) && (F.value = JSON.parse(JSON.stringify(z.value)), n.back());
    }
    ul(() => {
      F.value || n.push({ name: "reports" });
    });
    const oe = [
      {
        labelKey: "report.common.default",
        width: void 0,
        height: void 0
      },
      {
        labelKey: "report.editor.devices.desktop",
        width: 1920,
        height: 1080
      },
      {
        labelKey: "report.editor.devices.tablet",
        width: 820,
        height: 1180
      },
      {
        labelKey: "report.editor.devices.phone",
        width: 390,
        height: 859
      }
    ], f = R(oe[0]), le = R(!1), _e = N(() => le.value ? Math.max(f.value.width || 0, f.value.height || 0) : Math.min(f.value.width || 0, f.value.height || 0)), Z = N(() => le.value ? Math.min(f.value.width || 0, f.value.height || 0) : Math.max(f.value.width || 0, f.value.height || 0)), G = N(() => window.innerHeight - 72 - 56), ie = N(() => {
      if (!_e.value) return 1;
      let $ = (G.value - 48) / _e.value, I = Z.value * $;
      return I > window.innerWidth && ($ = window.innerWidth / Z.value, I = Z.value * $), $ > 1 ? 1 : $;
    });
    function se($) {
      f.value = $;
    }
    function pe() {
      le.value = !le.value;
    }
    return ($, I) => {
      const P = h("FmTooltip"), ae = h("FmButton"), Ce = h("FmPageHead");
      return r(), T(gl, null, {
        default: p(() => [
          a(Ce, {
            "data-editor-header": "true",
            actions: O.value,
            "onClick:action": I[0] || (I[0] = (J) => {
              J === "cancel" && L(), J === "save" && U();
            })
          }, {
            title: p(() => [
              y("div", Zl, [
                a(P, {
                  content: D.value,
                  placement: "bottom"
                }, {
                  default: p(() => [
                    y("p", {
                      class: ke(`${t(s).sm || t(s).xs ? "hidden" : ""} text-ellipsis overflow-hidden text-nowrap fm-typo-en-title-md-600 w-[250px]`)
                    }, X(D.value), 3)
                  ]),
                  _: 1
                }, 8, ["content"]),
                y("div", et, [
                  y("div", lt, [
                    (r(), C(ee, null, ce(oe, (J) => {
                      var m;
                      return a(ae, {
                        key: J.labelKey,
                        label: t(v)(J.labelKey),
                        variant: ((m = f.value) == null ? void 0 : m.labelKey) === J.labelKey ? "primary" : "secondary",
                        size: "md",
                        onClick: (o) => se(J)
                      }, null, 8, ["label", "variant", "onClick"]);
                    }), 64))
                  ]),
                  a(ae, {
                    icon: "screen_rotation",
                    variant: "tertiary",
                    size: "md",
                    class: "text-fm-color-typo-primary",
                    onClick: pe
                  })
                ])
              ])
            ]),
            _: 1
          }, 8, ["actions"]),
          t(F) ? (r(), T(Yl, {
            key: 0,
            modelValue: t(F),
            "onUpdate:modelValue": I[1] || (I[1] = (J) => Ye(F) ? F.value = J : null),
            style: He({ height: G.value + "px" }),
            class: ke(t(s).lg || t(s).md ? "flex" : ""),
            "hide-configuration": V.value,
            "preview-width": Z.value,
            "preview-height": _e.value,
            "preview-scale": ie.value,
            onHideConfiguration: I[2] || (I[2] = (J) => V.value = J)
          }, null, 8, ["modelValue", "style", "class", "hide-configuration", "preview-width", "preview-height", "preview-scale"])) : A("", !0)
        ]),
        _: 1
      });
    };
  }
});
export {
  gt as default
};
