'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var index = require('../../utils/index.js');
var IconCross = require('../_Icon/Icons/IconCross.js');
var IconCrossThin = require('../_Icon/Icons/IconCrossThin.js');
var Notification_tokens = require('./Notification.tokens.js');
var base$1 = require('./variations/_view/base.js');
var base = require('./variations/_layout/base.js');
var base$2 = require('./variations/_size/base.js');
var base$3 = require('./variations/_closeIconType/base.js');
var Notification_types = require('./Notification.types.js');
var Notification_styles = require('./Notification.styles.js');
var index$1 = require('./utils/index.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var _excluded = ["role", "title", "children", "actions", "view", "size", "iconPlacement", "layout", "icon", "showCloseIcon", "closeIconType", "customCloseIcon", "textColor", "titleColor", "backgroundColor", "width", "maxWidth", "onCloseButtonClick"];

/**
 * Компонент для небольших уведомлений пользователя
 */
var notificationRoot = function notificationRoot(Root) {
  return /*#__PURE__*/React.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 ? Notification_types.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 = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);
    var ariaLive = 'polite';
    var ariaAtomic = false;
    if (role === 'alert') {
      ariaLive = 'assertive';
    } else if (role === 'status') {
      ariaAtomic = true;
    }
    var isOneLine = !content || !title;
    var oneLineClass = isOneLine ? Notification_tokens.classes.oneLine : undefined;
    var withoutIconClass = icon ? undefined : Notification_tokens.classes.withoutIcon;
    var withoutCloseIconClass = showCloseIcon ? undefined : Notification_tokens.classes.withoutCloseIcon;
    var IconPlacementInternal = React.useMemo(function () {
      return icon ? iconPlacement : undefined;
    }, [icon, iconPlacement]);
    return /*#__PURE__*/React__default.default.createElement(Root, _rollupPluginBabelHelpers.extends({
      view: view,
      size: size,
      layout: layout,
      closeIconType: closeIconType,
      ref: ref,
      role: role,
      "aria-live": ariaLive,
      "aria-atomic": ariaAtomic
    }, rest), /*#__PURE__*/React__default.default.createElement(Notification_styles.Wrapper, {
      backgroundColor: backgroundColor,
      width: width,
      maxWidth: maxWidth,
      className: index.cx(Notification_tokens.classes.wrapper, index$1.getLayoutClass(layout), oneLineClass, withoutCloseIconClass)
    }, /*#__PURE__*/React__default.default.createElement(Notification_styles.ContentBox, {
      iconPlacement: IconPlacementInternal,
      className: index.cx(Notification_tokens.classes.contentBox, index$1.getLayoutClass(layout), withoutIconClass)
    }, icon && /*#__PURE__*/React__default.default.createElement(Notification_styles.IconWrapper, {
      iconPlacement: IconPlacementInternal,
      className: index.cx(Notification_tokens.classes.icon, index$1.getLayoutClass(layout))
    }, icon), /*#__PURE__*/React__default.default.createElement(Notification_styles.TextBox, {
      iconPlacement: IconPlacementInternal,
      showCloseIcon: showCloseIcon,
      className: index.cx(Notification_tokens.classes.textbox, index$1.getLayoutClass(layout))
    }, title && /*#__PURE__*/React__default.default.createElement(Notification_styles.StyledTitle, {
      className: Notification_tokens.classes.title,
      textColor: titleColor
    }, title), content && /*#__PURE__*/React__default.default.createElement(Notification_styles.StyledContent, {
      className: Notification_tokens.classes.text,
      textColor: textColor
    }, content))), actions && /*#__PURE__*/React__default.default.createElement(Notification_styles.ButtonsWrapper, {
      iconPlacement: IconPlacementInternal,
      className: index.cx(Notification_tokens.classes.buttonsWrapper, index$1.getLayoutClass(layout))
    }, actions), showCloseIcon && /*#__PURE__*/React__default.default.createElement(Notification_styles.CloseIconWrapper, {
      view: "clear",
      size: "s",
      onClick: onCloseButtonClick,
      className: index.cx(Notification_tokens.classes.closeIcon, index$1.getLayoutClass(layout))
    }, customCloseIcon || (closeIconType === 'default' ? /*#__PURE__*/React__default.default.createElement(IconCross.IconCross, {
      size: "s",
      sizeCustomProperty: Notification_tokens.tokens.closeIconSize,
      color: "inherit"
    }) : /*#__PURE__*/React__default.default.createElement(IconCrossThin.IconCrossThin, {
      size: "s",
      sizeCustomProperty: Notification_tokens.tokens.closeIconSize,
      color: "inherit"
    })))));
  });
};
var notificationConfig = {
  name: 'Notification',
  tag: 'div',
  layout: notificationRoot,
  base: Notification_styles.StyledNotification,
  variations: {
    layout: {
      css: base.base
    },
    view: {
      css: base$1.base
    },
    size: {
      css: base$2.base
    },
    closeIconType: {
      css: base$3.base
    }
  },
  defaults: {
    view: 'default',
    layout: Notification_types.layouts.vertical,
    size: 'xs',
    closeIconType: 'default'
  }
};

exports.notificationConfig = notificationConfig;
exports.notificationRoot = notificationRoot;
