import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs2/core-js/object/get-own-property-descriptor";
import "core-js/modules/es6.regexp.replace";
import "core-js/modules/es6.regexp.search";
import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array";
import _createClass from "@babel/runtime-corejs2/helpers/createClass";
import _inheritsLoose from "../../inheritsLoose";
import _defineProperty from "@babel/runtime-corejs2/helpers/defineProperty";
import _applyDecoratedDescriptor from "@babel/runtime-corejs2/helpers/applyDecoratedDescriptor";

var _dec, _class, _class2, _temp;

import Intact from 'intact-angular';
import template from './index.vdt';
var Link = (_dec = Intact.template(), (_class = (_temp = _class2 =
/*#__PURE__*/
function (_Intact) {
  _inheritsLoose(Link, _Intact);

  function Link() {
    return _Intact.apply(this, arguments) || this;
  }

  var _proto = Link.prototype;

  _proto.defaults = function defaults() {
    return {
      href: undefined,
      name: undefined,
      isReplace: false
    };
  };

  _proto.to = function to(e) {
    e.preventDefault();
    this.trigger('click', e);
    var href = this.get('href');
    var name = this.get('name');
    var history = Link.history;
    var url;

    if (href != null) {
      url = href;
    } else if (name != null) {
      if (_Array$isArray(name)) {
        url = Link.url.apply(Link.url, name);
      } else {
        url = Link.url(name);
      }
    }

    if (url) {
      // if the href is equal to the current href, then do nothing
      var _history$location = history.location,
          pathname = _history$location.pathname,
          search = _history$location.search;
      if (pathname + search === url) return;

      if (this.get('isReplace')) {
        history.replace(url);
      } else {
        history.push(url);
      }
    }
  };

  _createClass(Link, [{
    key: "template",
    get: function get() {
      return template;
    }
  }]);

  return Link;
}(Intact), _defineProperty(_class2, "history", undefined), _defineProperty(_class2, "propTypes", {
  href: String,
  name: [String, Array],
  isReplace: Boolean
}), _defineProperty(_class2, "events", {
  click: true
}), _temp), (_applyDecoratedDescriptor(_class.prototype, "template", [_dec], _Object$getOwnPropertyDescriptor(_class.prototype, "template"), _class.prototype)), _class));
export { Link as default };
export { Link };