import _extends from "@babel/runtime/helpers/extends";
import _Loading from "@alifd/next/es/loading";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
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"];
import * as React from 'react';
import classnames from 'classnames';
import { CardHeader } from "../card-header";
import { useFiledState } from "../../../../utils/hooks/useFiledState";
import Operations from "../../../../common/operations";
export 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 = _objectWithoutPropertiesLoose(props, _excluded);
  var _useFiledState = 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, {
    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: classnames('fusion-ui-card-body', {})
  }, !collapsed && /*#__PURE__*/React.createElement("div", {
    className: classnames('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: classnames('fusion-ui-card-footer-actions', {})
  }, /*#__PURE__*/React.createElement(Operations, {
    operations: operations,
    operationConfig: operationConfig,
    lastSaveTime: lastSaveTime
  })));
  return /*#__PURE__*/React.createElement("div", _extends({
    className: classnames('fusion-ui-card', (_classnames2 = {
      'fusion-ui-card--dialog': isDialogCard
    }, _classnames2[className] = className, _classnames2)),
    style: style || {}
  }, otherProps, {
    "data-name": "Card"
  }), loading ? /*#__PURE__*/React.createElement(_Loading, {
    visible: true,
    inline: false,
    size: "medium"
  }, content) : content);
};
Card.defaultProps = {
  segmentLine: false,
  loading: false,
  isDialogCard: false,
  hasCollapse: false,
  defaultCollapse: false
};
Card.displayName = 'Card';