"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const useUpdateEffect_1 = require("../../useUpdateEffect");
const classNames_1 = require("../../utils/classNames");
const constants_1 = require("../constants");
const useLogic = ({ checked = false, disabled = false, isError = false, onChange: propsOnChange, className: propClassNames, name, style, inputRef, value, id, ...restProps }) => {
    const [isChecked, setIsChecked] = (0, react_1.useState)(checked);
    (0, useUpdateEffect_1.useUpdateEffect)(() => {
        setIsChecked(checked);
    }, [checked]);
    const onChange = (event) => {
        propsOnChange?.(event, event.target.checked);
        setIsChecked(event.target.checked);
    };
    const className = (0, react_1.useMemo)(() => (0, classNames_1.classNames)(constants_1.radioClassnames.root, isChecked ? constants_1.radioClassnames.checked : '', disabled ? constants_1.radioClassnames.disabled : '', propClassNames), [isChecked, disabled, propClassNames]);
    return {
        onChange,
        isChecked,
        isError,
        disabled,
        className,
        restProps,
        name,
        style,
        inputRef,
        value,
        id,
    };
};
exports.useLogic = useLogic;
