import { __assign, __extends } from "tslib";
import { Button } from '@alicloud/console-components';
import classnames from 'classnames';
import React from 'react';
import Item from './item';
;
function InfoHeader(props) {
    var title = props.title, status = props.status, extra = props.extra, buttons = props.buttons, rightExtra = props.rightExtra;
    if (title === undefined && buttons && buttons.length === 0) {
        return null;
    }
    return React.createElement("div", { className: "lp-info-header" },
        React.createElement("div", { className: "lp-info-header-left" },
            React.createElement("p", { className: "lp-info-header-left-name" }, title),
            React.createElement("div", { className: "lp-info-header-left-status" }, status)),
        React.createElement("div", { className: "lp-info-header-right" },
            extra && React.createElement("div", { className: "lp-info-header-right-extra" }, extra),
            buttons &&
                buttons.length > 0 &&
                buttons.map(function (item, index) {
                    var title = item.title;
                    var className = classnames('lp-info-header-right-button', item.className);
                    return (React.createElement(Button, __assign({ key: 'button' + index }, item, { className: className }), title));
                }),
            rightExtra && (React.createElement("div", { className: "lp-info-header-right-extra" }, rightExtra))));
}
var Info = /** @class */ (function (_super) {
    __extends(Info, _super);
    function Info() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Info.prototype.render = function () {
        var _a = this.props, title = _a.title, attributes = _a.attributes, buttons = _a.buttons, extra = _a.extra, rightExtra = _a.rightExtra, status = _a.status, colsPerRow = _a.colsPerRow, locale = _a.locale, finishEditFunc = _a.finishEditFunc, onClick = _a.onClick, onChange = _a.onChange, isNest = _a.isNest, nest = _a.nest, needTitleColon = _a.needTitleColon, dataSource = _a.dataSource, className = _a.className;
        var resultAttributes = attributes;
        if (dataSource) {
            resultAttributes = attributes.map(function (item) {
                if (typeof item.convertDataFunc === "function" && item.dataIndex !== undefined) {
                    item["value"] = item.convertDataFunc(dataSource[item.dataIndex]);
                }
                else if (item.dataIndex) {
                    item["value"] = dataSource[item.dataIndex];
                }
                else if (!item.value) {
                    item["value"] = "";
                }
                delete item.convertDataFunc;
                delete item.dataIndex;
                return item;
            });
        }
        return (React.createElement("div", { style: this.props.style, className: classnames('lp-info', { 'lp-nest-info': isNest !== undefined ? isNest : nest }, className) },
            React.createElement(InfoHeader, { title: title, status: status, extra: extra, buttons: buttons, rightExtra: rightExtra }),
            resultAttributes && (React.createElement("div", { className: "lp-info-content" }, resultAttributes.map(function (item, index) {
                return (React.createElement(Item, __assign({ key: item.name + item.value + index, colsPerRow: colsPerRow, finishEditFunc: finishEditFunc, onClick: onClick, onChange: onChange, locale: locale, needTitleColon: needTitleColon }, item)));
            })))));
    };
    return Info;
}(React.Component));
Info.defaultProps = {
    descToggle: false,
    needTitleColon: false
};
Info.Item = Item;
export default Info;
