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

import { defineComponent, ref, reactive, computed, onMounted, onBeforeUnmount } from '@vue/composition-api';
import { d as SLIDER_DEFAULT_WIDTH } from '../../../_chunks/dep-d1f2fda1.js';
import { Select, Option } from '../../select/index.js';
import '../../../_chunks/dep-68c4f269.js';
import { D as Draggable } from '../../../_chunks/dep-2aa8145a.js';
import { useBaseClassName } from '../hooks/index.js';
import baseProps from './base-props.js';
import '../../../utils/with-install.js';
import 'vue';
import 'lodash';
import '../../../config.js';
import '../../select/select.js';
import '../../../_chunks/dep-29915b8e.js';
import 'lodash/isFunction';
import 'lodash/debounce';
import 'lodash/get';
import 'lodash/cloneDeep';
import 'lodash/isArray';
import 'lodash/isObject';
import '../../../_chunks/dep-70c789e5.js';
import '../../../_chunks/dep-5210251b.js';
import '../../../hooks/use-default-value.js';
import '../../../hooks/use-vmodel.js';
import 'lodash/kebabCase';
import '../../../hooks/lnode.js';
import 'lodash/isEmpty';
import 'lodash/camelCase';
import '../../../hooks/render-lnode.js';
import '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import '../../../_chunks/dep-def4c2ce.js';
import '../../loading/index.js';
import '../../loading/loading.js';
import '../../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../../utils/easing.js';
import '../../../utils/render-node.js';
import '../../../utils/transfer-dom.js';
import '../../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../../../utils/mixins.js';
import '../../loading/props.js';
import '../../loading/icon/gradient.js';
import '../../../_chunks/dep-eb467ddf.js';
import '../../../_chunks/dep-cf772670.js';
import '../../../_chunks/dep-47d77fc8.js';
import '../../loading/plugin.js';
import '../../popup/index.js';
import '../../../utils/map-props.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../../utils/helper.js';
import '../../popup/props.js';
import '../../popup/container.js';
import '../../input/index.js';
import '../../input/input.js';
import '@ldesign/icons-vue';
import '../../../utils/event.js';
import '../../input/props.js';
import '../../input/group.js';
import '../../tag/index.js';
import '../../tag/tag.js';
import '../../tag/props.js';
import '../../tag/check-tag.js';
import '../../select-input/index.js';
import '../../select-input/select-input.js';
import '../../select-input/props.js';
import '../../select-input/hooks/use-single.js';
import 'lodash/pick';
import '../../../hooks/use-config.js';
import '../../select-input/hooks/use-multiple.js';
import '../../tag-input/index.js';
import '../../tag-input/tag-input.js';
import '../../../hooks/use-global-icon.js';
import '../../tag-input/props.js';
import '../../tag-input/hooks/use-tag-scroll.js';
import '../../tag-input/hooks/use-tag-list.js';
import '../../tag-input/hooks/use-hover.js';
import '../../tag-input/hooks/use-drag-sorter.js';
import '../../select-input/hooks/use-overlay-innerstyle.js';
import '../../common/fake-arrow.js';
import '../../../hooks/use-form-disabled.js';
import '../../select/option.js';
import '../../../utils/ripple.js';
import '../../checkbox/index.js';
import '../../checkbox/group.js';
import 'lodash/intersection';
import '../../checkbox/checkbox.js';
import '../../checkbox/props.js';
import '../../../hooks/use-lazy-load.js';
import '../../../_chunks/dep-356f585c.js';
import '../../../hooks/use-common-classname.js';
import '../../select/utils.js';
import '../../select/props.js';
import '../../select/select-panel.js';
import '../../../hooks/use-virtual-scroll.js';
import '../../select/hooks/use-select-options.js';
import '../../select/option-group.js';

var ColorSlider = defineComponent({
  name: "ColorSlider",
  components: {
    LSelect: Select,
    LOption: Option
  },
  props: {
    ...baseProps,
    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 = useBaseClassName();
    const refPanel = ref(null);
    const refThumb = ref(null);
    const dragInstance = ref(null);
    const panelRect = reactive({
      width: SLIDER_DEFAULT_WIDTH
    });
    const styles = 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);
    };
    onMounted(() => {
      panelRect.width = refPanel.value.offsetWidth || SLIDER_DEFAULT_WIDTH;
      dragInstance.value = new Draggable(refPanel.value, {
        start: () => {
          panelRect.width = refPanel.value.offsetWidth;
        },
        drag: coordinate => {
          handleDrag(coordinate);
        },
        end: handleDragEnd
      });
    });
    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
    })])]);
  }
});

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