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, 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 var notificationRoot = function notificationRoot(Root) {
    return /*#__PURE__*/ forwardRef(function(props, ref) {
        var _props_role = props.role, role = _props_role === void 0 ? 'status' : _props_role, title = props.title, content = props.children, actions = props.actions, view = props.view, size = props.size, iconPlacement = props.iconPlacement, _props_layout = props.layout, layout = _props_layout === void 0 ? layouts.vertical : _props_layout, icon = props.icon, _props_showCloseIcon = props.showCloseIcon, showCloseIcon = _props_showCloseIcon === void 0 ? true : _props_showCloseIcon, closeIconType = props.closeIconType, customCloseIcon = props.customCloseIcon, textColor = props.textColor, titleColor = props.titleColor, backgroundColor = props.backgroundColor, width = props.width, maxWidth = props.maxWidth, onCloseButtonClick = props.onCloseButtonClick, rest = _object_without_properties(props, [
            "role",
            "title",
            "children",
            "actions",
            "view",
            "size",
            "iconPlacement",
            "layout",
            "icon",
            "showCloseIcon",
            "closeIconType",
            "customCloseIcon",
            "textColor",
            "titleColor",
            "backgroundColor",
            "width",
            "maxWidth",
            "onCloseButtonClick"
        ]);
        var ariaLive = 'polite';
        var ariaAtomic = false;
        if (role === 'alert') {
            ariaLive = 'assertive';
        } else if (role === 'status') {
            ariaAtomic = true;
        }
        var isOneLine = !content || !title;
        var oneLineClass = isOneLine ? classes.oneLine : undefined;
        var withoutIconClass = icon ? undefined : classes.withoutIcon;
        var withoutCloseIconClass = showCloseIcon ? undefined : classes.withoutCloseIcon;
        var IconPlacementInternal = useMemo(function() {
            return icon ? iconPlacement : undefined;
        }, [
            icon,
            iconPlacement
        ]);
        return /*#__PURE__*/ React.createElement(Root, _object_spread({
            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 var 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'
    }
};
