/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');
var constants = require('../../../chunks/constants.js');
var components_select_index = require('../../select/index.js');
require('../../../chunks/color.js');
var draggable = require('../../../chunks/draggable.js');
var components_colorPicker_hooks_index = require('../hooks/index.js');
var components_colorPicker_panel_baseProps = require('./base-props.js');
require('../../../utils/with-install.js');
require('vue');
require('lodash');
require('../../../config.js');
require('../../select/select.js');
require('../../../chunks/helper.js');
require('lodash/isFunction');
require('lodash/debounce');
require('lodash/get');
require('lodash/cloneDeep');
require('lodash/isArray');
require('lodash/isObject');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../../hooks/use-default-value.js');
require('../../../hooks/use-vmodel.js');
require('lodash/kebabCase');
require('../../../hooks/lnode.js');
require('lodash/isEmpty');
require('lodash/camelCase');
require('../../../hooks/render-lnode.js');
require('../../config-provider/useConfig.js');
require('../../config-provider/context.js');
require('../../../chunks/zh_CN.js');
require('../../loading/index.js');
require('../../loading/loading.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../utils/easing.js');
require('../../../utils/render-node.js');
require('../../../utils/transfer-dom.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../../utils/mixins.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../../chunks/defineProperty-838e4192.js');
require('../../../chunks/set-style.js');
require('../../../chunks/helper2.js');
require('../../loading/plugin.js');
require('../../popup/index.js');
require('../../../utils/map-props.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../../utils/helper.js');
require('../../popup/props.js');
require('../../popup/container.js');
require('../../input/index.js');
require('../../input/input.js');
require('@ldesign/icons-vue');
require('../../../utils/event.js');
require('../../input/props.js');
require('../../input/group.js');
require('../../tag/index.js');
require('../../tag/tag.js');
require('../../tag/props.js');
require('../../tag/check-tag.js');
require('../../select-input/index.js');
require('../../select-input/select-input.js');
require('../../select-input/props.js');
require('../../select-input/hooks/use-single.js');
require('lodash/pick');
require('../../../hooks/use-config.js');
require('../../select-input/hooks/use-multiple.js');
require('../../tag-input/index.js');
require('../../tag-input/tag-input.js');
require('../../../hooks/use-global-icon.js');
require('../../tag-input/props.js');
require('../../tag-input/hooks/use-tag-scroll.js');
require('../../tag-input/hooks/use-tag-list.js');
require('../../tag-input/hooks/use-hover.js');
require('../../tag-input/hooks/use-drag-sorter.js');
require('../../select-input/hooks/use-overlay-innerstyle.js');
require('../../common/fake-arrow.js');
require('../../../hooks/use-form-disabled.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('../../../hooks/use-lazy-load.js');
require('../../../chunks/observe.js');
require('../../../hooks/use-common-classname.js');
require('../../select/utils.js');
require('../../select/props.js');
require('../../select/select-panel.js');
require('../../../hooks/use-virtual-scroll.js');
require('../../select/hooks/use-select-options.js');
require('../../select/option-group.js');

var ColorSlider = VueCompositionAPI.defineComponent({
  name: "ColorSlider",
  components: {
    LSelect: components_select_index.Select,
    LOption: components_select_index.Option
  },
  props: {
    ...components_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(props, _ref) {
    let {
      emit
    } = _ref;
    const baseClassName = components_colorPicker_hooks_index.useBaseClassName();
    const refPanel = VueCompositionAPI.ref(null);
    const refThumb = VueCompositionAPI.ref(null);
    const dragInstance = VueCompositionAPI.ref(null);
    const panelRect = VueCompositionAPI.reactive({
      width: constants.SLIDER_DEFAULT_WIDTH
    });
    const styles = VueCompositionAPI.computed(() => {
      const {
        width
      } = panelRect;
      if (!width) return;
      const left = Math.round(props.value / props.maxValue * width);
      return {
        left: `${left}px`,
        color: props.color.rgb
      };
    });
    const handleDrag = (coordinate, isEnded) => {
      if (props.disabled) return;
      const {
        width
      } = panelRect;
      const {
        x
      } = coordinate;
      const value = Math.round(x / width * props.maxValue * 100) / 100;
      props.handleChange(value, isEnded);
      emit("change", value, isEnded);
    };
    const handleDragEnd = coordinate => {
      if (props.disabled) return;
      handleDrag(coordinate, true);
    };
    VueCompositionAPI.onMounted(() => {
      panelRect.width = refPanel.value.offsetWidth || constants.SLIDER_DEFAULT_WIDTH;
      dragInstance.value = new draggable.Draggable(refPanel.value, {
        start: () => {
          panelRect.width = refPanel.value.offsetWidth;
        },
        drag: coordinate => {
          handleDrag(coordinate);
        },
        end: handleDragEnd
      });
    });
    VueCompositionAPI.onBeforeUnmount(() => {
      dragInstance.value.destroy();
    });
    return {
      baseClassName,
      refThumb,
      refPanel,
      styles
    };
  },
  render() {
    const h = arguments[0];
    const {
      baseClassName,
      className,
      railStyle,
      styles,
      type,
      color
    } = this;
    const paddingStyle = {
      background: `linear-gradient(90deg, rgba(0,0,0,.0) 0%, rgba(0,0,0,.0) 93%, ${color.rgb} 93%, ${color.rgb} 100%)`
    };
    return h("div", {
      "class": [`${baseClassName}__slider-wrapper`, `${baseClassName}__slider-wrapper--${type}-type`]
    }, [type === "alpha" && h("div", {
      "class": `${baseClassName}__slider-padding`,
      "style": paddingStyle
    }), h("div", {
      "class": [`${baseClassName}__slider`, className],
      "ref": "refPanel"
    }, [h("div", {
      "class": `${baseClassName}__rail`,
      "style": railStyle
    }), h("span", {
      "class": [`${baseClassName}__thumb`],
      "attrs": {
        "role": "slider",
        "tabindex": 0
      },
      "ref": "refThumb",
      "style": styles
    })])]);
  }
});

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