import React, {ReactNode} from 'react';
import pdfIcon from '../../../assets/images/pdf_icon.png'
import pngIcon from '../../../assets/images/png_icon.png'

type DocumentAttachmentsProps = {
    attachments: string[]
}


const MimeIconMap:any = {
    'image/png': pngIcon,
    'application/pdf' : pdfIcon
}


const DocumentAttachments = ({attachments}: DocumentAttachmentsProps) => {


    // attachments.forEach(async (at)=>{
    //     fetch(at)
    //         .then(res => res.blob())
    //         .then(console.log)
    // })




    return (
        <div className={'document-attachments'}>
            {
                attachments.map((a:any)=>

                        <a download={a.name} href={`data:${a.mime};base64,${a.base64}`}>
                            <img src={MimeIconMap[a.mime]}  height={64}/>
                            <span>{a.name}</span>
                        </a>


                )
            }
        </div>
    );
}

export default DocumentAttachments;