import { useEffect, useState } from "react";
import { useControllableState } from "../utils/hooks/index.js";
export function useToggleGroup({ onChange, value, defaultValue = "", }) {
    const [focusedValue, setFocusedValue] = useState(defaultValue);
    const [selectedValue, setSelectedValue] = useControllableState({
        defaultValue,
        value,
        onChange,
    });
    /* Sync focused `value` with controlled `selectedValue` */
    useEffect(() => {
        if (value != null) {
            setFocusedValue(value); // eslint-disable-line react-hooks/set-state-in-effect
        }
    }, [value]);
    return {
        selectedValue,
        setSelectedValue,
        focusedValue,
        setFocusedValue,
    };
}
//# sourceMappingURL=useToggleGroup.js.map