"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 free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
var react_fontawesome_1 = require("@fortawesome/react-fontawesome");
var styles_1 = require("../styles");
var SelectCore_1 = require("./SelectCore");
var S = __importStar(require("./Select.style"));
exports.SelectPure = react_1.default.forwardRef(function SelectPure(_a, inputRef) {
    var _b;
    var value = _a.value, onChange = _a.onChange, options = _a.options, title = _a.title, defaultValue = _a.defaultValue, error = _a.error, color = _a.color, rightSelect = _a.rightSelect, children = _a.children, as = _a.as, rest = __rest(_a, ["value", "onChange", "options", "title", "defaultValue", "error", "color", "rightSelect", "children", "as"]);
    var ref = react_1.useRef();
    react_1.useImperativeHandle(inputRef, function () { return ref.current; }, []);
    var _c = react_1.useState(false), focus = _c[0], setFocus = _c[1];
    return (react_1.default.createElement(styles_1.FormStyle, null,
        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 ? JSON.stringify(defaultValue) : undefined, ref: ref, value: value ? JSON.stringify(value) : undefined, onChange: function (event) {
                        if (onChange) {
                            onChange(JSON.parse(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) { return (react_1.default.createElement("option", { value: JSON.stringify(i.value), key: JSON.stringify(i.value), disabled: i.disabled }, i.name)); })),
                react_1.default.createElement("div", { className: "select-icon" },
                    react_1.default.createElement(react_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faAngleDown }))),
            error && (react_1.default.createElement("div", { "data-cy": "input-error." + ((_b = rest['data-cy']) !== null && _b !== void 0 ? _b : ''), 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