import { IMAGE_COMPRESS_THRESHOLD } from '#/utils/image-compress';
import { openImageCompressModal } from '#/utils/open-image-compress-modal';

export interface PrepareImageUploadMeta {
  originalSize: number;
  compressedSize?: number;
  usedCompress: boolean;
}

export async function prepareImageForUpload(
  file: File,
): Promise<{ file: File | null; meta?: PrepareImageUploadMeta }> {
  if (file.size <= IMAGE_COMPRESS_THRESHOLD) {
    return {
      file,
      meta: {
        originalSize: file.size,
        usedCompress: false,
      },
    };
  }

  return openImageCompressModal(file);
}
