"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: 'VxeText',
  mixins: [_ui.globalMixins.sizeMixin, _ui.globalMixins.permissionMixin],
  props: {
    status: String,
    title: [String, Number],
    icon: String,
    prefixIcon: String,
    suffixIcon: String,
    loading: Boolean,
    content: [String, Number],
    clickToCopy: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().text.clickToCopy;
      }
    },
    copyConfig: Object,
    size: {
      type: String,
      default: function _default() {
        return (0, _ui.getConfig)().text.size || (0, _ui.getConfig)().size;
      }
    }
  },
  data: function data() {
    var reactData = {};
    return {
      xID: _xeUtils.default.uniqueId(),
      reactData: reactData
    };
  },
  computed: Object.assign(Object.assign({}, {}), {
    computeCopyOpts: function computeCopyOpts() {
      var $xeText = this;
      var props = $xeText;
      return Object.assign({}, (0, _ui.getConfig)().text.copyConfig, props.copyConfig);
    }
  }),
  methods: {
    //
    // Method
    //
    dispatchEvent: function dispatchEvent(type, params, evnt) {
      var $xeText = this;
      $xeText.$emit(type, (0, _ui.createEvent)(evnt, {
        $text: $xeText
      }, params));
    },
    handleCopy: function handleCopy(evnt) {
      var $xeText = this;
      var props = $xeText;
      var content = props.content;
      var copyOpts = $xeText.computeCopyOpts;
      var showMessage = copyOpts.showMessage;
      var contentEl = $xeText.$refs.refContentElem;
      var copyVal = (contentEl ? contentEl.textContent : '') || content;
      if (copyVal) {
        if (_ui.VxeUI.clipboard.copy(copyVal)) {
          if (showMessage && _ui.VxeUI.modal) {
            _ui.VxeUI.modal.message({
              content: (0, _ui.getI18n)('vxe.text.copySuccess'),
              status: 'success'
            });
          }
          $xeText.dispatchEvent('copy-success', {}, evnt);
        } else {
          if (showMessage && _ui.VxeUI.modal) {
            _ui.VxeUI.modal.message({
              content: (0, _ui.getI18n)('vxe.text.copyError'),
              status: 'error'
            });
          }
          $xeText.dispatchEvent('copy-error', {}, evnt);
        }
      }
    },
    clickIconEvent: function clickIconEvent(evnt) {
      var $xeText = this;
      var props = $xeText;
      var clickToCopy = props.clickToCopy;
      var copyOpts = $xeText.computeCopyOpts;
      if (clickToCopy && copyOpts.trigger !== 'dblclick') {
        $xeText.handleCopy(evnt);
      }
    },
    dblclickIconEvent: function dblclickIconEvent(evnt) {
      var $xeText = this;
      var props = $xeText;
      var clickToCopy = props.clickToCopy;
      var copyOpts = $xeText.computeCopyOpts;
      if (clickToCopy && copyOpts.trigger === 'dblclick') {
        $xeText.handleCopy(evnt);
      }
    },
    clickEvent: function clickEvent(evnt) {
      var $xeText = this;
      var props = $xeText;
      var loading = props.loading;
      if (!loading) {
        $xeText.dispatchEvent('click', {}, evnt);
      }
    },
    dblclickEvent: function dblclickEvent(evnt) {
      var $xeText = this;
      var props = $xeText;
      var loading = props.loading;
      if (!loading) {
        $xeText.dispatchEvent('dblclick', {}, evnt);
      }
    },
    prefixEvent: function prefixEvent(evnt) {
      var $xeText = this;
      var props = $xeText;
      var loading = props.loading;
      if (!loading) {
        $xeText.dispatchEvent('prefix-click', {}, evnt);
      }
    },
    suffixEvent: function suffixEvent(evnt) {
      var $xeText = this;
      var props = $xeText;
      var loading = props.loading;
      if (!loading) {
        $xeText.dispatchEvent('suffix-click', {}, evnt);
      }
    },
    //
    // Render
    //
    renderCopyIcon: function renderCopyIcon(h) {
      var $xeText = this;
      var copyOpts = $xeText.computeCopyOpts;
      var icon = copyOpts.icon,
        status = copyOpts.status;
      return h('span', {
        key: 'ci',
        class: ['vxe-text--copy-icon', _defineProperty({}, "theme--".concat(status), status)],
        on: {
          click: $xeText.clickIconEvent,
          dblclick: $xeText.dblclickIconEvent
        }
      }, [h('i', {
        class: icon || (0, _ui.getIcon)().TEXT_COPY
      })]);
    },
    renderContent: function renderContent(h) {
      var $xeText = this;
      var props = $xeText;
      var slots = $xeText.$scopedSlots;
      var loading = props.loading,
        icon = props.icon,
        prefixIcon = props.prefixIcon,
        suffixIcon = props.suffixIcon,
        clickToCopy = props.clickToCopy,
        content = props.content;
      var copyOpts = $xeText.computeCopyOpts;
      var defaultSlot = slots.default;
      var prefixIconSlot = slots.prefixIcon || slots['prefix-icon'] || slots.icon;
      var suffixIconSlot = slots.suffixIcon || slots['suffix-icon'];
      var copyToRight = copyOpts.layout === 'right';
      var contVNs = [];
      if (loading) {
        contVNs.push(h('span', {
          key: 'lg',
          class: 'vxe-text--loading'
        }, [h('i', {
          class: (0, _ui.getIcon)().TEXT_LOADING
        })]));
      } else if (clickToCopy && !copyToRight) {
        contVNs.push($xeText.renderCopyIcon(h));
      }
      if (prefixIcon || icon) {
        contVNs.push(h('span', {
          key: 'si',
          class: 'vxe-text--prefix-icon',
          on: {
            click: $xeText.prefixEvent
          }
        }, prefixIconSlot ? prefixIconSlot({}) : [h('i', {
          class: prefixIcon || icon
        })]));
      }
      contVNs.push(h('span', {
        key: 'ct',
        ref: 'refContentElem',
        class: 'vxe-text--content',
        on: {
          click: $xeText.clickEvent,
          dblclick: $xeText.dblclickEvent
        }
      }, defaultSlot ? defaultSlot({}) : _xeUtils.default.toValueString(content)));
      if (suffixIcon) {
        contVNs.push(h('span', {
          key: 'si',
          class: 'vxe-text--suffix-icon',
          on: {
            click: $xeText.suffixEvent
          }
        }, suffixIconSlot ? suffixIconSlot({}) : [h('i', {
          class: suffixIcon
        })]));
      }
      if (clickToCopy && copyToRight && !loading) {
        contVNs.push($xeText.renderCopyIcon(h));
      }
      return contVNs;
    },
    renderVN: function renderVN(h) {
      var $xeText = this;
      var props = $xeText;
      var loading = props.loading,
        status = props.status,
        title = props.title,
        clickToCopy = props.clickToCopy;
      var vSize = $xeText.computeSize;
      return h('span', {
        ref: 'refElem',
        class: ['vxe-text', _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "size--".concat(vSize), vSize), "theme--".concat(status), status), 'is--copy', clickToCopy), 'is--loading', loading)],
        attrs: {
          title: title
        }
      }, $xeText.renderContent(h));
    }
  },
  render: function render(h) {
    return this.renderVN(h);
  }
});
/* define-vxe-component end */