"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _vue = require("vue");
var _context = require("../context");
var _Track = _interopRequireDefault(require("./Track"));
var _classNames = _interopRequireDefault(require("../../_util/classNames"));
var _util = require("../util");
const tracksProps = () => ({
  prefixCls: String,
  style: [Object, Array],
  values: Array,
  onStartMove: Function,
  startPoint: Number
});
const Tracks = (0, _vue.defineComponent)({
  name: 'ATracks',
  props: tracksProps(),
  setup(props) {
    const context = (0, _context.useInjectSlider)();
    const trackList = (0, _vue.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) ? (0, _vue.createVNode)(_Track.default, {
        "index": null,
        "prefixCls": prefixCls,
        "start": trackList.value[0].start,
        "end": trackList.value[trackList.value.length - 1].end,
        "replaceCls": (0, _classNames.default)(classNames.tracks, `${prefixCls}-tracks`),
        "style": styles.tracks
      }, null) : null;
      return (0, _vue.createVNode)(_vue.Fragment, null, [tracksNode, trackList.value.map(({
        start,
        end
      }, index) => (0, _vue.createVNode)(_Track.default, {
        "index": index,
        "prefixCls": prefixCls,
        "style": (0, _extends2.default)((0, _extends2.default)({}, (0, _util.getIndex)(style, index)), styles.track),
        "start": start,
        "end": end,
        "key": index,
        "onStartMove": onStartMove
      }, null))]);
    };
  }
});
var _default = exports.default = Tracks;