function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys, key, i;
    if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
        sourceKeys = Reflect.ownKeys(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
        return target;
    }
    target = _object_without_properties_loose(source, excluded);
    if (Object.getOwnPropertySymbols) {
        sourceKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
    }
    return target;
}
function _object_without_properties_loose(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
        target[key] = source[key];
    }
    return target;
}
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 var toastRoot = function toastRoot(Root) {
    return /*#__PURE__*/ forwardRef(function(props, ref) {
        var _props_role = props.role, role = _props_role === void 0 ? 'status' : _props_role, width = props.width, text = props.text, hasClose = props.hasClose, contentLeft = props.contentLeft, view = props.view, size = props.size, pilled = props.pilled, className = props.className, style = props.style, closeIconType = props.closeIconType, onCloseButtonClick = props.onCloseButtonClick, textColor = props.textColor, rest = _object_without_properties(props, [
            "role",
            "width",
            "text",
            "hasClose",
            "contentLeft",
            "view",
            "size",
            "pilled",
            "className",
            "style",
            "closeIconType",
            "onCloseButtonClick",
            "textColor"
        ]);
        var pilledClass = pilled ? classes.toastPilled : undefined;
        var fixedWidth = !Number.isNaN(Number(width)) ? "".concat(width, "%") : width;
        var ariaLive = 'polite';
        var ariaAtomic = false;
        if (role === 'alert') {
            ariaLive = 'assertive';
        } else if (role === 'status') {
            ariaAtomic = true;
        }
        return /*#__PURE__*/ React.createElement(Root, _object_spread({
            view: view,
            size: size,
            pilled: pilled,
            closeIconType: closeIconType,
            className: cx(pilledClass, className),
            style: _object_spread({
                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 var toastConfig = {
    name: 'Toast',
    tag: 'div',
    layout: toastRoot,
    base: base,
    variations: {
        view: {
            css: viewCSS
        },
        size: {
            css: sizeCSS
        },
        pilled: {
            css: pilledCSS,
            attrs: true
        },
        closeIconType: {
            css: closeIconTypeCSS
        }
    },
    defaults: {
        view: 'primary',
        size: 'm',
        closeIconType: 'default'
    }
};
