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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var colorPicker_hooks = require('../hooks.js');
var colorPicker_panel_baseProps = require('./base-props.js');
var _common_js_colorPicker_constants = require('../../_common/js/color-picker/constants.js');
var _common_js_colorPicker_draggable = require('../../_common/js/color-picker/draggable.js');
require('../../hooks/useConfig.js');
require('../../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isFunction');
require('lodash/isString');
require('../../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
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');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var ColorSlider = vue.defineComponent({
  name: "ColorSlider",
  props: _objectSpread(_objectSpread({}, colorPicker_panel_baseProps["default"]), {}, {
    className: {
      type: String,
      "default": ""
    },
    value: {
      type: Number,
      "default": 0
    },
    maxValue: {
      type: Number,
      "default": 360
    },
    railStyle: {
      type: Object
    },
    type: {
      type: String,
      "default": "hue"
    }
  }),
  setup: function setup(props) {
    var baseClassName = colorPicker_hooks.useBaseClassName();
    var refPanel = vue.ref(null);
    var refThumb = vue.ref(null);
    var dragInstance = vue.ref(null);
    var panelRect = vue.reactive({
      width: _common_js_colorPicker_constants.SLIDER_DEFAULT_WIDTH
    });
    var styles = vue.computed(function () {
      var width = panelRect.width;
      if (!width) return;
      var left = Math.round(props.value / props.maxValue * width);
      return {
        left: "".concat(left, "px"),
        color: props.color.rgb
      };
    });
    var handleDrag = function handleDrag(coordinate, isEnded) {
      if (props.disabled) return;
      var width = panelRect.width;
      var x = coordinate.x;
      var value = Math.round(x / width * props.maxValue * 100) / 100;
      props.onChange(value, isEnded);
    };
    var handleDragEnd = function handleDragEnd(coordinate) {
      if (props.disabled) return;
      handleDrag(coordinate, true);
    };
    vue.onMounted(function () {
      panelRect.width = refPanel.value.offsetWidth || _common_js_colorPicker_constants.SLIDER_DEFAULT_WIDTH;
      dragInstance.value = new _common_js_colorPicker_draggable.Draggable(refPanel.value, {
        start: function start() {
          panelRect.width = refPanel.value.offsetWidth;
        },
        drag: function drag(coordinate) {
          handleDrag(coordinate);
        },
        end: handleDragEnd
      });
    });
    vue.onBeforeUnmount(function () {
      dragInstance.value.destroy();
    });
    return {
      baseClassName: baseClassName,
      refThumb: refThumb,
      refPanel: refPanel,
      styles: styles
    };
  },
  render: function render() {
    var baseClassName = this.baseClassName,
      className = this.className,
      railStyle = this.railStyle,
      styles = this.styles,
      type = this.type,
      color = this.color;
    var paddingStyle = {
      background: "linear-gradient(90deg, rgba(0,0,0,.0) 0%, rgba(0,0,0,.0) 93%, ".concat(color.rgb, " 93%, ").concat(color.rgb, " 100%)")
    };
    return vue.createVNode("div", {
      "class": ["".concat(baseClassName, "__slider-wrapper"), "".concat(baseClassName, "__slider-wrapper--").concat(type, "-type")]
    }, [type === "alpha" && vue.createVNode("div", {
      "class": "".concat(baseClassName, "__slider-padding"),
      "style": paddingStyle
    }, null), vue.createVNode("div", {
      "class": ["".concat(baseClassName, "__slider"), className],
      "ref": "refPanel"
    }, [vue.createVNode("div", {
      "class": "".concat(baseClassName, "__rail"),
      "style": railStyle
    }, null), vue.createVNode("span", {
      "class": ["".concat(baseClassName, "__thumb")],
      "role": "slider",
      "tabindex": 0,
      "ref": "refThumb",
      "style": styles
    }, null)])]);
  }
});

exports["default"] = ColorSlider;
//# sourceMappingURL=slider.js.map
