import { jsx as _jsx } from "react/jsx-runtime";
import { useTranslation } from 'react-i18next';
import useCriteriaDrawer from '../../../audience/hooks/useCriteriaDrawer';
import FormConditionGroup from '../../../ConditionGroup/form';
import { merge } from 'lodash';
import { isSegmentationCriteriaEmpty } from './utils';
const useSegmentationCriteriaDrawer = ({ defaultValues, collaboratorsReach, validate, }) => {
    const { t } = useTranslation('material_hu_only');
    const { criteriaDrawer, showCriteriaDrawer, closeCriteriaDrawer, criteriaForm, } = useCriteriaDrawer({
        defaultValues,
        collaboratorsReach: collaboratorsReach
            ? {
                ...collaboratorsReach,
                isFormEmpty: isSegmentationCriteriaEmpty,
            }
            : undefined,
        validate: values => {
            const callerValid = validate ? validate(values) : true;
            return !isSegmentationCriteriaEmpty(values) && callerValid;
        },
    });
    const showSegmentationCriteriaDrawer = (props) => {
        const { showInfo = true, ...restProps } = props;
        showCriteriaDrawer({
            ...restProps,
            title: t('audience.segmentation_groups_title'),
            description: t(showInfo
                ? 'audience.segmentation_criteria_description'
                : 'audience.segmentation_groups_description'),
            children: (_jsx(FormConditionGroup, { name: "conditions", inputProps: merge({
                    disabled: restProps.disabled,
                }, restProps.inputProps) })),
        });
    };
    return {
        showSegmentationCriteriaDrawer,
        closeSegmentationCriteriaDrawer: closeCriteriaDrawer,
        segmentationCriteriaDrawer: criteriaDrawer,
        segmentationCriteriaForm: criteriaForm,
    };
};
export default useSegmentationCriteriaDrawer;
