/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var helper = require('../_chunks/dep-c3e1ffac.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var isFunction = require('lodash/isFunction');
var popup_props = require('../popup/props.js');
var popup_popup = require('../popup/popup.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../utils/mixins.js');
var tooltip_props = require('./props.js');
require('@babel/runtime/helpers/typeof');
require('@popperjs/core');
require('../utils/dom.js');
require('vue');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');
require('../_common/js/utils/set-style.js');
require('../utils/event.js');
require('../popup/container.js');
require('../popup/utils.js');
require('../popup/trigger.js');
require('@vue/composition-api');
require('lodash/kebabCase');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-7c884501.js');
require('dayjs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var classPrefixMixins = configProvider_configReceiver.getClassPrefixMixins("tooltip");
var _Tooltip = utils_mixins["default"](classPrefixMixins).extend({
  name: "TTooltip",
  components: {
    Popup: popup_popup["default"]
  },
  props: _objectSpread(_objectSpread({}, popup_props["default"]), tooltip_props["default"]),
  data: function data() {
    return {
      timer: null,
      x: 0,
      offsetX: 0,
      tooltipVisible: false
    };
  },
  computed: {
    tooltipOverlayClassName: function tooltipOverlayClassName() {
      return [this.componentName, _defineProperty__default["default"]({}, "".concat(this.componentName, "--").concat(this.theme), this.theme), this.overlayClassName];
    },
    tooltipOverlayInnerStyle: function tooltipOverlayInnerStyle() {
      var _this = this;
      if (this.placement !== "mouse" || this.offsetX === 0) return this.overlayInnerStyle;
      var offsetStyle = function offsetStyle(triggerEl) {
        return {
          transform: "translateX(".concat(_this.offsetX - triggerEl.getBoundingClientRect().left, "px)")
        };
      };
      if (this.overlayInnerStyle) {
        return function (triggerEl, popupEl) {
          return _objectSpread(_objectSpread({}, offsetStyle(triggerEl)), isFunction__default["default"](_this.overlayInnerStyle) ? _this.overlayInnerStyle(triggerEl, popupEl) : _this.overlayInnerStyle);
        };
      }
      return offsetStyle;
    }
  },
  watch: {
    visible: function visible(_visible) {
      if (this.timer && !_visible) {
        clearTimeout(this.timer);
        this.timer = null;
      }
    }
  },
  created: function created() {
    var _this2 = this;
    if (this.duration && this.visible) {
      this.timer = setTimeout(function () {
        _this2.$emit("visible-change", false);
        clearTimeout(_this2.timer);
        _this2.timer = null;
      }, this.duration);
    }
  },
  mounted: function mounted() {
    var _window;
    (_window = window) === null || _window === void 0 ? void 0 : _window.addEventListener("mousemove", this.onMouseMove, {
      passive: true
    });
  },
  destroyed: function destroyed() {
    var _window2;
    (_window2 = window) === null || _window2 === void 0 ? void 0 : _window2.removeEventListener("mousemove", this.onMouseMove);
  },
  methods: {
    onMouseMove: function onMouseMove(e) {
      this.x = e.clientX;
    },
    onTipVisibleChange: function onTipVisibleChange(val, ctx) {
      if (this.timer && (ctx === null || ctx === void 0 ? void 0 : ctx.trigger) !== "document") return;
      if (val) this.offsetX = this.x;
      this.$emit("visible-change", val);
    },
    getPopupProps: function getPopupProps() {
      var _this3 = this;
      var r = _objectSpread(_objectSpread({}, this.$props), {}, {
        showArrow: this.placement === "mouse" ? false : this.showArrow,
        placement: this.placement === "mouse" ? "bottom-left" : this.placement,
        content: function content() {
          return utils_renderTnode.renderTNodeJSX(_this3, "content");
        },
        "default": function _default() {
          return utils_renderTnode.renderContent(_this3, "default", "triggerElement");
        },
        overlayClassName: this.tooltipOverlayClassName,
        overlayInnerStyle: this.tooltipOverlayInnerStyle
      });
      return r;
    },
    updatedTooltip: function updatedTooltip() {
      this.$refs.popup && this.$refs.popup.updatePopper();
    }
  },
  render: function render() {
    var h = arguments[0];
    return h(popup_popup["default"], helper.helper([{
      "ref": "popup",
      "attrs": {
        "visible": this.visible
      }
    }, {
      "props": this.getPopupProps()
    }, {}, {
      "on": {
        "visible-change": this.onTipVisibleChange
      }
    }]));
  }
});

exports["default"] = _Tooltip;
//# sourceMappingURL=tooltip.js.map
