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

import { h as helper } from '../../chunks/helper.js';
import isFunction from 'lodash/isFunction';
import popupProps from '../popup/props.js';
import LPopup from '../popup/popup.js';
import { renderLNodeJSX, renderContent } from '../../utils/render-node.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import props from './props.js';
import '../../chunks/_commonjsHelpers.js';
import '@popperjs/core';
import '../../chunks/set-style.js';
import '../../utils/dom.js';
import 'vue';
import 'raf';
import 'lodash/isString';
import '../../chunks/index.js';
import '../../chunks/log.js';
import '../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../utils/easing.js';
import '../../utils/helper.js';
import 'lodash/camelCase';
import '../popup/container.js';
import 'lodash';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';

const classPrefixMixins = getClassPrefixMixins("tooltip");
var _Tooltip = mixins(classPrefixMixins).extend({
  name: "LTooltip",
  components: {
    LPopup
  },
  props: {
    ...popupProps,
    ...props
  },
  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(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: () => renderLNodeJSX(this, "content"),
        default: () => 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([{
      "ref": "popup",
      "attrs": {
        "visible": this.visible
      }
    }, {
      "props": this.getPopupProps()
    }, {}, {
      "on": {
        "visible-change": this.onTipVisibleChange
      }
    }]));
  }
});

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