/* @oracle/oraclejet-preact: undefined */
import { jsx } from 'preact/jsx-runtime';
import { B as BaseTabBarItem } from './TabBarItem-b97091e4.js';
import { useRef, useState, useLayoutEffect, useCallback } from 'preact/hooks';
import { u as useResizeObserver } from './useResizeObserver-838164c1.js';
import { g as getTabWidths } from './tabBarUtils-ee027465.js';

/**
 * TabBarLinkItem is used to render links in a TabBar. It allows to view the browser's built in link context menu to open the link in new browser tab.
 */
function TabBarLinkItem({ itemKey, icon, badge, metadata, severity, labelMaxWidth, href, label, 'aria-controls': ariaControls }) {
    return (jsx(BaseTabBarItem, { "aria-controls": ariaControls, itemKey: itemKey, label: label, icon: icon, badge: badge, metadata: metadata, severity: severity, labelMaxWidth: labelMaxWidth, href: href }));
}

const useProgressiveTruncation = ({ rootRef, isDisabled = false }) => {
    const trailingContentWidths = useRef(new Map());
    const [tabMaxWidth, setTabMaxWidth] = useState();
    const [tabBarWidth, setTabBarWidth] = useState(0);
    useLayoutEffect(() => {
        if (tabMaxWidth == undefined && rootRef && rootRef.current && !isDisabled) {
            const isOverflow = tabBarWidth < rootRef.current.scrollWidth;
            if (!isOverflow) {
                return;
            }
            const tabWidths = getTabWidths(rootRef.current, trailingContentWidths, isDisabled, tabBarWidth, false);
            const tabMaxWidthMap = new Map(tabWidths.map((tab) => [tab.key, (tab.maxWidth + 'px')]));
            setTabMaxWidth(tabMaxWidthMap);
        }
    }, [tabBarWidth, tabMaxWidth, isDisabled, rootRef]);
    const getTabBarMaxWidth = useCallback((entry) => {
        if (tabBarWidth !== entry.contentRect.width) {
            setTabBarWidth(entry.contentRect.width);
            if (tabMaxWidth !== undefined) {
                setTabMaxWidth(undefined);
            }
        }
    }, [tabMaxWidth, tabBarWidth]);
    useResizeObserver(rootRef, getTabBarMaxWidth, { isDisabled: isDisabled });
    return {
        maxWidths: tabMaxWidth
    };
};

export { TabBarLinkItem as T, useProgressiveTruncation as u };
//# sourceMappingURL=useProgressiveTruncation-05189846.js.map
