"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
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);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
            t[p[i]] = s[p[i]];
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var has = require("lodash/has");
var includes = require("lodash/includes");
var React = require("react");
var styled_components_1 = require("styled-components");
var Badge_1 = require("./Badge");
var Divider_1 = require("./Divider");
var DropDownButton_1 = require("./DropDownButton");
var Txt_1 = require("./Txt");
var ButtonWrapper = styled_components_1.default.button(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\tborder: 0;\n\tbackground: none;\n\tdisplay: block;\n\tmargin-top: 5px;\n\tmargin-bottom: 5px;\n\ttext-align: left;\n\tmin-width: 182px;\n\tpadding-left: 10px;\n\tpadding-right: 10px;\n\tpadding-top: 3px;\n\tpadding-bottom: 3px;\n\tcursor: pointer;\n\n\t&:hover {\n\t\tbackground-color: #f0f3f7;\n\t}\n"], ["\n\tborder: 0;\n\tbackground: none;\n\tdisplay: block;\n\tmargin-top: 5px;\n\tmargin-bottom: 5px;\n\ttext-align: left;\n\tmin-width: 182px;\n\tpadding-left: 10px;\n\tpadding-right: 10px;\n\tpadding-top: 3px;\n\tpadding-bottom: 3px;\n\tcursor: pointer;\n\n\t&:hover {\n\t\tbackground-color: #f0f3f7;\n\t}\n"])));
var BadgeSelect = (function (_super) {
    __extends(BadgeSelect, _super);
    function BadgeSelect(props) {
        var _this = _super.call(this, props) || this;
        _this.state = {
            selected: has(props, 'default') ? props.defaultSelected : null,
        };
        return _this;
    }
    BadgeSelect.prototype.setSelected = function (selected) {
        this.setState({ selected: selected });
        if (this.props.onItemChange) {
            this.props.onItemChange(selected);
        }
    };
    BadgeSelect.prototype.render = function () {
        var _this = this;
        var _a = this.props, items = _a.items, extra = _a.extra, onItemChange = _a.onItemChange, defaultSelected = _a.defaultSelected, placeholder = _a.placeholder, props = __rest(_a, ["items", "extra", "onItemChange", "defaultSelected", "placeholder"]);
        return (React.createElement(DropDownButton_1.default, __assign({}, props, { noListFormat: true, joined: true, label: React.createElement(Txt_1.default, null,
                this.state.selected == null &&
                    !!this.props.placeholder &&
                    this.props.placeholder,
                this.state.selected == null &&
                    !this.props.placeholder &&
                    'Choose an option',
                this.state.selected != null &&
                    includes(this.props.items, this.state.selected) && (React.createElement(Badge_1.default, { text: this.state.selected })),
                this.state.selected != null &&
                    !includes(this.props.items, this.state.selected) &&
                    this.state.selected) }),
            !!this.props.extraPrefix &&
                this.props.extraPrefix.map(function (item) { return (React.createElement(ButtonWrapper, { key: item, onClick: function () { return _this.setSelected(item); } },
                    React.createElement(Txt_1.default, { fontSize: 2 }, item))); }),
            !!this.props.extraPrefix && (React.createElement(Divider_1.default, { height: 1, color: "#dadada", mx: 10 })),
            this.props.items.map(function (item) { return (React.createElement(ButtonWrapper, { key: item, onClick: function () { return _this.setSelected(item); } },
                React.createElement(Badge_1.default, { text: item }))); }),
            (!!this.props.extra || this.props.extraSuffix) && (React.createElement(Divider_1.default, { height: 1, color: "#dadada", mx: 10 })),
            !!this.props.extra &&
                this.props.extra.map(function (item) { return (React.createElement(ButtonWrapper, { key: item, onClick: function () { return _this.setSelected(item); } },
                    React.createElement(Txt_1.default, { fontSize: 2 }, item))); }),
            !!this.props.extraSuffix &&
                this.props.extraSuffix.map(function (item) { return (React.createElement(ButtonWrapper, { key: item, onClick: function () { return _this.setSelected(item); } },
                    React.createElement(Txt_1.default, { fontSize: 2 }, item))); })));
    };
    return BadgeSelect;
}(React.Component));
exports.default = BadgeSelect;
var templateObject_1;
