"use strict";

exports.__esModule = true;
exports.default = void 0;
var _babelRuntimeJsxStyleTransform = require("babel-runtime-jsx-style-transform");
var _classnames = _interopRequireDefault(require("classnames"));
var _react = _interopRequireWildcard(require("react"));
var _view = _interopRequireDefault(require("../view"));
var _utils = require("./utils");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Track = function (props, ref) {
  var size = props.size,
    prefix = props.prefix,
    min = props.min,
    max = props.max,
    ratio = props.ratio,
    disabled = props.disabled,
    marks = props.marks,
    rangeWidth = props.rangeWidth,
    marksPosition = props.marksPosition;
  var statePrefix = disabled ? '--disabled' : '';
  var _useMemo = (0, _react.useMemo)(function () {
      var markEl = [];
      var labelEl = [];
      var getKey = function (key) {
        if (marks instanceof Object && !Array.isArray(marks)) {
          return marks[key];
        }
        return key;
      };
      (0, _utils.handleMarks)(marks, min, max).forEach(function (key) {
        var _ref;
        var left = (key - min) / (max - min) * rangeWidth;
        var isActive = (0, _utils.isInRange)((key - min) / (max - min), ratio);
        markEl.push( /*#__PURE__*/(0, _react.createElement)(_view.default, {
          key: "mark-" + key,
          className: (0, _classnames.default)(prefix + "range--mark", isActive ? prefix + "range--mark--active" : '', isActive ? prefix + "range--mark" + statePrefix : ''),
          style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)({
            left: left + _utils.unit
          })
        }));
        labelEl.push( /*#__PURE__*/(0, _react.createElement)(_view.default, {
          key: "label-" + key,
          className: (0, _classnames.default)([prefix + "range--label", prefix + "range--label--" + marksPosition, (_ref = {}, _ref[prefix + "range--label--active"] = isActive, _ref)]),
          style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)({
            left: left + _utils.unit
          })
        }, getKey(key)));
      });
      return [markEl, labelEl];
    }, [marks, min, max, ratio, rangeWidth, prefix, statePrefix]),
    markItems = _useMemo[0],
    labelItems = _useMemo[1];
  var selectedLeft = ratio.length === 2 ? ratio[0] * rangeWidth : 0;
  var width = ratio.length === 2 ? Math.abs(ratio[1] - ratio[0]) * rangeWidth : ratio[0] * rangeWidth;
  return /*#__PURE__*/(0, _react.createElement)(_view.default, {
    ref: ref,
    className: (0, _classnames.default)(prefix + "range--track", prefix + "range--track--" + size, prefix + "range--track" + statePrefix)
  }, /*#__PURE__*/(0, _react.createElement)(_view.default, {
    ref: ref,
    className: (0, _classnames.default)(prefix + "range--track--selected", prefix + "range--track--" + size, prefix + "range--track--selected" + statePrefix),
    style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)({
      left: selectedLeft + _utils.unit,
      width: width + _utils.unit
    })
  }), /*#__PURE__*/(0, _react.createElement)(_view.default, {
    style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)({
      position: 'static'
    })
  }, markItems), /*#__PURE__*/(0, _react.createElement)(_view.default, {
    style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)({
      position: 'static'
    })
  }, labelItems));
};
var _default = /*#__PURE__*/(0, _react.forwardRef)(Track);
exports.default = _default;