/* @oracle/oraclejet-preact: undefined */
'use strict';

var jsxRuntime = require('preact/jsx-runtime');
var TabBarItem = require('./TabBarItem-868455a3.js');
var hooks = require('preact/hooks');
var useResizeObserver = require('./useResizeObserver-1597395f.js');
var tabBarUtils = require('./tabBarUtils-f6828fc8.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 (jsxRuntime.jsx(TabBarItem.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 = hooks.useRef(new Map());
    const [tabMaxWidth, setTabMaxWidth] = hooks.useState();
    const [tabBarWidth, setTabBarWidth] = hooks.useState(0);
    hooks.useLayoutEffect(() => {
        if (tabMaxWidth == undefined && rootRef && rootRef.current && !isDisabled) {
            const isOverflow = tabBarWidth < rootRef.current.scrollWidth;
            if (!isOverflow) {
                return;
            }
            const tabWidths = tabBarUtils.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 = hooks.useCallback((entry) => {
        if (tabBarWidth !== entry.contentRect.width) {
            setTabBarWidth(entry.contentRect.width);
            if (tabMaxWidth !== undefined) {
                setTabMaxWidth(undefined);
            }
        }
    }, [tabMaxWidth, tabBarWidth]);
    useResizeObserver.useResizeObserver(rootRef, getTabBarMaxWidth, { isDisabled: isDisabled });
    return {
        maxWidths: tabMaxWidth
    };
};

exports.TabBarLinkItem = TabBarLinkItem;
exports.useProgressiveTruncation = useProgressiveTruncation;
//# sourceMappingURL=useProgressiveTruncation-6c7f99bc.js.map
