"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.Actions = exports.Body = exports.Title = exports.Warning = exports.Content = exports.Trigger = exports.Root = void 0;
const react_1 = __importStar(require("react"));
const DialogBase = __importStar(require("@radix-ui/react-dialog"));
const inlines_1 = require("inlines");
const varsUtilities_1 = require("../../varsUtilities");
const Text_1 = require("../Text");
const icons_1 = require("../../icons");
const ScrollArea_1 = require("../ScrollArea");
const useControllableState_1 = require("../../hooks/useControllableState");
const Button_1 = require("../Button");
const utils_1 = require("../../utils");
const SidePanelContext = (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(SidePanelContext.Provider, { value: { open, setOpen } },
        react_1.default.createElement(DialogBase.Root, { open: open, onOpenChange: setOpen }, children)));
}
exports.Root = Root;
function Trigger({ children }) {
    return react_1.default.createElement(DialogBase.Trigger, { asChild: true }, children);
}
exports.Trigger = Trigger;
function Content({ children, width = '55%', position = 'right', }) {
    const { open, setOpen } = (0, react_1.useContext)(SidePanelContext);
    if (!open)
        return null;
    return (react_1.default.createElement(DialogBase.Portal, null,
        react_1.default.createElement(DialogBase.Overlay, { style: {
                inset: 0,
                position: 'fixed',
                background: (0, varsUtilities_1.color)('standalone', 'dimmer', 'default'),
                opacity: open ? 1 : 0,
                transition: '0.2s all',
            } }),
        react_1.default.createElement(DialogBase.Content, { onOpenAutoFocus: (e) => {
                e.preventDefault();
            }, onCloseAutoFocus: (e) => {
                e.preventDefault();
            } },
            react_1.default.createElement(inlines_1.styled.div, { style: {
                    position: 'fixed',
                    inset: 0,
                    display: 'flex',
                    padding: 24,
                    [utils_1.BpMobile]: {
                        padding: 16,
                    },
                } },
                react_1.default.createElement(inlines_1.styled.div, { style: {
                        marginRight: position === 'right' ? '0px' : 'auto',
                        marginLeft: position === 'right' ? 'auto' : '0px',
                        height: '100%',
                        position: 'relative',
                        width: '90vw',
                        maxWidth: width,
                        overflow: 'hidden',
                        [utils_1.BpTablet]: {
                            maxWidth: '100%',
                        },
                        background: (0, varsUtilities_1.color)('standalone', 'modal', 'default'),
                        borderRadius: 12,
                    } }, typeof children === 'function'
                    ? children({
                        open,
                        close: () => {
                            setOpen(false);
                        },
                    })
                    : children)))));
}
exports.Content = Content;
const Warning = ({ type = 'warning', children, style, }) => {
    const genColor = type === 'warning' ? 'warning' : 'negative';
    return (react_1.default.createElement(inlines_1.styled.div, { style: {
            height: '24px',
            padding: '12px 16px',
            display: 'flex',
            alignItems: 'center',
            gap: 8,
            borderRadius: '4px',
            backgroundColor: (0, varsUtilities_1.color)('background', genColor, 'subtle'),
            ...style,
        } },
        react_1.default.createElement(icons_1.IconAlertFill, { color: genColor }),
        react_1.default.createElement(Text_1.Text, null, children)));
};
exports.Warning = Warning;
function Title({ children, closeFunc }) {
    const theContext = (0, react_1.useContext)(SidePanelContext);
    return (react_1.default.createElement(DialogBase.Title, { asChild: true, style: {} },
        react_1.default.createElement(inlines_1.styled.div, { style: {
                display: 'flex',
                padding: '24px 32px',
                borderBottom: `1px solid ${(0, varsUtilities_1.color)('border', 'default', 'strong')}`,
                justifyContent: 'space-between',
                alignItems: 'center',
            } },
            react_1.default.createElement(Text_1.Text, { weight: "strong", size: 18, style: {
                    lineHeight: '32px',
                } }, children),
            react_1.default.createElement(Button_1.Button, { icon: react_1.default.createElement(icons_1.IconClose, null), style: { borderRadius: '50%' }, light: true, keyboardShortcut: "Esc", hideFocusState: true, onClick: () => {
                    theContext.setOpen(false);
                    closeFunc?.();
                } }))));
}
exports.Title = Title;
function Body({ children }) {
    return (react_1.default.createElement(inlines_1.styled.div, { style: {
            // height: '-webkit-fill-available',
            height: '100%',
            padding: '24px 24px 24px',
            paddingBottom: '200px',
            display: 'flex',
            flexDirection: 'column',
            overflowY: 'auto',
            gap: 24,
            ...ScrollArea_1.scrollAreaStyle,
        } }, children));
}
exports.Body = Body;
function Actions({ children, transparent = false, }) {
    return (react_1.default.createElement(inlines_1.styled.div, { style: {
            // position: 'sticky',
            pointerEvents: 'none',
            // bottom: 0,
            left: 0,
            right: 0,
            // padding: 24,
            // background: color('standalone', 'modal', 'default'),
            // display: 'flex',
            // justifyContent: 'end',
            // alignItems: 'center',
            // '& > * + *': {
            //   marginLeft: '24px',
            // },
            // // padding: '24px 32px 32px',
            // // margin: '0 -32px',
            // borderTop: `1px solid ${color('border', 'default', 'strong')}`,
            position: 'sticky',
            top: 'auto',
            bottom: 0,
            overflow: 'hidden',
            background: transparent
                ? null
                : (0, varsUtilities_1.color)('standalone', 'modal', 'default'),
            display: 'flex',
            justifyContent: 'end',
            alignItems: 'center',
            '& > * + *': {
                marginLeft: '24px',
            },
            padding: '24px 32px 32px',
            // margin: '0 -32px',
            borderTop: `1px solid ${(0, varsUtilities_1.color)('border', 'default', 'strong')}`,
        } }, children));
}
exports.Actions = Actions;
//# sourceMappingURL=index.js.map