1import{j as e,m as R,A as we}from"./vendor-ui-BRVg3_iW.js";import{r as l,L as tr}from"./vendor-react-fhnP-ZxB.js";import{ah as rr,x as ee,y as ie,aq as _t,ad as St,aD as Je,S as ue,_ as je,Z as Ct,v as C,o as D,aO as ar,a6 as Be,P as sr,j as pe,al as It,am as Tt,ao as $t,ce as nr,aN as xe,bm as ir,an as or,u as lr,at as cr,av as Me,$ as be,z as ct,aZ as ve,au as Ut,K as Xe,k as dr,cb as Et,b8 as Ze,ae as Pt,bo as Mt,c0 as Ge,as as mr,ac as ur,bO as pr,H as xr,R as hr}from"./index-BTZS4ZAF.js";import{L as gr}from"./link-2-C1hWKL9E.js";import{M as Ae}from"./mic-CF1Xk4wD.js";import{U as At}from"./upload-blZ-ZbK1.js";import{R as fr}from"./rotate-cw-CqkrdjVT.js";import{D as Ot}from"./download-DVZYklFy.js";import{T as br}from"./trophy-BNZRqBUI.js";import{S as Rt,b as Dt,d as Ft,c as Lt,a as yr,e as jr}from"./sheet-BF2okP4S.js";import{T as dt}from"./textarea-D-Y40bXc.js";import{T as Ht}from"./type-DVqBw-WX.js";import{S as vr}from"./shirt-DsOXrdaS.js";import{M as wr}from"./map-pin-BhMpk5-9.js";import{L as Ye}from"./lightbulb-D6WP6MBf.js";import{S as Nr}from"./save-BsTZEswx.js";import{B as Bt,a as kr}from"./BrainAnnotations-kAKIRN9q.js";import{B as _r}from"./brain-D1EBUI49.js";import{S as Gt}from"./scan-line--QY-HoCz.js";import{T as Sr,a as Cr,b as mt,c as ut}from"./tabs-B-u7iS49.js";import{F as pt}from"./flame-Dvjw28XX.js";import{S as Ir}from"./scissors-D8X_phTL.js";import{u as Tr}from"./useRemixHydration-DNXyxCHI.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";/** 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 $r=rr("SquareUserRound",[["path",{d:"M18 21a6 6 0 0 0-12 0",key:"kaz2du"}],["circle",{cx:"12",cy:"11",r:"4",key:"1gt34v"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);function Ur({onSubmit:t,isWorking:r,initialUrl:s}){const[a,n]=l.useState(s??"");l.useEffect(()=>{s&&n(s)},[s]);const[c,o]=l.useState(""),[i,x]=l.useState(""),[m,j]=l.useState(!1),[b,k]=l.useState(null),[h,$]=l.useState(null),[S,f]=l.useState(null),[d,u]=l.useState(!1),[g,y]=l.useState(!1),I=l.useRef(null),E=25,_=S?(N=>{const F=Math.max(3,Math.min(30,Math.round(N)));return F<=10?1:F<=20?2:3})(S)*20:null,U=_?`${_}`:"20â60",A=N=>new Promise(F=>{const z=document.createElement("video");z.preload="metadata",z.muted=!0;const M=URL.createObjectURL(N),te=()=>{URL.revokeObjectURL(M),z.remove()};z.onloadedmetadata=()=>{const re=z.duration;te(),F(Number.isFinite(re)?re:0)},z.onerror=()=>{te(),F(0)},z.src=M}),O=async N=>{if(!N.type.startsWith("video/")){C.error("Please upload a video file (.mp4 works best).");return}if(N.size>80*1024*1024){C.error("Keep videos under 80MB.");return}const F=await A(N);if(F&&F>30.5){C.error(`Ad is ${Math.round(F)}s â please trim to 30 seconds or less.`,{description:"Ad Decoder renders up to 30s (3 Ã 10s Omni clips)."});return}j(!0);try{const{data:{user:z}}=await D.auth.getUser();if(!z){C.error("Please sign in to upload."),j(!1);return}const M=N.name.split(".").pop()||"mp4",te=`${z.id}/ad-decoder/${Date.now()}-${Math.random().toString(36).slice(2,8)}.${M}`,{error:re}=await D.storage.from("motion-video-uploads").upload(te,N);if(re)throw re;const{data:{publicUrl:he}}=D.storage.from("motion-video-uploads").getPublicUrl(te);k(he),$(N.name),f(F||null),n("")}catch(z){const M=z instanceof Error?z.message:"Upload failed";C.error(M)}finally{j(!1)}},v=()=>{if(!a&&!b){C.error("Paste a TikTok or Meta Ads Library link, or upload an ad video.");return}if(a&&!b){const N=a.trim().toLowerCase(),F=/tiktok\.com|vm\.tiktok|vt\.tiktok/.test(N),z=/facebook\.com\/ads\/library|ads\.facebook\.com/.test(N),M=/instagram\.com/.test(N),te=/youtube\.com|youtu\.be/.test(N);if(!F&&!z){M||te?C.error(`${M?"Instagram":"YouTube"} links aren't supported yet. Download the video and upload the .mp4 instead.`):C.error("Paste a TikTok or Meta Ads Library link, or upload an .mp4.");return}}t({url:b?void 0:a.trim(),uploadedVideoUrl:b||void 0,productHint:c.trim()||void 0,manualTranscript:i.trim()||void 0})},q=(!!a.trim()||!!b)&&!r&&!m;return e.jsx("div",{className:"w-full max-w-4xl mx-auto",children:e.jsxs(R.div,{initial:{opacity:0,y:18}
6,animate:{opacity:1,y:0},className:ee("relative rounded-3xl p-3 sm:p-4","bg-white/[0.03] backdrop-blur-2xl","border border-white/[0.08]","shadow-[0_30px_80px_-30px_hsl(var(--primary)/0.35)]"),children:[e.jsx("input",{ref:I,type:"file",accept:"video/*",className:"hidden",onChange:N=>{var z;const F=(z=N.currentTarget.files)==null?void 0:z[0];N.currentTarget.value="",F&&O(F)}}),e.jsxs("div",{className:"flex items-center gap-2 px-3 sm:px-4 pt-2 pb-3",children:[e.jsx("button",{type:"button",onClick:()=>{var N;return(N=I.current)==null?void 0:N.click()},disabled:r||m,className:"h-9 w-9 shrink-0 rounded-full bg-white/[0.06] hover:bg-white/[0.12] grid place-items-center text-muted-foreground hover:text-foreground transition-colors",title:"Upload .mp4",children:m?e.jsx(ie,{className:"h-4 w-4 animate-spin"}):e.jsx(_t,{className:"h-4 w-4"})}),e.jsx(gr,{className:"h-4 w-4 text-muted-foreground/60 shrink-0"}),e.jsx("input",{value:a,onChange:N=>{n(N.target.value),N.target.value&&(k(null),$(null))},placeholder:"Paste a TikTok or Meta Ads Library URL â or click + to upload an .mp4",disabled:r||m||!!b,onKeyDown:N=>{N.key==="Enter"&&q&&v()},className:"flex-1 bg-transparent border-0 outline-none text-sm sm:text-base placeholder:text-muted-foreground/50 text-foreground py-2"}),!a&&!b&&e.jsx("kbd",{className:"hidden md:inline-flex items-center gap-1 px-2 py-1 rounded-md bg-white/[0.05] border border-white/10 text-[10px] font-mono text-muted-foreground shrink-0",children:typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"âV":"Ctrl+V"})]}),b&&e.jsxs("div",{className:"mx-3 sm:mx-4 mb-3 flex items-center gap-3 p-2 rounded-2xl bg-primary/10 border border-primary/25",children:[e.jsx("video",{src:b,className:"w-10 h-10 object-cover rounded-lg",muted:!0}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-primary truncate",children:h}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:S?`${Math.round(S)}s · ${E} credits to decode, ~${_} to render`:"Ready to decode"})]}),e.jsx("button",{onClick:()=>{k(null),$(null),f(null)},className:"h-7 w-7 rounded-full hover:bg-white/10 grid place-items-center text-muted-foreground",children:e.jsx(St,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex items-end justify-between gap-2 px-2 sm:px-3 pb-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(Ue,{icon:e.jsx(Je,{className:"h-3.5 w-3.5"}),active:d,onClick:()=>u(N=>!N),children:"Product hint"}),e.jsx(Ue,{icon:e.jsx(Ae,{className:"h-3.5 w-3.5"}),active:g,onClick:()=>y(N=>!N),children:i.trim()?"Transcript added":"Add transcript"}),e.jsx(Ue,{icon:e.jsx(At,{className:"h-3.5 w-3.5"}),onClick:()=>{var N;return(N=I.current)==null?void 0:N.click()},children:"Upload .mp4"}),e.jsxs(Ue,{icon:e.jsx(ue,{className:"h-3.5 w-3.5"}),disabled:!0,children:["9:16 · ",E," to decode · 20 / 10s to render"]})]}),e.jsx(je,{onClick:v,disabled:!q,title:`${E} credits to decode. Rendering the hero cut costs ${U} more (20 credits per 10s segment).`,className:ee("h-12 px-5 rounded-2xl font-display font-black uppercase tracking-wider text-sm","bg-gradient-to-br from-primary via-primary to-lime-400 text-primary-foreground","hover:opacity-95 shadow-[0_10px_40px_-10px_hsl(var(--primary)/0.6)]","disabled:opacity-40 disabled:shadow-none"),children:r?e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"h-4 w-4 animate-spin mr-2"})," Decoding"]}):e.jsxs(e.Fragment,{children:["Decode ",e.jsx(Ct,{className:"h-4 w-4 mx-1.5 fill-current"})," ",E]})})]}),d&&e.jsx(R.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},className:"px-3 sm:px-4 pb-3 -mt-1",children:e.jsx("input",{value:c,onChange:N=>o(N.target.value),placeholder:"What's your product? e.g. 'matte vegan lipstick for Gen Z'",disabled:r,className:"w-full bg-white/[0.04] border border-white/[0.08] rounded-xl px-3 py-2 text-xs text-foreground placeholder:text-muted-foreground/50 outline-none focus:border-primary/40"})}),g&&e.jsxs(R.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},className:"px-3 sm:px-4 pb-3 -mt-1 space-y-1.5",children:[e.jsx("textarea",{value:i,onChange:N=>x(N.target.value.slice(0,5e3)),placeholder:"Paste the voiceover / dialogue here. We'll skip the auto-transcription and use this verbatim â best for Meta Ads Library links where the audio isn't downloadable.",disabled:r,rows:4,className:"w-full resize-y bg-white/[0.04] border border-white/[0.08] rounded-xl px-3 py-2 text-xs text-foreground placeholder:text-muted-foreground
6/50 outline-none focus:border-primary/40 leading-relaxed"}),e.jsxs("p",{className:"text-[10px] text-muted-foreground/70",children:["Optional. Leave empty to auto-transcribe the audio. ",i.length,"/5000"]})]})]})})}function Ue({icon:t,children:r,onClick:s,active:a,disabled:n}){return e.jsxs("button",{type:"button",onClick:s,disabled:n,className:ee("inline-flex items-center gap-1.5 h-9 px-3 rounded-full text-xs font-medium transition-colors","border",a?"bg-primary/15 border-primary/40 text-primary":"bg-white/[0.04] border-white/[0.08] text-muted-foreground hover:text-foreground hover:bg-white/[0.08]",n&&"opacity-50 cursor-not-allowed"),children:[t,r]})}function Er(t,r=1100){const[s,a]=l.useState(0);return l.useEffect(()=>{let n=0;const c=performance.now(),o=i=>{const x=Math.min(1,(i-c)/r),m=1-Math.pow(1-x,3);a(Math.round(t*m)),x<1&&(n=requestAnimationFrame(o))};return n=requestAnimationFrame(o),()=>cancelAnimationFrame(n)},[t,r]),s}const Pr=[{key:"pattern_interrupt",label:"Pattern Interrupt"},{key:"curiosity_gap",label:"Curiosity Gap"},{key:"visual_contrast",label:"Visual Contrast"},{key:"pacing_score",label:"Pacing"}];function Mr({label:t,value:r,delay:s}){return e.jsxs(R.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.4,delay:s},className:"space-y-1",children:[e.jsxs("div",{className:"flex items-baseline justify-between text-[11px]",children:[e.jsx("span",{className:"font-semibold text-foreground",children:t}),e.jsx("span",{className:"font-mono text-muted-foreground",children:r})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx(R.div,{className:"h-full bg-primary rounded-full",initial:{width:0},animate:{width:`${r}%`},transition:{duration:1,ease:[.22,1,.36,1],delay:s+.1}})})]})}function Ar({score:t,dna:r,archetype:s}){const a=Er(t),n=72,c=2*Math.PI*n,o=c-a/100*c,i=t>=80?"HIGH":t>=60?"MEDIUM":"LOW",x=t>=80?"text-primary":t>=60?"text-yellow-400":"text-muted-foreground";return e.jsxs(R.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.5},className:"rounded-2xl border border-white/[0.06] bg-gradient-to-br from-white/[0.03] to-white/[0.01] p-6 backdrop-blur",children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.2em] text-muted-foreground mb-1",children:"Hook DNA"}),e.jsxs("div",{className:"flex items-center gap-5 mb-5",children:[e.jsxs("div",{className:"relative w-[176px] h-[176px] shrink-0",children:[e.jsxs("svg",{viewBox:"0 0 176 176",className:"w-full h-full -rotate-90",children:[e.jsx("circle",{cx:88,cy:88,r:n,stroke:"hsl(var(--border) / 0.3)",strokeWidth:6,fill:"none"}),e.jsx(R.circle,{cx:88,cy:88,r:n,stroke:"hsl(var(--primary))",strokeWidth:6,fill:"none",strokeLinecap:"round",strokeDasharray:c,initial:{strokeDashoffset:c},animate:{strokeDashoffset:o},transition:{duration:1.4,ease:[.22,1,.36,1]},style:{filter:"drop-shadow(0 0 12px hsl(var(--primary) / 0.5))"}})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("div",{className:ee("text-5xl font-black leading-none font-mono",x),children:a}),e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.2em] text-muted-foreground mt-1",children:"/ 100"}),e.jsx("div",{className:ee("text-[10px] font-bold uppercase tracking-[0.2em] mt-2",x),children:i})]})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.2em] text-muted-foreground mb-1",children:"Archetype"}),e.jsx("div",{className:"text-sm font-bold leading-tight",children:s})]})]}),e.jsx("div",{className:"space-y-3 pt-4 border-t border-white/[0.06]",children:Pr.map((m,j)=>e.jsx(Mr,{label:m.label,value:(r==null?void 0:r[m.key])??0,delay:.2+j*.08},m.key))})]})}function Or({shot:t,recast:r,recastInProgress:s,videoState:a,onAnimate:n,index:c,showPromoteToShowcase:o,originalVideoUrl:i,originalSourceUrl:x,onRetryRecast:m,disableAnimate:j}){var E;const b=!!(r!=null&&r.image_url),k=!!r&&!r.image_url,[h,$]=l.useState(!1),[S,f]=l.useState(!1),[d,u]=l.useState(!1),[g,y]=l.useState(!1),I=async()=>
6{if(!a.videoUrl||!i){C.error("Missing original or recreated video URL");return}f(!0);const{count:B}=await D.from("decoder_showcase").select("id",{count:"exact",head:!0}),{error:w}=await D.from("decoder_showcase").insert({original_tiktok_url:x||i,original_video_url:i,recreated_video_url:a.videoUrl,label:`Shot ${c+1}`,position:B??0,is_published:!0});f(!1),w?C.error(`Promote failed: ${w.message}`):(C.success("Added to showcase"),u(!0))};return e.jsxs(e.Fragment,{children:[e.jsxs(R.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:c*.04},className:"rounded-2xl border border-white/[0.06] bg-white/[0.02] p-3 backdrop-blur",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 px-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"text-[10px] font-mono uppercase tracking-[0.2em] text-primary font-bold",children:["Shot ",String(c+1).padStart(2,"0")]}),e.jsxs("div",{className:"text-[10px] font-mono text-muted-foreground",children:["· ",((E=t.duration_s)==null?void 0:E.toFixed(1))??"â","s"]})]}),e.jsx("div",{className:"text-[10px] font-mono text-muted-foreground truncate max-w-[55%] text-right",children:t.camera})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-2",children:[e.jsxs("div",{className:"relative aspect-[9/16] rounded-lg overflow-hidden bg-black border border-white/[0.06]",children:[t.reference_frame_url&&e.jsx("img",{src:t.reference_frame_url,alt:`Original shot ${c+1}`,className:"w-full h-full object-cover",loading:"lazy"}),e.jsx("div",{className:"absolute top-1.5 left-1.5 px-1.5 py-0.5 rounded bg-black/70 backdrop-blur text-[9px] font-mono uppercase tracking-wider text-white/80",children:"Original"})]}),e.jsxs("div",{className:"relative aspect-[9/16] rounded-lg overflow-hidden bg-black border border-primary/20",children:[a.status==="completed"&&a.videoUrl?e.jsxs(e.Fragment,{children:[e.jsx("video",{src:a.videoUrl,controls:!0,className:"w-full h-full object-cover"}),e.jsx("button",{onClick:()=>$(!0),className:"absolute bottom-1.5 right-1.5 h-7 w-7 inline-flex items-center justify-center rounded-md bg-black/70 hover:bg-black/90 text-white backdrop-blur transition-colors",title:"Expand",children:e.jsx(ar,{className:"h-3.5 w-3.5"})})]}):b?e.jsx("img",{src:r.image_url,alt:`Recast shot ${c+1}`,className:"w-full h-full object-cover",loading:"lazy"}):s?e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center bg-gradient-to-b from-white/[0.04] to-transparent",children:[e.jsx(ie,{className:"h-5 w-5 animate-spin text-primary mb-2"}),e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-wider text-primary",children:"Recastingâ¦"})]}):k?e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center px-2 text-center gap-2",children:[e.jsx(Be,{className:"h-5 w-5 text-destructive"}),e.jsx("div",{className:"text-[10px] text-destructive",children:"Recast failed"}),m&&e.jsxs("button",{onClick:async()=>{if(!g){y(!0);try{await m(c)}finally{y(!1)}}},disabled:g,className:"inline-flex items-center gap-1 px-2 py-1 rounded-md bg-primary/15 border border-primary/40 text-primary text-[9px] font-mono uppercase tracking-wider hover:bg-primary/25 transition-colors disabled:opacity-60",children:[g?e.jsx(ie,{className:"h-2.5 w-2.5 animate-spin"}):e.jsx(fr,{className:"h-2.5 w-2.5"}),"Retry · 3 cr"]})]}):e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center px-2 text-center",children:[e.jsx(ue,{className:"h-5 w-5 text-muted-foreground/60 mb-2"}),e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-wider text-muted-foreground",children:"Your version"})]}),e.jsx("div",{className:ee("absolute top-1.5 left-1.5 px-1.5 py-0.5 rounded backdrop-blur text-[9px] font-mono uppercase tracking-wider",a.status==="completed"?"bg-primary text-primary-foreground":"bg-primary/20 text-primary"),children:a.status==="completed"?"Animated":"Your Recast"}),a.status==="generating"&&e.jsxs("div",{className:"absolute inset-0 bg-black/40 flex flex-col items-center justify-center",children:[e.jsx(ie,{className:"h-5 w-5 animate-spin text-primary mb-1"}),e.jsxs("div",{className:"text-[10px] font-mono text-primary",children:["Omni rendering",a.attempts>0?` · ${a.attempts}`:"â¦"]})]})]})]}),e.jsxs("div",{className:"px-1 space-y-1.5 mb-2.5",children:[e.jsxs("div",{className:"rounded-md bg-white/[0.03] border border-white/[0.05] p-2",children:[e.jsx("div",{className:"text-[9px] font-mono uppercase tracking-wider text-primary mb-0.5",children:"VO · spoken line"}
6),e.jsx("div",{className:"text-[11px] text-foreground/95 leading-snug",children:t.vo_line?e.jsxs(e.Fragment,{children:["â",t.vo_line,"â"]}):e.jsx("span",{className:"text-muted-foreground italic",children:"(silent shot â ambient only)"})})]}),t.on_screen_text&&e.jsxs("div",{className:"rounded-md bg-amber-400/[0.06] border border-amber-400/20 p-2",children:[e.jsx("div",{className:"text-[9px] font-mono uppercase tracking-wider text-amber-300 mb-0.5",children:"On-screen text"}),e.jsx("div",{className:"text-[11px] text-foreground/95 leading-snug whitespace-pre-wrap break-words",children:t.on_screen_text})]})]}),a.status==="completed"&&a.videoUrl?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("a",{href:a.videoUrl,download:!0,className:"w-full inline-flex items-center justify-center gap-1.5 h-8 rounded-lg bg-white/[0.06] hover:bg-white/[0.1] text-foreground text-[11px] font-semibold transition-colors",children:[e.jsx(Ot,{className:"h-3 w-3"})," Download shot"]}),o&&e.jsxs("button",{onClick:I,disabled:S||d,className:"w-full inline-flex items-center justify-center gap-1.5 h-8 rounded-lg border border-primary/40 bg-primary/10 hover:bg-primary/20 text-primary text-[11px] font-bold uppercase tracking-wider transition-colors disabled:opacity-60",title:"Admin · add this shot's before/after to the homepage showcase",children:[S?e.jsx(ie,{className:"h-3 w-3 animate-spin"}):e.jsx(br,{className:"h-3 w-3"}),d?"Added to showcase":"Add to showcase"]})]}):j?e.jsx("div",{className:"w-full h-8 rounded-lg bg-white/[0.03] border border-white/[0.06] text-muted-foreground text-[10px] font-mono uppercase tracking-widest inline-flex items-center justify-center",children:b?"Recast ready · use 90s renderer":k?"Skipped":"Awaiting recast"}):b?a.status==="generating"?e.jsxs("button",{disabled:!0,className:"w-full h-8 rounded-lg bg-primary/30 text-primary-foreground text-[11px] font-bold inline-flex items-center justify-center gap-1.5 cursor-wait",children:[e.jsx(ie,{className:"h-3 w-3 animate-spin"})," Omni renderingâ¦"]}):e.jsxs("button",{onClick:n,className:"w-full h-8 rounded-lg bg-primary text-primary-foreground text-[11px] font-bold uppercase tracking-wider inline-flex items-center justify-center gap-1.5 hover:bg-primary/90 transition-colors",children:[e.jsx(sr,{className:"h-3 w-3"})," ",a.status==="failed"?"Retry Omni":"Animate with Omni"]}):e.jsx("button",{disabled:!0,className:"w-full h-8 rounded-lg bg-white/[0.04] text-muted-foreground text-[11px] font-semibold inline-flex items-center justify-center gap-1.5 cursor-not-allowed",children:k?e.jsxs(e.Fragment,{children:[e.jsx(Be,{className:"h-3 w-3"})," Skipped"]}):e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"h-3 w-3"})," Recast first"]})}),a.status==="failed"&&a.error&&e.jsxs("div",{className:"mt-1.5 text-[10px] text-destructive flex items-start gap-1",children:[e.jsx(Be,{className:"h-3 w-3 mt-0.5 shrink-0"}),e.jsx("span",{className:"truncate",children:a.error})]})]}),e.jsx(It,{open:h,onOpenChange:$,children:e.jsxs(Tt,{className:"max-w-3xl bg-black border-white/10 p-2",children:[e.jsx($t,{className:"sr-only",children:"Storyboard shot preview"}),a.videoUrl&&e.jsx("video",{src:a.videoUrl,controls:!0,autoPlay:!0,className:"w-full max-h-[85vh] rounded-lg"})]})})]})}const X="https://uemglyheqrjfpanjsjkh.supabase.co/storage/v1/object/public/ai-faces",Z="?v=3",ye=[{id:"young-professional",name:"Alex",description:"Friendly creator",imageUrl:`${X}/male-actor-1.jpg${Z}`,category:"male"},{id:"executive",name:"Richard",description:"Distinguished pro",imageUrl:`${X}/male-actor-2.jpg${Z}`,category:"male"},{id:"asian-professional",name:"Kevin",description:"Cafe vibes",imageUrl:`${X}/male-actor-3.jpg${Z}`,category:"male"},{id:"rugged-actor",name:"Jake",description:"Rugged outdoorsman",imageUrl:`${X}/male-actor-4.jpg${Z}`,category:"male"},{id:"latino-college",name:"Diego",description:"College energy",imageUrl:`${X}/male-actor-5.jpg${Z}`,category:"male"},{id:"office-creator",name:"Marcus",description:"Studio host",imageUrl:`${X}/male-actor-6.jpg${Z}`,category:"male"},{id:"athletic-creator",name:"Tyler",description:"Fitness creator",imageUrl:`${X}/male-actor-7.jpg${Z}`,category:"male"},{id:"dad-energy",name:"David",description:"Trusted dad",imageUrl:`${X}/male-actor-8.jpg${Z}`,category:"male"},{id:"blonde-model",name:"Sarah",description:"Soft blonde",imageUrl:`${X}/female-actor-1.jpg${Z}`,category:"female"},{id:"elegant-brunette",name:"Maria",description:"Elegant brunette",imageUrl:`${X}/female-actor-2.jpg${Z}`,category:"female"},{id:"natural-beauty",name:"Destiny",description:"Bright smile",imageUrl:`${X}/female-actor-3.jpg${Z}`,category:"female"},{id:"redhead-model",name:"Emma",description:"Freckled ginger",imageUrl:`${X}/female-actor-4.jpg${Z}`,category:"female"}
6,{id:"latina-lifestyle",name:"Camila",description:"Warm lifestyle",imageUrl:`${X}/female-actor-5.jpg${Z}`,category:"female"},{id:"minimalist-creator",name:"Yuna",description:"Glass-skin minimal",imageUrl:`${X}/female-actor-6.jpg${Z}`,category:"female"},{id:"south-asian-lifestyle",name:"Priya",description:"Kitchen lifestyle",imageUrl:`${X}/female-actor-7.jpg${Z}`,category:"female"},{id:"mom-creator",name:"Jessica",description:"Confident mom",imageUrl:`${X}/female-actor-8.jpg${Z}`,category:"female"}];function Rr({selectedId:t,onSelect:r}){const[s,a]=l.useState(!1),[n,c]=l.useState("all"),o=n==="all"?ye:ye.filter(m=>m.category===n),i=ye.find(m=>m.id===t)??null,x=ye.slice(0,3);return e.jsxs(It,{open:s,onOpenChange:a,children:[e.jsx(nr,{asChild:!0,children:e.jsx("button",{type:"button",className:ee("group w-full text-left rounded-lg border bg-white/[0.02] p-2.5 transition-all flex items-center gap-3",i?"border-primary/40":"border-white/[0.06] hover:border-primary/30"),children:i?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"relative w-12 h-12 rounded-lg overflow-hidden border border-primary/60 shrink-0",children:e.jsx("img",{src:i.imageUrl,alt:i.name,className:"w-full h-full object-cover"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-bold tracking-tight leading-none truncate",children:i.name}),e.jsx("div",{className:"text-[10px] text-primary/80 font-mono uppercase tracking-widest mt-1",children:"Selected"})]}),e.jsx(xe,{className:"h-3.5 w-3.5 text-muted-foreground group-hover:translate-x-0.5 transition-transform shrink-0"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex -space-x-2 shrink-0",children:[x.map(m=>e.jsx("div",{className:"w-8 h-8 rounded-full overflow-hidden border-2 border-[#0b
60a09]",children:e.jsx("img",{src:m.imageUrl,alt:m.name,className:"w-full h-full object-cover",loading:"lazy"})},m.id)),e.jsxs("div",{className:"w-8 h-8 rounded-full border-2 border-[#0b0a09] bg-primary text-primary-foreground text-[9px] font-black flex items-center justify-center",children:["+",ye.length-x.length]})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-bold tracking-tight leading-none whitespace-nowrap",children:"Choose avatar"}),e.jsxs("div",{className:"text-[10px] text-muted-foreground mt-1 flex items-center gap-1",children:[e.jsx(ir,{className:"h-2.5 w-2.5"}),ye.length," creators"]})]}),e.jsx(xe,{className:"h-3.5 w-3.5 text-primary group-hover:translate-x-0.5 transition-transform shrink-0"})]})})}),e.jsxs(Tt,{className:"max-w-3xl bg-[#0b0a09]/95 backdrop-blur-2xl border-white/[0.06] p-0 overflow-hidden",children:[e.jsx(or,{className:"px-7 pt-7 pb-4 border-b border-white/[0.06]",children:e.jsxs("div",{className:"flex items-end justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.25em] text-primary mb-1.5",children:"Avatar Library"}),e.jsxs($t,{className:"text-3xl font-display font-black tracking-tight",children:["Pick your ",e.jsx("span",{className:"text-primary",children:"UGC creator"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:[o.length," hyper-real avatars · click to select"]})]}),e.jsx("div",{className:"flex gap-1 text-[10px] font-mono shrink-0",children:["all","female","male"].map(m=>e.jsx("button",{onClick:()=>c(m),className:ee("px-3 py-1.5 rounded-md uppercase tracking-widest transition-colors",n===m?"bg-primary text-primary-foreground":"bg-white/[0.04] text-muted-foreground hover:text-foreground"),children:m},m))})]})}),e.jsx("div",{className:"px-7 py-6 max-h-[65vh] overflow-y-auto",children:e.jsx("div",{className:"grid grid-cols-4 gap-3",children:o.map(m=>{const j=t===m.id;return e.jsxs(R.button,{type:"button",whileTap:{scale:.96},onClick:()=>{r(m),a(!1)},className:ee("relative aspect-square rounded-2xl overflow-hidden border-2 transition-all group",j?"border-primary shadow-[0_0_30px_-5px_hsl(var(--primary)/0.7)]":"border-white/[0.06] hover:border-primary/40"),title:m.name,children:[e.jsx("img",{src:m.imageUrl,alt:m.name,className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-500",loading:"lazy"}),e.jsx("div",{className:"absolute inset-x-0 bottom-0 px-2.5 py-2 bg-gradient-to-t from-black/90 via-black/40 to-transparent",children:e.jsx("div",{className:"text-xs font-bold text-white truncate text-left",children:m.name})}),j&&e.jsx("div",{className:"absolute top-2 right-2 w-6 h-6 rounded-full bg-primary text-primary-foreground flex items-center justify-center shadow-lg",children:e.jsx(pe,{className:"h-3.5 w-3.5",strokeWidth:3})})]},m.id)})})})]})]})}const xt=.12;async function Dr(t,r){const s=await new Promise((b,k)=>{const h=new Image;h.crossOrigin="anonymous",h.onload=()=>b(h),h.onerror=()=>k(new Error("Could not load frame")),h.src=t}),a=s.naturalWidth,n=s.naturalHeight;let c=0,o=0,i=a,x=n;if(r){const b=r.w*xt,k=r.h*xt,h=Math.max(0,r.x-b),$=Math.max(0,r.y-k),S=Math.min(1-h,r.w+b*2),f=Math.min(1-$,r.h+k*2);c=Math.round(h*a),o=Math.round($*n),i=Math.round(S*a),x=Math.round(f*n)}const m=document.createElement("canvas");m.width=i,m.height=x;const j=m.getContext("2d");if(!j)throw new Error("Canvas unavailable");return j.drawImage(s,c,o,i,x,0,0,i,x),await new Promise((b,k)=>{m.toBlob(h=>h?b(h):k(new Error("Crop failed")),"image/jpeg",.92)})}function Fr({imageUrl:t,productName:r,onChange:s,adSuggestion:a}){const{user:n}=lr(),c=l.useRef(null),[o,i]=l.useState(!1),[x,m]=l.useState(!1),[j,b]=l.useState(null),k=!!a&&a.sources.length>0,h=async(d,u="jpg")=>{if(!n)throw new Error("Not signed in");const g=`${n.id}/ad-decoder/${Date.now()}-${crypto.randomUUID().slice(0,6)}.${u}`,{error:y}=await D.storage.from("product-images").upload(g,d,{contentType:d.type||"image/jpeg",upsert:!1});if(y)throw y;return D.storage.from("product-images").getPublicUrl(g).data.publicUrl},$=async d=>{if(!n){C.error("Please sign in first");return}if(!d.type.startsWith("image/")){C.error("Please upload an image");return}if(d.size>15*1024*1024){C.error("Image must be under 15 MB");return}i(!0);try{const u=d.name.split(".").pop()||"jpg",g=await h(d,u);s(g,r||d.name.replace(/\.[^.]+$/,"")),C.success("Product image uploaded")}catch(u){console.error("[ProductPicker] upload failed",u),C.error("Upload failed")}finally{i(!1)}},S=async()=>
6{if(!(!a||!n)){m(!0),b("cropping");try{let d=null,u=null;for(const E of a.sources)try{const B=await Dr(E.url,E.region);d=await h(B,"jpg");break}catch(B){u=B,console.warn("[ProductPicker] source failed, trying next",B)}if(!d)throw u||new Error("All frames failed to load");const g=r||a.name||"Product from ad";b("cleaning"),C.message("ECOMBOS AGENT is workingâ¦",{description:"Isolating your product on a clean white background"});const{data:y,error:I}=await D.functions.invoke("ad-decoder-packshot",{body:{imageUrl:d,productName:g}});if(I||!(y!=null&&y.imageUrl)){console.warn("[ProductPicker] packshot failed, falling back to raw crop",I,y==null?void 0:y.error),s(d,g),C.warning("Used raw crop â couldn't generate the clean packshot. You can re-upload manually.");return}s(y.imageUrl,g),C.success("Clean packshot ready")}catch(d){console.error("[ProductPicker] pick-from-ad failed",d);const u=d instanceof Error?d.message:"Couldn't pull product from ad";C.error(u)}finally{m(!1),b(null)}}},f=o||x;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex gap-2.5",children:[e.jsx("button",{type:"button",onClick:()=>{var d;return(d=c.current)==null?void 0:d.click()},disabled:f,className:ee("relative shrink-0 w-20 h-20 rounded-lg overflow-hidden border transition-all flex items-center justify-center",t?"border-primary/60 shadow-[0_0_18px_-2px_hsl(var(--primary)/0.5)]":"border-white/10 hover:border-primary/40 bg-white/[0.02]"),children:t?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:t,alt:"Product",className:"w-full h-full object-cover"}),e.jsx("div",{className:"absolute top-1 right-1 w-5 h-5 rounded-full bg-primary text-primary-foreground flex items-center justify-center",children:e.jsx(pe,{className:"h-3 w-3"})})]}):o?e.jsx(ie,{className:"h-5 w-5 animate-spin text-primary"}):e.jsxs("div",{className:"flex flex-col items-center text-center px-1",children:[e.jsx(At,{className:"h-4 w-4 text-muted-foreground mb-0.5"}),e.jsx("div",{className:"text-[9px] font-semibold text-foreground leading-tight",children:"Upload"})]})}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-1.5",children:[e.jsx("input",{type:"text",placeholder:"Product name",value:r,onChange:d=>s(t,d.target.value),className:"h-8 px-2.5 rounded-md bg-white/[0.02] border border-white/10 text-xs placeholder:text-muted-foreground/60 focus:outline-none focus:border-primary/50"}),e.jsxs("button",{type:"button",onClick:()=>{var d;return(d=c.current)==null?void 0:d.click()},disabled:f,className:"h-8 px-2 rounded-md bg-white/[0.04] border border-white/10 text-[11px] font-semibold text-foreground hover:border-white/20 transition-colors inline-flex items-center justify-center gap-1.5 disabled:opacity-50",children:[e.jsx(cr,{className:"h-3 w-3"}),t?"Replace":"Upload image"]}),e.jsx("p",{className:"text-[9px] text-muted-foreground leading-tight",children:"PNG / JPG · clean packshot"})]})]}),k&&e.jsxs("div",{className:"mt-2.5 rounded-lg border border-primary/25 bg-primary/[0.05] p-2 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[9px] font-mono uppercase tracking-[0.2em] text-primary",children:[e.jsx(ue,{className:"h-3 w-3"}),"Detected in this ad",a.name?` · ${a.name}`:""]}),e.jsx("button",{type:"button",disabled:f,onClick:S,className:"w-full h-9 rounded-md border border-primary/40 bg-primary text-primary-foreground hover:bg-primary/90 transition-colors text-[10px] font-black uppercase tracking-wider inline-flex items-center justify-center gap-1.5 disabled:opacity-50",children:x?e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"h-3 w-3 animate-spin"})," ",j==="cleaning"?"Generating packshotâ¦":"Croppingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(Me,{className:"h-3 w-3"})," Use product from ad"]})}),e.jsx("p",{className:"text-[9px] text-muted-foreground leading-tight text-center",children:"Crops the product from the ad and ECOMBOS AGENT drops it on a clean white background."})]}),e.jsx("input",{ref:c,type:"file",accept:"image/*",className:"hidden",onChange:d=>{var g;const u=(g=d.target.files)==null?void 0:g[0];u&&$(u),d.target.value=""}})]})}function Lr({formatType:t="ugc_human",avatar:r,productUrl:s,productName:a,onAvatarChange:n,onProductChange:c,onEditScript:o,scriptEditCount:i=0,adProductSuggestion:x}){const m=t==="ugc_human",[j,b]=l.useState(!1),k=m||j||!!r;return e.jsxs(R.section,{initial:{opacity:0,x:8}
6,animate:{opacity:1,x:0},className:"relative rounded-2xl border border-white/[0.07] bg-gradient-to-b from-primary/[0.06] via-white/[0.015] to-transparent backdrop-blur-xl flex flex-col",children:[e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-primary/10 border border-primary/30 flex items-center justify-center shrink-0",children:e.jsx(Me,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.3em] text-primary leading-none mb-1.5",children:".02 · Cast"}),e.jsx("h2",{className:"text-base font-display font-black uppercase tracking-tight leading-none",children:"Your talent + product"})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:"Pick the on-screen person and product. We'll lock both into the Omni render below â no intermediate image regeneration step."}),o&&e.jsx("button",{onClick:o,className:"mt-3 w-full h-8 rounded-md border border-primary/30 bg-primary/[0.08] hover:bg-primary/[0.14] transition-colors text-[10px] font-mono uppercase tracking-[0.2em] text-primary flex items-center justify-center gap-1.5",children:i>0?e.jsxs(e.Fragment,{children:["Script edited · ",e.jsxs("span",{className:"font-bold",children:[i," shot",i>1?"s":""]})]}):e.jsx(e.Fragment,{children:"Edit script & shots"})})]}),e.jsxs("div",{className:"p-3 pt-0 space-y-3 flex-1 min-h-0",children:[!m&&e.jsxs("div",{className:"px-2.5 py-2 rounded-md border border-primary/30 bg-primary/[0.06] text-[10px] font-mono uppercase tracking-[0.15em] text-primary flex items-center justify-between gap-2 flex-wrap",children:[e.jsx("span",{children:t==="unboxing_hands"?"Detected: Unboxing · hands + product only":"Detected: Product-only ad · no creator needed"}),!k&&e.jsxs("button",{type:"button",onClick:()=>b(!0),className:"inline-flex items-center gap-1 px-2 py-1 rounded-sm bg-primary/15 hover:bg-primary/25 text-primary normal-case tracking-normal font-sans text-[10px] font-semibold",children:[e.jsx(_t,{className:"w-3 h-3"})," Add a creator anyway"]})]}),e.jsx(ht,{step:"A",title:"Your product",icon:e.jsx(Je,{className:"w-3 h-3"}),ready:!!s,children:e.jsx(Fr,{imageUrl:s,productName:a,onChange:(h,$)=>c(h,$),adSuggestion:x})}),k&&e.jsxs(ht,{step:"B",title:"The creator",icon:e.jsx($r,{className:"w-3 h-3"}),ready:!!r,children:[e.jsx(Rr,{selectedId:(r==null?void 0:r.id)??null,onSelect:n}),!m&&e.jsx("button",{type:"button",onClick:()=>{n(null),b(!1)},className:"mt-2 text-[10px] font-mono uppercase tracking-[0.2em] text-muted-foreground hover:text-primary transition-colors",children:"Remove creator"})]})]})]})}function ht({step:t,title:r,icon:s,ready:a,children:n}){return e.jsxs("div",{className:ee("relative rounded-lg border bg-white/[0.015] p-2.5 transition-all",a?"border-primary/30":"border-white/[0.06]"),children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:ee("w-4 h-4 rounded border flex items-center justify-center",a?"bg-primary/15 border-primary/40 text-primary":"bg-white/[0.03] border-white/[0.08] text-muted-foreground"),children:s}),e.jsxs("div",{className:"text-[9px] font-mono uppercase tracking-[0.25em] text-muted-foreground",children:[t," · ",e.jsx("span",{className:"text-foreground font-bold",children:r})]})]}),a&&e.jsx("div",{className:"w-4 h-4 rounded-full bg-primary text-primary-foreground flex items-center justify-center",children:e.jsx(pe,{className:"w-2.5 h-2.5",strokeWidth:3})})]}),n]})}function Hr({open:t,onOpenChange:r,storyboard:s,scriptFull:a,transcriptFailed:n,onSave:c,persistKey:o}){const i=(a||"").split(/(?:\s*[.!?]\s+|\n+)/).map(f=>f.trim()).filter(f=>f.length>2),x=f=>n&&(i[f]||i[0])||"",m=(f,d)=>{const u={...f,...d??{}},g=(y,I)=>String(y??"").trim()||I;return{...u,camera:g(u.camera,"Handheld vertical UGC shot matched to the reference frame"),lens:g(u.lens,"Mobile social-video lens, natural perspective, platform-compressed 9:16 look"),composition:g(u.composition,"Recreate the reference frame exactly: subject placement, product position, crop, movement, and blocking."),wardrobe:g(u.wardrobe,"Match the visible wardrobe/accessories from the reference frame exactly."),setting:g(u.setting,"Match the visible location, surfaces, props, and background from the reference frame."),lighting:g(u.lighting,"Match the visible source lighting, color temperature, shadow softness, and exposure."),sfx:g(u.sfx,"Match the original ad audio bed; no extra sound effects unless visible in this shot."),vo_line:String(u.vo_line??""),on_screen_text:String(u.on_screen_text||f.on_screen_text||x(f.shot_index??0)||"")}},j=()=>
6{if(o)try{const f=localStorage.getItem(o);if(f){const d=JSON.parse(f);if(Array.isArray(d)&&d.length===s.length)return s.map((u,g)=>m(u,d[g]))}}catch{}return s.map(f=>m(f))},[b,k]=l.useState(j);l.useEffect(()=>{k(j())},[s]);const h=(f,d)=>{k(u=>u.map((g,y)=>y===f?{...g,...d}:g))},$=()=>{if(c(b),o)try{localStorage.setItem(o,JSON.stringify(b))}catch{}C.success("Script saved â next Recast will use your edits"),r(!1)},S=()=>{if(k(s.map(f=>m(f))),o)try{localStorage.removeItem(o)}catch{}C.message("Reverted to original script")};return e.jsx(Rt,{open:t,onOpenChange:r,children:e.jsxs(Dt,{side:"right",className:"z-[1000] w-full sm:max-w-[min(980px,calc(100vw-24px))] h-dvh overflow-y-auto bg-background border-l border-white/[0.08] p-0",children:[e.jsxs(Ft,{className:"sticky top-0 z-10 bg-background/95 backdrop-blur px-6 pt-6 pb-4 border-b border-white/[0.06]",children:[e.jsx(Lt,{className:"font-display text-xl uppercase tracking-tight",children:"Edit script & shots"}),e.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:"Tweak every shot before you Recast. Each field feeds the image model â the more specific you are, the more realistic the frame."})]}),n&&e.jsxs("div",{className:"mx-6 mt-4 p-3 rounded-lg border border-amber-500/30 bg-amber-500/[0.06] text-amber-200",children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.25em] mb-1",children:"â Transcript unavailable"}),e.jsxs("p",{className:"text-xs leading-snug",children:["We couldn't extract spoken audio for this ad. Voiceover stays empty unless real speech is detected; review each shot's ",e.jsx("strong",{children:"On-screen text"}
6)," because that is what gets burned into the frame."]})]}),a&&e.jsxs("div",{className:"mx-6 mt-4 p-3 rounded-lg border border-white/[0.06] bg-white/[0.02]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2 text-[10px] font-mono uppercase tracking-[0.25em] text-primary",children:[e.jsx(Ae,{className:"w-3 h-3"})," Full transcript"]}),e.jsx("p",{className:"text-xs text-foreground/85 leading-relaxed whitespace-pre-wrap max-h-32 overflow-y-auto",children:a})]}),e.jsx("div",{className:"mt-4 space-y-4 px-6",children:b.map((f,d)=>e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.015] p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"text-[10px] font-mono uppercase tracking-[0.25em] text-primary",children:["Shot ",d+1," ",e.jsxs("span",{className:"text-muted-foreground",children:["· ",f.duration_s??"?","s"]})]}),f.reference_frame_url&&e.jsx("img",{src:f.reference_frame_url,alt:"",className:"w-10 h-14 object-cover rounded border border-white/10"})]}),e.jsx(me,{icon:e.jsx(Ae,{className:"w-3 h-3"}),label:"Voiceover line",children:e.jsx(dt,{value:f.vo_line||"",onChange:u=>h(d,{vo_line:u.target.value}),rows:2,className:"text-xs",placeholder:"What the actor says in this shot"})}),e.jsx(me,{icon:e.jsx(Ht,{className:"w-3 h-3"}),label:"On-screen text",children:e.jsx(be,{value:f.on_screen_text||"",onChange:u=>h(d,{on_screen_text:u.target.value}),className:"text-xs h-9",placeholder:"Caption that burns into the frame"})}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-2",children:[e.jsx(me,{icon:e.jsx(ct,{className:"w-3 h-3"}),label:"Camera",children:e.jsx(be,{value:f.camera||"",onChange:u=>h(d,{camera:u.target.value}),className:"text-xs h-9",placeholder:"e.g. handheld close-up"})}),e.jsx(me,{icon:e.jsx(ve,{className:"w-3 h-3"}),label:"Lens / look",children:e.jsx(be,{value:f.lens||"",onChange:u=>h(d,{lens:u.target.value}),className:"text-xs h-9",placeholder:"35mm f/2.0, shallow DOF"})}),e.jsx(me,{icon:e.jsx(vr,{className:"w-3 h-3"}),label:"Wardrobe",children:e.jsx(be,{value:f.wardrobe||"",onChange:u=>h(d,{wardrobe:u.target.value}),className:"text-xs h-9",placeholder:"cream knit, gold hoops"})}),e.jsx(me,{icon:e.jsx(wr,{className:"w-3 h-3"}),label:"Setting",children:e.jsx(be,{value:f.setting||"",onChange:u=>h(d,{setting:u.target.value}),className:"text-xs h-9",placeholder:"sunlit kitchen, marble counter"})})]}),e.jsx(me,{icon:e.jsx(Ye,{className:"w-3 h-3"}),label:"Lighting",children:e.jsx(be,{value:f.lighting||"",onChange:u=>h(d,{lighting:u.target.value}),className:"text-xs h-9",placeholder:"soft window light from camera-left, warm 5600K"})}),e.jsx(me,{icon:e.jsx(ct,{className:"w-3 h-3"}),label:"Composition & blocking",children:e.jsx(dt,{value:f.composition||"",onChange:u=>h(d,{composition:u.target.value}),rows:2,className:"text-xs"})})]},d))}),e.jsxs("div",{className:"sticky bottom-0 mt-6 px-6 py-3 bg-background/95 backdrop-blur border-t border-white/[0.08] flex items-center justify-between gap-2",children:[e.jsxs(je,{variant:"ghost",size:"sm",onClick:S,className:"text-xs",children:[e.jsx(Ut,{className:"w-3.5 h-3.5 mr-1.5"})," Reset"]}),e.jsxs(je,{size:"sm",onClick:$,className:"text-xs font-bold uppercase tracking-wider",children:[e.jsx(Nr,{className:"w-3.5 h-3.5 mr-1.5"})," Save edits"]})]})]})})}function me({icon:t,label:r,children:s}){return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1 text-[9px] font-mono uppercase tracking-[0.25em] text-muted-foreground",children:[t," ",r]}),s]})}function gt(t){const r=t.toLowerCase();return r.includes("face")||r.includes("hand")?{stroke:"rgba(255,180,40,0.95)",fill:"rgba(255,180,40,0.18)"}:r.includes("product")?{stroke:"hsl(var(--primary))",fill:"hsl(var(--primary) / 0.22)"}:r.includes("cta")||r.includes("text")?{stroke:"rgba(255,80,140,0.95)",fill:"rgba(255,80,140,0.18)"}:{stroke:"rgba(255,255,255,0.85)",fill:"rgba(255,255,255,0.12)"}}function Br({frames:t,attention:r}){const s=r.filter(i=>i.regions.length>0&&t[i.frame_index]),[a,n]=l.useState(0);if(s.length===0)return null;const c=s[Math.min(a,s.length-1)],o=t[c.frame_index];return e.jsxs("div",{className:"rounded-2xl border border-white/[0.06] bg-white/[0.02] p-5 backdrop-blur",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-primary/15 border border-primary/30 flex items-center justify-center",children:e.jsx(Xe,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.3em] text-primary leading-none mb-1",children:"Attention Map"}),e.jsx("h3",{className:"text-sm font-bold uppercase tracking-wider leading-none",children:"Where the eye actually lands"})]})]}),e.jsx("div",{className:"flex items-center gap-1",children:s.map((i,x)=>e.jsx("button",{onClick:()=>n(x),className:`w-6 h-6 rounded text-[10px] font-mono font-bold transition-colors ${x===a?"bg-primary text-primary-foreground":"bg-white/[0.04] text-muted-foreground hover:text-foreground"}`,"aria-label":`Frame ${x+1}`,children:x+1},x))})]}),e.jsxs("div",{className:"grid sm:grid-cols-[1fr_180px] gap-4 items-start",children:[e.jsxs("div",{className:"relative w-full aspect-square rounded-xl overflow-hidden border border-white/[0.08] bg-black",children:[e.jsx("img",{src:o,alt:`Frame ${c.frame_index+1}`,className:"absolute inset-0 w-full h-full object-cover"}),e.jsx("svg",{viewBox:"0 0 100 100",preserveAspectRatio:"none",className:"absolute inset-0 w-full h-full",children:c.regions.map((i,x)=>{const m=gt(i.label),j=Math.max(0,Math.min(100,i.x*100)),b=Math.max(0,Math.min(100,i.y*100)),k=Math.max(0,Math.min(100-j,i.w*100)),h=Math.max(0,Math.min(100-b,i.h*100));return e.jsx("g",{children:e.jsx("rect",{x:j,y:b,width:k,height:h,fill:m.fill,stroke:m.stroke,strokeWidth:.5,rx:1})},x)})})]}),e.jsxs("div",{className:"space-y-2",children:[c.note&&e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug border-b border-white/[0.06] pb-2",children:c.note}),c.regions.slice().sort((i,x)=>x.weight-i.weight).map((i,x)=>{const m=gt(i.label);return e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm shrink-0",style:{background:m.stroke}}
6),e.jsx("span",{className:"font-semibold text-foreground/90 flex-1 truncate",children:i.label}),e.jsxs("span",{className:"text-muted-foreground font-mono",children:[Math.round(i.weight*100),"%"]})]},x)})]})]})]})}function Gr(t){const r=Math.floor(t),s=Math.floor(r/60),a=r%60;return`${s}:${String(a).padStart(2,"0")}`}function zr({transcript:t,onSeek:r}){var o;const[s,a]=l.useState(!1),n=Array.isArray(t.segments)&&t.segments.length>0,c=t.text||(((o=t.segments)==null?void 0:o.map(i=>i.text).join(" "))??"");return c.trim()?e.jsxs("div",{className:"rounded-2xl border border-white/[0.06] bg-white/[0.02] backdrop-blur",children:[e.jsxs("button",{onClick:()=>a(i=>!i),className:"w-full flex items-center justify-between gap-3 p-4 text-left hover:bg-white/[0.02] transition-colors rounded-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-primary/15 border border-primary/30 flex items-center justify-center shrink-0",children:e.jsx(Ae,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.3em] text-primary leading-none mb-1",children:"Voiceover"}),e.jsxs("h3",{className:"text-sm font-bold uppercase tracking-wider leading-none truncate",children:["Transcript ",t.language?`· ${t.language.toUpperCase()}`:""]})]})]}),e.jsx(dr,{className:`h-4 w-4 text-muted-foreground transition-transform shrink-0 ${s?"rotate-180":""}`})]}),!s&&e.jsxs("p",{className:"px-4 pb-4 text-[11px] text-muted-foreground leading-snug line-clamp-2",children:['"',c.slice(0,220),c.length>220?"â¦":"",'"']}),s&&e.jsx("div",{className:"px-4 pb-4 space-y-1.5 max-h-[280px] overflow-y-auto",children:n?t.segments.map((i,x)=>e.jsxs("button",{onClick:()=>r==null?void 0:r(i.t),disabled:!r,className:"w-full text-left flex gap-3 px-2 py-1.5 rounded-md hover:bg-primary/[0.06] disabled:hover:bg-transparent group transition-colors",children:[e.jsx("span",{className:"text-[10px] font-mono text-primary/80 shrink-0 mt-0.5 w-10 group-hover:text-primary",children:Gr(i.t)}),e.jsx("span",{className:"text-[12px] text-foreground/90 leading-snug flex-1",children:i.text})]},x)):e.jsx("p",{className:"text-[12px] text-foreground/85 leading-relaxed whitespace-pre-wrap",children:c})})]}):null}const Vr=[{key:"visualCortex",label:"Visual Cortex"},{key:"auditoryCortex",label:"Auditory Cortex"},{key:"attentionControl",label:"Attention Control"},{key:"focusDrift",label:"Focus Drift"},{key:"languageNetwork",label:"Language Network"}],Wr=[{icon:Xe,label:"Product lock",detail:"subject saliency"},{icon:Gt,label:"Caption read",detail:"on-screen text"}
6,{icon:Et,label:"Pace map",detail:"cut rhythm"},{icon:ue,label:"Hook pull",detail:"pattern interrupt"}];function Yr({scores:t}){var a;const r={visualCortex:t.visualCortex,auditoryCortex:t.auditoryCortex,attentionControl:t.attentionControl,focusDrift:t.focusDrift,languageNetwork:t.languageNetwork},s=t.viralityScore>=70?"HIGH":t.viralityScore>=40?"MEDIUM":"LOW";return e.jsxs(R.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},className:"rounded-2xl border border-white/[0.06] bg-gradient-to-br from-white/[0.03] to-white/[0.01] p-5 backdrop-blur",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-primary/10 border border-primary/30 flex items-center justify-center",children:e.jsx(_r,{className:"h-3.5 w-3.5 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.3em] text-primary leading-none mb-1",children:"Neuro decode"}),e.jsx("h3",{className:"text-sm font-bold uppercase tracking-wider leading-none",children:"The brain on this ad"})]})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-2",children:[e.jsxs("div",{className:"flex-1 max-w-[60%]",children:[e.jsx("div",{className:"h-2 rounded-full bg-gradient-to-r from-primary via-orange-500 to-rose-600 relative",children:e.jsx(R.div,{className:"absolute -top-1 w-1 h-4 bg-white rounded-full shadow",initial:{left:"0%"},animate:{left:`${t.viralityScore}%`},transition:{duration:1,ease:[.22,1,.36,1]}})}),e.jsxs("div",{className:"flex items-center justify-between mt-1 text-[10px] font-mono uppercase tracking-[0.2em] text-muted-foreground",children:[e.jsx("span",{children:"Low"}),e.jsx("span",{className:s==="HIGH"?"text-primary":"",children:s}),e.jsx("span",{children:"High"})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.2em] text-muted-foreground",children:"Viral Potential"}),e.jsxs("div",{className:"font-display font-black text-3xl leading-none tabular-nums",children:[e.jsx("span",{className:"text-foreground",children:t.viralityScore}),e.jsx("span",{className:"text-muted-foreground",children:"/100"})]})]})]}),e.jsxs("div",{className:"relative h-[380px] -mx-2 overflow-hidden",children:[e.jsx(Bt,{scores:r,compact:!0,className:"w-full h-full"}),e.jsx(kr,{isAnalyzing:!1,hasResult:!0,scores:r}),e.jsx("div",{className:"absolute left-4 right-4 bottom-4 grid grid-cols-2 gap-2 sm:grid-cols-4",children:Wr.map((n,c)=>{const o=n.icon;return e.jsxs(R.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.08*c,duration:.35,ease:[.22,1,.36,1]},className:"rounded-lg border border-primary/15 bg-background/70 px-2.5 py-2 shadow-[0_16px_44px_-32px_hsl(var(--primary)/0.8)] backdrop-blur-md",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-primary",children:[e.jsx(o,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[9px] font-mono uppercase tracking-[0.18em]",children:n.label})]}),e.jsx("div",{className:"mt-1 text-[10px] leading-none text-muted-foreground",children:n.detail})]},n.label)})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 mt-3 pb-3 border-b border-white/[0.06]",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.2em] text-muted-foreground",children:"Hold Rate"}),e.jsxs("div",{className:"font-display font-bold text-xl mt-1 tabular-nums",children:[t.holdRate,"%"]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.2em] text-muted-foreground",children:"Focus Drift"}),e.jsx("div",{className:"font-display font-bold text-xl mt-1 tabular-nums",children:t.focusDrift})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.2em] text-muted-foreground",children:"Language"}),e.jsx("div",{className:"font-display font-bold text-xl mt-1 tabular-nums",children:t.languageNetwork})]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2 mt-3",children:Vr.map(n=>e.jsxs("div",{className:"rounded-lg border border-white/[0.06] bg-white/[0.02] px-2.5 py-2",children:[e.jsx("div",{className:"text-[9px] font-mono uppercase tracking-[0.18em] text-muted-foreground",children:n.label}),e.jsxs("div",{className:"mt-1 flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-bold tabular-nums",children:r[n.key]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"/100"})]}),e.jsx("div",{className:"mt-1 h-1 rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx(R.div,{className:"h-full bg-primary",initial:{width:0},animate:{width:`${r[n.key]}%`},transition:{duration:1,ease:[.22,1,.36,1]}})})]},n.key))}),t.verdict&&e.jsxs("div",{className:"mt-4 p-3 rounded-lg bg-primary/5 border border-primary/15 text-sm text-foreground flex items-start gap-2",children:[e.jsx(pe,{className:"w-3.5 h-3.5 mt-1 text-primary shrink-0"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-[0.2em] text-primary mr-2",children:"Verdict"}),t.verdict]})]}),((a=t.topFixes)==null?void 0:a.length)>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.2em] text-muted-foreground mb-2",children:"Top fixes to raise the score"}),e.jsx("ul",{className:"space-y-1.5",children:t.topFixes.map((n,c)=>
6e.jsxs("li",{className:"text-sm text-foreground/90 pl-4 relative",children:[e.jsx("span",{className:"absolute left-0 top-2 w-1.5 h-1.5 rounded-full bg-primary"}),n]},c))})]})]})}function qr({status:t,scenePlan:r,subclips:s,finalVideoUrl:a,error:n,ready:c,readyHint:o,segmentCount:i,costPerSegment:x,progress:m,onRun:j,onOpenStoryboard:b}){var w,_;const k=t==="planning"||t==="rendering"||t==="stitching",[h,$]=l.useState(4),[S,f]=l.useState(0),d=m.total||i||1;let u=-1;for(let U=0;U<d;U++)if(((w=s[U])==null?void 0:w.status)==="rendering"){u=U;break}const g=Math.round((m.done+(u>=0?S/100:0))/d*100),y=t==="planning"?h:t==="stitching"?Math.max(g,94):g,I=i>0,E=I?i*x:0,B=Array.from({length:d},(U,A)=>s[A]);return l.useEffect(()=>{if(t!=="planning"){$(4);return}const U=Date.now(),A=window.setInterval(()=>{const O=Date.now()-U;$(Math.min(88,Math.max(4,Math.round((1-Math.exp(-O/35e3))*90))))},700);return()=>window.clearInterval(A)},[t]),l.useEffect(()=>{if(t!=="rendering"||u<0){f(0);return}f(3);const U=Date.now(),A=window.setInterval(()=>{const O=Date.now()-U;f(Math.min(95,Math.round((1-Math.exp(-O/45e3))*100)))},700);return()=>window.clearInterval(A)},[t,u]),e.jsxs("div",{className:"mt-4 rounded-2xl border border-primary/30 bg-gradient-to-br from-primary/[0.08] via-white/[0.02] to-transparent p-5 backdrop-blur",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.3em] text-primary mb-1",children:".03 · Final cut"}),e.jsx("h3",{className:"text-base font-display font-black uppercase tracking-tight leading-none",children:"Render hero ad"}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1.5",children:i<=1?"One Omni clip from the original start frame.":`${i} chained Omni clips (each starts from the previous clip's last frame).`})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-widest text-muted-foreground",children:"Cost"}),e.jsx("div",{className:"text-lg font-black text-primary leading-none",children:I?`${E} cr`:"â¦"})]})]}),t==="idle"&&!a&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:j,disabled:!c||!I,className:"w-full h-12 rounded-xl bg-primary text-primary-foreground font-black text-xs uppercase tracking-[0.2em] flex items-center justify-center gap-2 hover:bg-primary/90 transition-colors disabled:opacity-40 disabled:cursor-not-allowed shadow-[0_0_30px_-6px_hsl(var(--primary)/0.6)]",children:[e.jsx(ve,{className:"w-4 h-4"}),c?I?`ð¬ Render hero ad · ${E} cr`:"Reading video durationâ¦":o||"Pick product & talent first",e.jsx(xe,{className:"w-4 h-4"})]}),!c&&o&&e.jsx("p",{className:"text-[10px] text-muted-foreground text-center mt-2",children:o})]}),k&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-lg bg-white/[0.04] border border-white/[0.08] p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-widest text-muted-foreground",children:t==="planning"?"Planning prompts + continuity locksâ¦":t==="stitching"?"Stitching final MP4â¦":u>=0?`Rendering clip ${u+1}/${d} · ${((_=s[u])==null?void 0:_.durationS)??"?"}s`:`Rendering ${m.done}/${d}`}),e.jsxs("span",{className:"text-[10px] font-mono text-primary font-bold",children:[y,"%"]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx(R.div,{className:"h-full bg-primary",animate:{width:`${y}%`},transition:{duration:.4}})})]}),e.jsx("div",{className:"flex gap-1.5 flex-wrap",children:B.map((U,A)=>{const O=U??{status:"pending",durationS:void 0,error:null};return e.jsxs("div",{className:`flex-1 min-w-[60px] h-9 rounded-md border text-[9px] font-mono uppercase tracking-widest flex items-center justify-center gap-1 ${O.status==="done"?"border-primary/60 bg-primary/15 text-primary":O.status==="rendering"?"border-primary/40 bg-primary/[0.06] text-foreground":O.status==="failed"?"border-red-500/40 bg-red-500/10 text-red-300":"border-white/[0.08] bg-white/[0.02] text-muted-foreground"}`,title:O.error||void 0,children:[O.status==="rendering"&&e.jsx(ie,{className:"w-2.5 h-2.5 animate-spin"}),O.status==="done"&&e.jsx(pe,{className:"w-2.5 h-2.5"}),O.status==="failed"&&e.jsx(St,{className:"w-2.5 h-2.5"}),e.jsxs("span",{children:["#",A+1,O.durationS?` · ${O.durationS}s`:""]})]},A)})}),e.jsx("p",{className:"text-[10px] text-muted-foreground text-center italic",children:d===1?"Single Omni render â usually ~1-2 min.":"Each clip starts from the previous clip's last frame for perfect continuity."})]}),e.jsx(we,{children:t==="done"&&a&&e.jsxs(R.div,{initial:{opacity:0,y:8}
6,animate:{opacity:1,y:0},className:"space-y-3",children:[e.jsx("div",{className:"rounded-xl overflow-hidden border border-primary/40 bg-black shadow-[0_0_40px_-10px_hsl(var(--primary)/0.4)]",children:e.jsx("video",{src:a,controls:!0,playsInline:!0,className:"w-full h-auto max-h-[60vh] object-contain"})}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"text-[10px] font-mono uppercase tracking-widest text-primary flex items-center gap-1.5",children:[e.jsx(ue,{className:"w-3 h-3"})," Saved to Assets"]}),e.jsxs("a",{href:a,download:"ad-decoder-hero.mp4",className:"inline-flex items-center gap-1.5 h-9 px-3 rounded-lg bg-primary text-primary-foreground text-[10px] font-black uppercase tracking-widest hover:bg-primary/90 transition-colors",children:[e.jsx(Ot,{className:"w-3 h-3"})," Download"]})]}),e.jsxs("button",{onClick:j,disabled:!c,className:"w-full h-10 rounded-lg border border-white/[0.08] bg-white/[0.02] text-xs font-bold uppercase tracking-wider text-muted-foreground hover:text-foreground hover:border-white/[0.14] transition-colors disabled:opacity-40",children:["Re-render (",E," cr)"]})]})}),t==="failed"&&e.jsxs("div",{className:"rounded-lg border border-red-500/30 bg-red-500/[0.06] p-3 mb-3",children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-widest text-red-300 mb-1",children:"Render failed"}),e.jsx("p",{className:"text-xs text-red-200/90",children:n||"Something went wrong."}),e.jsx("button",{onClick:j,disabled:!c,className:"mt-2 h-9 px-3 rounded-lg bg-primary text-primary-foreground text-[10px] font-black uppercase tracking-widest hover:bg-primary/90 disabled:opacity-40",children:"Retry"})]}),e.jsxs("button",{onClick:b,className:"mt-3 w-full h-9 rounded-lg border border-white/[0.06] bg-white/[0.02] text-[10px] font-mono uppercase tracking-widest text-muted-foreground hover:text-foreground hover:border-white/[0.14] transition-colors flex items-center justify-center gap-1.5",children:[e.jsx(ve,{className:"w-3 h-3"})," Inspect original storyboard"]})]})}const Kr={low:4,medium:8,high:14};function Ee(t){const r=t.reduce((a,n)=>{const c=Kr[n.impact]??6,o=typeof n.confidence=="number"?Math.max(0,Math.min(100,n.confidence))/100:.7;return a+c*o},0),s=r<=25?r:25+(r-25)*.4;return Math.min(40,Math.round(s))}function Pe(t,r){return Math.max(0,Math.min(100,Math.round(t+r)))}function ze(t,r,s){if(!t.length)return[];const a=o=>{const i=o.impact==="high"?14:o.impact==="medium"?8:4,x=typeof o.confidence=="number"?Math.max(0,Math.min(100,o.confidence))/100:.7;return i*x},n=t.map((o,i)=>({i,score:a(o)})).sort((o,i)=>i.score-o.score).map(o=>o.i),c=[];for(const o of n){c.push(o);const i=Ee(c.map(x=>t[x]));if(Pe(r,i)>=s)return c}return c}const Jr=3e3,Xr=200,ft=t=>t.image_url!=null||t.error!=null||t.status==="done"||t.status==="failed";function Zr(t){const[r,s]=l.useState("idle"),[a,n]=l.useState([]),[c,o]=l.useState(null),i=l.useRef(null),x=l.useRef(new Set),m=l.useCallback(()=>{i.current&&(clearInterval(i.current),i.current=null)},[]),j=l.useCallback(()=>{m(),s("idle"),n([]),o(null)},[m]);l.useEffect(()=>()=>m(),[m]),l.useEffect(()=>{if(!t)return;let h=!1;return(async()=>{const{data:$}=await D.from("ad_teardowns").select("recast_frames").eq("id",t).maybeSingle();if(h)return;const S=($==null?void 0:$.recast_frames)||[];if(!S.length)return;n(S.map(({shot_index:u,image_url:g,error:y})=>({shot_index:u,image_url:g,error:y})));const f=S.every(ft),d=S.filter(u=>u.image_url).length;f&&s(d>0?"done":"failed")})(),()=>{h=!0}},[t]);const b=l.useCallback((h,$)=>{m();let S=0,f=[];const d=D.auth.getUser().then(({data:g})=>{var y;return((y=g.user)==null?void 0:y.id)??null}).catch(()=>null),u=async()=>{if(S++,S>Xr){m();const w=f.filter(_=>_.image_url).length;if(w>0)s("done"),o(`Recast timed out with ${w}/${$} shots ready.`),C.warning(`Recast timed out â ${w}/${$} shots finished.`);else{const _="Recast is taking longer than 10 minutes, so we stopped watching. Reload the page to pick up any shots that finish.";s("failed"),o(_),C.error(_)}return}const{data:g,error:y}=await D.from("ad_teardowns").select("recast_frames").eq("id",h).single();if(y)return;const I=(g==null?void 0:g.recast_frames)||[];if(!I.length)return;f=I,n(I.map(({shot_index:w,image_url:_,error:U})=>({shot_index:w,image_url:_,error:U})));const E=await d;if(E)for(const w of I)w.image_url&&!x.current.has(w.shot_index)&&(x.current.add(w.shot_index),Ze({userId:E,name:`Ad Decoder · Recast shot ${w.shot_index+1}`,content:w.image_url,type:"ad",tags:["ad-decoder","recast"],metadata:{teardownId:h,shot_index:w.shot_index,source:"ad-decoder-recast"}}));if(I.filter(ft).length>=$){m();const w=I.filter(_=>_.image_url).length;w===0?(s("failed"),o("All shots failed to regenerate. Credits refunded."),C.error("Recast failed. Credits refunded.")):(s("done"),C.success(`Recast ${w}/${$} shots`))}};i.current=window.setInterval(u,Jr),u()},[m]),k=l.useCallback(async h=>{var $,S,f;s("running"),o(null),n([]);try{const{data:d,error:u}=await D.functions.invoke("ad-decoder-recast",{body:h});if(u){const y=(($=u.context)==null?void 0:$.error)||u.message||"Recast failed";throw new Error(y)}(S=d==null?void 0:d.recastFrames)!=null&&S.length&&n(d.recastFrames);
6const g=(d==null?void 0:d.totalShots)||((f=d==null?void 0:d.recastFrames)==null?void 0:f.length)||0;if(!g)throw new Error("No shots returned");b(h.teardownId,g)}catch(d){const u=d instanceof Error?d.message:"Recast failed";o(u),s("failed"),C.error(u)}},[b]);return{status:r,frames:a,error:c,run:k,reset:j}}const Qr="ad-decoder-omni-video",ea=6e3,ta=90,bt={status:"idle",videoUrl:null,error:null,attempts:0};async function ra(t){const{data:r,error:s}=await D.from("ad_teardowns").select("recast_prepaid_count").eq("id",t).maybeSingle();if(s||typeof(r==null?void 0:r.recast_prepaid_count)!="number")return;const a=r.recast_prepaid_count,{error:n}=await D.from("ad_teardowns").update({recast_prepaid_count:a+1}).eq("id",t).eq("recast_prepaid_count",a);n&&console.error("[useShotAnimate] prepaid slot restore failed",t,n)}function aa(){const{deductCredits:t,refundCredits:r,balance:s}=Pt(),[a,n]=l.useState({}),c=l.useCallback((m,j)=>{n(b=>({...b,[m]:{...b[m]??bt,...j}}))},[]),o=l.useCallback(async m=>{const{shotIndex:j,startingFrameUrl:b,prompt:k,durationS:h,teardownId:$}=m;c(j,{status:"generating",videoUrl:null,error:null,attempts:0});const S=!!$;let f=null;if(!S){const y=await t(Qr);if(!y.success){const I=y.error==="Insufficient credits",E=I?`Need more credits (balance: ${s})`:Mt(y.error)?"Sign in to render this shot.":y.error||"Could not start render";c(j,{status:"failed",error:E}),I&&C.error("Insufficient credits");return}f=y.transactionId??null}let d=!1,u=!1;const g=async y=>{u||(u=!0,c(j,{status:"failed",error:y}),f?await r(f):S&&d&&$&&await ra($),C.error(y))};try{const I=(A=>[4,6,8,10].reduce((O,v)=>Math.abs(v-A)<Math.abs(O-A)?v:O,8))(Math.max(2,Math.min(10,h??8))),{data:E,error:B}=await D.functions.invoke("ad-decoder-omni-video",{body:{prompt:k,duration:I,aspectRatio:"9:16",resolution:"720p",imageUrl:b,teardownId:$??void 0,transactionId:f}});if(B||!(E!=null&&E.taskId))throw new Error((B==null?void 0:B.message)||"Could not start render");const w=E.taskId;d=!0;let _=0;const U=async()=>{var A,O;_++,c(j,{attempts:_});try{const{data:v,error:q}=await D.functions.invoke("check-video-status",{body:{taskId:w,provider:"kie"}});if(q)throw q;if(((v==null?void 0:v.state)==="success"||(v==null?void 0:v.state)==="completed")&&(v!=null&&v.videoUrl)){c(j,{status:"completed",videoUrl:v.videoUrl}),C.success(`Shot ${j+1} ready`);const{data:N}=await D.auth.getSession();(O=(A=N==null?void 0:N.session)==null?void 0:A.user)!=null&&O.id&&Ze({userId:N.session.user.id,name:`Ad Decoder Shot ${j+1} â ${new Date().toLocaleDateString()}`,content:v.videoUrl,type:"video_prompt",tags:["ad-decoder","shot","video"],metadata:{prompt:k,shotIndex:j,startingFrameUrl:b}});return}if((v==null?void 0:v.state)==="fail"||(v==null?void 0:v.state)==="failed")throw new Error(v.error||"Generation failed");if(_<ta)setTimeout(U,ea);else throw new Error("Generation timed out")}catch(v){await g(v instanceof Error?v.message:"Generation failed")}};U()}catch(y){await g(y instanceof Error?y.message:"Render failed")}},[s,t,r,c]),i=l.useCallback(m=>a[m]??bt,[a]),x=l.useCallback(m=>{var j;if(m===0)return!1;for(let b=0;b<m;b++)if((((j=a[b])==null?void 0:j.status)??"idle")!=="completed")return!1;return!0},[a]);return{animate:o,getState:i,allCompleted:x,states:a}}const sa="ad-decoder-hero-segment",yt=20,zt=30,na=6e3,ia=90,oa=15e4;function la(t,r,s){if(t==="Insufficient credits")return{message:`Need ${r} credits (balance: ${s})`,toast:!0};if(Mt(t))return{message:"Sign in to render this ad.",toast:!1};switch(t){case"Rate limit exceeded":return{message:"Too many requests â wait a moment and hit Retry.",toast:!1};case"Concurrent generation limit reached":return{message:"You already have the maximum number of generations running. Wait for one to finish.",toast:!1};case"tool_restricted":return{message:"Hero render isn't included in your current plan.",toast:!1};case"spaces_only_restricted":return{message:"You can only generate inside your invited Space.",toast:!1};default:return{message:t||"Couldn't reserve credits for this render.",toast:!0}}}function ca(t){let r=2166136261;for(let s=0;s<t.length;
6s++)r^=t.charCodeAt(s),r=Math.imul(r,16777619);return(r>>>0).toString(36)}function Vt(t){var r;return t.productImageUrl?ca(JSON.stringify({avatarId:t.avatarId??null,avatarImageUrl:t.avatarImageUrl??null,productImageUrl:t.productImageUrl,productName:((r=t.productName)==null?void 0:r.trim())??"",storyboardOverride:t.storyboardOverride??null,selectedImprovements:t.selectedImprovements??null})):null}const Ve=(t,r)=>`ad-decoder:hero-final:v2:${t}:${r}`;function da(t){return!!t&&/\/l_video:[^/]+\/fl_splice\//.test(t)&&!t.includes("fl_layer_apply")}function ma(t,r,s){return new Promise((a,n)=>{const c=window.setTimeout(()=>n(new Error(s)),r);t.then(o=>{window.clearTimeout(c),a(o)},o=>{window.clearTimeout(c),n(o)})})}function qe(t){const r=Math.max(3,Math.min(zt,Math.round(t||0)));if(r<=10)return[[4,6,8,10].reduce((c,o)=>Math.abs(o-r)<Math.abs(c-r)?o:c)];const s=[];let a=r;for(;a>0;)a>=10?(s.push(10),a-=10):a>=8?(s.push(8),a=0):a>=6?(s.push(6),a=0):(s.push(Math.max(4,Math.round(a))),a=0);return s}function ua(t,r=null,s=1){const{deductCredits:a,refundCredits:n,balance:c}=Pt(),[o,i]=l.useState("idle"),[x,m]=l.useState(null),[j,b]=l.useState({}),[k,h]=l.useState(s),[$,S]=l.useState(()=>{try{return r?localStorage.getItem(Ve(t,r)):null}catch{return null}}),[f,d]=l.useState(null),u=l.useRef(0);l.useEffect(()=>{o==="idle"&&h(s)},[s,o]),l.useEffect(()=>{try{const w=r?localStorage.getItem(Ve(t,r)):null;w?(S(w),i("done")):o==="done"&&(S(null),i("idle"))}catch{}},[r,t]);const g=l.useCallback((w,_)=>{b(U=>({...U,[w]:{sceneIndex:0,subIndex:w,status:"pending",videoUrl:null,error:null,...U[w],..._}}))},[]),y=l.useCallback(async w=>{const{data:_,error:U}=await D.functions.invoke("ad-decoder-omni-video",{body:{prompt:w.prompt,duration:w.durationS,aspectRatio:"9:16",resolution:"720p",imageUrl:w.imageUrl}});if(U||!(_!=null&&_.taskId))throw new Error((U==null?void 0:U.message)||"Failed to start clip");const A=_.taskId;for(let O=0;O<ia;O++){await new Promise(N=>setTimeout(N,na));const{data:v,error:q}=await D.functions.invoke("check-video-status",{body:{taskId:A,provider:"kie"}});if(q)throw q;if(((v==null?void 0:v.state)==="success"||(v==null?void 0:v.state)==="completed")&&(v!=null&&v.videoUrl))return{videoUrl:v.videoUrl};if((v==null?void 0:v.state)==="fail"||(v==null?void 0:v.state)==="failed")throw new Error(v.error||"Clip generation failed")}throw new Error("Clip timed out")},[]),I=l.useCallback(async(w,_)=>{const{data:U,error:A}=await D.functions.invoke("ad-decoder-last-frame",{body:{videoUrl:w,durationS:_}});if(A||!(U!=null&&U.lastFrameUrl))throw new Error((A==null?void 0:A.message)||"Last-frame extraction failed");return U.lastFrameUrl},[]),E=l.useCallback(async w=>{if(o==="rendering"||o==="stitching"||o==="planning")return;d(null),b({});const _=Vt(w),U=++u.current;i("planning");const{data:A}=await D.from("ad_teardowns").select("duration_seconds, video_storage_path").eq("id",t).maybeSingle(),O=Math.max(3,Math.min(zt,Math.round(Number(A==null?void 0:A.duration_seconds)||10))),v=qe(O);h(v.length),v.forEach((P,H)=>g(H,{status:"pending",durationS:P}));const q=v.length*yt;if(c<q){i("failed"),d(`Need ${q} credits (balance: ${c})`),C.error(`Need ${q} credits. Balance: ${c}`);return}const N=[];for(let P=0;P<v.length;P++){const H=await a(sa);if(!H.success){for(const G of N)await n(G);const{message:V,toast:Y}=la(H.error,q,c);i("failed"),d(V),Y&&C.error(V);return}H.transactionId&&N.push(H.transactionId)}let F=null;try{const{data:P,error:H}=await ma(D.functions.invoke("ad-decoder-scene-plan",{body:{teardownId:t,avatarImageUrl:w.avatarImageUrl,productImageUrl:w.productImageUrl,productName:w.productName,renderSignature:_,storyboardOverride:w.storyboardOverride,selectedImprovements:w.selectedImprovements,segments:v.map((V,Y)=>({index:Y,duration_s:V}))}}),oa,"Planning timed out â credits refunded. Try again with fewer script edits.");if(H){let V=H.message||"Planner failed";try{const Y=H.context;if(Y&&typeof Y.json=="function"){const G=await Y.json();G!=null&&G.error&&(V=G.detail?`${G.error} â ${String(G.detail).slice(0,160)}`:G.error)}}catch{}throw new Error(V)}if(!(P!=null&&P.heroPlan))throw new Error((P==null?void 0:P.error)||"Planner returned no plan");F=P.heroPlan,m(F)}catch(P){for(const V of N)await n(V);const H=P instanceof Error?P.message:"Planner failed";d(H),i("failed"),C.error(H);return}if(!F.start_frame_url){for(const P of N)await n(P);d("Couldn't extract a start frame from the original ad."),i("failed"),C.error("Missing start frame â credits refunded.");return}i("rendering");let z=F.start_frame_url;const M=[],te=new Set;for(let P=0;P<F.segments.length;P++){if(u.current!==U)return;const H=F.segments[P];g(P,{status:"rendering",durationS:H.duration_s});try{const{videoUrl:V}=await y({prompt:H.prompt,imageUrl:z,durationS:H.duration_s});g(P,{status:"done",videoUrl:V}),M.push(V),P<F.segments.length-1&&(z=await I(V,H.duration_s))}catch(V){const Y=V instanceof Error?V.message:"Segment failed";g(P,{status:"failed",error:Y});for(let G=P;G<N.length;G++){const ne=N[G];ne&&!te.has(ne)&&(te.add(ne),await n(ne))}break}}if(M.length===0){i("failed"),d("Render failed"),C.error("Render failed â credits refunded");return}
6if(M.length<F.segments.length){const P=M.reduce((Y,G,ne)=>{var Ce;return Y+(((Ce=F.segments[ne])==null?void 0:Ce.duration_s)||0)},0),H=F.segments.reduce((Y,G)=>Y+G.duration_s,0),V=`Only ${M.length}/${F.segments.length} clips rendered (${P}s of ${H}s) â remaining credits refunded. Tap Retry to finish.`;i("failed"),d(V),C.error(V);return}let re=M[0];if(M.length>1){i("stitching");try{const{data:P,error:H}=await D.functions.invoke("ad-decoder-stitch",{body:{shots:M.map((V,Y)=>{var G;return{order:Y,videoUrl:V,duration:(G=F.segments[Y])==null?void 0:G.duration_s}})}});if(H||!(P!=null&&P.videoUrl))throw new Error((H==null?void 0:H.message)||"Stitch failed");re=P.videoUrl}catch(P){const H=P instanceof Error?P.message:"Stitch failed";d(H),i("failed"),C.error(H);return}}S(re);try{_&&localStorage.setItem(Ve(t,_),re)}catch{}await D.from("ad_teardowns").update({final_stitched_video_url:re}).eq("id",t),i("done"),C.success(M.length===1?"Hero ad ready":`Hero ad ready (${M.length} clips stitched)`);const{data:{user:he}}=await D.auth.getUser();he&&Ze({userId:he.id,name:`Ad Decoder · Hero cut · ${new Date().toLocaleDateString()}`,content:re,type:"ad",tags:["ad-decoder","hero-cut"],metadata:{teardownId:t,source:"ad-decoder-hero",clipCount:M.length,durationS:O}})},[c,a,n,y,I,o,t,g]);l.useEffect(()=>{let w=!1;return(async()=>{const{data:_}=await D.from("ad_teardowns").select("final_stitched_video_url, scene_plan, duration_seconds").eq("id",t).maybeSingle();if(w)return;_!=null&&_.duration_seconds&&h(qe(Number(_.duration_seconds)).length);const U=_==null?void 0:_.scene_plan,A=(U==null?void 0:U.render_signature)??null;r&&(_!=null&&_.final_stitched_video_url)&&A===r&&!$&&!da(_.final_stitched_video_url)&&(S(_.final_stitched_video_url),i("done")),U&&(!r||A===r)&&!x&&m(U)})(),()=>{w=!0}},[r,t]);const B=(()=>{var O;let w=0,_=0,U=0;const A=k||(((O=x==null?void 0:x.segments)==null?void 0:O.length)??1);for(const v of Object.keys(j)){const q=j[Number(v)];q.status==="done"?w++:q.status==="rendering"?_++:q.status==="failed"&&U++}return{total:A,done:w,rendering:_,failed:U}})();return{status:o,scenePlan:x,subclips:j,finalVideoUrl:$,error:f,run:E,progress:B,segmentCount:k,costPerSegment:yt}}function pa({teardown:t,videoUrl:r,teardownId:s,sourceUrl:a,initialRecastFrames:n,onRecastStatusChange:c}){var st,nt,it,ot,lt;const o=Zr(s),i=aa(),x=t.storyboard??[],m=t.format_type??"ugc_human",[j,b]=l.useState(new Map),k=`ad-decoder:hero-cast:${s}`,[h,$]=l.useState(()=>{try{const p=localStorage.getItem(`${k}:avatar`);return p?JSON.parse(p):null}catch{return null}}),[S,f]=l.useState(()=>{try{return localStorage.getItem(`${k}:productUrl`)}catch{return null}}),[d,u]=l.useState(()=>{try{return localStorage.getItem(`${k}:productName`)||""}catch{return""}});l.useEffect(()=>{try{h?localStorage.setItem(`${k}:avatar`,JSON.stringify(h)):localStorage.removeItem(`${k}:avatar`)}catch{}},[h,k]),l.useEffect(()=>{try{S?localStorage.setItem(`${k}:productUrl`,S):localStorage.removeItem(`${k}:productUrl`),localStorage.setItem(`${k}:productName`,d)}catch{}},[S,d,k]);const y=(o.frames.length?o.frames:n??[]).map(p=>j.get(p.shot_index)??p);l.useEffect(()=>{c==null||c(o.status)},[o.status,c]);const I=new Map(y.map(p=>[p.shot_index,p])),E=o.status==="running",[B,w]=l.useState(!1),[_,U]=l.useState(!1),A=`ad-decoder:script:${s}`,[O,v]=l.useState(()=>{try{const p=localStorage.getItem(A);if(p)return JSON.parse(p)}catch{}return null}),q=O?O.reduce((p,T,L)=>{const K=x[L];return K&&["vo_line","on_screen_text","camera","lens","wardrobe","setting","lighting","composition"].some(Q=>T[Q]!==K[Q])?p+1:p},0):0,[N,F]=l.useState("decode"),z=y.length>0,M=80,te=l.useRef(null),[re,he]=l.useState(()=>Number(t.duration_seconds)||null),P=t.static_source_image_url??null,[H,V]=l.useState(!1),Y=`ad-decoder:fixes:${s}`,[G,ne]=l.useState(()=>{try{const p=localStorage.getItem(Y);if(p)return new Set(JSON.parse(p))}catch{}return new Set});l.useEffect(()=>{try{localStorage.setItem(Y,JSON.stringify(Array.from(G)))}catch{}},[Y,G]);const[Ce,Wt]=l.useState(null),ae=(Ce??t.improvements??[]).filter(p=>!!p),[ce,Qe]=l.useState(!1),Oe=ae.filter((p,T)=>G.has(T)),Yt=Vt({avatarImageUrl:h==null?void 0:h.imageUrl,avatarId:h==null?void 0:h.id,productImageUrl:S,productName:d,storyboardOverride:O,selectedImprovements:Oe}),et=x.reduce((p,T)=>p+(Number(T.duration_s)||0),0),tt=re||(et>0?et:0),qt=tt>0?qe(tt).length:0,oe=ua(s,Yt,qt),Kt=p=>ne(T=>{const L=new Set(T);return L.has(p)?L.delete(p):L.add(p),L}),Jt=p=>{const T=te.current;T&&(T.currentTime=Math.max(0,p),T.play().catch(()=>{}))},se=t.hook_score??0,rt=Ee(Oe),Re=Pe(se,rt),De=se<M,at=(p=ae)=>{const T=ze(p,se,M);return ne(new Set(T)),T},Xt=async()=>{Qe(!0);try{const{data:p,error:T}=await D.functions.invoke("ad-decoder-improvements",{body:{teardownId:s}});if(T)throw T;
6const L=((p==null?void 0:p.improvements)??[]).filter(Boolean);if(!L.length)throw new Error("No fixes returned");return Wt(L),L}catch(p){const T=p instanceof Error?p.message:"Could not generate fixes";return C.error(T),null}finally{Qe(!1)}},Fe=async()=>{F("insights"),setTimeout(()=>{var T;(T=document.getElementById("ai-coach-panel"))==null||T.scrollIntoView({behavior:"smooth",block:"start"})},80);let p=ae;if(p.length===0){C.info("AI Coach generating fixesâ¦");const T=await Xt();if(!T)return;p=T}at(p),C.success(`Auto-selected fixes · projected ${se} â ${M}+`)},Zt=(p,T)=>{var _e,W;const L=x[p],K=(L.vo_line||"").trim(),J=(L.on_screen_text||"").trim(),Q=p>0?x[p-1]:null,le=p<x.length-1?x[p+1]:null,ge=x.map((de,Se)=>`[${Se+1}] "${de.vo_line||"(silent)"}"`).join(" â "),Le=t.hook_line||"",He=((_e=t.detected_product)==null?void 0:_e.name)||"the product",Ne=m==="unboxing_hands",ke=m==="product_only",Ie=Ne?"IDENTITY LOCK: Show ONLY hands + product + surface. NO face, NO torso, NO full person. Hands must look identical across shots.":ke?"IDENTITY LOCK: Show ONLY the product on a surface. NO hands, NO person.":"IDENTITY LOCK: the talent's face, hair, skin tone, and outfit must remain visually IDENTICAL to the starting frame across every frame â same person, no morphing, no aging, no style drift.",Te=Ne||ke?"Use natural room-tone ambient audio only â no spoken dialogue, no music. No mouth on screen.":K?`SPOKEN AUDIO (MANDATORY, lip-sync EXACTLY word-for-word â no paraphrasing, no extra words, no omitted words, no improvisation): "${K}". Use a natural conversational UGC voice that matches the talent's age, gender, and apparent ethnicity. Pace delivery so the full line lands inside the clip duration. Do not add music or any other dialogue. Only subtle ambient room tone.`:"Use natural room-tone ambient audio only â no spoken dialogue, no music. Talent should NOT mouth any words.";return[`Animate this exact starting frame into a photorealistic 9:16 vertical UGC video clip. Duration ~${((W=L.duration_s)==null?void 0:W.toFixed(1))??2.5}s.`,`This is SHOT ${p+1} of ${x.length} in a cohesive ad for "${He}". Hook of the ad: "${Le}".`,`FULL AD SCRIPT (for tone & continuity ONLY â do NOT speak any other shot's line in this clip): ${ge}.`,Q?`Previous shot ended with VO: "${Q.vo_line||"(silent)"}". Continue the same energy and setting.`:"This is the OPENING shot â deliver with high-energy hook attention.",le?`Next shot will be VO: "${le.vo_line||"(silent)"}". Land this shot so it flows into that beat.`:"This is the CLOSING shot â land it cleanly without trailing off.",`Camera: ${L.camera}. Composition: ${L.composition}.`,Te,J?`ON-SCREEN TEXT (MANDATORY, reproduce EXACTLY as it appears in the starting frame â character-for-character, same font weight, size, position, color, animation): "${J}". Do NOT translate, restyle, abbreviate, reposition, or change it. Do NOT add any other captions, watermarks, logos, or text overlays.`:"Do NOT add any captions, watermarks, logos, or text overlays that are not already in the starting frame.",Ie,"PRODUCT LOCK: the product must remain visually IDENTICAL to the one in the starting frame â same shape, color, logo, and label. Do NOT swap, morph, or restyle it.","Natural handheld motion only. Photorealistic, ad-quality, native synced audio."].filter(Boolean).join(" ")},Qt=async()=>{try{await navigator.clipboard.writeText(t.formula||""),V(!0),C.success("Formula copied"),setTimeout(()=>V(!1),1500)}catch{C.error("Couldn't copy")}};return e.jsxs(R.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},className:"grid lg:grid-cols-[minmax(0,1fr)_500px] gap-4 lg:min-h-[640px]",children:[e.jsx("div",{className:"flex flex-col gap-3 min-h-0",children:e.jsxs(Sr,{value:N,onValueChange:p=>F(p),className:"flex flex-col flex-1 min-h-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs(Cr,{className:"h-10 bg-white/[0.03] border border-white/[0.08] p-1 gap-1",children:[e.jsxs(mt,{value:"decode",className:"text-xs font-bold uppercase tracking-wider gap-2 px-4 data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-[0_0_20px_-5px_hsl(var(--primary)/0.6)]",children:[e.jsx(pt,{className:"w-3.5 h-3.5"})," Decode"]}),e.jsxs(mt,{value:"insights",className:"text-xs font-bold uppercase tracking-wider gap-2 px-4 data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-[0_0_20px_-5px_hsl(var(--primary)/0.6)]",children:[e.jsx(ue,{className:"w-3.5 h-3.5"})," Insights"]})]}),De&&e.jsxs("button",{onClick:Fe,disabled:ce,className:"group inline-flex items-center gap-2 h-9 px-3 rounded-lg bg-gradient-to-r from-primary to-primary/80 text-primary-foreground text-xs font-bold uppercase tracking-wider hover:shadow-[0_0_24px_-4px_hsl(var(--primary)/0.7)] transition-all disabled:opacity-60",title:"Auto-pick AI fixes and jump to Insights",children:[e.jsx(Ge,{className:`w-3.5 h-3.5 ${ce?"animate-pulse":""}`}),e.jsx("span",{children:ce?"AI Coach thinkingâ¦":ae.length>0?e.jsxs(e.Fragment,{children:["Apply fixes · ",se," â ",Pe(se,Ee(ze(
6ae,se,M).map(p=>ae[p])))]}):e.jsxs(e.Fragment,{children:["Boost to ",M,"+"]})}),e.jsx(xe,{className:"w-3 h-3 group-hover:translate-x-0.5 transition-transform"})]}),e.jsxs(Rt,{open:B,onOpenChange:w,children:[e.jsx(yr,{asChild:!0,children:e.jsxs("button",{className:"group inline-flex items-center gap-2 h-9 px-3 rounded-lg bg-white/[0.03] border border-white/[0.06] text-xs font-semibold hover:border-primary/40 transition-colors",children:[e.jsx(ve,{className:"w-3.5 h-3.5 text-primary"}),e.jsx("span",{children:"Storyboard"}),e.jsxs("span",{className:"font-mono text-[10px] text-muted-foreground",children:[String(x.length).padStart(2,"0")," shots"]}),e.jsx(xe,{className:"w-3 h-3 text-muted-foreground group-hover:translate-x-0.5 transition-transform"})]})}),e.jsxs(Dt,{side:"right",className:"w-full sm:max-w-3xl bg-[#0b0a09]/95 backdrop-blur-2xl border-white/[0.06] overflow-y-auto p-0",children:[e.jsxs(Ft,{className:"sticky top-0 z-10 bg-[#0b0a09]/95 backdrop-blur-2xl pt-6 px-6 pb-4 border-b border-white/[0.06]",children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.3em] text-primary",children:".03 · Shot-by-shot"}),e.jsxs(Lt,{className:"text-2xl font-display font-black uppercase tracking-tight",children:["The Storyboard · ",e.jsxs("span",{className:"text-primary",children:[x.length," shots"]})]}),e.jsx(jr,{className:"text-xs text-muted-foreground",children:z?"Recast frames ready â animate each shot with Omni.":"Run Recast first, then animate each shot."})]}),e.jsx("div",{className:"px-6 pb-6",children:x.length===0?e.jsxs("div",{className:"mt-8 text-center py-12 rounded-2xl border border-dashed border-white/10 bg-white/[0.02]",children:[e.jsx(ve,{className:"h-8 w-8 text-muted-foreground mx-auto mb-3 opacity-60"}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:"No shots detected"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"This ad couldn't be split into shots. Try another one."})]}):e.jsx("div",{className:"grid sm:grid-cols-2 gap-4 mt-5",children:x.map((p,T)=>e.jsx(Or,{index:T,shot:p,recast:I.get(T),recastInProgress:E,videoState:i.getState(T),showPromoteToShowcase:!1,originalVideoUrl:r,originalSourceUrl:a??null,onRetryRecast:async L=>{var Q;const{data:K,error:J}=await D.functions.invoke("ad-decoder-recast-shot",{body:{teardownId:s,shotIndex:L}});if(J||!((Q=K==null?void 0:K.frame)!=null&&Q.image_url)){C.error((J==null?void 0:J.message)||"Retry failed");return}b(le=>{const ge=new Map(le);return ge.set(L,K.frame),ge}),C.success(`Shot ${L+1} regenerated`)},onAnimate:()=>{var K;const L=(K=I.get(T))==null?void 0:K.image_url;L&&i.animate({shotIndex:T,startingFrameUrl:L,prompt:Zt(T),durationS:p.duration_s})},disableAnimate:!0},T))})})]})]})]}),e.jsxs(ut,{value:"decode",className:"flex-1 min-h-0 mt-3 data-[state=inactive]:hidden flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 px-3 py-1.5 rounded-full bg-primary/15 border border-primary/40",children:[e.jsx(ue,{className:"w-3 h-3 text-primary"}),e.jsx("span",{className:"text-[10px] uppercase tracking-widest text-primary/90 font-bold",children:"Hook"}),e.jsx("span",{className:"text-xs font-black text-foreground",children:t.hook_score??0})]}),De&&e.jsxs("button",{onClick:Fe,disabled:ce,className:"group inline-flex items-center gap-2 px-3 py-1.5 rounded-full bg-gradient-to-r from-primary to-primary/80 text-primary-foreground hover:shadow-[0_0_24px_-4px_hsl(var(--primary)/0.7)] transition-all disabled:opacity-60",title:"Auto-pick AI fixes and jump to Insights",children:[e.jsx(Ge,{className:`w-3 h-3 ${ce?"animate-pulse":""}`}),e.jsx("span",{className:"text-[10px] uppercase tracking-widest font-black",children:ce?"AI Coach thinkingâ¦":ae.length>0?e.jsxs(e.Fragment,{children:["Boost to ",M,"+ ",e.jsxs("span",{className:"opacity-80",children:["· ",se," â ",Pe(se,Ee(ze(ae,se,M).map(p=>ae[p])))]})]}):e.jsxs(e.Fragment,{children:["Boost to ",M,"+ ",e.jsx("span",{className:"opacity-80",children:"· Generate fixes"})]})}),e.jsx(xe,{className:"w-3 h-3 group-hover:translate-x-0.5 transition-transform"})]}),e.jsxs("button",{onClick:Qt,className:"group inline-flex items-center gap-2 px-3 py-1.5 rounded-full bg-white/[0.04] border border-white/10 hover:border-primary/40 transition-colors",title:"Copy formula",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-widest text-muted-foreground",children:"Formula"}),e.jsx("span",{className:"text-xs font-semibold text-foreground truncate max-w-[260px]",children:t.formula}),H?e.jsx(pe,{className:"w-3 h-3 text-primary"}):e.jsx(mr,{className:"w-3 h-3 text-muted-foreground group-hover:text-primary"})]}),e.jsxs("div",{className:"inline-flex items-center gap-2 px-3 py-1.5 rounded-full bg-white/[0.04] border border-white/10",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-widest text-muted-foreground",children:"Pacing"}),e.jsx("span",{className:"text-xs font-semibold text-foreground",children:t.pacing})]}),((st=t.detected_product)==null?void 0:st.name)&&e.jsxs("div",{className:"inline-flex items-center gap-2 px-3 py-1.5 rounded-full bg-primary/10 border border-primary/30",children:[e.jsx(Je,{className:"w-3 h-3 text-primary"}),e.jsx("span",{className:"text-[10px] uppercase tracking-widest text-primary/80",children:"Detected"}),e.jsxs("span",{className:"text-xs font-semibold text-foreground truncate max-w-[200px]",children:[t.detected_product.name,t.detected_product.category?e.jsxs("span",{className:"text-muted-foreground",children:[" · ",t.detected_product.category]}):null]})]})]}),e.jsx("div",{className:"relative flex-1 min-h-0 flex items-center justify-center rounded-2xl overflow-hidden border border-white/[0.06] bg-white/[0.015] p-3",children:P?e.jsx("div",{className:"relative h-full max-h-[70vh] aspect-[9/16] max-w-full overflow-hidden rounded-xl bg-black",children:e.jsx("img",{src:P,alt:"Meta ad creative preview",className:"h-full w-full object-contain"})}):r&&e.jsx("div",{className:"relative h-full max-h-[70vh] aspect-[9/16] max-w-full overflow-hidden rounded-xl bg-black shadow-[0_0_40px_-18px_hsl(var(--primary)/0.35)]",children:e.jsx("video",{ref:te,src:r,controls:!0,playsInl
6ine:!0,onLoadedMetadata:p=>he(p.currentTarget.duration||null),className:"h-full w-full object-contain"})})})]}),e.jsxs(ut,{value:"insights",className:"flex-1 min-h-0 mt-3 data-[state=inactive]:hidden overflow-y-auto",children:[t.brain_scores&&e.jsx("div",{className:"mb-3",children:e.jsx(Yr,{scores:t.brain_scores})}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-3",children:[e.jsx(Ar,{score:t.hook_score??0,dna:t.hook_dna,archetype:t.hook_archetype}),e.jsxs("div",{className:"rounded-2xl border border-white/[0.06] bg-white/[0.02] p-5 backdrop-blur",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(pt,{className:"h-4 w-4 text-primary"}),e.jsx("h3",{className:"text-sm font-bold uppercase tracking-wider",children:"Why this hook converts"})]}),e.jsxs("p",{className:"text-sm text-foreground/85 leading-relaxed mb-4",children:[e.jsxs("span",{className:"italic",children:['"',t.hook_line,'"']})," â ",t.why_it_works]}),t.color_palette&&t.color_palette.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-widest text-muted-foreground mr-1",children:"Palette"}),t.color_palette.slice(0,5).map((p,T)=>e.jsx("div",{className:"h-7 w-7 rounded-md border border-white/[0.06]",style:{background:p},title:p},T))]})]})]}),(((nt=t.attention)==null?void 0:nt.length)||((it=t.transcript)==null?void 0:it.text))&&e.jsxs("div",{className:"grid md:grid-cols-2 gap-3 mt-3",children:[t.attention&&t.attention.length>0&&e.jsx(Br,{frames:t.frames||[],attention:t.attention}),((ot=t.transcript)==null?void 0:ot.text)&&e.jsx(zr,{transcript:t.transcript,onSeek:Jt})]}),ae.length===0&&e.jsxs("div",{id:"ai-coach-panel",className:"mt-3 rounded-2xl border border-primary/20 bg-gradient-to-br from-primary/[0.06] via-white/[0.02] to-transparent p-6 backdrop-blur scroll-mt-20 text-center",children:[e.jsx("div",{className:"inline-flex w-10 h-10 rounded-lg bg-primary/15 border border-primary/30 items-center justify-center mb-3",children:e.jsx(Ye,{className:"h-5 w-5 text-primary"})}),e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.3em] text-primary mb-1",children:"AI Coach"}),e.jsx("h3",{className:"text-base font-bold uppercase tracking-wider mb-1.5",children:"No fixes generated yet"}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-4 max-w-md mx-auto",children:["Get 4-6 concrete, evidence-backed improvements that would push this ad from ",se," to ",M,"+. Free."]}),e.jsx("button",{onClick:Fe,disabled:ce,className:"inline-flex items-center gap-2 px-4 h-10 rounded-lg bg-primary text-primary-foreground font-black text-[11px] uppercase tracking-[0.2em] hover:bg-primary/90 transition-colors disabled:opacity-60",children:ce?e.jsxs(e.Fragment,{children:[e.jsx(Me,{className:"w-3.5 h-3.5 animate-pulse"})," Generating fixesâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ge,{className:"w-3.5 h-3.5"})," Generate fixes to hit ",M,"+"]})})]}),ae.length>0&&e.jsxs("div",{id:"ai-coach-panel",className:"mt-3 rounded-2xl border border-primary/20 bg-gradient-to-br from-primary/[0.06] via-white/[0.02] to-transparent p-5 backdrop-blur scroll-mt-20",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4 flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-primary/15 border border-primary/30 flex items-center justify-center",children:e.jsx(Ye,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-[0.3em] text-primary leading-none mb-1",children:"AI Coach"}),e.jsx("h3",{className:"text-sm font-bold uppercase tracking-wider leading-none",children:"Pick fixes to apply when you recast"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[De&&e.jsxs("button",{onClick:()=>at(),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-primary text-primary-foreground text-[10px] font-black uppercase tracking-widest hover:bg-primary/90 transition-colors",title:`Auto-pick the minimum fixes to reach ${M}+`,children:[e.jsx(Me,{className:"w-3 h-3"})," Auto-pick to ",M,"+"]}),e.jsxs("span",{className:"text-[10px] font-mono uppercase tracking-widest text-muted-foreground",children:[G.size,"/",ae.length," selected"]}),G.size>0&&e.jsx("button",{onClick:()=>ne(new Set),className:"text-[10px] font-mono uppercase tracking-widest text-muted-foreground hover:text-foreground",children:"Clear"})]})]}),G.size>0&&e.jsxs("div",{className:"mb-3 px-3 py-2 rounded-lg bg-primary/[0.08] border border-primary/30 flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("div",{className:"text-[11px] text-foreground
6/90",children:[e.jsx("span",{className:"text-muted-foreground",children:"Projected hook"})," ",e.jsxs("span",{className:"font-mono font-bold",children:[se," â ",e.jsx("span",{className:"text-primary",children:Re})]})," ",e.jsxs("span",{className:"text-primary/80 font-mono",children:["(+",rt,")"]})]}),e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-widest",children:Re>=M?e.jsxs("span",{className:"text-primary",children:["â Target ",M,"+ reached"]}):e.jsxs("span",{className:"text-muted-foreground",children:["+",M-Re," more to target"]})})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mb-3 leading-relaxed",children:"Toggle a fix to inject it into the Recast prompt. Leave all off for an exact 1:1 recreation."}),e.jsx("div",{className:"grid sm:grid-cols-2 gap-2.5",children:ae.map((p,T)=>{const L=G.has(T),K=p.impact==="high"?"text-primary border-primary/40 bg-primary/10":p.impact==="medium"?"text-amber-300 border-amber-400/30 bg-amber-400/5":p.impact==="low"?"text-sky-300 border-sky-400/30 bg-sky-400/5":"text-muted-foreground border-white/10 bg-white/[0.03]",J=typeof p.confidence=="number"?Math.max(0,Math.min(100,p.confidence)):null;return e.jsxs("button",{type:"button",onClick:()=>Kt(T),className:`text-left rounded-xl border p-3.5 transition-all ${L?"border-primary/60 bg-primary/[0.08] shadow-[0_0_24px_-8px_hsl(var(--primary)/0.5)]":"border-white/[0.06] bg-black/30 hover:border-white/[0.14]"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-bold uppercase tracking-wider",children:[e.jsx("span",{className:`w-3.5 h-3.5 rounded border flex items-center justify-center shrink-0 ${L?"bg-primary border-primary text-primary-foreground":"border-white/20"}`,children:L&&e.jsx("span",{className:"text-[8px] font-black leading-none",children:"â"})}),e.jsx(ur,{className:"h-3 w-3 text-primary"}),p.area]}),e.jsxs("span",{className:`text-[9px] font-mono uppercase tracking-widest px-2 py-0.5 rounded-full border ${K}`,children:[p.impact," lift"]})]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground leading-snug mb-1.5",children:[e.jsx("span",{className:"text-foreground/70 font-semibold",children:"Issue: "}),p.issue]}),e.jsxs("p",{className:"text-[11px] text-foreground/90 leading-snug mb-2",children:[e.jsx("span",{className:"text-primary font-semibold",children:"Fix: "}),p.suggestion]}),J!==null&&e.jsxs("div",{className:"mb-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-[9px] font-mono uppercase tracking-widest text-muted-foreground mb-1",children:[e.jsx("span",{children:"Confidence"}),e.jsxs("span",{className:"text-foreground/80 font-bold",children:[J,"%"]})]}),e.jsx("div",{className:"h-1 rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary",style:{width:`${J}%`}})})]}),p.evidence&&p.evidence.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 pt-1 border-t border-white/[0.05] mt-2",children:[e.jsx("span",{className:"text-[9px] font-mono uppercase tracking-widest text-muted-foreground self-center mr-1",children:"Evidence"}),p.evidence.map((Q,le)=>e.jsx("span",{className:"text-[10px] text-foreground/75 bg-white/[0.04] border border-white/[0.06] rounded px-1.5 py-0.5 leading-tight",children:Q},le))]})]},T)})})]})]})]})}),e.jsxs("div",{className:"min-h-0 lg:overflow-y-auto",children:[e.jsx(Lr,{formatType:m,avatar:h,productUrl:S,productName:d,onAvatarChange:$,onProductChange:(p,T)=>{f(p),u(T)},onEditScript:x.length>0?()=>U(!0):void 0,scriptEditCount:q,adProductSuggestion:(()=>{var ke,Ie,Te,_e;const p=t.frames||[];if(!p.length)return;const T=[(ke=t.product_lock)==null?void 0:ke.name,(Ie=t.product_lock)==null?void 0:Ie.category,...((Te=t.product_lock)==null?void 0:Te.attributes)||[]].filter(Boolean).join(" ").toLowerCase().split(/[^a-z0-9]+/).filter(W=>W.length>=3),L=new RegExp(["product","bottle","pack","packaging","jar","tube","box","can","cup","sachet","pouch","dropper","device","kit","label",...T].join("|"),"i"),K=/face|head|person|hair|skin|body|hand/i,J=[],Q=new Set;for(const W of t.attention||[]){const de=p[W.frame_index];if(!de)continue;const Se=[...W.regions||[]].sort(($e,er)=>(er.weight||0)-($e.weight||0)),fe=Se.filter($e=>L.test($e.label)&&!K.test($e.label))[0];fe?J.push({url:de,region:{x:fe.x,y:fe.y,w:fe.w,h:fe.h},weight:fe.weight||0}):Se[0]&&K.test(Se[0].label)&&Q.add(W.frame_index)}J.sort((W,de)=>de.weight-W.weight);const le=p.map((W,de)=>({url:W,i:de})),ge=le.filter(W=>!Q.has(W.i)).reverse(),Le=le.filter(W=>Q.has(W.i)).reverse(),He=[...ge,...Le].map(({url:W})=>({url:W})),Ne=[...J.map(W=>
6({url:W.url,region:W.region})),...He];if(Ne.length)return{name:(_e=t.detected_product)==null?void 0:_e.name,sources:Ne.slice(0,6)}})()}),e.jsx(Hr,{open:_,onOpenChange:U,storyboard:x,scriptFull:t.script_full||((lt=t.transcript)==null?void 0:lt.text),persistKey:A,transcriptFailed:t.transcript_failed,onSave:async p=>{v(p);try{await D.from("ad_teardowns").update({storyboard:p}).eq("id",s)}catch{}}}),(()=>{const p=m==="ugc_human",T=!!S&&(!p||!!h),L=S?p&&!h?"Pick a talent next":void 0:"Pick a product image first";return e.jsx(qr,{status:oe.status,scenePlan:oe.scenePlan,subclips:oe.subclips,finalVideoUrl:oe.finalVideoUrl,error:oe.error,ready:T,readyHint:L,segmentCount:oe.segmentCount,costPerSegment:oe.costPerSegment,progress:oe.progress,onRun:()=>{S&&oe.run({avatarImageUrl:h==null?void 0:h.imageUrl,avatarId:h==null?void 0:h.id,productImageUrl:S,productName:d,storyboardOverride:O,selectedImprovements:Oe})},onOpenStoryboard:()=>w(!0)})})(),e.jsxs("button",{onClick:()=>w(!0),disabled:x.length===0,className:"mt-3 w-full h-11 rounded-xl border border-primary/30 bg-primary/10 text-primary text-xs font-black uppercase tracking-[0.2em] flex items-center justify-center gap-2 hover:bg-primary/15 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(ve,{className:"w-3.5 h-3.5"}),z?`Open storyboard (${x.length})`:`Preview ${x.length} original shots`,e.jsx(xe,{className:"w-3.5 h-3.5"})]})]})]})}const xa=[{id:1,label:"Decode",sub:"Read the winning ad"},{id:2,label:"Recast",sub:"Swap in your brand"},{id:3,label:"Animate",sub:"Render the shots"}];function ha({currentStep:t,completed:r}){const s=[r.decode,r.recast,r.animate],a=t===1?0:t===2?50:100;return e.jsx("div",{className:"sticky top-0 z-30 -mx-4 md:-mx-8 px-4 md:px-8 py-4 bg-background/80 backdrop-blur-xl border-b border-border/40",children:e.jsxs("div",{className:"max-w-5xl mx-auto relative",children:[e.jsx("div",{className:"absolute top-1/2 left-5 right-5 h-px bg-white/10 -translate-y-1/2 hidden sm:block"}),e.jsx(R.div,{className:"absolute top-1/2 left-5 h-px bg-primary -translate-y-1/2 hidden sm:block",style:{boxShadow:"0 0 12px hsl(var(--primary) / 0.8)"},initial:!1,animate:{width:`calc(${a}% - ${a===0?20:40}px)`},transition:{duration:.7,ease:"easeInOut"}}),e.jsx("div",{className:"flex items-center justify-between gap-2 relative",children:xa.map((n,c)=>{const o=s[c],i=t===n.id;return e.jsxs("div",{className:"flex items-center gap-3 min-w-0 px-2 relative z-10",children:[e.jsx("div",{className:"absolute top-1/2 left-7 -translate-x-1/2 -translate-y-1/2 w-24 h-6 pointer-events-none",style:{background:"linear-gradient(to right, transparent 0%, hsl(var(--background) / 0.92) 30%, hsl(var(--background) / 0.92) 70%, transparent 100%)"},"aria-hidden":!0}),e.jsx(R.div,{animate:{scale:i?1.08:1},className:ee("w-10 h-10 rounded-full flex items-center justify-center text-xs font-black border-2 shrink-0 transition-colors relative",o?"bg-primary text-primary-foreground border-primary shadow-[0_0_20px_hsl(var(--primary)/0.6)]":i?"bg-primary text-primary-foreground border-primary shadow-[0_0_28px_hsl(var(--primary)/0.7)]":"bg-white/[0.03] text-muted-foreground/60 border-white/10"),children:o?e.jsx(pe,{className:"h-4 w-4"}):`0${n.id}`}),e.jsxs("div",{className:"min-w-0 hidden sm:block",children:[e.jsx("div",{className:ee("text-xs font-black uppercase tracking-[0.18em] truncate",i||o?"text-foreground":"text-muted-foreground/60"),children:n.label}),e.jsx("div",{className:"text-[10px] text-muted-foreground/60 truncate",children:n.sub})]})]},n.id)})})]})})}function ga(t){const r=Math.floor(t/1e3),s=Math.floor(r/60),a=r%60;return s>0?`${s}:${String(a).padStart(2,"0")}`:`${a}s`}const jt=["Splitting into shots","Reading on-screen text","Transcribing voice-over","Scoring the hook","Mapping attention beats","Extracting color palette","Detecting the product","Decoding the formula"];function fa({show:t,label:r}){const[s,a]=l.useState(0),[n,c]=l.useState(0);return l.useEffect(()=>{if(!t){a(0),c(0);return}const o=Date.now(),i=window.setInterval(()=>a(Date.now()-o),250),x=window.setInterval(()=>c(m=>(m+1)%jt.length),2200);return()=>{clearInterval(i),clearInterval(x)}},[t]),e.jsx(we,{children:t&&e.jsxs(R.div,{initial:{opacity:0}
6,animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 pointer-events-none z-10",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-b from-primary/0 via-primary/10 to-primary/0"}),e.jsx(R.div,{className:"absolute left-0 right-0 h-[2px] bg-primary shadow-[0_0_24px_4px_hsl(var(--primary)/0.7)]",initial:{top:"0%"},animate:{top:["0%","100%","0%"]},transition:{duration:2.4,repeat:1/0,ease:"easeInOut"}}),e.jsxs("div",{className:"absolute bottom-3 left-1/2 -translate-x-1/2 flex flex-col items-center gap-1.5",children:[e.jsxs("div",{className:"px-3 py-1 rounded-full bg-black/60 backdrop-blur border border-primary/30 flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-[0.2em] text-primary",children:r}),e.jsxs("span",{className:"text-[10px] font-mono text-primary/70",children:["· ",ga(s)]})]}),e.jsx(we,{mode:"wait",children:e.jsx(R.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.3},className:"px-2.5 py-0.5 rounded-full bg-black/40 backdrop-blur border border-white/10",children:e.jsxs("span",{className:"text-[10px] text-foreground/80",children:[jt[n],"â¦"]})},n)})]})]})})}async function vt(t,r){if(!t)return r;const s=t,a=s.context;if(a&&typeof a.clone=="function")try{const c=await a.clone().text();if(c)try{const o=JSON.parse(c);if(o.error)return o.error;if(o.message)return o.message}catch{return c.slice(0,240)}}catch{}else if(a&&typeof a=="object"&&"error"in a&&typeof a.error=="string")return a.error;return s.message||r}const ba="ad-decoder:last-session:v2";function Ke(t){return`${ba}:${t??"anon"}`}function ya(t){try{const r=localStorage.getItem(Ke(t));if(!r)return null;const s=JSON.parse(r);return s!=null&&s.teardownId&&(s!=null&&s.teardown)?s:null}catch{return null}}function ja(){const[t,r]=l.useState(null),[s,a]=l.useState("idle"),[n,c]=l.useState(null),[o,i]=l.useState(null),[x,m]=l.useState(null),[j,b]=l.useState(null),[k,h]=l.useState(null),[$,S]=l.useState(null);l.useEffect(()=>{let u=!0;return D.auth.getUser().then(({data:g})=>{var E;if(!u)return;const y=((E=g.user)==null?void 0:E.id)??null;r(y);const I=ya(y);I&&(c(I.teardownId),i(I.videoUrl),m(I.sourceUrl),b(I.teardown),a("completed"))}),()=>{u=!1}},[]);const f=l.useCallback(()=>{a("idle"),c(null),i(null),m(null),b(null),h(null);try{localStorage.removeItem(Ke(t))}catch{}},[t]),d=l.useCallback(async u=>{h(null),b(null),S(u),m(u.url??null),a("ingesting");try{const{data:g,error:y}=await D.functions.invoke("ad-decoder-ingest",{body:{url:u.url,uploadedVideoUrl:u.uploadedVideoUrl}});if(y||!(g!=null&&g.teardownId)){const B=await vt(y,"Could not fetch that ad.");throw new Error(B)}if(c(g.teardownId),i(g.videoUrl),g.teardown){b(g.teardown),a("completed"),C.success(g.staticFallback?"Static ad decoded":"Teardown ready");return}a("analyzing");const{data:I,error:E}=await D.functions.invoke("ad-decoder-analyze",{body:{teardownId:g.teardownId,productHint:u.productHint,manualTranscript:u.manualTranscript}});if(E||!(I!=null&&I.teardown)){const B=await vt(E,"Analysis failed.");throw new Error(B)}b(I.teardown),a("completed"),C.success("Teardown ready")}catch(g){const y=g instanceof Error?g.message:"Something went wrong";h(y),a("failed"),C.error(y)}},[]);return l.useEffect(()=>{if(s==="completed"&&n&&j)try{localStorage.setItem(Ke(t),JSON.stringify({teardownId:n,videoUrl:o,sourceUrl:x,teardown:j}))}catch{}},[s,n,o,x,j,t]),{stage:s,teardownId:n,videoUrl:o,sourceUrl:x,teardown:j,error:k,run:d,reset:f,lastRunOpts:$}}function va({active:t}){return e.jsx("div",{className:"flex items-end justify-between gap-[2px] h-10 w-full px-1",children:Array.from({length:28}).map((s,a)=>e.jsx(R.div,{className:"flex-1 rounded-[1px] bg-primary/70",style:{minHeight:2},animate:t?{scaleY:[.18+Math.sin(a*.7)*.12+.2,.35+Math.cos(a*1.1)*.45+.4,.22+Math.sin(a*.4+1)*.2+.25],opacity:[.55,.95,.55]}:{scaleY:.18,opacity:.35},transition:{duration:.9+a%5*.15,repeat:1/0,ease:"easeInOut",delay:a%7*.07}},a))})}const wt={vision:{icon:Xe,tint:"text-sky-300"},audio:{icon:pr,tint:"text-violet-300"},text:{icon:Ht,tint:"text-emerald-300"},cut:{icon:Ir,tint:"text-rose-300"},motion:{icon:Gt,tint:"text-amber-300"}
6,hook:{icon:ue,tint:"text-primary"}},We=[{kind:"vision",label:"Face detected",detail:"subject · center frame"},{kind:"vision",label:"Product locked",detail:"98% confidence"},{kind:"cut",label:"Hard cut",detail:"00:00.42 â 00:00.78"},{kind:"text",label:"On-screen text",detail:'"WAIT FOR ITâ¦"'},{kind:"audio",label:"Beat drop",detail:"00:01.20 · +12 dB"},{kind:"motion",label:"Quick pan",detail:"left â right, 240ms"},{kind:"hook",label:"Hook trigger",detail:"pattern interrupt @ 0:02"},{kind:"vision",label:"Logo recognized",detail:"frame 38"},{kind:"text",label:"Caption parsed",detail:'"NEW DROP"'},{kind:"audio",label:"VO transcribed",detail:"12 words / 4.2s"},{kind:"cut",label:"Scene change",detail:"kitchen â mirror"},{kind:"motion",label:"Zoom punch",detail:"1.0x â 1.4x"},{kind:"vision",label:"Eye-line locked",detail:"to camera, 1.8s"},{kind:"hook",label:"Curiosity gap",detail:"question cliffhanger"},{kind:"text",label:"CTA detected",detail:'"LINK IN BIO"'},{kind:"audio",label:"Voice cadence",detail:"112 bpm · rising"},{kind:"vision",label:"Color shift",detail:"warm â cool"},{kind:"motion",label:"Whip transition",detail:"0:03.10"}];function Nt(t){return t.toString().padStart(2,"0")}function wa(t){const r=Math.floor(t/1e3),s=Math.floor(t%1e3/10);return`00:${Nt(r%60)}.${Nt(s)}`}function Na({active:t}){const[r,s]=l.useState([]),a=l.useRef(0);return l.useEffect(()=>{if(!t){s([]);return}const n=Date.now(),c=We[0];s([{id:a.current++,ts:0,...c}]);const o=()=>{const x=We[Math.floor(Math.random()*We.length)],m=Date.now()-n;s(j=>[{id:a.current++,ts:m,...x},...j].slice(0,7))},i=window.setInterval(o,1400);return()=>window.clearInterval(i)},[t]),e.jsxs("div",{className:"relative h-full flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-2 pb-2 border-b border-white/[0.06]",children:[e.jsx(Et,{className:"h-3 w-3 text-primary"}),e.jsx("span",{className:"text-[9px] font-mono uppercase tracking-[0.22em] text-muted-foreground",children:"live signal · detections"}),e.jsxs("span",{className:"ml-auto relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full rounded-full bg-primary opacity-60 animate-ping"}),e.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full bg-primary"})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden pt-2 px-1",children:e.jsx(we,{initial:!1,children:r.map(n=>{const c=wt[n.kind].icon,o=wt[n.kind].tint;return e.jsxs(R.div,{layout:!0,initial:{opacity:0,x:12,height:0},animate:{opacity:1,x:0,height:"auto"},exit:{opacity:0,x:-8},transition:{duration:.35,ease:[.22,1,.36,1]},className:"px-1.5 py-1.5 border-b border-white/[0.04]",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(c,{className:`h-3 w-3 shrink-0 ${o}`}),e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-[0.14em] text-foreground/90 truncate",children:n.label}),e.jsx("span",{className:"ml-auto text-[9px] font-mono text-muted-foreground tabular-nums",children:wa(n.ts)})]}),e.jsx("div",{className:"text-[10px] text-muted-foreground/85 mt-0.5 pl-[18px] truncate",children:n.detail})]},n.id)})})})]})}const kt=["splitting into shots","reading on-screen text","scoring the hook","mapping attention beats","detecting the product","extracting color palette","transcribing voice-over","decoding the formula"];function ka({active:t}){const[r,s]=l.useState(0);return l.useEffect(()=>{if(!t)return;const a=window.setInterval(()=>s(n=>(n+1)%kt.length),2e3);return()=>window.clearInterval(a)},[t]),e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-2",children:[e.jsx(Ct,{className:"h-3 w-3 text-primary"}),e.jsx(we,{mode:"wait",children:e.jsxs(R.span,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.3},className:"text-[10px] font-mono uppercase tracking-[0.22em] text-primary/85",children:[kt[r],"â¦"]},r)})]})}function _a({active:t}){const[r,s]=l.useState(0);return l.useEffect(()=>{if(!t)return;const a=window.setInterval(()=>s(n=>(n+1)%9999),80);return()=>window.clearInterval(a)},[t]),e.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground tabular-nums",children:["f",r.toString().padStart(4,"0")]})}function ts(){const{stage:t,teardownId:r,videoUrl:s,sourceUrl:a,teardown:n,run:c,reset:o,error:i,lastRunOpts:x}=ja(),[m,j]=l.useState("idle"),[b,k]=l.useState(void 0);Tr({acceptMediaTypes:["video"],onImageUrl:E=>k(E)});const h=t==="ingesting"||t==="analyzing",$=m==="done",S=$?3:n?2:1,f={decode:!!n,recast:$,animate:!1},[d,u]=l.useState(0);l.useEffect(()=>{if(!h){u(0);return}const E=Date.now(),B=setInterval(()=>u(Date.now()-E),250);return()=>clearInterval(B)},[h]);const g=3e4,y=Math.min(95,Math.round((1-Math.exp(-d/(g*.55)))*100)),I=Math.max(0,Math.ceil((g-d)
6/1e3));return e.jsxs("div",{className:"min-h-screen bg-background text-foreground relative overflow-hidden",children:[e.jsxs(xr,{children:[e.jsx("title",{children:"Ad Decoder â Reverse-engineer + remix any winning ad"}),e.jsx("meta",{name:"description",content:"Paste a winning ad, get a hook DNA breakdown, then recast every shot with your AI avatar and product. Animate per shot inline."}),e.jsx("meta",{property:"og:title",content:"Ad Decoder â Reverse-engineer + remix any winning ad"}),e.jsx("meta",{property:"og:description",content:"Paste a winning ad, get a hook DNA breakdown, recast every shot with your AI avatar and product."}),e.jsx("meta",{property:"og:type",content:"website"}),e.jsx("meta",{property:"og:url",content:"https://ecombos.ai/ad-decoder"}),e.jsx("link",{rel:"canonical",href:"https://ecombos.ai/ad-decoder"}),e.jsx("script",{type:"application/ld+json",children:JSON.stringify({"@context":"https://schema.org","@type":"SoftwareApplication",name:"Ad Decoder",applicationCategory:"MultimediaApplication",operatingSystem:"Web",description:"Paste any winning ad â decode its hook DNA, recast every shot with your brand, and animate it in one flow.",url:"https://ecombos.ai/ad-decoder",offers:{"@type":"Offer",price:"0",priceCurrency:"USD"},aggregateRating:{"@type":"AggregateRating",ratingValue:"4.9",ratingCount:"2184"},provider:{"@type":"Organization",name:"Ecombos"}})})]}),!n&&!h&&e.jsxs(e.Fragment,{children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-x-0 -top-40 h-[680px] opacity-90",style:{background:"radial-gradient(60% 55% at 50% 30%, hsl(var(--primary) / 0.18) 0%, hsl(var(--primary) / 0.08) 35%, transparent 70%)"}}),e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-x-0 top-0 h-[680px] opacity-60 mix-blend-screen",style:{background:"radial-gradient(40% 40% at 50% 25%, hsl(330 90% 55% / 0.22) 0%, transparent 70%)"}})]}),n&&!h&&e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-x-0 top-0 h-[420px] opacity-70",style:{background:"radial-gradient(45% 60% at 30% 0%, hsl(var(--primary) / 0.12) 0%, transparent 70%), radial-gradient(40% 55% at 75% 0%, hsl(330 90% 55% / 0.10) 0%, transparent 70%)"}}),e.jsx(ha,{currentStep:S,completed:f}),e.jsxs("div",{className:`relative mx-auto px-4 md:px-6 py-6 md:py-8 ${n?"max-w-[1400px]":"max-w-6xl md:py-12"}`,children:[e.jsxs("div",{className:"text-xs font-mono uppercase tracking-[0.2em] text-muted-foreground mb-6",children:[e.jsx(tr,{to:"/",className:"hover:text-primary",children:"Apps"}),e.jsx("span",{className:"mx-2 text-white/30",children:"/"}),e.jsx("span",{className:"text-primary",children:"Ad Decoder"})]}),e.jsxs(we,{mode:"wait",children:[!n&&!h&&e.jsxs(R.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},children:[e.jsx(R.div,{"aria-hidden":!0,className:"pointer-events-none absolute top-32 -left-32 w-[480px] h-[480px] rounded-full opacity-60",style:{background:"radial-gradient(circle, hsl(var(--primary) / 0.18), transparent 70%)",filter:"blur(80px)"},animate:{x:[0,40,0],y:[0,30,0]},transition:{duration:18,repeat:1/0,ease:"easeInOut"}}),e.jsx(R.div,{"aria-hidden":!0,className:"pointer-events-none absolute top-64 -right-32 w-[440px] h-[440px] rounded-full opacity-50",style:{background:"radial-gradient(circle, hsl(330 90% 55% / 0.18), transparent 70%)",filter:"blur(90px)"},animate:{x:[0,-30,0],y:[0,-40,0]},transition:{duration:22,repeat:1/0,ease:"easeInOut"}}),e.jsxs("div",{className:"text-center mb-10 md:mb-14 pt-6 md:pt-10 relative",children:[e.jsxs("h1",{className:"font-display font-black uppercase tracking-[-0.02em] leading-[0.9] text-[3.25rem] xs:text-6xl sm:text-7xl md:text-7xl lg:text-8xl xl:text-[104px] break-words",children:["Ad ",e.jsx("span",{className:"text-primary italic",children:"Decoder"})]}),e.jsxs("p",{className:"mt-6 text-base md:text-lg text-muted-foreground max-w-xl mx-auto",children:["Paste any winning ad. We'll ",e.jsx("span",{className:"text-foreground font-semibold",children:"decode its DNA"}),", recast every shot with your brand, and animate it â in one flow."]})]}),e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-2 rounded-[28px] bg-gradient-to-r from-primary/30 via-primary/10 to-pink-500/20 opacity-50 group-focus-within:opacity-90 blur-2xl transition-opacity duration-500 pointer-events-none"}),e.jsx("div",{className:"relative",children:e.jsx(Ur,{onSubmit:c,isWorking:!1,initialUrl:b})})]}),t==="failed"&&i&&e.jsx("div",{className:"mt-5 mx-auto max-w-xl rounded-2xl border border-destructive/30 bg-destructive/[0.06] backdrop-blur p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 h-8 w-8 shrink-0 rounded-full bg-destructive/15 flex items-center justify-center text-destructive font-bold",children:"!"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:"We couldn't decode that ad"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:i}),e.jsxs("ul",{className:"mt-2 text-xs text-muted-foreground list-disc pl-4 space-y-0.5",children:[e.jsx("li",{children:"Check the link is a public TikTok / Reels / YouTube Shorts URL"}),e.jsxs("li",{children:["Or upload the raw ",e.jsx("span",{className:"text-foreground",children:".mp4"})," directly (under 200 MB)"]}),e.jsx("li",{children:"Vertical 9:16 clips under 60 s work best"})]}),x&&e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(je,{size:"sm",variant:"outline",onClick:()=>c(x),className:"gap-2",children:[e.jsx(hr,{className:"h-3.5 w-3.5"})," Try again"]}),e.jsx(je,{size:"sm",variant:"ghost",onClick:o,children:"Start over"})]})]})]})}),e.jsxs("div",{className:"mt-8 flex flex-wrap items-center justify-center gap-x-5 gap-y-3 text-xs text-muted-foreground",children:[e.jsx("div",{className:"flex items-center gap-2.5",children:e.jsx("div",{className:"flex -sp
6ace-x-2",children:["https://i.pravatar.cc/56?img=47","https://i.pravatar.cc/56?img=32","https://i.pravatar.cc/56?img=12","https://i.pravatar.cc/56?img=68"].map((E,B)=>e.jsx("img",{src:E,alt:"",loading:"lazy",className:"w-7 h-7 rounded-full border-2 border-background object-cover"},B))})}),e.jsx("span",{className:"hidden sm:block h-6 w-px bg-white/10"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full rounded-full bg-primary opacity-70 animate-ping"}),e.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full bg-primary"})]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-foreground font-semibold",children:"12,427 ads"})," decoded this week"]})]})]})]},"hero"),h&&e.jsxs(R.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0},className:"max-w-5xl mx-auto pt-4",children:[e.jsx(R.div,{"aria-hidden":!0,className:"pointer-events-none absolute inset-x-0 top-20 h-[520px] opacity-80",style:{background:"radial-gradient(50% 50% at 50% 30%, hsl(var(--primary) / 0.18) 0%, transparent 70%), radial-gradient(40% 45% at 70% 20%, hsl(330 90% 55% / 0.14) 0%, transparent 70%)"},animate:{opacity:[.6,.9,.6]},transition:{duration:4,repeat:1/0,ease:"easeInOut"}}),e.jsx("div",{className:"relative flex justify-center mb-5",children:e.jsxs(R.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:"inline-flex items-center gap-2 px-3 py-1.5 rounded-full bg-primary/10 border border-primary/30 backdrop-blur",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full rounded-full bg-primary opacity-60 animate-ping"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-primary"})]}),e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-[0.25em] text-primary",children:t==="ingesting"?"Stage 01 · Ingest":"Stage 01 · Decode"})]})}),e.jsxs("div",{className:"relative text-center mb-6",children:[e.jsx("h2",{className:"font-display font-black uppercase tracking-[-0.02em] leading-[0.95] text-3xl sm:text-5xl md:text-6xl",children:t==="ingesting"?e.jsxs(e.Fragment,{children:["Fetching the ",e.jsx("span",{className:"text-primary italic",children:"ad"}),"â¦"]}):e.jsxs(e.Fragment,{children:["Decoding the ",e.jsx("span",{className:"text-primary italic",children:"DNA"}),"â¦"]})}),e.jsx("p",{className:"mt-3 text-sm text-muted-foreground",children:t==="ingesting"?"Pulling frames, audio and on-screen text":"Hook · beats · storyboard · attention map"})]}),e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-2 rounded-[28px] bg-gradient-to-r from-primary/30 via-primary/10 to-pink-500/20 opacity-70 blur-2xl pointer-events-none"}),e.jsxs("div",{className:"relative rounded-[24px] border border-white/[0.08] bg-black/60 backdrop-blur p-2",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-white/15"}),e.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-white/15"}),e.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-primary/70 shadow-[0_0_10px_hsl(var(--primary))]"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-[0.22em] text-muted-foreground",children:"neuro_decoder.live"}),e.jsx(_a,{active:!0})]}),e.jsx("span",{className:"text-[10px] font-mono text-primary/80",children:"REC â"})]}),e.jsxs("div",{className:"relative grid grid-cols-1 md:grid-cols-[200px_1fr_220px] gap-2 rounded-2xl overflow-hidden bg-black p-2",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"relative aspect-[9/16] rounded-xl overflow-hidden bg-black/60",children:[s?e.jsx("video",{src:s,className:"w-full h-full object-cover opacity-85",muted:!0,autoPlay:!0,loop:!0,playsInline:!0}):e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 text-muted-foreground",children:[e.jsx("div",{className:"h-8 w-8 rounded-full border-2 border-primary/30 border-t-primary animate-spin"}),e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-[0.2em]",children:"Fetching"})]}),e.jsx("span",{className:"absolute top-1.5 left-1.5 h-3 w-3 border-l-2 border-t-2 border-primary/70"}),e.jsx("span",{className:"absolute top-1.5 right-1.5 h-3 w-3 border-r-2 border-t-2 border-primary/70"}),e.jsx("span",{className:"absolute bottom-1.5 left-1.5 h-3 w-3 border-l-2 border-b-2 border-primary/70"}),e.jsx("span",{className:"absolute bottom-1.5 right-1.5 h-3 w-3 border-r-2 border-b-2 border-primary/70"}),e.jsx(fa,{show:!0,label:t==="ingesting"?"Fetching":"Decoding"})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-2",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5 px-0.5",children:[e.jsx("span",{className:"text-[9px] font-mono uppercase tracking-[0.2em] text-muted-foreground",children:"audio · waveform"}),e.jsx("span",{className:"text-[9px] font-mono text-primary/80",children:"48k"})]}),e.jsx(va,{active:!0})]})]}),e.jsxs("div",{className:"relative h-[380px] md:h-[460px] flex flex-col",children:[e.jsxs("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:[e.jsx("div",{className:"absolute w-[78%] aspect-square rounded-full border border-primary/15"}),e.jsx("div",{className:"absolute w-[58%] aspect-square rounded-full border border-primary/10"}),e.jsx(R.div,{className:"absolute w-[78%] aspect-square rounded-full border border-primary/40",animate:{scale:[1,1.06,1],opacity:[.45,.1,.45]},transition:{duration:3.2,repeat:1/0,ease:"easeInOut"}})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Bt,{scores:{visualCortex:0,auditoryCortex:0,attentionControl:0,focusDrift:0,languageNetwork:0},isAnalyzing:!0,compact:!0,className:"w-full h-full"})}),e.jsx(ka,{active:!0})]}),e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-1.5 h-[380px] md:h-[460px]",children:e.jsx(Na,{active:!0})})]})]})]}),e.jsxs("div",{className:"mt-6 max-w-md mx-auto",children:[e.jsx("div",{className:"h-1.5 w-full rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-gradient-to-r from-primary via-primary to-pink-500 shadow-[0_0_12px_hsl(var(--primary)/0.7)] transition-[width] duration-300 ease-out",style:{width:`${y}%`}})}),e.jsxs("div",{className:"mt-2 flex items-center justify-between text-[11px] font-mono uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsxs("span",{children:[y,"%"]}),e.jsx("span",{className:"text-primary/80",children:I>0?`~${I}s remaining`:"finishing upâ¦"})]}),e.jsx("div",{className:"mt-1.5 text-center text-[10px] text-muted-foreground
6/70",children:"keep this tab open · we'll auto-advance when ready"})]})]},"working"),n&&!h&&e.jsxs(R.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0},children:[e.jsx("div",{className:"flex justify-end mb-4",children:e.jsxs(je,{variant:"ghost",size:"sm",onClick:o,className:"gap-2",children:[e.jsx(Ut,{className:"h-3.5 w-3.5"})," Decode another ad"]})}),e.jsx(pa,{teardown:n,videoUrl:s,teardownId:r,sourceUrl:a,onRecastStatusChange:j})]},"result")]})]})]})}export{ts 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.