'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 Toast_tokens = require('./Toast.tokens.js');
var base = require('./variations/_view/base.js');
var base$1 = require('./variations/_size/base.js');
var base$2 = require('./variations/_pilled/base.js');
var base$3 = require('./variations/_closeIconType/base.js');
var Toast_styles = require('./Toast.styles.js');

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

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

var _excluded = ["role", "width", "text", "hasClose", "contentLeft", "view", "size", "pilled", "className", "style", "closeIconType", "onCloseButtonClick", "textColor"];

// TODO https://github.com/salute-developers/plasma/issues/1015
var toastRoot = function toastRoot(Root) {
  return /*#__PURE__*/React.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 = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);
    var pilledClass = pilled ? Toast_tokens.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__default.default.createElement(Root, _rollupPluginBabelHelpers.extends({
      view: view,
      size: size,
      pilled: pilled,
      closeIconType: closeIconType,
      className: index.cx(pilledClass, className),
      style: _rollupPluginBabelHelpers.objectSpread2({
        width: width ? fixedWidth : 'unset'
      }, style),
      ref: ref,
      role: role,
      "aria-live": ariaLive,
      "aria-atomic": ariaAtomic
    }, rest), contentLeft && /*#__PURE__*/React__default.default.createElement(Toast_styles.StyledContentLeft, null, contentLeft), /*#__PURE__*/React__default.default.createElement(Toast_styles.StyledContent, {
      textColor: textColor
    }, text), hasClose && /*#__PURE__*/React__default.default.createElement(Toast_styles.CloseIconWrapper, {
      view: "clear",
      size: "s",
      onClick: onCloseButtonClick,
      className: index.cx(Toast_tokens.classes.closeIcon),
      stretching: "fixed"
    }, closeIconType === 'default' ? /*#__PURE__*/React__default.default.createElement(IconCross.IconCross, {
      size: "s",
      sizeCustomProperty: Toast_tokens.tokens.closeIconSize,
      color: "inherit"
    }) : /*#__PURE__*/React__default.default.createElement(IconCrossThin.IconCrossThin, {
      size: "s",
      sizeCustomProperty: Toast_tokens.tokens.closeIconSize,
      color: "inherit"
    })));
  });
};
var toastConfig = {
  name: 'Toast',
  tag: 'div',
  layout: toastRoot,
  base: Toast_styles.base,
  variations: {
    view: {
      css: base.base
    },
    size: {
      css: base$1.base
    },
    pilled: {
      css: base$2.base,
      attrs: true
    },
    closeIconType: {
      css: base$3.base
    }
  },
  defaults: {
    view: 'primary',
    size: 'm',
    closeIconType: 'default'
  }
};

exports.toastConfig = toastConfig;
exports.toastRoot = toastRoot;
