"use strict";

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

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

var _reactDom = _interopRequireDefault(require("react-dom"));

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _styles = require("@vincent_za/styles");

var _assets = require("@vincent_za/assets");

var _component = _interopRequireDefault(require("../../Svg/component"));

var _constants = require("../constants");

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

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

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _templateObject7() {
  var data = _taggedTemplateLiteral(["\n    position: fixed;\n    top: 0;\n    right: 0;\n    padding: ", ";\n  "]);

  _templateObject7 = function _templateObject7() {
    return data;
  };

  return data;
}

function _templateObject6() {
  var data = _taggedTemplateLiteral(["\n  display: flex;\n  box-sizing: content-box;\n  margin-left: auto;\n  padding-left: 2rem;\n  width: 1rem;\n  height: 1rem;\n  fill: #e8e8e8;\n  cursor: pointer;\n  visibility: hidden;\n\n  &:hover {\n    fill: ", ";\n  };\n\n  ", ";\n\n  ", ":hover & {\n    visibility: visible;\n  };\n"]);

  _templateObject6 = function _templateObject6() {
    return data;
  };

  return data;
}

function _templateObject5() {
  var data = _taggedTemplateLiteral(["\n  padding-bottom: ", ";\n  color: ", ";\n"]);

  _templateObject5 = function _templateObject5() {
    return data;
  };

  return data;
}

function _templateObject4() {
  var data = _taggedTemplateLiteral(["\n  display: flex;\n  padding: ", ";\n  line-height: 1rem;\n  text-transform: uppercase;\n  font-family: ", ";\n  color: #ADCCC8;\n  cursor: ", ";\n  white-space: nowrap;\n  user-select: none;\n"]);

  _templateObject4 = function _templateObject4() {
    return data;
  };

  return data;
}

function _templateObject3() {
  var data = _taggedTemplateLiteral(["\n  position: relative;\n"]);

  _templateObject3 = function _templateObject3() {
    return data;
  };

  return data;
}

function _templateObject2() {
  var data = _taggedTemplateLiteral(["\n    transform: none !important;\n  "]);

  _templateObject2 = function _templateObject2() {
    return data;
  };

  return data;
}

function _templateObject() {
  var data = _taggedTemplateLiteral(["\n  display: ", ";\n  z-index: 3;\n  position: fixed;\n  top: 50%;\n  left: 50%;\n  flex-grow: 1;\n  flex-direction: column;\n  text-transform: none;\n  outline: none;\n  background-color: #fff;\n  box-shadow: 3px 3px 11px -9px #000;\n  user-select: ", ";\n  transform: translate(-50%, -50%);\n\n  ", ";\n"]);

  _templateObject = function _templateObject() {
    return data;
  };

  return data;
}

function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

var Wrap = _styledComponents.default.div(_templateObject(), function (props) {
  return props.isVisible ? 'flex' : 'none';
}, function (props) {
  return props.isTouchDevice ? 'none' : 'inherit';
}, _styles.mediaWidthMax.xsm(_templateObject2()));

var InnerWrap = _styledComponents.default.div(_templateObject3());

var Header = _styledComponents.default.header(_templateObject4(), _styles.REM_UNIT_LG, _styles.FONT_BOLD, function (props) {
  return props.isDraggable ? 'move' : 'inherit';
});

var Content = _styledComponents.default.div(_templateObject5(), _styles.REM_UNIT_LG, _styles.SONIC_SILVER);

var Icon = (0, _styledComponents.default)(_component.default)(_templateObject6(), _styles.GRAY_X11, _styles.mediaWidthMax.xsm(_templateObject7(), _styles.REM_UNIT_LG), Wrap);

var ResizeAndDrag =
/*#__PURE__*/
function (_React$Component) {
  _inherits(ResizeAndDrag, _React$Component);

  function ResizeAndDrag() {
    _classCallCheck(this, ResizeAndDrag);

    return _possibleConstructorReturn(this, _getPrototypeOf(ResizeAndDrag).apply(this, arguments));
  }

  _createClass(ResizeAndDrag, [{
    key: "shouldComponentUpdate",
    value: function shouldComponentUpdate(nextProps) {
      if (nextProps.isModalActive !== this.props.isModalActive) return true;
      if (nextProps.title !== this.props.title) return true;
      if (nextProps.id !== this.props.id) return true;
      if (nextProps.children !== this.props.children) return true;
      return false;
    }
  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var _this$props = this.props,
          isTouchDevice = _this$props.isTouchDevice,
          isModalActive = _this$props.isModalActive,
          hasOverlay = _this$props.hasOverlay,
          title = _this$props.title,
          id = _this$props.id,
          children = _this$props.children,
          onOverlayToggle = _this$props.onOverlayToggle,
          portalSelector = _this$props.portalSelector;
      return _reactDom.default.createPortal(_react.default.createElement(Wrap, {
        isTouchDevice: isTouchDevice,
        isVisible: isModalActive,
        tabIndex: 0,
        className: _constants.CN_MODAL
      }, _react.default.createElement(InnerWrap, null, _react.default.createElement(Header, {
        className: _constants.CLASSNAME_HEADER,
        ref: function ref(el) {
          _this.modalRef = el;
        }
      }, title, _react.default.createElement(Icon, {
        svg: _assets.closeSvg,
        onClick: function onClick(event) {
          return onOverlayToggle({
            event: event,
            id: id,
            hasOverlay: hasOverlay,
            showOverlay: false
          });
        }
      })), isModalActive && _react.default.createElement(Content, {
        className: _constants.MODAL_CLASSNAME_CONTENT
      }, children))), document.querySelector(portalSelector || '#app'));
    }
  }]);

  return ResizeAndDrag;
}(_react.default.Component);

ResizeAndDrag.propTypes = {
  isTouchDevice: _propTypes.bool.isRequired,
  isModalActive: _propTypes.bool.isRequired,
  hasOverlay: _propTypes.bool.isRequired,
  title: _propTypes.string.isRequired,
  id: _propTypes.string.isRequired,
  children: _propTypes.node.isRequired,
  portalSelector: _propTypes.string,
  onOverlayToggle: _propTypes.func.isRequired
};
ResizeAndDrag.defaultProps = {
  portalSelector: undefined
};
var _default = ResizeAndDrag;
exports.default = _default;