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

Object.defineProperty(exports, '__esModule', { value: true });

var jsxRuntime = require('preact/jsx-runtime');
var preact = require('preact');
var compat = require('preact/compat');
var hooks = require('preact/hooks');
var HiddenAccessible = require('./HiddenAccessible-087eb49a.js');
var LiveRegion = require('./LiveRegion-62ce9ac7.js');
var TabBar = require('./TabBar-d84e222e.js');
var mergeInterpolations = require('./mergeInterpolations-6727b536.js');
var flexitem = require('./flexitem-fee13e26.js');
var collectionUtils = require('./collectionUtils-f1d3183f.js');
var useUser = require('./useUser-1295b5cb.js');
require('./LayerHost-3cd73603.js');
var useReorderableItem = require('./useReorderableItem-64be8d2b.js');
var ReorderableContext = require('./ReorderableContext-16396e17.js');
var UNSAFE_ReorderableTabBar_themes_ReorderableTabBarItemStyles_css = require('./UNSAFE_ReorderableTabBar/themes/ReorderableTabBarItemStyles.css.js');
var keys = require('./keys-25710458.js');
var classNames = require('./classNames-c14c6ef3.js');

require('./StyledCheckbox-9047ed7d.js');

require('./CollectionInteractionContext-f84ff7a1.js');



require('./useTestId-4f53d561.js');
require('./UNSAFE_Text/themes/TextStyles.css.js');

require('./vanilla-extract-recipes-createRuntimeFn.esm-d1301b2d.js');
require('./Flex-3a257bc3.js');
require('./boxalignment-e287d370.js');
require('./size-1914356b.js');
require('./utils-c0efcd5e.js');
require('./themeContract.css-f3d431c6.js');
require('./colorUtils-01f3caa2.js');
require('./_curry1-e8f0d7ea.js');
require('./arrayUtils-7d8dcfc3.js');

require('./vanilla-extract-sprinkles-createRuntimeSprinkles.esm-d68f3e0f.js');
require('./dimensions-6101ca1f.js');
require('./flexbox-2cae9a01.js');


require('./TabBarLayout-ca8af14b.js');
require('./logger-2b636482.js');


require('./UNSAFE_TabBarCommon/themes/redwood/TabBarItemVariants.css.js');



require('./UNSAFE_Badge/themes/redwood/BadgeVariants.css.js');

require('./ConveyorBeltContext-bfe84b44.js');
require('./BusyStateContext-86f40d3c.js');
require('./TabbableModeContext-e99d527e.js');


require('./hooks/UNSAFE_useTooltip/themes/redwood/TooltipContentVariants.css.js');

require('./tooltipUtils-2bc15136.js');
require('./EnvironmentProvider-5f2435e6.js');
require('./LayerManager-c535d963.js');
require('./Floating-79cbe5ad.js');
require('./useFloating-c753a7f9.js');
require('./positionUtils-a780137e.js');
require('./refUtils-a9872e75.js');
require('./useOutsideClick-dbf3d604.js');
require('./Layer-b60deb1b.js');
require('./UNSAFE_Layer/themes/LayerStyles.css.js');

require('./useThemeInterpolations-a37b37d9.js');
require('./useColorScheme-f8b1447d.js');
require('./useScale-db16c2b8.js');
require('./theme-dfd6a9fe.js');
require('./Theme-f06687af.js');
require('./useDensity-0b9fd9ca.js');
require('./unsafeDomAccess-c3a492f0.js');
require('./useModal-0739a528.js');
require('./useComponentTheme-082fc8e4.js');
require('./UNSAFE_Floating/themes/redwood/FloatingTheme.js');
require('./UNSAFE_Floating/themes/FloatingStyles.css.js');

require('./UNSAFE_Floating/themes/redwood/FloatingBaseTheme.css.js');

require('./UNSAFE_Floating/themes/redwood/FloatingVariants.css.js');
require('./vanilla-extract-dynamic.esm-2e1b7c25.js');
require('./UNSAFE_Floating/themes/FloatingContract.css.js');
require('./useUnsafeDomElementRef-f22a2f0c.js');

require('./BaseButton-d8f96bfa.js');
require('./useHover-49b0430d.js');
require('./useToggle-3ebba7d8.js');
require('./useActive-6770f917.js');
require('./clientHints-c40c5250.js');
require('./mergeProps-e3da7237.js');
require('./UNSAFE_BaseButton/themes/redwood/BaseButtonTheme.js');
require('./UNSAFE_BaseButton/themes/BaseButtonStyles.css.js');

