import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import { createVNode as _createVNode } from "vue";
import { computed, defineComponent, shallowRef } from 'vue';
import { ColorBlock } from '../../vc-color-picker';
import classNames from '../../_util/classNames';
import ColorClear from './ColorClear';
import { getAlphaColor } from '../util';
var ColorTrigger = defineComponent({
  name: 'ColorTrigger',
  props: ['prefixCls', 'colorCleared', 'disabled', 'color', 'open', 'showText', 'format'],
  setup: function setup(props, _ref) {
    var expose = _ref.expose;
    var colorTriggerPrefixCls = computed(function () {
      return "".concat(props.prefixCls, "-trigger");
    });
    var containerNode = computed(function () {
      return props.colorCleared ? _createVNode(ColorClear, {
        "prefixCls": props.prefixCls
      }, null) : _createVNode(ColorBlock, {
        "prefixCls": props.prefixCls,
        "color": props.color.toRgbString()
      }, null);
    });
    var genColorString = function genColorString() {
      var hexString = props.color.toHexString().toUpperCase();
      var alpha = 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 = shallowRef();
    var renderText = 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 _createVNode("div", {
        "ref": colorTriggerRef,
        "class": classNames(colorTriggerPrefixCls.value, (_classNames = {}, _defineProperty(_classNames, "".concat(colorTriggerPrefixCls.value, "-active"), props.open), _defineProperty(_classNames, "".concat(colorTriggerPrefixCls.value, "-disabled"), props.disabled), _classNames))
      }, [containerNode.value, props.showText && _createVNode("div", {
        "class": "".concat(colorTriggerPrefixCls.value, "-text")
      }, [renderText.value])]);
    };
  }
});
export default ColorTrigger;