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

var jsxRuntime = require('preact/jsx-runtime');
var hooks = require('preact/hooks');
var Flex = require('./Flex-da9f223a.js');
var usePress = require('./usePress-886180e4.js');
var UNSAFE_Selector_themes_SelectorStyles_css = require('./UNSAFE_Selector/themes/SelectorStyles.css.js');
var StyledCheckbox = require('./StyledCheckbox-a78cdad7.js');
var mergeProps = require('./mergeProps-e3da7237.js');
var useActive = require('./useActive-6770f917.js');
var useFocus = require('./useFocus-1b288fb9.js');
var useTestId = require('./useTestId-32c35bff.js');
var useTooltip = require('./useTooltip-cf4a15f3.js');
var useHover = require('./useHover-c099039f.js');
require('./logger-2b636482.js');
require('./LayerHost-8ec73638.js');
require('preact/compat');


require('./hooks/UNSAFE_useTooltip/themes/redwood/TooltipContentVariants.css.js');
require('./tooltipUtils-d461919d.js');
var useTranslationBundle = require('./useTranslationBundle-38c0edae.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 = hooks.useRef(null);
    const { isActive, activeProps } = useActive.useActive();
    const { isFocus, focusProps } = useFocus.useFocus();
    const { pressProps } = usePress.usePress(pressHandler);
    const { isHover, hoverProps } = useHover.useHover();
    const isChecked = selected === 'partial' || selected === 'partial-all'
        ? 'partial'
        : selected === 'all'
            ? 'checked'
            : 'unchecked';
    const testIdProps = useTestId.useTestId(testId);
    const onClick = () => {
        // ensure the checkbox is focused after click
        inputRef.current?.focus();
    };
    const translations = useTranslationBundle.useTranslationBundle('@oracle/oraclejet-preact');
    const tooltipLabel = selected === 'none' || selected === 'partial'
        ? translations.selectorAll_selectAll()
        : translations.selectorAll_deselectAll();
    const { tooltipContent, tooltipProps } = useTooltip.useTooltip({
        text: tooltipLabel,
        isDisabled: showTooltip === 'disabled' ? true : false
    });
    const ariaLabelText = !ariaLabel && !ariaLabelledby ? tooltipLabel : undefined;
    return (jsxRuntime.jsx("div", { class: UNSAFE_Selector_themes_SelectorStyles_css.styles.container, ...mergeProps.mergeProps({ onClick }, pressProps, tooltipProps), ...testIdProps, children: jsxRuntime.jsx("div", { class: UNSAFE_Selector_themes_SelectorStyles_css.styles.base, ...activeProps, ...hoverProps, children: jsxRuntime.jsxs(Flex.Flex, { align: "center", justify: "center", children: [jsxRuntime.jsx(StyledCheckbox.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();
    }
};

exports.SelectorAll = SelectorAll;
//# sourceMappingURL=SelectorAll-e0989aef.js.map
