import '@das-fed/ui/packages/components/split-panel/style.css';
import { getCurrentScope as ge, onScopeDispose as be, getCurrentInstance as ye, onMounted as se, nextTick as Se, unref as q, ref as y, watch as $, defineComponent as he, computed as x, createElementBlock as z, openBlock as A, normalizeStyle as L, createElementVNode as w, renderSlot as R, createCommentVNode as P, normalizeClass as Q, createVNode as J, withModifiers as X } from "vue";
import { withInstall as Oe } from "@das-fed/utils/with-install/index";
import { DasIconShuyoufanye as Ee } from "@das-fed/ui/packages/icons/shuyoufanye/index";
import { DasIconShuzuofanye as we } from "@das-fed/ui/packages/icons/shuzuofanye/index";
import { setThemeRule as Te } from "@das-fed/web/packages/theme/index";
function G(e) {
  var n = typeof e;
  return e != null && (n == "object" || n == "function");
}
var Fe = typeof global == "object" && global && global.Object === Object && global, Ie = typeof self == "object" && self && self.Object === Object && self, ie = Fe || Ie || Function("return this")(), U = function() {
  return ie.Date.now();
}, ke = /\s/;
function Me(e) {
  for (var n = e.length; n-- && ke.test(e.charAt(n)); )
    ;
  return n;
}
var Ce = /^\s+/;
function _e(e) {
  return e && e.slice(0, Me(e) + 1).replace(Ce, "");
}
var W = ie.Symbol, fe = Object.prototype, xe = fe.hasOwnProperty, je = fe.toString, j = W ? W.toStringTag : void 0;
function De(e) {
  var n = xe.call(e, j), t = e[j];
  try {
    e[j] = void 0;
    var s = !0;
  } catch {
  }
  var r = je.call(e);
  return s && (n ? e[j] = t : delete e[j]), r;
}
var Ne = Object.prototype, Re = Ne.toString;
function Pe(e) {
  return Re.call(e);
}
var We = "[object Null]", Be = "[object Undefined]", Y = W ? W.toStringTag : void 0;
function ze(e) {
  return e == null ? e === void 0 ? Be : We : Y && Y in Object(e) ? De(e) : Pe(e);
}
function Ae(e) {
  return e != null && typeof e == "object";
}
var Le = "[object Symbol]";
function Qe(e) {
  return typeof e == "symbol" || Ae(e) && ze(e) == Le;
}
var Z = NaN, Xe = /^[-+]0x[0-9a-f]+$/i, Ue = /^0b[01]+$/i, qe = /^0o[0-7]+$/i, $e = parseInt;
function ee(e) {
  if (typeof e == "number")
    return e;
  if (Qe(e))
    return Z;
  if (G(e)) {
    var n = typeof e.valueOf == "function" ? e.valueOf() : e;
    e = G(n) ? n + "" : n;
  }
  if (typeof e != "string")
    return e === 0 ? e : +e;
  e = _e(e);
  var t = Ue.test(e);
  return t || qe.test(e) ? $e(e.slice(2), t ? 2 : 8) : Xe.test(e) ? Z : +e;
}
var Ge = "Expected a function", Ve = Math.max, He = Math.min;
function Ke(e, n, t) {
  var s, r, i, f, o, g, S = 0, a = !1, p = !1, v = !0;
  if (typeof e != "function")
    throw new TypeError(Ge);
  n = ee(n) || 0, G(t) && (a = !!t.leading, p = "maxWait" in t, i = p ? Ve(ee(t.maxWait) || 0, n) : i, v = "trailing" in t ? !!t.trailing : v);
  function d(c) {
    var b = s, E = r;
    return s = r = void 0, S = c, f = e.apply(E, b), f;
  }
  function u(c) {
    return S = c, o = setTimeout(T, n), a ? d(c) : f;
  }
  function h(c) {
    var b = c - g, E = c - S, N = n - b;
    return p ? He(N, i - E) : N;
  }
  function M(c) {
    var b = c - g, E = c - S;
    return g === void 0 || b >= n || b < 0 || p && E >= i;
  }
  function T() {
    var c = U();
    if (M(c))
      return D(c);
    o = setTimeout(T, h(c));
  }
  function D(c) {
    return o = void 0, v && s ? d(c) : (s = r = void 0, f);
  }
  function F() {
    o !== void 0 && clearTimeout(o), S = 0, s = g = r = o = void 0;
  }
  function O() {
    return o === void 0 ? f : D(U());
  }
  function I() {
    var c = U(), b = M(c);
    if (s = arguments, r = this, g = c, b) {
      if (o === void 0)
        return u(g);
      if (p)
        return clearTimeout(o), o = setTimeout(T, n), d(g);
    }
    return o === void 0 && (o = setTimeout(T, n)), f;
  }
  return I.cancel = F, I.flush = O, I;
}
var te;
const V = typeof window < "u", Je = (e) => typeof e == "string", Ye = () => {
};
V && ((te = window == null ? void 0 : window.navigator) != null && te.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
function ce(e) {
  return typeof e == "function" ? e() : q(e);
}
function Ze(e) {
  return e;
}
function de(e) {
  return ge() ? (be(e), !0) : !1;
}
function et(e, n = !0) {
  ye() ? se(e) : n ? e() : Se(e);
}
function ve(e) {
  var n;
  const t = ce(e);
  return (n = t == null ? void 0 : t.$el) != null ? n : t;
}
const tt = V ? window : void 0, nt = V ? window.document : void 0;
function lt(...e) {
  let n, t, s, r;
  if (Je(e[0]) || Array.isArray(e[0]) ? ([t, s, r] = e, n = tt) : [n, t, s, r] = e, !n)
    return Ye;
  Array.isArray(t) || (t = [t]), Array.isArray(s) || (s = [s]);
  const i = [], f = () => {
    i.forEach((a) => a()), i.length = 0;
  }, o = (a, p, v, d) => (a.addEventListener(p, v, d), () => a.removeEventListener(p, v, d)), g = $(() => [ve(n), ce(r)], ([a, p]) => {
    f(), a && i.push(...t.flatMap((v) => s.map((d) => o(a, v, d, p))));
  }, { immediate: !0, flush: "post" }), S = () => {
    g(), f();
  };
  return de(S), S;
}
function rt(e, n = !1) {
  const t = y(), s = () => t.value = !!e();
  return s(), et(s, n), t;
}
const ne = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, le = "__vueuse_ssr_handlers__";
ne[le] = ne[le] || {};
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 at(e, n = {}) {
  const { document: t = nt, autoExit: s = !1 } = n, r = t == null ? void 0 : t.querySelector("html"), i = y(!1);
  let f = re[0];
  const o = rt(() => {
    if (t) {
      for (const h of re)
        if (h[1] in t)
          return f = h, !0;
    } else
      return !1;
    return !1;
  }), [g, S, a, , p] = f;
  async function v() {
    o.value && (t != null && t[a] && await t[S](), i.value = !1);
  }
  async function d() {
    if (!o.value)
      return;
    await v();
    const h = ve(r);
    h && (await h[g](), i.value = !0);
  }
  async function u() {
    i.value ? await v() : await d();
  }
  return t && lt(t, p, () => {
    i.value = !!(t != null && t[a]);
  }, !1), s && de(v), {
    isSupported: o,
    isFullscreen: i,
    enter: d,
    exit: v,
    toggle: u
  };
}
var ae;
(function(e) {
  e.UP = "UP", e.RIGHT = "RIGHT", e.DOWN = "DOWN", e.LEFT = "LEFT", e.NONE = "NONE";
})(ae || (ae = {}));
var ot = Object.defineProperty, oe = Object.getOwnPropertySymbols, ut = Object.prototype.hasOwnProperty, st = Object.prototype.propertyIsEnumerable, ue = (e, n, t) => n in e ? ot(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t, it = (e, n) => {
  for (var t in n || (n = {}))
    ut.call(n, t) && ue(e, t, n[t]);
  if (oe)
    for (var t of oe(n))
      st.call(n, t) && ue(e, t, n[t]);
  return e;
};
const ft = {
  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]
};
it({
  linear: Ze
}, ft);
const ct = { class: "das-split-panel-second" }, dt = {
  name: "DasSplitPanel"
}, vt = /* @__PURE__ */ he({
  ...dt,
  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: s } = at(), r = e, i = t, f = y(null), o = y(null), g = x(() => {
      var l;
      return console.log("分割线宽度"), console.dir(o == null ? void 0 : o.value), o != null && o.value && Number((l = o == null ? void 0 : o.value) == null ? void 0 : l.offsetWidth) - 2 || 1;
    });
    x(() => g.value + "px");
    const S = y(null), a = y(), p = y(), v = y(), d = y(0), u = y(0), h = y(!0), M = x(() => u.value + "px"), T = x(() => ({ width: M.value })), D = x(() => ({ left: M.value })), F = y(!1), O = y(!1);
    $(
      u,
      (l, m) => {
        l === 0 ? F.value = !0 : F.value = !1, l === (a == null ? void 0 : a.value) ? O.value = !0 : O.value = !1;
      },
      { immediate: !0 }
    ), $(s, (l) => {
      console.log("isFullscreen", l), B();
    });
    const I = () => {
      u.value > d.value ? (u.value = d.value, i("onDefault")) : u.value <= d.value && u.value > 0 && (u.value = 0, i("onLeft"));
    }, c = () => {
      u.value < d.value ? (u.value = d.value, i("onDefault")) : u.value >= d.value && u.value < a.value && (u.value = a.value, i("onRight"));
    }, b = y({
      mouseFlag: !1,
      startX: 0,
      startWidth: 0
    }), E = (l) => {
      r.canDrag && (b.value.mouseFlag = !0, b.value.startX = l.clientX, b.value.startWidth = u.value, document.onmousemove = N, document.onmouseup = pe, i("onMouseDown"));
    }, N = (l) => {
      if (l.preventDefault(), !b.value.mouseFlag) return;
      let k = l.clientX - b.value.startX, _ = b.value.startWidth + k;
      _ < p.value ? u.value = p.value : _ > v.value ? u.value = v.value : _ > p.value && _ < v.value && (u.value = _), i("onMouseMove");
    }, pe = () => {
      b.value.mouseFlag = !1, document.onmousemove = null, document.onmouseup = null, i("onMouseUp");
    }, C = (l, m) => {
      let k = 0;
      return typeof m == "number" && m <= 1 ? k = l * m : typeof m == "number" ? k = m : k = Number(m), k;
    }, H = () => {
      let l = 0;
      r.defaultSplit.first !== void 0 ? (l = C(a.value, r.defaultSplit.first), d.value = l, u.value = l) : r.defaultSplit.second !== void 0 && (typeof r.defaultSplit.second == "number" && r.defaultSplit.second <= 1 ? l = C(a.value, 1 - r.defaultSplit.second) : l = a.value - C(a.value, r.defaultSplit.second), d.value = l, u.value = l), r.defaultClose && r.defaultClose == "first" ? u.value = 0 : r.defaultClose && r.defaultClose == "second" && (u.value = a.value);
    }, me = () => {
      H();
    };
    let K = y(!0);
    const B = () => {
      var m;
      console.log("onresize");
      let l = !1;
      if (O.value && (l = !0), !!(f != null && f.value) && (a.value = Number(((m = f == null ? void 0 : f.value) == null ? void 0 : m.offsetWidth) - (g == null ? void 0 : g.value)) || 0, p.value = C(a.value, r.firstMin), v.value = a.value - C(a.value, r.secondMin), console.log(a.value, p.value, v.value), l && (u.value = a.value), h.value === !0)) {
        if (H(), K.value) {
          K.value = !1;
          return;
        }
        h.value = !1;
      }
    };
    return se(() => {
      var l;
      h.value = !0, S.value = new ResizeObserver(Ke(B, 30)), (l = S.value) == null || l.observe(f == null ? void 0 : f.value), B();
    }), n({
      toLeft: I,
      toRight: c,
      reset: me
    }), (l, m) => (A(), z(
      "div",
      {
        class: "das-ui-split-panel",
        ref_key: "$splitPanel",
        ref: f,
        style: L(l.boxStyle)
      },
      [
        w(
          "div",
          {
            class: "das-split-panel-first",
            style: L(T.value)
          },
          [
            R(l.$slots, "firstSlot", {}, void 0, !0)
          ],
          4
          /* STYLE */
        ),
        w(
          "div",
          {
            class: "das-split-panel-mid",
            ref_key: "$splitLine",
            ref: o,
            style: L(D.value)
          },
          [
            l.canFold ? (A(), z("span", {
              key: 0,
              onClick: I
            }, [
              R(l.$slots, "leftBtn", {}, () => [
                w(
                  "span",
                  {
                    class: Q(["das-split-panel-btn left", [O.value ? "isBase" : ""]])
                  },
                  [
                    J(q(we), { size: "medium" })
                  ],
                  2
                  /* CLASS */
                )
              ], !0)
            ])) : P("v-if", !0),
            w(
              "div",
              {
                class: Q(["das-split-panel-line", { hide: F.value || O.value, canDrag: r.canDrag }]),
                onDragstart: m[0] || (m[0] = X(() => {
                }, ["stop", "prevent"])),
                onMousedown: X(E, ["prevent"]),
                onClick: m[1] || (m[1] = X(() => {
                }, ["stop", "prevent"]))
              },
              [
                P(' <slot name="splitLine"> '),
                m[2] || (m[2] = w(
                  "div",
                  { class: "das-split-panel-divider" },
                  null,
                  -1
                  /* CACHED */
                )),
                P(" </slot> ")
              ],
              34
              /* CLASS, NEED_HYDRATION */
            ),
            l.canFold ? (A(), z("span", {
              key: 1,
              onClick: c
            }, [
              R(l.$slots, "rightBtn", {}, () => [
                w(
                  "span",
                  {
                    class: Q(["das-split-panel-btn right", [F.value ? "isBase" : ""]])
                  },
                  [
                    J(q(Ee), { size: "medium" })
                  ],
                  2
                  /* CLASS */
                )
              ], !0)
            ])) : P("v-if", !0)
          ],
          4
          /* STYLE */
        ),
        w("div", ct, [
          R(l.$slots, "secondSlot", {}, void 0, !0)
        ])
      ],
      4
      /* STYLE */
    ));
  }
}), pt = (e, n) => {
  const t = e.__vccOpts || e;
  for (const [s, r] of n)
    t[s] = r;
  return t;
}, mt = /* @__PURE__ */ pt(vt, [["__scopeId", "data-v-ba259a73"]]), gt = {
  "--das-ui-split-panel-color-primary": "#5582F3",
  // 主题色
  "--das-ui-split-panel-color-line": "#D9D9D9",
  // 线条色
  "--das-ui-split-panel-color-btn": "#999999"
  // 按钮icon色
};
Te(gt);
const Et = Oe(mt), wt = () => y(null), Tt = { name: "splitPanel 分割面板" };
export {
  Et as DasSplitPanel,
  wt as DasSplitPanelRef,
  Tt as default
};
