"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("core-js/modules/es.array.iterator.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _react = _interopRequireWildcard(require("react"));
var _icons = require("@wii/icons");
var _classnames = _interopRequireDefault(require("classnames"));
var _space = _interopRequireDefault(require("../../../space"));
var _configProvider = _interopRequireDefault(require("../../../config-provider"));
var _fieldContext = _interopRequireDefault(require("../../field-context"));
var _utils = require("../../../utils");
var _wauLabelIconTip = _interopRequireDefault(require("../../../wau-label-icon-tip"));
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const Group = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
  const {
    groupProps
  } = _react.default.useContext(_fieldContext.default);
  const {
    children,
    collapsible,
    defaultCollapsed,
    style,
    labelLayout,
    title,
    tooltip,
    direction,
    size = 32,
    titleStyle,
    titleRender,
    extra
  } = {
    ...groupProps,
    ...props
  };
  const [collapsed, setCollapsed] = (0, _utils.useMountMergeState)(() => defaultCollapsed || false, {
    value: props.collapsed,
    onChange: props.onCollapse
  });
  const {
    getPrefixCls
  } = (0, _react.useContext)(_configProvider.default.ConfigContext);
  const className = getPrefixCls('pro-form-group');
  const collapsibleButton = collapsible && /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.RightOutlined, {
    style: {
      marginRight: 8
    },
    rotate: !collapsed ? 90 : undefined
  });
  const label = /*#__PURE__*/(0, _jsxRuntime.jsx)(_wauLabelIconTip.default, {
    label: collapsibleButton ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      children: [collapsibleButton, title]
    }) : title,
    tooltip: tooltip
  });
  const titleDom = titleRender ? titleRender(label, props) : label;
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: (0, _classnames.default)(className, {
      [`${className}-twoLine`]: labelLayout === 'twoLine'
    }),
    style: style,
    ref: ref,
    children: [(title || tooltip || extra) && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: `${className}-title`,
      style: titleStyle,
      onClick: () => {
        setCollapsed(!collapsed);
      },
      children: extra ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        style: {
          display: 'flex',
          width: '100%',
          alignItems: 'center',
          justifyContent: 'space-between'
        },
        children: [titleDom, /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
          onClick: e => e.stopPropagation(),
          children: extra
        })]
      }) : titleDom
    }), collapsible && collapsed ? null : /*#__PURE__*/(0, _jsxRuntime.jsx)(_space.default, {
      className: `${className}-container`,
      size: size,
      direction: direction,
      children: children
    })]
  });
});
Group.displayName = 'ProForm-Group';
var _default = Group;
exports.default = _default;