require('./UNSAFE_BaseButton/themes/redwood/BaseButtonVariants.css.js');

require('./BareButton-e8a030d7.js');
require('./useBareButton-463210c9.js');
require('./usePress-886180e4.js');
require('./usePressClick-7a34624a.js');
require('./useTabbableMode-dbd254e8.js');
require('./useId-6c0eeb27.js');
require('./buttonUtils-dff2ea3e.js');
require('./id-86356250.js');
require('./ButtonLabelLayout-c876923f.js');
require('./Text-056f1ec5.js');
require('./useButtonLabelLayoutTheme-d09db0c9.js');
require('./UNSAFE_ButtonLabelLayout/themes/redwood/ButtonLabelLayoutTheme.js');
require('./UNSAFE_ButtonLabelLayout/themes/ButtonLabelLayoutStyles.css.js');

require('./UNSAFE_ButtonLabelLayout/themes/redwood/ButtonLabelLayoutBaseTheme.css.js');

require('./UNSAFE_ButtonLabelLayout/themes/redwood/ButtonLabelLayoutVariants.css.js');

require('./NavigationList-d0d74565.js');
require('./clientUtils-ef5e20ce.js');
require('./UNSAFE_NavigationList/themes/NavigationListStyles.css.js');

require('./useCollectionFocusRing-bed0aa16.js');
require('./useCurrentKey-1b9e3382.js');
require('./useContextMenuGesture-530ef8dd.js');
require('./textSelectionUtils-57082239.js');
require('./useTranslationBundle-12dd087d.js');
require('./TabBarContextMenu-d9bf65c2.js');
require('./SelectMenuGroupContext-a349d259.js');
require('./Sheet-1d6e8cf8.js');
require('./Modal-b751b643.js');
require('./UNSAFE_Modal/themes/ModalStyles.css.js');

require('./tabbableUtils-22a50472.js');
require('./head-68d0992f.js');
require('./_arity-c228159c.js');
require('./_curry3-18677bca.js');
require('./_curry2-c15d89cd.js');
require('./_isArray-73160ad5.js');
require('./_isString-f4443c9e.js');
require('./popupUtils-1d123cbe.js');
require('./WindowOverlay-85d999fa.js');
require('./UNSAFE_WindowOverlay/themes/WindowOverlayStyles.css.js');

require('./UNSAFE_WindowOverlay/themes/WindowOverlayContract.css.js');
require('./UNSAFE_WindowOverlay/themes/redwood/WindowOverlayTheme.js');
require('./UNSAFE_WindowOverlay/themes/redwood/WindowOverlayBaseTheme.css.js');

require('./UNSAFE_WindowOverlay/themes/redwood/WindowOverlayVariants.css.js');
require('./UNSAFE_Sheet/themes/SheetStyles.css.js');

require('./useAnimationStatus-8075dc19.js');
require('./useAnimation-65c0e455.js');
require('./animationUtils-54852d03.js');
require('./Dropdown-1ba432a8.js');
require('./keyboardUtils-b42fe7d5.js');
require('./usePopupAnimation-f3b34413.js');
require('./popupAnimationUtils-dcace427.js');
require('./UNSAFE_Dropdown/themes/dropdownStyles.css.js');

require('./useOutsideMousedown-70f36cca.js');
require('./useEffectEvent-832ffba5.js');
require('./UNSAFE_Menu/themes/MenuStyles.css.js');

require('./UNSAFE_Menu/themes/DropdownMenuStyles.css.js');

require('./Skeleton-8e35c7d1.js');
require('./borders-4b8488cb.js');
require('./UNSAFE_Skeleton/themes/redwood/SkeletonTheme.js');
require('./UNSAFE_Skeleton/themes/SkeletonStyles.css.js');

require('./UNSAFE_Skeleton/themes/redwood/SkeletonBaseTheme.css.js');

require('./UNSAFE_Skeleton/themes/redwood/SkeletonVariants.css.js');
require('./UNSAFE_Menu/themes/MenuSkeletonStyles.css.js');

require('./UNSAFE_Menu/themes/redwood/MenuItemTheme.js');
require('./UNSAFE_Menu/themes/MenuItemStyles.css.js');

require('./UNSAFE_Menu/themes/redwood/MenuItemBaseTheme.css.js');

