1import{r as D}from"./rolldown-runtime.C1f3BsDW.js";import"./http.DWpeO7Ui.js";import{I as S,Jt as U,K as V,Qr as X,Xt as z,dr as Z,tt as F}from"./icons.ChOq_Y4q.js";import{t as ee}from"./react-core.CAMe6Z4j.js";import"./utils.CgzVjNgC.js";import"./state.L8kQliOB.js";import{Ct as re,J as te,Tt as se,Ut as y,bt as O,k as T,ut as Y}from"./entry-client.DX3aUoe5.js";import{n as ae}from"./useFreeTierGate.CwupVhTY.js";import{n as i,t as l}from"./NoticeCenter.0k-H7Gch.js";import{t as o}from"./banner.Do1etl08.js";import{r as oe}from"./filmProgress.BMWLABZx.js";import{t as ne}from"./trial.B9u_I_11.js";var t=D(X(),1),e=D(ee(),1),ie=6e3;const le=({projectUuid:d,castReviewPending:v,castPassRunning:P,frames:c,onShare:C,onRunStarted:x,onScriptStarted:b,onRunningChange:g,runAskedAt:W,startRef:m})=>{const[r,q]=(0,t.useState)(null),[N,I]=(0,t.useState)(!1),{isFreeTier:$,onTrial:J,freeTierOn:K}=ae(),{showUpgrade:E}=re(),_=`mstudio_free_complete_dismissed:${d}`,[Q,R]=(0,t.useState)(()=>O.getItem(_)==="1"),H=(0,t.useCallback)(()=>{O.setItem(_,"1"),R(!0)},[_]),j=(0,t.useRef)(x);(0,t.useEffect)(()=>{j.current=x},[x]);const k=(0,t.useRef)(b);(0,t.useEffect)(()=>{k.current=b},[b]);const n=(0,t.useCallback)(async()=>{try{q((await Y.autoStoryboardStatus(d)).data?.data??null)}catch{}},[d]);(0,t.useEffect)(()=>{n()},[n,v,P,(0,t.useMemo)(()=>{let s=0,a=0;for(const p of c)p.has_image?s+=1:p.last_failed_generation_job&&(a+=1);return`${c.length}:${s}:${a}`},[c]),W]);const h=r?.running??!1;(0,t.useEffect)(()=>(g?.(h),()=>g?.(!1)),[h,g]),(0,t.useEffect)(()=>{if(!h)return;const s=setInterval(()=>{n(),j.current()},ie);return()=>clearInterval(s)},[h,n]);const w=(0,t.useCallback)(async()=>{I(!0);try{const s=await Y.startAutoStoryboard(d);await n(),s.data?.data?.phase==="script"?k.current?.():j.current()}catch(s){const a=s?.response?.status;a!==409&&a!==402&&(te(s)||se.error(s?.response?.data?.message??"Could not start the storyboards. Try again."))}finally{I(!1)}},[d,n]);if((0,t.useEffect)(()=>{if(m)return m.current=w,()=>{m.current=null}},[m,w]),!r?.enabled||v)return null;if(r.running)return c.length>0&&c.every(oe)?null:(0,e.jsx)(i,{id:"auto-storyboard",priority:l.autoStoryboard,label:"Generating storyboards",children:(0,e.jsxs)(o,{icon:(0,e.jsx)(z,{className:"animate-spin text-primary"}),children:[(0,e.jsx)("span",{children:"Generating storyboards for your film."})," ",(0,e.jsx)("span",{className:"text-muted-foreground",children:"You can keep working while this runs."})]})});const G=Math.min(r.remaining,r.window_size),A=`${J?"Your trial":"The first storyboard run"} covers the first ${y(r.window_size,"shot")}.`,B=r.remaining>0&&r.drawn_through>0,u=r.frames_failed??0;if(r.frames_total>0&&r.frames_drawn>=r.frames_total&&r.remaining===0&&u===0&&$&&!Q)return(0,e.jsx)(i,{id:"free-tier-complete",priority:l.autoStoryboard,label:"Your film is boarded",children:(0,e.jsxs)(o,{tone:"attention",icon:(0,e.jsx)(Z,{}),onDismiss:H,actions:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(T,{size:"xs",onClick:()=>E({feature:"generate-video"}),leftIcon:(0,e.jsx)(S,{className:"h-3 w-3"}),children:"See it move"}),C&&(0,e.jsx)(T,{variant:"outline",size:"xs",onClick:C,leftIcon:(0,e.jsx)(V,{className:"h-3 w-3"}),children:"Share it"})]}),children:[(0,e.jsxs)("span",{className:"font-medium",children:["That is your whole film boarded â"," ",y(r.frames_total,"shot"),", scored and voiced."]})," ",(0,e.jsxs)("span",{className:"text-muted-foreground",children:[ne," A plan also turns them into video clips you can export."]})]})});const L=!!r.failed,M=!!r.needs_script;if(!B&&u===0&&!L&&!M)return null;const f=(s,a,p=w)=>(0,e.jsxs)(T,{size:"xs",onClick:p,disabled:N,children:[N?(0,e.jsx)(z,{className:"h-3 w-3 animate-spin","aria-hidden":"true"}):(0,e.jsx)(a,{className:"h-3 w-3","aria-hidden":"true"}),s]});return(0,e.jsxs)(e.Fragment,{children:[M?(0,e.jsx)(i,{id:"storyboard-needs-script",priority:l.failures,label:"Script not written",children:(0,e.jsx)(o,{actions:f("Generate the storyboard",S),children:"This film has no script yet. Generating the storyboard writes it first."})}):L&&(0,e.jsx)(i,{id:"storyboard-run-failed",priority:l.failures,label:"Storyboard stopped",children:(0,e.jsx)(o,{actions:f("Try again",F),children:r.error_message??"Generating stopped before any storyboards were ready."})}),u>0&&(0,e.jsx)(i,{id:"failed-shots",priority:l.failures,label:`${y(u,"shot")} failed`,children:(0,e.jsxs)(o,{actions:f("Draw them again",F),children:["Could not draw the storyboard for ",y(u,"shot"),"."]})}),B&&(0,e.jsx)(i,{id:"auto-storyboard",priority:l.autoStoryboard,label:"Storyboards left to generate",children:$&&K?(0,e.jsx)(o,{actions:f(`Generate the next ${G}`,U,()=>E({feature:"generate-image",message:`${A} Start your plan to generate the storyboard for the rest.`})),children:A}):(0,e.jsx)(o,{actions:f(`Generate the next ${G}`,S),children:"More shots are ready for a storyboard."})})]})};var je=le;export{le as AutoStoryboardBanner,je 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.