'use strict';

const httpService = require('./httpService-d2e7bf8f.js');
const auth_store = require('./auth.store-1e630a7d.js');

const { state, reset } = auth_store.createStore({
  mediaUploading: false,
});
const mediaStore = { state, reset };

class MediaService {
  constructor() { }
  static getInstance() {
    if (!MediaService.instance) {
      MediaService.instance = new MediaService();
    }
    return MediaService.instance;
  }
  async uploadImage(files) {
    let formData = new FormData();
    for (let i = 0; i < files.length; i++) {
      formData.append("uploads[]", files[i], files[i].name);
    }
    mediaStore.state.mediaUploading = true;
    let result;
    try {
      result = await httpService.HttpService.http.post(`api/v1/MediaItems/Upload`, formData);
      if (result) {
        mediaStore.state.mediaUploading = false;
      }
    }
    catch (e) {
      mediaStore.state.mediaUploading = false;
    }
    return result;
  }
}

exports.MediaService = MediaService;
exports.mediaStore = mediaStore;
