import { useCssVars as J, computed as _, ref as r, watch as K, openBlock as w, createElementBlock as y, createElementVNode as g, normalizeStyle as z, createCommentVNode as I, Fragment as D, renderList as Q, normalizeClass as Z, renderSlot as ee, pushScopeId as te, popScopeId as oe, createStaticVNode as ae } from "vue";
import { p as le } from "./pdf-97UbtKC2.js";
import { u as ue } from "./useNestedProp-BbEbJmgv.js";
import { u as ne } from "./index-CguVaFlt.js";
import { _ as se } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const ie = (M) => (te("data-v-57895b3a"), M = M(), oe(), M), re = {
  key: 0,
  "data-html2canvas-ignore": "",
  style: { width: "100%", display: "flex", "justify-content": "end" }
}, de = ["disabled"], ce = ["stroke"], he = /* @__PURE__ */ ae('<path stroke="none" d="M0 0h24v24H0z" fill="none" data-v-57895b3a></path><path d="M18 16v.01" data-v-57895b3a></path><path d="M6 16v.01" data-v-57895b3a></path><path d="M12 5v.01" data-v-57895b3a></path><path d="M12 12v.01" data-v-57895b3a></path><path d="M12 1a4 4 0 0 1 2.001 7.464l.001 .072a3.998 3.998 0 0 1 1.987 3.758l.22 .128a3.978 3.978 0 0 1 1.591 -.417l.2 -.005a4 4 0 1 1 -3.994 3.77l-.28 -.16c-.522 .25 -1.108 .39 -1.726 .39c-.619 0 -1.205 -.14 -1.728 -.391l-.279 .16l.007 .231a4 4 0 1 1 -2.212 -3.579l.222 -.129a3.998 3.998 0 0 1 1.988 -3.756l.002 -.071a4 4 0 0 1 -1.995 -3.265l-.005 -.2a4 4 0 0 1 4 -4z" data-v-57895b3a></path>', 6), ve = [
  he
], fe = { key: 1 }, pe = ["id"], ge = /* @__PURE__ */ ie(() => /* @__PURE__ */ g("div", { class: "vue-ui-dashboard-grid" }, null, -1)), be = ["onMousedown", "onTouchstart"], we = ["onMousedown", "onTouchstart"], ye = ["onMousedown", "onTouchstart"], _e = ["onMousedown", "onTouchstart"], Me = ["onMousedown", "onTouchstart"], x = 20, me = {
  __name: "vue-ui-dashboard",
  props: {
    dataset: Array,
    config: Object
  },
  emits: ["change"],
  setup(M, { expose: W, emit: E }) {
    const X = M;
    J((e) => ({
      "417957d3": V.value,
      "60fae9e7": j.value
    }));
    const { vue_ui_dashboard: L } = ne(), s = _(() => ue({
      userConfig: X.config,
      defaultConfig: L
    })), Y = r(`vue-ui-dashboard-${Math.random()}`), c = r(s.value.locked);
    function N() {
      c.value = !c.value;
    }
    const n = r(X.dataset), h = r(null), u = r(null), v = r({ x: 0, y: 0 }), f = r({ x: 0, y: 0 }), i = r(null), d = r(!1), p = r(null), T = r(!1);
    function S() {
      T.value = !0, le({
        domElement: document.getElementById(`vue-ui-dashboard_${Y.value}`),
        fileName: "vue-ui-dashboard"
      }).finally(() => {
        T.value = !1;
      });
    }
    function R(e) {
      if (!c.value && (d.value = !0, p.value = e, u.value === null)) {
        h.value = e, v.value = { x: event.clientX, y: event.clientY };
        const t = n.value[e], a = 100 - t.width, o = 100 - t.height;
        t.left < 0 && (t.left = 0), t.top < 0 && (t.top = 0), t.left > a && (t.left = a), t.top > o && (t.top = o), t.left < 0 && (t.left = 0), t.top < 0 && (t.top = 0), t.left + t.width > 100 && (t.left = 100 - t.width), t.top + t.height > 100 && (t.top = 100 - t.height);
      }
    }
    function k(e, t) {
      d.value = !0, p.value = e, u.value = { index: e, direction: t };
      const a = n.value[e];
      f.value = { x: event.clientX, y: event.clientY, initialWidth: a.width, initialHeight: a.height };
    }
    function H(e, t, a) {
      if (u.value.direction.includes("top")) {
        const o = e.height - a / i.value.offsetHeight * 100;
        o >= x && (e.top += a / i.value.offsetHeight * 100, e.height = o);
      }
      if (u.value.direction.includes("bottom")) {
        const o = e.height + a / i.value.offsetHeight * 100;
        o >= x && (e.height = o);
      }
      if (u.value.direction.includes("left")) {
        const o = e.width - t / i.value.offsetWidth * 100;
        o >= x && (e.left += t / i.value.offsetWidth * 100, e.width = o);
      }
      if (u.value.direction.includes("right")) {
        const o = e.width + t / i.value.offsetWidth * 100;
        o >= x && (e.width = o);
      }
    }
    function B(e) {
      if (!c.value) {
        if (d.value = !0, h.value !== null) {
          const t = n.value[h.value], a = e.clientX - v.value.x, o = e.clientY - v.value.y, l = t.left + a / i.value.offsetWidth * 100, b = t.top + o / i.value.offsetHeight * 100;
          l >= 0 && b >= 0 && l + t.width <= 100 && b + t.height <= 100 && (t.left = l, t.top = b), v.value = { x: e.clientX, y: e.clientY };
        }
        if (u.value !== null) {
          const t = n.value[u.value.index], a = e.clientX - f.value.x, o = e.clientY - f.value.y;
          H(t, a, o), f.value = { x: e.clientX, y: e.clientY };
        }
      }
    }
    K(
      n,
      (e) => {
        e && !d.value && E("change", n.value);
      },
      { deep: !0 }
    );
    function F() {
      h.value = null, u.value = null, d.value = !1, p.value = null, n.value.forEach((e) => {
        e.left = Math.round(e.left / 100 * 100), e.top = Math.round(e.top / 100 * 100), e.width = Math.round(e.width / 100 * 100), e.height = Math.round(e.height / 100 * 100);
      });
    }
    function P(e) {
      c.value || (d.value = !0, p.value = e, u.value === null && (h.value = e, v.value = { x: event.touches[0].clientX, y: event.touches[0].clientY }));
    }
    function C(e, t, a) {
      if (d.value = !0, p.value = e, u.value === null) {
        u.value = { index: e, direction: t };
        const o = n.value[e];
        f.value = { x: a.touches[0].clientX, y: a.touches[0].clientY, initialWidth: o.width, initialHeight: o.height };
      }
    }
    function $(e) {
      if (d.value = !0, e.preventDefault(), u.value !== null) {
        const t = n.value[u.value.index], a = e.touches[0].clientX - f.value.x, o = e.touches[0].clientY - f.value.y;
        H(t, a, o), f.value = { x: e.touches[0].clientX, y: e.touches[0].clientY };
      }
    }
    function O(e) {
      if (!c.value && (d.value = !0, e.preventDefault(), h.value !== null)) {
        const t = n.value[h.value], a = e.touches[0].clientX - v.value.x, o = e.touches[0].clientY - v.value.y, l = t.left + a / i.value.offsetWidth * 100, b = t.top + o / i.value.offsetHeight * 100;
        l >= 0 && b >= 0 && l + t.width <= 100 && b + t.height <= 100 && (t.left = l, t.top = b), v.value = { x: e.touches[0].clientX, y: e.touches[0].clientY };
      }
    }
    function m() {
      d.value = !1, p.value = null, h.value = null, u.value = null, n.value.forEach((e) => {
        e.left = Math.round(e.left / 100 * 100), e.top = Math.round(e.top / 100 * 100), e.width = Math.round(e.width / 100 * 100), e.height = Math.round(e.height / 100 * 100);
      });
    }
    const V = _(() => s.value.style.item.borderColor), j = _(() => s.value.style.resizeHandles.backgroundColor), A = _(() => s.value.style.board.aspectRatio), G = _(() => s.value.style.board.backgroundColor), U = _(() => s.value.style.board.border);
    function q() {
      return n.value;
    }
    return W({
      generatePdf: S,
      getItemsPositions: q,
      toggleLock: N
    }), (e, t) => (w(), y("div", null, [
      s.value.allowPrint ? (w(), y("div", re, [
        g("button", {
          class: "vue-ui-dashboard-button",
          onClick: S,
          disabled: T.value,
          style: z([{ "margin-top": "12px" }, `color:${s.value.style.board.color}`])
        }, [
          T.value ? (w(), y("svg", {
            key: 0,
            class: "vue-ui-dashboard-print-icon",
            xmlns: "http://www.w3.org/2000/svg",
            width: "20",
            height: "20",
            viewBox: "0 0 24 24",
            "stroke-width": "1.5",
            stroke: s.value.style.board.color,
            fill: "none",
            "stroke-linecap": "round",
            "stroke-linejoin": "round"
          }, ve, 8, ce)) : (w(), y("span", fe, "PDF"))
        ], 12, de)
      ])) : I("", !0),
      g("div", {
        class: "vue-ui-dashboard-container",
        ref_key: "dashboardContainer",
        ref: i,
        id: `vue-ui-dashboard_${Y.value}`,
        style: z(`border:${U.value}; sbackground:${G.value}; aspect-ratio:${A.value}`)
      }, [
        g("div", {
          class: "vue-ui-dashboard-grid-container",
          ref: "container",
          onMousemove: B,
          onMouseup: F,
          onTouchmove: O,
          onTouchend: m,
          style: z(`background:${s.value.style.board.backgroundColor}`)
        }, [
          ge,
          (w(!0), y(D, null, Q(n.value, (a, o) => (w(), y("div", {
            key: a.id,
            class: Z({ "vue-ui-dashboard-grid-item": !0, "vue-ui-dashboard-grid-item--locked": c.value }),
            style: z({
              width: `${a.width}%`,
              height: `${a.height}%`,
              left: `${a.left}%`,
              top: `${a.top}%`,
              cursor: "move",
              boxShadow: p.value === o ? "0 6px 12px -3px rgba(0,0,0,0.3)" : "",
              zIndex: p.value === o ? "1" : "0",
              backgroundColor: s.value.style.item.backgroundColor
            }),
            onMousedown: (l) => R(o),
            onTouchstart: (l) => P(o)
          }, [
            c.value ? I("", !0) : (w(), y(D, { key: 0 }, [
              g("div", {
                class: "vue-ui-dashboard-resize-handle vue-ui-dashboard-top-left",
                onMousedown: (l) => k(o, "top-left"),
                onTouchstart: (l) => C(o, "top-left", l),
                onTouchmove: t[0] || (t[0] = (l) => $(l)),
                onTouchend: m
              }, null, 40, we),
              g("div", {
                class: "vue-ui-dashboard-resize-handle vue-ui-dashboard-top-right",
                onMousedown: (l) => k(o, "top-right"),
                onTouchstart: (l) => C(o, "top-right", l),
                onTouchmove: t[1] || (t[1] = (l) => $(l)),
                onTouchend: m
              }, null, 40, ye),
              g("div", {
                class: "vue-ui-dashboard-resize-handle vue-ui-dashboard-bottom-left",
                onMousedown: (l) => k(o, "bottom-left"),
                onTouchstart: (l) => C(o, "bottom-left", l),
                onTouchmove: t[2] || (t[2] = (l) => $(l)),
                onTouchend: m
              }, null, 40, _e),
              g("div", {
                class: "vue-ui-dashboard-resize-handle vue-ui-dashboard-bottom-right",
                onMousedown: (l) => k(o, "bottom-right"),
                onTouchstart: (l) => C(o, "bottom-right", l),
                onTouchmove: t[3] || (t[3] = (l) => $(l)),
                onTouchend: m
              }, null, 40, Me)
            ], 64)),
            ee(e.$slots, "content", {
              item: a,
              index: o,
              left: a.left,
              top: a.top,
              height: a.height,
              width: a.width
            }, void 0, !0)
          ], 46, be))), 128))
        ], 36)
      ], 12, pe)
    ]));
  }
}, xe = /* @__PURE__ */ se(me, [["__scopeId", "data-v-57895b3a"]]);
export {
  xe as default
};
