import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import AllCriteriaCard from '../../../audience/AllCriteriaCard';
import IndividualCriteriaCard from '../../../audience/IndividualCriteriaCard';
import SegmentationCriteriaCard from '../../../audience/SegmentationCriteriaCard';
import useAudienceDrawers from '../hooks/useAudienceDrawers';
import { CriteriaType, } from '../types';
const ALL_TYPES = [
    CriteriaType.ALL,
    CriteriaType.SEGMENTATION,
    CriteriaType.INDIVIDUAL,
];
const CriteriaSelector = ({ segmentationDrawerProps, individualDrawerProps, availableCriteriaTypes, showCriteriaInfo = true, }) => {
    const allowed = availableCriteriaTypes && availableCriteriaTypes.length > 0
        ? availableCriteriaTypes
        : ALL_TYPES;
    const { criterias, setValue, segmentationInputProps, segmentationCriteriaDrawer, showSegmentationCriteriaDrawer, individualCriteriaDrawer, showIndividualCriteriaDrawer, } = useAudienceDrawers({
        segmentationDrawerProps,
        individualDrawerProps,
    });
    const addCriteria = (entry) => {
        setValue('criterias', [...criterias, entry], { shouldDirty: true });
    };
    const handleSegmentationClick = () => {
        showSegmentationCriteriaDrawer({
            showInfo: showCriteriaInfo,
            onConfirm: values => {
                addCriteria({
                    type: CriteriaType.SEGMENTATION,
                    conditions: values.conditions,
                });
            },
            inputProps: segmentationInputProps,
        });
    };
    const handleIndividualClick = () => {
        showIndividualCriteriaDrawer({
            onConfirm: values => {
                addCriteria({
                    type: CriteriaType.INDIVIDUAL,
                    userIds: values.userIds ?? new Set(),
                });
            },
        });
    };
    const handleAllClick = () => {
        addCriteria({ type: CriteriaType.ALL });
    };
    return (_jsxs(_Fragment, { children: [allowed.map(type => {
                switch (type) {
                    case CriteriaType.SEGMENTATION:
                        return (_jsx(SegmentationCriteriaCard, { onClick: handleSegmentationClick, showInfo: showCriteriaInfo }, type));
                    case CriteriaType.INDIVIDUAL:
                        return (_jsx(IndividualCriteriaCard, { onClick: handleIndividualClick }, type));
                    case CriteriaType.ALL:
                        return (_jsx(AllCriteriaCard, { onClick: handleAllClick, showInfo: showCriteriaInfo }, type));
                    default:
                        return null;
                }
            }), segmentationCriteriaDrawer, individualCriteriaDrawer] }));
};
export default CriteriaSelector;
