import { jsx } from 'react/jsx-runtime';
import RcCollapse from 'rc-collapse';
import { a as $rcPrefixCls, $ as $prefixCls } from '../_verture/constant-66aa48a1.js';
import * as React from 'react';
import Right from '@iam-com/icons/Right';
import { s as styleInject } from '../_verture/style-inject.es-300983ab.js';

var CollapsePanelProps = function CollapsePanelProps(props) {
  var _props$className = props.className,
    className = _props$className === void 0 ? '' : _props$className,
    _props$showArrow = props.showArrow,
    showArrow = _props$showArrow === void 0 ? true : _props$showArrow;
  /** 处理className */
  var handClass = function handClass() {
    var str = '';
    if (className) str += className;
    if (!showArrow) str += ' collapse-panel-no-arrow';
    return str;
  };
  return jsx(RcCollapse.Panel, Object.assign({}, props, {
    className: handClass(),
    prefixCls: $rcPrefixCls + '-collapse'
  }));
};

var isValidElement = React.isValidElement;
function replaceElement(element, replacement, props) {
  if (!isValidElement(element)) return replacement;
  return /*#__PURE__*/React.cloneElement(element, typeof props === 'function' ? props(element.props || {}) : props);
}
function cloneElement(element, props) {
  return replaceElement(element, element, props);
}
/** toArray */
function toArray(list) {
  if (!list) {
    return [];
  }
  return Array.isArray(list) ? list : [list];
}
/** omit */
function omit(obj, fields) {
  var clone = Object.assign({}, obj);
  if (Array.isArray(fields)) {
    fields.forEach(function (key) {
      delete clone[key];
    });
  }
  return clone;
}

// ================== Collapse Motion ==================
var getCollapsedHeight = function getCollapsedHeight() {
  return {
    height: 0,
    opacity: 0
  };
};
var getRealHeight = function getRealHeight(node) {
  var scrollHeight = node.scrollHeight;
  return {
    height: scrollHeight,
    opacity: 1
  };
};
var getCurrentHeight = function getCurrentHeight(node) {
  return {
    height: node ? node.offsetHeight : 0
  };
};
var skipOpacityTransition = function skipOpacityTransition(_, event) {
  return (event === null || event === void 0 ? void 0 : event.deadline) === true || event.propertyName === 'height';
};
var collapseMotion = {
  motionName: 'collapse-motion-collapse',
  onAppearStart: getCollapsedHeight,
  onEnterStart: getCollapsedHeight,
  onAppearActive: getRealHeight,
  onEnterActive: getRealHeight,
  onLeaveStart: getCurrentHeight,
  onLeaveActive: getCollapsedHeight,
  onAppearEnd: skipOpacityTransition,
  onEnterEnd: skipOpacityTransition,
  onLeaveEnd: skipOpacityTransition,
  motionDeadline: 500
};

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 {\n  font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, WenQuanYi Micro Hei, sans-serif;\n  font-size: 14px;\n  font-weight: 400;\n  background-color: white;\n  border-bottom: 1px solid rgba(171, 176, 185, 0.4);\n}\n.paraui-v3-collapse .collapse-motion-collapse {\n  overflow: hidden;\n  transition: height 0.2s cubic-bezier(0.645, 0.045, 0.355, 1), opacity 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) !important;\n}\n.paraui-v3-collapse > .component-collapse-item {\n  border-top: 1px solid rgba(171, 176, 185, 0.4);\n}\n.paraui-v3-collapse > .component-collapse-item > .component-collapse-header {\n  display: flex;\n  align-items: center;\n  padding: 16px;\n  color: rgb(46, 55, 67);\n  cursor: pointer;\n  font-weight: 700;\n}\n.paraui-v3-collapse > .component-collapse-item > .component-collapse-header > .collapse-svg-box {\n  line-height: 0;\n  margin-right: 16px;\n}\n.paraui-v3-collapse > .component-collapse-item > .component-collapse-header > .collapse-svg-box svg {\n  color: rgb(46, 55, 67);\n}\n.paraui-v3-collapse > .component-collapse-item > .component-collapse-header > .collapse-svg-box .collapse-expand-svg {\n  transition: all 0.3s, visibility 0s;\n  color: rgb(46, 55, 67);\n}\n.paraui-v3-collapse > .component-collapse-item > .component-collapse-header > .component-collapse-extra {\n  line-height: 0;\n  margin-left: auto;\n}\n.paraui-v3-collapse > .component-collapse-item > .component-collapse-header > .component-collapse-extra svg {\n  color: rgb(46, 55, 67);\n}\n.paraui-v3-collapse > .component-collapse-item > .component-collapse-content.collapse-content-hidden {\n  display: none;\n}\n.paraui-v3-collapse > .component-collapse-item > .component-collapse-content > .component-collapse-content-box {\n  padding: 0 16px 16px;\n  color: rgb(46, 55, 67);\n  font-size: 14px;\n}\n.paraui-v3-collapse > .component-collapse-item.component-collapse-item-active > .component-collapse-header > .collapse-svg-box .collapse-expand-svg {\n  transform: rotate(90deg);\n}\n.paraui-v3-collapse.paraui-v3-collapse-svg-right > .component-collapse-item > .component-collapse-header {\n  padding-right: 40px;\n  position: relative;\n}\n.paraui-v3-collapse.paraui-v3-collapse-svg-right > .component-collapse-item > .component-collapse-header > .collapse-svg-box {\n  position: absolute;\n  right: 12px;\n  top: 17px;\n  margin-right: 0;\n}\n.paraui-v3-collapse > .component-collapse-item-disabled > .component-collapse-header {\n  color: rgb(46, 55, 67);\n  cursor: not-allowed;\n  background-color: rgba(171, 176, 185, 0.12);\n}\n.paraui-v3-collapse > .component-collapse-item-disabled > .component-collapse-header > .collapse-svg-box svg {\n  color: rgb(46, 55, 67);\n}\n.paraui-v3-collapse > .component-collapse-item-disabled > .component-collapse-header > .collapse-svg-box .collapse-expand-svg {\n  color: rgb(46, 55, 67);\n}\n.paraui-v3-collapse > .component-collapse-item-disabled > .component-collapse-header > .component-collapse-extra svg {\n  color: rgb(46, 55, 67);\n}";
styleInject(css_248z);

