import { useContext, useMemo } from 'react';
import { classNames } from '../../utils/classNames';
import { ChipContext } from '../ChipProvider';
import { chipClassnames } from '../constants';
export const useLogic = ({ className, isDisabled, isSelected, onChange, size = 'medium', label, status, icon, counter, endAdornment, maxCount, name: nameProp, value: valueProp, }) => {
    const { mode, name: contextName } = useContext(ChipContext);
    const isMultiple = mode === 'multiple';
    const inputName = nameProp ?? contextName;
    const classnames = useMemo(() => classNames(className, chipClassnames.root, {
        [chipClassnames.disabled]: isDisabled,
        [chipClassnames.selected]: isSelected,
        [chipClassnames.sizeSmall]: size === 'small',
        [chipClassnames.sizeMedium]: size === 'medium',
        [chipClassnames.sizeLarge]: size === 'large',
        [chipClassnames.hasStatusIcon]: Boolean(status),
        [chipClassnames.hasCounter]: Boolean(counter),
        [chipClassnames.hasEndAdornment]: Boolean(endAdornment) && !counter,
        [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,
    };
};
