import { createVNode as _createVNode } from "vue";
import { computed, defineComponent, ref, watch } from 'vue';
import { generateColor, getAlphaColor } from '../util';
import ColorSteppers from './ColorSteppers';
var ColorAlphaInput = defineComponent({
  name: 'ColorAlphaInput',
  props: ['prefixCls', 'value', 'onChange'],
  setup: function setup(props) {
    var colorAlphaInputPrefixCls = computed(function () {
      return "".concat(props.prefixCls, "-alpha-input");
    });
    var alphaValue = ref(generateColor(props.value || '#000'));
    watch(function () {
      return props.value;
    }, function (val) {
      if (val) {
        alphaValue.value = generateColor(val);
      }
    }, {
      immediate: true
    });
    var handleAlphaChange = function handleAlphaChange(step) {
      var _props$onChange;
      var hsba = alphaValue.value.toHsb();
      hsba.a = (step || 0) / 100;
      var genColor = generateColor(hsba);
      if (!props.value) {
        alphaValue.value = genColor;
      }
      (_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, genColor);
    };
    return function () {
      return _createVNode(ColorSteppers, {
        "value": getAlphaColor(alphaValue.value),
        "prefixCls": props.prefixCls,
        "formatter": function formatter(step) {
          return "".concat(step, "%");
        },
        "class": colorAlphaInputPrefixCls.value,
        "onChange": handleAlphaChange,
        "min": 0,
        "max": 100
      }, null);
    };
  }
});
export default ColorAlphaInput;