import "../styles/reset.css";
import "./resize-layout.less";
import { PropTypes as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__, withInstall as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_withInstall__ } from "../shared";
import { computed as __WEBPACK_EXTERNAL_MODULE_vue_computed__, createVNode as __WEBPACK_EXTERNAL_MODULE_vue_createVNode__, defineComponent as __WEBPACK_EXTERNAL_MODULE_vue_defineComponent__, nextTick as __WEBPACK_EXTERNAL_MODULE_vue_nextTick__, onBeforeUnmount as __WEBPACK_EXTERNAL_MODULE_vue_onBeforeUnmount__, onMounted as __WEBPACK_EXTERNAL_MODULE_vue_onMounted__, ref as __WEBPACK_EXTERNAL_MODULE_vue_ref__, toRefs as __WEBPACK_EXTERNAL_MODULE_vue_toRefs__, vShow as __WEBPACK_EXTERNAL_MODULE_vue_vShow__, watch as __WEBPACK_EXTERNAL_MODULE_vue_watch__, withDirectives as __WEBPACK_EXTERNAL_MODULE_vue_withDirectives__, withModifiers as __WEBPACK_EXTERNAL_MODULE_vue_withModifiers__ } from "vue";
import { usePrefix as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_config_provider_fe8577a3_usePrefix__ } from "../config-provider";
import { AngleLeft as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_icon_a97c79c3_AngleLeft__, AngleRight as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_icon_a97c79c3_AngleRight__ } from "../icon";

;// external "../shared"

;// external "vue"

;// ../../node_modules/@babel/runtime/helpers/esm/typeof.js
function _typeof(o) {
  "@babel/helpers - typeof";

  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
    return typeof o;
  } : function (o) {
    return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  }, _typeof(o);
}

;// ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js

