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, Host } from '@stencil/core';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import ResponsiveFormatFacade from '../../../../helpers/formatter/responsive-map-formatter/responsive-format-facade';
/** The VegaImageUploaderRenderer class is a TypeScript React component that renders a VegaImageUploader with different content based on its status. */
export class VegaImageUploaderRenderer extends VegaSlimmer {
  getImageUploaderContainer() {
    return this.imageUploaderContainerRef;
  }
  /**
   * The render function returns a JSX element that represents a VegaImageUploader component with a disabled border if it is disabled and does not have a value.
   *
   * @returns {VegaImageUploader} The render() function is returning a JSX element of type VegaImageUploader.
   */
  render() {
    return (h(Host, { class: { disabled: this.disabled } },
      this.renderLabelDom(),
      h("div", { ref: (e) => (this.imageUploaderContainerRef = e), class: {
          'vega-image-uploader-select': true,
          'disabled-border': this.disabled && !this.value,
        }, style: {
          width: this.getSize(this.width),
          height: this.getSize(this.height),
        } }, this.renderContentByStatus()),
      this.inputRenderer.render(),
      this.renderHint()));
  }
  renderLabelDom() {
    return (h("vega-field-label", { "is-field-required": this.required, disabled: this.disabled, label: this.label }));
  }
  renderContentByStatus() {
    if (this.status === 'uploading') {
      return this.uploadingContentRenderer.render();
    }
    else {
      const imagePreviewURL = this.previewController.getImagePreviewURL();
      return imagePreviewURL
        ? this.previewContentRenderer.render(imagePreviewURL)
        : this.defaultContentRenderer.render();
    }
  }
  renderHint() {
    return (this.hint && (h("div", { class: "vega-hint" },
      h("label", null, this.hint))));
  }
  getSize(size) {
    if (size) {
      const result = ResponsiveFormatFacade.format(size, 'size');
      return typeof result === 'number' ? `${result}px` : `${result}`;
    }
  }
}
__decorate([
  MapToComponentField({ componentFieldName: 'vegaImageUploaderInputRenderer' })
], VegaImageUploaderRenderer.prototype, "inputRenderer", void 0);
__decorate([
  MapToComponentField({ componentFieldName: 'vegaImageUploaderDefaultContentRenderer' })
], VegaImageUploaderRenderer.prototype, "defaultContentRenderer", void 0);
__decorate([
  MapToComponentField({ componentFieldName: 'vegaImageUploaderPreviewContentRenderer' })
], VegaImageUploaderRenderer.prototype, "previewContentRenderer", void 0);
__decorate([
  MapToComponentField({ componentFieldName: 'vegaImageUploaderUploadingContentRenderer' })
], VegaImageUploaderRenderer.prototype, "uploadingContentRenderer", void 0);
__decorate([
  MapToComponentField({ componentFieldName: 'vegaImageUploaderPreviewController' })
], VegaImageUploaderRenderer.prototype, "previewController", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderRenderer.prototype, "value", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderRenderer.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderRenderer.prototype, "status", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderRenderer.prototype, "label", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderRenderer.prototype, "required", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderRenderer.prototype, "width", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderRenderer.prototype, "height", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderRenderer.prototype, "hint", void 0);