var Collapse = function Collapse(props) {
  var _props$className = props.className,
    className = _props$className === void 0 ? '' : _props$className,
    _props$expandIconPosi = props.expandIconPosition,
    expandIconPosition = _props$expandIconPosi === void 0 ? 'left' : _props$expandIconPosi;
  /** 处理字内容 */
  var getItems = function getItems() {
    var children = props.children;
    return toArray(children).map(function (child, index) {
      var _a;
      if ((_a = child.props) === null || _a === void 0 ? void 0 : _a.disabled) {
        var key = child.key || String(index);
        var _child$props = child.props,
          disabled = _child$props.disabled,
          collapsible = _child$props.collapsible;
        var childProps = Object.assign(Object.assign({}, omit(child.props, ['disabled'])), {
          key: key,
          collapsible: collapsible !== null && collapsible !== void 0 ? collapsible : disabled ? 'disabled' : undefined
        });
        return cloneElement(child, childProps);
      }
      return child;
    });
  };
  /** 处理展开图标 */
  var renderExpandIcon = function renderExpandIcon() {
    var panelProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    var expandIcon = props.expandIcon;
    var icon = expandIcon ? expandIcon(panelProps) : jsx(Right, {
      className: "collapse-expand-svg"
    });
    return jsx("div", Object.assign({
      className: "collapse-svg-box"
    }, {
      children: icon
    }));
  };
  /** 处理className */
  var handClass = function handClass() {
    var str = $prefixCls + '-collapse';
    if (className) str += ' ' + className;
    if (expandIconPosition) str += " ".concat($prefixCls, "-collapse-svg-").concat(expandIconPosition);
    return str;
  };
  /** 处理过度动画 */
  var openMotion = Object.assign(Object.assign({}, collapseMotion), {
    motionAppear: false,
    leavedClassName: "collapse-content-hidden"
  });
  return jsx(RcCollapse, Object.assign({
    openMotion: openMotion
  }, props, {
    expandIcon: renderExpandIcon,
    prefixCls: $rcPrefixCls + '-collapse',
    className: handClass()
  }, {
    children: getItems()
  }));
};
Collapse.Panel = CollapsePanelProps;

export { Collapse, Collapse as default };
