/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var helper = require('../../chunks/helper.js');
var isFunction = require('lodash/isFunction');
var components_popup_props = require('../popup/props.js');
var components_popup_popup = require('../popup/popup.js');
var utils_renderNode = require('../../utils/render-node.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
var components_tooltip_props = require('./props.js');
require('@popperjs/core');
require('../../chunks/set-style.js');
require('../../utils/dom.js');
require('vue');
require('raf');
require('lodash/isString');
require('../../chunks/log.js');
require('../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../utils/easing.js');
require('../../utils/helper.js');
require('lodash/camelCase');
require('../popup/container.js');
require('lodash');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');

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

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

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("tooltip");
var _Tooltip = utils_mixins["default"](classPrefixMixins).extend({
  name: "LTooltip",
  components: {
    LPopup: components_popup_popup["default"]
  },
  props: {
    ...components_popup_props["default"],
    ...components_tooltip_props["default"]
  },
  data() {
    return {
      timer: null,
      x: 0,
      offsetX: 0,
      tooltipVisible: false
    };
  },
  computed: {
    tooltipOverlayClassName() {
      return [this.componentName, {
        [`${this.componentName}--${this.theme}`]: this.theme
      }, this.overlayClassName];
    },
    tooltipOverlayInnerStyle() {
      if (this.placement !== "mouse" || this.offsetX === 0) return this.overlayInnerStyle;
      const offsetStyle = triggerEl => ({
        transform: `translateX(${this.offsetX - triggerEl.getBoundingClientRect().left}px)`
      });
      if (this.overlayInnerStyle) {
        return (triggerEl, popupEl) => ({
          ...offsetStyle(triggerEl),
          ...(isFunction__default["default"](this.overlayInnerStyle) ? this.overlayInnerStyle(triggerEl, popupEl) : this.overlayInnerStyle)
        });
      }
      return offsetStyle;
    }
  },
  watch: {
    visible(visible) {
      if (this.timer && !visible) {
        clearTimeout(this.timer);
        this.timer = null;
      }
    }
  },
  created() {
    if (this.duration && this.visible) {
      this.timer = setTimeout(() => {
        this.$emit("visible-change", false);
        clearTimeout(this.timer);
        this.timer = null;
      }, this.duration);
    }
  },
  mounted() {
    var _window;
    (_window = window) === null || _window === void 0 ? void 0 : _window.addEventListener("mousemove", this.onMouseMove, {
      passive: true
    });
  },
  destroyed() {
    var _window2;
    (_window2 = window) === null || _window2 === void 0 ? void 0 : _window2.removeEventListener("mousemove", this.onMouseMove);
  },
  methods: {
    onMouseMove(e) {
      this.x = e.clientX;
    },
    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() {
      const r = {
        ...this.$props,
        showArrow: this.placement === "mouse" ? false : this.showArrow,
        placement: this.placement === "mouse" ? "bottom-left" : this.placement,
        content: () => utils_renderNode.renderLNodeJSX(this, "content"),
        default: () => utils_renderNode.renderContent(this, "default", "triggerElement"),
        overlayClassName: this.tooltipOverlayClassName,
        overlayInnerStyle: this.tooltipOverlayInnerStyle
      };
      return r;
    },
    updatedTooltip() {
      this.$refs.popup && this.$refs.popup.updatePopper();
    }
  },
  render() {
    const h = arguments[0];
    return h("l-popup", helper.helper([{
      "ref": "popup",
      "attrs": {
        "visible": this.visible
      }
    }, {
      "props": this.getPopupProps()
    }, {}, {
      "on": {
        "visible-change": this.onTipVisibleChange
      }
    }]));
  }
});

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