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 { createEnterKeyHandlerToTriggerClick } from '../../../../utils/accessibility';
/** The VegaImageUploaderDefaultContentRenderer class is a TypeScript React component that renders a button-like element for uploading images. */
export class VegaImageUploaderDefaultContentRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.handleUploaderClick = (e) => {
      e.stopPropagation();
      this.inputController.triggerInputClick();
    };
    /**
     * An event handler that is triggered when files are dropped onto the image uploader drop area.
     *
     * preventDefault() is always called (even when `disabled`) to stop the browser's default
     * behavior of navigating to the dropped file URL — some browsers (e.g., Firefox) will navigate
     * away from the page if a file drop is not preventDefault'd by some handler in the propagation
     * path. stopPropagation() is called because the drop has been consumed by this component and
     * parent containers should not re-process the same files (e.g., a page-level drop handler
     * shouldn't also try to upload them). Parent containers can still observe dragenter/dragover
     * to manage drag overlays and dismiss them via the dragleave/dragend events.
     *
     * @param {DragEvent} e drag event object
     */
    this.dropHandler = (e) => {
      var _a;
      e.preventDefault();
      e.stopPropagation();
      if (this.disabled) {
        return;
      }
      const files = this.dropFileFilterController.process((_a = e.dataTransfer) === null || _a === void 0 ? void 0 : _a.files);
      if (files.length) {
        this.valueController.setValue(files[0]);
      }
    };
    /**
     * Used to prevent the default browser behavior on dragenter/dragover so the element is registered
     * as a valid drop target. stopPropagation() is intentionally omitted here so parent containers
     * can still react to drag events (e.g., page-level drag overlays).
     *
     * @param {DragEvent} e drag event object
     */
    this.handleDragEvent = (e) => {
      e.preventDefault();
    };
  }
  /**
   * The render function returns a div element with a button-like appearance that triggers a click event when clicked or when the enter key is pressed.
   *
   * @returns {HTMLDivElement} The render() method is returning an HTMLDivElement.
   */
  render() {
    return (h("div", { class: "action-wrapper", role: "button", tabIndex: 0, onClick: this.handleUploaderClick, onKeyDown: createEnterKeyHandlerToTriggerClick(), onDrop: this.dropHandler, onDragEnter: this.handleDragEvent, onDragOver: this.handleDragEvent },
      h("vega-icon", { icon: "plus-sign", size: "size-24" }),
      h("div", { class: "vega-image-uploader-text" }, this.translationSlimmer.t(this.actionTitle)),
      this.renderSubtitle()));
  }
  renderSubtitle() {
    return this.actionSubTitle && h("div", { class: "sub-title" }, this.actionSubTitle);
  }
}
__decorate([
  MapToComponentField({ componentFieldName: 'vegaImageUploaderInputController' })
], VegaImageUploaderDefaultContentRenderer.prototype, "inputController", void 0);
__decorate([
  MapToComponentField({ componentFieldName: 'vegaImageUploaderValueController' })
], VegaImageUploaderDefaultContentRenderer.prototype, "valueController", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderDefaultContentRenderer.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderDefaultContentRenderer.prototype, "dropFileFilterController", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderDefaultContentRenderer.prototype, "actionTitle", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderDefaultContentRenderer.prototype, "actionSubTitle", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderDefaultContentRenderer.prototype, "translationSlimmer", void 0);
