import { r as registerInstance, i as createEvent, h, H as Host, e as getElement } from './index-c04b9ed5.js';
import { M as MediaService } from './media.service-6e90bc41.js';
import './httpService-7986aeed.js';
import './auth.store-dba2c2da.js';
import './overlays-4233a39d.js';
import './ionic-global-4903e23e.js';
import './hardware-back-button-fa04d6e9.js';
import './helpers-bf0e23d6.js';
import './environment-config.service-b191f276.js';
import './token.service-71a5d33f.js';
import './localstorage.service-4bf408c8.js';

const sparkleFileUploadCss = "";

const SparkleFileUpload = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.fileUploaded = createEvent(this, "fileUploaded", 7);
    this.uploadImageLoading = false;
  }
  componentDidLoad() { }
  async uploadImage(evt) {
    this.uploadImageLoading = true;
    var files = evt.target.files;
    let result = await MediaService.getInstance().uploadImage(files);
    if (result.Succeeded) {
      console.log(result);
      this.uploadImageLoading = false;
      this.uploadedImage = result.Data.length > 0 ? result.Data[0].FullImageUrl : '';
      this.value = this.uploadedImage;
      this.fileUploaded.emit(this.uploadedImage);
    }
    else {
      this.uploadImageLoading = false;
      this.errorMessage = 'There is an error while uploading an image.';
    }
  }
  selectFile() {
    var fileInput = this.el.shadowRoot.querySelector('#fileInput');
    fileInput.click();
  }
  render() {
    return (h(Host, null, this.uploadedImage ? (h("ion-item", { class: "ion-padding", lines: "none" }, h("img", { class: "uploaded-image", src: this.uploadedImage }))) : (''), h("ion-item", { lines: "none" }, h("input", { type: "file", id: "fileInput", onChange: evt => this.uploadImage(evt), style: { display: 'none' }, accept: "image/*,application/pdf,application/msword,application/vnd.ms-excel,application/vnd.ms-powerpoint,text/plain" }), this.uploadImageLoading ? h("ion-spinner", { color: "primary" }) : '', h("ion-button", { slot: "start", onClick: evt => this.selectFile() }, h("ion-icon", { name: "add" }), "Upload Image"))));
  }
  get el() { return getElement(this); }
};
SparkleFileUpload.style = sparkleFileUploadCss;

export { SparkleFileUpload as sparkle_file_upload };
