"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const useId_1 = require("../../useId");
const useLogic = ({ children, groupLabel, errorText, isError, required, formControlProps, row = false, name, value, onChange, className, disabled, style, inputRef, }) => {
    const labelId = (0, useId_1.useId)();
    const [internalValue, setInternalValue] = (0, react_1.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,
    };
};
exports.useLogic = useLogic;
