"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var antd_1 = require("antd");
var _ = require("lodash");
var Panel = /** @class */ (function (_super) {
    __extends(Panel, _super);
    function Panel() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.cardParam = {
            className: "vap-panel",
        };
        _this.state = {
            tabContext: null,
            activeTabKey: null,
        };
        return _this;
    }
    Panel.prototype.componentWillMount = function () {
        var _this = this;
        if (this.props.tabList) {
            this.setState({
                activeTabKey: this.props.tabList[0].key,
                // @ts-ignore
                tabContext: this.props.tabList[0].content
            });
            if (this.props.onTabChange) {
                this.props.onTabChange(this.props.tabList[0].key);
            }
            this.cardParam.onTabChange = function (key) {
                var tab = _.find(_this.props.tabList, { key: key });
                _this.setState({
                    activeTabKey: key,
                    // @ts-ignore
                    tabContext: tab.content
                });
                if (_this.props.onTabChange) {
                    _this.props.onTabChange(key);
                }
            };
        }
    };
    // componentDidMount() {
    //     if (!_.has(this.props, 'width') && this.props.fixed) {
    //         var div = ReactDOM.findDOMNode(this);
    //         //@ts-ignore
    //         let diff = document.body.offsetWidth - div.offsetWidth - 24;
    //         //@ts-ignore
    //         div.style.maxWidth = `calc(100% - ${diff}px)`;
    //     }
    // }
    Panel.prototype.render = function () {
        var param = {};
        if (this.props.width) {
            param.style = {
                width: this.props.width,
                minWidth: this.props.width
            };
        }
        else if (this.props.span) {
            param.span = this.props.span;
        }
        else {
            param.style = {
                flex: '1 1 auto'
            };
        }
        if (this.props.fixed) {
            if (param.style) {
                param.style.maxWidth = "calc(100% - " + this.props.fixed + "px)";
            }
            else {
                param.style = {
                    maxWidth: "calc(100% - " + this.props.fixed + "px)",
                };
            }
        }
        var className = ["vap-col"];
        if (_.has(this.props, 'title')) {
            if (_.has(this.props, 'icon')) {
                this.cardParam.title = [React.createElement(antd_1.Icon, { type: this.props.icon, className: "title-icon" }), this.props.title];
            }
            className.push("vap-panel-header");
            if (_.has(this.props, 'tabList')) {
                className.push("ant-card-had-tab");
            }
        }
        if (_.has(this.props, 'className')) {
            this.cardParam.className = this.cardParam.className + ' ' + this.props.className;
        }
        return React.createElement(antd_1.Col, __assign({ className: className.join(" ") }, param),
            React.createElement(antd_1.Card, __assign({}, this.props, this.cardParam, { activeTabKey: this.state.activeTabKey }), this.state.tabContext || this.props.children));
    };
    return Panel;
}(React.PureComponent));
exports.Panel = Panel;
var RowPanel = /** @class */ (function (_super) {
    __extends(RowPanel, _super);
    function RowPanel() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.cardParam = {
            className: "vap-panel",
        };
        _this.state = {
            activeTabKey: null,
            tabContext: null,
        };
        return _this;
    }
    RowPanel.prototype.componentWillMount = function () {
        var _this = this;
        if (this.props.tabList) {
            this.setState({
                tabContext: this.props.tabList[0].content,
                activeTabKey: this.props.tabList[0].key,
            });
            if (this.props.onTabChange) {
                this.props.onTabChange(this.props.tabList[0].key);
            }
            this.cardParam.onTabChange = function (key) {
                var tab = _.find(_this.props.tabList, { key: key });
                _this.setState({
                    activeTabKey: key,
                    // @ts-ignore
                    tabContext: tab.content
                });
                if (_this.props.onTabChange) {
                    _this.props.onTabChange(key);
                }
            };
        }
    };
    RowPanel.prototype.render = function () {
        var className = ["vap-row", "vap-row-block"];
        if (_.has(this.props, 'title')) {
            if (_.has(this.props, 'icon')) {
                this.cardParam.title = [React.createElement(antd_1.Icon, { type: this.props.icon, className: "title-icon" }), this.props.title];
            }
            className.push("vap-panel-header");
            if (_.has(this.props, 'tabList')) {
                className.push("ant-card-had-tab");
            }
        }
        if (this.props.height === 0) {
            className.push('vap-row-block-hidden');
        }
        if (_.has(this.props, 'className')) {
            this.cardParam.className = this.cardParam.className + ' ' + this.props.className;
        }
        return React.createElement("div", { className: className.join(" "), style: { height: this.props.height } },
            React.createElement(antd_1.Card, __assign({}, this.props, this.cardParam, { activeTabKey: this.state.activeTabKey }), this.props.children));
    };
    return RowPanel;
}(React.Component));
exports.RowPanel = RowPanel;
