import { useState } from 'react';
const useLinkedMode = ({ initial = true, onChangeCallbacks, onInvalidCallbacks, onBlurCallbacks, }) => {
    const [isLinkingEnabled, setLinking] = useState(initial);
    const [isDirty, setIsDirty] = useState(false);
    const linkedOnChange = (...args) => {
        onChangeCallbacks.forEach(onChange => onChange?.(...args));
        setIsDirty(true);
    };
    const linkedOnInvalid = (...args) => {
        onInvalidCallbacks.forEach(onInvalid => onInvalid?.(...args));
        setIsDirty(true);
    };
    const linkedOnBlur = () => {
        isDirty && onBlurCallbacks.forEach(onBlur => onBlur());
        setIsDirty(false);
    };
    return [
        {
            linkedOnChange,
            linkedOnInvalid,
            linkedOnBlur,
            isLinkingEnabled,
        },
        setLinking,
    ];
};
export { useLinkedMode };
//# sourceMappingURL=useLinkedMode.js.map