"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Content = exports.Anchor = exports.Trigger = exports.Root = void 0;
const react_1 = __importStar(require("react"));
const PopoverBase = __importStar(require("@radix-ui/react-popover"));
const inlines_1 = require("inlines");
const varsUtilities_1 = require("../../varsUtilities");
const useControllableState_1 = require("../../hooks/useControllableState");
const PopoverContext = (0, react_1.createContext)({
    open: false,
    setOpen: () => { },
});
function Root({ children, open: openProp, onOpenChange, }) {
    const [open, setOpen] = (0, useControllableState_1.useControllableState)({
        prop: openProp,
        defaultProp: false,
        onChange: onOpenChange,
    });
    return (react_1.default.createElement(PopoverContext.Provider, { value: { open, setOpen } },
        react_1.default.createElement(PopoverBase.Root, { open: open, onOpenChange: setOpen }, children)));
}
exports.Root = Root;
function Trigger({ children }) {
    return react_1.default.createElement(PopoverBase.Trigger, { asChild: true }, children);
}
exports.Trigger = Trigger;
function Anchor({ children }) {
    return react_1.default.createElement(PopoverBase.Anchor, { asChild: true }, children);
}
exports.Anchor = Anchor;
function Content(props) {
    const { open, setOpen } = (0, react_1.useContext)(PopoverContext);
    const { style, children, ...rest } = props;
    if (!open)
        return null;
    return (react_1.default.createElement(PopoverBase.Portal, null,
        react_1.default.createElement(PopoverBase.Content, { asChild: true, ...rest, onOpenAutoFocus: (e) => {
                e.preventDefault();
            }, onCloseAutoFocus: (e) => {
                e.preventDefault();
            }, style: {} },
            react_1.default.createElement(inlines_1.styled.div, { style: {
                    display: 'flex',
                    alignItems: 'center',
                    // justifyContent: 'center',
                    flexDirection: 'column',
                    boxShadow: '0px 8px 16px -2px rgba(27, 36, 44, 0.12), 0px 2px 2px -1px rgba(27, 35, 44, 0.04)',
                    backgroundColor: (0, varsUtilities_1.color)('background', 'default'),
                    border: `1px solid ${(0, varsUtilities_1.color)('border', 'default')}`,
                    borderRadius: 16,
                    maxHeight: '600px',
                    overflow: 'auto',
                    maxWidth: 'calc(var(--radix-dropdown-menu-content-available-width) - 16px)',
                    // maxHeight:
                    //   'calc(var(--radix-dropdown-menu-content-available-height) - 16px)',
                } }, typeof children === 'function'
                ? children({
                    open,
                    close: () => {
                        setOpen(false);
                    },
                })
                : children))));
}
exports.Content = Content;
//# sourceMappingURL=index.js.map