caterium-app/public/core/classic-offer-pdf-v1767.js

121 lines
27 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(()=>{
'use strict';
if(window.SunClassicOfferPDFV1767)return;
const VERSION='17.6.7';
const RELEASE='20260908-v17-6-7-classic-offer-pdf';
const W=1000,H=1414,SCALE=1.6,M=54;
const CLASSIC_IDS=['light','midnight-glass','editorial-grid','warm-sun','bento-cards','event-story','black-gold','personal-letter','event-ticket','solar-experience'];
const ARCHIVE_IDS=['midnight-compact','emerald-gold','neon-emerald'];
const CLASSIC_SET=new Set(CLASSIC_IDS),ARCHIVE_SET=new Set(ARCHIVE_IDS);
const INNER_THEME={
light:'light',
'midnight-glass':'midnight-glass',
'editorial-grid':'editorial-grid',
'warm-sun':'light',
'bento-cards':'light',
'event-story':'editorial-grid',
'black-gold':'black-gold',
'personal-letter':'light',
'event-ticket':'editorial-grid',
'solar-experience':'light'
};
const PALETTES={
light:{bg:'#fffdf8',paper:'#ffffff',ink:'#17231c',muted:'#6f746e',accent:'#c99b47',deep:'#28533a',line:'#eadfca',foot:'#fffdf8'},
'midnight-glass':{bg:'#090b0b',paper:'#111513',ink:'#f6f1e7',muted:'#b5aea1',accent:'#d4ad62',deep:'#e3c176',line:'#5d4a2a',foot:'#090b0b'},
'editorial-grid':{bg:'#fbf8f1',paper:'#fffdf8',ink:'#15251c',muted:'#746f64',accent:'#b79155',deep:'#1f5a42',line:'#ddd2bd',foot:'#fbf8f1'},
'warm-sun':{bg:'#fff5d8',paper:'#fffdf5',ink:'#442d19',muted:'#8a6747',accent:'#f3ad17',deep:'#8a4d13',line:'#f0d9a6',foot:'#fff5d8'},
'bento-cards':{bg:'#f8f7f1',paper:'#ffffff',ink:'#1d251f',muted:'#788079',accent:'#f4b423',deep:'#263f32',line:'#e5e3d9',foot:'#f8f7f1'},
'event-story':{bg:'#f6efe4',paper:'#fffaf2',ink:'#3a2d22',muted:'#7f7064',accent:'#c78c42',deep:'#5f4a37',line:'#dfccb4',foot:'#f6efe4'},
'black-gold':{bg:'#080807',paper:'#151412',ink:'#f6f0e5',muted:'#b9b0a2',accent:'#d0a345',deep:'#e4bd68',line:'#5a4928',foot:'#080807'},
'personal-letter':{bg:'#f6efe0',paper:'#fffaf0',ink:'#42362a',muted:'#817365',accent:'#b9844e',deep:'#604832',line:'#dfcfb5',foot:'#f6efe0'},
'event-ticket':{bg:'#f8f3e7',paper:'#fffdf7',ink:'#172331',muted:'#68717d',accent:'#e5a91b',deep:'#173a50',line:'#d9cdbb',foot:'#f8f3e7'},
'solar-experience':{bg:'#f6ad00',paper:'#ffd13b',ink:'#172022',muted:'#584929',accent:'#fff0a3',deep:'#102f33',line:'#e79a00',foot:'#f6ad00'}
};
const money=v=>Math.round(Number(v||0)).toLocaleString('ru-RU')+' ₽';
const classicBoxCount=s=>(s?.items||[]).filter(i=>[0,5].includes(Number(i?.categoryId))).reduce((sum,i)=>sum+Math.max(0,Number(i?.qty||0)),0);
const dateText=value=>{if(!value)return'';const d=new Date(String(value)+'T12:00:00');return Number.isNaN(d.getTime())?String(value):d.toLocaleDateString('ru-RU',{day:'numeric',month:'long',year:'numeric'})};
const plural=(n,a,b,c)=>{const x=Math.abs(Number(n)||0)%100,y=x%10;return x>10&&x<20?c:y===1?a:y>=2&&y<=4?b:c};
const safeImage=src=>/^data:image\/(?:png|jpe?g|webp);base64,/i.test(String(src||''));
function loadImage(src){return new Promise(resolve=>{if(!safeImage(src))return resolve(null);const im=new Image();let done=false;const finish=v=>{if(done)return;done=true;clearTimeout(timer);resolve(v)};const timer=setTimeout(()=>finish(null),3500);im.onload=()=>finish(im);im.onerror=()=>finish(null);im.src=String(src)})}
function roundRect(ctx,x,y,w,h,r,fill,stroke,width=1){const rr=Math.min(r,w/2,h/2);ctx.beginPath();ctx.moveTo(x+rr,y);ctx.arcTo(x+w,y,x+w,y+h,rr);ctx.arcTo(x+w,y+h,x,y+h,rr);ctx.arcTo(x,y+h,x,y,rr);ctx.arcTo(x,y,x+w,y,rr);ctx.closePath();if(fill){ctx.fillStyle=fill;ctx.fill()}if(stroke){ctx.strokeStyle=stroke;ctx.lineWidth=width;ctx.stroke()}}
function wrap(ctx,text,maxWidth){const words=String(text||'').trim().split(/\s+/).filter(Boolean),lines=[];let line='';for(const word of words){const test=line?line+' '+word:word;if(ctx.measureText(test).width<=maxWidth)line=test;else{if(line)lines.push(line);line=word}}if(line)lines.push(line);return lines}
function text(ctx,value,x,y,width,lineHeight,{font='16px Arial',color='#111',align='left',maxLines=0}={}){ctx.save();ctx.font=font;ctx.fillStyle=color;ctx.textAlign=align;ctx.textBaseline='top';let lines=wrap(ctx,value,width);if(maxLines&&lines.length>maxLines){lines=lines.slice(0,maxLines);let last=lines[lines.length-1]||'';while(last&&ctx.measureText(last+'…').width>width)last=last.slice(0,-1);lines[lines.length-1]=last+'…'}lines.forEach((line,i)=>ctx.fillText(line,x,y+i*lineHeight));ctx.restore();return lines.length*lineHeight}
function line(ctx,x1,y1,x2,y2,color,width=1,dash=[]){ctx.save();ctx.strokeStyle=color;ctx.lineWidth=width;ctx.setLineDash(dash);ctx.beginPath();ctx.moveTo(x1,y1);ctx.lineTo(x2,y2);ctx.stroke();ctx.restore()}
function coverImage(ctx,img,x,y,w,h,r=24){if(!img)return;const s=Math.max(w/img.naturalWidth,h/img.naturalHeight),sw=w/s,sh=h/s,sx=(img.naturalWidth-sw)/2,sy=(img.naturalHeight-sh)/2;ctx.save();roundRect(ctx,x,y,w,h,r);ctx.clip();ctx.drawImage(img,sx,sy,sw,sh,x,y,w,h);ctx.restore()}
function circleImage(ctx,img,cx,cy,r){if(!img)return;const d=r*2,s=Math.max(d/img.naturalWidth,d/img.naturalHeight),sw=d/s,sh=d/s,sx=(img.naturalWidth-sw)/2,sy=(img.naturalHeight-sh)/2;ctx.save();ctx.beginPath();ctx.arc(cx,cy,r,0,Math.PI*2);ctx.clip();ctx.drawImage(img,sx,sy,sw,sh,cx-r,cy-r,d,d);ctx.restore()}
function drawContain(ctx,img,x,y,w,h){if(!img)return;const s=Math.min(w/img.naturalWidth,h/img.naturalHeight),dw=img.naturalWidth*s,dh=img.naturalHeight*s;ctx.drawImage(img,x+(w-dw)/2,y+(h-dh)/2,dw,dh)}
function sun(ctx,cx,cy,r,color,rays=18){ctx.save();ctx.strokeStyle=color;ctx.fillStyle=color;ctx.lineWidth=2;for(let i=0;i<rays;i++){const a=i*Math.PI*2/rays,ri=r+8,ro=r+24+(i%2)*8;ctx.beginPath();ctx.moveTo(cx+Math.cos(a)*ri,cy+Math.sin(a)*ri);ctx.lineTo(cx+Math.cos(a)*ro,cy+Math.sin(a)*ro);ctx.stroke()}ctx.beginPath();ctx.arc(cx,cy,r,0,Math.PI*2);ctx.fill();ctx.restore()}
function factPills(ctx,s,p,x,y,w,{dark=false}={}){const facts=[];if(s.date)facts.push(dateText(s.date));if(s.guests)facts.push(String(s.guests)+' '+plural(s.guests,'гость','гостя','гостей'));if(s.time)facts.push('Доставка '+String(s.time));facts.push(String(Math.round(classicBoxCount(s)))+' '+plural(s.boxCount,'бокс','бокса','боксов'));const gap=8,cw=(w-gap*(facts.length-1))/facts.length;facts.forEach((f,i)=>{const xx=x+i*(cw+gap);roundRect(ctx,xx,y,cw,50,14,dark?'rgba(255,255,255,.07)':p.paper,dark?'rgba(255,255,255,.22)':p.line);text(ctx,f,xx+cw/2,y+16,cw-16,18,{font:'12px Arial',color:dark?'#f7f2e7':p.ink,align:'center',maxLines:1})})}
function totalBlock(ctx,s,p,x,y,w,h,{dark=false,accentFill=false}={}){roundRect(ctx,x,y,w,h,18,accentFill?p.accent:(dark?'rgba(10,10,10,.58)':p.paper),dark?'rgba(255,255,255,.2)':p.line);text(ctx,'ИТОГОВАЯ СТОИМОСТЬ',x+22,y+18,w-44,18,{font:'700 11px Arial',color:accentFill?p.deep:p.accent,maxLines:1});text(ctx,money(s.pricing?.total),x+22,y+48,w-44,46,{font:'500 34px Georgia',color:accentFill?p.deep:(dark?'#fff':p.deep),maxLines:1});if(s.guests)text(ctx,'на гостя: '+money((Number(s.pricing?.itemsTotal||s.pricing?.total||0))/Math.max(1,Number(s.guests))),x+22,y+96,w-44,20,{font:'12px Arial',color:accentFill?p.deep:(dark?'#ddd3c1':p.muted),maxLines:1})}
function logoOrBrand(ctx,logo,p,{x=M,y=46,dark=false}={}){if(logo){const scale=Math.min(190/logo.naturalWidth,64/logo.naturalHeight);ctx.drawImage(logo,x,y,logo.naturalWidth*scale,logo.naturalHeight*scale);return}text(ctx,p.brandName||'Моя компания',x,y+8,300,28,{font:'700 22px Arial',color:dark?'#fff':p.ink,maxLines:2})}
function eventTitle(s){const event=String(s.event||'Персональное предложение').trim();return String(s.client||'').trim()?'Предложение для '+String(s.client).trim():event}
function menuPreview(ctx,s,p,x,y,w,h,{dark=false,cards=4}={}){const items=(s.items||[]).slice(0,cards),gap=9,rowH=(h-gap*Math.max(0,items.length-1))/Math.max(1,items.length);items.forEach((item,i)=>{const yy=y+i*(rowH+gap);roundRect(ctx,x,yy,w,rowH,14,dark?'rgba(255,255,255,.07)':p.paper,dark?'rgba(255,255,255,.15)':p.line);text(ctx,item.name||'Позиция меню',x+16,yy+12,w-92,21,{font:dark?'600 13px Arial':'500 14px Georgia',color:dark?'#fff':p.ink,maxLines:2});text(ctx,'× '+Math.round(Number(item.qty||1)),x+w-16,yy+14,60,18,{font:'700 11px Arial',color:p.accent,align:'right',maxLines:1})})}
function footer(ctx,p,page,total,brandName='Моя компания'){line(ctx,M,H-48,W-M,H-48,p.line,1);text(ctx,(brandName+" · предложение клиенту"),M,H-34,500,16,{font:'10px Arial',color:p.muted,maxLines:1});text(ctx,String(page)+' / '+String(total),W-M,H-34,100,16,{font:'10px Arial',color:p.muted,align:'right',maxLines:1})}
async function renderCover(s,id){
const p={...(PALETTES[id]||PALETTES.light),brandName:s.brandName||'Моя компания'},canvas=document.createElement('canvas');canvas.width=Math.round(W*SCALE);canvas.height=Math.round(H*SCALE);const ctx=canvas.getContext('2d',{alpha:false});ctx.setTransform(SCALE,0,0,SCALE,0,0);ctx.fillStyle=p.bg;ctx.fillRect(0,0,W,H);
const logo=await loadImage(s.logo||''),heroSrc=(s.items||[]).find(x=>safeImage(x.photoData||x.photo))?.photoData||(s.finalGallery||[]).find(safeImage)||'',hero=await loadImage(heroSrc),title=eventTitle(s),event=String(s.event||'Персональное предложение').trim();
if(id==='light'){
logoOrBrand(ctx,logo,p);text(ctx,'ПЕРСОНАЛЬНОЕ ПРЕДЛОЖЕНИЕ',M,165,390,20,{font:'700 11px Arial',color:p.accent,maxLines:1});text(ctx,title,M,202,405,54,{font:'500 42px Georgia',color:p.ink,maxLines:3});text(ctx,event,M,375,405,30,{font:'500 20px Georgia',color:p.deep,maxLines:2});line(ctx,M,445,445,445,p.accent,1);text(ctx,'Меню собрано под формат вашего события, количество гостей и пожелания.',M,475,385,25,{font:'14px Arial',color:p.muted,maxLines:4});if(hero)coverImage(ctx,hero,500,150,446,600,28);factPills(ctx,s,p,M,795,W-2*M);menuPreview(ctx,s,p,M,875,565,300,{cards:4});totalBlock(ctx,s,p,640,875,306,175);text(ctx,'Всё под контролем нашей команды',640,1080,300,26,{font:'500 19px Georgia',color:p.deep,maxLines:2});text(ctx,'Доставка · свежие продукты · аккуратная подача · готовность к сервировке',640,1140,290,22,{font:'12px Arial',color:p.muted,maxLines:4});
}else if(id==='midnight-glass'){
ctx.fillStyle='#080907';ctx.fillRect(0,0,W,H);if(hero)coverImage(ctx,hero,485,0,515,H,0);const g=ctx.createLinearGradient(0,0,720,0);g.addColorStop(0,'rgba(5,5,4,.99)');g.addColorStop(.72,'rgba(5,5,4,.84)');g.addColorStop(1,'rgba(5,5,4,.05)');ctx.fillStyle=g;ctx.fillRect(0,0,W,H);ctx.strokeStyle=p.accent;ctx.lineWidth=1;ctx.strokeRect(27,27,W-54,H-54);logoOrBrand(ctx,logo,p,{x:58,y:58,dark:true});text(ctx,'LUXURY CATERING',58,210,380,20,{font:'700 11px Arial',color:p.accent,maxLines:1});text(ctx,title.toUpperCase(),58,252,390,60,{font:'500 43px Georgia',color:'#fff',maxLines:4});text(ctx,event,58,500,370,28,{font:'16px Arial',color:'#d9d1c4',maxLines:3});factPills(ctx,s,p,58,615,370,{dark:true});menuPreview(ctx,s,p,58,705,370,330,{dark:true,cards:4});totalBlock(ctx,s,p,58,1070,370,170,{dark:true});text(ctx,String(s.brandCity||'').toUpperCase(),58,1275,280,18,{font:'10px Arial',color:p.accent,maxLines:1});
}else if(id==='editorial-grid'){
logoOrBrand(ctx,logo,p);text(ctx,'EDITORIAL / EVENT MENU',M,155,400,18,{font:'700 10px Arial',color:p.accent,maxLines:1});text(ctx,title,M,190,500,66,{font:'500 52px Georgia',color:p.ink,maxLines:3});line(ctx,M,405,520,405,p.ink,2);const sections=[['01','СОБЫТИЕ',event],['02','ФОРМАТ',s.guests?String(s.guests)+' гостей':'Персонально'],['03','МЕНЮ',String((s.items||[]).length)+' позиций'],['04','ДЕТАЛИ',s.time?'Доставка '+s.time:'Время согласуем']];sections.forEach((it,i)=>{const yy=455+i*115;text(ctx,it[0],M,yy,50,24,{font:'700 15px Arial',color:p.accent,maxLines:1});text(ctx,it[1],M+62,yy,170,20,{font:'700 10px Arial',color:p.muted,maxLines:1});text(ctx,it[2],M+62,yy+26,270,30,{font:'500 18px Georgia',color:p.ink,maxLines:2});line(ctx,M+60,yy+86,430,yy+86,p.line,1)});if(hero)coverImage(ctx,hero,540,170,406,670,0);menuPreview(ctx,s,p,540,875,406,245,{cards:3});totalBlock(ctx,s,p,540,1150,406,160);text(ctx,'Составлено специально для вашего события',M,1050,390,33,{font:'italic 24px Georgia',color:p.deep,maxLines:2});
}else if(id==='warm-sun'){
logoOrBrand(ctx,logo,p);sun(ctx,810,210,78,p.accent,24);ctx.save();ctx.globalAlpha=.18;sun(ctx,810,210,150,p.accent,28);ctx.restore();text(ctx,'ТЁПЛОЕ ПРЕДЛОЖЕНИЕ',M,180,400,20,{font:'700 11px Arial',color:p.deep,maxLines:1});text(ctx,title,M,220,475,57,{font:'500 44px Georgia',color:p.ink,maxLines:3});text(ctx,event,M,395,430,28,{font:'16px Arial',color:p.muted,maxLines:2});if(hero)coverImage(ctx,hero,520,350,426,420,72);factPills(ctx,s,p,M,805,W-2*M);const steps=['Вы выбрали формат','Мы собрали меню','Готовим в день события','Доставляем к вашему времени'];steps.forEach((st,i)=>{const x=M+i*225;ctx.beginPath();ctx.arc(x+25,930,23,0,Math.PI*2);ctx.fillStyle=p.accent;ctx.fill();text(ctx,String(i+1),x+25,919,30,18,{font:'700 12px Arial',color:'#fff',align:'center',maxLines:1});text(ctx,st,x,970,190,42,{font:'500 14px Georgia',color:p.ink,align:'center',maxLines:2});if(i<steps.length-1)line(ctx,x+55,930,x+205,930,p.accent,2)});totalBlock(ctx,s,p,M,1110,W-2*M,170,{accentFill:true});
}else if(id==='bento-cards'){
logoOrBrand(ctx,logo,p);text(ctx,title,M,165,620,52,{font:'700 40px Arial',color:p.ink,maxLines:2});text(ctx,event,M,270,620,25,{font:'14px Arial',color:p.muted,maxLines:2});const facts=[['ГОСТИ',s.guests||'—'],['ПОЗИЦИИ',(s.items||[]).length],['БОКСЫ',classicBoxCount(s)||0],['ДОСТАВКА',s.time||'—']];facts.forEach((it,i)=>{const x=M+i*222;roundRect(ctx,x,355,205,112,20,p.paper,p.line);text(ctx,it[0],x+18,376,160,18,{font:'700 10px Arial',color:p.muted,maxLines:1});text(ctx,String(it[1]),x+18,406,165,35,{font:'700 26px Arial',color:p.deep,maxLines:1})});if(hero)coverImage(ctx,hero,M,505,W-2*M,350,26);const cols=[['МЕНЮ','Подобрано под событие'],['КАЧЕСТВО','Свежие продукты'],['СЕРВИС','Всё готово к подаче']];cols.forEach((it,i)=>{const x=M+i*298;roundRect(ctx,x,885,280,142,20,p.paper,p.line);text(ctx,it[0],x+18,907,220,18,{font:'700 10px Arial',color:p.accent,maxLines:1});text(ctx,it[1],x+18,943,230,50,{font:'600 18px Arial',color:p.ink,maxLines:2})});totalBlock(ctx,s,p,M,1060,425,200,{accentFill:true});menuPreview(ctx,s,p,505,1060,441,200,{cards:3});
}else if(id==='event-story'){
logoOrBrand(ctx,logo,p);text(ctx,'ИСТОРИЯ ВАШЕГО СОБЫТИЯ',M,165,450,20,{font:'700 11px Arial',color:p.accent,maxLines:1});text(ctx,title,M,205,670,57,{font:'500 44px Georgia',color:p.ink,maxLines:3});text(ctx,event,M,385,600,28,{font:'17px Arial',color:p.muted,maxLines:2});const steps=[['01','Заявка'],['02','Меню'],['03','Готовим'],['04','Доставка'],['05','Ваш стол']];line(ctx,M+50,555,W-M-50,555,p.accent,3);steps.forEach((it,i)=>{const x=M+50+i*200;ctx.beginPath();ctx.arc(x,555,30,0,Math.PI*2);ctx.fillStyle=p.paper;ctx.fill();ctx.strokeStyle=p.accent;ctx.lineWidth=3;ctx.stroke();text(ctx,it[0],x,542,44,18,{font:'700 11px Arial',color:p.accent,align:'center',maxLines:1});text(ctx,it[1],x,603,150,24,{font:'500 15px Georgia',color:p.ink,align:'center',maxLines:1})});if(hero)coverImage(ctx,hero,M,690,W-2*M,400,26);factPills(ctx,s,p,M,1120,560);totalBlock(ctx,s,p,635,1120,311,160);
}else if(id==='black-gold'){
if(hero)coverImage(ctx,hero,0,0,W,H,0);const grad=ctx.createLinearGradient(0,0,0,H);grad.addColorStop(0,'rgba(0,0,0,.35)');grad.addColorStop(.55,'rgba(0,0,0,.62)');grad.addColorStop(1,'rgba(0,0,0,.94)');ctx.fillStyle=grad;ctx.fillRect(0,0,W,H);logoOrBrand(ctx,logo,p,{x:M,y:52,dark:true});text(ctx,'FOOD FIRST',M,200,400,20,{font:'700 11px Arial',color:p.accent,maxLines:1});text(ctx,title,M,240,760,70,{font:'500 54px Georgia',color:'#fff',maxLines:3});text(ctx,event,M,475,600,30,{font:'18px Arial',color:'#e2d9ca',maxLines:2});factPills(ctx,s,p,M,590,W-2*M,{dark:true});menuPreview(ctx,s,p,M,690,560,330,{dark:true,cards:4});totalBlock(ctx,s,p,640,690,306,180,{dark:true});text(ctx,'Еда — главный герой вашего события.',M,1080,650,46,{font:'italic 30px Georgia',color:'#fff',maxLines:2});text(ctx,'Соберём, приготовим и доставим всё вовремя.',M,1195,600,24,{font:'14px Arial',color:'#d6ccb9',maxLines:2});
}else if(id==='personal-letter'){
logoOrBrand(ctx,logo,p);roundRect(ctx,M,150,W-2*M,1110,8,p.paper,p.line);text(ctx,'Персональное письмо',M+55,205,320,20,{font:'italic 15px Georgia',color:p.accent,maxLines:1});text(ctx,String(s.client||'Здравствуйте')+',',M+55,265,520,60,{font:'italic 46px Georgia',color:p.deep,maxLines:2});text(ctx,'Мы собрали для вас предложение, в котором всё уже продумано: от состава меню до удобной доставки в день события.',M+55,390,520,32,{font:'20px Georgia',color:p.ink,maxLines:5});text(ctx,event,M+55,575,520,34,{font:'italic 25px Georgia',color:p.accent,maxLines:2});if(hero)coverImage(ctx,hero,650,230,240,360,120);line(ctx,M+55,720,W-M-55,720,p.line,1);factPills(ctx,s,p,M+55,770,W-2*M-110);menuPreview(ctx,s,p,M+55,855,520,250,{cards:3});totalBlock(ctx,s,p,620,855,270,170);text(ctx,("С теплом,\nкоманда «"+p.brandName+"»"),M+55,1140,470,35,{font:'italic 24px Georgia',color:p.deep,maxLines:2});
}else if(id==='event-ticket'){
logoOrBrand(ctx,logo,p);roundRect(ctx,M,160,W-2*M,1080,28,p.paper,p.deep,2);line(ctx,695,160,695,1240,p.line,2,[8,9]);text(ctx,'EVENT PASS',M+38,205,260,20,{font:'700 11px Arial',color:p.accent,maxLines:1});text(ctx,title,M+38,250,560,58,{font:'700 43px Arial',color:p.deep,maxLines:3});text(ctx,event,M+38,425,560,28,{font:'16px Arial',color:p.muted,maxLines:2});const labels=[['DATE',dateText(s.date)||'Уточняется'],['TIME',s.time||'Уточняется'],['GUESTS',s.guests||'—'],['BOXES',classicBoxCount(s)||0]];labels.forEach((it,i)=>{const x=M+38+(i%2)*286,y=535+Math.floor(i/2)*115;roundRect(ctx,x,y,264,92,12,'#faf7ee',p.line);text(ctx,it[0],x+16,y+14,100,16,{font:'700 9px Arial',color:p.accent,maxLines:1});text(ctx,String(it[1]),x+16,y+38,225,26,{font:'600 16px Arial',color:p.ink,maxLines:2})});menuPreview(ctx,s,p,M+38,785,550,270,{cards:3});totalBlock(ctx,s,p,M+38,1080,550,130,{accentFill:true});text(ctx,p.brandName+' / '+String(s.date||'EVENT'),725,205,185,24,{font:'700 12px Arial',color:p.deep,maxLines:3});for(let i=0;i<42;i++){const x=735+i*4.2,w=i%5===0?3:i%3===0?2:1;ctx.fillStyle=p.ink;ctx.fillRect(x,830,w,190)}text(ctx,'№ '+String(s.id||s.orderId||'0000'),725,1040,180,24,{font:'700 15px Arial',color:p.ink,maxLines:1});text(ctx,'Покажите этот билет хорошему настроению.',725,1100,170,30,{font:'12px Arial',color:p.muted,maxLines:4});
}else if(id==='solar-experience'){
const grad=ctx.createLinearGradient(0,0,W,H);grad.addColorStop(0,'#ffd43d');grad.addColorStop(.5,'#f7b40b');grad.addColorStop(1,'#ef8800');ctx.fillStyle=grad;ctx.fillRect(0,0,W,H);logoOrBrand(ctx,logo,p,{x:M,y:52});text(ctx,title,M,210,430,64,{font:'700 48px Arial',color:p.deep,maxLines:3});text(ctx,event,M,400,390,30,{font:'16px Arial',color:'#5d4719',maxLines:2});ctx.save();ctx.strokeStyle='rgba(255,255,255,.55)';ctx.lineWidth=2;ctx.beginPath();ctx.arc(720,430,330,0,Math.PI*2);ctx.stroke();ctx.beginPath();ctx.arc(720,430,270,0,Math.PI*2);ctx.stroke();ctx.restore();circleImage(ctx,hero,735,445,215);const steps=[['01','Меню'],['02','Готовим'],['03','Доставляем']];steps.forEach((it,i)=>{const yy=650+i*115;roundRect(ctx,M,yy,330,86,43,'rgba(255,255,255,.42)','rgba(255,255,255,.6)');text(ctx,it[0],M+26,yy+18,50,24,{font:'700 15px Arial',color:p.deep,maxLines:1});text(ctx,it[1],M+86,yy+24,190,30,{font:'700 18px Arial',color:p.deep,maxLines:1})});roundRect(ctx,515,800,431,330,28,'rgba(16,47,51,.92)',null);menuPreview(ctx,s,{...p,paper:'rgba(255,255,255,.08)',line:'rgba(255,255,255,.2)',ink:'#fff',accent:'#ffd95f'},545,835,371,220,{dark:true,cards:3});text(ctx,'ИТОГО',M,1080,220,24,{font:'700 13px Arial',color:p.deep,maxLines:1});text(ctx,money(s.pricing?.total),M,1118,420,64,{font:'700 47px Arial',color:p.deep,maxLines:1});text(ctx,'Событие, которое хочется запомнить.',M,1210,600,32,{font:'700 22px Arial',color:p.deep,maxLines:2});
}
canvas.dataset.sunClassicTemplate=id;canvas.dataset.sunClassicCover='1';return canvas;
}
function correctPageNumbers(pages,start,total,innerId){const foot=(PALETTES[innerId]||PALETTES.light).foot||'#fff';pages.forEach((canvas,i)=>{try{const scale=canvas.width/W,ctx=canvas.getContext('2d');ctx.save();ctx.setTransform(scale,0,0,scale,0,0);ctx.fillStyle=foot;ctx.fillRect(W-190,H-50,150,40);text(ctx,String(start+i)+' / '+String(total),W-M,H-34,100,16,{font:'10px Arial',color:(PALETTES[innerId]||PALETTES.light).muted,align:'right',maxLines:1});ctx.restore()}catch(_){}})}
async function renderPages(snapshot,baseRenderer){
if(typeof baseRenderer!=='function')throw new Error('Base PDF renderer is unavailable');
const id=String(snapshot?.offerTemplateId||'light');
if(ARCHIVE_SET.has(id))return baseRenderer(snapshot);
if(!CLASSIC_SET.has(id))return baseRenderer(snapshot);
const innerId=INNER_THEME[id]||'light',inner={...snapshot,offerTemplateId:innerId};
const [cover,basePages]=await Promise.all([renderCover(snapshot,id),baseRenderer(inner)]),pages=[cover,...(basePages||[])],total=pages.length;
try{const ctx=cover.getContext('2d'),p=PALETTES[id]||PALETTES.light;ctx.save();ctx.setTransform(SCALE,0,0,SCALE,0,0);footer(ctx,p,1,total,snapshot.brandName);ctx.restore()}catch(_){}
correctPageNumbers(basePages||[],2,total,innerId);
return pages;
}
function installPreviewStyles(){if(document.getElementById('sunClassicOfferPreviewV1767'))return;const style=document.createElement('style');style.id='sunClassicOfferPreviewV1767';style.textContent=`
.sun-v1764-offer-template-grid{grid-template-columns:repeat(3,minmax(0,1fr));max-height:none;overflow:visible;padding:2px 3px 5px}
.sun-v1764-offer-template-grid button{min-width:0}
.sun-offer-template-mini[data-template-mini]{position:relative;isolation:isolate}
.sun-offer-template-mini[data-template-mini="warm-sun"] i,.sun-offer-template-mini[data-template-mini="bento-cards"] i,.sun-offer-template-mini[data-template-mini="event-story"] i,.sun-offer-template-mini[data-template-mini="black-gold"] i,.sun-offer-template-mini[data-template-mini="personal-letter"] i,.sun-offer-template-mini[data-template-mini="event-ticket"] i,.sun-offer-template-mini[data-template-mini="solar-experience"] i,.sun-offer-template-mini[data-template-mini="midnight-compact"] i,.sun-offer-template-mini[data-template-mini="neon-emerald"] i{display:none!important}
.sun-offer-template-mini[data-template-mini="warm-sun"]{background:radial-gradient(circle at 75% 32%,#fff 0 19%,#f0ac18 20% 22%,transparent 23%),linear-gradient(#fff4d4,#ffe3a1)!important}
.sun-offer-template-mini[data-template-mini="bento-cards"]{background:linear-gradient(90deg,transparent 7%,#fff 7% 30%,transparent 30% 35%,#fff 35% 58%,transparent 58% 63%,#ffd05a 63% 93%,transparent 93%),#f3f2ec!important}
.sun-offer-template-mini[data-template-mini="event-story"]{background:radial-gradient(circle at 14% 45%,#c98b40 0 5%,transparent 6%),radial-gradient(circle at 34% 45%,#c98b40 0 5%,transparent 6%),radial-gradient(circle at 54% 45%,#c98b40 0 5%,transparent 6%),radial-gradient(circle at 74% 45%,#c98b40 0 5%,transparent 6%),linear-gradient(#f6efe4 0 57%,#b88d69 57% 100%)!important}
.sun-offer-template-mini[data-template-mini="black-gold"]{background:linear-gradient(90deg,rgba(0,0,0,.94),rgba(0,0,0,.18)),linear-gradient(135deg,#664326,#1b1710)!important;border-color:#6d5429!important}
.sun-offer-template-mini[data-template-mini="personal-letter"]{background:repeating-linear-gradient(0deg,#fff8e9 0 13%,#eadac0 14% 15%)!important}
.sun-offer-template-mini[data-template-mini="event-ticket"]{background:linear-gradient(90deg,#fffaf0 0 70%,#173a50 70% 72%,#f1e6d2 72% 100%)!important}
.sun-offer-template-mini[data-template-mini="solar-experience"]{background:radial-gradient(circle at 72% 44%,#fff5b9 0 23%,transparent 24%),linear-gradient(135deg,#ffd63b,#ed8a00)!important}
.sun-offer-template-mini[data-template-mini="midnight-compact"]{background:linear-gradient(90deg,#0a1b25 0 65%,#152f3b 65% 100%)!important;border-color:#40535e!important}
.sun-offer-template-mini[data-template-mini="neon-emerald"]{background:radial-gradient(circle at 50% 20%,#0b5037,transparent 45%),#031419!important;border-color:#2aa85a!important}
.sun-v1767-group-label{grid-column:1/-1;font-size:10px;font-weight:900;letter-spacing:.07em;text-transform:uppercase;color:#7d858c;padding:6px 2px 1px}
#sunClientOfferPreview .sun-offer-page-canvas[data-sun-classic-cover="1"]{box-shadow:0 18px 50px rgba(31,35,36,.16)}
`;document.head.appendChild(style)}
function groupPicker(){if(window.CateriumProposalPDF?.CURATED_IDS)return;const grid=document.querySelector('.sun-v1764-offer-template-grid');if(!grid||grid.dataset.sunV1767Grouped==='1')return;const classic=[...grid.querySelectorAll('button')].filter(b=>CLASSIC_SET.has(b.dataset.v1764OfferTemplate)),archive=[...grid.querySelectorAll('button')].filter(b=>ARCHIVE_SET.has(b.dataset.v1764OfferTemplate));if(!classic.length&&!archive.length)return;grid.dataset.sunV1767Grouped='1';const label=t=>{const d=document.createElement('div');d.className='sun-v1767-group-label';d.textContent=t;return d};const modern=[...grid.querySelectorAll('button')].filter(b=>!CLASSIC_SET.has(b.dataset.v1764OfferTemplate)&&!ARCHIVE_SET.has(b.dataset.v1764OfferTemplate));grid.innerHTML='';if(classic.length){grid.appendChild(label('Классические — как раньше'));classic.forEach(b=>grid.appendChild(b))}if(modern.length){grid.appendChild(label('Современная коллекция'));modern.forEach(b=>grid.appendChild(b))}if(archive.length){grid.appendChild(label('Дополнительные стили'));archive.forEach(b=>grid.appendChild(b))}}
function maintain(){installPreviewStyles();groupPicker()}
const observer=new MutationObserver(()=>setTimeout(maintain,0));if(document.documentElement)observer.observe(document.documentElement,{childList:true,subtree:true});if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',maintain,{once:true});else maintain();
window.SunClassicOfferPDFV1767={VERSION,RELEASE,CLASSIC_IDS:[...CLASSIC_IDS],ARCHIVE_IDS:[...ARCHIVE_IDS],renderPages,renderCover,checks:()=>({version:VERSION,classic:CLASSIC_IDS.length,archive:ARCHIVE_IDS.length,styles:Boolean(document.getElementById('sunClassicOfferPreviewV1767'))})};
})();