PageSourceSearch

https://www.karispizza.fi/assets/BrochureGeneratorPage-96acad7c.js

js karispizza.fi collected 2026-10-03 02:47:47 UTC 47,910 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-radix-08a60bdd.js";import{r as t}from"./vendor-react-9016e4a2.js";import{t as o}from"./index-2c661f14.js";import{aY as s,s as a}from"./index-06245da3.js";import{read as n,utils as r}from"./xlsx-99ffde2f.js";import{F as i,D as l,P as c,I as d,V as m,T as h,b as f,S as u,R as p,p as x}from"./react-pdf.browser-6ac7e1dd.js";import"./vendor-supabase-36eb0853.js";import"./vendor-capacitor-43d743f6.js";import"./vendor-icons-f2656d21.js";import"./vendor-motion-a26fe6c4.js";import"./_commonjs-dynamic-modules-3e972b61.js";const g=[{id:"hero-feast",name:"Hero Feast",description:"Suuri hero-kuva edessä, ruokalista takana",thumbnail:"🍽️",category:"photo-heavy",front:{layout:"hero-image",heroImagePosition:"full",overlayGradient:"linear-gradient(to bottom, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0.7) 60%, rgba(0,0,0,0.9) 100%)",headlinePosition:"bottom-left",maxFeaturedItems:3,showPrices:!0,showDescriptions:!0,accentColor:"#E63946",bgColor:"#1a1a2e",textColor:"#ffffff",fontSizes:{headline:36,subheadline:16,itemName:14,price:14,description:11}},back:{layout:"grid-cards",columns:2,maxItems:8,showDescriptions:!0,showAllergens:!0,showCategories:!0,showQR:!0,showContactInfo:!0,bgColor:"#ffffff",textColor:"#1a1a2e",accentColor:"#E63946",cardBgColor:"#f8f9fa",fontSizes:{categoryTitle:16,itemName:12,price:12,description:10,contact:9}},capacity:{frontItems:3,backItems:8,hasDescription:!0}},{id:"nordic-clean",name:"Nordic Clean",description:"Skandinaavinen minimalismi, paljon valkoista tilaa",thumbnail:"🇫🇮",category:"minimalist",front:{layout:"split-horizontal",imagePosition:"top-half",overlayGradient:"none",headlinePosition:"center",maxFeaturedItems:2,showPrices:!0,showDescriptions:!0,accentColor:"#2B6CB0",bgColor:"#FAFBFC",textColor:"#1A202C",fontSizes:{headline:32,subheadline:14,itemName:13,price:13,description:11}},back:{layout:"list-clean",columns:1,maxItems:10,showDescriptions:!0,showAllergens:!0,showCategories:!0,showQR:!0,showContactInfo:!0,bgColor:"#FAFBFC",textColor:"#1A202C",accentColor:"#2B6CB0",cardBgColor:"#ffffff",fontSizes:{categoryTitle:15,itemName:12,price:12,description:10,contact:9}},capacity:{frontItems:2,backItems:10,hasDescription:!0}},{id:"dark-elegance",name:"Dark Elegance",description:"Tumma luksus, kultaiset korostukset",thumbnail:"✨",category:"luxury",front:{layout:"centered-overlay",heroImagePosition:"full",overlayGradient:"linear-gradient(180deg, rgba(15,15,15,0.3) 0%, rgba(15,15,15,0.85) 100%)",headlinePosition:"center",maxFeaturedItems:4,showPrices:!0,showDescriptions:!0,accentColor:"#D4A853",bgColor:"#0f0f0f",textColor:"#f5f0e8",fontSizes:{headline:34,subheadline:14,itemName:13,price:13,description:10}},back:{layout:"grid-cards",columns:2,maxItems:8,showDescriptions:!0,showAllergens:!0,showCategories:!0,showQR:!0,showContactInfo:!0,bgColor:"#0f0f0f",textColor:"#f5f0e8",accentColor:"#D4A853",cardBgColor:"#1a1a1a",fontSizes:{categoryTitle:16,itemName:12,price:12,description:10,contact:9}},capacity:{frontItems:4,backItems:8,hasDescription:!0}},{id:"fresh-bistro",name:"Fresh Bistro",description:"Raikas ja värikäs bistro-tyyli",thumbnail:"🥗",category:"colorful",front:{layout:"collage",heroImagePosition:"collage-3",overlayGradient:"none",headlinePosition:"top-center",maxFeaturedItems:3,showPrices:!0,showDescriptions:!1,accentColor:"#38A169",bgColor:"#FFF8F0",textColor:"#2D3748",fontSizes:{headline:34,subheadline:15,itemName:13,price:13,description:10}},back:{layout:"list-clean",columns:2,maxItems:10,showDescriptions:!0,showAllergens:!0,showCategories:!0,showQR:!0,showContactInfo:!0,bgColor:"#FFF8F0",textColor:"#2D3748",accentColor:"#38A169",cardBgColor:"#ffffff",fontSizes:{categoryTitle:15,itemName:12,price:12,description:10,contact:9}},capacity:{frontItems:3,backItems:10,hasDescription:!0}},{id:"retro-diner",name:"Retro Diner",description:"50-luvun amerikkalainen diner-tyyli",thumbnail:"🍔",category:"retro",front:{layout:"banner-style",heroImagePosition:"center-circle",overlayGradient:"none",headlinePosition:"top-center",maxFeaturedItems:3,showPrices:!0,showDescriptions:!1,accentColor:"#E53E3E",bgColor:"#FFF5E6",textColor:"#2D2D2D",fontSizes:{headline:38,subheadline:16,itemName:14,price:14,description:11}},back:{layout:"grid-cards",columns:2,maxItems:8,showDescriptions:!0,showAllergens:!0,showCategories:!0,showQR:!0,showContactInfo:!0,bgColor:"#FFF5E6",textColor:"#2D2D2D",accentColor:"#E53E3E",cardBgColor:"#ffffff",fontSizes:{categoryTitle:16,itemName:12,price:12,description:10,contact:9}},capacity:{frontItems:3,backItems:8,hasDescription:!0}
1},{id:"urban-modern",name:"Urban Modern",description:"Kaupunkityylinen moderni ulkoasu",thumbnail:"🏙️",category:"modern",front:{layout:"asymmetric",heroImagePosition:"right-60",overlayGradient:"linear-gradient(to right, rgba(26,32,44,0.95) 0%, rgba(26,32,44,0.4) 50%, transparent 100%)",headlinePosition:"left-center",maxFeaturedItems:3,showPrices:!0,showDescriptions:!0,accentColor:"#ED8936",bgColor:"#1A202C",textColor:"#ffffff",fontSizes:{headline:32,subheadline:14,itemName:13,price:13,description:10}},back:{layout:"magazine",columns:2,maxItems:8,showDescriptions:!0,showAllergens:!0,showCategories:!0,showQR:!0,showContactInfo:!0,bgColor:"#F7FAFC",textColor:"#1A202C",accentColor:"#ED8936",cardBgColor:"#ffffff",fontSizes:{categoryTitle:15,itemName:12,price:12,description:10,contact:9}},capacity:{frontItems:3,backItems:8,hasDescription:!0}},{id:"garden-organic",name:"Garden Organic",description:"Luomu ja luontoystävällinen ilme",thumbnail:"🌿",category:"organic",front:{layout:"split-horizontal",imagePosition:"bottom-half",overlayGradient:"none",headlinePosition:"top-center",maxFeaturedItems:2,showPrices:!0,showDescriptions:!0,accentColor:"#276749",bgColor:"#F0FFF4",textColor:"#22543D",fontSizes:{headline:30,subheadline:14,itemName:13,price:13,description:11}},back:{layout:"list-clean",columns:1,maxItems:10,showDescriptions:!0,showAllergens:!0,showCategories:!0,showQR:!0,showContactInfo:!0,bgColor:"#F0FFF4",textColor:"#22543D",accentColor:"#276749",cardBgColor:"#ffffff",fontSizes:{categoryTitle:15,itemName:12,price:12,description:10,contact:9}},capacity:{frontItems:2,backItems:10,hasDescription:!0}},{id:"neon-night",name:"Neon Night",description:"Neon-valotettu yökerho-tyyli",thumbnail:"🌃",category:"nightlife",front:{layout:"hero-image",heroImagePosition:"full",overlayGradient:"linear-gradient(135deg, rgba(76,29,149,0.8) 0%, rgba(17,24,39,0.9) 50%, rgba(190,24,93,0.6) 100%)",headlinePosition:"center",maxFeaturedItems:4,showPrices:!0,showDescriptions:!1,accentColor:"#F472B6",bgColor:"#0F172A",textColor:"#ffffff",fontSizes:{headline:36,subheadline:15,itemName:14,price:14,description:11}},back:{layout:"grid-cards",columns:2,maxItems:8,showDescriptions:!0,showAllergens:!0,showCategories:!0,showQR:!0,showContactInfo:!0,bgColor:"#0F172A",textColor:"#E2E8F0",accentColor:"#F472B6",cardBgColor:"#1E293B",fontSizes:{categoryTitle:16,itemName:12,price:12,description:10,contact:9}},capacity:{frontItems:4,backItems:8,hasDescription:!0}},{id:"classic-italian",name:"Classic Italian",description:"Klassinen italialainen trattoria",thumbnail:"🍕",category:"classic",front:{layout:"centered-overlay",heroImagePosition:"full",overlayGradient:"linear-gradient(to bottom, rgba(139,69,19,0.2) 0%, rgba(139,69,19,0.7) 100%)",headlinePosition:"center",maxFeaturedItems:3,showPrices:!0,showDescriptions:!0,accentColor:"#C05621",bgColor:"#FFFAF0",textColor:"#ffffff",fontSizes:{headline:36,subheadline:15,itemName:14,price:14,description:11}},back:{layout:"list-clean",columns:2,maxItems:10,showDescriptions:!0,showAllergens:!0,showCategories:!0,showQR:!0,showContactInfo:!0,bgColor:"#FFFAF0",textColor:"#2D2D2D",accentColor:"#C05621",cardBgColor:"#FFF8F0",fontSizes:{categoryTitle:16,itemName:12,price:12,description:10,contact:9}},capacity:{frontItems:3,backItems:10,hasDescription:!0}},{id:"photo-grid",name:"Photo Grid",description:"Iso kuvagalleria molemmilla puolilla",thumbnail:"📸",category:"photo-heavy",front:{layout:"photo-grid",heroImagePosition:"grid-4",overlayGradient:"linear-gradient(to bottom, transparent 0%, rgba(0,0,0,0.6) 100%)",headlinePosition:"bottom-center",maxFeaturedItems:4,showPrices:!0,showDescriptions:!1,accentColor:"#4299E1",bgColor:"#ffffff",textColor:"#1A202C",fontSizes:{headline:32,subheadline:14,itemName:13,price:13,description:10}},back:{layout:"grid-cards",columns:2,maxItems:6,showDescriptions:!0,showAllergens:!0,showCategories:!0,showQR:!0,showContactInfo:!0,bgColor:"#ffffff",textColor:"#1A202C",accentColor:"#4299E1",cardBgColor:"#F7FAFC",fontSizes:{categoryTitle:15,itemName:12,price:12,description:10,contact:9}},capacity:{frontItems:4,backItems:6,hasDescription:!0}
1}];function b(e){return g.find(t=>t.id===e)||g[0]}function y(e){return b(e).capacity}const j={gluten:{emoji:"🌾",label:"Gluteeni"},lactose:{emoji:"🥛",label:"Laktoosi"},nuts:{emoji:"🥜",label:"Pähkinä"},eggs:{emoji:"🥚",label:"Kananmuna"},fish:{emoji:"🐟",label:"Kala"},soy:{emoji:"🫘",label:"Soija"},celery:{emoji:"🥬",label:"Selleri"},mustard:{emoji:"🟡",label:"Sinappi"},sesame:{emoji:"⚪",label:"Seesami"},shellfish:{emoji:"🦐",label:"Äyriäiset"},sulfites:{emoji:"🍷",label:"Sulfiitit"},lupin:{emoji:"🌸",label:"Lupiini"},mollusks:{emoji:"🐚",label:"Nilviäiset"},vegan:{emoji:"🌱",label:"Vegaani"},vegetarian:{emoji:"🥗",label:"Kasvis"},spicy:{emoji:"🌶️",label:"Tulinen"},halal:{emoji:"☪️",label:"Halal"}};function w({url:o,size:a=64}){const[n,r]=t.useState(null);return t.useEffect(()=>{o&&s.toDataURL(o,{width:2*a,margin:1,color:{dark:"#000000",light:"#ffffff"}}).then(r).catch(()=>{})},[o,a]),n?e.jsx("img",{src:n,alt:"QR",style:{width:a,height:a}}):null}function v({template:t,content:o,heroImage:s,logoImage:a,qrUrl:n}){const{front:r}=t,i=o?.restaurantInfo||{};return e.jsxs("div",{className:"relative overflow-hidden",style:{width:595,height:842,backgroundColor:r.bgColor,color:r.textColor,fontFamily:"'Inter', 'Helvetica', sans-serif"},children:[s&&e.jsxs(e.Fragment,{children:[e.jsx("img",{src:s,alt:"",className:"absolute inset-0 w-full h-full object-cover"}),e.jsx("div",{className:"absolute inset-0",style:{background:r.overlayGradient||"rgba(255,255,255,0.85)"}})]}),e.jsxs("div",{className:"relative h-full flex flex-col items-center px-10 py-8",style:{zIndex:2},children:[e.jsxs("div",{className:"text-center flex-shrink-0",children:[e.jsx("h1",{className:"font-extrabold uppercase tracking-wide leading-none",style:{fontSize:r.fontSizes?.headline||36,color:r.textColor},children:i.name||"RAVINTOLA"}),i.subtitle&&e.jsx("p",{className:"mt-1 font-semibold uppercase tracking-wider",style:{fontSize:13,color:r.accentColor},children:i.subtitle})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center my-4",style:{minHeight:120,maxHeight:260},children:a?e.jsx("img",{src:a,alt:"Logo",className:"max-h-full object-contain drop-shadow-lg",style:{maxWidth:280}}):e.jsx("div",{className:"flex items-center justify-center rounded-full font-extrabold",style:{width:180,height:180,backgroundColor:r.accentColor+"15",border:`4px solid ${r.accentColor}`,color:r.accentColor,fontSize:48},children:(i.name||"R").charAt(0)})}),e.jsxs("div",{className:"flex-shrink-0 text-center space-y-1 mb-4",style:{fontSize:11},children:[i.address&&e.jsxs("p",{className:"font-medium",children:[e.jsx("span",{style:{color:r.accentColor},children:"Osoite: "}),i.address]}),i.phone&&e.jsx("p",{className:"font-bold",style:{fontSize:13},children:i.phone}),i.phone2&&e.jsx("p",{className:"font-bold",style:{fontSize:13},children:i.phone2}),i.website&&e.jsx("p",{style:{color:r.accentColor},children:i.website})]}),i.openingHours&&e.jsxs("div",{className:"flex-shrink-0 w-full max-w-xs border-2 rounded-lg px-5 py-3 mb-4",style:{borderColor:r.textColor+"40"},children:[e.jsx("h3",{className:"text-center font-extrabold uppercase tracking-wider mb-2",style:{fontSize:14},children:"AVOINNA:"}),e.jsx("div",{className:"space-y-0.5 text-center",style:{fontSize:11},children:i.openingHours.split("\n").map((t,o)=>e.jsx("p",{className:"font-semibold",children:t},o))})]}),i.deliveryInfo&&e.jsxs("div",{className:"flex-shrink-0 w-full max-w-sm mb-4",children:[e.jsx("h3",{className:"text-center font-extrabold uppercase tracking-wider mb-1",style:{fontSize:12},children:"KULJETUSPALVELU"}),e.jsx("div",{className:"text-center leading-snug",style:{fontSize:9},children:i.deliveryInfo.split("\n").map((t,o)=>e.jsx("p",{children:t},o))})]}),o?.headline&&e.jsx("div",{className:"flex-shrink-0 text-center mb-3",children:e.jsx("p",{className:"font-bold italic",style:{fontSize:14,color:r.accentColor},children:o.headline})}),e.jsx("div",{className:"flex-shrink-0 flex items-end justify-center gap-6 mt-auto pt-3",children:n&&e.jsxs("div",{className:"text-center",children:[e.jsx(w,{url:n,size:56}),e.jsx("p",{className:"text-[7px] mt-0.5 opacity-60",children:"Tilaa verkossa"})]})})]})]})}function C({template:t,content:o,showAllergens:s=!0,displayMode:a="full-menu"}){const{back:n}=t,r=o?.backItems||[],i=o?.restaurantInfo||{},l={};
1r.forEach(e=>{const t=e.category||"Muut";l[t]||(l[t]=[]),l[t].push(e)});const c=Object.keys(l),d=r.length,m=772-22*c.length,h=Math.min(11,Math.max(6.5,m/(1.6*d))),f="full-menu"===a?h:11,u=1.55*f,p="promotional"===a||"full-menu"===a&&d<40,x=r.some(e=>e.price2>0);return e.jsx("div",{className:"relative overflow-hidden flex flex-col",style:{width:595,height:842,backgroundColor:n.bgColor,color:n.textColor,fontFamily:"'Inter', 'Helvetica', sans-serif"},children:"full-menu"===a?e.jsxs("div",{className:"h-full flex flex-col px-5 py-4",children:[e.jsx("div",{className:"flex-1 overflow-hidden",children:c.map(t=>e.jsxs("div",{className:"mb-2",children:[e.jsx("h3",{className:"font-extrabold italic border-b pb-0.5 mb-1",style:{fontSize:Math.max(f+3,11),color:n.accentColor,borderColor:n.accentColor+"40"},children:t}),l[t].map((t,o)=>{const a=r.indexOf(t)+1;return e.jsxs("div",{className:"flex items-baseline gap-1",style:{fontSize:f,lineHeight:`${u}px`},children:[e.jsxs("span",{className:"flex-shrink-0 font-bold",style:{width:20,textAlign:"right",fontSize:f-.5},children:[t.itemNo||a,"."]}),e.jsx("span",{className:"font-bold flex-shrink-0",children:t.name}),p&&t.description&&e.jsxs("span",{className:"flex-shrink-0 opacity-50",style:{fontSize:f-1},children:[" ",t.description]}),e.jsx("span",{className:"flex-1 overflow-hidden",style:{borderBottom:`1px dotted ${n.textColor}30`,minWidth:8,marginBottom:2}}),e.jsx("span",{className:"flex-shrink-0 font-semibold text-right",style:{minWidth:32},children:"number"==typeof t.price?t.price.toFixed(2).replace(".",","):t.price}),x&&e.jsx("span",{className:"flex-shrink-0 font-semibold text-right",style:{minWidth:32,color:n.accentColor},children:t.price2>0?t.price2.toFixed(2).replace(".",","):""}),s&&t.allergens?.length>0&&e.jsx("span",{className:"flex-shrink-0 flex gap-px ml-0.5",children:t.allergens.slice(0,3).map(t=>e.jsx("span",{title:j[t]?.label,style:{fontSize:f-2},children:j[t]?.emoji},t))})]},o)})]},t))}),e.jsx("div",{className:"flex-shrink-0 text-center pt-2 border-t",style:{borderColor:n.textColor+"15",fontSize:7},children:e.jsxs("span",{className:"opacity-50",children:[i.name," ",i.address?`— ${i.address}`:""]})})]}):e.jsxs("div",{className:"h-full flex flex-col px-7 py-5",children:[e.jsxs("div",{className:"flex-shrink-0 text-center border-b pb-3 mb-4",style:{borderColor:n.textColor+"15"},children:[e.jsx("h2",{className:"font-bold",style:{fontSize:18},children:i.name||"Ruokalista"}),i.subtitle&&e.jsx("p",{className:"text-xs opacity-60 mt-0.5",children:i.subtitle})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:c.map(t=>e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"font-bold uppercase tracking-wider mb-2 pb-1 border-b-2",style:{fontSize:14,borderColor:n.accentColor,color:n.accentColor},children:t}),e.jsx("div",{className:"grid gap-2 "+(2===n.columns?"grid-cols-2":"grid-cols-1"),children:l[t].map((t,o)=>e.jsxs("div",{className:"rounded-lg p-2.5",style:{backgroundColor:n.cardBgColor||n.bgColor},children:[e.jsxs("div",{className:"flex justify-between items-start gap-1",children:[e.jsx("h4",{className:"font-semibold",style:{fontSize:11},children:t.name}),e.jsx("span",{className:"font-bold whitespace-nowrap",style:{fontSize:11,color:n.accentColor},children:"number"==typeof t.price?`${t.price.toFixed(2).replace(".",",")} €`:t.price})]}),t.description&&e.jsx("p",{className:"mt-0.5 opacity-60",style:{fontSize:9},children:t.description}),s&&t.allergens?.length>0&&e.jsx("div",{className:"flex flex-wrap gap-0.5 mt-1",children:t.allergens.map(t=>e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1 py-0.5 rounded-full",style:{fontSize:7,backgroundColor:n.accentColor+"15",color:n.accentColor},children:[e.jsx("span",{children:j[t]?.emoji}),e.jsx("span",{children:j[t]?.label})]},t))})]},o))})]},t))}),o?.callToAction&&e.jsx("div",{className:"flex-shrink-0 text-center py-2",style:{backgroundColor:n.accentColor+"10"},children:e.jsx("p",{className:"font-semibold italic",style:{fontSize:11,color:n.accentColor},children:o.callToAction})}),e.jsxs("div",{className:"flex-shrink-0 text-center pt-2 border-t mt
1-2",style:{borderColor:n.textColor+"15",fontSize:8},children:[i.address&&e.jsx("p",{className:"opacity-70",children:i.address}),i.phone&&e.jsx("p",{className:"opacity-70",children:i.phone})]})]})})}const N=t.forwardRef(function({template:o,content:s,heroImage:a,logoImage:n,showAllergens:r,qrUrl:i,displayMode:l},c){const[d,m]=t.useState("front"),h=t.useRef(null),f=t.useRef(null);t.useImperativeHandle(c,()=>({getFrontElement:()=>h.current,getBackElement:()=>f.current}));const u=440/595;return e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsxs("div",{className:"flex gap-2 bg-zinc-800 rounded-lg p-1",children:[e.jsx("button",{onClick:()=>m("front"),className:"px-4 py-2 rounded-md text-sm font-medium transition-all "+("front"===d?"bg-white text-zinc-900 shadow":"text-zinc-400 hover:text-white"),children:"Etukansi"}),e.jsx("button",{onClick:()=>m("back"),className:"px-4 py-2 rounded-md text-sm font-medium transition-all "+("back"===d?"bg-white text-zinc-900 shadow":"text-zinc-400 hover:text-white"),children:"Takakansi"})]}),e.jsxs("div",{style:{width:440},children:[e.jsxs("div",{className:"mx-auto shadow-2xl rounded-lg overflow-hidden",style:{width:595,height:842,transform:`scale(${u})`,transformOrigin:"top center"},children:[e.jsx("div",{ref:h,style:{display:"front"===d?"block":"none"},children:e.jsx(v,{template:o,content:s,heroImage:a,logoImage:n,qrUrl:i})}),e.jsx("div",{ref:f,style:{display:"back"===d?"block":"none"},children:e.jsx(C,{template:o,content:s,showAllergens:r,displayMode:l})})]}),e.jsx("div",{style:{height:842*u}})]})]})}),z=["name","nimi","tuote","ürün","adı","producto","nombre","item","dish","ruoka","annos","producto"],k=["price","hinta","fiyat","precio","cost","preis","norm","€"],I=["desc","kuvaus","içindekiler","ingredient","ainekset","sisältö","descripcion","zutat"],S=["categ","kategor","luokka","ryhmä","categor","type","tyyppi"],F=["image","img","kuva","photo","foto","resim","pic","url"],A=["no","num","nro","#","id","järjestys"];function D(e){const t=e.toLowerCase().replace(/[^a-zäöåüığşçñ]/g," ").trim();return z.some(e=>t.includes(e))?"name":k.some(e=>t.includes(e))?"price":I.some(e=>t.includes(e))?"description":S.some(e=>t.includes(e))?"category":F.some(e=>t.includes(e))?"image":A.some(e=>t===e)?"number":null}function E({onDataLoaded:o,loading:s,displayMode:i,onDisplayModeChange:l}){const[c,d]=t.useState("xlsx"),[m,h]=t.useState(""),[f,u]=t.useState([]),[p,x]=t.useState(!1),[g,b]=t.useState({name:"",subtitle:"",address:"",phone:"",ph
1one2:"",website:"",openingHours:"",deliveryInfo:""}),[y,j]=t.useState(null),[w,v]=t.useState(null),[C,N]=t.useState(""),[z,k]=t.useState(0),I=t.useRef(null),S=e=>t=>{const o=t.target.files?.[0];if(!o)return;const s=new FileReader;s.onload=t=>e(t.target.result),s.readAsDataURL(o)},F=(e,t)=>b(o=>({...o,[e]:t}));return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-zinc-300 uppercase tracking-wider",children:"Esitteen tyyppi"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>l("full-menu"),className:"flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all "+("full-menu"===i?"bg-orange-500/20 text-orange-300 border border-orange-500/50":"bg-zinc-800 text-zinc-400 border border-zinc-700 hover:border-zinc-500"),children:"📋 Koko ruokalista"}),e.jsx("button",{onClick:()=>l("promotional"),className:"flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all "+("promotional"===i?"bg-orange-500/20 text-orange-300 border border-orange-500/50":"bg-zinc-800 text-zinc-400 border border-zinc-700 hover:border-zinc-500"),children:"🌟 Mainosesite"})]}),e.jsx("p",{className:"text-[10px] text-zinc-500",children:"full-menu"===i?"Kaikki tuotteet kompaktissa listassa (kuten perinteinen ruokalista)":"AI valitsee parhaat tuotteet mainontaan (10-20 tuotetta)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-zinc-300 uppercase tracking-wider",children:"Tietolähde"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>d("xlsx"),className:"flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all "+("xlsx"===c?"bg-emerald-500/20 text-emerald-300 border border-emerald-500/50":"bg-zinc-800 text-zinc-400 border border-zinc-700 hover:border-zinc-500"),children:"📄 Excel"}),e.jsx("button",{onClick:()=>{d("database"),(async()=>{if(!(f.length>0)){x(!0);try{const{data:e,error:t}=await a.from("restaurants").select("id, name, address, contact_phone, website, secret_url").order("name");if(t)return void alert("Ravintoloiden lataus epäonnistui: "+t.message);u(e||[])}finally{x(!1)}}})()},className:"flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all "+("database"===c?"bg-emerald-500/20 text-emerald-300 border border-emerald-500/50":"bg-zinc-800 text-zinc-400 border border-zinc-700 hover:border-zinc-500"),children:"🗄️ Tietokanta"})]})]}),"xlsx"===c?e.jsxs("div",{children:[e.jsx("input",{ref:I,type:"file",accept:".xlsx,.xls",onChange:e=>{const t=e.target.files?.[0];if(!t)return;const s=new FileReader;s.onload=e=>{try{const t=new Uint8Array(e.target.result),s=function(e){const t=[];for(const o of e.SheetNames){const s=e.Sheets[o],a=r.sheet_to_json(s,{defval:""});if(!a.length)continue;const n=Object.keys(a[0]),i={},l=[];for(const e of n){const t=D(e);"price"===t?(l.push(e),i.price||(i.price=e)):t&&!i[t]&&(i[t]=e)}if(!i.name&&n.length>=2)for(const e of n)if("number"!==D(e)&&!i.name){i.name=e;break}if(!i.name)for(const e of n){const t=a[0][e];if("string"==typeof t&&t.length>1){i.name=e;break}}for(const e of a){const s=String(e[i.name]||"").trim();if(!s)continue;let a=0;for(const t of l){const o=parseFloat(e[t]);if(o>0){a=o;break}}const n=i.description?String(e[i.description]||"").trim():"",r=i.category&&String(e[i.category]||"").trim()||o,c=i.image?String(e[i.image]||"").trim():"",d=i.number?String(e[i.number]||"").trim():"";t.push({name:s,price:a,description:n,category:r,imageUrl:c,itemNo:d})}}return t}(n(t,{type:"array"}));if(0===s.length)return void alert("Excel-tiedostosta ei löytynyt tuotteita.");k(s.length),o({menuItems:s,restaurantInfo:g,heroImage:y,logoImage:w,qrUrl:C})}catch(t){alert("Virhe: "+t.message)}},s.readAsArrayBuffer(t)},className:"hidden"}),e.jsx("button",{onClick:()=>I.current?.click(),disabled:s,className:"w-full py-3 rounded-lg border-2 border-dashed border-zinc-600 text-zinc-400 text-sm hover:border-zinc-400 hover:text-zinc-200 transition-all disabled:opacity-50",children:s?"Ladataan...":"Valitse Excel-tiedosto"}),e.jsx("p",{className:"text-[10px] text-zinc-500 mt-1",children:"Tunnistaa sarakkeet automaattisesti (FI/TR/EN/ES/DE)"}),z>0&&e.jsxs("p",{className:"text-[10px] text-emerald-400 mt-1",children:[z," tuotetta luettu"]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("select",{value:m,onChange:e=>h(e.target.value),className:"w-full px-3 py-2 rounded-lg bg-zinc-800 border border-zinc-700 text-sm text-zinc-200",disabled:p,children:[e.jsx("option",{value:"",children:p?"Ladataan...":"Valitse ravintola"}),f.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]}),e.jsx("button",{onClick:async()=>
1{if(m)try{const{data:e,error:t}=await a.from("menu_items").select("id, name, base_price, description, image_url, categories(name, display_order)").eq("restaurant_id",m).eq("is_active",!0).order("name").order("id");if(t)throw t;const s=(e||[]).slice().sort((e,t)=>(e.categories?.display_order??Number.MAX_SAFE_INTEGER)-(t.categories?.display_order??Number.MAX_SAFE_INTEGER)),n=f.find(e=>e.id===Number(m)),r={name:n?.name||g.name,subtitle:g.subtitle,address:n?.address||g.address,phone:n?.contact_phone||g.phone,phone2:g.phone2,website:n?.website||g.website,openingHours:g.openingHours,deliveryInfo:g.deliveryInfo};b(r);const i=(s||[]).map(e=>({name:e.name,price:e.base_price,description:e.description||"",category:e.categories?.name||"",imageUrl:e.image_url||"",itemNo:""})),l=n?.secret_url?`https://pitza.fi/menu/${n.secret_url}`:C;N(l),k(i.length),o({menuItems:i,restaurantInfo:r,heroImage:y,logoImage:w,qrUrl:l})}catch(e){alert("Virhe: "+e.message)}},disabled:!m||s,className:"w-full py-2 rounded-lg bg-emerald-600 text-white text-sm font-medium hover:bg-emerald-500 disabled:opacity-50 transition-all",children:s?"Ladataan...":"Lataa tiedot"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-zinc-300 uppercase tracking-wider",children:"Ravintolan tiedot"}),e.jsx("input",{type:"text",value:g.name,onChange:e=>F("name",e.target.value),placeholder:"Ravintolan nimi",className:"w-full px-3 py-2 rounded-lg bg-zinc-800 border border-zinc-700 text-sm text-zinc-200 placeholder:text-zinc-500"}),e.jsx("input",{type:"text",value:g.subtitle,onChange:e=>F("subtitle",e.target.value),placeholder:"Alaotsikko (esim. ESPOON KESKUS UUSI MENU)",className:"w-full px-3 py-2 rounded-lg bg-zinc-800 border border-zinc-700 text-sm text-zinc-200 placeholder:text-zinc-500"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("input",{type:"text",value:g.address,onChange:e=>F("address",e.target.value),placeholder:"Osoite",className:"px-3 py-2 rounded-lg bg-zinc-800 border border-zinc-700 text-sm text-zinc-200 placeholder:text-zinc-500"}),e.jsx("input",{type:"text",value:g.phone,onChange:e=>F("phone",e.target.value),placeholder:"Puhelin 1",className:"px-3 py-2 rounded-lg bg-zinc-800 border border-zinc-700 text-sm text-zinc-200 placeholder:text-zinc-500"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("input",{type:"text",value:g.phone2,onChange:e=>F("phone2",e.target.value),placeholder:"Puhelin 2 (valinnainen)",className:"px-3 py-2 rounded-lg bg-zinc-800 border border-zinc-700 text-sm text-zinc-200 placeholder:text-zinc-500"}),e.jsx("input",{type:"text",value:g.website,onChange:e=>F("website",e.target.value),placeholder:"Verkkosivusto",className:"px-3 py-2 rounded-lg bg-zinc-800 border border-zinc-700 text-sm text-zinc-200 placeholder:text-zinc-500"})]}),e.jsx("textarea",{value:g.openingHours,onChange:e=>F("openingHours",e.target.value),placeholder:"Aukioloajat (esim. Ma-To: 10-22, Pe: 10-23)",rows:3,className:"w-full px-3 py-2 rounded-lg bg-zinc-800 border border-zinc-700 text-sm text-zinc-200 placeholder:text-zinc-500 resize-none"}),e.jsx("textarea",{value:g.deliveryInfo,onChange:e=>F("deliveryInfo",e.target.value),placeholder:"Kuljetuspalvelu tiedot (valinnainen)",rows:2,className:"w-full px-3 py-2 rounded-lg bg-zinc-800 border border-zinc-700 text-sm text-zinc-200 placeholder:text-zinc-500 resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-zinc-300 uppercase tracking-wider",children:"Kuvat"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-zinc-400 block mb-1",children:"Logo"}),e.jsx("input",{type:"file",accept:"image/*",onChange:S(v),className:"w-full text-[10px] text-zinc-400 file:mr-1 file:px-2 file:py-1 file:rounded file:border-0 file:bg-zinc-700 file:text-zinc-200 file:text-[10px] file:cursor-pointer"}),w&&e.jsxs("div",{className:"relative mt-1 h-12 rounded overflow-hidden bg-zinc-800 flex items-center justify-center",children:[e.jsx("img",{src:w,alt:"Logo",className:"h-full object-contain"}),e.jsx("button",{onClick:()=>v(null),className:"absolute top-0.5 right-0.5 w-4 h-4 rounded-full bg-red-500 text-white text-[8px] flex items-center justify-center",children:"X"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-zinc-400 block mb-1",children:"Taustakuva"}),e.jsx("input",{type:"file",accept:"image/*",onChange:S(j),className:"w-full text-[10px] text-zinc-400 file:mr-1 file:px-2 file:py-1 file:rounded file:border-0 file:bg-zinc-700 file:text-zinc-200 file:text-[10px] f
1ile:cursor-pointer"}),y&&e.jsxs("div",{className:"relative mt-1 h-12 rounded overflow-hidden",children:[e.jsx("img",{src:y,alt:"Tausta",className:"w-full h-full object-cover"}),e.jsx("button",{onClick:()=>j(null),className:"absolute top-0.5 right-0.5 w-4 h-4 rounded-full bg-red-500 text-white text-[8px] flex items-center justify-center",children:"X"})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-zinc-300 uppercase tracking-wider",children:"QR-koodi"}),e.jsx("input",{type:"text",value:C,onChange:e=>N(e.target.value),placeholder:"https://pitza.fi/menu/...",className:"w-full px-3 py-2 rounded-lg bg-zinc-800 border border-zinc-700 text-sm text-zinc-200 placeholder:text-zinc-500"})]})]})}function T({selectedId:t,onSelect:o}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-zinc-300 uppercase tracking-wider",children:"Valitse Shablon"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:g.map(s=>{const a=s.id===t;return e.jsxs("button",{onClick:()=>
1o(s.id),className:"relative flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-all "+(a?"border-blue-500 bg-blue-500/10 ring-1 ring-blue-500":"border-zinc-700 bg-zinc-800/50 hover:border-zinc-500 hover:bg-zinc-800"),children:[e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[e.jsx("span",{className:"text-lg",children:s.thumbnail}),e.jsx("span",{className:"text-xs font-semibold truncate "+(a?"text-blue-300":"text-zinc-200"),children:s.name})]}),e.jsx("p",{className:"text-[10px] text-zinc-400 line-clamp-2",children:s.description}),e.jsxs("div",{className:"flex gap-1 mt-1",children:[e.jsxs("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-zinc-700 text-zinc-400",children:["E: ",s.capacity.frontItems]}),e.jsxs("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-zinc-700 text-zinc-400",children:["T: ",s.capacity.backItems]})]}),a&&e.jsx("div",{className:"absolute top-2 right-2 w-2 h-2 rounded-full bg-blue-500"})]},s.id)})})]})}i.register({family:"Inter",fonts:[{src:"/assets/Inter-Regular-1b08e7fc.ttf",fontWeight:400},{src:"/assets/Inter-Medium-8c883f63.ttf",fontWeight:500},{src:"/assets/Inter-SemiBold-e7a1aaf7.ttf",fontWeight:600},{src:"/assets/Inter-Bold-b37284b5.ttf",fontWeight:700},{src:"/assets/Inter-ExtraBold-eec66af7.ttf",fontWeight:800}]}),i.registerHyphenationCallback(e=>[e]);const B=f.create({page:{width:595,height:842,fontFamily:"Inter",position:"relative"},absolute:{position:"absolute",top:0,left:0,right:0,bottom:0}});function R({matrix:t,size:o}){if(!t)return null;const s=t.modules.size,a=o/s,n=[];for(let r=0;r<s;r++)for(let o=0;o<s;o++)t.modules.get(r,o)&&n.push(e.jsx(p,{x:o*a,y:r*a,width:a,height:a,fill:"black"},`${r}-${o}`));return e.jsxs(u,{width:o,height:o,viewBox:`0 0 ${o} ${o}`,children:[e.jsx(p,{x:0,y:0,width:o,height:o,fill:"white"}),n]})}function P({allergens:t,color:o}){if(!t?.length)return null;const s=t.map(e=>j[e]).filter(Boolean).map(e=>`${e.emoji} ${e.label}`).join("  ");return e.jsx(h,{style:{fontSize:7,color:o||"#666",marginTop:2},children:s})}function L({template:t,content:o,heroImageBase64:s}){const{front:a}=t,n=o?.frontItems||[];return e.jsxs(c,{size:"A4",style:[B.page,{backgroundColor:a.bgColor}],children:[s&&e.jsx(d,{src:s,style:[B.absolute,{objectFit:"cover"}]}),s&&e.jsx(m,{style:[B.absolute,{backgroundColor:"rgba(0,0,0,0.5)"}]}),e.jsxs(m,{style:{flex:1,padding:40,justifyContent:"flex-end"},children:[e.jsx(h,{style:{fontSize:a.fontSizes.headline,fontWeight:800,color:a.textColor,marginBottom:8},children:o?.headline||"Tervetuloa"}),o?.subheadline&&e.jsx(h,{style:{fontSize:a.fontSizes.subheadline,color:a.textColor,opacity:.8,marginBottom:24},children:o.subheadline}),n.slice(0,a.maxFeaturedItems).map((t,o)=>e.jsxs(m,{style:{backgroundColor:"rgba(255,255,255,0.1)",borderRadius:8,padding:12,marginBottom:8},children:[e.jsxs(m,{style:{flexDirection:"row",justifyContent:"space-between",alignItems:"flex-start"},children:[e.jsx(h,{style:{fontSize:a.fontSizes.itemName,fontWeight:700,color:a.textColor,flex:1},children:t.name}),e.jsx(h,{style:{fontSize:a.fontSizes.price,fontWeight:700,color:a.accentColor,marginLeft:8},children:t.price})]}),a.showDescriptions&&t.description&&e.jsx(h,{style:{fontSize:a.fontSizes.description,color:a.textColor,opacity:.7,marginTop:3},children:t.description}),e.jsx(P,{allergens:t.allergens,color:a.textColor})]},o))]}),e.jsx(m,{style:{alignItems:"center",paddingBottom:20},children:e.jsx(m,{style:{backgroundColor:a.accentColor,borderRadius:20,paddingHorizontal:16,paddingVertical:6},children:e.jsx(h,{style:{fontSize:9,fontWeight:700,color:"#ffffff",letterSpacing:2,textTransform:"uppercase"},children:o?.restaurantInfo?.name||"Restaurant"})})})]})}function U({template:t,content:o,showAllergens:s,qrMatrix:a}){const{back:n}=t,r=o?.backItems||[],i=o?.restaurantInfo||{},l={};r.forEach(e=>{const t=e.category||"Muut";l[t]||(l[t]=[]),l[t].push(e)});const d=Object.keys(l);return e.jsxs(c,{size:"A4",style:[B.page,{backgroundColor:n.bgColor}],children:[e.jsxs(m,{style:{flexDirection:"row",justifyContent:"space-between",alignItems:"center",paddingHorizontal:36,paddingTop:28,paddingBottom:16,borderBottomWidth:1,borderBottomColor:n.textColor+"20"},children:[e.jsxs(m,{children:[e.jsx(h,{style:{fontSize:18,fontWeight:700,color:n.textColor},children:i.name||"Ruokalista"}
1),i.subtitle&&e.jsx(h,{style:{fontSize:10,color:n.textColor,opacity:.6,marginTop:2},children:i.subtitle})]}),e.jsx(m,{style:{width:32,height:32,borderRadius:16,backgroundColor:n.accentColor,justifyContent:"center",alignItems:"center"},children:e.jsx(h,{style:{fontSize:14,fontWeight:700,color:"#ffffff"},children:(i.name||"R").charAt(0)})})]}),e.jsx(m,{style:{flex:1,paddingHorizontal:36,paddingTop:16},children:d.map(t=>e.jsxs(m,{style:{marginBottom:12},wrap:!1,children:[e.jsx(h,{style:{fontSize:n.fontSizes.categoryTitle,fontWeight:700,color:n.accentColor,textTransform:"uppercase",letterSpacing:1,borderBottomWidth:2,borderBottomColor:n.accentColor,paddingBottom:4,marginBottom:8},children:t}),l[t].map((o,a)=>e.jsxs(m,{style:{flexDirection:"row",justifyContent:"space-between",alignItems:"flex-start",paddingVertical:5,borderBottomWidth:a<l[t].length-1?.5:0,borderBottomColor:n.textColor+"10"},children:[e.jsxs(m,{style:{flex:1,paddingRight:8},children:[e.jsx(h,{style:{fontSize:n.fontSizes.itemName,fontWeight:600,color:n.textColor},children:o.name}),n.showDescriptions&&o.description&&e.jsx(h,{style:{fontSize:n.fontSizes.description,color:n.textColor,opacity:.6,marginTop:1},children:o.description}),s&&n.showAllergens&&e.jsx(P,{allergens:o.allergens,color:n.accentColor})]}),e.jsx(h,{style:{fontSize:n.fontSizes.price,fontWeight:700,color:n.accentColor},children:o.price})]},a))]},t))}),o?.callToAction&&e.jsx(m,{style:{paddingHorizontal:36,paddingVertical:10,backgroundColor:n.accentColor+"10",alignItems:"center"},children:e.jsx(h,{style:{fontSize:11,fontWeight:600,color:n.accentColor},children:o.callToAction})}),e.jsxs(m,{style:{flexDirection:"row",justifyContent:"space-between",alignItems:"flex-end",paddingHorizontal:36,paddingVertical:16,borderTopWidth:1,borderTopColor:n.textColor+"15"},children:[e.jsxs(m,{style:{flex:1},children:[i.address&&e.jsx(h,{style:{fontSize:n.fontSizes.contact,color:n.textColor,opacity:.7},children:i.address}),i.phone&&e.jsx(h,{style:{fontSize:n.fontSizes.contact,color:n.textColor,opacity:.7,marginTop:2},children:i.phone}),i.website&&e.jsx(h,{style:{fontSize:n.fontSizes.contact,color:n.textColor,opacity:.7,marginTop:2},children:i.website}),i.openingHours&&e.jsx(h,{style:{fontSize:n.fontSizes.contact,color:n.textColor,opacity:.7,marginTop:2},children:i.openingHours})]}),n.showQR&&a&&e.jsxs(m,{style:{alignItems:"center"},children:[e.jsx(R,{matrix:a,size:56}),e.jsx(h,{style:{fontSize:6,color:n.textColor,opacity:.5,marginTop:3},children:"Tilaa verkossa"})]})]})]})}function M({template:t,content:o,heroImageBase64:s,showAllergens:a=!0,qrMatrix:n,qrUrl:r}){return e.jsxs(l,{title:`${o?.restaurantInfo?.name||"Restaurant"} - Esite`,author:"pitza.fi Brochure Generator",subject:"Restaurant Advertising Brochure",children:[e.jsx(L,{template:t,content:o,heroImageBase64:s}),e.jsx(U,{template:t,content:o,showAllergens:a,qrMatrix:n,qrUrl:r})]})}function _({template:a,content:n,heroImage:r,showAllergens:i,qrUrl:l,previewRef:c,onReviewDesign:d,reviewLoading:m}){const[h,f]=t.useState(!1),[u,p]=t.useState(!1),g=(n?.restaurantInfo?.name||"brochure").replace(/[^a-zA-Z0-9äöåÄÖÅ -]/g,"").slice(0,40),b=async e=>{p(!0);try{const t="front"===e?c.current?.getFrontElement():c.current?.getBackElement();if(!t)return void alert("Ei löydetty esikatselu-elementtiä");const s="none"===t.style.display;s&&(t.style.display="block");const a=await o(t,{width:595,height:842,pixelRatio:4,quality:1,cacheBust:!0,style:{transform:"none",transformOrigin:"top left"}});s&&(t.style.display="none");const n=document.createElement("a");n.href=a,n.download=`${g}-${"front"===e?"etukansi":"takakansi"}.png`,n.click()}catch(t){alert("PNG-vienti epäonnistui: "+t.message)}finally{p(!1)}};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-zinc-300 uppercase tracking-wider",children:"Vienti"}),e.jsx("button",{onClick:async()=>{f(!0);try{let t=r;if(r&&!r.startsWith("data:"))try{const e=await fetch(r),o=await e.blob();t=await new Promise(e=>{const t=new FileReader;t.onload=()=>e(t.result),t.readAsDataURL(o)})}catch{t=null}const o=await async function(e){if(!e)return null;try{return await s.create(e,{errorCorrectionLevel:"M"})}catch{return null}}
1(l),c=await x(e.jsx(M,{template:a,content:n,heroImageBase64:t,showAllergens:i,qrMatrix:o,qrUrl:l})).toBlob(),d=URL.createObjectURL(c),m=document.createElement("a");m.href=d,m.download=`${g}-esite.pdf`,m.click(),URL.revokeObjectURL(d)}catch(t){alert("PDF-vienti epäonnistui: "+t.message)}finally{f(!1)}},disabled:h||!n,className:"w-full py-2.5 rounded-lg bg-red-600 text-white text-sm font-medium hover:bg-red-500 disabled:opacity-50 transition-all flex items-center justify-center gap-2",children:h?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}),"Luodaan PDF..."]}):"📄 Lataa PDF (baskivalmis)"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>b("front"),disabled:u||!n,className:"py-2 rounded-lg bg-blue-600 text-white text-xs font-medium hover:bg-blue-500 disabled:opacity-50 transition-all",children:u?"...":"🖼️ Etukansi PNG"}),e.jsx("button",{onClick:()=>b("back"),disabled:u||!n,className:"py-2 rounded-lg bg-blue-600 text-white text-xs font-medium hover:bg-blue-500 disabled:opacity-50 transition-all",children:u?"...":"🖼️ Takakansi PNG"})]}),d&&e.jsx("button",{onClick:d,disabled:m||!n,className:"w-full py-2 rounded-lg bg-purple-600/20 text-purple-300 text-xs font-medium border border-purple-500/30 hover:bg-purple-600/30 disabled:opacity-50 transition-all",children:m?"Tarkistetaan...":"🤖 AI tarkistus (laatu)"})]})}async function H(e){const{data:t,error:o}=await a.functions.invoke("brochure-ai",{body:e});if(o){try{const e=await(o.context?.json?.());if(e?.error){const t=new Error(e.error);throw Object.assign(t,e),t}}catch(s){if(s!==o&&s?.message!==o?.message)throw s}throw o}if(!t)throw new Error("Empty response from brochure-ai function.");if(t.error){const e=new Error(t.error);throw Object.assign(e,t),e}return t}function W(){const[s,a]=t.useState("hero-feast"),[n,r]=t.useState("full-menu"),[i,l]=t.useState(null),[c,d]=t.useState([]),[m,h]=t.useState(null),[f,u]=t.useState(null),[p,x]=t.useState(null),[g,j]=t.useState(""),[w,v]=t.useState(!0),[C,z]=t.useState(!1),[k,I]=t.useState(!1),[S,F]=t.useState(!1),[A,D]=t.useState(null),[B,R]=t.useState(null),P=t.useRef(null),L=b(s),U=(e,t,o)=>{const a=e.map(e=>({name:e.name,price:e.price,description:e.description||"",category:e.category||"Muut",imageUrl:e.imageUrl||"",itemNo:e.itemNo||"",allergens:e.allergens||[]}));if("full-menu"===o)return{headline:t?.subtitle||`Tervetuloa — ${t?.name||""}`,subheadline:"",callToAction:"",frontItems:[],backItems:a,restaurantInfo:t};const n=y(s);return{headline:`Tervetuloa — ${t?.name||""}`,subheadline:t?.subtitle||"",callToAction:"Tilaa nyt!",frontItems:a.slice(0,n.frontItems),backItems:a.slice(0,n.backItems),restaurantInfo:t}},M=t.useCallback(async e=>{if(d(e.menuItems),h(e.restaurantInfo),u(e.heroImage),x(e.logoImage),j(e.qrUrl||""),R(null),"full-menu"===n){const t=U(e.menuItems,e.restaurantInfo,"full-menu");l(t),W(e.menuItems)}else{z(!0);try{const t=y(s),o=await async function({menuItems:e,restaurantInfo:t,templateCapacity:o,language:s="fi"}){return H({mode:"generate-content",menuItems:e,restaurantInfo:t,templateCapacity:o,language:s})}({menuItems:e.menuItems,restaurantInfo:e.restaurantInfo,templateCapacity:t,language:"fi"}),a={...o,restaurantInfo:e.restaurantInfo};l(a),W(e.menuItems,a)}catch(t){R("AI-sisällön luonti epäonnistui, käytetään perustietoja: "+t.message);const o=U(e.menuItems,e.restaurantInfo,"promotional");l(o)}finally{z(!1)}}},[n,s]),W=async e=>{I(!0);try{const t=(e||c).map(e=>({name:e.name,description:e.description})),o=await async function({items:e,language:t="fi"}){return H({mode:"detect-allergens",items:e,language:t})}({items:t,language:"fi"});if(o?.items){const e={};o.items.forEach(t=>{e[t.name.toLowerCase()]=t.allergens.filter(e=>e.confidence>=.5).map(e=>e.type)}),l(t=>{if(!t)return t;const o=t=>t.map(t=>({...t,allergens:e[t.name.toLowerCase()]||t.allergens||[]}));return{...t,frontItems:o(t.frontItems||[]),backItems:o(t.backItems||[])}})}}catch(t){}finally{I(!1)}};return e.jsxs("div",{className:"flex h-full min-h-0 w-full overflow-hidden rounded-[28px] border border-zinc-800 bg-zinc-950 text-zinc-100 shadow-2xl font-sans",children:[e.jsxs("div",{className:"flex min-h-0 w-96 flex-shrink-0 flex-col overflow-hidden border-r border-zinc-800 bg-zinc-900",children:[e.jsxs("div",{className:"p-5 border-b border-zinc-800",children:[e.jsx("h1",{className:"bg-clip-text text-xl font-bold text-transparent",style:{backgroundImage:"linear-gradient(90deg, #f97316, #ef4444)"},children:"Esite-generaattori"}),e.jsx("p",{className:"text-xs text-zinc-400 mt-1",children:"Ravintolan mainosesitteet — tulostusvalmiita"})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-5 space-y-6",children:[e.jsx(E,{onDataLoaded:M,loading:C,displayMode:n,onDisplayModeChange:e=>{if(r(e),c.length>0&&m)if("full-menu"===e){const e=U(c,m,"full-menu"),t={};
1[...i?.frontItems||[],...i?.backItems||[]].forEach(e=>{e.allergens?.length&&(t[e.name.toLowerCase()]=e.allergens)}),e.backItems=e.backItems.map(e=>({...e,allergens:t[e.name.toLowerCase()]||[]})),l(e)}else{const e=U(c,m,"promotional"),t={};[...i?.frontItems||[],...i?.backItems||[]].forEach(e=>{e.allergens?.length&&(t[e.name.toLowerCase()]=e.allergens)});const o=e=>e.map(e=>({...e,allergens:t[e.name.toLowerCase()]||[]}));e.frontItems=o(e.frontItems),e.backItems=o(e.backItems),l(e)}}}),e.jsx(T,{selectedId:s,onSelect:e=>{a(e)}}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-sm text-zinc-300",children:"Allergeenit"}),k&&e.jsx("span",{className:"text-[10px] text-amber-300 ml-2",children:"tunnistetaan..."})]}),e.jsx("button",{onClick:()=>v(!w),className:"relative w-10 h-5 rounded-full transition-colors "+(w?"bg-emerald-500":"bg-zinc-600"),children:e.jsx("span",{className:"absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform "+(w?"left-5":"left-0.5")})})]}),i&&e.jsx("div",{className:"text-xs text-zinc-500 px-1",children:"full-menu"===n?`${i.backItems?.length||0} tuotetta (kaikki)`:`${(i.frontItems?.length||0)+(i.backItems?.length||0)} tuotetta (valitut)`}),e.jsx(_,{template:L,content:i,heroImage:f,showAllergens:w,qrUrl:g,previewRef:P,onReviewDesign:async()=>{F(!0),D(null);try{const e=P.current?.getFrontElement();if(!e)throw new Error("Preview not found");const t="none"===e.style.display;t&&(e.style.display="block");const s=await o(e,{width:595,height:842,pixelRatio:1});t&&(e.style.display="none");const a=s.split(",")[1],n=await async function({imageBase64:e,mimeType:t="image/png"}){return H({mode:"review-design",imageBase64:e,mimeType:t})}({imageBase64:a,mimeType:"image/png"});D(n)}catch(e){alert("Tarkistus epäonnistui: "+e.message)}finally{F(!1)}},reviewLoading:S}),A&&e.jsxs("div",{className:"rounded-lg border border-purple-500/30 bg-purple-500/10 p-3 space-y-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-purple-300",children:"AI arviointi"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[["Kokonais",A.overallScore],["Luettavuus",A.readability],["Värit",A.colorHarmony],["Asettelu",A.layoutBalance],["Baskivalmius",A.printReadiness]].map(([t,o])=>e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"text-lg font-bold text-purple-200",children:[o,"/10"]}),e.jsx("div",{className:"text-[9px] text-zinc-400",children:t})]},t))}),A.summary&&e.jsx("p",{className:"text-[10px] text-zinc-300",children:A.summary})]})]})]}),e.jsxs("div",{className:"relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-[radial-gradient(circle_at_top,rgba(24,24,27,0.96)_0%,rgba(9,9,11,1)_58%,rgba(3,7,18,1)_100%)]",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-zinc-800 bg-zinc-900/50 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"px-4 py-2 rounded-lg text-sm font-medium bg-orange-500/20 text-orange-300 border border-orange-500/50",children:"Esikatselu"}),C&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-amber-300",children:[e.jsx("span",{className:"w-3 h-3 border-2 border-amber-300/30 border-t-amber-300 rounded-full animate-spin"}),"AI käsittelee..."]})]}),e.jsxs("div",{className:"text-xs text-zinc-500",children:[L.name," — ","full-menu"===n?"Koko ruokalista":"Mainos"," — A4"]})]}),B&&e.jsx("div",{className:"mx-4 mt-3 px-4 py-2 rounded-lg bg-red-500/20 border border-red-500/30 text-red-300 text-xs",children:B}),e.jsx("div",{className:"relative flex min-h-0 flex-1 items-start justify-center overflow-y-auto p-6",children:i?e.jsx(N,{ref:P,template:L,content:i,heroImage:f,logoImage:p,showAllergens:w,qrUrl:g,displayMode:n}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center text-zinc-500",children:[e.jsx("div",{className:"text-6xl mb-4",children:"📋"}),e.jsx("p",{className:"text-lg font-medium",children:"Aloita lisäämällä tietoja"}),e.jsx("p",{className:"text-sm mt-1",children:"Lataa Excel tai valitse ravintola tietokannasta"})]})})]})]})}export{W as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.