"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ColumnFilterWindow = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const FormLayout_1 = tslib_1.__importStar(require("../../../components/FormLayout"));
const ColumnSelector_1 = require("../Selectors/ColumnSelector");
const AdaptableColumnFilter_1 = require("./AdaptableColumnFilter");
const AdaptableContext_1 = require("../../AdaptableContext");
const AdaptableIconComponent_1 = require("../AdaptableIconComponent");
const Flex_1 = require("../../../components/Flex");
const ColumnFilterWindow = (props) => {
    const { api } = (0, AdaptableContext_1.useAdaptable)();
    const { value: initialColumnId } = props?.popupProps;
    const [columnId, setColumnId] = React.useState(initialColumnId);
    React.useEffect(() => {
        setColumnId(initialColumnId);
    }, [props.popupProps.value]);
    // const onChange = props.popupProps.onChange;
    return (React.createElement(Flex_1.Flex, { flexDirection: "column", className: "ab-ColumnFilterWindow twa:flex-1 twa:min-h-0 twa:p-2 twa:h-full" },
        React.createElement(Flex_1.Box, { className: "twa:mb-2" },
            React.createElement(FormLayout_1.default, null,
                React.createElement(FormLayout_1.FormRow, { label: "Column" },
                    React.createElement(ColumnSelector_1.ColumnSelector, { renderOption: (column) => {
                            const columnFilter = api.filterApi.columnFilterApi.getColumnFilterForColumn(column.columnId);
                            const label = column.friendlyName ?? column.columnId;
                            if (columnFilter &&
                                api.filterApi.columnFilterApi.isColumnFilterActive(columnFilter)) {
                                return (React.createElement(Flex_1.Flex, null,
                                    label,
                                    React.createElement(Flex_1.Box, { className: "twa:flex-1" }),
                                    React.createElement(AdaptableIconComponent_1.AdaptableIconComponent, { icon: { name: 'filter' } })));
                            }
                            return label;
                        }, onChange: (column) => setColumnId(column), filterColumn: (column) => column.queryable, isMulti: false, value: columnId })))),
        React.createElement(AdaptableColumnFilter_1.AdaptableColumnFilter, { columnId: columnId, location: 'filterForm' })));
};
exports.ColumnFilterWindow = ColumnFilterWindow;
