import { createVNode as _createVNode } from "vue";
import _extends from "@babel/runtime/helpers/esm/extends";
import { defineComponent, computed } from 'vue';
import { useInjectSlider } from '../context';
import { getOffset } from '../util';
import classnames from '../../_util/classNames';
const trackProps = () => ({
  prefixCls: String,
  style: Object,
  replaceCls: String,
  start: Number,
  end: Number,
  index: Number,
  onStartMove: Function
});
const Track = defineComponent({
  name: 'ATrack',
  props: trackProps(),
  setup(props) {
    const context = useInjectSlider();
    const offset = computed(() => {
      const {
        start,
        end
      } = props;
      const {
        min,
        max
      } = context.value;
      return [getOffset(start, min, max), getOffset(end, min, max)];
    });
    // ============================ Events ============================
    const onInternalStartMove = e => {
      if (!context.value.disabled && props.onStartMove) {
        props.onStartMove(e, -1);
      }
    };
    return () => {
      const {
        replaceCls,
        prefixCls,
        index,
        onStartMove,
        style
      } = props;
      const {
        direction,
        range,
        classNames
      } = context.value;
      const [offsetStart, offsetEnd] = offset.value;
      const trackPrefixCls = `${prefixCls}-track`;
      const positionStyle = {};
      switch (direction) {
        case 'rtl':
          positionStyle.right = `${offsetStart * 100}%`;
          positionStyle.width = `${offsetEnd * 100 - offsetStart * 100}%`;
          break;
        case 'btt':
          positionStyle.bottom = `${offsetStart * 100}%`;
          positionStyle.height = `${offsetEnd * 100 - offsetStart * 100}%`;
          break;
        case 'ttb':
          positionStyle.top = `${offsetStart * 100}%`;
          positionStyle.height = `${offsetEnd * 100 - offsetStart * 100}%`;
          break;
        default:
          positionStyle.left = `${offsetStart * 100}%`;
          positionStyle.width = `${offsetEnd * 100 - offsetStart * 100}%`;
      }
      const className = replaceCls || classnames(trackPrefixCls, {
        [`${trackPrefixCls}-${index + 1}`]: index !== null && range,
        [`${prefixCls}-track-draggable`]: onStartMove
      }, classNames.track);
      return _createVNode("div", {
        "class": className,
        "style": _extends(_extends({}, positionStyle), style),
        "onMousedown": onInternalStartMove,
        "onTouchstart": onInternalStartMove
      }, null);
    };
  }
});
export default Track;