"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _vue = require("vue");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _context = require("../context");
var _util = require("../util");
var _classNames = _interopRequireDefault(require("../../_util/classNames"));
const trackProps = () => ({
  prefixCls: String,
  style: Object,
  replaceCls: String,
  start: Number,
  end: Number,
  index: Number,
  onStartMove: Function
});
const Track = (0, _vue.defineComponent)({
  name: 'ATrack',
  props: trackProps(),
  setup(props) {
    const context = (0, _context.useInjectSlider)();
    const offset = (0, _vue.computed)(() => {
      const {
        start,
        end
      } = props;
      const {
        min,
        max
      } = context.value;
      return [(0, _util.getOffset)(start, min, max), (0, _util.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 || (0, _classNames.default)(trackPrefixCls, {
        [`${trackPrefixCls}-${index + 1}`]: index !== null && range,
        [`${prefixCls}-track-draggable`]: onStartMove
      }, classNames.track);
      return (0, _vue.createVNode)("div", {
        "class": className,
        "style": (0, _extends2.default)((0, _extends2.default)({}, positionStyle), style),
        "onMousedown": onInternalStartMove,
        "onTouchstart": onInternalStartMove
      }, null);
    };
  }
});
var _default = exports.default = Track;