"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.Confirmation = exports.Actions = exports.Body = exports.Description = exports.Title = exports.Warning = exports.Content = exports.Trigger = exports.Root = exports.useModal = 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 Button_1 = require("../Button");
const icons_1 = require("../../icons");
const useControllableState_1 = require("../../hooks/useControllableState");
const ModalContext = (0, react_1.createContext)({
    open: false,
    setOpen: () => { },
});
const useModal = () => {
    return (0, react_1.useContext)(ModalContext);
};
exports.useModal = useModal;
function Root({ children, open: openProp, onOpenChange, }) {
    const [open, setOpen] = (0, useControllableState_1.useControllableState)({
        prop: openProp,
        defaultProp: false,
        onChange: onOpenChange,
    });
    return (react_1.default.createElement(ModalContext.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 = 552, style, onEscapeKeyDown, onPointerDownOutside, }) {
    const { open, setOpen } = (0, react_1.useContext)(ModalContext);
    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'),
                display: 'grid',
                placeItems: 'center',
            } },
            react_1.default.createElement(DialogBase.Content, { onPointerDownOutside: onPointerDownOutside, onEscapeKeyDown: onEscapeKeyDown, onOpenAutoFocus: (e) => {
                    e.preventDefault();
                }, onCloseAutoFocus: (e) => {
                    e.preventDefault();
                } },
                react_1.default.createElement(inlines_1.styled.div, { style: {
                        width: '90vw',
                        maxWidth: width,
                        height: 'auto',
                        maxHeight: '70vh',
                        background: (0, varsUtilities_1.color)('standalone', 'modal', 'default'),
                        borderRadius: 8,
                        boxShadow: '0px 16px 24px -6px rgba(27, 36, 44, 0.16), 0px 2px 2px -1px rgba(27, 36, 44, 0.04)',
                        padding: '24px 32px 0',
                        overflowY: 'auto',
                        overflowX: 'hidden',
                        ...style,
                    } }, typeof children === 'function'
                    ? children({
                        open,
                        close: () => {
                            setOpen(false);
                        },
                    })
                    : children)))));
}
exports.Content = Content;
const Warning = ({ type = 'warning', children, style, }) => {
    const genColor = type === 'warning'
        ? 'warning'
        : type === 'info'
            ? 'informative'
            : '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 }) {
    return (react_1.default.createElement(DialogBase.Title, { asChild: true },
        react_1.default.createElement(inlines_1.styled.div, { style: {
                fontWeight: 700,
                fontFamily: 'Inter',
                fontSize: 18,
                lineHeight: '32px',
                color: (0, varsUtilities_1.color)('content', 'default', 'primary'),
            } }, children)));
}
exports.Title = Title;
function Description({ children }) {
    return (react_1.default.createElement(DialogBase.Description, { asChild: true },
        react_1.default.createElement("div", { style: {
                fontWeight: 500,
                fontFamily: 'Inter',
                fontSize: 14,
                lineHeight: '24px',
                color: (0, varsUtilities_1.color)('content', 'default', 'secondary'),
                marginTop: 16,
            } }, children)));
}
exports.Description = Description;
function Body({ children }) {
    return (react_1.default.createElement(inlines_1.styled.div, { style: {
            padding: '24px 0 40px',
            display: 'flex',
            flexDirection: 'column',
            gap: 24,
        } }, children));
}
exports.Body = Body;
function Actions({ children }) {
    return (react_1.default.createElement(inlines_1.styled.div, { style: {
            position: 'sticky',
            bottom: 0,
            overflow: 'hidden',
            background: (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;
function Confirmation({ title, description, label, type = 'info', action, }) {
    return (react_1.default.createElement(Content, null, ({ close }) => (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(Title, null, title),
        react_1.default.createElement(Body, null,
            react_1.default.createElement(Text_1.Text, null, description),
            react_1.default.createElement(exports.Warning, { type: type }, label)),
        react_1.default.createElement(Actions, null,
            react_1.default.createElement(Button_1.Button, { onClick: close, color: "system" }, "Cancel"),
            react_1.default.createElement(Button_1.Button, { onClick: (e) => {
                    action.action(e);
                    close();
                }, color: type === 'alert' ? 'alert' : 'primary' }, action.label))))));
}
exports.Confirmation = Confirmation;
//# sourceMappingURL=index.js.map