import React, {ReactNode} from 'react';
import FormButtonSave from "../Forms/FormButton/FormButtonSave";
import {PDFForm} from 'pdf-lib';
import useDownloadFilledPetition from "./useDownloadFilledPetition";
import {getDocument} from "../../../API/dynamic-forms";

type DownloadPdfProps = {
    children?: ReactNode
    data: any,
    form_id: string | number
    form_name: string
    type: string
    docId?:any
}

const DownloadPdf = ({data, form_id,docId, form_name, type}: DownloadPdfProps) => {
    const [downloadPetition] = useDownloadFilledPetition()

    const downloadDocument = async (id: string, type: string) => {
        const res = await getDocument(id);
        const res2 = await downloadPetition(res.data.form.id.toString(), res.data.form_data, res.data.form.name, type);

    }


    return (
        <>
            <FormButtonSave
                onClick={() => {
                    downloadDocument(docId, type)
                }}
            >
                {
                    type === 'unsealed' ? 'DOWNLOAD PDF' : 'DOWNLOAD SEALED PDF'
                }
            </FormButtonSave>
        </>

    );
}

export default DownloadPdf;
