1import{r as s,j as r}from"./react-vendor-DUhHROXo.js";import{s as p}from"./client-DTel1CZI.js";import"./index-BLtzf0SR.js";import"./router-vendor-Dz9PdDzH.js";const U=({projectId:d,onComplete:u})=>{const[i,c]=s.useState("idle"),[W,f]=s.useState(0),[v,_]=s.useState([]),[w,S]=s.useState(null),[y,k]=s.useState(null),[j,E]=s.useState(null);s.useRef(null);const l=s.useCallback(o=>{_(e=>[...e.slice(-299),o]),console.log("[BrowserRenderer]",o)},[]),M=s.useCallback(async(o,e,g)=>{const m=e instanceof Error?e.message:String(e??""),a=m?`${o}: ${m}`:o;l(`ERROR: ${a}`),E(a),c("error");try{g?await p.from("pp_render_jobs").update({status:"failed",log:a}).eq("id",g):await p.from("pp_render_jobs").insert({project_id:d,status:"failed",progress_pct:0,log:a})}catch{}},[l,d]),z=s.useCallback(async()=>{c("rendering-audio"),f(2),_([]),E(null),S(null),k(null);let o;try{l("Dispatching render to server workerâ¦");const{data:e,error:g}=await p.functions.invoke("pp-render-dispatch",{body:{projectId:d}});if(g)throw g;if((e==null?void 0:e.configured)===!1)throw new Error(e.message||"Server render engine is not configured.");if(!(e!=null&&e.success))throw new Error((e==null?void 0:e.error)||"Dispatch failed");o=e.jobId,l(` â Queued (job ${o.slice(0,8)}). Worker is renderingâ¦`),f(5);const m=4e3;let a=0;for(;;){await new Promise(t=>setTimeout(t,m));const{data:h}=await p.from("pp_render_jobs").select("shotstack_render_id").eq("id",o).maybeSingle();if(h!=null&&h.shotstack_render_id)try{await p.functions.invoke("pp-shotstack-poll",{body:{jobId:o}})}catch{}const{data:n,error:P}=await p.from("pp_render_jobs").select("status, progress_pct, log, error_message").eq("id",o).single();if(P)throw new Error(`Polling failed: ${P.message}`);const R=Math.max(5,Math.min(99,Number(n.progress_pct)||0));if(f(R),typeof n.log=="string"&&n.log.length>a){const t=n.log.slice(a).trim();t&&l(t),a=n.log.length}if(R<50?c("rendering-audio"):R<90?c("rendering-video"):c("uploading"),n.status==="completed"||n.status==="complete"){const{data:t}=await p.from("post_production_projects").select("rendered_mp3_url, rendered_mp4_url").eq("id",d).single(),b=t==null?void 0:t.rendered_mp3_url,B=t==null?void 0:t.rendered_mp4_url;b&&S(b),B&&k(B),f(100),c("complete"),l("Server render complete â"),b&&(u==null||u(b));return}if(n.status==="failed")throw new Error(n.error_message||"Worker reported failure")}}catch(e){await M("Render failed",e,o)}},[d,l,M,u]),D={idle:"Ready to render","loading-ffmpeg":"Loading audio/video engineâ¦","fetching-data":"Loading project dataâ¦","downloading-assets":"Downloading audio + video assetsâ¦","building-command":"Building render pipelineâ¦","rendering-audio":"Pass 1/3 â Mastering audioâ¦","rendering-video":"Pass 2â3/3 â Assembling videoâ¦",uploading:"Uploading MP3 + MP4â¦",complete:"Render v3 complete â",error:"Render failed"},x=!["idle","complete","error"].includes(i);return r.jsxs("div",{style:{fontFamily:"'DM Mono','Courier New',monospace",background:"#0d0d0d",border:"1px solid #2a2a2a",borderRadius:"8px",padding:"24px",color:"#e0e0e0",maxWidth:"640px"},children:[r.jsxs("div",{style:{marginBottom:"20px"},children:[r.jsx("div",{style:{fontSize:"11px",letterSpacing:"0.12em",textTransform:"uppercase",color:"#666",marginBottom:"4px"},children:"Post-Production Renderer · v3"}),r.jsx("div",{style:{fontSize:"18px",fontWeight:600,color:"#fff"},children:"Export Episode â MP3 + MP4"}),r.jsx("div",{style:{fontSize:"12px",color:"#555",marginTop:"4px"},children:"Intro · Title Card · Sponsors · Outro · Mastered Audio"})]}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",marginBottom:"16px"},children:[r.jsx("div",{style:{width:"8px",height:"8px",borderRadius:"50%",background:i==="complete"?"#22c55e":i==="error"?"#ef4444":x?"#f59e0b":"#555",boxShadow:x?"0 0 6px #f59e0b":void 0}}),r.jsx("span",{style:{fontSize:"13px",color:"#ccc"},children:D[i]})]}),(x||i==="complete")&&r.jsx("div",{style:{height:"4px",background:"#1e1e1e",borderRadius:"2px",overflow:"hidden",marginBottom:"20px"},children:r.jsx("div",{style:{height:"100%",width:`${W}%`,background:i==="complete"?"#22c55e":"#f59e0b",borderRadius:"2px",transition:"width 0.4s ease"}})}),i==="error"&&j&&r.jsx("div",{style:{background:"#1c0a0a",border:"1px solid #7f1d1d",borderRadius:"6px",padding:"12px",marginBottom:"16
1px",fontSize:"12px",color:"#fca5a5",wordBreak:"break-all"},children:j}),(i==="idle"||i==="error")&&r.jsx("button",{onClick:z,style:{background:"#f59e0b",color:"#000",border:"none",borderRadius:"6px",padding:"10px 24px",fontSize:"13px",fontWeight:700,letterSpacing:"0.04em",cursor:"pointer",marginBottom:"16px",fontFamily:"inherit"},children:i==="error"?"⺠RETRY RENDER":"â¶ RENDER EPISODE (server)"}),i==="complete"&&(w||y)&&r.jsxs("div",{style:{display:"flex",gap:"10px",flexWrap:"wrap",marginBottom:"16px"},children:[w&&r.jsx("a",{href:w,download:`episode-${d.slice(0,8)}.mp3`,style:{display:"inline-block",background:"#22c55e",color:"#000",borderRadius:"6px",padding:"10px 20px",fontSize:"13px",fontWeight:700,letterSpacing:"0.04em",textDecoration:"none"},children:"â MP3 â Spotify / Apple"}),y&&r.jsx("a",{href:y,download:`episode-${d.slice(0,8)}.mp4`,style:{display:"inline-block",background:"#3b82f6",color:"#fff",borderRadius:"6px",padding:"10px 20px",fontSize:"13px",fontWeight:700,letterSpacing:"0.04em",textDecoration:"none"},children:"â MP4 â YouTube / Social"})]}),v.length>0&&r.jsx("div",{style:{background:"#111",border:"1px solid #1e1e1e",borderRadius:"6px",padding:"12px",maxHeight:"220px",overflowY:"auto",fontSize:"11px",lineHeight:"1.6"},children:v.map((o,e)=>r.jsx("div",{style:{color:o.startsWith("ERROR")?"#f87171":o.startsWith(" â")?"#4ade80":o.startsWith(" â ")?"#fbbf24":"#888"},children:o},e))}),x&&r.jsx("div",{style:{marginTop:"12px",fontSize:"11px",color:"#555"},children:"Rendering on the server. You can leave this page â the job will keep running."})]})};export{U as BrowserRenderer,U 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.