"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.useToast = exports.ToastProvider = void 0;
const react_1 = __importStar(require("react"));
const react_dom_1 = require("react-dom");
const Toast_1 = require("./Toast");
const inlines_1 = require("inlines");
const ToastContainer = ({ toasts }) => {
    return (0, react_dom_1.createPortal)(react_1.default.createElement(inlines_1.styled.div, { style: {
            position: 'fixed',
            minWidth: toasts.length < 4 ? null : '194px',
            top: toasts.length >= 4 ? 24 : 'auto',
            bottom: toasts.length >= 4 ? null : 24,
            left: 'auto',
            right: 24,
            display: 'flex',
            flexDirection: 'column',
            gap: 12,
        } }, toasts.map(({ label, action, closeable, color, style, strong, id }) => (react_1.default.createElement(Toast_1.Toast, { key: id, id: id, label: label, action: action, closeable: closeable, color: color, strong: strong, style: toasts.length < 4
            ? style
            : { ...style, position: 'absolute', top: 0, left: 0 } })))), document.body);
};
const ToastContext = (0, react_1.createContext)(null);
let id = 0;
const ToastProvider = ({ children }) => {
    const [toasts, setToasts] = (0, react_1.useState)([]);
    const add = ({ label, action, closeable, color, style, strong, }) => {
        setToasts([
            ...toasts,
            {
                id: id++,
                label: label,
                action: action,
                closeable: closeable,
                color: color,
                style: style,
                strong: strong,
            },
        ]);
    };
    const remove = (id) => {
        setToasts((toasts) => toasts.filter((t) => t.id !== id));
    };
    const useCount = () => {
        return toasts.length;
    };
    return (react_1.default.createElement(ToastContext.Provider, { value: { add, remove, useCount } },
        react_1.default.createElement(ToastContainer, { toasts: toasts }),
        children));
};
exports.ToastProvider = ToastProvider;
const useToast = () => {
    const toast = (0, react_1.useContext)(ToastContext);
    return toast;
};
exports.useToast = useToast;
//# sourceMappingURL=useToast.js.map