"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormQuickFilters = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const Checkbox_1 = require("../../components/Checkbox");
const Chip_1 = require("../../components/Chip");
const ListItemIcon_1 = require("../../components/ListItemIcon");
const MenuItem_1 = require("../../components/MenuItem");
const FormSelect_1 = require("../FormSelect");
const constants_1 = require("./constants");
const styles_1 = require("./styles");
const useLogic_1 = require("./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' },
 *       ]}
 *     />
 *   )}
 * />
 */
const FormQuickFilters = (props) => {
    const { field, filterOptions, checkIsAllSelected, handleChipChange, isSelected, label, allLabel, allCounter, multiple, maxCount, name, placeholder, control, getOptionLabel, getCounterLabel, } = (0, useLogic_1.useLogic)(props);
    const renderMultipleOptions = () => {
        return filterOptions.map((option) => {
            const checked = control._formValues[name]?.includes(option.value);
            return ((0, jsx_runtime_1.jsxs)(MenuItem_1.MenuItem, { value: option.value, children: [(0, jsx_runtime_1.jsx)(ListItemIcon_1.ListItemIcon, { children: (0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { checked: checked }) }), option.label, getCounterLabel(option)] }, option.value));
        });
    };
    const renderSingleOptions = () => {
        return filterOptions.map((option) => ((0, jsx_runtime_1.jsxs)(MenuItem_1.MenuItem, { value: option.value, children: [option.label, getCounterLabel(option)] }, option.value)));
    };
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(styles_1.Wrapper, { children: (0, jsx_runtime_1.jsxs)(Chip_1.ChipProvider, { mode: multiple ? 'multiple' : 'single', name: name, children: [(0, jsx_runtime_1.jsx)(Chip_1.Chip, { label: allLabel, isSelected: checkIsAllSelected(), onChange: () => handleChipChange(constants_1.FORM_QUICK_FILTERS_ALL_VALUE), counter: allCounter, size: "medium", maxCount: maxCount, value: constants_1.FORM_QUICK_FILTERS_ALL_VALUE }, constants_1.FORM_QUICK_FILTERS_ALL_CHIP_KEY), filterOptions.map((option) => ((0, jsx_runtime_1.jsx)(Chip_1.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)))] }) }), (0, jsx_runtime_1.jsx)(styles_1.MobileWrapper, { children: (0, jsx_runtime_1.jsx)(FormSelect_1.FormSelect, { control: control, name: name, inputProps: { id: constants_1.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() }) })] }));
};
exports.FormQuickFilters = FormQuickFilters;
