"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useTab = useTab;
const helpers_1 = require("../../../utils/helpers");
const Tabs_context_1 = require("../../Tabs.context");
function useTab({ id, value, disabled = false, onFocus: _onFocus, onClick, ariaControls, }) {
    const { id: contextId, setSelectedValue, selectionFollowsFocus, focusedValue, setFocusedValue, selectedValue, makeTabId, makeTabPanelId, } = (0, Tabs_context_1.useTabsContext)();
    const isSelected = value === selectedValue;
    const onFocus = () => {
        setFocusedValue(value);
        selectionFollowsFocus && setSelectedValue(value);
    };
    return {
        onClick: (0, helpers_1.composeEventHandlers)(onClick, () => setSelectedValue(value)),
        onFocus: disabled ? undefined : (0, helpers_1.composeEventHandlers)(_onFocus, onFocus),
        id: id !== null && id !== void 0 ? id : makeTabId(contextId, value),
        "aria-controls": ariaControls !== null && ariaControls !== void 0 ? ariaControls : makeTabPanelId(contextId, value),
        tabIndex: focusedValue === value ? 0 : -1,
        "aria-selected": isSelected,
        "data-state": isSelected ? "active" : "inactive",
        role: "tab",
        "data-aksel-tab": "",
        disabled,
        "data-disabled": disabled ? "" : undefined,
    };
}
//# sourceMappingURL=useTab.js.map