'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; }; }();

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

var Popup = function () {
  function Popup(wrapper) {
    var _this = this;

    _classCallCheck(this, Popup);

    this.wrapper = wrapper;
    this.wrapper.classList.add('abe-popup');
    document.addEventListener('click', function (e) {
      if (_this.isOpen && !_this.wrapper.contains(e.target)) _this.close();
    });
  }

  _createClass(Popup, [{
    key: 'open',
    value: function open() {
      var _this2 = this;

      var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
      var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;

      setTimeout(function () {
        _this2.isOpen = true;
      }, 500);
      this.wrapper.style.left = x + 'px';
      this.wrapper.style.top = y + 'px';
      if (!this.wrapper.classList.contains('on')) this.wrapper.classList.add('on');
    }
  }, {
    key: 'close',
    value: function close() {
      if (this.wrapper.classList.contains('on')) this.wrapper.classList.remove('on');
      this.isOpen = false;
    }
  }]);

  return Popup;
}();

exports.default = Popup;