'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-51e8292e.js');
const media_service = require('./media.service-8a1b9bc5.js');
require('./httpService-d2e7bf8f.js');
require('./auth.store-1e630a7d.js');
require('./overlays-32df265a.js');
require('./ionic-global-2cde9d3a.js');
require('./hardware-back-button-92d97ff8.js');
require('./helpers-c2496722.js');
require('./environment-config.service-c8ff1f3d.js');
require('./token.service-7a41953d.js');
require('./localstorage.service-6346a41d.js');

const sparkleFileUploadCss = "";

const SparkleFileUpload = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fileUploaded = index.createEvent(this, "fileUploaded", 7);
    this.uploadImageLoading = false;
  }
  componentDidLoad() { }
  async uploadImage(evt) {
    this.uploadImageLoading = true;
    var files = evt.target.files;
    let result = await media_service.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 (index.h(index.Host, null, this.uploadedImage ? (index.h("ion-item", { class: "ion-padding", lines: "none" }, index.h("img", { class: "uploaded-image", src: this.uploadedImage }))) : (''), index.h("ion-item", { lines: "none" }, index.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 ? index.h("ion-spinner", { color: "primary" }) : '', index.h("ion-button", { slot: "start", onClick: evt => this.selectFile() }, index.h("ion-icon", { name: "add" }), "Upload Image"))));
  }
  get el() { return index.getElement(this); }
};
SparkleFileUpload.style = sparkleFileUploadCss;

exports.sparkle_file_upload = SparkleFileUpload;