require('./UNSAFE_Menu/themes/redwood/MenuItemVariants.css.js');

require('./useInteractionStyle-c203a8a0.js');
require('./Separator-85962472.js');
require('./UNSAFE_Separator/themes/SeparatorStyles.css.js');



require('./UNSAFE_Menu/themes/redwood/MenuSeparatorVariants.css.js');
require('./tabBarUtils-54fc91af.js');
require('./useNavigationListItem-b97e76d5.js');
require('./UNSAFE_NavigationListCommon/themes/redwood/NavigationListItemTheme.js');
require('./UNSAFE_NavigationList/themes/NavigationListItemStyles.css.js');

require('./UNSAFE_NavigationList/themes/redwood/NavigationListItemBaseTheme.css.js');

require('./UNSAFE_NavigationList/themes/redwood/NavigationListItemVariants.css.js');



require('./UNSAFE_TabBar/themes/TabBarStyles.css.js');

require('./useTabBar-35b73d10.js');
require('./useReorderableContext-92514102.js');
require('./mergeDeepWithKey-210b024d.js');
require('./_isObject-28636267.js');

require('./Selector-6550b8e0.js');
require('./BaseSelector-2dc69917.js');
require('./useFocus-1b288fb9.js');
require('./PRIVATE_BaseSelector/themes/SelectorStyles.css.js');
require('./useCollectionInteractionContext-6fc0200e.js');
require('./index-0aa99b92.js');
require('./UNSAFE_Layer/themes/LayerHostStyles.css.js');

require('./dndUtils-21d97036.js');
require('./hooks/PRIVATE_useReorderable/themes/ReorderableItemStyles.css.js');

require('./Check-1272bb86.js');
require('./Icon-56789beb.js');
require('./useTooltip-34accecc.js');
require('./useTooltipControlled-0a95856c.js');
require('./useTouch-4dec8729.js');
require('./hooks/UNSAFE_useTooltip/themes/redwood/TooltipContentTheme.js');
require('./hooks/UNSAFE_useTooltip/themes/TooltipContentStyles.css.js');
require('./hooks/UNSAFE_useTooltip/themes/redwood/TooltipContentBaseTheme.css.js');
require('./UNSAFE_Icon/themes/IconStyle.css.js');
require('./CheckboxOff-a3ed334d.js');
require('./CheckboxOn-b5dda28b.js');
require('./CheckboxMixed-a17c8298.js');
require('./UNSAFE_Checkbox/themes/CheckboxIconContract.css.js');
require('./UNSAFE_Checkbox/themes/redwood/CheckboxIconTheme.js');
require('./UNSAFE_Checkbox/themes/CheckboxIconStyles.css.js');

require('./UNSAFE_Checkbox/themes/redwood/CheckboxIconBaseTheme.css.js');

require('./UNSAFE_Checkbox/themes/redwood/CheckboxIconVariants.css.js');



const ITEM_SELECTOR = '[role="tab"]';
/**
 * A private item that will be used by ReorderableTabBar, location TBD (could be moved to PRIVATE_TabBar)
 */
