"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 _ = require("lodash");
var antd_1 = require("antd");
var OrganizationTree_1 = require("./DataComponents/OrganizationTree");
var StaticTree_1 = require("./DataComponents/StaticTree");
var Selection_1 = require("./DataComponents/Selection");
var utils_1 = require("../../utils");
var default_1 = /** @class */ (function (_super) {
    __extends(default_1, _super);
    function default_1() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            collapsed: false,
            searchValue: '',
        };
        return _this;
    }
    default_1.prototype.renderSelect = function () {
        var _this = this;
        switch (this.props.type) {
            case 'organization':
                return React.createElement(OrganizationTree_1.default, __assign({}, this.props.config, { onSelect: function (item, perent) { return _this.props.onSelect(item, perent); }, useRoot: false }));
            case 'organizationroot':
                return React.createElement(OrganizationTree_1.default, __assign({}, this.props.config, { onSelect: function (item, perent) { return _this.props.onSelect(item, perent); }, useRoot: true }));
            case 'tree':
                if (!_.has(this.props.config, 'treeData')) {
                    return React.createElement("div", null);
                }
                var paramTree = {
                    onSelect: function (item, node) { return _this.props.onSelect(item, node); }
                };
                if (this.props.config.filter) {
                    paramTree.searchValue = this.state.searchValue;
                }
                return React.createElement(StaticTree_1.default, __assign({}, this.props.config, paramTree));
            case 'list':
                if (!_.has(this.props.config, 'data') || !_.isArray(this.props.config.data)) {
                    return React.createElement("div", null);
                }
                var paramSelect = {};
                if (this.props.onSelect) {
                    paramSelect.onSelect = function (item) { return _this.props.onSelect(item); };
                }
                return React.createElement(Selection_1.default, __assign({}, this.props.config, paramSelect));
            case 'chart':
                var type = 'bar';
                if (_.has(this.props.config, 'type')) {
                    type = this.props.config.type;
                }
                return React.createElement("div", null);
            case 'custom':
                return React.createElement("div", null);
            default:
                return React.createElement("div", null);
        }
    };
    default_1.prototype.check = function (searchValue) {
        if (utils_1.Const.SPECIAL_CHARACTER.test(searchValue)) {
            antd_1.message.error('不能输入特殊字符');
            return;
        }
        this.setState({ searchValue: searchValue });
    };
    default_1.prototype.renderTitle = function () {
        var _this = this;
        if (this.props.type == 'tree' && _.has(this.props.config, 'filter') && this.props.config.filter) {
            return React.createElement(React.Fragment, null,
                React.createElement("span", { className: "select-trigger-close", title: "\u6536\u8D77", onClick: function () { return _this.setState({ collapsed: !_this.state.collapsed }); } },
                    React.createElement(antd_1.Icon, { type: "left-circle" })),
                React.createElement(antd_1.Input, { size: "small", className: "select-search-input", placeholder: this.props.title, onChange: function (evt) { return _this.check(evt.target.value); } }),
                _.has(this.props, 'actions') && React.createElement("div", { className: "select-extra-actions" }, this.props.actions));
        }
        return React.createElement(React.Fragment, null,
            React.createElement("span", { className: "select-trigger-close", title: "\u6536\u8D77", onClick: function () { return _this.setState({ collapsed: !_this.state.collapsed }); } },
                React.createElement(antd_1.Icon, { type: "left-circle" })),
            this.props.title,
            _.has(this.props, 'actions') && React.createElement("div", { className: "select-extra-actions" }, this.props.actions));
    };
    default_1.prototype.render = function () {
        var _this = this;
        var width = this.props.width || 250;
        var param = { style: {} };
        if (this.props.style) {
            _.extend(param.style, {}, this.props.style);
        }
        return React.createElement(antd_1.Layout.Sider, __assign({ collapsed: this.state.collapsed, className: "vap-select-bar", width: width }, param),
            React.createElement(antd_1.Card, { className: "select-bar-card", bodyStyle: { padding: 0 }, title: this.renderTitle(), style: { width: width }, bordered: false }, this.renderSelect()),
            React.createElement("div", { className: "select-trigger-open", title: "\u5C55\u5F00", onClick: function () { return _this.setState({ collapsed: !_this.state.collapsed }); }, style: { display: this.state.collapsed ? 'block' : 'none' } }));
    };
    return default_1;
}(React.PureComponent));
exports.default = default_1;
