import { useState } from 'react';
import { useId } from '../../useId';
export const useLogic = ({ children, groupLabel, errorText, isError, required, formControlProps, row = false, name, value, onChange, className, disabled, style, inputRef, }) => {
    const labelId = useId();
    const [internalValue, setInternalValue] = useState(undefined);
    const handleChange = (event, newValue) => {
        setInternalValue(newValue);
        onChange?.(event, newValue);
    };
    const currentValue = value !== undefined ? value : internalValue;
    const contextValue = {
        isError,
        name,
        value: currentValue,
        onChange: handleChange,
        disabled,
    };
    return {
        errorText,
        formControlProps,
        groupLabel,
        labelId,
        isError,
        required,
        contextValue,
        className,
        row,
        children,
        disabled,
        style,
        inputRef,
    };
};
