import { _ as _defineProperty } from '../_verture/defineProperty-62acccfc.js';
import { _ as _slicedToArray } from '../_verture/slicedToArray-76060636.js';
import { jsxs, jsx } from 'react/jsx-runtime';
import { useRef, useState, useEffect } from 'react';
import DoubleLeft from '@iam-com/icons/DoubleLeft';
import DoubleRight from '@iam-com/icons/DoubleRight';
import { $ as $prefixCls } from '../_verture/constant-66aa48a1.js';
import clsx from 'clsx';
import { a as getAutoHeightDuration } from '../_verture/util-7e1fb1e2.js';
import { s as styleInject } from '../_verture/style-inject.es-300983ab.js';
import '../_verture/typeof-498dd2b1.js';
import '../_verture/unsupportedIterableToArray-cb478f24.js';

var css_248z = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2021/10/20 下午2:08\n* @description color\n*/\n.paraui-v3-collapse-layout {\n  height: 100%;\n  width: 100%;\n  position: relative;\n  overflow: hidden;\n  height: 100%;\n  width: 100%;\n  position: relative;\n  overflow: hidden;\n}\n.paraui-v3-collapse-layout > .collapse-layout-click > .collapse-layout-icon-transform-top {\n  transform: rotate(90deg);\n}\n.paraui-v3-collapse-layout > .collapse-layout-click > .collapse-layout-icon-transform-bottom {\n  transform: rotate(-90deg);\n}\n.paraui-v3-collapse-layout > .collapse-layout-click > .collapse-layout-icon-transform-right {\n  transform: rotate(180deg);\n}\n.paraui-v3-collapse-layout > .collapse-layout-display {\n  overflow: hidden;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-left .collapse-layout-click span, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-right .collapse-layout-click span, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-top .collapse-layout-click span, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-bottom .collapse-layout-click span {\n  font-size: 12px;\n  font-weight: 400;\n  text-align: center;\n  color: rgb(54, 102, 214);\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-right > .collapse-layout-click {\n  position: absolute;\n  top: 50%;\n  left: \"\";\n  width: 20px;\n  height: 72px;\n  background: rgba(171, 176, 185, 0.12);\n  text-align: center;\n  cursor: pointer;\n  margin-top: -36px;\n  z-index: 1;\n  display: flex;\n  justify-content: center;\n  padding: 2px;\n  transition-property: right;\n  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n  transition-delay: 0ms;\n  right: 0px;\n  border-radius: 4px 0 0 4px;\n  border-right: 1px solid rgb(54, 102, 214);\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-right > .collapse-layout-display > .collapse-layout-display-shadow {\n  transition-property: margin-right;\n  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n  transition-delay: 0ms;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-left > .collapse-layout-click {\n  position: absolute;\n  top: 50%;\n  left: 0;\n  width: 20px;\n  height: 72px;\n  background: rgba(171, 176, 185, 0.12);\n  text-align: center;\n  cursor: pointer;\n  margin-top: -36px;\n  z-index: 1;\n  display: flex;\n  justify-content: center;\n  padding: 2px;\n  transition-property: left;\n  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n  transition-delay: 0ms;\n  border-left: 1px solid rgb(54, 102, 214);\n  border-radius: 0 4px 4px 0;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-left > .collapse-layout-display > .collapse-layout-display-shadow {\n  transition-property: margin-left;\n  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n  transition-delay: 0ms;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-left > div, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-right > div {\n  display: inline-block;\n  vertical-align: middle;\n  height: 100%;\n  position: relative;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-left > .collapse-layout-display > .collapse-layout-display-shadow, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-right > .collapse-layout-display > .collapse-layout-display-shadow {\n  height: 100%;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-left > .collapse-layout-display, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-left > .collapse-layout-default, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-right > .collapse-layout-display, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-right > .collapse-layout-default {\n  transition: width;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-left > .collapse-layout-click, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-right > .collapse-layout-click {\n  flex-direction: column;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-top > .collapse-layout-click {\n  position: absolute;\n  top: 0;\n  left: 50%;\n  width: 72px;\n  height: 20px;\n  background: rgba(171, 176, 185, 0.12);\n  text-align: center;\n  cursor: pointer;\n  margin-top: 0;\n  z-index: 1;\n  display: flex;\n  justify-content: center;\n  padding: 2px;\n  transition-property: top;\n  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n  transition-delay: 0ms;\n  margin-left: -36px;\n  border-top: 1px solid rgb(54, 102, 214);\n  border-radius: 0 0 4px 4px;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-top > .collapse-layout-display > .collapse-layout-display-shadow {\n  transition-property: margin-top;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-bottom > .collapse-layout-click {\n  position: absolute;\n  top: \"\";\n  left: 50%;\n  width: 72px;\n  height: 20px;\n  background: rgba(171, 176, 185, 0.12);\n  text-align: center;\n  cursor: pointer;\n  margin-top: 0;\n  z-index: 1;\n  display: flex;\n  justify-content: center;\n  padding: 2px;\n  transition-property: bottom;\n  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n  transition-delay: 0ms;\n  margin-left: -36px;\n  bottom: 0px;\n  border-bottom: 1px solid rgb(54, 102, 214);\n  border-radius: 4px 4px 0 0;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-bottom > .collapse-layout-display > .collapse-layout-display-shadow {\n  transition-property: margin-bottom;\n  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n  transition-delay: 0ms;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-top > .collapse-layout-display, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-top > .collapse-layout-default, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-bottom > .collapse-layout-display, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-bottom > .collapse-layout-default {\n  transition-property: height;\n  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n  transition-delay: 0ms;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-top > .collapse-layout-display > .collapse-layout-display-shadow, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-bottom > .collapse-layout-display > .collapse-layout-display-shadow {\n  width: 100%;\n}\n.paraui-v3-collapse-layout.paraui-v3-collapse-layout-top > div, .paraui-v3-collapse-layout.paraui-v3-collapse-layout-bottom > div {\n  display: block;\n  width: 100%;\n  position: relative;\n}";
styleInject(css_248z);

/**
 * @author zhanzl
 * @date 2022/08/09
 */
var CollapseLayout = function CollapseLayout(props) {
  var _props$type = props.type,
    type = _props$type === void 0 ? 'left' : _props$type,
    showLabel = props.showLabel,
    _props$open = props.open,
    open = _props$open === void 0 ? false : _props$open,
    hideLabel = props.hideLabel,
    _props$spacing = props.spacing,
    spacing = _props$spacing === void 0 ? 20 : _props$spacing,
    _props$zoomLength = props.zoomLength,
    zoomLength = _props$zoomLength === void 0 ? 0 : _props$zoomLength,
    _props$unit = props.unit,
    unit = _props$unit === void 0 ? 'px' : _props$unit,
    style = props.style,
    _props$className = props.className,
    className = _props$className === void 0 ? '' : _props$className,
    onClickBtn = props.onClickBtn;
  var displayRef = useRef(null);
  /**
   * 处理动画时间
   * */
  var handTime = function handTime() {
    var dom = displayRef.current;
    if (!dom) return 0;
    var rect = dom.getBoundingClientRect();
    var durationHand = getAutoHeightDuration(rect.width);
    return durationHand;
  };
  var duration = handTime(); // 动画时间
  /**
   * 当前为收起还是展开
   */
  var _useState = useState(),
    _useState2 = _slicedToArray(_useState, 2),
    showBox = _useState2[0],
    setShowBox = _useState2[1];
  // 渲染配置
  var typeConfig = {
    layout: {
      left: ['display', 'default'],
      right: ['default', 'display'],
      top: ['display', 'default'],
      bottom: ['default', 'display']
    }
  };
  // 首字母大写
  var formatterType = function formatterType(str) {
    var newStr = str.slice(0, 1).toUpperCase() + str.slice(1);
    return newStr;
  };
  // 计算方位
  var hangWH = function hangWH() {
    var wH = 'width';
    if (type === "top" || type === "bottom") {
      wH = 'height';
    }
    return wH;
  };
  // 收缩容器的样式
  var handDisplayStyle = function handDisplayStyle() {
    var json = {};
    var collapseL = (showBox ? zoomLength : 0) + unit; // 收缩长度
    var wH = hangWH();
    json[wH] = collapseL;
    json['transitionDuration'] = duration + 'ms';
    return json;
  };
  // 收缩容器的样式,里面的样式
  var handDisplayShowStyle = function handDisplayShowStyle() {
    var json = {};
    var direction = "margin".concat(formatterType(type));
    var wH = hangWH();
    json[wH] = zoomLength + unit;
    json[direction] = (showBox ? 0 : zoomLength) + unit;
    json['transitionDuration'] = duration + 'ms';
    return json;
  };
  // 自适应容器的样式
  var handDefaultStyle = function handDefaultStyle() {
    var json = {};
    var wH = hangWH();
    var collapseL = showBox ? zoomLength : 0; // 收缩长度
    json[wH] = "calc(100% - ".concat(collapseL + spacing).concat(unit);
    var direction = "margin".concat(formatterType(type));
    json[direction] = spacing + unit;
    json['transitionDuration'] = duration + 'ms';
    return json;
  };
  // 布局
  var Layout = function Layout() {
    return typeConfig.layout[type].map(function (key, idx) {
      switch (key) {
        case "display":
          // 可收缩的
          return jsx("div", Object.assign({
            className: "collapse-layout-display",
            style: handDisplayStyle()
          }, {
            children: jsx("div", Object.assign({
              className: "collapse-layout-display-shadow",
              style: handDisplayShowStyle(),
              ref: displayRef
            }, {
              children: props.displayContent
            }))
          }), idx);
        default:
          return jsx("div", Object.assign({
            className: "collapse-layout-default",
            style: handDefaultStyle()
          }, {
            children: props.defaultContent
          }), idx);
      }
    });
  };
  /** 点击切换按钮 */
  var clickBtn = function clickBtn() {
    setShowBox(!showBox);
    onClickBtn && onClickBtn(!showBox);
  };
  /**
   * 展开收起按钮
   * */
  var handBtn = function handBtn() {
    var _style;
    /**
     * 计算后的展示文字
     */
    var computeLabel = showBox ? showLabel : hideLabel;
    return jsxs("div", Object.assign({
      className: "collapse-layout-click collapse-layout-click-label-".concat(!!computeLabel),
      style: (_style = {}, _defineProperty(_style, type, "".concat(showBox ? zoomLength : 0).concat(unit)), _defineProperty(_style, "transitionDuration", duration + 'ms'), _style),
      onClick: clickBtn
    }, {
      children: [computeLabel && jsx("span", {
        children: computeLabel
      }), showBox ? jsx(DoubleLeft, {
        className: "collapse-layout-icon-transform-".concat(type)
      }) : jsx(DoubleRight, {
        className: "collapse-layout-icon-transform-".concat(type)
      })]
    }));
  };
  useEffect(function () {
    setShowBox(open);
  }, [open]);
  return jsxs("div", Object.assign({
    className: clsx("".concat($prefixCls, "-collapse-layout"), "".concat($prefixCls, "-collapse-layout-").concat(showBox), "".concat($prefixCls, "-collapse-layout-").concat(type), "".concat($prefixCls, "-collapse-layout-").concat(type, "-").concat(showBox), className),
    style: style
  }, {
    children: [handBtn(), Layout()]
  }));
};

export { CollapseLayout as default };
