"use client"; import { useRef, useState } from "react"; import Link from "next/link"; import { QRCodeCanvas } from "qrcode.react"; import { toPng } from "html-to-image"; import { jsPDF } from "jspdf"; import { QR_STAND_PRESETS, type QrStandPreset } from "@menulio/shared"; interface QrStandGeneratorClientProps { restaurantName?: string; logoUrl?: string | null; slug?: string; categoriesList?: string[]; } export function QrStandGeneratorClient({ restaurantName = "THE URBAN BURGER", logoUrl = null, slug = "kebapci-sinan-3", categoriesList = [], }: QrStandGeneratorClientProps) { const [selectedKey, setSelectedKey] = useState("qr-4"); const [downloadingPng, setDownloadingPng] = useState(false); const [downloadingPdf, setDownloadingPdf] = useState(false); const standRef = useRef(null); const activePreset: QrStandPreset = (QR_STAND_PRESETS[selectedKey] || Object.values(QR_STAND_PRESETS)[0])!; const targetUrl = `https://menul.io/${slug}`; const displayCategories = categoriesList.length > 0 ? categoriesList.slice(0, 4) : activePreset.categories; async function handleDownloadPng() { if (!standRef.current) return; setDownloadingPng(true); try { const dataUrl = await toPng(standRef.current, { cacheBust: true, pixelRatio: 3, // 300 DPI high resolution }); const link = document.createElement("a"); link.download = `${slug}-masa-stant-qr.png`; link.href = dataUrl; link.click(); } catch (err) { console.error("PNG indirme hatası:", err); alert("PNG indirilemedi. Lütfen tekrar deneyin."); } finally { setDownloadingPng(false); } } async function handleDownloadPdf() { if (!standRef.current) return; setDownloadingPdf(true); try { const dataUrl = await toPng(standRef.current, { cacheBust: true, pixelRatio: 3, }); // A5 dimensions in mm: 148 x 210 const pdf = new jsPDF({ orientation: "portrait", unit: "mm", format: "a5", }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); pdf.addImage(dataUrl, "PNG", 0, 0, pdfWidth, pdfHeight); pdf.save(`${slug}-masa-stant-a5.pdf`); } catch (err) { console.error("PDF indirme hatası:", err); alert("PDF indirilemedi. Lütfen tekrar deneyin."); } finally { setDownloadingPdf(false); } } return (
{/* Top Navbar */}
MENULIO / Masa Stant QR Jeneratörü
Ana Sayfa →
{/* Main Content Area */}
{/* Left Panel: Preset Selectors & Download Controls */}
{Object.values(QR_STAND_PRESETS).length > 1 && (
1. Stant Teması Seçin

Masa Kartı Şablonları

Restoranınızın konseptine uygun masa stant tasarımını seçin.

{/* Presets List */}
{Object.values(QR_STAND_PRESETS).map((preset) => { const isSelected = preset.key === selectedKey; return ( ); })}
)} {/* Action Download Buttons */}
2. Baskı Çıktısı Alın {/* PNG Download Button */} {/* PDF Download Button */}
{/* Right Panel: Stand Live Visual Canvas Preview */}
{/* Tabletop Plaque Container */} {activePreset.svgTemplateUrl ? (
{/* Exact SVG Template Vector Background Graphic */} {activePreset.name} {/* Dynamic Restaurant Logo & Name Header Overlay */}
{logoUrl ? ( {restaurantName} ) : null} {restaurantName}
{/* Dynamic QR Code Canvas Overlay */}
) : (
{/* Inner Line Accent */}
{/* 01. Brand Badge */}
{logoUrl ? ( {restaurantName} ) : null} {restaurantName}
{/* Scan Action Text */}

DİJİTAL MENÜ
KAMERANIZLA TARATIN

{/* 02. Centered Custom QR Code Box */}
{/* 03. Category Highlights Footer */}
)}
); }