"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");
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: 'VxeTag',
  mixins: [_ui.globalMixins.sizeMixin, _ui.globalMixins.permissionMixin],
  props: {
    border: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().tag.border;
      }
    },
    visible: {
      type: Boolean,
      default: null
    },
    status: String,
    title: [String, Number],
    icon: String,
    closeIcon: {
      type: String,
      default: function _default() {
        return (0, _ui.getConfig)().tag.closeIcon;
      }
    },
    content: [String, Number],
    round: Boolean,
    closable: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().tag.closable;
      }
    },
    color: String,
    loading: Boolean,
    size: {
      type: String,
      default: function _default() {
        return (0, _ui.getConfig)().tag.size || (0, _ui.getConfig)().size;
      }
    }
  },
  data: function data() {
    var reactData = {
      showTag: true
    };
    return {
      xID: _xeUtils.default.uniqueId(),
      reactData: reactData
    };
  },
  computed: Object.assign({}, {}),
  watch: {
    visible: function visible() {
      var $xeTag = this;
      $xeTag.updateVisible();
    }
  },
  methods: {
    //
    // Method
    //
    dispatchEvent: function dispatchEvent(type, params, evnt) {
      var $xeTag = this;
      $xeTag.$emit(type, (0, _ui.createEvent)(evnt, {
        $tag: $xeTag
      }, params));
    },
    updateVisible: function updateVisible() {
      var $xeTag = this;
      var props = $xeTag;
      var reactData = $xeTag.reactData;
      reactData.showTag = props.visible !== false;
    },
    clickEvent: function clickEvent(evnt) {
      var $xeTag = this;
      var props = $xeTag;
      var loading = props.loading;
      if (!loading) {
        $xeTag.dispatchEvent('click', {}, evnt);
      }
    },
    dblclickEvent: function dblclickEvent(evnt) {
      var $xeTag = this;
      var props = $xeTag;
      var loading = props.loading;
      if (!loading) {
        $xeTag.dispatchEvent('dblclick', {}, evnt);
      }
    },
    closeEvent: function closeEvent(evnt) {
      var $xeTag = this;
      var props = $xeTag;
      var reactData = $xeTag.reactData;
      var loading = props.loading;
      if (!loading) {
        var visible = !reactData.showTag;
        reactData.showTag = visible;
        $xeTag.$emit('update:visible', visible);
        $xeTag.dispatchEvent('close', {
          visible: visible
        }, evnt);
      }
    },
    //
    // Render
    //
    renderContent: function renderContent(h) {
      var $xeTag = this;
      var props = $xeTag;
      var slots = $xeTag.$scopedSlots;
      var icon = props.icon,
        content = props.content,
        closable = props.closable,
        closeIcon = props.closeIcon,
        loading = props.loading;
      var defaultSlot = slots.default;
      var iconSlot = slots.icon;
      var closeIconSlot = slots.closeIcon || slots['close-icon'];
      return [iconSlot || icon ? h('span', {
        class: 'vxe-tag--icon'
      }, iconSlot ? iconSlot({}) : [h('i', {
        class: icon
      })]) : (0, _ui.renderEmptyElement)($xeTag), h('span', {
        class: 'vxe-tag--content'
      }, defaultSlot ? defaultSlot({}) : _xeUtils.default.toValueString(content)), loading || closable ? h('span', {
        class: loading ? 'vxe-tag--loading' : 'vxe-tag--close',
        on: {
          click: $xeTag.closeEvent
        }
      }, !loading && closeIconSlot ? closeIconSlot({}) : [h('i', {
        class: loading ? (0, _ui.getIcon)().TAG_LOADING : closeIcon || (0, _ui.getIcon)().TAG_CLOSE
      })]) : (0, _ui.renderEmptyElement)($xeTag)];
    },
    renderVN: function renderVN(h) {
      var $xeTag = this;
      var props = $xeTag;
      var reactData = $xeTag.reactData;
      var status = props.status,
        color = props.color,
        title = props.title,
        round = props.round,
        border = props.border,
        loading = props.loading;
      var showTag = reactData.showTag;
      var vSize = $xeTag.computeSize;
      if (!showTag) {
        return (0, _ui.renderEmptyElement)($xeTag);
      }
      return h('span', {
        ref: 'refElem',
        class: ['vxe-tag', _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "size--".concat(vSize), vSize), "theme--".concat(status), status && !color), "color--".concat(color), color && !status), 'is--color', color), 'is--round', round), 'is--border', border), 'is--loading', loading)],
        attrs: {
          title: title
        },
        on: {
          click: $xeTag.clickEvent,
          dblclick: $xeTag.dblclickEvent
        }
      }, $xeTag.renderContent(h));
    }
  },
  created: function created() {
    var $xeTag = this;
    $xeTag.updateVisible();
  },
  render: function render(h) {
    return this.renderVN(h);
  }
});
/* define-vxe-component end */