import React, { useContext } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
var Card = function (props) {
    var _a;
    var _b = props.bordered, bordered = _b === void 0 ? true : _b, _c = props.active, active = _c === void 0 ? false : _c, _d = props.hoverable, hoverable = _d === void 0 ? false : _d, customisedCls = props.prefixCls, title = props.title, extra = props.extra, header = props.header, headerStyle = props.headerStyle, actions = props.actions, footer = props.footer, footerStyle = props.footerStyle, className = props.className, style = props.style, children = props.children;
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('card', configContext.prefixCls, customisedCls);
    var cls = classNames(prefixCls, className, (_a = {},
        _a[prefixCls + "_bordered"] = bordered,
        _a[prefixCls + "_active"] = active,
        _a[prefixCls + "_hoverable"] = hoverable,
        _a));
    var renderHeader = function () {
        if (header) {
            return header;
        }
        else if (title || extra) {
            return (React.createElement("div", { className: prefixCls + "__header", style: headerStyle },
                title,
                extra));
        }
        else {
            return null;
        }
    };
    var renderFooter = function () {
        if (footer) {
            return footer;
        }
        else if (actions) {
            return (React.createElement("div", { className: prefixCls + "__footer", style: footerStyle }, actions));
        }
        else {
            return null;
        }
    };
    var renderChildren = function () {
        if (children) {
            return React.Children.map(children, function (child) {
                if (!React.isValidElement(child)) {
                    return child;
                }
                var childElement = child;
                if (childElement.type.displayName === 'CardContent') {
                    var childProps = {
                        prefixCls: prefixCls,
                    };
                    return React.cloneElement(childElement, childProps);
                }
                else {
                    return child;
                }
            });
        }
        return null;
    };
    return (React.createElement("div", { className: cls, style: style },
        renderHeader(),
        renderChildren(),
        renderFooter()));
};
Card.displayName = 'Card';
export default Card;
//# sourceMappingURL=card.js.map