"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.Card = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _loading = _interopRequireDefault(require("@alifd/next/lib/loading"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _classnames3 = _interopRequireDefault(require("classnames"));
var _cardHeader = require("../card-header");
var _useFiledState2 = require("../../../../utils/hooks/useFiledState");
var _operations = _interopRequireDefault(require("../../../../common/operations"));
var _excluded = ["title", "description", "visibleButtonCount", "className", "actionBar", "actionButtons", "loading", "tagGroup", "style", "hasCollapse", "isDialogCard", "explanation", "explanationTooltipProps", "children", "segmentLine", "defaultCollapse", "setCollapse", "isCollapse", "hasDivider", "operations", "operationConfig", "lastSaveTime", "bodyPadding", "text"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(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; }
var Card = function Card(props) {
  var _classnames, _classnames2;
  var title = props.title,
    description = props.description,
    visibleButtonCount = props.visibleButtonCount,
    className = props.className,
    actionBar = props.actionBar,
    actionButtons = props.actionButtons,
    loading = props.loading,
    tagGroup = props.tagGroup,
    style = props.style,
    hasCollapse = props.hasCollapse,
    isDialogCard = props.isDialogCard,
    explanation = props.explanation,
    explanationTooltipProps = props.explanationTooltipProps,
    children = props.children,
    segmentLine = props.segmentLine,
    defaultCollapse = props.defaultCollapse,
    setCollapse = props.setCollapse,
    isCollapse = props.isCollapse,
    hasDivider = props.hasDivider,
    operations = props.operations,
    operationConfig = props.operationConfig,
    lastSaveTime = props.lastSaveTime,
    bodyPadding = props.bodyPadding,
    text = props.text,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(props, _excluded);
  var _useFiledState = (0, _useFiledState2.useFiledState)({
      value: isCollapse,
      defaultValue: defaultCollapse,
      onChange: setCollapse
    }, 'isCollapse' in props),
    collapsed = _useFiledState[0],
    _onCollapse = _useFiledState[1];
  var cardBody = children;
  var layout = 'flow';
  var content = /*#__PURE__*/React.createElement(React.Fragment, null, (title || hasCollapse || actionBar || actionButtons || tagGroup) && /*#__PURE__*/React.createElement(_cardHeader.CardHeader, {
    text: text,
    title: title,
    description: description,
    visibleButtonCount: visibleButtonCount,
    hasCollapse: hasCollapse,
    actionBar: actionBar,
    actionButtons: actionButtons,
    tagGroup: tagGroup,
    collapsed: collapsed,
    onCollapse: function onCollapse() {
      return _onCollapse(!collapsed);
    },
    explanation: explanation,
    explanationTooltipProps: explanationTooltipProps,
    hasDivider: hasDivider
  }), /*#__PURE__*/React.createElement("div", {
    className: (0, _classnames3["default"])('fusion-ui-card-body', {})
  }, !collapsed && /*#__PURE__*/React.createElement("div", {
    className: (0, _classnames3["default"])('fusion-ui-card-body__panel', "fusion-ui-card-body__panel--" + layout, (_classnames = {}, _classnames["fusion-ui-card-body__nopadding"] = bodyPadding, _classnames))
  }, cardBody)), !collapsed && /*#__PURE__*/React.createElement("div", {
    className: (0, _classnames3["default"])('fusion-ui-card-footer-actions', {})
  }, /*#__PURE__*/React.createElement(_operations["default"], {
    operations: operations,
    operationConfig: operationConfig,
    lastSaveTime: lastSaveTime
  })));
  return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
    className: (0, _classnames3["default"])('fusion-ui-card', (_classnames2 = {
      'fusion-ui-card--dialog': isDialogCard
    }, _classnames2[className] = className, _classnames2)),
    style: style || {}
  }, otherProps, {
    "data-name": "Card"
  }), loading ? /*#__PURE__*/React.createElement(_loading["default"], {
    visible: true,
    inline: false,
    size: "medium"
  }, content) : content);
};
exports.Card = Card;
Card.defaultProps = {
  segmentLine: false,
  loading: false,
  isDialogCard: false,
  hasCollapse: false,
  defaultCollapse: false
};
Card.displayName = 'Card';