"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 __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.FormikSelect = void 0;
var React = require("react");
var Select_1 = require("@material-ui/core/Select");
var MenuItem_1 = require("@material-ui/core/MenuItem");
var FormControl_1 = require("@material-ui/core/FormControl");
var InputLabel_1 = require("@material-ui/core/InputLabel");
var FormHelperTextWrapper_1 = require("./FormHelperTextWrapper");
var FormikField_1 = require("./FormikField");
var utils_1 = require("./utils");
var defaultProps = {
    style: { minWidth: "240px" }
};
var defaultRemoveSelectionText = "";
function FormikSelect(props) {
    var label = props.label, name = props.name, error = props.error, helperText = props.helperText, useField = props.useField, options = props.options, formControlProps = props.formControlProps, formHelperTextProps = props.formHelperTextProps, hideRemoveSelection = props.hideRemoveSelection, removeSelectionText = props.removeSelectionText, fieldProps = props.fieldProps, validate = props.validate, others = __rest(props, ["label", "name", "error", "helperText", "useField", "options", "formControlProps", "formHelperTextProps", "hideRemoveSelection", "removeSelectionText", "fieldProps", "validate"]);
    var removeSelection = removeSelectionText || defaultRemoveSelectionText;
    return (React.createElement(FormikField_1.FormikField, __assign({ name: name, useField: useField, validate: validate }, fieldProps), function (_a) {
        var field = _a.field, form = _a.form;
        return (React.createElement(FormControl_1.default, __assign({ margin: "normal" }, formControlProps),
            label && React.createElement(InputLabel_1.default, null, label),
            React.createElement(Select_1.default, __assign({}, defaultProps, field, { value: field.value != null ? field.value : "", error: (0, utils_1.hasError)(name, form, error) }, others),
                hideRemoveSelection !== true && (React.createElement(MenuItem_1.default, { style: { minHeight: "30px" }, value: "" },
                    React.createElement("em", null, removeSelection))),
                options &&
                    options.map &&
                    options.map(function (d, idx) { return (React.createElement(MenuItem_1.default, { key: idx, value: d.key }, d.value)); })),
            React.createElement(FormHelperTextWrapper_1.default, { name: name, form: form, error: error, formHelperTextProps: formHelperTextProps, helperText: helperText })));
    }));
}
exports.FormikSelect = FormikSelect;
