import axios from 'axios';
import { type PostSetTempData } from '../photos-api';

import { API } from '../../../../types';
import { API_URL } from 'src/constants';

export const postSetUploadTemp = async (data: PostSetTempData) => {
  const url = API_URL + '/' + API.UPLOAD_TEMP;
  const formData = new FormData();
  formData.append('token', data.token);
  formData.append('file', data.file as unknown as Blob);

  const config = {
    onUploadProgress: (progressEvent: ProgressEvent) => {
      if (progressEvent.lengthComputable) {
        const progress = progressEvent.loaded / progressEvent.total;
        console.log('Upload progress:', progress);
      }
    }
  };

  try {
    const response = await axios.post(url, formData, config as any);
    return response.data;
  } catch (error) {
    console.error('Error', error);
  }
};
