import { defineComponent as U, reactive as E, resolveComponent as b, createElementBlock as a, openBlock as s, Fragment as h, renderList as I, createBlock as g, createCommentVNode as W, normalizeStyle as F, normalizeClass as f, withCtx as V, createVNode as c, createElementVNode as z, withDirectives as H, vShow as K } from "vue";
import { _ as D, c as P, a as j, b as q, t as A } from "./DynamicWidget.vue_vue_type_script_setup_true_lang-BGD1_4cA.js";
import { useBreakpoints as J } from "@feedmepos/ui-library";
const O = { class: "flex-1 min-h-0 overflow-y-auto" }, Q = {
  key: 0,
  class: "grid grid-cols-12"
}, R = { class: "grid grid-cols-12 max-h-full overflow-y-auto" }, ee = /* @__PURE__ */ U({
  __name: "TileGrid",
  props: {
    tiles: {},
    reportId: {},
    leafIndexById: {},
    hideExport: { type: Boolean },
    customScreenWidth: {},
    flat: { type: Boolean }
  },
  setup(N) {
    const e = N, { breakpoints: y } = J();
    function u(o) {
      var n;
      const r = ((n = o.size) == null ? void 0 : n.width) ?? 12;
      return y.value.lg || y.value.md ? P(r) : y.value.sm ? j(r) : q(r);
    }
    function _(o) {
      return e.flat && o > 0 ? "border-t border-neutral-200" : "";
    }
    function w(o) {
      var r;
      if (!e.flat)
        return { height: `${A(((r = o.size) == null ? void 0 : r.height) ?? 6)}px` };
    }
    const k = E({}), v = E({});
    function G(o) {
      return (o.tiles ?? []).map((r, n) => ({
        label: r.tabTitle || `Tab ${n + 1}`,
        value: String(n)
      }));
    }
    function p(o, r) {
      return o.id || `container_${r}`;
    }
    function m(o, r) {
      return k[p(o, r)] ?? 0;
    }
    function L(o, r, n) {
      return m(o, r) === n || v[`${p(o, r)}_${n}`];
    }
    function M(o, r, n) {
      if (n === null) return;
      const d = p(o, r);
      v[`${d}_${m(o, r)}`] = !0, k[d] = Number(n), v[`${d}_${n}`] = !0;
    }
    return (o, r) => {
      const n = b("FmTabs"), d = b("TileGrid", !0), $ = b("FmCard");
      return s(!0), a(h, null, I(e.tiles, (t, i) => {
        var S, B, T;
        return s(), a(h, {
          key: `tile_${e.reportId}_${t.id || i}`
        }, [
          t.tab && ((S = t.tiles) != null && S.length) ? (s(), g($, {
            key: 0,
            variant: "outlined",
            class: f(["p-0 overflow-hidden flex flex-col", [u(t), _(i)]]),
            style: F(w(t))
          }, {
            default: V(() => [
              c(n, {
                class: "px-16 pt-8 shrink-0",
                "model-value": String(m(t, i)),
                items: G(t),
                "onUpdate:modelValue": (l) => M(t, i, l)
              }, null, 8, ["model-value", "items", "onUpdate:modelValue"]),
              z("div", O, [
                (s(!0), a(h, null, I(t.tiles, (l, x) => {
                  var C;
                  return s(), a(h, {
                    key: `tab_${p(t, i)}_${x}`
                  }, [
                    L(t, i, x) ? H((s(), a("div", Q, [
                      c(d, {
                        tiles: (C = l.tiles) != null && C.length ? l.tiles : [l],
                        "report-id": e.reportId,
                        "leaf-index-by-id": e.leafIndexById,
                        "hide-export": e.hideExport,
                        "custom-screen-width": e.customScreenWidth,
                        flat: !0
                      }, null, 8, ["tiles", "report-id", "leaf-index-by-id", "hide-export", "custom-screen-width"])
                    ], 512)), [
                      [K, m(t, i) === x]
                    ]) : W("", !0)
                  ], 64);
                }), 128))
              ])
            ]),
            _: 2
          }, 1032, ["class", "style"])) : (B = t.tiles) != null && B.length && !e.flat ? (s(), g($, {
            key: 1,
            variant: "outlined",
            class: f(["p-0 overflow-hidden", u(t)]),
            style: F(w(t))
          }, {
            default: V(() => [
              z("div", R, [
                c(d, {
                  tiles: t.tiles,
                  "report-id": e.reportId,
                  "leaf-index-by-id": e.leafIndexById,
                  "hide-export": e.hideExport,
                  "custom-screen-width": e.customScreenWidth,
                  flat: !0
                }, null, 8, ["tiles", "report-id", "leaf-index-by-id", "hide-export", "custom-screen-width"])
              ])
            ]),
            _: 2
          }, 1032, ["class", "style"])) : (T = t.tiles) != null && T.length ? (s(), a("div", {
            key: 2,
            class: f(["grid grid-cols-12", [u(t), _(i)]])
          }, [
            c(d, {
              tiles: t.tiles,
              "report-id": e.reportId,
              "leaf-index-by-id": e.leafIndexById,
              "hide-export": e.hideExport,
              "custom-screen-width": e.customScreenWidth,
              flat: !0
            }, null, 8, ["tiles", "report-id", "leaf-index-by-id", "hide-export", "custom-screen-width"])
          ], 2)) : t.widget && e.flat ? (s(), a("div", {
            key: 3,
            class: f([u(t), _(i)])
          }, [
            c(D, {
              "model-value": t,
              "report-id": e.reportId,
              index: e.leafIndexById[t.id] ?? i,
              "hide-export": e.hideExport,
              "custom-screen-width": e.customScreenWidth,
              flat: !0
            }, null, 8, ["model-value", "report-id", "index", "hide-export", "custom-screen-width"])
          ], 2)) : t.widget ? (s(), g(D, {
            key: 4,
            "model-value": t,
            "report-id": e.reportId,
            index: e.leafIndexById[t.id] ?? i,
            "hide-export": e.hideExport,
            "custom-screen-width": e.customScreenWidth
          }, null, 8, ["model-value", "report-id", "index", "hide-export", "custom-screen-width"])) : W("", !0)
        ], 64);
      }), 128);
    };
  }
});
export {
  ee as _
};