function toPrimitive(t, r) {
  if ("object" != _typeof(t) || !t) return t;
  var e = t[Symbol.toPrimitive];
  if (void 0 !== e) {
    var i = e.call(t, r || "default");
    if ("object" != _typeof(i)) return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return ("string" === r ? String : Number)(t);
}

;// ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js


function toPropertyKey(t) {
  var i = toPrimitive(t, "string");
  return "symbol" == _typeof(i) ? i : i + "";
}

;// ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js

function _defineProperty(e, r, t) {
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
    value: t,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[r] = t, e;
}

;// external "../config-provider"

;// external "../icon"

;// ../../packages/resize-layout/src/resize-layout.tsx


/*
 * Tencent is pleased to support the open source community by making
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available.
 *
 * Copyright (C) 2025 Tencent.  All rights reserved.
 *
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) is licensed under the MIT License.
 *
 * License for 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition):
 *
 * ---------------------------------------------------
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
 * the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */




/* harmony default export */ const resize_layout = (__WEBPACK_EXTERNAL_MODULE_vue_defineComponent__({
  name: 'ResizeLayout',
  props: {
    placement: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.placement().def('left'),
    min: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.number.def(3),
    max: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.number.def(Infinity),
    triggerWidth: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.number.def(5),
    triggerOffset: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.number.def(3),
    initialDivide: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.oneOfType([String, Number]).def('20%'),
    immediate: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool,
    disabled: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool,
    collapsible: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool,
    isCollapsed: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool.def(false),
    // 初始化折叠状态
    autoMinimize: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.oneOfType([Boolean, Number]).def(false),
    border: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool.def(true)
  },
  emits: ['before-resize', 'resizing', 'after-resize', 'collapse-change'],
  setup: function setup(props, _ref) {
    var emit = _ref.emit;
    var _toRefs = __WEBPACK_EXTERNAL_MODULE_vue_toRefs__(props),
      placement = _toRefs.placement,
      initialDivide = _toRefs.initialDivide,
      triggerOffset = _toRefs.triggerOffset,
      triggerWidth = _toRefs.triggerWidth,
      max = _toRefs.max,
      min = _toRefs.min,
      immediate = _toRefs.immediate,
      autoMinimize = _toRefs.autoMinimize,
      collapsible = _toRefs.collapsible,
      isCollapsed = _toRefs.isCollapsed;
    var collapsed = __WEBPACK_EXTERNAL_MODULE_vue_ref__(isCollapsed.value);
    var asideContentVisible = __WEBPACK_EXTERNAL_MODULE_vue_ref__(true);
    var minimized = __WEBPACK_EXTERNAL_MODULE_vue_ref__(false);
    var limitMax = __WEBPACK_EXTERNAL_MODULE_vue_ref__(null);
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    var state = __WEBPACK_EXTERNAL_MODULE_vue_ref__({});
    var bkResizeLayoutRef = __WEBPACK_EXTERNAL_MODULE_vue_ref__(null);
    var resizeProxyRef = __WEBPACK_EXTERNAL_MODULE_vue_ref__(null);
    var resizeMaskRef = __WEBPACK_EXTERNAL_MODULE_vue_ref__(null);
    var asideRef = __WEBPACK_EXTERNAL_MODULE_vue_ref__(null);
    var vertical = __WEBPACK_EXTERNAL_MODULE_vue_computed__(function () {
      return ['left', 'right'].includes(placement.value);
    });
    var cssPropKey = __WEBPACK_EXTERNAL_MODULE_vue_computed__(function () {
      return vertical.value ? 'width' : 'height';
    });
    // 转换类型
    var parseInitialDivide = __WEBPACK_EXTERNAL_MODULE_vue_computed__(function () {
      var divide = initialDivide.value;
      // 如果min不是默认值，且initialDivide不是number类型，min优先级提升
      if (min.value !== 3 && typeof divide !== 'number') {
        return "".concat(min.value, "px");
      }
      if (typeof divide === 'number') {
        divide = divide <= min.value ? "".concat(min.value, "px") : "".concat(divide, "px");
      }
      return divide;
    });
    var asideStyle = __WEBPACK_EXTERNAL_MODULE_vue_computed__(function () {
      if (collapsible.value && isCollapsed.value) {
        return _defineProperty({}, cssPropKey.value, '0px');
      }
      return _defineProperty({}, cssPropKey.value, parseInitialDivide.value);
    });
    var triggerStyle = __WEBPACK_EXTERNAL_MODULE_vue_computed__(function () {
      var style = _defineProperty(_defineProperty({}, "margin-".concat(placement.value), "".concat(triggerOffset.value - triggerWidth.value, "px")), cssPropKey.value, "".concat(triggerWidth.value, "px"));
      return style;
    });
    var parseAutoMinimize = __WEBPACK_EXTERNAL_MODULE_vue_computed__(function () {
      if (autoMinimize.value) {
        return typeof autoMinimize.value === 'boolean' ? 50 : autoMinimize.value;
      }
      return 0;
    });
    var setMaxLimit = function setMaxLimit() {
      var rect = bkResizeLayoutRef.value.getBoundingClientRect();
      limitMax.value = vertical.value ? rect.width : rect.height;
    };
    var observer = new ResizeObserver(setMaxLimit);
    // 更新 resizeProxyRef 的样式
    var updateResizeProxyStyle = function updateResizeProxyStyle() {
      resizeProxyRef.value.style.visibility = 'visible';
      switch (placement.value) {
        case 'left':
          resizeProxyRef.value.style.inset = "0 auto auto ".concat(state.value.aside.width, "px");
          break;
        case 'right':
          resizeProxyRef.value.style.inset = "0  ".concat(state.value.aside.width, "px auto auto");
          break;
        case 'top':
          resizeProxyRef.value.style.inset = "".concat(state.value.aside.height, "px auto auto 0");
          break;
        case 'bottom':
          resizeProxyRef.value.style.inset = "auto auto ".concat(state.value.aside.height, "px 0");
          break;
      }
    };
    // 更新遮罩的样式
    var updateResizeMaskStyle = function updateResizeMaskStyle() {
      resizeMaskRef.value.style.display = 'block';
      resizeMaskRef.value.style.cursor = vertical.value ? 'col-resize' : 'row-resize';
    };
    var getRealValue = function getRealValue(current) {
      return Math.min(max.value, Math.max(min.value, current), limitMax.value - triggerWidth.value);
    };
    // mousedown 事件处理
    var handleMousedown = function handleMousedown(event) {
      emit('before-resize', event);
      var asideRect = asideRef.value.getBoundingClientRect();
      state.value = Object.freeze({
        mouse: {
          clientX: event.clientX,
          clientY: event.clientY
        },
        aside: {
          width: asideRect.width,
          height: asideRect.height
        }
      });
      updateResizeMaskStyle();
      if (!immediate.value) {
        updateResizeProxyStyle();
      }
      document.onselectstart = function () {
        return false;
      };
      document.ondragstart = function () {
        return false;
      };
      var resizingCallback = function resizingCallback(value) {
        emit('resizing', value);
      };
      var handleMouseMove = function handleMouseMove(event) {
        var delta;
        switch (placement.value) {
          case 'top':
            delta = event.clientY - state.value.mouse.clientY;
            break;
          case 'right':
            delta = state.value.mouse.clientX - event.clientX;
            break;
          case 'bottom':
            delta = state.value.mouse.clientY - event.clientY;
            break;
          case 'left':
            delta = event.clientX - state.value.mouse.clientX;
        }
        var current = state.value.aside[cssPropKey.value] + delta;
        var realValue = getRealValue(current) + triggerOffset.value;
        var pixel = "".concat(realValue, "px");
        if (immediate.value) {
          asideRef.value.style[cssPropKey.value] = pixel;
        } else {
          resizeProxyRef.value.style[placement.value] = pixel;
        }
        resizingCallback(realValue);
      };
      var _handleMouseUp = function handleMouseUp() {
        resizeProxyRef.value.style.visibility = 'hidden';
        resizeMaskRef.value.style.display = 'none';
        document.removeEventListener('mousemove', handleMouseMove);
        document.removeEventListener('mouseup', _handleMouseUp);
        document.onselectstart = null;
        document.ondragstart = null;
        __WEBPACK_EXTERNAL_MODULE_vue_nextTick__(function () {
          setupAutoMinimize();
          emit('after-resize', parseFloat(resizeProxyRef.value.style[placement.value]));
        });
        if (immediate.value) {
          return false;
        }
        asideRef.value.style[cssPropKey.value] = resizeProxyRef.value.style[placement.value];
      };
      document.addEventListener('mousemove', handleMouseMove);
      document.addEventListener('mouseup', _handleMouseUp);
    };
    var setupAutoMinimize = function setupAutoMinimize() {
      if (!autoMinimize.value) {
        return false;
      }
      var asideRect = asideRef.value.getBoundingClientRect();
      // 最小化同时设置为已折叠，此时展开以初始化initial-divide数据为参考
      minimized.value = collapsed.value = asideRect[cssPropKey.value] <= parseAutoMinimize.value;
      if (!minimized.value) {
        asideContentVisible.value = true;
        return false;
      }
      setupAsideAnimation();
      __WEBPACK_EXTERNAL_MODULE_vue_nextTick__(function () {
        asideRef.value.setAttribute("data-".concat(cssPropKey.value), asideStyle.value[cssPropKey.value]);
      });
    };
    var setCollapse = function setCollapse(collapse) {
      collapsed.value = typeof collapse === 'boolean' ? collapse : !collapsed.value;
      setupAsideAnimation();
      emit('collapse-change', collapsed.value);
    };
    var setupAsideAnimation = function setupAsideAnimation() {
      var asideRect = asideRef.value.getBoundingClientRect();
      setupAsideListener(!collapsed.value);
      if (collapsed.value) {
        asideRef.value.setAttribute("data-".concat(cssPropKey.value), "".concat(asideRect[cssPropKey.value], "px"));
        asideRef.value.style[cssPropKey.value] = props.collapsible ? '0px' : '5px';
      } else {
        asideContentVisible.value = true;
        asideRef.value.style[cssPropKey.value] = asideRef.value.getAttribute("data-".concat(cssPropKey.value)) || parseInitialDivide.value;
      }
    };
    var setupAsideListener = function setupAsideListener(visible) {
      var _removeClass = function removeClass() {
        asideContentVisible.value = visible;
        asideRef.value.style.transition = '';
        asideRef.value.removeEventListener('transitionend', _removeClass);
      };
      asideRef.value.addEventListener('transitionend', _removeClass);
      asideRef.value.style.transition = "".concat(cssPropKey.value, " cubic-bezier(0.4, 0, 0.2, 1) .3s");
    };
    // 监听折叠状态变化
    __WEBPACK_EXTERNAL_MODULE_vue_watch__(isCollapsed, function () {
      collapsed.value = isCollapsed.value;
      setCollapse(collapsed.value);
    });
    __WEBPACK_EXTERNAL_MODULE_vue_onMounted__(function () {
      observer.observe(bkResizeLayoutRef.value);
    });
    __WEBPACK_EXTERNAL_MODULE_vue_onBeforeUnmount__(function () {
      if (bkResizeLayoutRef.value) {
        observer.unobserve(bkResizeLayoutRef.value);
        observer = null;
      }
    });
    var _usePrefix = __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_config_provider_fe8577a3_usePrefix__(),
      resolveClassName = _usePrefix.resolveClassName;
    return {
      collapsed: collapsed,
      asideContentVisible: asideContentVisible,
      minimized: minimized,
      limitMax: limitMax,
      state: state,
      vertical: vertical,
      cssPropKey: cssPropKey,
      bkResizeLayoutRef: bkResizeLayoutRef,
      resizeProxyRef: resizeProxyRef,
      resizeMaskRef: resizeMaskRef,
      asideRef: asideRef,
      triggerStyle: triggerStyle,
      asideStyle: asideStyle,
      handleMousedown: handleMousedown,
      setCollapse: setCollapse,
      resolveClassName: resolveClassName
    };
  },
  render: function render() {
    var _this$$slots$aside, _this$$slots, _this$$slots$collapse, _this$$slots2, _this$$slots$main, _this$$slots3;
    var bkResizeLayoutClass = ["".concat(this.resolveClassName('resize-layout')), "".concat(this.resolveClassName("resize-layout-".concat(this.placement))), _defineProperty(_defineProperty(_defineProperty({}, "".concat(this.resolveClassName('resize-layout-collapsed')), this.collapsed), "".concat(this.resolveClassName('resize-layout-border')), this.border), "".concat(this.resolveClassName('resize-layout-collapsible')), this.collapsible)];
    return __WEBPACK_EXTERNAL_MODULE_vue_createVNode__("div", {
      "ref": "bkResizeLayoutRef",
      "class": bkResizeLayoutClass
    }, [__WEBPACK_EXTERNAL_MODULE_vue_createVNode__("aside", {
      "ref": "asideRef",
      "style": this.asideStyle,
      "class": "".concat(this.resolveClassName('resize-layout-aside'))
    }, [__WEBPACK_EXTERNAL_MODULE_vue_withDirectives__(__WEBPACK_EXTERNAL_MODULE_vue_createVNode__("div", {
      "class": "".concat(this.resolveClassName('resize-layout-aside-content'))
    }, [(_this$$slots$aside = (_this$$slots = this.$slots).aside) === null || _this$$slots$aside === void 0 ? void 0 : _this$$slots$aside.call(_this$$slots)]), [[__WEBPACK_EXTERNAL_MODULE_vue_vShow__, this.asideContentVisible]]), __WEBPACK_EXTERNAL_MODULE_vue_withDirectives__(__WEBPACK_EXTERNAL_MODULE_vue_createVNode__("i", {
      "style": this.triggerStyle,
      "class": "".concat(this.resolveClassName('resize-trigger')),
      "onMousedown": __WEBPACK_EXTERNAL_MODULE_vue_withModifiers__(this.handleMousedown, ['left'])
    }, null), [[__WEBPACK_EXTERNAL_MODULE_vue_vShow__, !this.disabled && (!this.collapsed || this.autoMinimize)]]), __WEBPACK_EXTERNAL_MODULE_vue_withDirectives__(__WEBPACK_EXTERNAL_MODULE_vue_createVNode__("i", {
      "ref": "resizeProxyRef",
      "class": ["".concat(this.resolveClassName('resize-proxy')), this.placement]
    }, null), [[__WEBPACK_EXTERNAL_MODULE_vue_vShow__, !this.collapsed || this.autoMinimize]]), this.collapsible && (((_this$$slots$collapse = (_this$$slots2 = this.$slots)['collapse-trigger']) === null || _this$$slots$collapse === void 0 ? void 0 : _this$$slots$collapse.call(_this$$slots2)) || (this.collapsed ? __WEBPACK_EXTERNAL_MODULE_vue_createVNode__(__WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_icon_a97c79c3_AngleRight__, {
      "width": 26,
      "height": 26,
      "class": "".concat(this.resolveClassName('resize-collapse')),
      "onClick": this.setCollapse
    }, null) : __WEBPACK_EXTERNAL_MODULE_vue_createVNode__(__WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_icon_a97c79c3_AngleLeft__, {
      "width": 26,
      "height": 26,
      "class": "".concat(this.resolveClassName('resize-collapse')),
      "onClick": this.setCollapse
    }, null)))]), __WEBPACK_EXTERNAL_MODULE_vue_createVNode__("main", {
      "class": "".concat(this.resolveClassName('resize-layout-main'))
    }, [(_this$$slots$main = (_this$$slots3 = this.$slots).main) === null || _this$$slots$main === void 0 ? void 0 : _this$$slots$main.call(_this$$slots3)]), __WEBPACK_EXTERNAL_MODULE_vue_createVNode__("div", {
      "ref": "resizeMaskRef",
      "class": "".concat(this.resolveClassName('resize-mask'))
    }, null)]);
  }
}));
;// ../../packages/resize-layout/src/index.ts
/*
 * Tencent is pleased to support the open source community by making
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available.
 *
 * Copyright (C) 2025 Tencent.  All rights reserved.
 *
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) is licensed under the MIT License.
 *
 * License for 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition):
 *
 * ---------------------------------------------------
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
 * the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */


var BkResizeLayout = __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_withInstall__(resize_layout);
/* harmony default export */ const src = (BkResizeLayout);
export { src as default };
