import "./Popover.css";
import {ColorSchemeContext as $9affbfa4e13b9582$export$374e0245597d19a3} from "./Provider.mjs";
import {mergeStyles as $feb886035e0d4633$export$e618dc39ac9ad607} from "../icons/runtime.mjs";
import {useSpectrumContextProps as $5ce63c423902f47d$export$764f6146fadd77f7} from "../icons/useSpectrumContextProps.mjs";
import {jsx as $ggIy9$jsx, jsxs as $ggIy9$jsxs, Fragment as $ggIy9$Fragment} from "react/jsx-runtime";
import {useLocale as $ggIy9$useLocale, Popover as $ggIy9$Popover, composeRenderProps as $ggIy9$composeRenderProps, OverlayArrow as $ggIy9$OverlayArrow, OverlayTriggerStateContext as $ggIy9$OverlayTriggerStateContext} from "react-aria-components";
import {createContext as $ggIy9$createContext, forwardRef as $ggIy9$forwardRef, useContext as $ggIy9$useContext, useCallback as $ggIy9$useCallback, useMemo as $ggIy9$useMemo} from "react";
import {mergeRefs as $ggIy9$mergeRefs} from "@react-aria/utils";
import {useDOMRef as $ggIy9$useDOMRef} from "@react-spectrum/utils";

/*
 * Copyright 2024 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.
 */ 







