import '@das-fed/upf-ui/packages/components/split-panel/style.css';
import { getCurrentScope as me, onScopeDispose as ge, unref as be, getCurrentInstance as ye, onMounted as se, nextTick as Se, ref as b, watch as $, defineComponent as he, computed as N, openBlock as L, createElementBlock as z, normalizeStyle as A, createElementVNode as O, renderSlot as R, normalizeClass as Q, createCommentVNode as C, withModifiers as X } from "vue";
import { withInstall as Oe } from "@das-fed/upf-utils/with-install/index";
import "@das-fed/upf-ui/packages/components/icon/index";
import "@das-fed/upf-ui/packages/icons/shuyoufanye/index";
import "@das-fed/upf-ui/packages/icons/shuzuofanye/index";
function q(e) {
  var n = typeof e;
  return e != null && (n == "object" || n == "function");
}
var we = typeof global == "object" && global && global.Object === Object && global, Ee = typeof self == "object" && self && self.Object === Object && self, ie = we || Ee || Function("return this")(), U = function() {
  return ie.Date.now();
}, Ie = /\s/;
function Te(e) {
  for (var n = e.length; n-- && Ie.test(e.charAt(n)); )
    ;
  return n;
}
var Fe = /^\s+/;
function ke(e) {
  return e && e.slice(0, Te(e) + 1).replace(Fe, "");
}
var B = ie.Symbol, oe = Object.prototype, Me = oe.hasOwnProperty, Ce = oe.toString, D = B ? B.toStringTag : void 0;
function xe(e) {
  var n = Me.call(e, D), t = e[D];
  try {
    e[D] = void 0;
    var i = !0;
  } catch {
  }
  var l = Ce.call(e);
  return i && (n ? e[D] = t : delete e[D]), l;
}
var je = Object.prototype, Ne = je.toString;
function De(e) {
  return Ne.call(e);
}
var We = "[object Null]", _e = "[object Undefined]", J = B ? B.toStringTag : void 0;
function Re(e) {
  return e == null ? e === void 0 ? _e : We : J && J in Object(e) ? xe(e) : De(e);
}
function Be(e) {
  return e != null && typeof e == "object";
}
var Pe = "[object Symbol]";
function Le(e) {
  return typeof e == "symbol" || Be(e) && Re(e) == Pe;
}
var Y = NaN, ze = /^[-+]0x[0-9a-f]+$/i, Ae = /^0b[01]+$/i, Qe = /^0o[0-7]+$/i, Xe = parseInt;
function Z(e) {
  if (typeof e == "number")
    return e;
  if (Le(e))
    return Y;
  if (q(e)) {
    var n = typeof e.valueOf == "function" ? e.valueOf() : e;
    e = q(n) ? n + "" : n;
  }
  if (typeof e != "string")
    return e === 0 ? e : +e;
  e = ke(e);
  var t = Ae.test(e);
  return t || Qe.test(e) ? Xe(e.slice(2), t ? 2 : 8) : ze.test(e) ? Y : +e;
}
var Ue = "Expected a function", $e = Math.max, qe = Math.min;
function Ge(e, n, t) {
  var i, l, f, c, u, y, S = 0, a = !1, m = !1, p = !0;
  if (typeof e != "function")
    throw new TypeError(Ue);
  n = Z(n) || 0, q(t) && (a = !!t.leading, m = "maxWait" in t, f = m ? $e(Z(t.maxWait) || 0, n) : f, p = "trailing" in t ? !!t.trailing : p);
  function v(d) {
    var g = i, I = l;
    return i = l = void 0, S = d, c = e.apply(I, g), c;
  }
  function s(d) {
    return S = d, u = setTimeout(F, n), a ? v(d) : c;
  }
  function h(d) {
    var g = d - y, I = d - S, _ = n - g;
    return m ? qe(_, f - I) : _;
  }
  function x(d) {
    var g = d - y, I = d - S;
    return y === void 0 || g >= n || g < 0 || m && I >= f;
  }
  function F() {
    var d = U();
    if (x(d))
      return W(d);
    u = setTimeout(F, h(d));
  }
  function W(d) {
    return u = void 0, p && i ? v(d) : (i = l = void 0, c);
  }
  function k() {
    u !== void 0 && clearTimeout(u), S = 0, i = y = l = u = void 0;
  }
  function E() {
    return u === void 0 ? c : W(U());
  }
  function M() {
    var d = U(), g = x(d);
    if (i = arguments, l = this, y = d, g) {
      if (u === void 0)
        return s(y);
      if (m)
        return clearTimeout(u), u = setTimeout(F, n), v(y);
    }
    return u === void 0 && (u = setTimeout(F, n)), c;
  }
  return M.cancel = k, M.flush = E, M;
}
var ee;
const G = typeof window < "u", Ve = (e) => typeof e == "string", He = () => {
};
G && ((ee = window == null ? void 0 : window.navigator) != null && ee.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
function fe(e) {
  return typeof e == "function" ? e() : be(e);
}
function Ke(e) {
  return e;
}
function ce(e) {
  return me() ? (ge(e), !0) : !1;
}
function Je(e, n = !0) {
  ye() ? se(e) : n ? e() : Se(e);
}
function de(e) {
  var n;
  const t = fe(e);
  return (n = t == null ? void 0 : t.$el) != null ? n : t;
}
const Ye = G ? window : void 0, Ze = G ? window.document : void 0;
function et(...e) {
  let n, t, i, l;
  if (Ve(e[0]) || Array.isArray(e[0]) ? ([t, i, l] = e, n = Ye) : [n, t, i, l] = e, !n)
    return He;
  Array.isArray(t) || (t = [t]), Array.isArray(i) || (i = [i]);
  const f = [], c = () => {
    f.forEach((a) => a()), f.length = 0;
  }, u = (a, m, p, v) => (a.addEventListener(m, p, v), () => a.removeEventListener(m, p, v)), y = $(() => [de(n), fe(l)], ([a, m]) => {
    c(), a && f.push(...t.flatMap((p) => i.map((v) => u(a, p, v, m))));
  }, { immediate: !0, flush: "post" }), S = () => {
    y(), c();
  };
  return ce(S), S;
}
function tt(e, n = !1) {
  const t = b(), i = () => t.value = !!e();
  return i(), Je(i, n), t;
}
const te = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, ne = "__vueuse_ssr_handlers__";
te[ne] = te[ne] || {};
const re = [
  [
    "requestFullscreen",
    "exitFullscreen",
    "fullscreenElement",
    "fullscreenEnabled",
    "fullscreenchange",
    "fullscreenerror"
  ],
  [
    "webkitRequestFullscreen",
    "webkitExitFullscreen",
    "webkitFullscreenElement",
    "webkitFullscreenEnabled",
    "webkitfullscreenchange",
    "webkitfullscreenerror"
  ],
  [
    "webkitRequestFullScreen",
    "webkitCancelFullScreen",
    "webkitCurrentFullScreenElement",
    "webkitCancelFullScreen",
    "webkitfullscreenchange",
    "webkitfullscreenerror"
  ],
  [
    "mozRequestFullScreen",
    "mozCancelFullScreen",
    "mozFullScreenElement",
    "mozFullScreenEnabled",
    "mozfullscreenchange",
    "mozfullscreenerror"
  ],
  [
    "msRequestFullscreen",
    "msExitFullscreen",
    "msFullscreenElement",
    "msFullscreenEnabled",
    "MSFullscreenChange",
    "MSFullscreenError"
  ]
];
function nt(e, n = {}) {
  const { document: t = Ze, autoExit: i = !1 } = n, l = t == null ? void 0 : t.querySelector("html"), f = b(!1);
  let c = re[0];
  const u = tt(() => {
    if (t) {
      for (const h of re)
        if (h[1] in t)
          return c = h, !0;
    } else
      return !1;
    return !1;
  }), [y, S, a, , m] = c;
  async function p() {
    u.value && (t != null && t[a] && await t[S](), f.value = !1);
  }
  async function v() {
    if (!u.value)
      return;
    await p();
    const h = de(l);
    h && (await h[y](), f.value = !0);
  }
  async function s() {
    f.value ? await p() : await v();
  }
  return t && et(t, m, () => {
    f.value = !!(t != null && t[a]);
  }, !1), i && ce(p), {
    isSupported: u,
    isFullscreen: f,
    enter: v,
    exit: p,
    toggle: s
  };
}
var le;
(function(e) {
  e.UP = "UP", e.RIGHT = "RIGHT", e.DOWN = "DOWN", e.LEFT = "LEFT", e.NONE = "NONE";
})(le || (le = {}));
var rt = Object.defineProperty, ae = Object.getOwnPropertySymbols, lt = Object.prototype.hasOwnProperty, at = Object.prototype.propertyIsEnumerable, ue = (e, n, t) => n in e ? rt(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t, ut = (e, n) => {
  for (var t in n)
    lt.call(n, t) && ue(e, t, n[t]);
  if (ae)
    for (var t of ae(n))
      at.call(n, t) && ue(e, t, n[t]);
  return e;
};
const st = {
  easeInSine: [0.12, 0, 0.39, 0],
  easeOutSine: [0.61, 1, 0.88, 1],
  easeInOutSine: [0.37, 0, 0.63, 1],
  easeInQuad: [0.11, 0, 0.5, 0],
  easeOutQuad: [0.5, 1, 0.89, 1],
  easeInOutQuad: [0.45, 0, 0.55, 1],
  easeInCubic: [0.32, 0, 0.67, 0],
  easeOutCubic: [0.33, 1, 0.68, 1],
  easeInOutCubic: [0.65, 0, 0.35, 1],
  easeInQuart: [0.5, 0, 0.75, 0],
  easeOutQuart: [0.25, 1, 0.5, 1],
  easeInOutQuart: [0.76, 0, 0.24, 1],
  easeInQuint: [0.64, 0, 0.78, 0],
  easeOutQuint: [0.22, 1, 0.36, 1],
  easeInOutQuint: [0.83, 0, 0.17, 1],
  easeInExpo: [0.7, 0, 0.84, 0],
  easeOutExpo: [0.16, 1, 0.3, 1],
  easeInOutExpo: [0.87, 0, 0.13, 1],
  easeInCirc: [0.55, 0, 1, 0.45],
  easeOutCirc: [0, 0.55, 0.45, 1],
  easeInOutCirc: [0.85, 0, 0.15, 1],
  easeInBack: [0.36, 0, 0.66, -0.56],
  easeOutBack: [0.34, 1.56, 0.64, 1],
  easeInOutBack: [0.68, -0.6, 0.32, 1.6]
};
ut({
  linear: Ke
}, st);
const it = { class: "das-split-panel-second" }, ot = {
  name: "DasSplitPanel"
}, ft = /* @__PURE__ */ he({
  ...ot,
  props: {
    canFold: { type: Boolean, default: !0 },
    canDrag: { type: Boolean, default: !0 },
    boxStyle: {},
    defaultSplit: { default: {
      first: 0.5,
      second: 0.5
    } },
    firstMin: { default: 225 },
    secondMin: { default: 600 },
    defaultClose: {}
  },
  emits: ["onLeft", "onRight", "onDefault", "onMouseDown", "onMouseMove", "onMouseUp"],
  setup(e, { expose: n, emit: t }) {
    const { isFullscreen: i } = nt(), l = e, f = t, c = b(null), u = b(null), y = N(() => {
      var o;
      if (!(u != null && u.value)) return 1;
      const r = (o = u == null ? void 0 : u.value) == null ? void 0 : o.offsetWidth;
      return r == null || isNaN(r) ? 1 : r - 2 || 1;
    });
    N(() => y.value + "px");
    const S = b(null), a = b(), m = b(), p = b(), v = b(0), s = b(0), h = b(!0), x = N(() => s.value + "px"), F = N(() => ({ width: x.value })), W = N(() => ({ left: x.value })), k = b(!1), E = b(!1);
    $(
      s,
      (r, o) => {
        r === 0 ? k.value = !0 : k.value = !1, r === (a == null ? void 0 : a.value) ? E.value = !0 : E.value = !1;
      },
      { immediate: !0 }
    ), $(i, (r) => {
      P();
    });
    const M = () => {
      s.value > v.value ? (s.value = v.value, f("onDefault")) : s.value <= v.value && s.value > 0 && (s.value = 0, f("onLeft"));
    }, d = () => {
      s.value < v.value ? (s.value = v.value, f("onDefault")) : s.value >= v.value && s.value < a.value && (s.value = a.value, f("onRight"));
    }, g = b({
      mouseFlag: !1,
      startX: 0,
      startWidth: 0
    }), I = (r) => {
      l.canDrag && (g.value.mouseFlag = !0, g.value.startX = r.clientX, g.value.startWidth = s.value, document.onmousemove = _, document.onmouseup = ve, f("onMouseDown"));
    }, _ = (r) => {
      if (r.preventDefault(), !g.value.mouseFlag) return;
      let w = r.clientX - g.value.startX, T = g.value.startWidth + w;
      T < m.value ? s.value = m.value : T > p.value ? s.value = p.value : T > m.value && T < p.value && (s.value = T), f("onMouseMove");
    }, ve = () => {
      g.value.mouseFlag = !1, document.onmousemove = null, document.onmouseup = null, f("onMouseUp");
    }, j = (r, o) => {
      let w = 0;
      const T = r ?? 0;
      if (typeof o == "number" && o <= 1)
        w = T * o;
      else if (typeof o == "number")
        w = o;
      else {
        const K = Number(o);
        w = isNaN(K) ? 0 : K;
      }
      return isNaN(w) ? 0 : w;
    }, V = () => {
      let r = 0;
      l.defaultSplit.first !== void 0 ? (r = j(a.value, l.defaultSplit.first), v.value = r, s.value = r) : l.defaultSplit.second !== void 0 && (typeof l.defaultSplit.second == "number" && l.defaultSplit.second <= 1 ? r = j(a.value, 1 - l.defaultSplit.second) : r = a.value - j(a.value, l.defaultSplit.second), v.value = r, s.value = r), l.defaultClose && l.defaultClose == "first" ? s.value = 0 : l.defaultClose && l.defaultClose == "second" && (s.value = a.value);
    }, pe = () => {
      V();
    };
    let H = b(!0);
    const P = () => {
      var w;
      let r = !1;
      if (E.value && (r = !0), !(c != null && c.value)) return;
      const o = ((w = c == null ? void 0 : c.value) == null ? void 0 : w.clientWidth) ?? 0;
      if (a.value = o - y.value || 0, m.value = j(a.value, l.firstMin), p.value = a.value - j(a.value, l.secondMin), r && (s.value = a.value), h.value === !0) {
        if (V(), H.value) {
          H.value = !1;
          return;
        }
        h.value = !1;
      }
    };
    return se(() => {
      var r;
      h.value = !0, S.value = new ResizeObserver(Ge(P, 30)), (r = S.value) == null || r.observe(c == null ? void 0 : c.value), P();
    }), n({
      toLeft: M,
      toRight: d,
      reset: pe
    }), (r, o) => (L(), z(
      "div",
      {
        class: "das-ui-split-panel",
        ref_key: "$splitPanel",
        ref: c,
        style: A(e.boxStyle)
      },
      [
        O(
          "div",
          {
            class: "das-split-panel-first",
            style: A(F.value)
          },
          [
            R(r.$slots, "firstSlot", {}, void 0, !0)
          ],
          4
          /* STYLE */
        ),
        O(
          "div",
          {
            class: "das-split-panel-mid",
            ref_key: "$splitLine",
            ref: u,
            style: A(W.value)
          },
          [
            e.canFold ? (L(), z("span", {
              key: 0,
              onClick: M
            }, [
              R(r.$slots, "leftBtn", {}, () => [
                O(
                  "span",
                  {
                    class: Q(["das-split-panel-btn left", [E.value ? "isBase" : ""]])
                  },
                  [
                    C(' <DasIconShuzuofanye size="medium"></DasIconShuzuofanye> '),
                    o[2] || (o[2] = O(
                      "div",
                      { class: "arrow" },
                      [
                        O("span", { class: "arrowItem" })
                      ],
                      -1
                      /* CACHED */
                    ))
                  ],
                  2
                  /* CLASS */
                )
              ], !0)
            ])) : C("v-if", !0),
            O(
              "div",
              {
                class: Q(["das-split-panel-line", { hide: k.value || E.value, canDrag: l.canDrag }]),
                onDragstart: o[0] || (o[0] = X(() => {
                }, ["stop", "prevent"])),
                onMousedown: X(I, ["prevent"]),
                onClick: o[1] || (o[1] = X(() => {
                }, ["stop", "prevent"]))
              },
              [
                C(' <slot name="splitLine"> '),
                o[3] || (o[3] = O(
                  "div",
                  { class: "das-split-panel-divider" },
                  null,
                  -1
                  /* CACHED */
                )),
                C(" </slot> ")
              ],
              34
              /* CLASS, NEED_HYDRATION */
            ),
            e.canFold ? (L(), z("span", {
              key: 1,
              onClick: d
            }, [
              R(r.$slots, "rightBtn", {}, () => [
                O(
                  "span",
                  {
                    class: Q(["das-split-panel-btn right", [k.value ? "isBase" : ""]])
                  },
                  [
                    C(' <DasIconShuyoufanye size="medium"></DasIconShuyoufanye> '),
                    o[4] || (o[4] = O(
                      "div",
                      { class: "arrow" },
                      [
                        O("span", { class: "arrowItem" })
                      ],
                      -1
                      /* CACHED */
                    ))
                  ],
                  2
                  /* CLASS */
                )
              ], !0)
            ])) : C("v-if", !0)
          ],
          4
          /* STYLE */
        ),
        O("div", it, [
          R(r.$slots, "secondSlot", {}, void 0, !0)
        ])
      ],
      4
      /* STYLE */
    ));
  }
}), ct = (e, n) => {
  const t = e.__vccOpts || e;
  for (const [i, l] of n)
    t[i] = l;
  return t;
}, dt = /* @__PURE__ */ ct(ft, [["__scopeId", "data-v-88bf6e6c"]]), yt = Oe(dt), St = () => b(null), ht = { name: "splitPanel 分割面板" };
export {
  yt as DasSplitPanel,
  St as DasSplitPanelRef,
  ht as default
};
