"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get showToast () {
        return showToast;
    },
    get toastContainerConfig () {
        return toastContainerConfig;
    },
    get toastContainerRoot () {
        return toastContainerRoot;
    }
});
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _reacthottoast = /*#__PURE__*/ _interop_require_wildcard(require("react-hot-toast"));
const _Toasttokens = require("../Toast.tokens");
const _IconCrossThin = require("../../_Icon/Icons/IconCrossThin");
const _ToastNewstyles = require("./ToastNew.styles");
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
const toastContainerRoot = (Root)=>/*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
        const { hasClose = true, view, size, pilled, contentLeft, width, textColor, position = 'bottom-center', duration = Infinity, onCloseButtonClick, ...rest } = props;
        return /*#__PURE__*/ _react.default.createElement(Root, {
            ref: ref,
            view: view,
            size: size,
            pilled: pilled,
            ...rest
        }, /*#__PURE__*/ _react.default.createElement(_reacthottoast.Toaster, {
            toastOptions: {
                duration,
                position
            }
        }, (options)=>{
            return /*#__PURE__*/ _react.default.createElement(Root, {
                view: options.plasmaOptions?.view,
                size: options.plasmaOptions?.size,
                pilled: options.plasmaOptions?.pilled
            }, /*#__PURE__*/ _react.default.createElement(_ToastNewstyles.Toast, {
                style: {
                    opacity: options.visible ? 1 : 0
                },
                width: options.plasmaOptions?.width || width,
                textColor: options.plasmaOptions?.textColor || textColor
            }, (options.plasmaOptions?.contentLeft || contentLeft) && /*#__PURE__*/ _react.default.createElement(_ToastNewstyles.StyledContentLeft, null, options.plasmaOptions?.contentLeft || contentLeft), (0, _reacthottoast.resolveValue)(options.message, options), (options.plasmaOptions?.hasClose || (options.plasmaOptions?.hasClose ?? hasClose)) && /*#__PURE__*/ _react.default.createElement(_ToastNewstyles.CloseIconWrapper, {
                view: "clear",
                size: "s",
                stretching: "fixed",
                onClick: ()=>{
                    if (onCloseButtonClick) {
                        onCloseButtonClick();
                    }
                    _reacthottoast.default.dismiss(options.id);
                }
            }, /*#__PURE__*/ _react.default.createElement(_IconCrossThin.IconCrossThin, {
                size: "s",
                color: "inherit",
                sizeCustomProperty: _Toasttokens.tokens.closeIconSize
            }))));
        }));
    });
const showToast = (text, options)=>{
    (0, _reacthottoast.default)(text, {
        // INFO: id всегда одинаковый для отключения стекирования
        id: 'toast',
        ...options?.position ? {
            position: options?.position
        } : undefined,
        ...options?.duration ? {
            duration: options?.duration
        } : undefined,
        // @ts-ignore
        plasmaOptions: {
            view: options?.view,
            size: options?.size,
            pilled: options?.pilled,
            contentLeft: options?.contentLeft,
            hasClose: options?.hasClose,
            width: options?.width,
            textColor: options?.textColor
        }
    });
};
const toastContainerConfig = {
    name: 'ToastContainer',
    tag: 'div',
    layout: toastContainerRoot,
    base: _ToastNewstyles.base,
    variations: {
        view: {
            css: ''
        },
        size: {
            css: ''
        },
        pilled: {
            css: '',
            attrs: true
        }
    },
    defaults: {
        view: 'default',
        size: 'm'
    }
};
