"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _vue = require("vue");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _vcColorPicker = require("../../vc-color-picker");
var _classNames2 = _interopRequireDefault(require("../../_util/classNames"));
var _ColorClear = _interopRequireDefault(require("./ColorClear"));
var _util = require("../util");
var ColorTrigger = (0, _vue.defineComponent)({
  name: 'ColorTrigger',
  props: ['prefixCls', 'colorCleared', 'disabled', 'color', 'open', 'showText', 'format'],
  setup: function setup(props, _ref) {
    var expose = _ref.expose;
    var colorTriggerPrefixCls = (0, _vue.computed)(function () {
      return "".concat(props.prefixCls, "-trigger");
    });
    var containerNode = (0, _vue.computed)(function () {
      return props.colorCleared ? (0, _vue.createVNode)(_ColorClear.default, {
        "prefixCls": props.prefixCls
      }, null) : (0, _vue.createVNode)(_vcColorPicker.ColorBlock, {
        "prefixCls": props.prefixCls,
        "color": props.color.toRgbString()
      }, null);
    });
    var genColorString = function genColorString() {
      var hexString = props.color.toHexString().toUpperCase();
      var alpha = (0, _util.getAlphaColor)(props.color);
      switch (props.format) {
        case 'rgb':
          return props.color.toRgbString();
        case 'hsb':
          return props.color.toHsbString();
        case 'hex':
        default:
          return alpha < 100 ? "".concat(hexString.slice(0, 7), ",").concat(alpha, "%") : hexString;
      }
    };
    var colorTriggerRef = (0, _vue.shallowRef)();
    var renderText = (0, _vue.computed)(function () {
      if (typeof props.showText === 'function') {
        return props.showText(props.color);
      }
      if (props.showText) {
        return genColorString();
      }
      return null;
    });
    expose({
      colorTriggerRef: colorTriggerRef
    });
    return function () {
      var _classNames;
      return (0, _vue.createVNode)("div", {
        "ref": colorTriggerRef,
        "class": (0, _classNames2.default)(colorTriggerPrefixCls.value, (_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(colorTriggerPrefixCls.value, "-active"), props.open), (0, _defineProperty2.default)(_classNames, "".concat(colorTriggerPrefixCls.value, "-disabled"), props.disabled), _classNames))
      }, [containerNode.value, props.showText && (0, _vue.createVNode)("div", {
        "class": "".concat(colorTriggerPrefixCls.value, "-text")
      }, [renderText.value])]);
    };
  }
});
var _default = ColorTrigger;
exports.default = _default;