import React, { forwardRef, useMemo } from "react";
import { cx } from "../../utils";
import { IconCross } from "../_Icon/Icons/IconCross";
import { IconCrossThin } from "../_Icon/Icons/IconCrossThin";
import { classes, tokens } from "./Notification.tokens";
import { base as viewCSS } from "./variations/_view/base";
import { base as layoutCSS } from "./variations/_layout/base";
import { base as sizeCSS } from "./variations/_size/base";
import { base as closeIconTypeCSS } from "./variations/_closeIconType/base";
import { layouts } from "./Notification.types";
import { ButtonsWrapper, CloseIconWrapper, ContentBox, IconWrapper, StyledContent, StyledNotification, StyledTitle, TextBox, Wrapper } from "./Notification.styles";
import { getLayoutClass } from "./utils";
/**
 * Компонент для небольших уведомлений пользователя
 */ export const notificationRoot = (Root)=>/*#__PURE__*/ forwardRef((props, ref)=>{
        const { role = 'status', title, children: content, actions, view, size, iconPlacement, layout = layouts.vertical, icon, showCloseIcon = true, closeIconType, customCloseIcon, textColor, titleColor, backgroundColor, width, maxWidth, onCloseButtonClick, ...rest } = props;
        let ariaLive = 'polite';
        let ariaAtomic = false;
        if (role === 'alert') {
            ariaLive = 'assertive';
        } else if (role === 'status') {
            ariaAtomic = true;
        }
        const isOneLine = !content || !title;
        const oneLineClass = isOneLine ? classes.oneLine : undefined;
        const withoutIconClass = icon ? undefined : classes.withoutIcon;
        const withoutCloseIconClass = showCloseIcon ? undefined : classes.withoutCloseIcon;
        const IconPlacementInternal = useMemo(()=>icon ? iconPlacement : undefined, [
            icon,
            iconPlacement
        ]);
        return /*#__PURE__*/ React.createElement(Root, {
            view: view,
            size: size,
            layout: layout,
            closeIconType: closeIconType,
            ref: ref,
            role: role,
            "aria-live": ariaLive,
            "aria-atomic": ariaAtomic,
            ...rest
        }, /*#__PURE__*/ React.createElement(Wrapper, {
            backgroundColor: backgroundColor,
            width: width,
            maxWidth: maxWidth,
            className: cx(classes.wrapper, getLayoutClass(layout), oneLineClass, withoutCloseIconClass)
        }, /*#__PURE__*/ React.createElement(ContentBox, {
            iconPlacement: IconPlacementInternal,
            className: cx(classes.contentBox, getLayoutClass(layout), withoutIconClass)
        }, icon && /*#__PURE__*/ React.createElement(IconWrapper, {
            iconPlacement: IconPlacementInternal,
            className: cx(classes.icon, getLayoutClass(layout))
        }, icon), /*#__PURE__*/ React.createElement(TextBox, {
            iconPlacement: IconPlacementInternal,
            showCloseIcon: showCloseIcon,
            className: cx(classes.textbox, getLayoutClass(layout))
        }, title && /*#__PURE__*/ React.createElement(StyledTitle, {
            className: classes.title,
            textColor: titleColor
        }, title), content && /*#__PURE__*/ React.createElement(StyledContent, {
            className: classes.text,
            textColor: textColor
        }, content))), actions && /*#__PURE__*/ React.createElement(ButtonsWrapper, {
            iconPlacement: IconPlacementInternal,
            className: cx(classes.buttonsWrapper, getLayoutClass(layout))
        }, actions), showCloseIcon && /*#__PURE__*/ React.createElement(CloseIconWrapper, {
            view: "clear",
            size: "s",
            onClick: onCloseButtonClick,
            className: cx(classes.closeIcon, getLayoutClass(layout))
        }, customCloseIcon || (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 notificationConfig = {
    name: 'Notification',
    tag: 'div',
    layout: notificationRoot,
    base: StyledNotification,
    variations: {
        layout: {
            css: layoutCSS
        },
        view: {
            css: viewCSS
        },
        size: {
            css: sizeCSS
        },
        closeIconType: {
            css: closeIconTypeCSS
        }
    },
    defaults: {
        view: 'default',
        layout: layouts.vertical,
        size: 'xs',
        closeIconType: 'default'
    }
};
