import Dropdown from "../Dropdown/Dropdown";
import FieldType from "../Types/FieldType";
import React from "react";
const DropdownFilter = (props) => {
    var _a;
    const filter = props.filter;
    const filterData = Object.assign({}, props.filterData);
    const dropdownValues = ((_a = props.filter.filterDropdownOptions) === null || _a === void 0 ? void 0 : _a.filter((option) => {
        var _a;
        if (filterData[filter.key] instanceof Array) {
            return filterData[filter.key]
                .map((value) => {
                return value.toString();
            })
                .includes(option.value.toString());
        }
        return option.value.toString() === ((_a = filterData[filter.key]) === null || _a === void 0 ? void 0 : _a.toString());
    })) || [];
    if (filter.type !== FieldType.Entity &&
        filter.type !== FieldType.EntityArray &&
        filter.filterDropdownOptions) {
        return (React.createElement(Dropdown, { options: filter.filterDropdownOptions, onChange: (value) => {
                if (!filter.key) {
                    return;
                }
                if (!value || (Array.isArray(value) && value.length === 0)) {
                    delete filterData[filter.key];
                }
                else {
                    filterData[filter.key] = value;
                }
                if (props.onFilterChanged) {
                    props.onFilterChanged(filterData);
                }
            }, value: dropdownValues, isMultiSelect: props.isMultiSelect || false, placeholder: `Filter by ${filter.title}`, className: "relative rounded-md w-full overflow-visible" }));
    }
    return React.createElement(React.Fragment, null);
};
export default DropdownFilter;
//# sourceMappingURL=DropdownFilter.js.map