"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ColumnValueSelector = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const FieldWrap_1 = tslib_1.__importDefault(require("../../../components/FieldWrap"));
const UIHelper_1 = tslib_1.__importDefault(require("../../UIHelper"));
const AdaptableInput_1 = tslib_1.__importDefault(require("../AdaptableInput"));
const rebass_1 = require("rebass");
const PermittedValuesSelector_1 = require("./PermittedValuesSelector");
const Select_1 = require("../../../components/Select");
const ColumnValueSelector = (props) => {
    var _a, _b;
    const [valueType, setValueType] = React.useState('existing');
    const columnType = (_a = props.selectedColumn) === null || _a === void 0 ? void 0 : _a.dataType;
    const isDateType = props.selectedColumn && columnType === 'Date';
    const permittedValueSelector = (React.createElement(rebass_1.Box, null,
        React.createElement(PermittedValuesSelector_1.PermittedValuesSelector, { allowNewValues: true, disabled: props.disabled || !props.selectedColumn, value: props.selectedColumnValue === '' ? null : props.selectedColumnValue, columnId: (_b = props.selectedColumn) === null || _b === void 0 ? void 0 : _b.columnId, placeholder: isDateType ? 'Select' : 'Select or type new value', onChange: (value) => {
                if (!value) {
                    props.onColumnValueChange(null);
                }
                else {
                    props.onColumnValueChange(value);
                }
            } })));
    const input = (React.createElement(AdaptableInput_1.default, { "data-name": "bulkupdate-value-input", type: props.selectedColumn
            ? UIHelper_1.default.getDescriptionForDataType(props.selectedColumn.dataType)
            : 'text', placeholder: props.selectedColumn
            ? UIHelper_1.default.getPlaceHolderforDataType(props.selectedColumn.dataType)
            : 'Enter Value', autoFocus: true, disabled: props.disabled, style: { width: '100%' }, value: props.selectedColumnValue, onChange: (e) => {
            props.onColumnValueChange(e.target.value);
        } }));
    let valueTypeSelector = null;
    if (isDateType) {
        valueTypeSelector = (React.createElement(Select_1.Select, { options: [
                { label: 'New', value: 'new' },
                { label: 'Existing', value: 'existing' },
            ], value: valueType, onChange: (value) => {
                setValueType(value);
            } }));
    }
    return (React.createElement(FieldWrap_1.default, { className: props.className, style: Object.assign(Object.assign({}, props.style), { overflow: 'visible', maxWidth: '100%' }) }, isDateType ? (React.createElement(React.Fragment, null,
        valueType === 'new' ? input : permittedValueSelector,
        valueTypeSelector)) : (permittedValueSelector)));
};
exports.ColumnValueSelector = ColumnValueSelector;
