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;
};
import React from 'react';
import classnames from 'classnames';
import { defaultTo, identity, pipe, prop, remove } from 'ramda';
import TextField from '@mui/material/TextField';
import { getValue } from '../helpers/events';
import { ValueChip } from '../ValueChip';
import { useStyles } from './styles';
var defaultGetValueLabel = function () { return ''; };
export var MultipliableSelect = function (_a) {
    var _b;
    var multiple = _a.multiple, value = _a.value, children = _a.children, _c = _a.getValueLabel, getValueLabel = _c === void 0 ? defaultGetValueLabel : _c, _d = _a.getValuePlaceholder, getValuePlaceholder = _d === void 0 ? identity : _d, _e = _a.onChange, onChange = _e === void 0 ? identity : _e, fullWidth = _a.fullWidth, TextFieldProps = _a.TextFieldProps, MenuProps = _a.MenuProps, classes = _a.classes, isCrossedOut = _a.isCrossedOut, otherProps = __rest(_a, ["multiple", "value", "children", "getValueLabel", "getValuePlaceholder", "onChange", "fullWidth", "TextFieldProps", "MenuProps", "classes", "isCrossedOut"]);
    var styles = useStyles();
    return (React.createElement(TextField, __assign({ variant: "standard", select: true, fullWidth: fullWidth }, TextFieldProps, { value: defaultTo(multiple ? [] : '', value), onChange: pipe(getValue, onChange), SelectProps: __assign(__assign({}, otherProps), { MenuProps: __assign({ anchorOrigin: { vertical: 'bottom', horizontal: 'center' } }, MenuProps), classes: __assign(__assign({}, classes), { select: classnames((_b = {}, _b[styles.multiSelect] = multiple, _b[styles.isCrossedOut] = isCrossedOut, _b), prop('root', classes), prop('select', classes)) }), multiple: multiple, renderValue: function (selected) {
                return multiple ? (React.createElement("div", { className: styles.chips }, selected.map(function (value, index) { return (React.createElement(ValueChip, { key: value, label: getValueLabel(value) || getValuePlaceholder(value), onMouseDown: function (event) { return event.stopPropagation(); }, onDelete: function () { return onChange(remove(index, 1, selected)); } })); }))) : (getValueLabel(selected) || getValuePlaceholder(selected));
            } }) }), children));
};
