import { Attachment } from 'src/types/attachments';
import { isPdf } from 'src/utils/files';

import FileAttachment from 'src/components/attachment/FileAttachment';
import PdfAttachment from 'src/components/attachment/PdfAttachment';

type FileProps = {
  file: Attachment;
  isLoading?: boolean;
};

const File = ({ file, isLoading = false }: FileProps) => {
  const extension = file.name.split('.')[1];

  if (isPdf(extension)) {
    return (
      <PdfAttachment
        file={file}
        isLoading={isLoading}
      />
    );
  }

  return (
    <FileAttachment
      file={file}
      extension={extension}
      isLoading={isLoading}
    />
  );
};

export default File;
