/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var vue = require('vue');
var cloneDeep = require('lodash/cloneDeep');
var isArray = require('lodash/isArray');
var _common_js_log_log = require('../../_common/js/log/log.js');
var slider_util_common = require('../util/common.js');
var slider_sliderMark = require('../slider-mark.js');
require('lodash/isString');
require('../../hooks/useConfig.js');
require('../../config-provider/useConfig.js');
require('lodash/isFunction');
require('../../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../../_chunks/dep-7f0559c3.js');
require('dayjs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);

var useSliderMark = function useSliderMark(config) {
  var name = config.value.prefixName;
  var markList = vue.computed(function () {
    var markProps = config.value;
    if (!markProps.marks) return [];
    var legalMarks = [];
    if (isArray__default["default"](markProps.marks)) {
      var marksList = cloneDeep__default["default"](markProps.marks).sort(function (a, b) {
        return a - b;
      });
      var maxLimit = Math.max.apply(Math, _toConsumableArray__default["default"](marksList).concat([markProps.max]));
      var minLimit = Math.min.apply(Math, _toConsumableArray__default["default"](marksList).concat([markProps.min]));
      if (minLimit < markProps.min) _common_js_log_log["default"].errorOnce("TSlider", "marks min value should >= props min");
      if (maxLimit > markProps.max) _common_js_log_log["default"].errorOnce("TSlider", "marks max value should <= props max");
      marksList.forEach(function (item) {
        legalMarks.push({
          point: item,
          position: (item - minLimit) / (maxLimit - minLimit) * 100,
          mark: item
        });
      });
    } else {
      Object.keys(markProps.marks).map(parseFloat).sort(function (a, b) {
        return a - b;
      }).filter(function (point) {
        return point <= markProps.max && point >= markProps.min;
      }).forEach(function (point) {
        var item = {
          point: point,
          position: (point - markProps.min) * 100 / (markProps.max - markProps.min),
          mark: markProps.marks[point]
        };
        legalMarks.push(item);
      });
    }
    return legalMarks;
  });
  var renderMask = function renderMask(onChangeFn) {
    if (!markList.value.length) return null;
    return vue.createVNode("div", null, [vue.createVNode("div", {
      "class": "".concat(name, "__stops")
    }, [markList.value.map(function (item, index) {
      if (item.position === 0 || item.position === 100) return null;
      return vue.createVNode("div", {
        "class": "".concat(name, "__stop ").concat(name, "__mark-stop"),
        "style": slider_util_common.getStopStyle(item.position, config.value.vertical),
        "key": index
      }, null);
    })]), vue.createVNode("div", {
      "class": "".concat(name, "__mark")
    }, [markList.value.map(function (item, key) {
      return vue.createVNode(slider_sliderMark["default"], {
        "mark": item.mark,
        "point": item.point,
        "key": key,
        "style": slider_util_common.getStopStyle(item.position, config.value.vertical),
        "onClickMarkPoint": onChangeFn
      }, null);
    })])]);
  };
  return renderMask;
};

exports.useSliderMark = useSliderMark;
//# sourceMappingURL=useSliderMark.js.map
