// frontend/src/services/pdfExport.js
import html2pdf from 'html2pdf.js';

export const exportToPDF = async (element, template) => {
    const opt = {
        margin: [0.5, 0.5, 0.5, 0.5],
        filename: `resume_${Date.now()}.pdf`,
        image: { type: 'jpeg', quality: 0.98 },
        html2canvas: { scale: 2, letterRendering: true, useCORS: true },
        jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' }
    };
    
    const elementClone = element.cloneNode(true);
    elementClone.style.padding = '0.5in';
    elementClone.classList.add(`template-${template}`);
    document.body.appendChild(elementClone);
    
    await html2pdf().set(opt).from(elementClone).save();
    document.body.removeChild(elementClone);
};