"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.Prompt = exports.Alert = exports.Content = exports.Trigger = exports.Root = exports.usePromptAlert = 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 Input_1 = require("../Input");
const Button_1 = require("../Button");
const useControllableState_1 = require("../../hooks/useControllableState");
const PromptAlertContext = (0, react_1.createContext)({
    open: false,
    setOpen: () => { },
});
const usePromptAlert = () => {
    return (0, react_1.useContext)(PromptAlertContext);
};
exports.usePromptAlert = usePromptAlert;
function Root({ children, open: openProp, onOpenChange, }) {
    const [open, setOpen] = (0, useControllableState_1.useControllableState)({
        prop: openProp,
        defaultProp: false,
        onChange: onOpenChange,
    });
    return (react_1.default.createElement(PromptAlertContext.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 }) {
    const { open, setOpen } = (0, react_1.useContext)(PromptAlertContext);
    if (!open)
        return null;
    return (react_1.default.createElement(DialogBase.Portal, null,
        react_1.default.createElement(DialogBase.Overlay, { style: {
                inset: 0,
                position: 'fixed',
            } }),
        react_1.default.createElement(DialogBase.Content, { onPointerDownOutside: (e) => {
                e.preventDefault();
            }, 
            // onEscapeKeyDown={(e) => {
            //   e.preventDefault()
            // }}
            onOpenAutoFocus: (e) => {
                e.preventDefault();
            }, onCloseAutoFocus: (e) => {
                e.preventDefault();
            } },
            react_1.default.createElement(inlines_1.styled.div, { style: {
                    position: 'fixed',
                    top: '3%',
                    left: '50%',
                    transform: 'translate(-50%, 0%)',
                    width: '80%',
                    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',
                } }, typeof children === 'function'
                ? children({
                    open,
                    close: () => {
                        setOpen(false);
                    },
                })
                : children))));
}
exports.Content = Content;
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)));
}
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'),
            } }, children)));
}
function Body({ children }) {
    return (react_1.default.createElement(inlines_1.styled.div, { style: {
            padding: '24px 0 40px',
            display: 'flex',
            flexDirection: 'column',
            gap: 24,
        } }, children));
}
function Actions({ children }) {
    return (react_1.default.createElement(inlines_1.styled.div, { style: {
            position: 'sticky',
            background: (0, varsUtilities_1.color)('standalone', 'modal', 'default'),
            display: 'flex',
            justifyContent: 'end',
            alignItems: 'center',
            '& > * + *': {
                marginLeft: '24px',
            },
            padding: '24px 24px 24px',
            margin: '0 -32px',
            borderTop: `1px solid ${(0, varsUtilities_1.color)('border', 'default', 'strong')}`,
        } }, children));
}
function Alert({ title, description, 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(Description, null, description)),
        react_1.default.createElement(Actions, null,
            react_1.default.createElement(Button_1.Button, { onClick: (e) => {
                    action(e);
                    close();
                }, color: 'primary' }, "OK"))))));
}
exports.Alert = Alert;
function Prompt({ title, description, onChange }) {
    const [value, setValue] = (0, react_1.useState)('');
    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(Description, null, description),
            react_1.default.createElement(Input_1.Input, { type: "text", value: value, onChange: (e) => setValue(e) })),
        react_1.default.createElement(Actions, null,
            react_1.default.createElement(Button_1.Button, { onClick: () => {
                    setValue('');
                    close();
                }, color: "system" }, "Cancel"),
            react_1.default.createElement(Button_1.Button, { onClick: () => {
                    onChange(value);
                    setValue('');
                    close();
                } }, "OK"))))));
}
exports.Prompt = Prompt;
//# sourceMappingURL=index.js.map