"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PermitedValuesSelector = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const rebass_1 = require("rebass");
const OverlayTrigger_1 = tslib_1.__importDefault(require("../../../components/OverlayTrigger"));
const SimpleButton_1 = tslib_1.__importDefault(require("../../../components/SimpleButton"));
const AdaptableContext_1 = require("../../AdaptableContext");
const ListBoxFilterForm_1 = require("../FilterForm/ListBoxFilterForm");
const PermitedValuesSelector = (props) => {
    var _a, _b, _c;
    const adaptable = (0, AdaptableContext_1.useAdaptable)();
    const columnId = props.columnId;
    const column = adaptable.api.columnApi.getColumnWithColumnId(columnId);
    const distinctValues = ((_a = adaptable.api.gridApi.internalApi.getDistinctDisplayValuesForColumn(columnId)) !== null && _a !== void 0 ? _a : []).map((value) => { var _a; return ({ value: value, label: (value === null || value === void 0 ? void 0 : value.toString) ? (_a = value.toString) === null || _a === void 0 ? void 0 : _a.call(value) : value }); });
    const predicateInputs = (_b = props.predicate.Inputs) !== null && _b !== void 0 ? _b : [];
    const isClearDisabled = ((_c = predicateInputs === null || predicateInputs === void 0 ? void 0 : predicateInputs.filter) === null || _c === void 0 ? void 0 : _c.call(predicateInputs, (item) => item !== undefined || item !== null || item !== '').length) === 0;
    const popupContent = (React.createElement(rebass_1.Flex, { className: "ab-PermitedValuesSelector__PopupContent", padding: 1, flexDirection: "column" },
        React.createElement(ListBoxFilterForm_1.ListBoxFilterForm, { currentColumn: column, columns: [], columnDistinctValues: distinctValues, dataType: column.dataType, uiSelectedColumnValues: props.predicate.Inputs, useAgGridStyle: true, onColumnValueSelectedChange: (list) => props.onPredicateValuesChange(list) })));
    return (React.createElement(rebass_1.Box, { className: "ab-PermitedValuesSelector", mt: 2 },
        React.createElement(rebass_1.Box, { flex: 1 },
            React.createElement(OverlayTrigger_1.default, { render: () => popupContent },
                React.createElement(SimpleButton_1.default, { width: "100%", mb: 2 }, (predicateInputs === null || predicateInputs === void 0 ? void 0 : predicateInputs.join(', ')) || 'No Selected values'))),
        React.createElement(SimpleButton_1.default, { disabled: isClearDisabled, onClick: () => props.onPredicateValuesChange([]) }, "Clear Values")));
};
exports.PermitedValuesSelector = PermitedValuesSelector;
