"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const classNames_1 = require("../../utils/classNames");
const ChipProvider_1 = require("../ChipProvider");
const constants_1 = require("../constants");
const useLogic = ({ className, isDisabled, isSelected, onChange, size = 'medium', label, status, icon, counter, endAdornment, maxCount, name: nameProp, value: valueProp, }) => {
    const { mode, name: contextName } = (0, react_1.useContext)(ChipProvider_1.ChipContext);
    const isMultiple = mode === 'multiple';
    const inputName = nameProp ?? contextName;
    const classnames = (0, react_1.useMemo)(() => (0, classNames_1.classNames)(className, constants_1.chipClassnames.root, {
        [constants_1.chipClassnames.disabled]: isDisabled,
        [constants_1.chipClassnames.selected]: isSelected,
        [constants_1.chipClassnames.sizeSmall]: size === 'small',
        [constants_1.chipClassnames.sizeMedium]: size === 'medium',
        [constants_1.chipClassnames.sizeLarge]: size === 'large',
        [constants_1.chipClassnames.hasStatusIcon]: Boolean(status),
        [constants_1.chipClassnames.hasCounter]: Boolean(counter),
        [constants_1.chipClassnames.hasEndAdornment]: Boolean(endAdornment) && !counter,
        [constants_1.chipClassnames.hasIcon]: Boolean(icon) && !status,
    }), [isSelected, isDisabled, size, status, counter, endAdornment, icon]);
    const hasStartAdornment = Boolean(status || icon);
    const hasEndAdornment = Boolean(endAdornment || counter);
    const inputType = isMultiple ? 'checkbox' : 'radio';
    return {
        classnames,
        inputProps: {
            checked: isSelected,
            onChange,
            type: inputType,
            disabled: isDisabled,
            ...(inputName !== undefined ? { name: inputName } : {}),
            ...(valueProp !== undefined ? { value: valueProp } : {}),
        },
        label,
        status,
        icon,
        counter,
        endAdornment,
        hasStartAdornment,
        hasEndAdornment,
        maxCount,
    };
};
exports.useLogic = useLogic;
