import React, { forwardRef } from "react";
import toast, { Toaster, resolveValue } from "react-hot-toast";
import { tokens } from "../Toast.tokens";
import { IconCrossThin } from "../../_Icon/Icons/IconCrossThin";
import { base, Toast, CloseIconWrapper, StyledContentLeft } from "./ToastNew.styles";
export const toastContainerRoot = (Root)=>/*#__PURE__*/ forwardRef((props, ref)=>{
        const { hasClose = true, view, size, pilled, contentLeft, width, textColor, position = 'bottom-center', duration = Infinity, onCloseButtonClick, ...rest } = props;
        return /*#__PURE__*/ React.createElement(Root, {
            ref: ref,
            view: view,
            size: size,
            pilled: pilled,
            ...rest
        }, /*#__PURE__*/ React.createElement(Toaster, {
            toastOptions: {
                duration,
                position
            }
        }, (options)=>{
            return /*#__PURE__*/ React.createElement(Root, {
                view: options.plasmaOptions?.view,
                size: options.plasmaOptions?.size,
                pilled: options.plasmaOptions?.pilled
            }, /*#__PURE__*/ React.createElement(Toast, {
                style: {
                    opacity: options.visible ? 1 : 0
                },
                width: options.plasmaOptions?.width || width,
                textColor: options.plasmaOptions?.textColor || textColor
            }, (options.plasmaOptions?.contentLeft || contentLeft) && /*#__PURE__*/ React.createElement(StyledContentLeft, null, options.plasmaOptions?.contentLeft || contentLeft), resolveValue(options.message, options), (options.plasmaOptions?.hasClose || (options.plasmaOptions?.hasClose ?? hasClose)) && /*#__PURE__*/ React.createElement(CloseIconWrapper, {
                view: "clear",
                size: "s",
                stretching: "fixed",
                onClick: ()=>{
                    if (onCloseButtonClick) {
                        onCloseButtonClick();
                    }
                    toast.dismiss(options.id);
                }
            }, /*#__PURE__*/ React.createElement(IconCrossThin, {
                size: "s",
                color: "inherit",
                sizeCustomProperty: tokens.closeIconSize
            }))));
        }));
    });
export const showToast = (text, options)=>{
    toast(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
        }
    });
};
export const toastContainerConfig = {
    name: 'ToastContainer',
    tag: 'div',
    layout: toastContainerRoot,
    base,
    variations: {
        view: {
            css: ''
        },
        size: {
            css: ''
        },
        pilled: {
            css: '',
            attrs: true
        }
    },
    defaults: {
        view: 'default',
        size: 'm'
    }
};
