import React, { forwardRef } from "react";
import { cx } from "../../utils";
import { IconCross } from "../_Icon/Icons/IconCross";
import { IconCrossThin } from "../_Icon/Icons/IconCrossThin";
import { classes, tokens } from "./Toast.tokens";
import { base as viewCSS } from "./variations/_view/base";
import { base as sizeCSS } from "./variations/_size/base";
import { base as pilledCSS } from "./variations/_pilled/base";
import { base as closeIconTypeCSS } from "./variations/_closeIconType/base";
import { CloseIconWrapper, StyledContent, StyledContentLeft, base } from "./Toast.styles";
// TODO https://github.com/salute-developers/plasma/issues/1015
export const toastRoot = (Root)=>/*#__PURE__*/ forwardRef((props, ref)=>{
        const { role = 'status', width, text, hasClose, contentLeft, view, size, pilled, className, style, closeIconType, onCloseButtonClick, textColor, ...rest } = props;
        const pilledClass = pilled ? classes.toastPilled : undefined;
        const fixedWidth = !Number.isNaN(Number(width)) ? `${width}%` : width;
        let ariaLive = 'polite';
        let ariaAtomic = false;
        if (role === 'alert') {
            ariaLive = 'assertive';
        } else if (role === 'status') {
            ariaAtomic = true;
        }
        return /*#__PURE__*/ React.createElement(Root, {
            view: view,
            size: size,
            pilled: pilled,
            closeIconType: closeIconType,
            className: cx(pilledClass, className),
            style: {
                width: width ? fixedWidth : 'unset',
                ...style
            },
            ref: ref,
            role: role,
            "aria-live": ariaLive,
            "aria-atomic": ariaAtomic,
            ...rest
        }, contentLeft && /*#__PURE__*/ React.createElement(StyledContentLeft, null, contentLeft), /*#__PURE__*/ React.createElement(StyledContent, {
            textColor: textColor
        }, text), hasClose && /*#__PURE__*/ React.createElement(CloseIconWrapper, {
            view: "clear",
            size: "s",
            onClick: onCloseButtonClick,
            className: cx(classes.closeIcon),
            stretching: "fixed"
        }, closeIconType === 'default' ? /*#__PURE__*/ React.createElement(IconCross, {
            size: "s",
            sizeCustomProperty: tokens.closeIconSize,
            color: "inherit"
        }) : /*#__PURE__*/ React.createElement(IconCrossThin, {
            size: "s",
            sizeCustomProperty: tokens.closeIconSize,
            color: "inherit"
        })));
    });
export const toastConfig = {
    name: 'Toast',
    tag: 'div',
    layout: toastRoot,
    base,
    variations: {
        view: {
            css: viewCSS
        },
        size: {
            css: sizeCSS
        },
        pilled: {
            css: pilledCSS,
            attrs: true
        },
        closeIconType: {
            css: closeIconTypeCSS
        }
    },
    defaults: {
        view: 'primary',
        size: 'm',
        closeIconType: 'default'
    }
};
