import { useCssVars as Z, computed as _, ref as s, watch as ee, openBlock as w, createElementBlock as y, createElementVNode as g, normalizeStyle as x, createCommentVNode as E, Fragment as L, renderList as te, normalizeClass as oe, renderSlot as ae, pushScopeId as ne, popScopeId as le, createStaticVNode as ue } from "vue";
import se from "./pdf-B7oVat64.js";
import { u as ie } from "./useNestedProp-CTDeT4KA.js";
import { u as re } from "./index-MWHrTFPq.js";
import { _ as de } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const ce = (M) => (ne("data-v-0caf17e8"), M = M(), le(), M), he = {
  key: 0,
  "data-html2canvas-ignore": "",
  style: { width: "100%", display: "flex", "justify-content": "end" }
}, ve = ["disabled"], fe = ["stroke"], pe = /* @__PURE__ */ ue('<path stroke="none" d="M0 0h24v24H0z" fill="none" data-v-0caf17e8></path><path d="M18 16v.01" data-v-0caf17e8></path><path d="M6 16v.01" data-v-0caf17e8></path><path d="M12 5v.01" data-v-0caf17e8></path><path d="M12 12v.01" data-v-0caf17e8></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-0caf17e8></path>', 6), ge = [
  pe
], be = { key: 1 }, we = ["id"], ye = /* @__PURE__ */ ce(() => /* @__PURE__ */ g("div", { class: "vue-ui-dashboard-grid" }, null, -1)), _e = ["onMousedown", "onTouchstart"], Me = ["onMousedown", "onTouchstart"], Te = ["onMousedown", "onTouchstart"], me = ["onMousedown", "onTouchstart"], ke = ["onMousedown", "onTouchstart"], I = 20, Ce = {
  __name: "vue-ui-dashboard",
  props: {
    dataset: Array,
    config: Object
  },
  emits: ["change"],
  setup(M, { expose: P, emit: W }) {
    const X = M;
    Z((e) => ({
      "4458b906": A.value,
      "8bf0a1d8": G.value
    }));
    const { vue_ui_dashboard: R } = re(), i = _(() => ie({
      userConfig: X.config,
      defaultConfig: R
    })), Y = s(`vue-ui-dashboard-${Math.random()}`), c = s(i.value.locked);
    function B() {
      c.value = !c.value;
    }
    const u = s(X.dataset.map((e, t) => ({
      ...e,
      index: t
    }))), h = s(null), l = s(null), v = s({ x: 0, y: 0 }), f = s({ x: 0, y: 0 }), r = s(null), d = s(!1), p = s(null), k = s(!1), T = s(!1);
    function N(e) {
      const t = e.target;
      (t.tagName === "INPUT" && t.type === "range" || t.classList.contains("range-handle")) && (T.value = !0);
    }
    function S(e) {
      const t = e.target;
      t.tagName === "INPUT" && t.type === "range" && (T.value = !1);
    }
    function H() {
      k.value = !0, se({
        domElement: document.getElementById(`vue-ui-dashboard_${Y.value}`),
        fileName: "vue-ui-dashboard"
      }).finally(() => {
        k.value = !1;
      });
    }
    function F(e) {
      if (!c.value && (d.value = !0, p.value = e, l.value === null)) {
        h.value = e, v.value = { x: event.clientX, y: event.clientY };
        const t = u.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 C(e, t) {
      d.value = !0, p.value = e, l.value = { index: e, direction: t };
      const a = u.value[e];
      f.value = { x: event.clientX, y: event.clientY, initialWidth: a.width, initialHeight: a.height };
    }
    function D(e, t, a) {
      if (l.value.direction.includes("top")) {
        const o = e.height - a / r.value.offsetHeight * 100;
        o >= I && (e.top += a / r.value.offsetHeight * 100, e.height = o);
      }
      if (l.value.direction.includes("bottom")) {
        const o = e.height + a / r.value.offsetHeight * 100;
        o >= I && (e.height = o);
      }
      if (l.value.direction.includes("left")) {
        const o = e.width - t / r.value.offsetWidth * 100;
        o >= I && (e.left += t / r.value.offsetWidth * 100, e.width = o);
      }
      if (l.value.direction.includes("right")) {
        const o = e.width + t / r.value.offsetWidth * 100;
        o >= I && (e.width = o);
      }
    }
    function O(e) {
      if (!(c.value || T.value)) {
        if (d.value = !0, h.value !== null) {
          const t = u.value[h.value], a = e.clientX - v.value.x, o = e.clientY - v.value.y, n = t.left + a / r.value.offsetWidth * 100, b = t.top + o / r.value.offsetHeight * 100;
          n >= 0 && b >= 0 && n + t.width <= 100 && b + t.height <= 100 && (t.left = n, t.top = b), v.value = { x: e.clientX, y: e.clientY };
        }
        if (l.value !== null) {
          const t = u.value[l.value.index], a = e.clientX - f.value.x, o = e.clientY - f.value.y;
          D(t, a, o), f.value = { x: e.clientX, y: e.clientY };
        }
      }
    }
    ee(
      u,
      (e) => {
        e && !d.value && W("change", u.value);
      },
      { deep: !0 }
    );
    function U() {
      h.value = null, l.value = null, d.value = !1, p.value = null, u.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 V(e) {
      c.value || T.value || (d.value = !0, p.value = e, l.value === null && (h.value = e, v.value = { x: event.touches[0].clientX, y: event.touches[0].clientY }));
    }
    function $(e, t, a) {
      if (d.value = !0, p.value = e, l.value === null) {
        l.value = { index: e, direction: t };
        const o = u.value[e];
        f.value = { x: a.touches[0].clientX, y: a.touches[0].clientY, initialWidth: o.width, initialHeight: o.height };
      }
    }
    function z(e) {
      if (d.value = !0, e.preventDefault(), l.value !== null) {
        const t = u.value[l.value.index], a = e.touches[0].clientX - f.value.x, o = e.touches[0].clientY - f.value.y;
        D(t, a, o), f.value = { x: e.touches[0].clientX, y: e.touches[0].clientY };
      }
    }
    function j(e) {
      if (!(c.value || T.value) && (d.value = !0, e.preventDefault(), h.value !== null)) {
        const t = u.value[h.value], a = e.touches[0].clientX - v.value.x, o = e.touches[0].clientY - v.value.y, n = t.left + a / r.value.offsetWidth * 100, b = t.top + o / r.value.offsetHeight * 100;
        n >= 0 && b >= 0 && n + t.width <= 100 && b + t.height <= 100 && (t.left = n, 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, l.value = null, u.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 A = _(() => i.value.style.item.borderColor), G = _(() => i.value.style.resizeHandles.backgroundColor), q = _(() => i.value.style.board.aspectRatio), J = _(() => i.value.style.board.backgroundColor), K = _(() => i.value.style.board.border);
    function Q() {
      return u.value;
    }
    return P({
      generatePdf: H,
      getItemsPositions: Q,
      toggleLock: B
    }), (e, t) => (w(), y("div", {
      onMousedown: N,
      onMouseup: S,
      onTouchstart: N,
      onTouchend: S
    }, [
      i.value.allowPrint ? (w(), y("div", he, [
        g("button", {
          class: "vue-ui-dashboard-button",
          onClick: H,
          disabled: k.value,
          style: x([{ "margin-top": "12px" }, `color:${i.value.style.board.color}`])
        }, [
          k.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: i.value.style.board.color,
            fill: "none",
            "stroke-linecap": "round",
            "stroke-linejoin": "round"
          }, ge, 8, fe)) : (w(), y("span", be, "PDF"))
        ], 12, ve)
      ])) : E("", !0),
      g("div", {
        class: "vue-ui-dashboard-container",
        ref_key: "dashboardContainer",
        ref: r,
        id: `vue-ui-dashboard_${Y.value}`,
        style: x(`border:${K.value}; sbackground:${J.value}; aspect-ratio:${q.value}`)
      }, [
        g("div", {
          class: "vue-ui-dashboard-grid-container",
          ref: "container",
          onMousemove: O,
          onMouseup: U,
          onTouchmove: j,
          onTouchend: m,
          style: x(`background:${i.value.style.board.backgroundColor}`)
        }, [
          ye,
          (w(!0), y(L, null, te(u.value, (a, o) => (w(), y("div", {
            key: a.id,
            class: oe({ "vue-ui-dashboard-grid-item": !0, "vue-ui-dashboard-grid-item--locked": c.value }),
            style: x({
              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 ? u.value.length + 1 : a.index,
              backgroundColor: i.value.style.item.backgroundColor
            }),
            onMousedown: (n) => F(o),
            onTouchstart: (n) => V(o)
          }, [
            c.value ? E("", !0) : (w(), y(L, { key: 0 }, [
              g("div", {
                class: "vue-ui-dashboard-resize-handle vue-ui-dashboard-top-left",
                onMousedown: (n) => C(o, "top-left"),
                onTouchstart: (n) => $(o, "top-left", n),
                onTouchmove: t[0] || (t[0] = (n) => z(n)),
                onTouchend: m
              }, null, 40, Me),
              g("div", {
                class: "vue-ui-dashboard-resize-handle vue-ui-dashboard-top-right",
                onMousedown: (n) => C(o, "top-right"),
                onTouchstart: (n) => $(o, "top-right", n),
                onTouchmove: t[1] || (t[1] = (n) => z(n)),
                onTouchend: m
              }, null, 40, Te),
              g("div", {
                class: "vue-ui-dashboard-resize-handle vue-ui-dashboard-bottom-left",
                onMousedown: (n) => C(o, "bottom-left"),
                onTouchstart: (n) => $(o, "bottom-left", n),
                onTouchmove: t[2] || (t[2] = (n) => z(n)),
                onTouchend: m
              }, null, 40, me),
              g("div", {
                class: "vue-ui-dashboard-resize-handle vue-ui-dashboard-bottom-right",
                onMousedown: (n) => C(o, "bottom-right"),
                onTouchstart: (n) => $(o, "bottom-right", n),
                onTouchmove: t[3] || (t[3] = (n) => z(n)),
                onTouchend: m
              }, null, 40, ke)
            ], 64)),
            ae(e.$slots, "content", {
              item: a,
              index: o,
              left: a.left,
              top: a.top,
              height: a.height,
              width: a.width
            }, void 0, !0)
          ], 46, _e))), 128))
        ], 36)
      ], 12, we)
    ], 32));
  }
}, Ye = /* @__PURE__ */ de(Ce, [["__scopeId", "data-v-0caf17e8"]]);
export {
  Ye as default
};
