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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var select_index = require('../../select/index.js');
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('../../utils/withInstall.js');
require('vue');
require('lodash/capitalize');
require('../../select/select.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/typeof');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/isFunction');
require('lodash/debounce');
require('lodash/get');
require('lodash/cloneDeep');
require('lodash/isArray');
require('lodash/isObject');
require('../../hooks/useDefaultValue.js');
require('../../hooks/useVModel.js');
require('lodash/kebabCase');
require('../../hooks/tnode.js');
require('lodash/isEmpty');
require('lodash/camelCase');
require('../../hooks/render-tnode.js');
require('lodash/isString');
require('../../config-provider/useConfig.js');
require('../../config-provider/context.js');
require('lodash/merge');
require('lodash/mergeWith');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('../../_chunks/dep-7c884501.js');
require('dayjs');
require('../../loading/index.js');
require('../../loading/directive.js');
require('lodash/mapKeys');
require('lodash/isEqual');
require('../../loading/plugin.js');
require('../../config.js');
require('../../utils/dom.js');
require('raf');
require('../../utils/easing.js');
require('../../loading/loading.js');
require('../../utils/render-tnode.js');
require('../../utils/transfer-dom.js');
require('../../config-provider/config-receiver.js');
require('../../utils/mixins.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../_common/js/loading/circle-adapter.js');
require('../../_common/js/utils/set-style.js');
require('../../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('../../popup/index.js');
require('../../utils/map-props.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../utils/helper.js');
require('../../utils/event.js');
require('../../popup/props.js');
require('../../popup/container.js');
require('../../popup/utils.js');
require('../../popup/trigger.js');
require('../../popup/plugin.js');
require('../../input/index.js');
require('../../input/input.js');
require('../../_chunks/dep-c3e1ffac.js');
require('@ldesign/icons-vue');
require('../../_common/js/log/log.js');
require('../../input/props.js');
require('../../input/input-group.js');
require('../../tag/index.js');
require('../../tag/tag.js');
require('../../tag/props.js');
require('../../tag/check-tag.js');
require('../../tag/check-tag-props.js');
require('../../select-input/index.js');
require('../../select-input/select-input.js');
require('../../select-input/props.js');
require('../../select-input/useSingle.js');
require('lodash/pick');
require('../../hooks/useConfig.js');
require('../../select-input/useMultiple.js');
require('../../tag-input/index.js');
require('../../tag-input/tag-input.js');
require('../../hooks/useGlobalIcon.js');
require('../../tag-input/props.js');
require('../../tag-input/hooks/useTagScroll.js');
require('../../tag-input/useTagList.js');
require('../../tag-input/hooks/useHover.js');
require('../../tag-input/hooks/useDragSorter.js');
require('../../select-input/useOverlayInnerStyle.js');
require('../../common-components/fake-arrow.js');
require('../../hooks/useFormDisabled.js');
require('../../select/option.js');
require('../../utils/ripple.js');
require('../../checkbox/index.js');
require('../../checkbox/group.js');
require('lodash/intersection');
require('../../checkbox/checkbox.js');
require('../../checkbox/props.js');
require('../../checkbox/checkbox-group-props.js');
require('../../hooks/useLazyLoad.js');
require('../../_common/js/utils/observe.js');
require('../../hooks/useCommonClassName.js');
require('../../select/util.js');
require('../../select/option-props.js');
require('../../select/select-panel.js');
require('../../hooks/useVirtualScroll.js');
require('../../select/hooks/useSelectOptions.js');
require('../../select/props.js');
require('../../select/optionGroup.js');
require('../../select/option-group-props.js');
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 = VueCompositionAPI.defineComponent({
  name: "ColorSlider",
  components: {
    TSelect: select_index.Select,
    TOption: select_index.Option
  },
  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, _ref) {
    var emit = _ref.emit;
    var baseClassName = colorPicker_hooks.useBaseClassName();
    var refPanel = VueCompositionAPI.ref(null);
    var refThumb = VueCompositionAPI.ref(null);
    var dragInstance = VueCompositionAPI.ref(null);
    var panelRect = VueCompositionAPI.reactive({
      width: _common_js_colorPicker_constants.SLIDER_DEFAULT_WIDTH
    });
    var styles = VueCompositionAPI.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);
    };
    VueCompositionAPI.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
      });
    });
    VueCompositionAPI.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
    })])]);
  }
});

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