"use strict";
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
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 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Select = exports.SelectPure = void 0;
var react_1 = __importStar(require("react"));
var faAngleDown_1 = require("@fortawesome/free-solid-svg-icons/faAngleDown");
var react_fontawesome_1 = require("@fortawesome/react-fontawesome");
var LoaderIcon_1 = require("../LoaderIcon");
var styles_1 = require("../styles");
var S = __importStar(require("./Select.style"));
var SelectCore_1 = require("./SelectCore");
exports.SelectPure = react_1.default.forwardRef(function SelectPure(_a, inputRef) {
    var value = _a.value, onChange = _a.onChange, options = _a.options, title = _a.title, _b = _a.defaultValue, defaultValue = _b === void 0 ? null : _b, error = _a.error, color = _a.color, _c = _a.loading, loading = _c === void 0 ? false : _c, children = _a.children, as = _a.as, rest = __rest(_a, ["value", "onChange", "options", "title", "defaultValue", "error", "color", "loading", "children", "as"]);
    var ref = react_1.useRef();
    react_1.useImperativeHandle(inputRef, function () { return ref.current; }, []);
    var _d = react_1.useState(false), focus = _d[0], setFocus = _d[1];
    return (react_1.default.createElement(styles_1.FormStyle, { className: "select-input-container" },
        react_1.default.createElement(S.Container, { color: color },
            title && react_1.default.createElement("div", { className: "input-title " + (focus && 'focus') }, title),
            react_1.default.createElement("label", { className: "select-box" },
                react_1.default.createElement("select", __assign({}, rest, { defaultValue: defaultValue ? SelectCore_1.convertToJSON(defaultValue) : undefined, ref: ref, value: value ? SelectCore_1.convertToJSON(value) : undefined, onChange: function (event) {
                        if (onChange) {
                            onChange(SelectCore_1.convertToString(event.target.value));
                        }
                    }, className: error && 'has-error', onFocus: function (ev) {
                        if (rest.onFocus)
                            rest.onFocus(ev);
                        setFocus(true);
                    }, onBlur: function (ev) {
                        if (rest.onBlur)
                            rest.onBlur(ev);
                        setFocus(false);
                    } }),
                    !options && children,
                    options &&
                        options.map(function (i, index) {
                            return (react_1.default.createElement("option", { value: SelectCore_1.convertToJSON(i.value), key: SelectCore_1.convertToJSON(i.value), disabled: i.disabled, selected: index == 0 }, i.name));
                        })),
                loading && (react_1.default.createElement("div", { className: "suffix-loading" },
                    react_1.default.createElement(LoaderIcon_1.LoaderIcon, { size: 18 }))),
                react_1.default.createElement("div", { className: "select-icon" },
                    react_1.default.createElement(react_fontawesome_1.FontAwesomeIcon, { icon: faAngleDown_1.faAngleDown }))),
            error && (react_1.default.createElement("div", { className: "error-input", "data-testid": "input-error" }, error)))));
});
exports.Select = react_1.default.forwardRef(function Checkbox(props, inputRef) {
    var ref = react_1.useRef();
    react_1.useImperativeHandle(inputRef, function () { return ref.current; }, []);
    return react_1.default.createElement(SelectCore_1.SelectCore, __assign({}, props, { ref: ref, as: exports.SelectPure }));
});
//# sourceMappingURL=Select.js.map