"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Alert = void 0;

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

require("./Alert.css");

var _CloseIcon = _interopRequireDefault(require("mdi-react/CloseIcon"));

var _ramda = require("ramda");

var _IconSuccess = _interopRequireDefault(require("../IconSuccess"));

var _IconInfo = _interopRequireDefault(require("../IconInfo"));

var _IconWarning = _interopRequireDefault(require("../IconWarning"));

var _Button = require("../Button");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var concatAll = (0, _ramda.unapply)((0, _ramda.reduce)(_ramda.concat, []));

var makeAlert = function makeAlert() {
  return function (_ref) {
    var children = _ref.children,
        className = _ref.className,
        type = _ref.type,
        closeType = _ref.closeType,
        onClose = _ref.onClose,
        closeButtonText = _ref.closeButtonText,
        restProps = _objectWithoutProperties(_ref, ["children", "className", "type", "closeType", "onClose", "closeButtonText"]);

    var classes = concatAll(['vs-alert-d', "vs-".concat(type, "-alert")], className ? [className] : []);
    var iconMap = {
      success: _react.default.createElement(_IconSuccess.default, {
        className: "vs-alert-icon"
      }),
      info: _react.default.createElement(_IconInfo.default, {
        className: "vs-alert-icon"
      }),
      warning: _react.default.createElement(_IconWarning.default, {
        className: "vs-alert-icon"
      })
    };
    var closeButtonMap = {
      icon: _react.default.createElement(_CloseIcon.default, {
        className: "vs-alert-close-icon",
        onClick: function onClick() {
          return onClose();
        }
      }),
      button: _react.default.createElement(_Button.Button, {
        type: "outline-secondary",
        className: 'vs-alert-close-button',
        onClick: function onClick() {
          return onClose();
        }
      }, closeButtonText)
    };
    return _react.default.createElement("div", _extends({}, restProps, {
      className: classes.join(' ')
    }), _react.default.createElement("div", {
      className: "vs-alert-icon-container"
    }, iconMap[type] || iconMap.info), _react.default.createElement("div", {
      className: "vs-alert-content"
    }, children), _react.default.createElement("div", {
      className: "vs-alert-close-container"
    }, closeButtonMap[closeType]));
  };
};

var Alert = makeAlert();
exports.Alert = Alert;
Alert.propTypes = {
  type: _propTypes.default.oneOf(['info', 'warning', 'success']),
  closeType: _propTypes.default.oneOf(['icon', 'button'])
};