'use strict';

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

var vue = require('vue');
var Slider$1 = require('../vc-slider/src/Slider.js');
var Range = require('../vc-slider/src/Range.js');
var Handle = require('../vc-slider/src/Handle.js');
var FormItemContext = require('../form/FormItemContext.js');
var devWarning = require('../vc-util/devWarning.js');
var type = require('../_util/type.js');
require('../hooks/index.js');
var classNames = require('../_util/classNames.js');
var SliderTooltip = require('./SliderTooltip.js');
var index$1 = require('./style/index.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');

const defaultTipFormatter = (value) => typeof value === "number" ? value.toString() : "";
const sliderProps = () => ({
  "id": String,
  "prefixCls": String,
  "tooltipPrefixCls": String,
  "range": type.someType([Boolean, Object]),
  "reverse": type.booleanType(),
  "min": Number,
  "max": Number,
  "step": type.someType([Object, Number]),
  "marks": type.objectType(),
  "dots": type.booleanType(),
  "value": type.someType([Array, Number]),
  "defaultValue": type.someType([Array, Number]),
  "included": type.booleanType(),
  "disabled": type.booleanType(),
  "vertical": type.booleanType(),
  "tipFormatter": type.someType([Function, Object], () => defaultTipFormatter),
  "tooltipOpen": type.booleanType(),
  /** @deprecated `tooltipVisible` is deprecated. Please use `tooltipOpen` instead. */
  "tooltipVisible": type.booleanType(),
  "tooltipPlacement": type.stringType(),
  "getTooltipPopupContainer": type.functionType(),
  "autofocus": type.booleanType(),
  "handleStyle": type.someType([Array, Object]),
  "trackStyle": type.someType([Array, Object]),
  "onChange": type.functionType(),
  "onAfterChange": type.functionType(),
  "onFocus": type.functionType(),
  "onBlur": type.functionType(),
  "onUpdate:value": type.functionType()
});
const Slider = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ASlider",
  inheritAttrs: false,
  props: sliderProps(),
  // emits: ['update:value', 'change', 'afterChange', 'blur'],
  slots: Object,
  setup(props, {
    attrs,
    slots,
    emit,
    expose
  }) {
    if (process.env.NODE_ENV !== "production") {
      [["tooltipVisible", "tooltipOpen"]].forEach(([deprecatedName, newName]) => {
        devWarning.default(props.tooltipVisible === void 0, "Slider", `\`${deprecatedName}\` is deprecated, please use \`${newName}\` instead.`);
      });
    }
    const {
      prefixCls,
      rootPrefixCls,
      direction,
      getPopupContainer,
      configProvider
    } = useConfigInject.default("slider", props);
    const [wrapSSR, hashId] = index$1.default(prefixCls);
    const formItemContext = FormItemContext.useInjectFormItemContext();
    const sliderRef = vue.ref();
    const visibles = vue.ref({});
    const toggleTooltipOpen = (index, visible) => {
      visibles.value[index] = visible;
    };
    const tooltipPlacement = vue.computed(() => {
      if (props.tooltipPlacement)
        return props.tooltipPlacement;
      if (!props.vertical)
        return "top";
      return direction.value === "rtl" ? "left" : "right";
    });
    const focus = () => {
      var _a;
      (_a = sliderRef.value) == null ? void 0 : _a.focus();
    };
    const blur = () => {
      var _a;
      (_a = sliderRef.value) == null ? void 0 : _a.blur();
    };
    const handleChange = (val) => {
      emit("update:value", val);
      emit("change", val);
      formItemContext.onFieldChange();
    };
    const handleBlur = (e) => {
      emit("blur", e);
    };
    expose({
      focus,
      blur
    });
    const handleWithTooltip = ({
      tooltipPrefixCls,
      info: {
        value,
        dragging,
        index,
        ...restProps
      }
    }) => {
      const {
        tipFormatter,
        tooltipOpen = props.tooltipVisible,
        getTooltipPopupContainer
      } = props;
      const isTipFormatter = tipFormatter ? visibles.value[index] || dragging : false;
      const open = tooltipOpen || tooltipOpen === void 0 && isTipFormatter;
      return vue.createVNode(SliderTooltip.default, {
        "prefixCls": tooltipPrefixCls,
        "title": tipFormatter ? tipFormatter(value) : "",
        "open": open,
        "placement": tooltipPlacement.value,
        "transitionName": `${rootPrefixCls.value}-zoom-down`,
        "key": index,
        "overlayClassName": `${prefixCls.value}-tooltip`,
        "getPopupContainer": getTooltipPopupContainer || (getPopupContainer == null ? void 0 : getPopupContainer.value)
      }, {
        default: () => [vue.createVNode(Handle.default, vue.mergeProps(restProps, {
          "value": value,
          "onMouseenter": () => toggleTooltipOpen(index, true),
          "onMouseleave": () => toggleTooltipOpen(index, false)
        }), null)]
      });
    };
    return () => {
      const {
        tooltipPrefixCls: customizeTooltipPrefixCls,
        range,
        id = formItemContext.id.value,
        ...restProps
      } = props;
      const tooltipPrefixCls = configProvider.getPrefixCls("tooltip", customizeTooltipPrefixCls);
      const cls = classNames.default(attrs.class, {
        [`${prefixCls.value}-rtl`]: direction.value === "rtl"
      }, hashId.value);
      if (direction.value === "rtl" && !restProps.vertical)
        restProps.reverse = !restProps.reverse;
      let draggableTrack;
      if (typeof range === "object")
        draggableTrack = range.draggableTrack;
      if (range) {
        return wrapSSR(vue.createVNode(Range.default, vue.mergeProps(attrs, restProps, {
          "step": restProps.step,
          "draggableTrack": draggableTrack,
          "class": cls,
          "ref": sliderRef,
          "handle": (info) => handleWithTooltip({
            tooltipPrefixCls,
            prefixCls: prefixCls.value,
            info
          }),
          "prefixCls": prefixCls.value,
          "onChange": handleChange,
          "onBlur": handleBlur
        }), {
          mark: slots.mark
        }));
      }
      return wrapSSR(vue.createVNode(Slider$1.default, vue.mergeProps(attrs, restProps, {
        "id": id,
        "step": restProps.step,
        "class": cls,
        "ref": sliderRef,
        "handle": (info) => handleWithTooltip({
          tooltipPrefixCls,
          prefixCls: prefixCls.value,
          info
        }),
        "prefixCls": prefixCls.value,
        "onChange": handleChange,
        "onBlur": handleBlur
      }), {
        mark: slots.mark
      }));
    };
  }
});
var index = type.withInstall(Slider);

exports.default = index;
exports.sliderProps = sliderProps;
//# sourceMappingURL=index.js.map
