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 { h } from '@stencil/core';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { DomNodeSubjectObserverFactory } from '../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-observer-factory';
import { VegaClick } from '../../../../helpers/event-manager/event-id/vega-event-id';
/** The `VegaImageUploaderActionsRenderer` class is a TypeScript React component that renders action buttons for an image uploader component. */
export class VegaImageUploaderActionsRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    /**
     * render the action button by action type, preview button, delete button
     *
     * @param {UploaderActionTypes} actionType action type
     * @returns {HTMLVegaButtonCircleElement} tooltip element
     */
    this.renderActionButton = (actionType) => {
      const options = this.getButtonOptions(actionType);
      return (h("vega-button-circle", Object.assign({ size: "small", variant: "icon-only", iconColor: this.isInDarkMode ? 'text-primary' : 'text-inverted-primary', role: "menuitem", ref: (ref) => {
          DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaClick, () => {
            this.handleClick(actionType);
          });
        } }, options)));
    };
  }
  /**
   * The handleClick function takes a type parameter and performs different actions based on the value of the type.
   *
   * @param {string} type - The `type` parameter is a string that represents the type of action to be performed. It can have one of the following values: 'Preview', 'Delete', or 'Replace'.
   */
  handleClick(type) {
    switch (type) {
      case 'Preview':
        this.previewController.showPreview();
        break;
      case 'Delete':
        this.removeController.showRemoveDialog();
        break;
      case 'Replace':
        this.inputController.triggerInputClick();
        break;
    }
  }
  /**
   * The render function returns a span element with action buttons based on certain conditions.
   *
   * @returns {HTMLSpanElement | null} an HTMLSpanElement if the condition "withActions" is true. Otherwise, it returns null.
   */
  render() {
    const withActions = this.showRemoveButton || this.showPreviewButton || this.showReplaceButton;
    return withActions ? (h("span", { class: "actions" },
      this.showPreviewButton && this.renderActionButton('Preview'),
      this.showReplaceButton && !this.disabled && this.renderActionButton('Replace'),
      this.showRemoveButton && !this.disabled && this.renderActionButton('Delete'))) : null;
  }
  /**
   * get action button props icon, onClick, label by action type
   *
   * @param {UploaderActionTypes} actionType action type
   * @returns {Nullable<ActionButtonOptions>} the options result
   */
  getButtonOptions(actionType) {
    let options;
    switch (actionType) {
      case 'Preview':
        options = {
          icon: 'zoom-in',
          label: actionType,
        };
        break;
      case 'Delete':
        options = {
          icon: 'delete-bin',
          label: actionType,
        };
        break;
      case 'Replace':
        options = {
          icon: 'photo',
          label: actionType,
        };
        break;
      /* istanbul ignore next */
      default:
        break;
    }
    return options;
  }
}
__decorate([
  MapToComponentField({ componentFieldName: 'vegaImageUploaderInputController' })
], VegaImageUploaderActionsRenderer.prototype, "inputController", void 0);
__decorate([
  MapToComponentField({ componentFieldName: 'vegaImageUploaderValueController' })
], VegaImageUploaderActionsRenderer.prototype, "valueController", void 0);
__decorate([
  MapToComponentField({ componentFieldName: 'vegaImageUploaderPreviewController' })
], VegaImageUploaderActionsRenderer.prototype, "previewController", void 0);
__decorate([
  MapToComponentField({ componentFieldName: 'vegaImageUploaderRemoveController' })
], VegaImageUploaderActionsRenderer.prototype, "removeController", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderActionsRenderer.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderActionsRenderer.prototype, "showPreviewButton", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderActionsRenderer.prototype, "showRemoveButton", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderActionsRenderer.prototype, "showReplaceButton", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderActionsRenderer.prototype, "removeEventEmitter", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderActionsRenderer.prototype, "isInDarkMode", void 0);
