import _extends from "@babel/runtime/helpers/esm/extends";
import { computed, defineComponent, createVNode as _createVNode, Fragment as _Fragment } from 'vue';
import { useInjectSlider } from '../context';
import Track from './Track';
import classnames from '../../_util/classNames';
import { getIndex } from '../util';
const tracksProps = () => ({
  prefixCls: String,
  style: [Object, Array],
  values: Array,
  onStartMove: Function,
  startPoint: Number
});
const Tracks = defineComponent({
  name: 'ATracks',
  props: tracksProps(),
  setup(props) {
    const context = useInjectSlider();
    const trackList = computed(() => {
      const {
        range,
        min
      } = context.value;
      const {
        values,
        startPoint
      } = props;
      if (!range) {
        if (values.length === 0) {
          return [];
        }
        const startValue = startPoint !== null && startPoint !== void 0 ? startPoint : min;
        const endValue = values[0];
        return [{
          start: Math.min(startValue, endValue),
          end: Math.max(startValue, endValue)
        }];
      }
      const list = [];
      for (let i = 0; i < values.length - 1; i += 1) {
        list.push({
          start: values[i],
          end: values[i + 1]
        });
      }
      return list;
    });
    return () => {
      var _a;
      const {
        included,
        classNames,
        styles
      } = context.value;
      const {
        prefixCls,
        style,
        onStartMove
      } = props;
      if (!included) {
        return null;
      }
      const tracksNode = ((_a = trackList.value) === null || _a === void 0 ? void 0 : _a.length) && (classNames.tracks || styles.tracks) ? _createVNode(Track, {
        "index": null,
        "prefixCls": prefixCls,
        "start": trackList.value[0].start,
        "end": trackList.value[trackList.value.length - 1].end,
        "replaceCls": classnames(classNames.tracks, `${prefixCls}-tracks`),
        "style": styles.tracks
      }, null) : null;
      return _createVNode(_Fragment, null, [tracksNode, trackList.value.map(({
        start,
        end
      }, index) => _createVNode(Track, {
        "index": index,
        "prefixCls": prefixCls,
        "style": _extends(_extends({}, getIndex(style, index)), styles.track),
        "start": start,
        "end": end,
        "key": index,
        "onStartMove": onStartMove
      }, null))]);
    };
  }
});
export default Tracks;