/* @oracle/oraclejet-preact: undefined */
import { useContext, useCallback } from 'preact/hooks';
import { u as usePress } from './usePress-051f5adb.js';
import { m as mergeProps } from './mergeProps-88ea8306.js';
import { c as classNames } from './classNames-4e12b00d.js';
import { u as useInteractionStyle } from './useInteractionStyle-52222fdd.js';
import { u as useComponentTheme } from './useComponentTheme-d2f9e47f.js';
import { createContext } from 'preact';
import { m as mergeInterpolations } from './mergeInterpolations-e2db2a66.js';
import { f as flexitemInterpolations } from './flexitem-7b7f7920.js';
import { NavigationListItemRedwoodTheme } from './UNSAFE_NavigationListCommon/themes/redwood/NavigationListItemTheme.js';

/**
 * @license
 * Copyright (c) %FIRST_YEAR% %CURRENT_YEAR%, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 * @ignore
 */
/**
 * Context used to pass navlist information without having to pass it to navlist children props.
 * We want to communicate information down to any interested navlist item children.
 */
const NavigationListContext = createContext(null);

/**
 * @license
 * Copyright (c) %FIRST_YEAR% %CURRENT_YEAR%, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 * @ignore
 */
/**
 * Utility hook for consuming the NavigationListContext
 *
 * @returns The value of NavigationListContext provider
 */
function useNavigationListContext() {
    return useContext(NavigationListContext);
}

const flexItemStyleInterpolations = mergeInterpolations([
    ...Object.values(flexitemInterpolations)
]);
const { class: labelContainerFlexItemClasses, ...labelContainerFlexItemStyle } = flexItemStyleInterpolations({
    alignSelf: 'center'
});
function useNavigationListItem({ itemKey }) {
    const { onSelectionChange, selection, currentKey, showFocusRing, navigationListItemPrefix } = useNavigationListContext();
    //Selection and focus state
    const isCurrent = currentKey === itemKey;
    const isSelected = selection === itemKey;
    //Styling
    const { interactionProps, applyPseudoHoverStyle, applyHoverStyle, applyActiveStyle } = useInteractionStyle();
    const { classes: listItemClasses, styles: { labelContainerClasses } } = useComponentTheme(NavigationListItemRedwoodTheme, {
        focusRing: showFocusRing ? 'isFocusRing' : 'notFocusRing',
        current: isCurrent ? 'isCurrent' : 'notCurrtent',
        selected: isSelected ? 'isSelected' : 'notSelected',
        hybridHover: applyHoverStyle ? 'isHybridHover' : 'notHybridHover',
        pseudoHover: applyPseudoHoverStyle ? 'isPseudoHover' : 'notPseudoHover',
        active: applyActiveStyle ? 'isActive' : 'notActive'
    });
    //Item handlers
    const handlePress = useCallback(() => {
        onSelectionChange?.({ value: itemKey, reason: 'pointer' });
    }, [itemKey, onSelectionChange]);
    //Legacy navlist makes selection on keyDown, but since preact tabbar made selection after keyUp, will do the same
    //for preact navlist
    const { pressProps } = usePress(handlePress);
    return {
        itemId: navigationListItemPrefix + itemKey,
        itemHandlers: mergeProps(interactionProps, pressProps /*,onFocusProps*/),
        itemClasses: classNames([listItemClasses]),
        isSelected,
        labelContainerClasses: classNames([labelContainerClasses, labelContainerFlexItemClasses]),
        labelContainerStyle: labelContainerFlexItemStyle
    };
}

export { NavigationListContext as N, useNavigationListItem as a, useNavigationListContext as u };
//# sourceMappingURL=useNavigationListItem-a28f2c34.js.map
