var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { MapToComponentField, MapToComponentMethod, VegaSlimmer } from 'vega-slimmer/core';
/**
 * Controller for handling color format in VegaColorSwatchPicker.
 */
export class ColorSwatchPickerColorFormatController extends VegaSlimmer {
  /**
   * watch the prop, update the internal color when changes.
   */
  updateTheColor() {
    if (this.internalColor) {
      this.colorSwatchPickerValueController.updateInternalColor(this.formatColor('input', this.internalColor));
    }
  }
  /**
   * Formats a color value based on the specified color stage type.
   *
   * @param {VegaColorStageType} colorStageType - The stage of color processing ('input' or 'output').
   * @param {string} color - The color value to format.
   * @returns {string} The formatted color value.
   */
  formatColor(colorStageType, color) {
    if (this.inputFormatter === ColorSwatchPickerColorFormatController.DEFAULT_INPUT_FORMATTER) {
      return this.handleHexFormat(colorStageType, color);
    }
    else if (typeof this.inputFormatter === 'function') {
      return this.inputFormatter(colorStageType, color);
    }
    return color;
  }
  /**
   * Handles the formatting of a color value when the inputFormatter is set to 'hexColorFormatter'.
   *
   * @param {VegaColorStageType} colorStageType The stage of color processing ('input' or 'output').
   * @param {string} color The color value to format.
   * @returns {string} The formatted color value.
   */
  handleHexFormat(colorStageType, color) {
    if (colorStageType === 'input') {
      return color.startsWith('#') ? color.slice(1) : color;
    }
    else {
      return color.startsWith('#') ? color : color ? `#${color}` : color;
    }
  }
}
ColorSwatchPickerColorFormatController.DEFAULT_INPUT_FORMATTER = 'hexColorFormatter';
__decorate([
  MapToComponentField()
], ColorSwatchPickerColorFormatController.prototype, "inputFormatter", void 0);
__decorate([
  MapToComponentField()
], ColorSwatchPickerColorFormatController.prototype, "internalColor", void 0);
__decorate([
  MapToComponentField()
], ColorSwatchPickerColorFormatController.prototype, "colorSwatchPickerValueController", void 0);
__decorate([
  MapToComponentMethod('watchInputFormatter')
], ColorSwatchPickerColorFormatController.prototype, "updateTheColor", null);
