"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _vue = require("vue");
var _util = require("../util");
var _ColorSteppers = _interopRequireDefault(require("./ColorSteppers"));
var ColorAlphaInput = (0, _vue.defineComponent)({
  name: 'ColorAlphaInput',
  props: ['prefixCls', 'value', 'onChange'],
  setup: function setup(props) {
    var colorAlphaInputPrefixCls = (0, _vue.computed)(function () {
      return "".concat(props.prefixCls, "-alpha-input");
    });
    var alphaValue = (0, _vue.ref)((0, _util.generateColor)(props.value || '#000'));
    (0, _vue.watch)(function () {
      return props.value;
    }, function (val) {
      if (val) {
        alphaValue.value = (0, _util.generateColor)(val);
      }
    }, {
      immediate: true
    });
    var handleAlphaChange = function handleAlphaChange(step) {
      var _props$onChange;
      var hsba = alphaValue.value.toHsb();
      hsba.a = (step || 0) / 100;
      var genColor = (0, _util.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 (0, _vue.createVNode)(_ColorSteppers.default, {
        "value": (0, _util.getAlphaColor)(alphaValue.value),
        "prefixCls": props.prefixCls,
        "formatter": function formatter(step) {
          return "".concat(step, "%");
        },
        "class": colorAlphaInputPrefixCls.value,
        "onChange": handleAlphaChange,
        "min": 0,
        "max": 100
      }, null);
    };
  }
});
var _default = ColorAlphaInput;
exports.default = _default;