import { createVNode as _createVNode } from "vue";
import { computed, defineComponent, ref, watch } from 'vue';
import { getRoundNumber } from '../../vc-color-picker/color';
import { generateColor } from '../util';
import ColorSteppers from './ColorSteppers';
var ColorHsbInput = defineComponent({
  name: 'ColorHsbInput',
  props: ['prefixCls', 'value', 'onChange'],
  setup: function setup(props) {
    var colorHsbInputPrefixCls = computed(function () {
      return "".concat(props.prefixCls, "-hsb-input");
    });
    var hsbValue = ref(generateColor(props.value || '#000'));
    watch(function () {
      return props.value;
    }, function (val) {
      if (val) {
        hsbValue.value = generateColor(val || '#000');
      }
    }, {
      immediate: true
    });
    var handleHsbChange = function handleHsbChange(step, type) {
      var _props$onChange;
      var hsb = hsbValue.value.toHsb();
      hsb[type] = type === 'h' ? step : (step || 0) / 100;
      var genColor = generateColor(hsb);
      if (!props.value) {
        hsbValue.value = genColor;
      }
      (_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, genColor);
    };
    return function () {
      return _createVNode("div", {
        "class": colorHsbInputPrefixCls.value
      }, [_createVNode(ColorSteppers, {
        "max": 360,
        "min": 0,
        "value": Number(hsbValue.value.toHsb().h),
        "prefixCls": props.prefixCls,
        "class": colorHsbInputPrefixCls.value,
        "formatter": function formatter(step) {
          return getRoundNumber(step || 0).toString();
        },
        "onChange": function onChange(step) {
          return handleHsbChange(Number(step), 'h');
        }
      }, null), _createVNode(ColorSteppers, {
        "max": 100,
        "min": 0,
        "value": Number(hsbValue.value.toHsb().s) * 100,
        "prefixCls": props.prefixCls,
        "class": colorHsbInputPrefixCls.value,
        "formatter": function formatter(step) {
          return "".concat(getRoundNumber(step || 0), "%");
        },
        "onChange": function onChange(step) {
          return handleHsbChange(Number(step), 's');
        }
      }, null), _createVNode(ColorSteppers, {
        "max": 100,
        "min": 0,
        "value": Number(hsbValue.value.toHsb().b) * 100,
        "prefixCls": props.prefixCls,
        "class": colorHsbInputPrefixCls.value,
        "formatter": function formatter(step) {
          return "".concat(getRoundNumber(step || 0), "%");
        },
        "onChange": function onChange(step) {
          return handleHsbChange(Number(step), 'b');
        }
      }, null)]);
    };
  }
});
export default ColorHsbInput;