1import{j as e,A as rt,m as J}from"./vendor-ui-BRVg3_iW.js";import{r as t}from"./vendor-react-fhnP-ZxB.js";import{ah as fr,_ as L,S as oe,x as v,P as Ft,a6 as br,a7 as Fe,al as yt,am as vt,an as yr,ao as wt,b0 as vr,aY as wr,$ as Ge,at as ft,az as De,j as Ue,aD as jr,ak as Wt,ap as Nr,y as Te,R as qt,av as jt,o as K,v as N,bm as kr,Z as Nt,k as Cr,bb as Ir,bc as Sr,u as kt,ae as Ot,a3 as Ut,ad as at,z as Pr,w as Tr,a5 as Er,a1 as Ar,a2 as Rr,a4 as Mr,aX as Ye,c0 as Dr,aj as Ur,bN as Lr,bM as zr,C as _r,aO as Gr,c1 as Vr,b8 as Fr,a_ as Lt,bo as Wr}from"./index-BTZS4ZAF.js";import{T as Bt,a as Kt,b as He,c as $e}from"./tabs-B-u7iS49.js";import{u as qr}from"./usePlanRestrictions-sAzuqAso.js";import{u as Or,I as Br,a as bt}from"./ImageUploadSlot-uKa_fttQ.js";import{V as Kr}from"./volume-x-BhXt1yjf.js";import{V as Ht}from"./volume-2-BQWO2kjM.js";import{C as zt,s as U}from"./showcaseAssets-D4BysKDc.js";import{T as st}from"./textarea-D-Y40bXc.js";import{L as Pe}from"./label-BPIIQwcF.js";import{T as Hr}from"./tag-Dhfe2m_r.js";import{S as $t,a as $r}from"./scroll-area-DqwOcre8.js";import{C as Yr,a as Xr,b as Jr}from"./collapsible-CSOUtSE9.js";import{S as Yt}from"./send-BPUeirQC.js";import{M as Xt}from"./message-square-BP5RKd48.js";import{M as dt}from"./mic-CF1Xk4wD.js";import{InsufficientCreditsModal as Zr}from"./InsufficientCreditsModal-S9k4UDiw.js";import{C as Qr}from"./coins-CiMmuh5b.js";import{Z as ea}from"./zoom-in-rqRggvpq.js";import{P as ta}from"./paperclip-DPXMbfdu.js";import{L as _t}from"./lock-DeRcLZvT.js";import{S as ra}from"./SaveToAssetsModal-DUTOvyPY.js";import{M as aa}from"./minimize-2-IlIaMOpv.js";import{D as sa}from"./download-DVZYklFy.js";import{u as na}from"./useRemixHydration-DNXyxCHI.js";import{U as ia}from"./upload-blZ-ZbK1.js";import{L as oa}from"./link-2-C1hWKL9E.js";import"./vendor-three-BixXOMS4.js";import"./vendor-charts-CM-rxR9X.js";import"./vendor-radix-B2hiDlNL.js";import"./vendor-query-fmpM_ONB.js";import"./vendor-supabase-BDcQUG0T.js";import"./vendor-date-D8Ds2zcx.js";import"./AssetPickerModal-dCg4wh70.js";import"./heart-CZ4amK0d.js";import"./pickedAssetToFile-DO1Aqj9f.js";import"./star-CcfTLwr2.js";import"./save-BsTZEswx.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const la=fr("Pen",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]]),Ze="https://uemglyheqrjfpanjsjkh.supabase.co/storage/v1/object/public/showcase-assets",mt=[{video:`${Ze}/videos/velvet-creme-ugc.mp4`,thumb:`${Ze}/products/velvet-creme.png`,label:"Velvet Creme"},{video:`${Ze}/videos/pure-serum.mp4`,thumb:`${Ze}/products/pure-serum.png`,label:"Aurora Botanicals Serum"}];function ca(){const a=t.useRef(null),[o,u]=t.useState(!0),[n,i]=t.useState(!0),[d,w]=t.useState(0),M=mt[d];t.useEffect(()=>{a.current&&a.current.play().catch(()=>{u(!1)})},[d]),t.useEffect(()=>{const S=setInterval(()=>{w(I=>(I+1)%mt.length)},8e3);return()=>clearInterval(S)},[]);const y=()=>{a.current&&(a.current.muted=!a.current.muted,i(!n))};return e.jsxs("div",{className:"relative w-full max-w-[200px] sm:max-w-sm mx-auto",children:[e.jsx("div",{className:"absolute -inset-4 sm:-inset-6 bg-gradient-to-r from-primary/30 via-emerald-500/20 to-primary/30 rounded-[2rem] sm:rounded-[3rem] blur-xl sm:blur-2xl opacity-50 pointer-events-none"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"relative rounded-[1.5rem] sm:rounded-[2.5rem] bg-gradient-to-br from-zinc-800 via-zinc-900 to-black p-1.5 sm:p-2 shadow-2xl",children:e.jsxs("div",{className:"relative rounded-[1.25rem] sm:rounded-[2rem] overflow-hidden bg-black aspect-[9/16]",children:[e.jsx("div",{className:"absolute top-2 sm:top-3 left-1/2 -translate-x-1/2 z-20 w-16 sm:w-24 h-5 sm:h-7 bg-black rounded-full"}),e.jsx("video",{ref:a,src:M.video,poster:M.thumb,muted:n,autoPlay:!0,loop:!0,playsInline:!0,className:"absolute inset-0 w-full h-full object-cover"},M.video),e.jsx("div",{className:"absolute bottom-0 inset-x-0 p-2 sm:p-3 bg-gradient-to-t from-black/60 to-transparent z-10",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] sm:text-xs text-white/80 font-medium truncate mr-2",children:M.label}),e.jsx(L,{variant:"ghost",size:"icon",className:"h-6 w-6 sm:h-7 sm:w-7 bg-white/10 hover:bg-white/20 text-white rounded-full shrink-0",onClick:y,children:n?e.jsx(Kr,{className:"h-3 w-3 sm:h-3.5 sm:w-3.5"}):e.jsx(Ht,{className:"h-3 w-3 sm:h-3.5 sm:w-3.5"})})]})}),e.jsxs("div",{className:"absolute top-8 sm:top-12 left-2 sm:left-3 z-20 px-2 py-0.5
6sm:py-1 rounded-full bg-primary/90 backdrop-blur-sm text-[10px] sm:text-xs font-bold text-primary-foreground flex items-center gap-1 shadow-lg",children:[e.jsx(oe,{className:"h-2.5 w-2.5 sm:h-3 sm:w-3"}),e.jsx("span",{className:"hidden sm:inline",children:"AI Generated"}),e.jsx("span",{className:"sm:hidden",children:"AI"})]})]})}),e.jsx("div",{className:"absolute -bottom-4 sm:-bottom-5 left-1/2 -translate-x-1/2 flex gap-1.5 sm:gap-2",children:mt.map((S,I)=>e.jsx("button",{onClick:()=>w(I),className:v("w-1.5 h-1.5 rounded-full transition-all duration-300",I===d?"bg-primary w-3 sm:w-4":"bg-muted-foreground/30 hover:bg-muted-foreground/50")},I))})]})]})}const da=288,ut=da*(16/9),Qe=[{video:U.midnightPerfume.video,thumb:U.midnightPerfume.thumb,title:U.midnightPerfume.title,category:U.midnightPerfume.category,template:U.midnightPerfume.template,type:"product"},{video:U.noirCoffeeUgc.video,thumb:U.noirCoffeeUgc.thumb,title:U.noirCoffeeUgc.title,category:U.noirCoffeeUgc.category,template:U.noirCoffeeUgc.template,type:"ugc"},{video:U.velvetLipstick.video,thumb:U.velvetLipstick.thumb,title:U.velvetLipstick.title,category:U.velvetLipstick.category,template:U.velvetLipstick.template,type:"product"},{video:U.velvetCremeUgc.video,thumb:U.velvetCremeUgc.thumb,title:U.velvetCremeUgc.title,category:U.velvetCremeUgc.category,template:U.velvetCremeUgc.template,type:"ugc"},{video:U.pureSerum.video,thumb:U.pureSerum.thumb,title:U.pureSerum.title,category:U.pureSerum.category,template:U.pureSerum.template,type:"product"},{video:U.noirEssenceUgc.video,thumb:U.noirEssenceUgc.thumb,title:U.noirEssenceUgc.title,category:U.noirEssenceUgc.category,template:U.noirEssenceUgc.template,type:"ugc"}],ma=1.2;function ua({onSelectTemplate:a}){const o=t.useRef(null),u=t.useRef(new Map),n=t.useRef(new Map),[i,d]=t.useState(null),[w,M]=t.useState(null),[y,S]=t.useState(new Set),[I,c]=t.useState(new Set),[j,B]=t.useState(new Map),[P,re]=t.useState([]),_=t.useRef(0),z=t.useRef(new Map),le=t.useRef(null),[q,H]=t.useState(!1),[k,G]=t.useState(0),[F,D]=t.useState(0),[W,$]=t.useState(!1),T=t.useRef(null),me=[...Qe,...Qe,...Qe];t.useEffect(()=>{console.log("[Showcase] mounted",{version:zt,itemCount:Qe.length})},[]);const ue=t.useCallback((r,s,C)=>{const b=2+Math.floor(Math.random()*3),V=[];for(let g=0;g<b;g++)V.push({id:_.current++,x:r,y:s+Math.random()*Math.min(C,ut),vx:(Math.random()-.5)*6,vy:(Math.random()-.5)*3-1,life:1,size:2+Math.random()*4});re(g=>[...g,...V].slice(-60))},[]);t.useEffect(()=>{let r;const s=()=>{re(C=>C.map(b=>({...b,x:b.x+b.vx,y:b.y+b.vy,life:b.life-.025,vy:b.vy+.08,vx:b.vx*.98})).filter(b=>b.life>0)),r=requestAnimationFrame(s)};return r=requestAnimationFrame(s),()=>cancelAnimationFrame(r)},[]);const l=t.useCallback(()=>{const r=o.current;if(!r)return;const s=r.getBoundingClientRect();le.current=s;const C=s.left+s.width/2,b=new Map;let V=null,g=1/0;n.current.forEach((Q,de)=>{const O=Q.getBoundingClientRect(),Ae=O.left,X=O.right,Z=O.width,he=Ae+Z/2;let ee=0;if(X<=C)ee=100;else if(Ae>=C)ee=0;
6else{const ke=C-Ae;ee=Math.max(0,Math.min(100,ke/Z*100))}if(b.set(de,ee),ee>5&&ee<95){const ke=Date.now(),ge=z.current.get(de)||0;ke-ge>60&&(ue(C,O.top,O.height),z.current.set(de,ke))}const ve=u.current.get(de);ee>0?ve&&ve.paused&&ve.play().catch(()=>{}):ve&&!ve.paused&&(ve.pause(),ve.currentTime=0);const Xe=Math.abs(he-C);Xe<g&&(g=Xe,V=de)}),B(b),V!==null&&g<150&&d(V)},[ue]),se=t.useCallback(()=>{const r=o.current;if(!r)return;const{scrollLeft:s,scrollWidth:C}=r,b=C/3;s<b*.1?r.scrollLeft=b+s:s>b*1.9&&(r.scrollLeft=s-b),requestAnimationFrame(l)},[l]);t.useEffect(()=>{let r;const s=()=>{const C=o.current;C&&!q&&!W&&(C.scrollLeft+=ma),r=requestAnimationFrame(s)};return r=requestAnimationFrame(s),()=>cancelAnimationFrame(r)},[q,W]);const xe=r=>{const s=o.current;s&&(H(!0),G(r.clientX),D(s.scrollLeft),T.current=r.pointerId,s.setPointerCapture(r.pointerId),s.style.cursor="grabbing")},ne=r=>{if(!q||T.current!==r.pointerId)return;const s=o.current;if(!s)return;r.preventDefault();const C=r.clientX-k;s.scrollLeft=F-C},ce=r=>{if(T.current!==r.pointerId)return;const s=o.current;s&&T.current!==null&&s.releasePointerCapture(T.current),H(!1),T.current=null,s&&(s.style.cursor="grab")},ye=r=>{const s=o.current;s&&Math.abs(r.deltaY)>Math.abs(r.deltaX)&&(r.preventDefault(),s.scrollLeft+=r.deltaY)};t.useEffect(()=>{const r=o.current;if(!r)return;const s=r.scrollWidth/3;return r.scrollLeft=s,r.addEventListener("scroll",se,{passive:!0}),setTimeout(l,100),()=>{r.removeEventListener("scroll",se)}},[se,l]);const Ee=r=>{if(q)return;M(r);const s=u.current.get(r);s&&(s.currentTime=0,s.play().catch(()=>{}))},Ne=r=>{if(M(null),(j.get(r)||0)===0){const C=u.current.get(r);C&&(C.pause(),C.currentTime=0)}},Le=t.useCallback(r=>{if(console.log(`[Showcase] Video loaded: index=${r}`),S(C=>new Set(C).add(r)),(j.get(r)||0)>0){const C=u.current.get(r);C&&C.play().catch(()=>{})}},[j]),m=t.useCallback((r,s)=>{console.error(`[Showcase] Video failed to load: index=${r}, url=${s}`),c(C=>new Set(C).add(r))},[]),A=r=>w===r?100:j.get(r)||0,Y=r=>i===r||w===r;return e.jsx("section",{className:"py-20 relative overflow-hidden bg-background",children:e.jsxs("div",{className:"max-w-[1600px] mx-auto px-4",children:[e.jsxs("div",{className:"text-center mb-12",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 px-4 py-1.5 rounded-full bg-primary/10 border border-primary/20 mb-6",children:[e.jsx(oe,{className:"h-3.5 w-3.5 text-primary"}),e.jsx("span",{className:"text-xs font-semibold text-primary tracking-wide uppercase",children:"Ads Showcase"})]}),e.jsxs("h2",{className:"text-4xl md:text-5xl font-bold text-foreground mb-4 tracking-tight",children:["MAKE YOUR PRODUCTS ",e.jsx("span",{className:"text-primary",children:"UNSKIPPABLE"})]}),e.jsx("p",{className:"text-muted-foreground text-lg max-w-2xl mx-auto",children:"Create scroll-stopping video ads with AI. Each example was generated in under 2 minutes."})]}),e.jsxs("div",{className:"relative",onMouseEnter:()=>$(!0),onMouseLeave:()=>$(!1),children:[e.jsxs("div",{className:"absolute left-1/2 z-20 pointer-events-none -translate-x-1/2",style:{top:0,height:`${ut}px`},children:[e.jsx("div",{className:"absolute inset-0 w-20 -translate-x-1/2 bg-gradient-to-r from-transparent via-primary/20 to-transparent blur-3xl"}),e.jsx("div",{className:"absolute inset-0 w-10 -translate-x-1/2 bg-gradient-to-r from-transparent via-primary/35 to-transparent blur-xl animate-laser-pulse"}),e.jsx("div",{className:"absolute inset-0 w-5 -translate-x-1/2 bg-gradient-to-r from-transparent via-primary/55 to-transparent blur-md"}),e.jsx("div",{className:"absolute inset-y-0 left-1/2 w-[3px] -translate-x-1/2 bg-primary shadow-[0_0_25px_6px] shadow-primary/70 animate-laser-pulse"}),e.jsx("div",{className:"absolute left-1/2 w-10 h-28 bg-gradient-to-b from-transparent via-primary/80 to-transparent rounded-full blur-lg animate-laser-sweep"}),e.jsx("div",{className:"absolute -top-2 left-1/2 -translate-x-1/2 w-4 h-4 bg-primary rounded-full blur-sm shadow-[0_0_20px_6px] shadow-primary/80"}),e.jsx("div",{className:"absolute -bottom-2 left-1/2 -translate-x-1/2 w-4 h-4 bg-primary rounded-full blur-sm shadow-[0_0_20px_6px] shadow-primary/80"})]}),e.jsx("div",{className:"absolute inset-0 z-30 pointer-events-none overflow-hidden",style:{height:`${ut}px`},children:P.map(r=>{var s;return e.jsx("div",{className:"absolute rounded-full bg-primary",style:{left:r.x-(((s=le.current)==null?void 0:s.left)||0),top:r.y,width:r.size,height:r.size,opacity:r.life,boxShadow:`0 0 ${r.size*3}px ${r.size*1.5}px hsl(65 100% 50% / ${r.life*.6})`,transform:"translate(-50%, -50%)"}},r.id)})}),e.jsx("div",{ref:o,className:"flex gap-5 overflow-x-auto pb-4 cursor-grab select-none touch-p
6an-x",style:{scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch"},onPointerDown:xe,onPointerMove:ne,onPointerUp:ce,onPointerCancel:ce,onWheel:ye,children:me.map((r,s)=>{const C=Y(s),b=I.has(s),V=A(s);return e.jsxs("div",{ref:g=>{g&&n.current.set(s,g)},"data-index":s,className:"flex-shrink-0 w-72 cursor-pointer group/card",onMouseEnter:()=>Ee(s),onMouseLeave:()=>Ne(s),onClick:()=>!q&&(a==null?void 0:a(r.template)),children:[e.jsxs("div",{className:v("relative rounded-xl overflow-hidden aspect-[9/16] bg-card","ring-2 ring-transparent transition-all duration-300",C&&"ring-primary/60 scale-[1.02]",i===s&&"shadow-[0_0_30px_-5px] shadow-primary/40"),children:[e.jsx("img",{src:r.thumb,alt:r.title,className:"absolute inset-0 w-full h-full object-cover",loading:"lazy",draggable:!1,onError:g=>{console.error(`[Showcase] Thumb failed: ${r.thumb}`),g.target.src="/placeholder.svg"}}),e.jsx("video",{ref:g=>{g&&(u.current.set(s,g),(V>0||w===s)&&g.play().catch(()=>{}))},src:`${r.video}?v=${zt}`,muted:!0,loop:!0,playsInline:!0,preload:"auto",onLoadedData:()=>Le(s),onCanPlay:g=>{(V>0||w===s)&&g.target.play().catch(()=>{})},onError:()=>m(s,r.video),style:{clipPath:`inset(0 ${100-V}% 0 0)`},className:"absolute inset-0 w-full h-full object-cover"}),C&&!y.has(s)&&!b&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/40",children:e.jsx("div",{className:"w-10 h-10 rounded-full bg-primary/20 backdrop-blur-sm flex items-center justify-center animate-pulse",children:e.jsx(Ft,{className:"w-4 h-4 text-primary fill-primary"})})}),b&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/60",children:e.jsxs("div",{className:"flex flex-col items-center gap-1 text-muted-foreground",children:[e.jsx(br,{className:"w-6 h-6"}),e.jsx("span",{className:"text-[10px]",children:"Video unavailable"})]})}),e.jsxs("div",{className:v("absolute top-2 left-2 px-2 py-0.5 rounded-md text-[10px] font-medium",r.type==="ugc"?"bg-primary text-primary-foreground":"bg-background/60 text-foreground/90 backdrop-blur-sm"),children:[r.type==="ugc"&&e.jsx(Fe,{className:"w-2.5 h-2.5 inline mr-1"}),r.category]}),i===s&&e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-primary/10 via-trans
6parent to-transparent pointer-events-none"})]}),e.jsx("p",{className:v("mt-2.5 text-sm font-medium text-center transition-colors",C?"text-primary":"text-muted-foreground"),children:r.title})]},`${r.title}-${s}`)})}),e.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-20 bg-gradient-to-r from-background to-transparent pointer-events-none z-10"}),e.jsx("div",{className:"absolute right-0 top-0 bottom-0 w-20 bg-gradient-to-l from-background to-transparent pointer-events-none z-10"})]})]})})}const pa=({open:a,onOpenChange:o,productData:u,onConfirm:n})=>{const[i,d]=t.useState(u),[w,M]=t.useState(0),[y,S]=t.useState(!1),I=()=>{const c=i.productImages[w]||i.productImages[0];n({...i,selectedImage:c}),o(!1)};return e.jsx(yt,{open:a,onOpenChange:o,children:e.jsxs(vt,{className:"max-w-3xl max-h-[90vh] overflow-y-auto bg-background/95 backdrop-blur-xl border-border/50",children:[e.jsxs(yr,{children:[e.jsxs(wt,{className:"flex items-center gap-2 text-xl",children:[e.jsx(oe,{className:"h-5 w-5 text-primary"}),"Product Ad Kit"]}),e.jsx(vr,{children:"We extracted your product details. Review and edit before generating your video ad."})]}),e.jsxs("div",{className:"space-y-6 py-4",children:[i.logoUrl&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(Pe,{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(wr,{className:"h-4 w-4"}),"Brand Logo"]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-lg border border-border/50 bg-white flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:i.logoUrl,alt:"Brand logo",className:"max-w-full max-h-full object-contain",onError:c=>{c.target.style.display="none"}})}),e.jsx("div",{className:"flex-1",children:e.jsx(Ge,{value:i.logoUrl||"",onChange:c=>d(j=>({...j,logoUrl:c.target.value})),className:"bg-muted/30 text-sm",placeholder:"Logo URL"})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Pe,{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(ft,{className:"h-4 w-4"}),"Product Images"]}),e.jsxs(De,{variant:"secondary",className:"text-xs",children:[i.productImages.length," found"]})]}),i.productImages.length>0?e.jsx("div",{className:"grid grid-cols-4 gap-3",children:i.productImages.slice(0,8).map((c,j)=>e.jsxs("button",{onClick:()=>M(j),className:v("relative aspect-square rounded-lg overflow-hidden border-2 transition-all",w===j?"border-primary ring-2 ring-primary/30":"border-border/50 hover:border-primary/50"),children:[e.jsx("img",{src:c,alt:`Product ${j+1}`,className:"w-full h-full object-cover",onError:B=>{B.target.src="/placeholder.svg"}}),w===j&&e.jsx("div",{className:"absolute top-1 right-1 bg-primary rounded-full p-0.5",children:e.jsx(Ue,{className:"h-3 w-3 text-primary-foreground"})})]},j))}):e.jsx("div",{className:"bg-muted/30 rounded-lg p-6 text-center text-muted-foreground",children:"No images found. You'll be able to upload one in the next step."}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Select the main product image for your video ad"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Pe,{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(jr,{className:"h-4 w-4"}),"Product Name"]}),e.jsx(Ge,{value:i.productName,onChange:c=>d(j=>({...j,productName:c.target.value})),className:"bg-muted/30",placeholder:"Enter product name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Pe,{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(la,{className:"h-4 w-4"}),"Description"]}),e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>S(!y),className:"text-xs",children:y?"Done":"Edit"})]}),y?e.jsx(st,{value:i.productDescription,onChange:c=>d(j=>({...j,productDescription:c.target.value})),className:"bg-muted/30 min-h-[100px]",placeholder:"Enter product description"}):e.jsx("div",{className:"bg-muted/30 rounded-lg p-3 text-sm text-muted-foreground min-h-[60px]",children:i.productDescription||"No description found"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Pe,{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Hr,{className:"h-4 w-4"}),"Brand"]}),e.jsx(Ge,{value:i.brandName||"",onChange:c=>d(j=>({...j,brandName:c.target.value})),className:"bg-muted/30",placeholder:"Brand name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Pe,{className:"text-sm font-medium",children:"Category"}),e.jsx(Ge,{value:i.category||"",onChange:c=>d(j=>({...j,category:c.target.value})),className:"bg-muted/30",placeholder:"Product category"})]})]}),i.brandColors&&i.brandColors.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Pe,{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Wt,{className:"h-4 w-4"}),"Brand Colors"]}),e.jsx("div",{className:"flex gap-2",children:i.brandColors.map((c,j)=>e.jsx("div",{className:"w-10 h-10 rounded-lg border border-border/50 shadow-sm cursor-pointer hover:scale-110 transition-transform",style:{backgroundColor:c},title:c},j))})]}),i.price&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(De,{variant:"outline",className:"text-lg px-4 py-1",children:i.price})})]}),e.jsxs(Nr,{className:"flex gap-2",children:[e.jsx(L,{variant:"outline",onClick:()=>o(!1),children:"Cancel"}),e.jsxs(L,{onClick:I,className:"gap-2",disabled:!i.productName,children:[e.jsx(Ue,{className:"h-4 w-4"}),"Looks Good, Continue"]})]})]})})},ha=[{label:"Tech Influencer",prompt:"A young tech influencer, trendy and modern, casual but polished"},{label:"Luxury Model",prompt:"An elegant, sophisticated model with a premium luxury aesthetic"},{label:"Fitness Expert",prompt:"An athletic, energetic fitness enthusiast, motivational and friendly"},{label:"Beauty Guru",prompt:"A glamorous beauty influencer, stylish and approachable"},{label:"Corporate Pro",prompt:"A polished corporate professional, trustworthy and confident"},{label:"Lifestyle Blogger",prompt:"A relatable lifestyle content creator, warm and authentic"}];function ga({productName:a,productDescription:o,onPromptConfirmed:u,className:n}){const[i,d]=t.useState([{role:"assistant",content:`Let's create your perfect presenter for ${a||"your product"}! ⨠7 8Describe who you envision - their age, style, ethnicity, or vibe. Or try a quick suggestion below!`}]),[w,M]=t.useState(""),[y,S]=t.useState(!1),[I,c]=t.useState(null),[j,B]=t.useState(null),[P,re]=t.useState(!1),_=t.useRef(null);t.useEffect(()=>{_.current&&(_.current.scrollTop=_.current.scrollHeight)},[i]);const z=async k=>{const G=k||w.trim();if(!G||y)return;const F={role:"user",content:G};d(D=>[...D,F]),M(""),S(!0),c(null),B(null);try{const{data:D,error:W}=await K.functions.invoke("generate-presenter-prompt",{body:{messages:[...i,F].map(T=>({role:T.role,content:T.content}
8)),productContext:{productName:a,productDescription:o}}});if(W)throw new Error(W.message);if(D!=null&&D.error)throw new Error(D.error);const $={role:"assistant",content:D.content};d(T=>[...T,$]),D.isOptimizedPrompt&&c(D.content)}catch(D){console.error("Chat error:",D),N.error(D instanceof Error?D.message:"Failed to get AI response"),d(W=>[...W,{role:"assistant",content:"I had trouble with that. Try describing your presenter differently!"}])}finally{S(!1)}},le=async()=>{var k,G,F,D,W,$;if(I){re(!0);try{const{data:T,error:me}=await K.functions.invoke("nano-banana-chat",{body:{messages:[{role:"user",content:`Generate a professional headshot portrait: ${I}`}]}});if(me)throw new Error(me.message);if(T!=null&&T.error)throw new Error(T.error);const ue=($=(W=(D=(F=(G=(k=T.choices)==null?void 0:k[0])==null?void 0:G.message)==null?void 0:F.images)==null?void 0:D[0])==null?void 0:W.image_url)==null?void 0:$.url;if(ue)B(ue),N.success("Preview generated!");else throw new Error("No image generated")}catch(T){console.error("Preview generation error:",T),N.error("Failed to generate preview. Try again!")}finally{re(!1)}}},q=()=>{I&&(u(I),N.success("Presenter style saved!"))},H=async()=>{S(!0);try{const{data:k,error:G}=await K.functions.invoke("generate-presenter-prompt",{body:{messages:[...i,{role:"user",content:"Generate the final optimized avatar prompt based on our conversation."}
8],productContext:{productName:a,productDescription:o}}});if(G)throw new Error(G.message);const F={role:"assistant",content:k.content};d(D=>[...D,F]),k.isOptimizedPrompt&&c(k.content)}catch(k){console.error("Optimization error:",k),N.error("Failed to generate prompt")}finally{S(!1)}};return e.jsxs("div",{className:v("flex flex-col h-full",n),children:[e.jsxs("div",{ref:_,className:"flex-1 overflow-y-auto space-y-3 pr-1 scrollbar-thin scrollbar-thumb-muted scrollbar-track-transparent",children:[i.map((k,G)=>e.jsxs("div",{className:v("flex gap-2",k.role==="user"?"justify-end":"justify-start"),children:[k.role==="assistant"&&e.jsx("div",{className:"w-7 h-7 rounded-full bg-gradient-to-br from-primary/20 to-primary/5 flex items-center justify-center flex-shrink-0 ring-1 ring-primary/20",children:e.jsx(oe,{className:"h-3.5 w-3.5 text-primary"})}),e.jsx("div",{className:v("rounded-2xl px-3.5 py-2.5 max-w-[85%] text-sm leading-relaxed",k.role==="user"?"bg-primary text-primary-foreground rounded-br-md":"bg-muted/60 text-foreground rounded-bl-md border border-border/30"),children:k.content}),k.role==="user"&&e.jsx("div",{className:"w-7 h-7 rounded-full bg-primary/90 flex items-center justify-center flex-shrink-0",children:e.jsx(Fe,{className:"h-3.5 w-3.5 text-primary-foreground"})})]},G)),y&&e.jsxs("div",{className:"flex gap-2 justify-start",children:[e.jsx("div",{className:"w-7 h-7 rounded-full bg-gradient-to-br from-primary/20 to-primary/5 flex items-center justify-center ring-1 ring-primary/20",children:e.jsx(Te,{className:"h-3.5 w-3.5 text-primary animate-spin"})}),e.jsx("div",{className:"bg-muted/60 border border-border/30 rounded-2xl rounded-bl-md px-4 py-3",children:e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 bg-primary/40 rounded-full animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("span",{className:"w-2 h-2 bg-primary/40 rounded-full animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("span",{className:"w-2 h-2 bg-primary/40 rounded-full animate-bounce",style:{animationDelay:"300ms"}})]})})]})]}),I&&!y&&e.jsx("div",{className:"mt-3 p-3 rounded-xl bg-gradient-to-br from-primary/10 to-primary/5 border border-primary/20 space-y-3",children:j?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"relative aspect-[3/4] max-h-[160px] mx-auto rounded-lg overflow-hidden ring-2 ring-primary/30 shadow-lg",children:e.jsx("img",{src:j,alt:"Presenter preview",className:"w-full h-full object-cover"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(L,{size:"sm",onClick:q,className:"flex-1 gap-1.5 bg-primary hover:bg-primary/90",children:[e.jsx(Ue,{className:"h-3.5 w-3.5"}),"Use This Look"]}),e.jsxs(L,{size:"sm",variant:"outline",onClick:()=>{B(null),c(null)},className:"gap-1.5",children:[e.jsx(qt,{className:"h-3.5 w-3.5"}),"Try Again"]})]})]}):P?e.jsxs("div",{className:"flex flex-col items-center gap-2 py-4",children:[e.jsxs("div",{className:"relative w-16 h-16",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-primary/30 border-t-primary animate-spin"}),e.jsx(ft,{className:"absolute inset-0 m-auto h-6 w-6 text-primary/50"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Creating your presenter..."})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-primary",children:[e.jsx(jt,{className:"h-4 w-4"}),"Ready to preview your presenter!"]}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",children:I}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(L,{size:"sm",onClick:le,className:"flex-1 gap-1.5",children:[e.jsx(ft,{className:"h-3.5 w-3.5"}),"Generate Preview (2 credits)"]}),e.jsx(L,{size:"sm",variant:"ghost",onClick:()=>c(null),className:"text-muted-foreground",children:"Refine"})]})]})}),i.length<=2&&!y&&!I&&e.jsx("div",{className:"mt-3",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:ha.map(k=>e.jsx(De,{variant:"outline",className:"cursor-pointer hover:bg-primary/10 hover:border-primary/40 hover:text-primary transition-all text-xs py-1 px-2.5",onClick:()=>z(k.prompt),children:k.label},k.label))})}),i.length>2&&!I&&!y&&e.jsxs(L,{size:"sm",variant:"outline",onClick:H,className:"mt-3 gap-1.5 border-primary/30 text-primary hover:bg-primary/10",children:[e.jsx(oe,{className:"h-3.5 w-3.5"}),"Generate Presenter"]}),e.jsxs("div",{className:"flex gap-2 items-end mt-3",children:[e.jsx(st,{value:w,onChange:k=>M(k.target.value),placeholder:"Describe your ideal presenter...",className:"min-h-[52px] max-h-[80px] resize-none bg-muted/40 border-border/50 rounded-xl text-sm focus-visible:ring-primary/30",onKeyDown:k=>{k.key==="Enter"&&!k.shiftKey&&(k.preventDefault(),z())},disabled:y||P}),e.jsx(L,{size:"icon",onClick:()=>z(),disabled:!w.trim()||y||P,className:"h-[52px] w-11 rounded-xl shrink-0",children:y?e.jsx(Te,{className:"h-4 w-4 animate-spin"}):e.jsx(Yt,{className:"h-4 w-4"})})]})]})}const Ke=[{id:"f1-tech-millennial",name:"Maya",category:"Tech",description:"Millennial tech reviewer",gender:"female",defaultVoice:{id:"EXAVITQu4vr4xnSDxMaL",name:"Sarah",desc:"Warm, Friendly"},prompt:"Professional headshot of a 28-year-old South Asian woman with sleek black hair in a modern bob, minimal makeup, confident friendly smile, wearing a fitted charcoal blazer over white t-shirt, small gold hoop earrings, soft studio lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"f2-beauty-influencer",name:"Sofia",category:"Beauty",description:"Glamorous beauty guru",gender:"female",defaultVoice:{id:"FGY2WhTYpPnrIDTdsKH5",name:"Laura",desc:"Calm, Soothing"},prompt:"Professional headshot of a 25-year-old Latina woman with long wavy dark brown hair, flawless makeup with subtle highlighter, warm brown eyes, radiant smile, wearing an elegant cream silk blouse, delicate gold necklace, soft diffused lighting with catchlights, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"f3-fitness-coach",name:"Jasmine",category:"Fitness",description:"Energetic fitness pro",gender:"female",defaultVoice:{id:"cgSgspJ2msm6clMCkdW9",name:"Jessica",desc:"Energetic"},prompt:"Professional headshot of a 30-year-old African American woman with
8natural curly hair pulled back, athletic build, bright energetic smile, wearing a sleek black athletic top, minimal jewelry, glowing healthy skin, motivational expression, studio lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"f4-luxury-model",name:"Victoria",category:"Luxury",description:"Elegant sophisticate",gender:"female",defaultVoice:{id:"FGY2WhTYpPnrIDTdsKH5",name:"Laura",desc:"Calm, Soothing"},prompt:"Professional headshot of a 35-year-old European woman with elegant blonde hair in a low chignon, refined features, subtle sophisticated makeup, pearl stud earrings, wearing a luxurious black cashmere sweater, graceful confident expression, soft dramatic lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"f5-lifestyle-creator",name:"Emma",category:"Lifestyle",description:"Relatable content creator",gender:"female",defaultVoice:{id:"EXAVITQu4vr4xnSDxMaL",name:"Sarah",desc:"Warm, Friendly"},prompt:"Professional headshot of a 27-year-old Caucasian woman with natural auburn hair and soft waves, freckles, warm approachable smile, minimal natural makeup, wearing a cozy sage green sweater, dainty gold pendant necklace, warm friendly expression, natural lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"f6-corporate-pro",name:"Priya",category:"Corporate",description:"Polished executive",gender:"female",defaultVoice:{id:"FGY2WhTYpPnrIDTdsKH5",name:"Laura",desc:"Calm, Soothing"},prompt:"Professional headshot of a 38-year-old Indian woman with straight black hair in a professional style, subtle professional makeup, confident authoritative yet approachable expression, wearing a tailored navy blazer with white blouse, small diamond studs, executive presence, studio lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"f7-gen-z-trendy",name:"Zoe",category:"Trendy",description:"Gen-Z trendsetter",gender:"female",defaultVoice:{id:"cgSgspJ2msm6clMCkdW9",name:"Jessica",desc:"Energetic"},prompt:"Professional headshot of a 22-year-old mixed-race woman with textured curly hair and highlights, youthful glowing skin, playful confident smile, wearing an oversized vintage denim jacket, multiple ear piercings with tiny hoops, trendy effortless style, bright even lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"f8-mom-influencer",name:"Sarah",category:"Family",description:"Trusted mom figure",gender:"female",defaultVoice:{id:"EXAVITQu4vr4xnSDxMaL",name:"Sarah",desc:"Warm, Friendly"},prompt:"Professional headshot of a 34-year-old Caucasian woman with honey blonde hair in soft layers, warm maternal smile, natural fresh-faced makeup, wearing a casual cream cardigan, simple wedding band visible, approachable trustworthy expression, soft warm lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"f9-wellness-guru",name:"Mei",category:"Wellness",description:"Serene wellness expert",gender:"female",defaultVoice:{id:"FGY2WhTYpPnrIDTdsKH5",name:"Laura",desc:"Calm, Soothing"},prompt:"Professional headshot of a 32-year-old East Asian woman with long straight black hair, serene calm expression, minimal natural makeup, clear radiant skin, wearing a simple white linen top, jade pendant necklace, peaceful mindful presence, soft natural lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"f10-bold-creative",name:"Nia",category:"Creative",description:"Bold creative spirit",gender:"female",defaultVoice:{id:"cgSgspJ2msm6clMCkdW9",name:"Jessica",desc:"Energetic"},prompt:"Professional headshot of a 29-year-old Black woman with stunning natural afro, bold confident expression, artistic subtle makeup with defined brows, wearing a structured mustard yellow top, statement geometric earrings, creative powerful presence, dramatic studio lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"m1-tech-reviewer",name:"Alex",category:"Tech",description:"Modern tech expert",gender:"male",defaultVoice:{id:"TX3LPaxmHKxFdv7VOQHJ",name:"Liam",desc:"Friendly"},prompt:"Professional headshot of a 29-year-old East Asian man with modern short haircut, clean-shaven, friendly confident smile, wearing a casual navy hoodie over white t-shirt, subtle modern glasses, warm engaging expression, soft studio lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"m2-fitness-trainer",name:"Marcus",category:"Fitness",description:"Athletic fitness coach",gender:"male",defaultVoice:{id:"JBFqnCBsd6RMkjVDRZzb",name:"George",desc:"Confident"},prompt:"Professional headshot of a 32-year-old African American man with short fade haircut, athletic muscular build, bright motivational smile, wearing a fitted black performance shirt, healthy glowing skin, powerful encouraging presence, dynamic lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"m3-business-exec",name:"James",category:"Corporate",description:"Trusted business leader",gender:"male",defaultVoice:{id:"onwK4e9ZLuTAKqWW03F9",name:"Daniel",desc:"Professional"},prompt:"Professional headshot of a 42-year-old Caucasian man with salt-and-pepper hair neatly styled, well-groomed short beard, confident trustworthy expression, wearing a charcoal suit with light blue dress shirt, silver cufflinks, executive presence, professional lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"m4-lifestyle-influencer",name:"Diego",category:"Lifestyle",description:"Charismatic lifestyle creator",gender:"male",defaultVoice:{id:"TX3LPaxmHKxFdv7VOQHJ",name:"Liam",desc:"Friendly"},prompt:"Professional headshot of a 27-year-old Latino man with textured dar
8k hair and light stubble, warm charismatic smile, wearing a relaxed cream linen shirt with top button undone, silver chain necklace, approachable friendly vibe, natural warm lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"m5-luxury-refined",name:"Sebastian",category:"Luxury",description:"Sophisticated gentleman",gender:"male",defaultVoice:{id:"onwK4e9ZLuTAKqWW03F9",name:"Daniel",desc:"Professional"},prompt:"Professional headshot of a 36-year-old European man with slicked back dark hair, refined handsome features, subtle confident smile, wearing a premium black turtleneck sweater, expensive watch visible, elegant sophisticated presence, dramatic studio lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"m6-gen-z-creator",name:"Jordan",category:"Trendy",description:"Gen-Z content creator",gender:"male",defaultVoice:{id:"TX3LPaxmHKxFdv7VOQHJ",name:"Liam",desc:"Friendly"},prompt:"Professional headshot of a 23-year-old mixed-race man with curly hair and subtle highlights, youthful energetic expression, wearing an oversized vintage graphic tee, small hoop earring, trendy streetwear aesthetic, bright modern lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"m7-dad-relatable",name:"Mike",category:"Family",description:"Relatable everyday dad",gender:"male",defaultVoice:{id:"JBFqnCBsd6RMkjVDRZzb",name:"George",desc:"Confident"},prompt:"Professional headshot of a 38-year-old Caucasian man with short brown hair and friendly smile, light stubble, wearing a casual navy polo shirt, wedding band visible, warm approachable dad energy, trustworthy genuine expression, soft natural lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"m8-wellness-coach",name:"Raj",category:"Wellness",description:"Calm wellness expert",gender:"male",defaultVoice:{id:"onwK4e9ZLuTAKqWW03F9",name:"Daniel",desc:"Professional"},prompt:"Professional headshot of a 34-year-old South Asian man with neatly styled black hair, well-groomed beard, calm serene expression, wearing a relaxed white henley shirt, mala bead bracelet, peaceful mindful presence, soft diffused lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"m9-creative-artist",name:"Noah",category:"Creative",description:"Artistic creative type",gender:"male",defaultVoice:{id:"TX3LPaxmHKxFdv7VOQHJ",name:"Liam",desc:"Friendly"},prompt:"Professional headshot of a 30-year-old Caucasian man with messy artistic hair and light beard, creative thoughtful expression, wearing a black denim jacket over simple white tee, subtle tattoo visible on neck, artistic bohemian vibe, moody studio lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"},{id:"m10-mature-expert",name:"David",category:"Expert",description:"Distinguished authority",gender:"male",defaultVoice:{id:"JBFqnCBsd6RMkjVDRZzb",name:"George",desc:"Confident"},prompt:"Professional headshot of a 52-year-old Caucasian man with distinguished gray hair and warm smile, reading glasses pushed up on head, wearing a quality navy blazer with open collar shirt, scholarly wise appearance, authoritative yet approachable, warm professional lighting, looking directly at camera, photorealistic portrait, 8K quality, PURE WHITE background"}],_e={female:[{id:"EXAVITQu4vr4xnSDxMaL",label:"Sarah",desc:"Warm, Friendly"},{id:"FGY2WhTYpPnrIDTdsKH5",label:"Laura",desc:"Calm, Soothing"},{id:"cgSgspJ2msm6clMCkdW9",label:"Jessica",desc:"Energetic"}],male:[{id:"JBFqnCBsd6RMkjVDRZzb",label:"George",desc:"Confident"},{id:"TX3LPaxmHKxFdv7VOQHJ",label:"Liam",desc:"Friendly"},{id:"onwK4e9ZLuTAKqWW03F9",label:"Daniel",desc:"Professional"}]},xa="/assets/f1-tech-millennial-B6xO385z.png",fa="/assets/f2-beauty-influencer-CDyqnfEB.png",ba="/assets/f3-fitness-coach-DJ3kCBHl.png",ya="/assets/f4-luxury-model-DTDSVFUQ.png",va="/assets/f5-lifestyle-creator-BMpugP8c.png",wa="/assets/f6-corporate-pro-BID4Clvq.png",ja="/assets/f7-gen-z-trendy-B8-yd44S.png",Na="/assets/f8-mom-influencer-CSMyfG8a.png",ka="/assets/f9-wellness-guru-n_qMxQ0R.png",Ca="/assets/f10-bold-creative-CeXNm89k.png",Ia="/assets/m1-tech-reviewer-S37MKzfe.png",Sa="/assets/m2-fitness-trainer-C1kVacEv.png",Pa="/assets/m3-business-exec-BCYTmAAz.png",Ta="/assets/m4-lifestyle-influencer-JDhwtOVm.png",Ea="/assets/m5-luxury-refined-C7bhL51E.png",Aa="/assets/m6-gen-z-creator-BPlibTPX.png",Ra="/assets/m7-dad-relatable-B8HnsOAj.png",Ma="/assets/m8-wellness-coach-B-9Z2IZM.png",Da="/assets/m9-creative-artist-0spDfvRQ.png",Ua="/assets/m10-mature-expert-yGp6RBrh.png",pt={"f1-tech-millennial":xa,"f2-beauty-influencer":fa,"f3-fitness-coach":ba,"f4-luxury-model":ya,"f5-lifestyle-creator":va,"f6-corporate-pro":wa,"f7-gen-z-trendy":ja,"f8-mom-influencer":Na,"f9-wellness-guru":ka,"f10-bold-creative":Ca,"m1-tech-reviewer":Ia,"m2-fitness-trainer":Sa,"m3-business-exec":Pa,"m4-lifestyle-influencer":Ta,"m5-luxury-refined":Ea,"m6-gen-z-creator":Aa,"m7-dad-relatable":Ra,"m8-wellness-coach":Ma,"m9-creative-artist":Da,"m10-mature-expert":Ua};function La({script:a,onScriptChange:o,personaStyle:u,onPersonaStyleChange:n,voice:i,onVoiceChange:d,productName:w,productDescription:M,onGenerateScript:y,isGeneratingScript:S=!1,customPresenterPrompt:I,onCustomPresenterPromptChange:c}){const[j,B]=t.useState("presets"),[P,re]=t.useState(null),[_,z]=t.useState("All"),[le,q]=t.useState(!1),H=a.split(/\s+/).filter(
8Boolean).length,k=Math.round(H/2.5),G=30;t.useEffect(()=>{if(!P&&u&&u!=="custom"){const l=Ke.find(se=>se.id===u);l&&re(l)}},[u,P]);const F=l=>{re(l),n(l.id),c==null||c(l.prompt),d(l.defaultVoice.id),q(!1)},D=l=>{c==null||c(l),n("custom"),re(null)},W=_==="All"?Ke:Ke.filter(l=>l.category===_),$=["All",...new Set(Ke.map(l=>l.category))],T=P?_e[P.gender]:[..._e.female,..._e.male],me=T.find(l=>l.id===i),ue=(me==null?void 0:me.label)||(P==null?void 0:P.defaultVoice.name)||"Sarah";return e.jsxs("div",{className:"space-y-4 p-4 rounded-xl bg-card border border-border/50",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(kr,{className:"h-4 w-4 text-primary"})}),e.jsx("h3",{className:"font-semibold text-sm",children:"Choose Your Presenter"})]}),e.jsxs(De,{variant:"secondary",className:"text-[10px] bg-primary/10 text-primary border-0",children:[e.jsx(oe,{className:"h-2.5 w-2.5 mr-1"}),"20 AI Models"]})]}),e.jsxs(Bt,{value:j,onValueChange:l=>B(l),children:[e.jsxs(Kt,{className:"grid w-full grid-cols-2 h-9 bg-muted/50",children:[e.jsxs(He,{value:"presets",className:"gap-1.5 text-xs data-[state=active]:bg-background",children:[e.jsx(Wt,{className:"h-3 w-3"}),"Presets (20)"]}),e.jsxs(He,{value:"custom",className:"gap-1.5 text-xs data-[state=active]:bg-background",children:[e.jsx(Xt,{className:"h-3 w-3"}),"Create Custom"]})]}),e.jsxs($e,{value:"presets",className:"mt-3 space-y-3",children:[e.jsx("div",{className:"flex gap-1 overflow-x-auto pb-1 scrollbar-none",children:$.map(l=>e.jsx(De,{variant:_===l?"default":"outline",className:v("cursor-pointer text-[10px] px-2 py-0.5 shrink-0 transition-all",_===l?"bg-primary text-primary-foreground":"hover:bg-primary/10 hover:border-primary/40"),onClick:()=>z(l),children:l},l))}),e.jsxs("div",{className:"relative",children:[e.jsx($t,{className:"h-[240px]",children:e.jsx("div",{className:"grid grid-cols-4 gap-2 pr-2 pb-4",children:W.map(l=>{const se=pt[l.id],xe=(P==null?void 0:P.id)===l.id||u===l.id;return e.jsxs("button",{onClick:()=>F(l),className:v("relative group rounded-lg overflow-hidden border-2 transition-all aspect-[3/4]",xe?"border-primary ring-2 ring-primary/30 scale-[1.02]":"border-border/50 hover:border-primary/50 hover:scale-[1.02]"),children:[se?e.jsx("img",{src:se,alt:l.name,className:"w-full h-full object-cover",onError:ne=>{var ce;ne.currentTarget.style.display="none",(ce=ne.currentTarget.nextElementSibling)==null||ce.classList.remove("hidden")}}):null,e.jsxs("div",{className:v("absolute inset-0 flex flex-col items-center justify-center bg-muted/80",se?"hidden":""),children:[e.jsx(Fe,{className:"h-6 w-6 text-muted-foreground/50 mb-1"}),e.jsx("span",{className:"text-[8px] text-muted-foreground",children:"Loading..."})]}),e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/90 via-black/70 to-transparent p-1.5 pt-4",children:[e.jsx("p",{className:"text-[9px] font-medium text-white truncate",children:l.name}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(dt,{className:"h-2 w-2 text-primary"}),e.jsx("p",{className:"text-[7px] text-primary truncate",children:l.defaultVoice.name})]})]}),xe&&e.jsx("div",{className:"absolute top-1 right-1 w-4 h-4 rounded-full bg-primary flex items-center justify-center",children:e.jsx(Nt,{className:"h-2.5 w-2.5 text-primary-foreground"})})]},l.id)})})}),e.jsx("div",{className:"absolute bottom-0 left-0 right-3 h-12 bg-gradient-to-t from-card via-card/80 to-transparent pointer-events-none flex items-end justify-center pb-1",children:e.jsxs("div",{className:"flex items-center gap-1 text-[10px] text-muted-foreground animate-bounce",children:[e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 14l-7 7m0 0l-7-7m7 7V3"})}),e.jsx("span",{children:"Scroll for more"})]})})]}),P&&e.jsxs("div",{className:"p-2.5 rounded-lg bg-primary/5 border border-primary/20 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-10 rounded overflow-hidden border border-primary/30 shrink-0",children:pt[P.id]?e.jsx("img",{src:pt[P.id],alt:P.name,className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full bg-muted flex items-center justify-center",children:e.jsx(Fe,{className:"h-3 w-3 text-muted-foreground"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:"text-xs font-medium text-primary",children:P.name}),e.jsx("span",{className:"text-[9px] text-muted-foreground",children:"â¢"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Ht,{className:"h-2.5 w-2.5 text-muted-foreground"}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:ue})]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground truncate",children:P.description})]})]}),e.jsxs(Yr,{open:le,onOpenChange:q,children:[e.jsx(Xr,{asChild:!0,children:e.jsxs(L,{variant:"ghost",size:"sm",className:"w-full h-7 text-[10px] gap-1.5 text-muted-foreground hover:text-foreground",children:[e.jsx(dt,{className:"h-3 w-3"}
8),"Change Voice",e.jsx(Cr,{className:v("h-3 w-3 ml-auto transition-transform",le&&"rotate-180")})]})}),e.jsx(Jr,{className:"pt-2",children:e.jsxs("div",{className:"p-2 rounded-lg bg-muted/30 border border-border/50",children:[e.jsxs("p",{className:"text-[10px] text-muted-foreground mb-2",children:[P.gender==="female"?"Female":"Male"," voices for ",P.name,":"]}),e.jsx(Ir,{value:i,onValueChange:d,className:"space-y-1",children:T.map(l=>e.jsxs("div",{className:v("flex items-center gap-2 p-1.5 rounded-md cursor-pointer transition-colors",i===l.id?"bg-primary/10":"hover:bg-muted/50"),onClick:()=>d(l.id),children:[e.jsx(Sr,{value:l.id,id:l.id,className:"h-3 w-3"}),e.jsxs("label",{htmlFor:l.id,className:"flex-1 cursor-pointer",children:[e.jsx("span",{className:"text-xs font-medium",children:l.label}),e.jsxs("span",{className:"text-[10px] text-muted-foreground ml-1.5",children:["(",l.desc,")"]})]}),i===l.id&&e.jsx(Ue,{className:"h-3 w-3 text-primary"})]},l.id))})]})})]})]})]}),e.jsxs($e,{value:"custom",className:"mt-3",children:[e.jsx("div",{className:"h-[280px] rounded-lg border border-border/30 bg-muted/10 p-3",children:e.jsx(ga,{productName:w,productDescription:M,onPromptConfirmed:D,className:"h-full"})}),I&&u==="custom"&&e.jsx("div",{className:"mt-2 p-2.5 rounded-lg bg-gradient-to-r from-primary/10 to-primary/5 border border-primary/20",children:e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-primary font-medium",children:[e.jsx(oe,{className:"h-3 w-3"}),"Custom presenter configured"]})}),u==="custom"&&e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(dt,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx(Pe,{className:"text-xs text-muted-foreground",children:"Voice"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-1",children:[..._e.female,..._e.male].map(l=>e.jsxs("button",{onClick:()=>d(l.id),className:v("flex items-center gap-2 p-2 rounded-lg border text-left transition-all text-xs",i===l.id?"border-primary bg-primary/10":"border-border/50 hover:border-primary/40"),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"font-medium",children:l.label}),e.jsx("span",{className:"text-[10px] text-muted-foreground block",children:l.desc})]}),i===l.id&&e.jsx(Ue,{className:"h-3 w-3 text-primary shrink-0"})]},l.id))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Pe,{className:"text-xs text-muted-foreground",children:"Ad Script"}),y&&e.jsx(L,{variant:"ghost",size:"sm",className:"gap-1 text-primary h-6 text-xs px-2",onClick:y,disabled:S||!w,children:S?e.jsxs(e.Fragment,{children:[e.jsx(Te,{className:"h-3 w-3 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-3 w-3"}),"Auto-Generate"]})})]}),e.jsx(st,{placeholder:"Write a short, punchy script (max 15 seconds)...",value:a,onChange:l=>o(l.target.value),className:v("min-h-[70px] bg-muted/30 text-sm resize-none",k>15&&"border-destructive focus-visible:ring-destructive"),maxLength:150}),e.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground",children:[e.jsxs("span",{children:[H,"/",G," words"]}),e.jsxs("span",{className:v(H>G&&"text-destructive font-medium",H>25&&H<=G&&"text-warning"),children:["~",k,"s / 15s max"]})]}),H>G&&e.jsxs("p",{className:"text-[10px] text-destructive font-medium",children:["â Script too long! Max ",G," words. Shorten your script."]}),H>20&&H<=G&&e.jsx("p",{className:"text-[10px] text-warning",children:"â ï¸ Approaching limit - aim for 25 words or less"})]})]})}const Gt=Ke.reduce((a,o)=>({...a,[o.id]:o.prompt}),{});[..._e.female.map(a=>a.id),..._e.male.map(a=>a.id)];const za=["text","typography","headline","caption","title","logo","wordmark","brand","branding","poster","billboard","signage","sign ","menu","label","packaging","tag","subtitle","letters","wording","copy ","advertisement","ad copy","tagline","slogan"],_a=["4k","2k","ultra hd","uhd","ultra-detailed","ultra high resolution","8k"],Ga=["photorealistic","hyperrealistic","studio shot","professional photo","magazine cover"];function et(a){if(!a)return!1;const o=a.toLowerCase(),u=za.some(d=>o.includes(d)),n=_a.some(d=>o.includes(d)),i=Ga.some(d=>o.includes(d))&&(u||n);return u||n||i}const Va=a=>a.split(/\*\*(.+?)\*\*/g).map((u,n)=>n%2===1?e.jsx("strong",{className:"font-semibold text-foreground",children:u},n):u);function Fa({onImageGenerated:a,onStyleDirectionReady:o,onClose:u}){const{session:n}=kt(),{balance:i,deductCredits:d,getToolCost:w,refundCredits:M}=Ot(),y=w("generate-product-image"),[S,I]=t.useState([{id:"welcome",role:"assistant",content:`Hey! ð I'm your AI creative assistant powered by **Nano Banana Pro**. Describe your product and I'll generate a professional photo. 9 10You can **attach a reference image** for style inspiration!`}
10]),[c,j]=t.useState(""),[B,P]=t.useState(!1),[re,_]=t.useState(!1),[z,le]=t.useState(null),[q,H]=t.useState(!1),[k,G]=t.useState({required:0,available:0}),[F,D]=t.useState(null),[W,$]=t.useState("2K"),[T,me]=t.useState(!1),ue=t.useRef(null),l=t.useRef(null),se=t.useRef(null),xe=t.useRef(S.length),ne=()=>{var m;(m=ue.current)==null||m.scrollIntoView({behavior:"smooth",block:"end"})};t.useEffect(()=>{S.length>xe.current&&ne(),xe.current=S.length},[S]);const ce=m=>{j(m.target.value),m.target.style.height="auto",m.target.style.height=Math.min(m.target.scrollHeight,100)+"px"},ye=m=>{var r;const A=(r=m.target.files)==null?void 0:r[0];if(m.target&&(m.target.value=""),!A)return;if(!A.type.startsWith("image/")){N.error("Please upload an image file");return}if(A.size>10*1024*1024){N.error("Image must be under 10MB");return}const Y=new FileReader;Y.onload=s=>{var C;D((C=s.target)==null?void 0:C.result),N.success("Reference image added!")},Y.onerror=()=>N.error("Failed to read image"),Y.readAsDataURL(A)},Ee=async()=>{if(!c.trim()||B)return;const m={id:`user-${Date.now()}`,role:"user",content:c.trim(),referenceImageUrl:F||void 0};I(b=>[...b,m]);const A=c.trim(),Y=F;j(""),D(null),l.current&&(l.current.style.height="auto"),P(!0);const r=A.toLowerCase();if(!(A.length<25&&(r.match(/^(hi|hey|hello|thanks|thank you|ok|okay|sure|yes|no|help|what|how|why|who)\b/)!==null||r.includes("?")))){const b=T||et(A),V=!!Y,g=`gpt-image-2-${V?"edit":"generate"}-${W.toLowerCase()}`,Q=b?g:"generate-product-image",de=w(Q);if(i<de){G({required:de,available:i}),H(!0),P(!1);return}const O=await d(Q);if(!O.success){O.error==="Insufficient credits"?(G({required:O.required||de,available:O.available||i}),H(!0)):N.error("Failed to process credits"),P(!1);return}const Ae={id:`loading-${Date.now()}`,role:"assistant",content:b?`Creating your ad with GPT Image 2 (${W} â crisp text rendering)...`:"Creating your product image...",isLoading:!0};I(X=>[...X,Ae]);try{let X;if(b){const{data:Z,error:he}=await K.functions.invoke("gpt-image-2",{headers:n?{Authorization:`Bearer ${n.access_token}`}:{},body:{prompt:A,mode:V?"edit":"generate",imageUrls:V?[Y]:void 0,aspectRatio:"1:1",resolution:W}});if(he)throw he;if(Z!=null&&Z.error)throw new Error(Z.error);X=Z==null?void 0:Z.imageUrl}else{const Z={productDescription:A};Y&&(Z.referenceImage=Y);const{data:he,error:ee}=await K.functions.invoke("generate-product-image",{headers:n?{Authorization:`Bearer ${n.access_token}`}:{},body:Z});if(ee)throw ee;X=he==null?void 0:he.imageUrl}I(Z=>[...Z.filter(ee=>!ee.isLoading),{id:`result-${Date.now()}`,role:"assistant",content:b?"⨠Generated with **GPT Image 2** for crisp text. Click below to use it, or describe changes.":Y?"⨠Here's your product image inspired by your reference! Click below to use it, or describe changes.":"⨠Here's your product image! Click below to use it for your video ad, or describe changes.",imageUrl:X}])}catch(X){console.error("Image generation error:",X),O.transactionId&&(await M(O.transactionId),N.info("Credits refunded due to generation failure")),I(Z=>[...Z.filter(ee=>!ee.isLoading),{id:`error-${Date.now()}`,role:"assistant",content:"Oops! I couldn't generate that image. Try being more specific about the product type, materials, and setting you want."}]),N.error("Failed to generate image")}}else{const b={greeting:`Hey! ð I'm ready to create product images for you. Just describe what you want â e.g. **"A white coffee mug on a wooden table with morning light"** â and I'll generate a professional photo!`,help:`I generate **professional product photos** from descriptions! Just tell me: 11 12⢠What the product is 13⢠The setting or background 14⢠The mood or style you want 15 16For example: *"A sleek black headphone on a dark marble surface with dramatic rim lighting"*`,thanks:"You're welcome! ð Ready to create another image whenever you are â just describe your next product!"};let V="help";r.match(/^(hi|hey|hello|yo|sup)\b/)?V="greeting":r.match(/^(thanks|thank you|thx)\b/)&&(V="thanks");const g={id:`response-${Date.now()}`,role:"assistant",content:b[V]};I(Q=>[...Q,g])}P(!1)},Ne=m=>{const A=S.filter(r=>r.role==="user").pop(),Y=(A==null?void 0:A.content)||"AI generated product";a(m,Y)},Le=async()=>
16{if(!(!c.trim()||re||B)){_(!0);try{const{data:m,error:A}=await K.functions.invoke("enhance-product-prompt",{headers:n?{Authorization:`Bearer ${n.access_token}`}:{},body:{prompt:c.trim()}});if(A)throw A;if(m!=null&&m.enhanced){j(m.enhanced),requestAnimationFrame(()=>{l.current&&(l.current.style.height="auto",l.current.style.height=Math.min(l.current.scrollHeight,100)+"px")});const Y=m.category||"product",r=m.tip||"Ready to generate!";N.success(`⨠Enhanced for ${Y}`,{description:r})}}catch(m){console.error("Enhance error:",m),N.error("Failed to enhance prompt")}finally{_(!1)}}};return e.jsxs("div",{className:"flex flex-col rounded-2xl border border-border/40 overflow-hidden bg-card/50 w-full min-w-0 h-[60vh] min-h-[420px] max-h-[640px]",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border/30 bg-muted/20",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg overflow-hidden border border-primary/20 shadow-sm",children:e.jsx("img",{src:Ut,alt:"Nano Banana",className:"w-full h-full object-cover"})}),e.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 bg-emerald-500 rounded-full border-2 border-card"})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-foreground flex items-center gap-1.5",children:["AI Creative Assistant",e.jsx(oe,{className:"h-3.5 w-3.5 text-amber-500"})]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground flex items-center gap-1.5",children:[e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(oe,{className:"h-2.5 w-2.5 text-primary"}),"Nano Banana Pro"]}),e.jsx("span",{className:"text-muted-foreground/40",children:"â¢"}),e.jsxs("span",{className:"flex items-center gap-0.5 text-amber-600 font-medium",children:[e.jsx(Qr,{className:"h-2.5 w-2.5"}),y," credits"]})]})]})]}),e.jsx(L,{variant:"ghost",size:"icon",onClick:u,className:"h-8 w-8 rounded-lg hover:bg-destructive/10 hover:text-destructive",children:e.jsx(at,{className:"h-3.5 w-3.5"})})]}),e.jsxs($t,{className:"flex-1 min-h-0 touch-pan-y",type:"always",children:[e.jsxs("div",{className:"px-4 py-3 space-y-3",children:[e.jsx(rt,{mode:"popLayout",children:S.map(m=>e.jsxs(J.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0},layout:!0,className:v("flex gap-2.5",m.role==="user"?"justify-end":"justify-start"),children:[m.role==="assistant"&&e.jsx("div",{className:"w-7 h-7 rounded-lg overflow-hidden flex-shrink-0 border border-primary/10 mt-0.5",children:e.jsx("img",{src:Ut,alt:"",className:"w-full h-full object-cover"})}),e.jsx("div",{className:v("max-w-[78%] min-w-0 rounded-2xl px-3.5 py-2.5 break-words",m.role==="user"?"bg-primary text-primary-foreground rounded-tr-sm":"bg-muted/50 border border-border/30 rounded-tl-sm"),children:m.isLoading?e.jsxs("div",{className:"flex items-center gap-2.5 min-w-[180px] py-1",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Pr,{className:"h-4 w-4 text-primary"}),e.jsx(J.div,{className:"absolute -top-1 -right-1",animate:{rotate:360},transition:{duration:2,repeat:1/0,ease:"linear"},children:e.jsx(Te,{className:"h-3 w-3 text-amber-500"})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium",children:"Creating image..."}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"~10-20 seconds ð"})]})]}):e.jsxs(e.Fragment,{children:[m.role==="user"&&m.referenceImageUrl&&e.jsxs("div",{className:"mb-2",children:[e.jsx("img",{src:m.referenceImageUrl,alt:"Reference",className:"max-h-16 rounded-lg border border-white/20 object-cover"}),e.jsx("span",{className:"text-[10px] opacity-70 mt-0.5 block",children:"Reference"})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed break-words",children:Va(m.content)}),m.imageUrl&&e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs(J.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:"relative rounded-xl overflow-hidden border border-border/30 cursor-pointer group",onClick:()=>le(m.imageUrl),children:[e.jsx("img",{src:m.imageUrl,alt:"Generated product",onLoad:ne,className:"w-full h-auto max-h-52 object-contain bg-gradient-to-br from-white to-gray-50 transition-transform duration-300 group-hover:scale-[1.02]"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/40 opacity-0 group-hover:opacity-100 transition-all",children:e.jsxs("div",{className:"flex items-center gap-1.5 text-white bg-black/60 px-3 py-1.5 rounded-full text-xs font-medium backdrop-blur-sm",children:[e.jsx(ea,{className:"h-3 w-3"}),"View full size"]})})]}),e.jsxs(L,{type:"button",size:"sm",onClick:A=>{A.preventDefault(),A.stopPropagation(),Ne(m.imageUrl)},className:"w-full gap-2 bg-gradient-to-r from-emerald-500 to-emerald-600 hover:from-emerald-600 hover:to-emerald-700 shadow-md shadow-emerald-500/15 h-9 text-xs font-medium relative z-10",children:[e.jsx(Tr,{className:"h-3.5 w-3.5"}),"Use This for Video Ad"]})]})]})}),m.role==="user"&&e.jsx("div",{className:"w-7 h-7 rounded-lg bg-primary/10 flex items-center justify-center flex-shrink-0 border border-primary/15 mt-0.5",children:e.jsx(Fe,{className:"h-3.5 w-3.5 text-primary"})})]},m.id))}),e.jsx("div",{ref:ue})]}),e.jsx($r,{className:"w-3"})]}),e.jsxs("div",{className:"border-t border-border/30 bg-background/50",children:[e.jsx(rt,{children:F&&e.jsx(J.div,{initial:{opacity:0,height:0}
16,animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"px-3 pt-2.5 overflow-hidden",children:e.jsxs("div",{className:"flex items-center gap-2.5 p-2 rounded-lg bg-primary/5 border border-primary/15",children:[e.jsx("img",{src:F,alt:"Reference",className:"w-10 h-10 object-cover rounded-md border border-primary/20"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("p",{className:"text-[11px] font-medium text-primary flex items-center gap-1",children:[e.jsx(Er,{className:"h-3 w-3"}),"Reference attached"]})}),e.jsx(L,{size:"icon",variant:"ghost",onClick:()=>D(null),className:"h-6 w-6 rounded-md text-muted-foreground hover:text-foreground",children:e.jsx(at,{className:"w-3 h-3"})})]})})}),(()=>{const m=T||et(c),A=!!F,Y=r=>({"1K":2,"2K":4,"4K":6})[r]+(A?1:0);return e.jsxs("div",{className:"px-3 pt-2 pb-1 flex items-center gap-1.5 flex-wrap",children:[e.jsxs("button",{type:"button",onClick:()=>me(r=>!r),className:v("flex items-center gap-1 px-2 py-1 rounded-md text-[10px] font-medium transition-all",m?"bg-emerald-500/15 text-emerald-500 border border-emerald-500/30":"bg-muted/30 text-muted-foreground border border-border/40 hover:border-emerald-500/30"),title:T?"GPT Image 2 forced â click to disable":et(c)?"Auto-detected text/poster â using GPT Image 2":"Force GPT Image 2 for legible text & 4K",children:[e.jsx(oe,{className:"w-3 h-3"}),m?"GPT Image 2":"Nano Banana Pro",!T&&et(c)&&e.jsx("span",{className:"text-[8px] px-1 rounded bg-emerald-500/20",children:"AUTO"})]}),m&&e.jsx("div",{className:"flex items-center gap-0.5 rounded-md p-0.5 bg-muted/30 border border-border/40",children:["1K","2K","4K"].map(r=>{const s=W===r;return e.jsxs("button",{type:"button",onClick:()=>$(r),className:v("flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-medium transition-all",s?"bg-emerald-500/20 text-emerald-500":"text-muted-foreground hover:text-foreground"),title:`${r} â ${Y(r)} credits`,children:[r,e.jsxs("span",{className:"text-[8px] opacity-60",children:[Y(r),"c"]})]},r)})})]})})(),e.jsxs("div",{className:"flex items-end gap-1.5 p-2.5 pt-1",children:[e.jsx("input",{ref:se,type:"file",accept:"image/*",onChange:ye,className:"hidden"}),e.jsx(L,{type:"button",variant:"ghost",size:"icon",onClick:m=>{var A;m.preventDefault(),m.stopPropagation(),(A=se.current)==null||A.click()},disabled:B,className:v("flex-shrink-0 h-9 w-9 rounded-lg hover:bg-primary/10 relative z-10",F&&"text-primary bg-primary/10"),title:"Attach reference image",children:e.jsx(ta,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1 relative overflow-hidden",children:[e.jsx("textarea",{ref:l,value:c,onChange:ce,placeholder:F?"Describe how to use this reference...":"Describe your product...",className:v("w-full min-h-[40px] max-h-[100px] px-3 py-2.5 pr-10 rounded-xl resize-none","bg-muted/40 border border-border/50 focus:border-primary/40 focus:ring-1 focus:ring-primary/15","text-sm placeholder:text-muted-foreground/50 leading-relaxed","transition-all duration-200 outline-none"),onKeyDown:m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),Ee())},rows:1}),c.trim()&&e.jsx(L,{variant:"ghost",size:"icon",onClick:Le,disabled:re||B,className:"absolute right-1.5 bottom-1 h-7 w-7 rounded-md hover:bg-amber-500/20 hover:text-amber-500 disabled:opacity-30",title:"Enhance prompt (â¨)",children:re?e.jsx(Te,{className:"h-3.5 w-3.5 animate-spin text-amber-500"}):e.jsx(jt,{className:"h-3.5 w-3.5"})})]}),e.jsx(L,{type:"button",onClick:Ee,onPointerDown:m=>{m.stopPropagation()},disabled:!c.trim()||B,size:"icon",className:v("h-10 w-10 rounded-lg shadow-sm flex-shrink-0 relative z-10","bg-primary hover:bg-primary/90","disabled:opacity-30"),children:B?e.jsx(Te,{className:"h-4 w-4 animate-spin"}):e.jsx(Yt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"px-3 pb-2 flex items-center justify-between text-[10px] text-muted-foreground/60",children:[e.jsx("span",{children:"ð Attach reference ⢠Enter âµ send"}),e.jsx("span",{children:"⨠Ctrl+Enter enhance"})]})]}),e.jsx(yt,{open:!!z,onOpenChange:()=>le(null),children:e.jsxs(vt,{className:"max-w-4xl p-0 bg-black/95 border-none",children:[e.jsx(wt,{className:"sr-only",children:"Image Preview"}),z&&e.jsx("img",{src:z,alt:"Full size preview",className:"w-full h-auto max-h-[90vh] object-contain"})]})}
16),e.jsx(Zr,{open:q,onOpenChange:H,requiredCredits:k.required,currentBalance:k.available,toolName:"AI Product Image"})]})}const Wa=[{id:"product",name:"Product Ad",description:"Cinematic VFX showcase",icon:Ye,credits:18,features:["360° rotation","Particle effects","Dramatic lighting"]},{id:"ugc",name:"UGC Ad",description:"AI Avatar presenter",icon:Fe,credits:50,features:["AI Avatar","Voice-over","Natural gestures"]}];function qa({selectedType:a,onTypeChange:o,className:u,ugcRestricted:n=!1,minimumPlanForUGC:i="Pro"}){return e.jsx("div",{className:v("grid grid-cols-2 gap-3",u),children:Wa.map(d=>{const w=a===d.id,M=d.icon,y=d.id==="ugc"&&n,S=()=>{y||o(d.id)},I=e.jsxs(J.button,{onClick:S,whileHover:y?{}:{scale:1.01},whileTap:y?{}:{scale:.99},className:v("relative p-4 rounded-xl border text-left transition-all duration-200",y?"border-border/50 opacity-50 cursor-not-allowed bg-card/30":w?v("border-primary bg-primary/5 ring-1 ring-primary/40",d.id==="ugc"&&"border-violet-500 bg-violet-500/5 ring-violet-500/40"):"border-border/50 hover:border-muted-foreground/40 bg-card/50"),disabled:y,children:[w&&!y&&e.jsx(J.div,{initial:{scale:0},animate:{scale:1},className:v("absolute top-3 right-3 w-5 h-5 rounded-full flex items-center justify-center",d.id==="product"?"bg-primary":"bg-violet-500"),children:e.jsx(Ue,{className:"h-3 w-3 text-white"})}),y&&e.jsx("div",{className:"absolute top-3 right-3 w-5 h-5 rounded-full bg-muted flex items-center justify-center",children:e.jsx(_t,{className:"h-3 w-3 text-muted-foreground"})}),e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:v("w-9 h-9 rounded-lg flex items-center justify-center",y?"bg-muted text-muted-foreground":d.id==="product"?"bg-primary/15 text-primary":"bg-violet-500/15 text-violet-500"),children:e.jsx(M,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-foreground leading-tight",children:d.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d.description})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-3",children:d.features.map(c=>e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-background/60 text-muted-foreground border border-border/30",children:c},c))}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Nt,{className:v("h-3.5 w-3.5",y?"text-muted-foreground":d.id==="product"?"text-primary":"text-violet-500")}),e.jsxs("span",{className:v("text-xs font-bold",y?"text-muted-foreground":d.id==="product"?"text-primary":"text-violet-500"),children:[d.credits," credits"]})]}),y&&e.jsx("div",{className:"absolute -top-2 left-3 px-2 py-0.5 bg-muted rounded-full border border-border",children:e.jsxs("span",{className:"text-[10px] font-bold text-muted-foreground flex items-center gap-1",children:[e.jsx(_t,{className:"h-2.5 w-2.5"}),i,"+"]})}),d.id==="ugc"&&!y&&e.jsx("div",{className:"absolute -top-2 left-3 px-2 py-0.5 bg-gradient-to-r from-violet-500 to-purple-500 rounded-full",children:e.jsxs("span",{className:"text-[10px] font-bold text-white flex items-center gap-1",children:[e.jsx(oe,{className:"h-2.5 w-2.5"}),"POPULAR"]})})]},d.id);return y?e.jsxs(Ar,{children:[e.jsx(Rr,{asChild:!0,children:I}),e.jsx(Mr,{children:e.jsxs("p",{children:["Upgrade to ",i," or higher to create UGC videos"]})})]},d.id):I})})}const Oa=[{id:"9:16",label:"9:16",subtitle:"TikTok / Reels",w:24,h:42},{id:"1:1",label:"1:1",subtitle:"Instagram",w:34,h:34},{id:"16:9",label:"16:9",subtitle:"YouTube",w:42,h:24}];function Ba({selected:a,onChange:o,className:u}){return e.jsx("div",{className:v("grid grid-cols-3 gap-2",u),children:Oa.map(n=>{const i=a===n.id;return e.jsxs("button",{onClick:()=>o(n.id),className:v("relative flex flex-col items-center gap-1.5 p-3 rounded-lg border transition-all duration-200",i?"border-primary bg-primary/8 ring-1 ring-primary/30":"border-border/50 hover:border-muted-foreground/40 bg-card/50"),children:[i&&e.jsx("div",{className:"absolute top-1.5 right-1.5 w-4 h-4 rounded-full bg-primary flex items-center justify-center",children:e.jsx(Ue,{className:"h-2.5 w-2.5 text-white"})}),e.jsx("div",{className:"flex items-center justify-center h-11",children:e.jsx("div",{className:v("rounded-sm border-2 transition-colors",i?"border-primary bg-primary/20":"border-muted-foreground
16/25 bg-muted/30"),style:{width:`${n.w}px`,height:`${n.h}px`}})}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:v("text-xs font-bold",i?"text-primary":"text-foreground"),children:n.label}),e.jsx("p",{className:"text-[10px] text-muted-foreground leading-tight",children:n.subtitle})]})]},n.id)})})}const ht=a=>Lr(zr["generate-click-to-ad"],"generate-click-to-ad",{tier:a}),Ka=[{id:"fast",name:"Fast",desc:"~90s",credits:ht("fast"),icon:Dr,color:"emerald",badge:"BEST VALUE"},{id:"standard",name:"Standard",desc:"~2min",credits:ht("standard"),icon:Nt,color:"blue",badge:null},{id:"premium",name:"Premium",desc:"~3min",credits:ht("premium"),icon:Ur,color:"amber",badge:"PRO"}],Ha={emerald:{bg:"bg-emerald-500/15",text:"text-emerald-500",border:"border-emerald-500",ring:"ring-emerald-500/30",dot:"bg-emerald-500",badge:"bg-emerald-500"},blue:{bg:"bg-blue-500/15",text:"text-blue-500",border:"border-blue-500",ring:"ring-blue-500/30",dot:"bg-blue-500",badge:"bg-blue-500"},amber:{bg:"bg-amber-500/15",text:"text-amber-500",border:"border-amber-500",ring:"ring-amber-500/30",dot:"bg-amber-500",badge:"bg-amber-500"}};function $a({selectedTier:a,onTierChange:o,className:u}){return e.jsx("div",{className:v("grid grid-cols-3 gap-2",u),children:Ka.map(n=>{const i=a===n.id,d=n.icon,w=Ha[n.color];return e.jsxs(J.button,{onClick:()=>o(n.id),whileHover:{scale:1.02},whileTap:{scale:.98},className:v("relative flex flex-col items-center gap-1 p-3 rounded-lg border transition-all duration-200",i?v(w.border,"ring-1",w.ring,"bg-card/80"):"border-border/50 hover:border-muted-foreground/40 bg-card/50"),children:[i&&e.jsx(J.div,{initial:{scale:0},animate:{scale:1},className:v("absolute top-1.5 right-1.5 w-4 h-4 rounded-full flex items-center justify-center",w.dot),children:e.jsx(Ue,{className:"h-2.5 w-2.5 text-white"})}),n.badge&&e.jsx("div",{className:v("absolute -top-1.5 left-1/2 -translate-x-1/2 px-1.5 py-px rounded text-[8px] font-bold text-white leading-none whitespace-nowrap",w.badge),children:n.badge}),e.jsx("div",{className:v("w-7 h-7 rounded-md flex items-center justify-center mt-1",w.bg,w.text),children:e.jsx(d,{className:"h-3.5 w-3.5"})}),e.jsx("h4",{className:"font-semibold text-foreground text-xs leading-tight",children:n.name}),e.jsxs("div",{className:v("text-xs font-bold",w.text),children:[n.credits," cr"]}),e.jsx("div",{className:"text-[10px] text-muted-foreground leading-tight",children:n.desc})]},n.id)})})}const Ya=a=>{const o=Math.floor(a/60),u=a%60;return`${o}:${u.toString().padStart(2,"0")}`};function Xa({productImage:a,productName:o,elapsedTime:u,currentPhase:n,phases:i,currentPhaseIndex:d,isUGCAd:w,realProgress:M}){const y=i.length,S=M!=null?Math.min(M,99):Math.min((d+1)/y*100,n.progress),I=u>=360;return e.jsx("div",{className:"flex flex-col items-center justify-center min-h-[420px] sm:min-h-[480px] py-6 sm:py-8",children:e.jsxs("div",{className:"relative w-full max-w-xl overflow-hidden rounded-[2rem] border border-border/60 bg-card/70 px-4 sm:px-6 py-6 sm:py-8 shadow-2xl backdrop-blur-sm",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-gradient-to-br from-primary/10 via-trans
16parent to-primary/5"}),e.jsx(J.div,{className:"pointer-events-none absolute inset-x-10 top-10 h-24 rounded-full bg-primary/20 blur-3xl",animate:{opacity:[.3,.65,.3],scale:[.96,1.05,.96]},transition:{duration:3.2,repeat:1/0,ease:"easeInOut"}}),e.jsxs("div",{className:"relative flex flex-col items-center gap-6",children:[e.jsxs("div",{className:"text-center space-y-2",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-primary/30 bg-primary/10 px-3 py-1 text-[11px] font-medium text-primary",children:[e.jsx(oe,{className:"h-3.5 w-3.5"}),"Creative Director Render"]}),e.jsx(J.p,{className:"text-sm text-muted-foreground text-center",initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.3},children:n.label},n.label)]}),e.jsxs("div",{className:"relative",children:[e.jsx(J.div,{className:"absolute -inset-8 rounded-full border border-primary/20",animate:{scale:[.92,1.1],opacity:[.35,0]},transition:{duration:2.4,repeat:1/0,ease:"easeOut"}}),e.jsx(J.div,{className:"absolute -inset-5 rounded-full border border-primary/30",animate:{scale:[.96,1.06],opacity:[.4,.08,.4]},transition:{duration:2.1,repeat:1/0,ease:"easeInOut"}}),e.jsx(J.div,{className:"absolute -inset-4 rounded-[2rem] bg-primary/20 blur-2xl",animate:{opacity:[.35,.8,.35]},transition:{duration:2.6,repeat:1/0,ease:"easeInOut"}}),e.jsx("div",{className:"relative w-40 h-40 sm:w-48 sm:h-48 rounded-[1.75rem] overflow-hidden border border-border/60 bg-background/95 shadow-2xl",children:a?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:a,alt:o||"Product",className:"w-full h-full object-contain p-4"}),e.jsx(J.div,{className:"absolute left-0 right-0 h-px bg-primary/70",style:{boxShadow:"0 0 18px 3px hsl(var(--primary) / 0.55)"},animate:{top:["8%","88%"]},transition:{duration:1.8,repeat:1/0,ease:"linear"}}),e.jsx(J.div,{className:"absolute inset-0 bg-gradient-to-b from-transparent via-primary/5 to-transparent",animate:{opacity:[.2,.45,.2]},transition:{duration:1.8,repeat:1/0,ease:"linear"}})]}):e.jsx("div",{className:"flex h-full w-full items-center justify-center bg-muted",children:e.jsx(Ye,{className:"h-12 w-12 text-muted-foreground animate-pulse"})})}),e.jsx(J.div,{className:"absolute -top-2 -right-2 rounded-full border border-primary/40 bg-background/90 p-1.5 shadow-lg",animate:{rotate:360,scale:[1,1.08,1]},transition:{rotate:{duration:4.5,repeat:1/0,ease:"linear"},scale:{duration:1.8,repeat:1/0,ease:"easeInOut"}},children:e.jsx(oe,{className:"h-4 w-4 text-primary"})})]}),e.jsxs("div",{className:"flex items-center gap-2 rounded-full border border-border/60 bg-background/70 px-4 py-2 font-mono text-xl font-semibold text-foreground shadow-sm",children:[e.jsx(_r,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:Ya(u)})]}
16),e.jsxs("div",{className:"w-full max-w-md space-y-2",children:[e.jsx("div",{className:"h-2 rounded-full bg-muted/80 overflow-hidden",children:e.jsx(J.div,{className:"h-full rounded-full bg-primary",initial:{width:"0%"},animate:{width:`${S}%`},transition:{duration:.6,ease:"easeOut"}})}),e.jsxs("div",{className:"flex justify-between text-[11px] text-muted-foreground",children:[e.jsxs("span",{children:["Step ",Math.min(d+1,y),"/",y]}),e.jsxs("span",{children:[Math.round(S),"%"]})]})]}),e.jsxs("div",{className:"grid w-full max-w-md grid-cols-3 gap-2 text-center",children:[e.jsxs("div",{className:"rounded-2xl border border-border/50 bg-background/60 px-3 py-3",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:"Phase"}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:"Generate"})]}),e.jsxs("div",{className:"rounded-2xl border border-border/50 bg-background/60 px-3 py-3",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:"Mode"}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:w?"UGC Ad":"Product Ad"})]}),e.jsxs("div",{className:"rounded-2xl border border-border/50 bg-background/60 px-3 py-3",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:"Status"}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:I?"Still rendering":"In progress"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground/80 text-center max-w-sm",children:I?"This render is taking longer than normal, but the job is still being tracked in the Generate phase.":w?"UGC ads typically take 4-8 minutes to render.":"Product ads typically take 4-10 minutes to render."})]})]})})}function Ja({open:a,onOpenChange:o,productImage:u,productName:n,productDescription:i,adType:d,onAdTypeChange:w,selectedTemplate:M,onTemplateChange:y,aspectRatio:S,onAspectRatioChange:I,qualityTier:c,onQualityTierChange:j,styleDirection:B,onStyleDirectionChange:P,personaStyle:re,onPersonaStyleChange:_,ugcVoice:z,onUgcVoiceChange:le,avatarScript:q,onAvatarScriptChange:H,isGeneratingScript:k,onGenerateScript:G,customPresenterPrompt:F,onCustomPresenterPromptChange:D,isLoading:W,videoResult:$,onGenerate:T,onDownload:me,onReset:ue,onCancel:l,canAfford:se,creditCost:xe,balance:ne,elapsedTime:ce,currentPhase:ye,loadingPhases:Ee,loadingPhaseIndex:Ne,loadingProgress:Le,canSelectUGC:m,ugcMinimumPlan:A}){const[Y,r]=t.useState(!1),{session:s,isLoading:C}=kt(),b=d==="ugc",V=!C&&!s,g=$?"result":W?"generating":"configure",Q=de=>{o(de)};return t.useEffect(()=>(a||(document.body.style.overflow="",document.body.style.pointerEvents=""),()=>{document.body.style.overflow="",document.body.style.pointerEvents=""}),[a]),e.jsx(yt,{open:a,onOpenChange:Q,children:e.jsxs(vt,{showClose:!1,className:v("w-[94vw] max-w-2xl xl:max-w-3xl p-0 gap-0 border-border/40 rounded-xl shadow-2xl","bg-gradient-to-b from-card via-card to-background/95","fixed left-[50%] -translate-x-1/2","top-[calc(64px+0.75rem)] translate-y-0 max-h-[calc(100dvh-64px-1.5rem)]","sm:top-[calc(64px+1rem)] sm:max-h-[calc(100dvh-64px-2rem)]","flex flex-col overflow-hidden",g==="generating"&&"max-w-md sm:max-w-lg",g==="result"&&"max-w-xl"),overlayClassName:v(g==="generating"||g==="result"?"bg-background/95 backdrop-blur-md":"bg-background/80 backdrop-blur-sm"),children:[e.jsx(wt,{className:"sr-only",children:g==="result"?"Your Ad is Ready":g==="generating"?"Creating Your Ad":"Create Ad"}),e.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5 border-b border-border/30",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg overflow-hidden bg-white/90 border border-border/30 flex-shrink-0",children:e.jsx("img",{src:u,alt:n,className:"w-full h-full object-contain"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold text-foreground leading-tight",children:g==="result"?"Your Ad is Ready!":g==="generating"?"Creating Your Adâ¦":"Create Ad"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n||"Product"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[W&&e.jsxs(L,{variant:"ghost",size:"sm",className:"h-8 px-2.5 gap-1.5 text-xs text-muted-foreground hover:text-foreground",onClick:()=>o(!1),"aria-label":"Run in background",children:[e.jsx(aa,{className:"h-3.5 w-3.5"}),"Minimize"]}),!W&&e.jsx(L,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-full",onClick:()=>o(!1),children:e.jsx(at,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs(rt,{mode:"wait",children:[g==="configure"&&e.jsxs(J.div,{initial:{opacity:0}
16,animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},className:"flex flex-col min-h-0 flex-1",children:[e.jsxs("div",{className:"overflow-y-auto max-h-[58vh] overscroll-contain px-5 py-5 space-y-5",children:[e.jsxs("section",{children:[e.jsx(gt,{step:1,label:"Ad Type"}),e.jsx(qa,{selectedType:d,onTypeChange:w,ugcRestricted:!m,minimumPlanForUGC:A})]}),b&&e.jsxs("section",{children:[e.jsx(gt,{step:2,label:"Avatar & Script"}),e.jsx(La,{script:q,onScriptChange:H,personaStyle:re,onPersonaStyleChange:_,voice:z,onVoiceChange:le,productName:n,productDescription:i,onGenerateScript:G,isGeneratingScript:k,customPresenterPrompt:F,onCustomPresenterPromptChange:D})]}),!b&&e.jsxs("section",{children:[e.jsx(gt,{step:2,label:"Settings"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-muted-foreground mb-2 uppercase tracking-wider",children:"Aspect Ratio"}),e.jsx(Ba,{selected:S,onChange:I})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-muted-foreground mb-2 uppercase tracking-wider",children:"Quality"}),e.jsx($a,{selectedTier:c,onTierChange:j})]})]})]}),!b&&e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(jt,{className:"h-3.5 w-3.5 text-primary"}),e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Style Direction"}),e.jsx("span",{className:"text-[10px] px-1.5 py-0 rounded-full border border-border/50 text-muted-foreground",children:"Optional"})]}),e.jsx(st,{placeholder:"e.g. 'luxury feel, golden lighting, slow dramatic reveal'",value:B,onChange:de=>P(de.target.value),className:"bg-card/50 min-h-[48px] text-xs resize-none border-border/40",maxLength:300})]})]}),e.jsx("div",{className:"px-5 py-3 border-t border-border/30 bg-card/60",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-bold text-foreground",children:xe})," credits",!se&&!V&&e.jsxs("span",{className:"text-destructive ml-1.5 text-[11px]",children:["(need ",xe-ne," more)"]})]}),e.jsxs(L,{size:"default",className:"h-10 px-6 text-sm gap-2 shadow-md shadow-primary/15",onClick:T,disabled:!se&&!V||b&&!q.trim(),children:[e.jsx(Ye,{className:"h-4 w-4"}),"Generate ",b?"UGC":"Product"," Ad"]})]})})]},"configure"),g==="generating"&&e.jsx(J.div,{initial:{opacity:0,scale:.98},animate:{opacity:1,scale:1},exit:{opacity:0},transition:{duration:.3},className:"p-6",children:e.jsx(Xa,{productImage:u,productName:n,elapsedTime:ce,currentPhase:ye,phases:Ee,currentPhaseIndex:Ne,isUGCAd:b,realProgress:Le})},"generating"),g==="result"&&$&&e.jsxs(J.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0},transition:{duration:.3},className:"flex flex-col items-center justify-center gap-5 px-5 py-5 min-h-0 flex-1",children:[e.jsxs("div",{className:v("relative rounded-2xl overflow-hidden shadow-2xl bg-black ring-1 ring-border/30 mx-auto",S==="9:16"&&"h-[60vh] max-h-[560px] aspect-[9/16]",S==="1:1"&&"w-full max-w-[460px] aspect-square",S==="16:9"&&"w-full aspect-video"),children:[e.jsx("video",{src:$,controls:!0,autoPlay:!0,muted:!0,playsInline:!0,preload:"auto",loop:!0,className:"absolute inset-0 w-full h-full object-contain bg-black"},$),e.jsxs(De,{className:"absolute top-2 right-2 bg-primary/90 text-primary-foreground text-[10px] px-2 py-0.5 backdrop-blur-sm",children:[e.jsx(Ft,{className:"h-2.5 w-2.5 mr-1"}),b?"UGC Ad":"Product Ad"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 justify-center w-full",children:[e.jsxs(L,{onClick:me,size:"default",className:"gap-2 h-10 text-sm shadow-md shadow-primary/15",children:[e.jsx(sa,{className:"h-4 w-4"}),"Download"]}),e.jsx(L,{variant:"outline",size:"default",className:"gap-2 h-10 text-sm",onClick:()=>r(!0),children:"Save to Assets"}),e.jsxs(L,{variant:"outline",size:"default",onClick:()=>{ue(),o(!1)},className:"gap-2 h-10 text-sm",children:[e.jsx(qt,{className:"h-4 w-4"}),"Create Another"]})]}),e.jsx(ra,{open:Y,onOpenChange:r,content:$,assetType:"ad",agentName:`Click to Ad - ${n||"Product"}`})]},"result")]})]})})}function gt({step:a,label:o}){return e.jsxs("h3",{className:"text-xs font-semibold text-foreground mb-2.5 flex items-center gap-2",children:[e.jsx("span",{className:"w-5 h-5 rounded-full bg-primary text-primary-foreground text-[10px] flex items-center justify-center font-bold",children:a}),o]})}function Za(a){const o=Math.floor(a/60),u=a%60;return`${o}:${u.toString().padStart(2,"0")}`}function Qa({visible:a,productImage:o,productName:u,elapsedTime:n,progress:i,onReopen:d,onCancel:w}){return e.jsx(rt,{children:a&&e.jsxs(J.div,{initial:{opacity:0,y:30,scale:.9}
16,animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:30,scale:.9},transition:{type:"spring",stiffness:320,damping:26},className:"fixed bottom-5 right-5 z-50 max-w-[calc(100vw-2.5rem)]",children:[e.jsxs("div",{role:"button",onClick:d,className:v("group flex items-center gap-3 pl-2 pr-3 py-2 rounded-full","bg-card/95 backdrop-blur-md border border-border shadow-2xl","hover:border-primary/60 hover:bg-card transition-all cursor-pointer"),children:[e.jsxs("div",{className:"relative w-9 h-9 rounded-full overflow-hidden bg-white/90 border border-border/50 flex-shrink-0",children:[o?e.jsx("img",{src:o,alt:u||"Product",className:"w-full h-full object-contain"}):e.jsx("div",{className:"w-full h-full bg-gradient-to-br from-primary/30 to-primary/10"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/40",children:e.jsx(Te,{className:"h-4 w-4 text-white animate-spin"})})]}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsx("span",{className:"text-xs font-semibold text-foreground leading-tight truncate max-w-[180px]",children:"Generating adâ¦"}),e.jsxs("span",{className:"text-[10px] text-muted-foreground leading-tight tabular-nums",children:[Za(n)," · ",Math.round(i),"%"]})]}),e.jsx(L,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-full opacity-70 group-hover:opacity-100",tabIndex:-1,"aria-label":"Reopen",children:e.jsx(Gr,{className:"h-3.5 w-3.5"})}),w&&e.jsx(L,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-full opacity-50 hover:opacity-100 hover:text-destructive",onClick:M=>{M.stopPropagation(),w()},"aria-label":"Cancel generation",children:e.jsx(at,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"mx-3 mt-1 h-0.5 bg-border/50 rounded-full overflow-hidden",children:e.jsx(J.div,{className:"h-full bg-primary",animate:{width:`${Math.max(2,Math.min(100,i))}%`},transition:{duration:.5}})})]})})}const xt=3e3,es=600;function Ve(a,o="Something went wrong"){if(!a)return o;if(typeof a=="string")return a;
16if(a instanceof Error)return a.message||o;if(Array.isArray(a)){const u=a.map(n=>(n==null?void 0:n.msg)||(n==null?void 0:n.message)||(typeof n=="string"?n:null)).filter(Boolean);if(u.length)return u.join("; ")}if(typeof a=="object"){const u=a;if(typeof u.message=="string")return u.message;if(typeof u.error=="string")return u.error;if(typeof u.msg=="string")return u.msg;if(Array.isArray(u.detail))return Ve(u.detail,o);try{return JSON.stringify(a)}catch{return o}}return o}async function Vt(a,o,u){if(!o.startsWith("data:")&&!o.startsWith("blob:"))return o;const i=await(await fetch(o)).blob(),d=i.type||"image/png",w=d.split("/")[1]||"png",M=new File([i],`image.${w}`,{type:d});return bt(a,M,u)}const tt=[{phase:"upload",label:"Uploading your product...",progress:5},{phase:"analyze",label:"Analyzing product details...",progress:15},{phase:"remove-bg",label:"Preparing cutout...",progress:25},{phase:"routing",label:"Warming up the AI director...",progress:32},{phase:"generate",label:"Filming your scene...",progress:50},{phase:"render",label:"Rendering frames...",progress:70},{phase:"enhance",label:"Polishing the final cut...",progress:85},{phase:"finalize",label:"Almost ready...",progress:95}];function ts(a){return a<=0?{phaseIndex:3,mappedProgress:30}:a<10?{phaseIndex:4,mappedProgress:30+a*1.5}:a<50?{phaseIndex:4,mappedProgress:35+(a-10)*.75}:a<80?{phaseIndex:5,mappedProgress:55+(a-50)*.5}:a<95?{phaseIndex:6,mappedProgress:70+(a-80)*1}:{phaseIndex:7,mappedProgress:85+(a-95)*2}}function Fs(){var Dt;const{user:a,session:o}=kt(),{canAccessUGC:u,getToolRestriction:n}=qr(),{isOtherTabBusy:i,setBusy:d,forceClear:w}=Vr("clicktoad",a==null?void 0:a.id),[M,y]=t.useState("upload"),[S,I]=t.useState(""),[c,j]=t.useState(""),[B,P]=t.useState(""),[re,_]=t.useState(!1),[z,le]=t.useState("product"),[q,H]=t.useState("standard"),[k,G]=t.useState("ai-auto"),[F,D]=t.useState("9:16"),[W,$]=t.useState(""),[T,me]=t.useState(!1),[ue,l]=t.useState(null),[se,xe]=t.useState(!1),[ne,ce]=t.useState(null),[ye,Ee]=t.useState("influencer"),[Ne,Le]=t.useState("EXAVITQu4vr4xnSDxMaL"),[m,A]=t.useState(""),[Y,r]=t.useState(!1),[s,C]=t.useState(""),[b,V]=t.useState(null),[g,Q]=t.useState(!1),[de,O]=t.useState(0),[Ae,X]=t.useState(0),[Z,he]=t.useState(null),[ee,ve]=t.useState(0),[Xe,ke]=t.useState(!1),[ge,We]=t.useState(null),[nt,qe]=t.useState(null),[Ct,ze]=t.useState(null),ie=t.useRef(null),ae=t.useRef(null),It=t.useRef(0),Oe=t.useRef(0),pe=t.useRef(null),Ce=t.useRef(!1),St=t.useRef(!1);na({onPrompt:h=>{$(h),P(h)},onImageUrl:h=>{ce(h),y("upload")},acceptMediaTypes:["image"]});const{handleUpload:Jt,handleClear:Pt,getImage:Zt}=Or(),{balance:it,deductCredits:Qt,refundCredits:Re,getToolCost:er}=Ot(),tr=n("generate-click-to-ad-ugc"),rr=u,Tt=z==="ugc"?"generate-click-to-ad-ugc":"generate-click-to-ad",Et=z==="ugc"?void 0:{tier:q},ot=er(Tt,Et),ar=it>=ot,we=z==="ugc",je=Zt("product"),At=je.file||ne,Rt=ne||je.preview||"";t.useEffect(()=>{At&&!g&&!b&&_(!0)},[At]),t.useEffect(()=>{if(!g||!Z)return;const h=setInterval(()=>{ve(Math.floor((Date.now()-Z)/1e3))},1e3);return()=>clearInterval(h)},[g,Z]),t.useEffect(()=>{if(!g){O(0),X(0);return}const h=setInterval(()=>{O(x=>{if(x<3){const R=x+1;return X(p=>Math.max(p,tt[R].progress)),R}return x})},2e3);return()=>clearInterval(h)},[g]),t.useEffect(()=>{if(!g)return;const x=Math.min(1,ee/(we?360:120)),R=1-Math.pow(1-x,1.6),p=Math.round(32+R*60);X(f=>Math.max(f,p)),p>=85?O(f=>Math.max(f,6)):p>=70?O(f=>Math.max(f,5)):p>=45&&O(f=>Math.max(f,4))},[g,ee,we]),t.useEffect(()=>()=>{ie.current&&clearTimeout(ie.current),ae.current&&clearInterval(ae.current)},[]);const sr=(h,x)=>{ce(h),j(x),y("upload"),N.success("AI image ready!")},nr=h=>$(h),ir=async()=>{var h;if(!c){N.error("Please add a product name first");return}r(!0);try{const{data:x,error:R}=await K.functions.invoke("generate-video-script",{body:{videoType:"ugc ad",duration:"15",topic:c,keyPoints:B,productImageUrl:ne}});if(R)throw new Error(R.message);if((h=x==null?void 0:x.script)!=null&&h.script)A(x.script.script),N.success("Script generated!");else throw new Error("No script in response")}catch(x){console.error("Script generation error:",x),N.error("Failed to generate script. Please write one manually.")}finally{r(!1)}};async function or(h="veo"){const x=k||"lifestyle-scene";let R=je.file?await bt(K,je.file,"click-to-ad"):ne;if(!R)throw new Error("No product image available for retry");R=await Vt(K,R,"click-to-ad");const{data:p,error:f}=await K.functions.invoke("generate-click-to-ad",{body:{productImageUrl:R,productName:c.trim()||"Product",productDescription:B.trim()||void 0,adType:z,qualityTier:z==="product"?q:void 0,template:x,aspectRatio:z==="product"?F:void 0,styleDirection:W.trim()||void 0,inputSource:M,preferredVideoProvider:h,script:we?m:void 0,avatarPrompt:we?ye==="custom"&&s?s:Gt[ye]:void 0,voice:we?Ne:void 0,transactionId:pe.current}});if(f)throw new Error(f.message);if(p!=null&&p.error)throw new Error(Ve(p.error,"Retry failed"));if(!(p!=null&&p.taskId))throw new Error("No task ID returned from retry");return G(x),We(p.taskId),qe(p.provider),ze(p.falModel??null),O(4),X(45),p}const Je=t.useCallback((h,x,R,p)=>{var f;
16V(h),Q(!1),Ce.current=!1,X(100),ke(!1),ze(null),ie.current&&(clearTimeout(ie.current),ie.current=null),ae.current&&(clearInterval(ae.current),ae.current=null),(f=o==null?void 0:o.user)!=null&&f.id&&Fr({userId:o.user.id,name:`${p||"Product"} Ad - ${x}`,content:h,type:"video_prompt",tags:["click-to-ad",x,R],metadata:{productName:p,adType:x,qualityTier:R}}),N.success("Video ad generated successfully!")},[(Dt=o==null?void 0:o.user)==null?void 0:Dt.id]),Me=t.useCallback(async(h,x,R=0,p)=>{if(It.current=Date.now(),R>=es){Q(!1),Ce.current=!1,N.error("Video generation timed out. Please try again."),pe.current&&await Re(pe.current);return}const f=(E=xt)=>{ie.current=setTimeout(()=>{Me(h,x,R+1,p)},E)};try{const{data:E,error:Ie}=await K.functions.invoke("check-video-status",{body:{taskId:h,provider:x,...p&&{falModel:p},toolType:"click-to-ad"}});if(Ie)throw new Error(Ie.message);Oe.current=0;const fe=E==null?void 0:E.state;if(fe==="retry"&&(E!=null&&E.retryTaskId)){console.log(`[ClickToAd] Auto-failover: switching to ${E.retryProvider} task ${E.retryTaskId}`),N.info("This one's taking a bit longer than usual â hang tight, we're still on it."),Me(E.retryTaskId,E.retryProvider||"fal",0,E.retryFalModel);return}const Se=typeof(E==null?void 0:E.progress)=="number"?E.progress:null;if(Se!==null&&Se>0){const{phaseIndex:Be,mappedProgress:be}=ts(Se);O(Be),X(ct=>Math.max(ct,Math.round(be)))}if(fe==="success"&&(E!=null&&E.videoUrl)){Je(E.videoUrl,z,q,c);return}if(fe==="fail"){Q(!1),Ce.current=!1,ke(!1),ze(null),ie.current&&(clearTimeout(ie.current),ie.current=null),N.error(Ve(E==null?void 0:E.error,"Video generation failed")),pe.current&&await Re(pe.current);return}f()}catch(E){Oe.current+=1;const Ie=Oe.current;if(console.warn(`[ClickToAd] Poll attempt ${R} failed (${Ie} consecutive):`,E),Ie>=5){console.error("[ClickToAd] 5 consecutive poll failures â backing off but keeping DB fallback active"),f(xt*4),Oe.current=3;return}f(xt*Math.pow(2,Math.min(Ie-1,4)))}},[z,q,c,Xe,Re,or,Je]);t.useEffect(()=>{if(!g||!ge||!(a!=null&&a.id)){ae.current&&(clearInterval(ae.current),ae.current=null);return}const h=async()=>{try{const{data:R}=await K.from("generation_tasks").select("status, result_url, error_message").eq("user_id",a.id).eq("task_id",ge).maybeSingle(),p=R??(ge.startsWith("pending-")?(await K.from("generation_tasks").select("status, result_url, error_message").eq("user_id",a.id).eq("metadata->>pendingTaskId",ge).order("created_at",{ascending:!1}).limit(1).maybeSingle()).data:null);if(!p)return;p.status==="completed"&&p.result_url?(console.log("[ClickToAd] DB fallback recovered finished video"),Je(p.result_url,z,q,c)):p.status==="failed"&&(ie.current&&(clearTimeout(ie.current),ie.current=null),ae.current&&(clearInterval(ae.current),ae.current=null),Q(!1),Ce.current=!1,N.error(Ve(p.error_message,"Video generation failed")),pe.current&&Re(pe.current))}catch(R){console.warn("[ClickToAd] DB fallback check failed:",R)}},x=setTimeout(h,15e3);return ae.current=setInterval(h,3e4),()=>{clearTimeout(x),ae.current&&(clearInterval(ae.current),ae.current=null)}},[g,ge,a==null?void 0:a.id,z,q,c,Je,Re]),t.useEffect(()=>{if(!g||!ge||!nt)return;const h=setInterval(()=>{const x=Date.now()-It.current;x>2e4&&(console.warn(`[ClickToAd] Watchdog: poll silent for ${Math.round(x/1e3)}s â restarting`),ie.current&&clearTimeout(ie.current),Oe.current=0,Me(ge,nt,0,Ct??void 0))},1e4);return()=>clearInterval(h)},[g,ge,nt,Ct,Me]),t.useEffect(()=>{if(!(a!=null&&a.id)||St.current)return;St.current=!0,(async()=>{try{const{data:x,error:R}=await K.from("generation_tasks").select("*").eq("user_id",a.id).eq("tool_type","generate-click-to-ad").in("status",["processing","completed"]).order("created_at",{ascending:!1}).limit(5);if(R||!(x!=null&&x.length))return;const p=x.find(te=>te.status==="completed"&&te.result_url&&(Date.now()-new Date(te.created_at).getTime())/(1e3*60)<60);if(p!=null&&p.result_url){const te=p.metadata,hr=(te==null?void 0:te.adType)||"product",gr=(te==null?void 0:te.qualityTier)||"standard",xr=(te==null?void 0:te.productName)||"Product";te!=null&&te.productImageUrl&&ce(te.productImageUrl),j(xr),le(hr),H(gr),V(p.result_url),X(100),_(!0),N.success("Here's the video that finished while you were away.");return}const f=x.find(te=>te.status==="processing");if(!f)return;const E=new Date(f.created_at).getTime(),Ie=(Date.now()-E)/(1e3*60),fe=f.metadata,Se=typeof(fe==null?void 0:fe.falModel)=="str
16ing"?fe.falModel:void 0,Be=()=>{We(f.task_id),qe(f.provider),ze(Se??null),he(E),fe&&(j(fe.productName||"Product"),ce(fe.productImageUrl||null),le(fe.adType||"product"))},{data:be,error:ct}=await K.functions.invoke("check-video-status",{body:{taskId:f.task_id,provider:f.provider,...Se&&{falModel:Se}}});if(ct){Ie<30&&(Be(),Q(!0),_(!0),N.info("Resuming your video generation..."),Me(f.task_id,f.provider,0,Se));return}if((be==null?void 0:be.state)==="success"&&be.videoUrl){await K.from("generation_tasks").update({status:"completed",result_url:be.videoUrl,completed_at:new Date().toISOString()}).eq("id",f.id),Be(),V(be.videoUrl),Q(!1),X(100),_(!0),N.success("Recovered your finished video.");return}if((be==null?void 0:be.state)==="fail"){await K.from("generation_tasks").update({status:"failed",error_message:be.error||"Generation failed"}).eq("id",f.id);return}Ie<30?(Be(),Q(!0),_(!0),N.info("Resuming your video generation..."),Me(f.task_id,f.provider,0,Se)):await K.from("generation_tasks").update({status:"failed",error_message:"Generation timed out"}).eq("id",f.id)}catch(x){console.error("Error in checkPendingGenerations:",x)}})()},[a==null?void 0:a.id,Me]),t.useEffect(()=>(d(g),()=>{g&&d(!1)}),[g,d]);const lr=async()=>{if(Ce.current||g)return;if(i){N.error("Another tab is already generating",{description:"Click-to-Ad is running in another browser tab. Wait for it to finish, or close that tab before starting a new generation."});return}if(!o){Lt();return}const h=je.file?null:ne;if(!je.file&&!h){N.error("Please upload a product image first");return}if(we&&!m.trim()){N.error("Please add a script for the avatar presenter");return}if(we){const x=m.split(/\s+/).filter(Boolean).length;if(x>30){N.error("Script too long!",{description:`${x} words but max is 30.`});return}}Ce.current=!0,pe.current=null,Q(!0),ke(!1),V(null),O(0),X(5),he(Date.now()),ve(0);try{let x;je.file?(O(0),x=await bt(K,je.file,"click-to-ad")):x=h,x=await Vt(K,x,"click-to-ad"),O(1),X(15);const R=await Qt(Tt,Et);if(!R.success){Wr(R.error)?Lt():N.error("Insufficient credits",{description:`You need ${ot} credits but only have ${it}.`}),Q(!1),Ce.current=!1;return}pe.current=R.transactionId||null;const{data:p,error:f}=await K.functions.invoke("generate-click-to-ad",{body:{productImageUrl:x,productName:c.trim()||"Product",productDescription:B.trim()||void 0,adType:z,qualityTier:z==="product"?q:void 0,template:k||void 0,aspectRatio:z==="product"?F:void 0,styleDirection:W.trim()||void 0,inputSource:M,script:we?m:void 0,avatarPrompt:we?ye==="custom"&&s?s:Gt[ye]:void 0,voice:we?Ne:void 0,transactionId:pe.current}});if(f)throw new Error(f.message);if(p!=null&&p.error)throw new Error(Ve(p.error,"Failed to generate video"));if(!(p!=null&&p.taskId))throw new Error("No task ID returned from API");We(p.taskId),qe(p.provider),ze(p.falModel??null),O(4),X(45);const E=we?"3-5 minutes":"2-4 minutes";N.info(`Video generation started! This may take ${E}.`),Me(p.taskId,p.provider,0,p.falModel)}catch(x){console.error("Click to Ad error:",x),N.error(x instanceof Error?x.message:"Failed to generate video"),Q(!1),Ce.current=!1,pe.current&&await Re(pe.current)}},cr=()=>{b&&window.open(b,"_blank")},dr=t.useCallback(async()=>{if(g){if(ie.current&&(clearTimeout(ie.current),ie.current=null),ae.current&&(clearInterval(ae.current),ae.current=null),Q(!1),X(0),ke(!1),ze(null),Ce.current=!1,ge&&(a!=null&&a.id))try{await K.from("generation_tasks").update({status:"failed",error_message:"Cancelled by user",completed_at:new Date().toISOString()}).eq("user_id",a.id).or(`task_id.eq.${ge},metadata->>pendingTaskId.eq.${ge}`)}catch(h){console.warn("[ClickToAd] cancel: failed to update task row",h)}pe.current&&(await Re(pe.current),pe.current=null),We(null),qe(null),N.success("Generation cancelled. Credits refunded.")}},[g,ge,a==null?void 0:a.id,Re]),lt=()=>{V(null),We(null),qe(null),ze(null),ve(0),he(null),A("")},mr=()=>{lt(),_(!1),ce(null),j(""),P(""),l(null),$(""),Pt("product")()},ur=h=>{lt(),j(h.productName),P(h.productDescription),ce(h.selectedImage),l(h),window.setTimeout(()=>_(!0),0),N.success("Product ready!")},Mt=async()=>{const h=S.trim();if(!h){N.error("Paste a product URL first");return}try{const p=new URL(h.startsWith("http")?h:`https://${h}`);
16if(!["http:","https:"].includes(p.protocol))throw new Error("bad protocol")}catch{N.error("That doesn't look like a valid URL");return}me(!0);let x=null;const R=new Promise((p,f)=>{x=setTimeout(()=>{f(new Error("__SCRAPE_TIMEOUT__"))},6e4)});try{const p=K.functions.invoke("scrape-product-url",{body:{url:h.startsWith("http")?h:`https://${h}`}}),{data:f,error:E}=await Promise.race([p,R]);if(E)throw new Error(E.message||"Scrape failed");if(!(f!=null&&f.success))throw new Error(Ve(f==null?void 0:f.error,"Could not extract product details"));l(f.data),xe(!0),N.success("Product details extracted!")}catch(p){console.error("[ClickToAd] Scrape error:",p);const f=p instanceof Error?p.message:"Failed to scrape product page";f==="__SCRAPE_TIMEOUT__"?N.error("Extraction is taking unusually long",{description:i?"Another browser tab is mid-generation. Wait for it to finish, or close it and try again.":"Try again in a few seconds, or paste a more direct product link."}):N.error(f)}finally{x&&clearTimeout(x),me(!1)}},pr=tt[de]||tt[0];return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsxs("section",{className:"relative py-12 lg:py-16 overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-b from-primary/5 via-transparent to-transparent pointer-events-none"}),e.jsx("div",{className:"container mx-auto px-4",children:e.jsxs("div",{className:"grid xl:grid-cols-2 gap-8 xl:gap-16 items-center",children:[e.jsxs("div",{className:"text-center xl:text-left space-y-6 min-w-0",children:[e.jsxs(De,{variant:"outline",className:"mb-4 text-primary border-primary/30",children:[e.jsx(oe,{className:"h-3 w-3 mr-1"}),"AI Video Ad Generator"]}),e.jsxs("h1",{className:"text-3xl sm:text-4xl md:text-5xl xl:text-6xl font-bold tracking-tight",children:[e.jsx("span",{className:"text-primary",children:"TURN ANY PRODUCT"}),e.jsx("br",{}),e.jsx("span",{className:"text-foreground",children:"INTO A VIDEO AD"})]}),e.jsx("p",{className:"text-base sm:text-lg text-muted-foreground max-w-lg mx-auto xl:mx-0",children:"Upload an image and AI handles the rest â style, motion, and cinematic direction."}),e.jsxs("div",{className:"space-y-4 max-w-lg mx-auto xl:mx-0",children:[i&&!g&&e.jsxs("div",{className:"rounded-lg border border-primary/30 bg-primary/5 px-3 py-2 text-xs text-foreground/80 flex items-start gap-2",children:[e.jsx(Te,{className:"h-3.5 w-3.5 mt-0.5 shrink-0 animate-spin text-primary"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("p",{children:"Another browser tab is currently generating an ad. Starting a new generation here is paused until that one finishes."}),e.jsx("button",{type:"button",onClick:w,className:"text-[11px] text-primary hover:underline",children:"Nothing actually running? Reset and continue â"})]})]}),e.jsxs(Bt,{value:M,onValueChange:h=>y(h),className:"w-full",children:[e.jsxs(Kt,{className:"grid w-full grid-cols-3 mb-4 relative z-10",children:[e.jsxs(He,{value:"upload",className:"gap-2",children:[e.jsx(ia,{className:"h-4 w-4"})," Upload"]}),e.jsxs(He,{value:"chat",className:"gap-2",children:[e.jsx(Xt,{className:"h-4 w-4"})," AI Chat"]}),e.jsxs(He,{value:"url",className:"gap-2",children:[e.jsx(oa,{className:"h-4 w-4"})," URL"]})]}),e.jsx($e,{value:"upload",className:"space-y-4",children:ne&&!je.file?e.jsxs("div",{className:"max-w-xs mx-auto xl:mx-0 space-y-3",children:[e.jsxs("div",{className:"relative aspect-square rounded-xl overflow-hidden border-2 border-primary/50 bg-white",children:[e.jsx("img",{src:ne,alt:c||"Product",className:"w-full h-full object-contain"}),e.jsxs(De,{className:"absolute top-2 right-2 bg-primary/90",children:[e.jsx(oe,{className:"h-3 w-3 mr-1"})," AI Generated"]})]}),e.jsx(Ge,{placeholder:"Product name (optional)",value:c,onChange:h=>j(h.target.value),className:"bg-card"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{variant:"outline",size:"sm",className:"flex-1",onClick:mr,children:"Change Image"}),e.jsxs(L,{size:"sm",className:"flex-1 gap-1.5",onClick:()=>_(!0),children:[e.jsx(Ye,{className:"h-4 w-4"})," Create Ad"]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Br,{id:"product-upload",label:"Product Photo",tooltip:"Upload a clear photo of your product",preview:je.preview,onUpload:Jt("product"),onClear:Pt("product"),aspectRatio:"square",placeholder:"Drop product image here",className:"max-w-xs mx-auto xl:mx-0"}),je.preview&&e.jsxs("div",{className:"max-w-xs mx-auto xl:mx-0 space-y-3",children:[e.jsx(Ge,{placeholder:"Product name (optional)",value:c,onChange:h=>j(h.target.value),className:"bg-card"}),e.jsxs(L,{size:"sm",className:"w-full gap-1.5",onClick:()=>_(!0),children:[e.jsx(Ye,{className:"h-4 w-4"})," Create Ad"]})]})]})}),e.jsx($e,{value:"chat",className:"space-y-4",children:e.jsx(Fa,{onImageGenerated:sr,onStyleDirectionReady:nr,onClose:()=>y("upload")})}),e.jsx($e,{value:"url",className:"space-y-4",children:e.jsx("div",{className:"max-w-lg mx-auto xl:mx-0 space-y-3",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ge,{type:"url",placeholder:"https://yourstore.com/products/awesome-thing",value:S,onChange:h=>I(h.target.value),onKeyDown:h=>{h.key==="Enter"&&!T&&Mt()},disabled:T,className:"bg-card"}),e.jsx(L,{onClick:Mt,disabled:T||!S.trim(),className:"gap-1.5 shrink-0",children:T?e.jsxs(e.Fragment,{children:[e.jsx(Te,{className:"h-4 w-4 animate-spin"})," Scanningâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-4 w-4"})," Extract"]})})]})})})]})]})]}),e.jsx("div",{className:"order-first xl:order-last min-w-0 flex justify-center",children:e.jsx(ca,{})})]})})]}),!g&&!b&&e.jsx(ua,{}),ue&&e.jsx(pa,{open:se,onOpenChange:xe,productData:ue,onConfirm:ur}),e.jsx(Ja,{open:re,onOpenChange:_,productImage:Rt,productName:c,productDescription:B,adType:z,onAdTypeChange:le,selectedTemplate:k,onTemplateChange:G,aspectRatio:F,onAspectRatioChange:D,qualityTier:q,onQualityTierChange:H,styleDirection:W,onStyleDirectionChange:$,personaStyle:ye,onPersonaStyleChange:Ee,ugcVoice:Ne,onUgcVoiceChange:Le,avatarScript:m,onAvatarScriptChange:A,isGeneratingScript:Y,onGenerateScript:ir,customPresenterPrompt:s,onCustomPresenterPromptChange:C,isLoading:g,videoResult:b,onGenerate:lr,onDownload:cr,onReset:lt,onCancel:dr,canAfford:ar,credit
16Cost:ot,balance:it,elapsedTime:ee,currentPhase:pr,loadingPhases:tt,loadingPhaseIndex:de,loadingProgress:Ae,canSelectUGC:rr,ugcMinimumPlan:tr.minimumPlanDisplayName||"Pro"}),e.jsx(Qa,{visible:g&&!re,productImage:Rt,productName:c,elapsedTime:ee,progress:Ae,onReopen:()=>_(!0)})]})}export{Fs 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.