"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useToggleGroup = useToggleGroup;
const react_1 = require("react");
const hooks_1 = require("../utils/hooks");
function useToggleGroup({ onChange, value, defaultValue = "", }) {
    const [focusedValue, setFocusedValue] = (0, react_1.useState)(defaultValue);
    const [selectedValue, setSelectedValue] = (0, hooks_1.useControllableState)({
        defaultValue,
        value,
        onChange,
    });
    /* Sync focused `value` with controlled `selectedValue` */
    (0, react_1.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