"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 ColorRgbInput = (0, _vue.defineComponent)({
  name: 'ColorRgbInput',
  props: ['prefixCls', 'value', 'onChange'],
  setup: function setup(props) {
    var colorRgbInputPrefixCls = (0, _vue.computed)(function () {
      return "".concat(props.prefixCls, "-rgb-input");
    });
    var rgbValue = (0, _vue.ref)((0, _util.generateColor)(props.value || '#000'));
    (0, _vue.watch)(function () {
      return props.value;
    }, function (val) {
      if (val) {
        rgbValue.value = (0, _util.generateColor)(val || '#000');
      }
    }, {
      immediate: true
    });
    var handleRgbChange = function handleRgbChange(step, type) {
      var _props$onChange;
      var rgb = rgbValue.value.toRgb();
      rgb[type] = step || 0;
      var genColor = (0, _util.generateColor)(rgb);
      if (!props.value) {
        rgbValue.value = genColor;
      }
      (_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, genColor);
    };
    return function () {
      return (0, _vue.createVNode)("div", {
        "class": colorRgbInputPrefixCls.value
      }, [(0, _vue.createVNode)(_ColorSteppers.default, {
        "max": 255,
        "min": 0,
        "value": Number(rgbValue.value.toRgb().r),
        "prefixCls": props.prefixCls,
        "class": colorRgbInputPrefixCls.value,
        "onChange": function onChange(step) {
          return handleRgbChange(Number(step), 'r');
        }
      }, null), (0, _vue.createVNode)(_ColorSteppers.default, {
        "max": 255,
        "min": 0,
        "value": Number(rgbValue.value.toRgb().g),
        "prefixCls": props.prefixCls,
        "class": colorRgbInputPrefixCls.value,
        "onChange": function onChange(step) {
          return handleRgbChange(Number(step), 'g');
        }
      }, null), (0, _vue.createVNode)(_ColorSteppers.default, {
        "max": 255,
        "min": 0,
        "value": Number(rgbValue.value.toRgb().b),
        "prefixCls": props.prefixCls,
        "class": colorRgbInputPrefixCls.value,
        "onChange": function onChange(step) {
          return handleRgbChange(Number(step), 'b');
        }
      }, null)]);
    };
  }
});
var _default = ColorRgbInput;
exports.default = _default;