"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _comp = require("../../ui/src/comp");
var _xeUtils = _interopRequireDefault(require("xe-utils"));
var _ui = require("../../ui");
var _vn = require("../../ui/src/vn");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var _default2 = exports.default = /* define-vxe-component start */(0, _comp.defineVxeComponent)({
  name: 'VxeLink',
  mixins: [_ui.globalMixins.sizeMixin, _ui.globalMixins.permissionMixin],
  props: {
    href: String,
    target: String,
    status: String,
    title: [String, Number],
    disabled: Boolean,
    icon: String,
    routerLink: Object,
    underline: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().link.underline;
      }
    },
    /**
     * 权限码
     */
    permissionCode: [String, Number],
    content: [String, Number],
    size: {
      type: String,
      default: function _default() {
        return (0, _ui.getConfig)().link.size || (0, _ui.getConfig)().size;
      }
    }
  },
  data: function data() {
    var reactData = {};
    return {
      xID: _xeUtils.default.uniqueId(),
      reactData: reactData
    };
  },
  computed: Object.assign({}, {}),
  methods: {
    //
    // Method
    //
    dispatchEvent: function dispatchEvent(type, params, evnt) {
      var $xeLink = this;
      $xeLink.$emit(type, (0, _ui.createEvent)(evnt, {
        $link: $xeLink
      }, params));
    },
    clickEvent: function clickEvent(evnt) {
      var $xeLink = this;
      var props = $xeLink;
      var disabled = props.disabled;
      if (!disabled) {
        $xeLink.dispatchEvent('click', {}, evnt);
      }
    },
    //
    // Render
    //
    renderContent: function renderContent(h) {
      var $xeLink = this;
      var props = $xeLink;
      var slots = $xeLink.$scopedSlots;
      var icon = props.icon,
        content = props.content;
      var defaultSlot = slots.default;
      var iconSlot = slots.icon;
      var textContent = _xeUtils.default.toValueString(content);
      return [iconSlot || icon ? h('span', {
        class: 'vxe-link--icon'
      }, iconSlot ? (0, _vn.getSlotVNs)(iconSlot({})) : [h('i', {
        class: icon
      })]) : (0, _ui.renderEmptyElement)($xeLink), defaultSlot || textContent ? h('span', {
        class: 'vxe-link--content'
      }, defaultSlot ? defaultSlot({}) : textContent) : (0, _ui.renderEmptyElement)($xeLink)];
    },
    renderVN: function renderVN(h) {
      var $xeLink = this;
      var props = $xeLink;
      var status = props.status,
        target = props.target,
        href = props.href,
        title = props.title,
        underline = props.underline,
        disabled = props.disabled,
        routerLink = props.routerLink;
      var permissionInfo = $xeLink.computePermissionInfo;
      var vSize = $xeLink.computeSize;
      if (!permissionInfo.visible) {
        return (0, _ui.renderEmptyElement)($xeLink);
      }
      if (routerLink && !disabled) {
        return h('router-link', {
          class: ['vxe-link', _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "size--".concat(vSize), vSize), "theme--".concat(status), status), 'is--disabled', disabled), 'is--underline', underline)],
          props: {
            title: title,
            target: target,
            custom: true,
            to: disabled ? null : routerLink
          },
          on: {
            click: $xeLink.clickEvent
          }
        }, $xeLink.renderContent(h));
      }
      return h('a', {
        ref: 'refElem',
        class: ['vxe-link', _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "size--".concat(vSize), vSize), "theme--".concat(status), status), 'is--disabled', disabled), 'is--underline', underline)],
        attrs: {
          href: disabled ? null : href,
          target: target,
          title: title
        },
        on: {
          click: $xeLink.clickEvent
        }
      }, $xeLink.renderContent(h));
    }
  },
  render: function render(h) {
    return this.renderVN(h);
  }
});
/* define-vxe-component end */