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