import {dom as $b7b7a92703138c9b$export$df3a06d6289f983e, Provider as $b7b7a92703138c9b$export$2881499e37b75b9a, useContextProps as $b7b7a92703138c9b$export$29f1550f4b0d4415, useRenderProps as $b7b7a92703138c9b$export$4d86445c2cf5e3} from "./utils.js";
import {OverlayArrowContext as $5cdd5922a5c055ad$export$2de4954e8ae13b9f} from "./OverlayArrow.js";
import {useOverlayPosition as $kbHsW$useOverlayPosition} from "react-aria/private/overlays/useOverlayPosition";
import {filterDOMProps as $kbHsW$filterDOMProps} from "react-aria/private/utils/filterDOMProps";
import {FocusableProvider as $kbHsW$FocusableProvider} from "react-aria/private/interactions/useFocusable";
import {mergeProps as $kbHsW$mergeProps} from "react-aria/mergeProps";
import {OverlayContainer as $kbHsW$OverlayContainer} from "react-aria/private/overlays/useModal";
import $kbHsW$react, {createContext as $kbHsW$createContext, useRef as $kbHsW$useRef, forwardRef as $kbHsW$forwardRef, useContext as $kbHsW$useContext} from "react";
import {useTooltipTriggerState as $kbHsW$useTooltipTriggerState} from "react-stately/useTooltipTriggerState";
import {useExitAnimation as $kbHsW$useExitAnimation, useEnterAnimation as $kbHsW$useEnterAnimation} from "react-aria/private/utils/animation";
import {useTooltipTrigger as $kbHsW$useTooltipTrigger, useTooltip as $kbHsW$useTooltip} from "react-aria/useTooltipTrigger";

/*
 * Copyright 2022 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */ 










const $86371daa326220e5$export$7a7623236eec67fa = /*#__PURE__*/ (0, $kbHsW$createContext)(null);
const $86371daa326220e5$export$39ae08fa83328b12 = /*#__PURE__*/ (0, $kbHsW$createContext)(null);
function $86371daa326220e5$export$8c610744efcf8a1d(props) {
    let state = (0, $kbHsW$useTooltipTriggerState)(props);
    let ref = (0, $kbHsW$useRef)(null);
    let { triggerProps: triggerProps, tooltipProps: tooltipProps } = (0, $kbHsW$useTooltipTrigger)(props, state, ref);
    return /*#__PURE__*/ (0, $kbHsW$react).createElement((0, $b7b7a92703138c9b$export$2881499e37b75b9a), {
        values: [
            [
                $86371daa326220e5$export$7a7623236eec67fa,
                state
            ],
            [
                $86371daa326220e5$export$39ae08fa83328b12,
                {
                    ...tooltipProps,
                    triggerRef: ref
                }
            ]
        ]
    }, /*#__PURE__*/ (0, $kbHsW$react).createElement((0, $kbHsW$FocusableProvider), {
        ...triggerProps,
        ref: ref
    }, props.children));
}
const $86371daa326220e5$export$28c660c63b792dea = /*#__PURE__*/ (0, $kbHsW$forwardRef)(function Tooltip({ UNSTABLE_portalContainer: UNSTABLE_portalContainer, ...props }, ref) {
    [props, ref] = (0, $b7b7a92703138c9b$export$29f1550f4b0d4415)(props, ref, $86371daa326220e5$export$39ae08fa83328b12);
    let contextState = (0, $kbHsW$useContext)($86371daa326220e5$export$7a7623236eec67fa);
    let localState = (0, $kbHsW$useTooltipTriggerState)(props);
    let state = props.isOpen != null || props.defaultOpen != null || !contextState ? localState : contextState;
    let isExiting = (0, $kbHsW$useExitAnimation)(ref, state.isOpen) || props.isExiting || false;
    if (!state.isOpen && !isExiting) return null;
    return /*#__PURE__*/ (0, $kbHsW$react).createElement((0, $kbHsW$OverlayContainer), {
        portalContainer: UNSTABLE_portalContainer
    }, /*#__PURE__*/ (0, $kbHsW$react).createElement($86371daa326220e5$var$TooltipInner, {
        ...props,
        tooltipRef: ref,
        isExiting: isExiting
    }));
});
function $86371daa326220e5$var$TooltipInner(props) {
    let state = (0, $kbHsW$useContext)($86371daa326220e5$export$7a7623236eec67fa);
    let arrowRef = (0, $kbHsW$useRef)(null);
    let { overlayProps: overlayProps, arrowProps: arrowProps, placement: placement, triggerAnchorPoint: triggerAnchorPoint } = (0, $kbHsW$useOverlayPosition)({
        placement: props.placement || 'top',
        targetRef: props.triggerRef,
        overlayRef: props.tooltipRef,
        arrowRef: arrowRef,
        offset: props.offset,
        crossOffset: props.crossOffset,
        isOpen: state.isOpen,
        arrowBoundaryOffset: props.arrowBoundaryOffset,
        shouldFlip: props.shouldFlip,
        containerPadding: props.containerPadding,
        onClose: ()=>state.close(true)
    });
    let isEntering = (0, $kbHsW$useEnterAnimation)(props.tooltipRef, !!placement) || props.isEntering || false;
    let renderProps = (0, $b7b7a92703138c9b$export$4d86445c2cf5e3)({
        ...props,
        defaultClassName: 'react-aria-Tooltip',
        values: {
            placement: placement,
            isEntering: isEntering,
            isExiting: props.isExiting,
            state: state
        }
    });
    props = (0, $kbHsW$mergeProps)(props, overlayProps);
    let { tooltipProps: tooltipProps } = (0, $kbHsW$useTooltip)(props, state);
    let DOMProps = (0, $kbHsW$filterDOMProps)(props, {
        global: true
    });
    return /*#__PURE__*/ (0, $kbHsW$react).createElement((0, $b7b7a92703138c9b$export$df3a06d6289f983e).div, {
        ...(0, $kbHsW$mergeProps)(DOMProps, renderProps, tooltipProps),
        ref: props.tooltipRef,
        style: {
            ...overlayProps.style,
            '--trigger-anchor-point': triggerAnchorPoint ? `${triggerAnchorPoint.x}px ${triggerAnchorPoint.y}px` : undefined,
            ...renderProps.style
        },
        "data-placement": placement !== null && placement !== void 0 ? placement : undefined,
        "data-entering": isEntering || undefined,
        "data-exiting": props.isExiting || undefined
    }, /*#__PURE__*/ (0, $kbHsW$react).createElement((0, $5cdd5922a5c055ad$export$2de4954e8ae13b9f).Provider, {
        value: {
            ...arrowProps,
            placement: placement,
            ref: arrowRef
        }
    }, renderProps.children));
}


export {$86371daa326220e5$export$7a7623236eec67fa as TooltipTriggerStateContext, $86371daa326220e5$export$39ae08fa83328b12 as TooltipContext, $86371daa326220e5$export$8c610744efcf8a1d as TooltipTrigger, $86371daa326220e5$export$28c660c63b792dea as Tooltip};
//# sourceMappingURL=Tooltip.js.map
