'use strict';

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

var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var toast = require('react-hot-toast');
var Toast_tokens = require('../Toast.tokens.js');
var IconCrossThin = require('../../_Icon/Icons/IconCrossThin.js');
var ToastNew_styles = require('./ToastNew.styles.js');

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

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

var _excluded = ["hasClose", "view", "size", "pilled", "contentLeft", "width", "textColor", "position", "duration", "onCloseButtonClick"];
var toastContainerRoot = function toastContainerRoot(Root) {
  return /*#__PURE__*/React.forwardRef(function (props, ref) {
    var _props$hasClose = props.hasClose,
      hasClose = _props$hasClose === void 0 ? true : _props$hasClose,
      view = props.view,
      size = props.size,
      pilled = props.pilled,
      contentLeft = props.contentLeft,
      width = props.width,
      textColor = props.textColor,
      _props$position = props.position,
      position = _props$position === void 0 ? 'bottom-center' : _props$position,
      _props$duration = props.duration,
      duration = _props$duration === void 0 ? Infinity : _props$duration,
      onCloseButtonClick = props.onCloseButtonClick,
      rest = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);
    return /*#__PURE__*/React__default.default.createElement(Root, _rollupPluginBabelHelpers.extends({
      ref: ref,
      view: view,
      size: size,
      pilled: pilled
    }, rest), /*#__PURE__*/React__default.default.createElement(toast.Toaster, {
      toastOptions: {
        duration: duration,
        position: position
      }
    }, function (options) {
      var _options$plasmaOption, _options$plasmaOption2, _options$plasmaOption3, _options$plasmaOption4, _options$plasmaOption5, _options$plasmaOption6, _options$plasmaOption7, _options$plasmaOption8, _options$plasmaOption9, _options$plasmaOption0;
      return /*#__PURE__*/React__default.default.createElement(Root, {
        view: (_options$plasmaOption = options.plasmaOptions) === null || _options$plasmaOption === void 0 ? void 0 : _options$plasmaOption.view,
        size: (_options$plasmaOption2 = options.plasmaOptions) === null || _options$plasmaOption2 === void 0 ? void 0 : _options$plasmaOption2.size,
        pilled: (_options$plasmaOption3 = options.plasmaOptions) === null || _options$plasmaOption3 === void 0 ? void 0 : _options$plasmaOption3.pilled
      }, /*#__PURE__*/React__default.default.createElement(ToastNew_styles.Toast, {
        style: {
          opacity: options.visible ? 1 : 0
        },
        width: ((_options$plasmaOption4 = options.plasmaOptions) === null || _options$plasmaOption4 === void 0 ? void 0 : _options$plasmaOption4.width) || width,
        textColor: ((_options$plasmaOption5 = options.plasmaOptions) === null || _options$plasmaOption5 === void 0 ? void 0 : _options$plasmaOption5.textColor) || textColor
      }, (((_options$plasmaOption6 = options.plasmaOptions) === null || _options$plasmaOption6 === void 0 ? void 0 : _options$plasmaOption6.contentLeft) || contentLeft) && /*#__PURE__*/React__default.default.createElement(ToastNew_styles.StyledContentLeft, null, ((_options$plasmaOption7 = options.plasmaOptions) === null || _options$plasmaOption7 === void 0 ? void 0 : _options$plasmaOption7.contentLeft) || contentLeft), toast.resolveValue(options.message, options), (((_options$plasmaOption8 = options.plasmaOptions) === null || _options$plasmaOption8 === void 0 ? void 0 : _options$plasmaOption8.hasClose) || ((_options$plasmaOption9 = (_options$plasmaOption0 = options.plasmaOptions) === null || _options$plasmaOption0 === void 0 ? void 0 : _options$plasmaOption0.hasClose) !== null && _options$plasmaOption9 !== void 0 ? _options$plasmaOption9 : hasClose)) && /*#__PURE__*/React__default.default.createElement(ToastNew_styles.CloseIconWrapper, {
        view: "clear",
        size: "s",
        stretching: "fixed",
        onClick: function onClick() {
          if (onCloseButtonClick) {
            onCloseButtonClick();
          }
          toast__default.default.dismiss(options.id);
        }
      }, /*#__PURE__*/React__default.default.createElement(IconCrossThin.IconCrossThin, {
        size: "s",
        color: "inherit",
        sizeCustomProperty: Toast_tokens.tokens.closeIconSize
      }))));
    }));
  });
};
var showToast = function showToast(text, options) {
  toast__default.default(text, _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({
    // INFO: id всегда одинаковый для отключения стекирования
    id: 'toast'
  }, options !== null && options !== void 0 && options.position ? {
    position: options === null || options === void 0 ? void 0 : options.position
  } : undefined), options !== null && options !== void 0 && options.duration ? {
    duration: options === null || options === void 0 ? void 0 : options.duration
  } : undefined), {}, {
    // @ts-ignore
    plasmaOptions: {
      view: options === null || options === void 0 ? void 0 : options.view,
      size: options === null || options === void 0 ? void 0 : options.size,
      pilled: options === null || options === void 0 ? void 0 : options.pilled,
      contentLeft: options === null || options === void 0 ? void 0 : options.contentLeft,
      hasClose: options === null || options === void 0 ? void 0 : options.hasClose,
      width: options === null || options === void 0 ? void 0 : options.width,
      textColor: options === null || options === void 0 ? void 0 : options.textColor
    }
  }));
};
var toastContainerConfig = {
  name: 'ToastContainer',
  tag: 'div',
  layout: toastContainerRoot,
  base: ToastNew_styles.base,
  variations: {
    view: {
      css: ''
    },
    size: {
      css: ''
    },
    pilled: {
      css: '',
      attrs: true
    }
  },
  defaults: {
    view: 'default',
    size: 'm'
  }
};

exports.showToast = showToast;
exports.toastContainerConfig = toastContainerConfig;
exports.toastContainerRoot = toastContainerRoot;
