"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _Text = _interopRequireDefault(require("../Text"));
var _Toast = _interopRequireDefault(require("../Toast"));
var _useToastTimeout = require("./hooks/useToastTimeout");
var _StatusToastSt = require("./StatusToast.st.css.js");
var _ToastAction = _interopRequireDefault(require("./components/ToastAction/ToastAction"));
var _ToastLink = _interopRequireDefault(require("./components/ToastLink/ToastLink"));
var _WixDesignSystemIconThemeProvider = require("../WixDesignSystemIconThemeProvider");
var _excluded = ["status", "action", "children", "className", "duration"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/StatusToast/StatusToast.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var DEFAULT_STATUS = 'info';
var SUCCESS_AUTO_DISMISS_DELAY = 7000;
var roleByStatus = {
  success: 'status',
  error: 'alert',
  warning: 'alert',
  info: 'status'
};
var StatusToast = /*#__PURE__*/(0, _react.memo)(_ref => {
  var _iconByStatus$status;
  var {
      status = DEFAULT_STATUS,
      action,
      children,
      className,
      duration
    } = _ref,
    rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var icons = (0, _WixDesignSystemIconThemeProvider.useIcons)('StatusToast', {
    StatusCompleteFilled: _wixUiIconsCommon.StatusCompleteFilled,
    StatusAlertFilled: _wixUiIconsCommon.StatusAlertFilled,
    StatusWarningFilled: _wixUiIconsCommon.StatusWarningFilled,
    InfoCircleFilled: _wixUiIconsCommon.InfoCircleFilled
  });
  var iconByStatus = {
    success: /*#__PURE__*/_react.default.createElement(icons.StatusCompleteFilled, {
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 48,
        columnNumber: 16
      }
    }),
    error: /*#__PURE__*/_react.default.createElement(icons.StatusAlertFilled, {
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 49,
        columnNumber: 14
      }
    }),
    warning: /*#__PURE__*/_react.default.createElement(icons.StatusWarningFilled, {
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 50,
        columnNumber: 16
      }
    }),
    info: /*#__PURE__*/_react.default.createElement(icons.InfoCircleFilled, {
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 51,
        columnNumber: 13
      }
    })
  };
  var autoDismissEnabled = duration !== null;
  var defaultAutoDismissDuration = ['info', 'success'].includes(status) ? SUCCESS_AUTO_DISMISS_DELAY : undefined;
  (0, _useToastTimeout.useToastTimeout)(autoDismissEnabled ? duration !== null && duration !== void 0 ? duration : defaultAutoDismissDuration : undefined, rest.onDismiss);
  return /*#__PURE__*/_react.default.createElement(_Toast.default, (0, _extends2.default)({
    role: roleByStatus[status],
    className: (0, _StatusToastSt.st)(_StatusToastSt.classes.toast, className)
  }, rest, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 65,
      columnNumber: 7
    }
  }), /*#__PURE__*/_react.default.createElement("div", {
    "data-hook": "status-toast-root",
    className: (0, _StatusToastSt.st)(_StatusToastSt.classes.root, {
      success: status === 'success',
      error: status === 'error',
      warning: status === 'warning'
    }),
    "data-status": status,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 70,
      columnNumber: 9
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _StatusToastSt.classes.content,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 79,
      columnNumber: 11
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _StatusToastSt.classes.icon,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 80,
      columnNumber: 13
    }
  }, (_iconByStatus$status = iconByStatus[status]) !== null && _iconByStatus$status !== void 0 ? _iconByStatus$status : iconByStatus[DEFAULT_STATUS]), /*#__PURE__*/_react.default.createElement(_Text.default, {
    light: true,
    size: "medium",
    dataHook: "status-toast-content",
    className: _StatusToastSt.classes.text,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 83,
      columnNumber: 13
    }
  }, children)), action && /*#__PURE__*/_react.default.createElement("div", {
    className: _StatusToastSt.classes.action,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 92,
      columnNumber: 22
    }
  }, action)));
});
StatusToast.displayName = 'StatusToast';
StatusToast.Action = _ToastAction.default;
StatusToast.Link = _ToastLink.default;
var _default = exports.default = StatusToast;
//# sourceMappingURL=StatusToast.js.map