/* @oracle/oraclejet-preact: undefined */
import { jsx, jsxs } from 'preact/jsx-runtime';
import { useRef } from 'preact/hooks';
import { F as Flex } from './Flex-ce31b351.js';
import { u as usePress } from './usePress-051f5adb.js';
import { styles } from './UNSAFE_Selector/themes/SelectorStyles.css.js';
import { S as StyledCheckbox } from './StyledCheckbox-4451bc4a.js';
import { m as mergeProps } from './mergeProps-88ea8306.js';
import { u as useActive } from './useActive-fb6d4d52.js';
import { u as useFocus } from './useFocus-38c95977.js';
import { u as useTestId } from './useTestId-9b504481.js';
import { u as useTooltip } from './useTooltip-89ca3f3e.js';
import { u as useHover } from './useHover-19340c22.js';
import './logger-c92f309c.js';
import './LayerHost-e6402730.js';
import 'preact/compat';
import './TooltipContentStyles.styles.css';
import './hooks/UNSAFE_useTooltip/themes/redwood/TooltipContentBaseTheme.styles.css';
import './hooks/UNSAFE_useTooltip/themes/redwood/TooltipContentVariants.css.js';
import './tooltipUtils-768450a7.js';
import { u as useTranslationBundle } from './useTranslationBundle-09302c20.js';

/**
 * The SelectorAll component renders checkboxes for select all case.
 */
function SelectorAll({ 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, selected, onChange, showTooltip = 'disabled', testId }) {
    const pressHandler = (event) => {
        if (selected == 'none' || selected == 'partial') {
            onChange?.({ value: { all: true, deletedKeys: new Set() }, target: event.target });
        }
        else {
            onChange?.({ value: { all: false, keys: new Set() }, target: event.target });
        }
    };
    const inputRef = useRef(null);
    const { isActive, activeProps } = useActive();
    const { isFocus, focusProps } = useFocus();
    const { pressProps } = usePress(pressHandler);
    const { isHover, hoverProps } = useHover();
    const isChecked = selected === 'partial' || selected === 'partial-all'
        ? 'partial'
        : selected === 'all'
            ? 'checked'
            : 'unchecked';
    const testIdProps = useTestId(testId);
    const onClick = () => {
        // ensure the checkbox is focused after click
        inputRef.current?.focus();
    };
    const translations = useTranslationBundle('@oracle/oraclejet-preact');
    const tooltipLabel = selected === 'none' || selected === 'partial'
        ? translations.selectorAll_selectAll()
        : translations.selectorAll_deselectAll();
    const { tooltipContent, tooltipProps } = useTooltip({
        text: tooltipLabel,
        isDisabled: showTooltip === 'disabled' ? true : false
    });
    const ariaLabelText = !ariaLabel && !ariaLabelledby ? tooltipLabel : undefined;
    return (jsx("div", { class: styles.container, ...mergeProps({ onClick }, pressProps, tooltipProps), ...testIdProps, children: jsx("div", { class: styles.base, ...activeProps, ...hoverProps, children: jsxs(Flex, { align: "center", justify: "center", children: [jsx(StyledCheckbox, { ref: inputRef, isHover: isHover, isChecked: isChecked, isActive: isActive, isFocusRingShown: isFocus, "aria-label": ariaLabel ? ariaLabel : ariaLabelText, "aria-labelledby": ariaLabelledby, onKeyDown: handleKeyboardEvent, onKeyUp: handleKeyboardEvent, ...focusProps }), tooltipContent] }) }) }));
}
const handleKeyboardEvent = (event) => {
    if (event.key == 'Enter') {
        // prevent active styles applied to checkbox
        event.stopPropagation();
    }
};

export { SelectorAll as S };
//# sourceMappingURL=SelectorAll-f52550a6.js.map
