"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.Toast = void 0;
const react_1 = __importStar(require("react"));
const useToast_1 = require("./useToast");
const varsUtilities_1 = require("../../varsUtilities");
const components_1 = require("../../components");
const inlines_1 = require("inlines");
const icons_1 = require("../../icons");
const Toast = ({ label, action, closeable, color = 'default', style, strong, id, ...props }) => {
    const { remove } = (0, useToast_1.useToast)();
    const [closeState, setCloseState] = (0, react_1.useState)(false);
    const closeFunc = () => {
        setCloseState(true);
        setTimeout(() => remove(id), 200);
    };
    (0, react_1.useEffect)(() => {
        const timeout = setTimeout(() => {
            if (!closeable)
                closeFunc();
        }, 5e3);
        return () => clearTimeout(timeout);
    });
    return (react_1.default.createElement(inlines_1.styled.div, { onClick: closeable ? () => null : () => remove(id), style: {
            borderRadius: 8,
            backgroundColor: (0, varsUtilities_1.color)(strong ? 'background' : 'standalone', strong ? color : 'modal', strong ? 'strong' : 'default'),
            boxShadow: 'rgb(0 0 0 / 12%) 0px 8px 20px',
            cursor: 'pointer',
            padding: '0px 16px',
            height: '48px',
            // width: '400px',
            opacity: closeState ? 0 : 1,
            transition: 'all 0.2s',
            display: 'flex',
            alignItems: 'center',
            '@keyframes': {
                '0%': { transform: 'translateY(200px)', opacity: 0 },
                '50%': { transform: 'translateY(200px)', opacity: 0 },
                '100%': { transform: 'translateY(0px)', opacity: 1 },
            },
            animationDuration: '0.5s',
            animationEffect: 'ease-in',
            ...style,
        }, ...props },
        color === 'negative' ? (react_1.default.createElement(icons_1.IconErrorFill, { color: strong ? 'inverted' : 'negative' })) : color === 'warning' ? (react_1.default.createElement(icons_1.IconWarningFill, { color: strong ? 'default' : 'warning' })) : color === 'positive' ? (react_1.default.createElement(icons_1.IconCheckCircleFill, { color: strong ? 'inverted' : 'positive' })) : color === 'informative' ? (react_1.default.createElement(icons_1.IconInfoFill, { color: strong ? 'inverted' : 'informative' })) : null,
        react_1.default.createElement(components_1.Text, { selectable: "none", style: { marginLeft: '16px' }, color: (strong && color === 'warning') || color === 'default'
                ? 'default'
                : strong
                    ? 'inverted'
                    : 'default' }, label),
        action && (react_1.default.createElement(components_1.Button, { style: {
                marginLeft: '16px',
                '& div div': {
                    color: (!strong && color === 'neutral') ||
                        (!strong && color === 'inverted')
                        ? `${(0, varsUtilities_1.color)('background', 'informative', 'strong')} !important`
                        : 'inherit',
                },
            }, size: "xsmall", underline: true, color: (strong && color === 'warning') || color === 'default'
                ? 'system'
                : strong
                    ? 'inverted'
                    : 'primary', onClick: action.onClick }, action.label)),
        closeable && (react_1.default.createElement(icons_1.IconClose, { onClick: closeFunc, style: { marginLeft: '21px' }, color: strong && color === 'default'
                ? 'default'
                : strong && color === 'warning'
                    ? 'default'
                    : strong
                        ? 'inverted'
                        : 'default' }))));
};
exports.Toast = Toast;
//# sourceMappingURL=Toast.js.map