import React, { useRef, useState, forwardRef, useImperativeHandle } from 'react'; import { toPng } from 'html-to-image'; import axios from 'axios'; import { useTranslation } from 'react-i18next'; interface ProcessGuideGeneratorProps { projectId?: string; project?: { id: string } | null; // Alternative to projectId onImageGenerated?: (path: string) => void; onGenerate?: () => void; // Alias for backward compatibility shopName?: string; } export interface ProcessGuideRef { generate: () => Promise; } export const ProcessGuideGenerator = forwardRef(({ projectId, project, onImageGenerated, onGenerate, shopName = "MrStitchPrintStudio" }, ref) => { const resolvedProjectId = projectId || project?.id; const { t } = useTranslation(); const elementRef = useRef(null); const [isGenerating, setIsGenerating] = useState(false); useImperativeHandle(ref, () => ({ generate: handleGenerate })); const handleGenerate = async () => { if (!elementRef.current) return; setIsGenerating(true); try { // Give fonts time to load visually if needed, though usually not an issue with simple fonts const dataUrl = await toPng(elementRef.current, { cacheBust: true, pixelRatio: 1 }); // Upload to server const response = await axios.post(`/api/projects/${projectId}/assets/upload`, { file: dataUrl, type: 'mockup', // Treated as mockup folder: 'mockups', filename: `process_guide_${Date.now()}.png` }, { headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` } }); if (response.data.success) { onImageGenerated(response.data.asset.path); } } catch (err) { console.error('Failed to generate process guide:', err); throw err; // Re-throw to let parent know } finally { setIsGenerating(false); } }; return (
{/* This container is what gets captured. It must be visible in DOM but can be hidden by parent overflow/opacity. */} {/* We strictly render ONLY the capture content here. Extra UI is removed. */}
{/* HEADER */}

HOW IT WORKS

{/* STEPS ROW */}
{/* STEP 1 */}

ADD TO CART

Select your digital product and add it to your cart.

{/* STEP 2 */}

CHECKOUT

Complete payment to securely confirm your purchase.

{/* STEP 3 */}

DOWNLOAD

Access your download link in the receipt email.

{/* IMPORTANT NOTICE */}

IMPORTANT:

• This is an INSTANT DOWNLOAD. No physical items will be shipped or sent.

{/* FOOTER */}
{/* Speech Bubble effect */}

Thank you for stopping by!

Our goal is to create products that inspire, uplift, and add a touch of positivity to your life. We hope you find joy in our products, and if you have any questions or feedback, we'd love to hear from you!

{/* Triangle */}
{shopName}
); }); ProcessGuideGenerator.displayName = 'ProcessGuideGenerator';