/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, reactive, computed, onMounted, onBeforeUnmount } from '@vue/composition-api';
import '../const.js';
import { Select, Option } from '../../select/index.js';
import '../utils/index.js';
import { useBaseClassName } from '../hooks.js';
import baseProps from './base-props.js';
import { SLIDER_DEFAULT_WIDTH } from '../../_common/js/color-picker/constants.js';
import { Draggable } from '../../_common/js/color-picker/draggable.js';
import '../../select/select.js';
import '../../_chunks/dep-a4bd011a.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isFunction';
import 'lodash/debounce';
import 'lodash/get';
import 'lodash/cloneDeep';
import 'lodash/isArray';
import '../../hooks/useDefaultValue.js';
import '../../hooks/useVModel.js';
import '../../hooks/tnode.js';
import 'lodash/isEmpty';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../hooks/render-tnode.js';
import 'lodash/isString';
import 'lodash/isObject';
import '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import 'lodash/merge';
import 'lodash/mergeWith';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '../../config-provider/type.js';
import '../../select/props.js';
import '../../loading/index.js';
import '../../loading/loading.js';
import '../../loading/icon/gradient.js';
import '../../_common/js/loading/circle-adapter.js';
import '../../_common/js/utils/set-style.js';
import '../../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '../../config-provider/config-receiver.js';
import 'vue';
import '../../utils/mixins.js';
import '../../utils/dom.js';
import 'raf';
import '../../utils/easing.js';
import '../../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import '../../utils/transfer-dom.js';
import '../../loading/props.js';
import '../../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../../loading/type.js';
import '../../loading/plugin.js';
import '../../config.js';
import '../../popup/index.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../utils/helper.js';
import '../../popup/props.js';
import '../../popup/container.js';
import '../../utils/map-props.js';
import '../../popup/type.js';
import '../../input/index.js';
import '../../input/input.js';
import 'tdesign-icons-vue';
import '../../utils/event.js';
import '../../input/props.js';
import '../../input/input-group.js';
import '../../input/type.js';
import '../../tag/index.js';
import '../../tag/tag.js';
import '../../tag/props.js';
import '../../tag/check-tag.js';
import '../../tag/check-tag-props.js';
import '../../tag/type.js';
import '../../select-input/index.js';
import '../../select-input/select-input.js';
import '../../select-input/props.js';
import '../../select-input/useSingle.js';
import 'lodash/pick';
import '../../hooks/useConfig.js';
import '../../select-input/useMultiple.js';
import '../../tag-input/index.js';
import '../../tag-input/tag-input.js';
import '../../tag-input/props.js';
import '../../tag-input/hooks/useTagScroll.js';
import '../../tag-input/useTagList.js';
import '../../tag-input/hooks/useHover.js';
import '../../tag-input/hooks/useDragSorter.js';
import '../../hooks/useGlobalIcon.js';
import '../../tag-input/type.js';
import '../../select-input/useOverlayInnerStyle.js';
import '../../select-input/type.js';
import '../../common-components/fake-arrow.js';
import '../../select/option.js';
import '../../utils/ripple.js';
import '../../select/option-props.js';
import '../../checkbox/index.js';
import '../../checkbox/group.js';
import 'lodash/intersection';
import '../../checkbox/checkbox.js';
import '../../checkbox/props.js';
import '../../checkbox/checkbox-group-props.js';
import '../../checkbox/type.js';
import '../../hooks/useLazyLoad.js';
import '../../_common/js/utils/observe.js';
import '../../select/util.js';
import '../../hooks/useCommonClassName.js';
import '../../select/select-panel.js';
import '../../hooks/useVirtualScroll.js';
import '../../select/hooks/useSelectOptions.js';
import '../../select/optionGroup.js';
import '../../select/option-group-props.js';
import '../../select/type.js';
import '../../_common/js/color-picker/index.js';
import '../../_common/js/color-picker/cmyk.js';
import '../../_common/js/color-picker/color.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import 'tinycolor2';
import '../../_common/js/color-picker/gradient.js';

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(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 = defineComponent({
  name: "ColorSlider",
  components: {
    TSelect: Select,
    TOption: Option
  },
  props: _objectSpread(_objectSpread({}, baseProps), {}, {
    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, _ref) {
    var emit = _ref.emit;
    var baseClassName = useBaseClassName();
    var refPanel = ref(null);
    var refThumb = ref(null);
    var dragInstance = ref(null);
    var panelRect = reactive({
      width: SLIDER_DEFAULT_WIDTH
    });
    var styles = 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.handleChange(value, isEnded);
      emit("change", value, isEnded);
    };

    var handleDragEnd = function handleDragEnd(coordinate) {
      if (props.disabled) {
        return;
      }

      handleDrag(coordinate, true);
    };

    onMounted(function () {
      panelRect.width = refPanel.value.offsetWidth || SLIDER_DEFAULT_WIDTH;
      dragInstance.value = new Draggable(refPanel.value, {
        start: function start() {
          panelRect.width = refPanel.value.offsetWidth;
        },
        drag: function drag(coordinate) {
          handleDrag(coordinate);
        },
        end: handleDragEnd
      });
    });
    onBeforeUnmount(function () {
      dragInstance.value.destroy();
    });
    return {
      baseClassName: baseClassName,
      refThumb: refThumb,
      refPanel: refPanel,
      styles: styles
    };
  },
  render: function render() {
    var h = arguments[0];
    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 h("div", {
      "class": ["".concat(baseClassName, "__slider-wrapper"), "".concat(baseClassName, "__slider-wrapper--").concat(type, "-type")]
    }, [type === "alpha" && h("div", {
      "class": "".concat(baseClassName, "__slider-padding"),
      "style": paddingStyle
    }), h("div", {
      "class": ["".concat(baseClassName, "__slider"), className],
      "ref": "refPanel"
    }, [h("div", {
      "class": "".concat(baseClassName, "__rail"),
      "style": railStyle
    }), h("span", {
      "class": ["".concat(baseClassName, "__thumb")],
      "attrs": {
        "role": "slider",
        "tabindex": 0
      },
      "ref": "refThumb",
      "style": styles
    })])]);
  }
});

export { ColorSlider as default };
//# sourceMappingURL=slider.js.map
