"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const index = require("../../../hooks/use-namespace/index.js");
const index$1 = require("../../../../../@element-plus/icons-vue/dist/index.js");
const Vue = require("vue");
var split_bar_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ Vue.defineComponent({
  name: "ElSplitterBar",
  __name: "split-bar",
  props: {
    index: {
      type: Number,
      required: true
    },
    layout: {
      type: String,
      values: ["horizontal", "vertical"],
      default: "horizontal"
    },
    resizable: {
      type: Boolean,
      default: true
    },
    lazy: Boolean,
    startCollapsible: Boolean,
    endCollapsible: Boolean
  },
  emits: [
    "moveStart",
    "moving",
    "moveEnd",
    "collapse"
  ],
  setup(__props, { emit: __emit }) {
    const ns = index.useNamespace("splitter-bar");
    const props = __props;
    const emit = __emit;
    const isHorizontal = Vue.computed(() => props.layout === "horizontal");
    const barWrapStyles = Vue.computed(() => {
      if (isHorizontal.value) return { width: 0 };
      return { height: 0 };
    });
    const draggerStyles = Vue.computed(() => {
      return {
        width: isHorizontal.value ? "16px" : "100%",
        height: isHorizontal.value ? "100%" : "16px",
        cursor: !props.resizable ? "auto" : isHorizontal.value ? "ew-resize" : "ns-resize",
        touchAction: "none"
      };
    });
    const draggerPseudoClass = Vue.computed(() => {
      const prefix = ns.e("dragger");
      return {
        [`${prefix}-horizontal`]: isHorizontal.value,
        [`${prefix}-vertical`]: !isHorizontal.value,
        [`${prefix}-active`]: !!startPos.value
      };
    });
    const startPos = Vue.ref(null);
    const onMousedown = (e) => {
      if (!props.resizable) return;
      startPos.value = [e.pageX, e.pageY];
      emit("moveStart", props.index);
      window.addEventListener("mouseup", onMouseUp);
      window.addEventListener("mousemove", onMouseMove);
    };
    const onTouchStart = (e) => {
      if (props.resizable && e.touches.length === 1) {
        e.preventDefault();
        const touch = e.touches[0];
        startPos.value = [touch.pageX, touch.pageY];
        emit("moveStart", props.index);
        window.addEventListener("touchend", onTouchEnd);
        window.addEventListener("touchmove", onTouchMove);
      }
    };
    const onMouseMove = (e) => {
      const { pageX, pageY } = e;
      const offsetX = pageX - startPos.value[0];
      const offsetY = pageY - startPos.value[1];
      const offset = isHorizontal.value ? offsetX : offsetY;
      emit("moving", props.index, offset);
    };
    const onTouchMove = (e) => {
      if (e.touches.length === 1) {
        e.preventDefault();
        const touch = e.touches[0];
        const offsetX = touch.pageX - startPos.value[0];
        const offsetY = touch.pageY - startPos.value[1];
        const offset = isHorizontal.value ? offsetX : offsetY;
        emit("moving", props.index, offset);
      }
    };
    const onMouseUp = () => {
      startPos.value = null;
      window.removeEventListener("mouseup", onMouseUp);
      window.removeEventListener("mousemove", onMouseMove);
      emit("moveEnd", props.index);
    };
    const onTouchEnd = () => {
      startPos.value = null;
      window.removeEventListener("touchend", onTouchEnd);
      window.removeEventListener("touchmove", onTouchMove);
      emit("moveEnd", props.index);
    };
    const StartIcon = Vue.computed(() => isHorizontal.value ? index$1.ArrowLeft : index$1.ArrowUp);
    const EndIcon = Vue.computed(() => isHorizontal.value ? index$1.ArrowRight : index$1.ArrowDown);
    return (_ctx, _cache) => {
      return Vue.openBlock(), Vue.createElementBlock("div", {
        class: Vue.normalizeClass([Vue.unref(ns).b()]),
        style: Vue.normalizeStyle(barWrapStyles.value)
      }, [
        __props.startCollapsible ? (Vue.openBlock(), Vue.createElementBlock("div", {
          key: 0,
          class: Vue.normalizeClass([Vue.unref(ns).e("collapse-icon"), Vue.unref(ns).e(`${__props.layout}-collapse-icon-start`)]),
          onClick: _cache[0] || (_cache[0] = ($event) => emit("collapse", __props.index, "start"))
        }, [Vue.renderSlot(_ctx.$slots, "start-collapsible", {}, () => [(Vue.openBlock(), Vue.createBlock(Vue.resolveDynamicComponent(StartIcon.value), { style: {
          "width": "12px",
          "height": "12px"
        } }))])], 2)) : Vue.createCommentVNode("v-if", true),
        Vue.createElementVNode("div", {
          class: Vue.normalizeClass([
            Vue.unref(ns).e("dragger"),
            draggerPseudoClass.value,
            Vue.unref(ns).is("disabled", !__props.resizable),
            Vue.unref(ns).is("lazy", __props.resizable && __props.lazy)
          ]),
          style: Vue.normalizeStyle(draggerStyles.value),
          onMousedown,
          onTouchstart: onTouchStart
        }, null, 38),
        __props.endCollapsible ? (Vue.openBlock(), Vue.createElementBlock("div", {
          key: 1,
          class: Vue.normalizeClass([Vue.unref(ns).e("collapse-icon"), Vue.unref(ns).e(`${__props.layout}-collapse-icon-end`)]),
          onClick: _cache[1] || (_cache[1] = ($event) => emit("collapse", __props.index, "end"))
        }, [Vue.renderSlot(_ctx.$slots, "end-collapsible", {}, () => [(Vue.openBlock(), Vue.createBlock(Vue.resolveDynamicComponent(EndIcon.value), { style: {
          "width": "12px",
          "height": "12px"
        } }))])], 2)) : Vue.createCommentVNode("v-if", true)
      ], 6);
    };
  }
});
exports.default = split_bar_vue_vue_type_script_setup_true_lang_default;
