import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { createVNode as _createVNode } from "vue";
import _extends from "@babel/runtime/helpers/esm/extends";
import { onBeforeUnmount, watch, onActivated, defineComponent, ref, computed } from 'vue';
import Tooltip, { tooltipProps } from '../tooltip';
import raf from '../_util/raf';
const sliderTooltipProps = () => _extends(_extends({}, tooltipProps()), {
  draggingDelete: Boolean,
  value: Number
});
export default defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: 'SliderTooltip',
  inheritAttrs: false,
  props: sliderTooltipProps(),
  setup(props, {
    attrs,
    slots
  }) {
    const innerRef = ref(null);
    const mergedOpen = computed(() => props.open && !props.draggingDelete);
    const rafRef = ref(null);
    function cancelKeepAlign() {
      raf.cancel(rafRef.value);
      rafRef.value = null;
    }
    function keepAlign() {
      rafRef.value = raf(() => {
        var _a;
        (_a = innerRef.value) === null || _a === void 0 ? void 0 : _a.forcePopupAlign();
        rafRef.value = null;
      });
    }
    const align = () => {
      cancelKeepAlign();
      if (mergedOpen.value) {
        keepAlign();
      }
    };
    watch([() => props.open, () => props.title], () => {
      align();
    }, {
      flush: 'post',
      immediate: true
    });
    onActivated(() => {
      align();
    });
    onBeforeUnmount(() => {
      cancelKeepAlign();
    });
    return () => {
      return _createVNode(Tooltip, _objectSpread(_objectSpread(_objectSpread({
        "ref": innerRef
      }, props), attrs), {}, {
        "open": mergedOpen.value
      }), slots);
    };
  }
});