"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useTabs = useTabs;
const react_1 = require("react");
const utils_external_1 = require("../utils-external");
const hooks_1 = require("../utils/hooks");
function useTabs({ onChange, value, defaultValue = "", id, }) {
    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]);
    /* Scope ids for better tracking */
    const uuid = (0, utils_external_1.useId)();
    return {
        id: `tabs-${id !== null && id !== void 0 ? id : uuid}`,
        selectedValue,
        setSelectedValue,
        focusedValue,
        setFocusedValue,
        makeTabId,
        makeTabPanelId,
    };
}
function makeTabId(id, value) {
    return `${id}--tab-${value}`;
}
function makeTabPanelId(id, value) {
    return `${id}--tabpanel-${value}`;
}
//# sourceMappingURL=useTabs.js.map