import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Checkbox } from '../../components/Checkbox';
import { Chip, ChipProvider } from '../../components/Chip';
import { ListItemIcon } from '../../components/ListItemIcon';
import { MenuItem } from '../../components/MenuItem';
import { FormSelect } from '../FormSelect';
import { FORM_FILTERS_QUICK_FILTERS_ID, FORM_QUICK_FILTERS_ALL_CHIP_KEY, FORM_QUICK_FILTERS_ALL_VALUE, } from './constants';
import { MobileWrapper, Wrapper } from './styles';
import { useLogic } from './useLogic/useLogic';
/**
 * Группа чипов для быстрых фильтров внутри FormFilters (слот quickFilters).
 *
 *   Поведение чипов задаётся параметром `multiple` через `ChipProvider mode`:
 *   - false (default) — `single` (radio)
 *   - true — `multiple` (checkbox)
 *
 * - На мобильных устройствах отображается как Select
 *
 * @example
 * <FormFilters
 *   quickFilters={({ control }) => (
 *     <FormQuickFilters
 *       control={control}
 *       name="status"
 *       label="Статус"
 *       options={[
 *         { label: 'Активные', value: 'active' },
 *         { label: 'Архив', value: 'archived' },
 *       ]}
 *     />
 *   )}
 * />
 */
export const FormQuickFilters = (props) => {
    const { field, filterOptions, checkIsAllSelected, handleChipChange, isSelected, label, allLabel, allCounter, multiple, maxCount, name, placeholder, control, getOptionLabel, getCounterLabel, } = useLogic(props);
    const renderMultipleOptions = () => {
        return filterOptions.map((option) => {
            const checked = control._formValues[name]?.includes(option.value);
            return (_jsxs(MenuItem, { value: option.value, children: [_jsx(ListItemIcon, { children: _jsx(Checkbox, { checked: checked }) }), option.label, getCounterLabel(option)] }, option.value));
        });
    };
    const renderSingleOptions = () => {
        return filterOptions.map((option) => (_jsxs(MenuItem, { value: option.value, children: [option.label, getCounterLabel(option)] }, option.value)));
    };
    return (_jsxs(_Fragment, { children: [_jsx(Wrapper, { children: _jsxs(ChipProvider, { mode: multiple ? 'multiple' : 'single', name: name, children: [_jsx(Chip, { label: allLabel, isSelected: checkIsAllSelected(), onChange: () => handleChipChange(FORM_QUICK_FILTERS_ALL_VALUE), counter: allCounter, size: "medium", maxCount: maxCount, value: FORM_QUICK_FILTERS_ALL_VALUE }, FORM_QUICK_FILTERS_ALL_CHIP_KEY), filterOptions.map((option) => (_jsx(Chip, { label: option.label, isSelected: isSelected(option.value), onChange: () => handleChipChange(option.value), status: option.status, counter: option.counter, size: "medium", maxCount: maxCount, value: String(option.value) }, option.value)))] }) }), _jsx(MobileWrapper, { children: _jsx(FormSelect, { control: control, name: name, inputProps: { id: FORM_FILTERS_QUICK_FILTERS_ID }, label: label, getOptionLabel: getOptionLabel, multiple: multiple, onChange: field.onChange, onBlur: field.onBlur, fullWidth: true, placeholder: placeholder, children: multiple ? renderMultipleOptions() : renderSingleOptions() }) })] }));
};
