/* eslint-disable react/display-name */
import { PdfRenderer } from "./PdfRenderer";
import { UnsupportedRenderer } from "./UnsupportedRenderer";
import React from "react";
import { ImageRenderer } from "./ImageRenderer";
import { Attachment } from "../../types";
import { utils } from "../..";


/**
 * Function returning the correct attachment renderer depending on the attachment type. Currently supports:
 * - application/pdf
 * - image/jpeg ( Custom Added )
 * - image/png ( Custom Added )
 * @default use UnsupportedRenderer when no suitable renderer is found
 */
export function fullAttachmentRenderer<D extends Document>(attachment: Attachment): React.FunctionComponent {
  if (utils.isV2Attachment(attachment)){
    switch (attachment.type) {
      case "application/pdf":
        return () => <PdfRenderer attachment={attachment} />;
      case "image/jpeg":
      case "image/png":
        return () => <ImageRenderer attachment={attachment} />;
      default:
        return () => <UnsupportedRenderer attachment={attachment} />;
    }
  } else {
    return () => <UnsupportedRenderer attachment={attachment} />;
  }
 
}
