'use strict';

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

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _styledComponents = require('styled-components');

var _styledComponents2 = _interopRequireDefault(_styledComponents);

var _ModalActionContent = require('./styles/ModalActionContent');

var _ModalActionContent2 = _interopRequireDefault(_ModalActionContent);

var _ModalBlocker = require('./styles/ModalBlocker');

var _ModalBlocker2 = _interopRequireDefault(_ModalBlocker);

var _ModalContent = require('./styles/ModalContent');

var _ModalContent2 = _interopRequireDefault(_ModalContent);

var _ModalTitle = require('./styles/ModalTitle');

var _ModalTitle2 = _interopRequireDefault(_ModalTitle);

var _ModalWindow = require('./styles/ModalWindow');

var _ModalWindow2 = _interopRequireDefault(_ModalWindow);

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Modal = function (_React$Component) {
  _inherits(Modal, _React$Component);

  function Modal() {
    var _ref;

    var _temp, _this, _ret;

    _classCallCheck(this, Modal);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Modal.__proto__ || Object.getPrototypeOf(Modal)).call.apply(_ref, [this].concat(args))), _this), _this.handleModalClicked = function (event) {
      // prevents click event bubbling to blocker and triggering blockerclicked callback
      event.stopPropagation();
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(Modal, [{
    key: 'render',
    value: function render() {
      var _props = this.props,
          id = _props.id,
          className = _props.className,
          onBlockerClicked = _props.onBlockerClicked,
          title = _props.title,
          children = _props.children,
          actionContent = _props.actionContent,
          Blocker = _props.Blocker,
          Content = _props.Content,
          Window = _props.Window,
          ActionContent = _props.ActionContent,
          Title = _props.Title;


      return _react2.default.createElement(
        Blocker,
        { onClick: onBlockerClicked },
        _react2.default.createElement(
          Window,
          { onClick: this.handleModalClicked, id: id, className: className },
          title ? _react2.default.createElement(
            Title,
            null,
            title
          ) : null,
          _react2.default.createElement(
            Content,
            null,
            children
          ),
          actionContent && _react2.default.createElement(
            ActionContent,
            null,
            actionContent
          )
        )
      );
    }
  }]);

  return Modal;
}(_react2.default.Component);

Modal.propTypes = {
  /**
   * Content to render in the modal.
   */
  children: _propTypes2.default.node.isRequired,
  /**
   * An optional title for the top of the modal.
   */
  title: _propTypes2.default.string,
  /**
   * Handles click events on the backdrop behind the modal. Use this to close it if desired.
   */
  onBlockerClicked: _propTypes2.default.func,
  /**
   * Sets a natural CSS width for the modal window. Defaults to 'auto'.
   */
  naturalWidth: _propTypes2.default.string,
  /**
   * Adds a class name to the modal window element.
   */
  className: _propTypes2.default.string,
  /**
   * Adds an id to the modal window element.
   */
  id: _propTypes2.default.string,
  /**
   * Content to render in a fixed position at the bottom of the modal - meant for action buttons, like close.
   */
  actionContent: _propTypes2.default.node,
  /**
   * A component to render the action content area
   */
  ActionContent: _propTypes2.default.func,
  /**
   * A component to render the full-screen blocker behind the modal
   */
  Blocker: _propTypes2.default.func,
  /**
   * A component to render the content inside the modal window
   */
  Content: _propTypes2.default.func,
  /**
   * A component to render the title at the top of the modal
   */
  Title: _propTypes2.default.func,
  /**
   * A component to render the window container of the modal
   */
  Window: _propTypes2.default.func
};
Modal.defaultProps = {
  title: null,
  onBlockerClicked: function onBlockerClicked() {
    return null;
  },
  className: null,
  id: null,
  actionContent: null,
  ActionContent: _ModalActionContent2.default,
  Blocker: _ModalBlocker2.default,
  Content: _ModalContent2.default,
  Title: _ModalTitle2.default,
  Window: _ModalWindow2.default
};
exports.default = Modal;