/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-37d5b9c4.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import isFunction from 'lodash/isFunction';
import { prefix } from '../config.js';
import props from './props.js';
import popupProps from '../popup/props.js';
import Popup from '../popup/popup.js';
import { renderTNodeJSX, renderContent } from '../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import '@popperjs/core';
import '../utils/classnames.js';
import '../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';
import '../_common/js/utils/set-style.js';
import '../popup/container.js';

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(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 _Tooltip = Vue.extend({
  name: "TTooltip",
  components: {
    Popup: Popup
  },
  props: _objectSpread(_objectSpread({}, popupProps), props),
  data: function data() {
    return {
      timer: null,
      x: 0,
      offsetX: 0,
      tooltipVisible: false
    };
  },
  computed: {
    tooltipOverlayClassName: function tooltipOverlayClassName() {
      return ["".concat(prefix, "-tooltip"), _defineProperty({}, "".concat(prefix, "-tooltip--").concat(this.theme), this.theme), this.overlayClassName];
    },
    tooltipOverlayStyle: function tooltipOverlayStyle() {
      var _this = this;

      if (this.placement !== "mouse" || this.offsetX === 0) {
        return this.overlayStyle;
      }

      var offsetStyle = function offsetStyle(triggerEl) {
        return {
          transform: "translateX(".concat(_this.offsetX - triggerEl.getBoundingClientRect().left, "px)")
        };
      };

      if (this.overlayStyle) {
        return function (triggerEl, popupEl) {
          return _objectSpread(_objectSpread({}, offsetStyle(triggerEl)), isFunction(_this.overlayStyle) ? _this.overlayStyle(triggerEl, popupEl) : _this.overlayStyle);
        };
      }

      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 renderTNodeJSX(_this3, "content");
        },
        "default": function _default() {
          return renderContent(_this3, "default", "triggerElement");
        },
        overlayClassName: this.tooltipOverlayClassName,
        overlayStyle: this.tooltipOverlayStyle
      });

      return r;
    },
    updatedTooltip: function updatedTooltip() {
      this.$refs.popup && this.$refs.popup.updatePopper();
    }
  },
  render: function render() {
    var h = arguments[0];
    return h(Popup, helper([{
      "ref": "popup",
      "attrs": {
        "visible": this.visible
      }
    }, {
      "props": this.getPopupProps()
    }, {}, {
      "on": {
        "visible-change": this.onTipVisibleChange
      }
    }]));
  }
});

export { _Tooltip as default };
//# sourceMappingURL=tooltip.js.map
