"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ColumnSelector = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const Select_1 = require("../../../components/Select");
const AdaptableContext_1 = require("../../AdaptableContext");
const ColumnSelector = function (props) {
    const { api } = (0, AdaptableContext_1.useAdaptable)();
    const columns = React.useMemo(() => {
        return api.columnApi.getColumnsWithDataType(props.type);
    }, []);
    const getColumn = (columnId) => columns.find((c) => c.columnId === columnId);
    const options = columns
        .map((column) => {
        let label = React.createElement(React.Fragment, null, column.friendlyName ?? column.columnId);
        if (props.renderOption) {
            label = props.renderOption(column);
        }
        return {
            label,
            value: column.columnId,
        };
    })
        .filter((option) => {
        if (props.filterColumn) {
            return props.filterColumn(getColumn(option.value));
        }
        return true;
    });
    return (React.createElement(Select_1.Select, { "data-name": "column-selector", searchable: 'inline', disabled: props.disabled, isMulti: props.isMulti, menuPosition: props.menuPosition, value: props.value, placeholder: props.placeholder ?? 'Select Column', onChange: (colId) => {
            props.onChange(colId);
        }, options: options }));
};
exports.ColumnSelector = ColumnSelector;