let $88b746eba92c8d0d$var$popover = function anonymous(props, overrides) {
    let rules = " ";
    let width = false;
    let maxWidth = false;
    let matches = String(overrides || '').matchAll(/(?:^|\s)(J|G|I|H|_u|_v|_s|__A|_d|_J|z|y|B|A|_P|_9|W|_l|_A|_z|_6|Z|N|L)[^\s]+/g);
    for (let p of matches){
        if (p[1] === "Z") width = true;
        if (p[1] === "L") maxWidth = true;
        rules += p[0];
    }
    if (props.colorScheme === "dark") rules += ' _pa12';
    else if (props.colorScheme === "light") rules += ' _pb12';
    else if (props.colorScheme === "light dark") rules += ' _pc12';
    else rules += ' _pN79Hzc12';
    rules += ' -Ovbhqd-g_g12';
    rules += ' -Ovbhqd-lga12';
    rules += ' gEzkoQe12';
    rules += ' oc12';
    rules += ' nc12';
    rules += ' kc12';
    rules += ' jc12';
    if (props.isArrowShown) rules += ' _rgr5H3d12';
    if (props.isArrowShown) rules += ' _nd12';
    else rules += ' _nLeasBb12';
    rules += ' _Lf12';
    rules += ' _Mb12';
    rules += ' Oye39g12';
    rules += ' Ola12';
    if (props.size === "L") {
        if (!width) rules += ' ZE12';
    } else if (props.size === "M") {
        if (!width) rules += ' ZB12';
    } else if (props.size === "S") {
        if (!width) rules += ' Zz12';
    }
    if (!maxWidth) rules += ' LEmL1Zb12';
    rules += ' _oa12';
    rules += ' sd12';
    if (props.isExiting) rules += ' _Ia12';
    else if (props.isEntering) rules += ' _Ia12';
    if (props.isSubmenu) {
        rules += ' -_8PloMd-s12';
        rules += ' __Ya12';
    } else if (props.placement === "bottom") {
        if (props.isExiting) {
            rules += ' -_8PloMd-l12';
            rules += ' __Ya12';
        } else if (props.isEntering) {
            rules += ' -_8PloMd-l12';
            rules += ' __Ya12';
        }
    } else if (props.placement === "top") {
        if (props.isExiting) {
            rules += ' -_8PloMd-F12';
            rules += ' __Ya12';
        } else if (props.isEntering) {
            rules += ' -_8PloMd-F12';
            rules += ' __Ya12';
        }
    }
    if (props.isSubmenu) {
        rules += ' -_7PloMd-s12';
        rules += ' __Ya12';
    } else if (props.placement === "right") {
        if (props.isExiting) {
            rules += ' -_7PloMd-m12';
            rules += ' __Ya12';
        } else if (props.isEntering) {
            rules += ' -_7PloMd-m12';
            rules += ' __Ya12';
        }
    } else if (props.placement === "left") {
        if (props.isExiting) {
            rules += ' -_7PloMd-G12';
            rules += ' __Ya12';
        } else if (props.isEntering) {
            rules += ' -_7PloMd-G12';
            rules += ' __Ya12';
        }
    }
    rules += ' YmenWad12';
    rules += ' Xc12';
    if (props.isExiting) rules += ' _2c12';
    rules += ' _Bb12';
    if (props.isExiting) rules += ' _Ob12';
    return rules;
};
// TODO: animations and real Popover Arrow
let $88b746eba92c8d0d$var$arrow = function anonymous(props) {
    let rules = " ";
    rules += ' sb12';
    rules += ' tEzkoQe12';
    rules += ' Zl12';
    rules += ' Fh12';
    if (props.placement === "right") rules += ' _Sd12';
    else if (props.placement === "left") rules += ' _Sa12';
    else if (props.placement === "bottom") rules += ' _Sc12';
    else if (props.placement === "top") rules += ' _Sb12';
    else rules += ' _Sc12';
    if (props.placement === "right") {
        rules += ' -_7PloMd-y12';
        rules += ' __Ya12';
    } else if (props.placement === "left") {
        rules += ' -_7PloMd-e12';
        rules += ' __Ya12';
    }
    rules += ' _Vb12';
    rules += ' Vye39g12';
    rules += ' Vlb12';
    return rules;
};
const $88b746eba92c8d0d$export$9b9a0cd73afb7ca4 = /*#__PURE__*/ (0, $ggIy9$createContext)(null);
const $88b746eba92c8d0d$export$60dfb2c3202ad27d = /*#__PURE__*/ (0, $ggIy9$createContext)(false);
const $88b746eba92c8d0d$export$fde1b04c590741a3 = /*#__PURE__*/ (0, $ggIy9$forwardRef)(function PopoverBase(props, ref) {
    let { hideArrow: hideArrow = false, UNSAFE_className: UNSAFE_className = '', UNSAFE_style: UNSAFE_style, styles: styles, size: size } = props;
    let colorScheme = (0, $ggIy9$useContext)((0, $9affbfa4e13b9582$export$374e0245597d19a3));
    let { locale: locale, direction: direction } = (0, $ggIy9$useLocale)();
    // TODO: should we pass through lang and dir props in RAC?
    let popoverRef = (0, $ggIy9$useCallback)((el)=>{
        if (el) {
            el.lang = locale;
            el.dir = direction;
        }
    }, [
        locale,
        direction
    ]);
    // Memoed so it doesn't break ComboBox/Picker scrolling
    let mergedRef = (0, $ggIy9$useMemo)(()=>(0, $ggIy9$mergeRefs)(popoverRef, ref), [
        ref,
        popoverRef
    ]);
    // On small devices, show a modal (or eventually a tray) instead of a popover.
    // TODO: reverted this until we have trays.
    // let isMobile = useIsMobileDevice();
    // if (isMobile && process.env.NODE_ENV !== 'test') {
    //   let mappedChildren = typeof children === 'function'
    //     ? (renderProps: ModalRenderProps) => children({...renderProps, defaultChildren: null, trigger, placement: 'bottom'})
    //     : children;
    //   return (
    //     <Modal size={size} isDismissable>
    //       {composeRenderProps(mappedChildren, (children, {state}) => (
    //         <>
    //           {children}
    //           {/* Add additional dismiss button at the end to match popovers. */}
    //           <DismissButton onDismiss={state.close} />
    //         </>
    //       ))}
    //     </Modal>
    //   );
    // }
    // TODO: this still isn't the final popover 'tip', copying various ones out of the designs files yields different results
    // containerPadding not working as expected
    return /*#__PURE__*/ (0, $ggIy9$jsx)((0, $ggIy9$Popover), {
        ...props,
        offset: (props.offset ?? 8) + (hideArrow ? 0 : 8),
        ref: mergedRef,
        style: {
            ...UNSAFE_style,
            // Override default z-index from useOverlayPosition. We use isolation: isolate instead.
            zIndex: undefined
        },
        className: (renderProps)=>UNSAFE_className + (0, $feb886035e0d4633$export$e618dc39ac9ad607)($88b746eba92c8d0d$var$popover({
                ...renderProps,
                size: size,
                isArrowShown: !hideArrow,
                colorScheme: colorScheme,
                isSubmenu: renderProps.trigger === 'SubmenuTrigger'
            }), styles),
        children: (0, $ggIy9$composeRenderProps)(props.children, (children, renderProps)=>/*#__PURE__*/ (0, $ggIy9$jsxs)((0, $ggIy9$Fragment), {
                children: [
                    !hideArrow && /*#__PURE__*/ (0, $ggIy9$jsx)((0, $ggIy9$OverlayArrow), {
                        className: "",
                        children: /*#__PURE__*/ (0, $ggIy9$jsx)("svg", {
                            viewBox: "0 0 18 10",
                            className: $88b746eba92c8d0d$var$arrow(renderProps),
                            children: /*#__PURE__*/ (0, $ggIy9$jsx)("path", {
                                transform: "translate(0 -1)",
                                d: "M1 1L7.93799 8.52588C8.07224 8.67448 8.23607 8.79362 8.41895 8.87524C8.60182 8.95687 8.79973 8.9993 9 9C9.19984 8.99882 9.39724 8.95606 9.57959 8.87427C9.76193 8.79248 9.9253 8.67336 10.0591 8.5249L17 1"
                            })
                        })
                    }),
                    /*#__PURE__*/ (0, $ggIy9$jsx)($88b746eba92c8d0d$export$60dfb2c3202ad27d.Provider, {
                        value: true,
                        children: children
                    })
                ]
            }))
    });
});
const $88b746eba92c8d0d$var$innerDivStyle = function anonymous(props, overrides) {
    let rules = " ";
    let position = false;
    let width = false;
    let maxWidth = false;
    let maxHeight = false;
    let matches = String(overrides || '').matchAll(/(?:^|\s)(J|G|I|H|_u|_v|_s|__A|_d|_J|z|y|B|A|_P|_9|W|_l|_A|_z|_6|Z|N|L|F|M|K)[^\s]+/g);
    for (let p of matches){
        if (p[1] === "_P") position = true;
        if (p[1] === "Z") width = true;
        if (p[1] === "L") maxWidth = true;
        if (p[1] === "K") maxHeight = true;
        rules += p[0];
    }
    if (props.padding === "none") rules += ' Td12';
    else if (props.padding === "default") rules += ' Tt12';
    if (props.padding === "none") rules += ' Qd12';
    else if (props.padding === "default") rules += ' Qt12';
    if (props.padding === "none") rules += ' Sd12';
    else if (props.padding === "default") rules += ' St12';
    if (props.padding === "none") rules += ' Rd12';
    else if (props.padding === "default") rules += ' Rt12';
    rules += ' _oa12';
    rules += ' _Le12';
    rules += ' oi12';
    rules += ' ni12';
    rules += ' ki12';
    rules += ' ji12';
    rules += ' _Na12';
    rules += ' Pa12';
    if (!position) rules += ' _Pc12';
    if (!width) rules += ' Za12';
    if (!maxWidth) rules += ' L40ub4c12';
    if (!maxHeight) rules += ' K40ub4c12';
    return rules;
};
const $88b746eba92c8d0d$export$5b6b19405a83ff9d = /*#__PURE__*/ (0, $ggIy9$forwardRef)(function Popover(props, ref) {
    [props, ref] = (0, $5ce63c423902f47d$export$764f6146fadd77f7)(props, ref, $88b746eba92c8d0d$export$9b9a0cd73afb7ca4);
    let domRef = (0, $ggIy9$useDOMRef)(ref);
    let { UNSAFE_className: UNSAFE_className, UNSAFE_style: UNSAFE_style, styles: styles, padding: padding = 'default', ...otherProps } = props;
    return /*#__PURE__*/ (0, $ggIy9$jsx)($88b746eba92c8d0d$export$fde1b04c590741a3, {
        ...otherProps,
        ref: domRef,
        children: (0, $ggIy9$composeRenderProps)(props.children, (children)=>/*#__PURE__*/ (0, $ggIy9$jsx)("div", {
                style: UNSAFE_style,
                className: (UNSAFE_className || '') + $88b746eba92c8d0d$var$innerDivStyle({
                    padding: padding
                }, styles),
                children: /*#__PURE__*/ (0, $ggIy9$jsx)((0, $ggIy9$OverlayTriggerStateContext).Provider, {
                    value: null,
                    children: children
                })
            }))
    });
});


export {$88b746eba92c8d0d$export$9b9a0cd73afb7ca4 as PopoverContext, $88b746eba92c8d0d$export$60dfb2c3202ad27d as InPopoverContext, $88b746eba92c8d0d$export$fde1b04c590741a3 as PopoverBase, $88b746eba92c8d0d$export$5b6b19405a83ff9d as Popover};
//# sourceMappingURL=Popover.mjs.map