function ReorderableTabBarItem({ children, dragKey, setDragKey, onReorder, layout, rootRef, isFirstItem, isLastItem }) {
    const tabBarItemRef = hooks.useRef(null);
    const getItem = hooks.useCallback(() => tabBarItemRef?.current?.querySelector(ITEM_SELECTOR), []);
    const setTransferData = hooks.useCallback((event) => {
        event.dataTransfer?.setData('text/tabbar-item-key', collectionUtils.getKey(getItem()) + '');
    }, [getItem]);
    const { direction } = useUser.useUser();
    const isRtl = direction === 'rtl';
    // Flex dimensions
    const styleInterpolations = mergeInterpolations.mergeInterpolations([
        ...Object.values(flexitem.flexitemInterpolations)
    ]);
    const flexDimensions = styleInterpolations({
        flex: layout === 'stretch' ? '1 0 auto' : '0 0 auto'
    });
    const { rootProps, isDragged, overlayZoneBeforeProps, overlayZoneAfterProps } = useReorderableItem.useReorderableItem({
        isDisabled: onReorder ? false : true,
        dragKey,
        setDragKey,
        onReorder,
        rootRef,
        ref: tabBarItemRef,
        getItem,
        setTransferData,
        itemStyles: {
            itemOverlayFront: UNSAFE_ReorderableTabBar_themes_ReorderableTabBarItemStyles_css.styles.itemOverlayFront,
            itemOverlayRear: UNSAFE_ReorderableTabBar_themes_ReorderableTabBarItemStyles_css.styles.itemOverlayRear,
            itemDragger: UNSAFE_ReorderableTabBar_themes_ReorderableTabBarItemStyles_css.styles.itemDragger
        },
        itemSelector: ITEM_SELECTOR
    });
    const overlayZoneBeforeClass = classNames.classNames([
        overlayZoneBeforeProps?.class,
        // Set the classes specific to isFirstItem/isLastItem which is passed down from reorderable tabbar which evaluated while mapping the children
        !isRtl && isFirstItem && UNSAFE_ReorderableTabBar_themes_ReorderableTabBarItemStyles_css.styles.itemOverlayFrontFirst,
        isRtl && isLastItem && UNSAFE_ReorderableTabBar_themes_ReorderableTabBarItemStyles_css.styles.itemOverlayFrontFirst
    ]);
    const overlayZoneAfterClass = classNames.classNames([
        overlayZoneAfterProps?.class,
        // Set the classes specific to isFirstItem/isLastItem which is passed down from reorderable tabbar which evaluated while mapping the children
        !isRtl && isLastItem && UNSAFE_ReorderableTabBar_themes_ReorderableTabBarItemStyles_css.styles.itemOverlayRearLast,
        isRtl && isFirstItem && UNSAFE_ReorderableTabBar_themes_ReorderableTabBarItemStyles_css.styles.itemOverlayRearLast
    ]);
    return (jsxRuntime.jsxs("div", { ...rootProps, draggable: onReorder ? true : false, "data-oj-draggable": onReorder ? '' : undefined, style: flexDimensions, children: [children, !isDragged && keys.isKeyDefined(dragKey) && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { ...overlayZoneBeforeProps, class: overlayZoneBeforeClass }), jsxRuntime.jsx("div", { ...overlayZoneAfterProps, class: overlayZoneAfterClass })] }))] }));
}

/**
 * A component that allows reordering of tabs within a TabBar.
 */
const ReorderableTabBar = compat.forwardRef(({ 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, children, layout = 'stretch', display = 'standard', size = 'md', edge = 'top', selection, onSelect, onRemove, onReorder, contextMenuConfig, testId }, ref) => {
    const rootRef = hooks.useRef(null);
    const [dragKey, setDragKey] = hooks.useState(undefined);
    const childrenArray = preact.toChildArray(children);
    const displayStackProps = {
        display: display
    };
    const displayNonStackProps = {
        display: display,
        size: size
    };
    const displayProps = display === 'stacked' ? displayStackProps : displayNonStackProps;
    const { reorderProps, reorderContext, reorderInstructionsId, reorderStatus, reorderInstructions } = useReorderableItem.useReorderable({
        onReorder,
        rootRef,
        itemSelector: ITEM_SELECTOR
    });
    const tabBarReorderContext = {
        currentItemKey: reorderContext.currentItemKey,
        onReorder: onReorder
    };
    return (jsxRuntime.jsxs("div", { ref: rootRef, ...reorderProps, children: [jsxRuntime.jsx(ReorderableContext.ReorderableContext.Provider, { value: tabBarReorderContext, children: jsxRuntime.jsx(TabBar.TabBar, { ref: ref, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, layout: layout, edge: edge, selection: selection, onSelect: onSelect, onRemove: onRemove, testId: testId, ...displayProps, "aria-describedby": reorderInstructionsId, contextMenuConfig: contextMenuConfig, children: childrenArray.map((child, idx) => {
                        return (jsxRuntime.jsx(ReorderableTabBarItem, { dragKey: dragKey, setDragKey: setDragKey, onReorder: onReorder, layout: layout, rootRef: rootRef, isFirstItem: idx === 0, isLastItem: idx === childrenArray.length - 1, children: child }));
                    }) }) }), jsxRuntime.jsx("span", { id: reorderInstructionsId, children: jsxRuntime.jsx(HiddenAccessible.HiddenAccessible, { children: reorderInstructions }) }), jsxRuntime.jsx(LiveRegion.LiveRegion, { children: reorderStatus })] }));
});

exports.ReorderableTabBar = ReorderableTabBar;
//# sourceMappingURL=UNSAFE_ReorderableTabBar.js.map
