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';
import { VegaDialog } from '../../../../helpers/dialog/vega-dialog-controller';
/** The `VegaImageUploaderRemoveController` class is responsible for handling the removal of images from the `VegaImageUploader` component. */
export class VegaImageUploaderRemoveController extends VegaSlimmer {
  constructor() {
    super(...arguments);
    /*
     * The below method is e2e-test covered in
     * @see{module:image-file-should-be-removed-when-click-the-remove-button}
     */
    /* istanbul ignore next */
    /**
     * open a vega dialog confirm remove the file
     */
    this.showRemoveDialog = () => {
      this.removeDialogRef = VegaDialog.open({
        type: 'danger',
        title: 'Delete Image',
        content: 'Are you sure you want to delete this image?',
        // eslint-disable-next-line jsdoc/require-jsdoc
        handleOk: () => {
          this.handleRemoveFile();
          return true;
        },
        okButton: {
          label: 'Delete',
        },
      });
    };
    /** The `handleRemoveFile` method is responsible for removing the image from the `VegaImageUploader` component. */
    this.handleRemoveFile = () => {
      this.valueController.setValue(null);
      this.removeEventEmitter.emit();
    };
  }
  /**
   * remove the dialog when element destroy
   */
  disconnectedCallback() {
    var _a;
    /* istanbul ignore next */
    (_a = this.removeDialogRef) === null || _a === void 0 ? void 0 : _a.remove();
  }
}
__decorate([
  MapToComponentField({ componentFieldName: 'vegaImageUploaderValueController' })
], VegaImageUploaderRemoveController.prototype, "valueController", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderRemoveController.prototype, "removeEventEmitter", void 0);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], VegaImageUploaderRemoveController.prototype, "disconnectedCallback", null);
