PageSourceSearch

https://mstudio.ai/build/assets/StoryboardCanvas.Z60PDj_o.js

js mstudio.ai collected 2026-10-05 12:17:56 UTC 167,367 bytes, 8 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TransitionPicker.BauYrp91.js","assets/entry-client.DX3aUoe5.js","assets/inertia.BE4YqsTM.js","assets/http.DWpeO7Ui.js","assets/rolldown-runtime.C1f3BsDW.js","assets/icons.ChOq_Y4q.js","assets/utils.CgzVjNgC.js","assets/react-core.CAMe6Z4j.js","assets/state.L8kQliOB.js","assets/app.BpxBHA-A.css","assets/dist.D4LCotyC.js","assets/dist.CoNAZqlp.js","assets/dist.DxccqHSW.js","assets/dist.C1cc-Zbw.js","assets/dist.DbqQa_sy.js","assets/es2015.Cr2X04_P.js","assets/slider.BZoarXCr.js","assets/dist.BhzTvz6X.js","assets/transitionConfig.CdUOd4v5.js","assets/dialog.Bb7MGeDP.js","assets/section-label.Cq6cQeLu.js","assets/FramePairEditor.C5GYFgik.js","assets/useAIProviders.DpznsHqJ.js","assets/useFramePairCharacters.BTpVDOC8.js","assets/characterMention.DcxgzALo.js","assets/projectStore.B74RetxK.js","assets/MotionEditor.CyEx2Eo8.js","assets/dist.D4237Rk6.js","assets/dropdown-menu.D1MnQ7U0.js","assets/select.vYEvBl4E.js","assets/dist.zmknLG-d.js","assets/input.GzdAc1Aj.js","assets/dist.B-JETxGF.js","assets/DemoTutorialModal.n7nzQPTB.js","assets/AnimationShotParts.B3fNwJfT.js","assets/badge.CK53iWwP.js","assets/segmented.DHcH2lTJ.js","assets/switch.D3Vh3rjF.js","assets/shotMedium.DYKLpru1.js","assets/DeletedMediaNote.4QDTVou1.js","assets/GenerationTimingLabel.K5WCvCRk.js","assets/PromptReferencesRow.Dil-fpz5.js","assets/ShotNavigator.Bf6k38ex.js","assets/ReviewShotsDialog.B0UjM6nz.js","assets/MentionText.Do-0ghUN.js","assets/locationStore.DwRNJtUf.js","assets/motionEditorConstants.DV7TNLB3.js","assets/AddLocationButton.6fxYeEMu.js","assets/useLocationActions.DjW0qbmO.js","assets/usePolling.mKMvMVRm.js","assets/useGenerationJobPoller.BUhANv0M.js","assets/useLocationMentions.Ch75-YXw.js","assets/filmLookStore.CfGPY-XO.js","assets/MentionTextarea.BoOwGw9M.js","assets/ModelPicker.B9qrijHK.js","assets/Tooltip.D5vWPvw2.js","assets/kbd.F_PH3ELp.js","assets/sheet.auH2KWa8.js","assets/projectLanguages.AcWHm09B.js","assets/useFreeTierGate.CwupVhTY.js","assets/usePreparePrompts.OtIhvjD2.js","assets/savedDraft.D7Sdk2MK.js","assets/sceneAudio.Do-Wp-E3.js","assets/spokenLength.DIzJV6he.js","assets/videoQuality.DDiClgPC.js","assets/AnimationEditor.BF-0lfx5.js","assets/VidstackPlayer.CObwjGn4.js","assets/TimelineEditor.qDd7h1nG.js","assets/timeline.466nS0lx.js","assets/useMediaQuery.CHA9c3gs.js","assets/colors.BuVhGii5.js","assets/filmProgress.BMWLABZx.js","assets/FrameEditorSidebar.Duq-I0lF.js","assets/FrameNode.BJPG-Sxj.js","assets/reactflow.BF3Fu-2u.js","assets/reactflow.spzl8Vqr.css","assets/directorStore.Hi7OPK7P.js","assets/label.D8t8fk_6.js","assets/FrameVersionHistory.B9DWBof-.js","assets/BestPracticeTip.vi3UQdmd.js","assets/Tabs.CLPFpYPu.js","assets/useBeatAligned.B5qIIZyh.js","assets/bestPractices.CtL0Jx0E.js","assets/AudioTrackEditorSidebar.C31xXGHn.js","assets/ExportModal.Mj-YrjKy.js","assets/QuickActions.CHHh7ufn.js","assets/clipLevelling.DXCqATC4.js","assets/directorSessionStore.BZC43bcK.js","assets/AudioGenerationModal.Bvs-C8vH.js","assets/MusicGenerationModal.3M7beR6F.js","assets/AssetGalleryModal.DBIZWl9v.js","assets/AssetGalleryModal.DteaM05Z.js","assets/imageValidation.BrtKjMLv.js","assets/ImportAssetsModal.CAdyaFRA.js","assets/ShareModal.D9N4WEer.js","assets/PreviewModal.DPdhlJFJ.js","assets/useFrameTransition.CCyvsxSP.js","assets/useSceneAudio.CcvzsUuI.js","assets/ConnectChatGptModal.DyTYlJ-k.js","assets/ConnectChatGptModal.-2T2bH-M.js","assets/connectClients.ChEbDYfN.js","assets/StoryDialog.BRy-LCta.js","assets/FilmLookDialog.C-5jROuI.js","assets/LookStep.CIeRezzD.js","assets/LocationPanel.BIYbZa-u.js","assets/LocationCard.721G6Ja_.js","assets/CharacterPanel.CkgJkpn9.js","assets/index.es.DWqa0lfv.js","assets/CharacterViewModal.Dgj8ZNyJ.js","assets/CharacterModal.ehp1Mvsj.js","assets/DesignSheetPreviewModal.Itvufz0h.js","assets/CastingBanner.Dk5V0MLe.js","assets/CastSetupModal.DHx49JhQ.js","assets/CastReview.HgcIjw9L.js","assets/AutoStoryboardBanner.CbTmov-Y.js","assets/NoticeCenter.0k-H7Gch.js","assets/banner.Do1etl08.js","assets/trial.B9u_I_11.js","assets/FilmPlanReviewDialog.Dn1C9kk2.js","assets/CharacterReviewBanner.S305396r.js","assets/ScriptLengthBanner.Chf6bBEc.js","assets/DirectorAvatar.r9U0J-HX.js","assets/DirectorPortrait.B755ZtHg.js","assets/DirectorPanel.CZzcRZsP.js","assets/PreviewPanel.DJ9O7shr.js"])))=>i.map(i=>d[i]);
2import{r as Wo}from"./rolldown-runtime.C1f3BsDW.js";import{r as Ks,t as Il}from"./inertia.BE4YqsTM.js";import{i as Dl}from"./http.DWpeO7Ui.js";import{Bn as $l,Cr as Bo,Dt as Ll,Et as Gl,Gr as Oo,I as Lt,Jn as Yo,Jt as Js,K as zl,L as Vl,Ln as We,Lr as bo,Mr as Wl,N as Bl,Nn as vo,Nr as Ol,Pn as Yl,Pt as Hl,Q as ql,Qn as Kl,Qr as Jl,Qt as Xl,S as Xs,Sn as Ql,T as Ho,Tn as yo,Tt as Zl,Wt as Ul,X as ec,Xt as xe,Zt as tc,an as sc,ct as cs,dn as 
2nc,dr as $t,et as rc,fn as ac,ft as oc,gn as ic,hn as wo,ht as lc,i as Gt,it as cc,lr as qo,m as Ko,on as dc,q as uc,r as Jo,rn as mc,rr as hc,sn as Qs,tn as fc,tt as pc,ut as So,vt as gc,wr as tn,wt as xc,x as bc,xr as vc,xt as Xo,z as yc}from"./icons.ChOq_Y4q.js";import{t as wc}from"./react-core.CAMe6Z4j.js";import"./utils.CgzVjNgC.js";import{i as ur,n as Sc,r as _c,t as Xn}from"./state.L8kQliOB.js";import{$ as Qo,A as Zo,At as jc,B as Cc,Ct as hs,D as Nc,Dt as kc,Ht as or,I as Ws,It as Ac,J as os,K as Tc,Kt as Ec,N as Rc,P as ir,Q as is,Tt as S,Ut as F,Z as gt,bt as Uo,i as us,j as ms,jt as te,k as P,kt as Pc,lt as Zs,t as Fc,ut as bt,wt as K,xt as Mc}from"./entry-client.DX3aUoe5.js";import"./segmented.DHcH2lTJ.js";import{t as Ic}from"./input.GzdAc1Aj.js";import"./dist.CoNAZqlp.js";import"./dist.DxccqHSW.js";import"./dist.D4237Rk6.js";import"./dist.BhzTvz6X.js";import"./dist.B-JETxGF.js";import"./dist.zmknLG-d.js";import{r as Us,t as Dc}from"./Tooltip.D5vWPvw2.js";import"./es2015.Cr2X04_P.js";import"./dist.DbqQa_sy.js";import{a as mr,i as hr,n as fr,o as pr,r as gr,t as xr}from"./dialog.Bb7MGeDP.js";import"./dist.D4LCotyC.js";import"./dist.C1cc-Zbw.js";import"./select.vYEvBl4E.js";import"./characterMention.DcxgzALo.js";import"./AssetGalleryModal.DteaM05Z.js";import"./imageValidation.BrtKjMLv.js";import{n as sn}from"./useFreeTierGate.CwupVhTY.js";import{t as ei}from"./badge.CK53iWwP.js";import"./switch.D3Vh3rjF.js";import{i as ds,n as ti,s as si,t as ni}from"./dropdown-menu.D1MnQ7U0.js";import"./PromptReferencesRow.Dil-fpz5.js";import{t as $c}from"./section-label.Cq6cQeLu.js";import{n as Lc}from"./locationStore.DwRNJtUf.js";import{t as Gc}from"./usePolling.mKMvMVRm.js";import{t as zc}from"./index.es.DWqa0lfv.js";import{i as Vc,n as Be,r as Wc,t as Oe}from"./NoticeCenter.0k-H7Gch.js";import{t as rt}from"./banner.Do1etl08.js";import{a as Bc,i as _o,n as Oc,r as jo,t as ue}from"./projectStore.B74RetxK.js";import{t as Yc}from"./directorStore.Hi7OPK7P.js";import{n as Hc,r as ls}from"./directorSessionStore.BZC43bcK.js";import{l as en}from"./shotMedium.DYKLpru1.js";import"./AnimationShotParts.B3fNwJfT.js";import{a as qc,n as Kc}from"./ShotNavigator.Bf6k38ex.js";import{n as Jc,t as Xc}from"./MentionText.Do-0ghUN.js";import{n as Co,o as Qc,s as Zc}from"./ReviewShotsDialog.B0UjM6nz.js";import"./motionEditorConstants.DV7TNLB3.js";import{a as Uc,c as No,d as ed,f as td,g as ri,h as sd,i as nd,m as rd,n as ad,o as od,p as id,r as ld,t as br,u as cd}from"./reactflow.BF3Fu-2u.js";import{a as Mt,c as dd,i as ud,o as md,r as hd,s as Qn,t as fd}from"./FrameNode.BJPG-Sxj.js";import"./DeletedMediaNote.4QDTVou1.js";import{n as ko,r as pd}from"./useAIProviders.DpznsHqJ.js";import{i as gd,n as xd}from"./sceneAudio.Do-Wp-E3.js";import"./videoQuality.DDiClgPC.js";import"./ModelPicker.B9qrijHK.js";import"./useGenerationJobPoller.BUhANv0M.js";import{t as bd}from"./usePreparePrompts.OtIhvjD2.js";import{t as Zn}from"./filmLookStore.CfGPY-XO.js";import{r as Un,t as ai}from"./filmProgress.BMWLABZx.js";import{a as vd}from"./transitionConfig.CdUOd4v5.js";import{i as J,n as lr,r as oi,t as yd}from"./useSceneAudio.CcvzsUuI.js";import{a as wd,i as Sd,t as Ao}from"./trial.B9u_I_11.js";import{n as _d,t as jd}from"./useMediaQuery.CHA9c3gs.js";import{t as Bs}from"./SEO.gPDL2mFy.js";import{n as Cd,r as Nd,t as kd}from"./useDuplicateProject.C3qcWcjs.js";import"./types.D-Isljfl.js";import{t as Ad}from"./QuickShotModal.iHZxjZ_d.js";import{a as Td,i as Ed,n as Rd,o as Pd,p as Fd,r as Md,t as Id}from"./ViewModeSwitch.Ck8uhNFK.js";var r=Wo(Jl(),1),e=Wo(wc(),1),Os="absolute top-full mt-1 bg-card border border-border rounded-lg shadow-lg z-50 py-1",Ys="px-3 py-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",It=(...t)=>t.filter(n=>!!n),xt=({groups:t,onDone:n})=>(0,e.jsx)(e.Fragment,{children:t.filter(i=>i.length>0).map((i,o)=>(0,e.jsxs)(r.Fragment,{children:[o>0&&(0,e.jsx)("div",{role:"separator",className:"h-px bg-border my-1"}),i.map(({label:m,icon:f,onSelect:c,busy:d,checked:g,...v})=>(0,e.jsxs)("button",{type:"button",role:g===void 0?"menuitem":"menuitemradio","aria-checked":g,className:"w-full flex items-center gap-2.5 px-3 py-2 text-sm text-left transition-colors duration-150 hover:bg-surface-hover outline-none focus-visible:bg-secondary focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/50 disabled:opacity-50 disabled:cursor-not-allowed",...v,onClick:()=>{c(),n()},children:[d?(0,e.jsx)(xe,{className:"h-4 w-4 text-muted-foreground flex-shrink-0 animate-spin","aria-hidden":"true"}):(0,e.jsx)(f,{className:"h-4 w-4 text-muted-foreground flex-shrink-0","aria-hidden":"true"}),(0,e.jsx)("span",{className:"flex-1",children:m}),g&&(0,e.jsx)(tn,{className:"h-4 w-4 text-primary","aria-hidden":"true"})]},m))]},o))}),Hs=t=>{if(t.key!=="ArrowDown"&&t.key!=="ArrowUp")return;const n=Array.from(t.currentTarget.querySelectorAll('[role^="menuitem"]:not(:disabled)'));if(n.length===0)return;t.preventDefault();const i=n.indexOf(document.activeElement),o=t.key==="ArrowDown"?1:-1;n[((i<0?o>0?0:n.length-1:i+o)+n.length)%n.length].focus()},Dd=({currentProject:t,frames:n,totalDuration:i,readOnly:o,layout:m,onLayoutChange:f,onAddFrame:c,onAddFrameFromAssets:d,isAddingFrame:g=!1,addFrameDisabled:v=!1,addFrameDisabledReason:x,onSaveProject:b,onPreview:_,onExport:A,onOpenAssetLibrary:C,onOpenShareModal:D,onDuplicateProject:h,isDuplicatingProject:p=!1,onOpenConnectGuide:T,onOpenImportAssets:E,onEditProject:O,onOpenStory:X,onAddAudioTrack:$,onOpenAssistant:k,onOpenDirector:V,onOpenQuickShot:R,onWritePrompts:M,isWritingPrompts:q=!1,onToggleCharacters:G,showCharacters:oe,onToggleLocations:ie,onOpenFilmLook:_e,onTogglePreviewPanel:Te,showPreviewPanel:at})=>{const{characters:je,isGeneratingSheet:fs,fetchCharacters:De}=ir(),{isFreeTier:zt}=sn(),ot=fs||je.some(se=>se.sheet_status==="processing"),[Ye,ps]=(0,r.useState)(!1),He=(0,r.useRef)(null),W=(0,r.useRef)({});(0,r.useEffect)(()=>{let se=!1;je.forEach(re=>{W.current[re.id]==="processing"&&re.sheet_status==="completed"&&(se=!0),W.current[re.id]=re.sheet_status}),se&&(ps(!0),He.current&&clearTimeout(He.current),He.current=setTimeout(()=>{ps(!1)},1e4))},[je]),(0,r.useEffect)(()=>()=>{He.current&&clearTimeout(He.current)},[]),Gc(()=>{t?.uuid&&De(t.uuid)},{enabled:ot,interval:5e3}),(0,r.useEffect)(()=>{t?.uuid&&De(t.uuid)},[t?.uuid,De]);const le=()=>{G&&!oe&&G()},[gs,Vt]=(0,r.useState)(!1),[be,vt]=(0,r.useState)(null),Wt=(0,r.useRef)(null),yt=se=>be===se?Wt:void 0,xs=se=>vt(re=>re===se?null:se),$e=()=>vt(null);(0,r.useEffect)(()=>
2{if(!be)return;const se=qe=>{Wt.current?.contains(qe.target)||vt(null)},re=qe=>{qe.key==="Escape"&&(vt(null),Wt.current?.querySelector("button")?.focus())};return document.addEventListener("pointerdown",se,!0),document.addEventListener("keydown",re),()=>{document.removeEventListener("pointerdown",se,!0),document.removeEventListener("keydown",re)}},[be]);const nn=()=>{Vt(!0)},wt=()=>{window.location.href=o?"/":"/dashboard"},ge=o?"Back to home":"Back to my films",ve=zt?Js:Kl,Bt=t?.uuid?`/dashboard/projects/${t.uuid}/script`:null,bs=[It(O&&{label:"Film details",icon:We,onSelect:O},X&&{label:"Story",icon:Wl,onSelect:X},Bt!==null&&{label:"Script, shot by shot",icon:$l,onSelect:()=>{window.location.href=Bt}},_e&&{label:"Film look",icon:Xo,onSelect:_e},G&&{label:"Characters",icon:Ko,onSelect:G},ie&&{label:"Film sets",icon:Ul,onSelect:ie},M&&{label:q?"Writing prompts…":"Write full prompts",icon:lc,onSelect:M,disabled:q,busy:q},{label:"Share",icon:zl,onSelect:D},h&&{label:p?"Duplicating…":"Duplicate film",icon:hc,onSelect:h,disabled:p,busy:p},E&&{label:"Import files",icon:Yl,onSelect:E},T&&{label:"Connect ChatGPT",icon:Lt,onSelect:T},{label:"Save",icon:ql,onSelect:b}),[{label:"Help and support",icon:fc,onSelect:()=>{window.location.href="/support"}},{label:"Video tutorials",icon:yo,onSelect:()=>window.open("/learn","_blank")}]],Ot=v?x:void 0,Ee=[It({label:g?"Adding a shot…":"Add a shot",icon:We,onSelect:c,disabled:g||v,busy:g,title:Ot},d&&{label:"Add a shot from my files",icon:ac,onSelect:d,disabled:v,title:Ot}),$?[{label:"Add voice",icon:Hl,onSelect:()=>$("voiceover")},{label:"Add music",icon:xc,onSelect:()=>$("music")},{label:"Add sound effects",icon:bo,onSelect:()=>$("sfx")},{label:"Add another timeline",icon:bo,onSelect:()=>$("custom")}]:[],It(R&&{label:"Quick shot",icon:Jo,onSelect:R})],vs=It(!o&&!!t?.uuid&&{label:"Simple view",icon:$t,onSelect:()=>{Rd("simple"),Ks.visit(Fd(t.uuid,"simple"),{preserveScroll:!0})}},!o&&!!t?.uuid&&{label:"Advanced view",icon:mc,onSelect:()=>{},checked:!0}),St=[[{label:"Shots in a row",icon:sc,onSelect:()=>f("line"),checked:m==="line"},{label:"Shots in a grid",icon:dc,onSelect:()=>f("grid"),checked:m==="grid"}],It(Te&&{label:at?"Hide preview panel":"Show preview panel",icon:gc,onSelect:Te},o&&{label:"Video tutorials",icon:yo,onSelect:()=>window.open("/learn","_blank")})],_t=(se,re,qe)=>{const ys=qe;return(0,e.jsxs)(P,{variant:"ghost",size:"sm",className:"gap-1 px-2.5",onClick:()=>xs(se),"aria-haspopup":"menu","aria-expanded":be===se,"data-tour":se==="add"?"header-add-frame":void 0,children:[ys&&(0,e.jsx)(ys,{className:"h-4 w-4","aria-hidden":"true"}),re,(0,e.jsx)(Bo,{className:"h-3.5 w-3.5 text-muted-foreground","aria-hidden":"true"})]})};return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"sticky top-0 z-50 flex items-center justify-between px-2 sm:px-3 lg:px-4 h-12 sm:h-14 border-b border-border bg-card/95 backdrop-blur-sm flex-shrink-0",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 sm:gap-4 min-w-0",children:[(0,e.jsx)(Us,{content:ge,side:"bottom",children:(0,e.jsx)(ms,{onClick:nn,className:"text-muted-foreground hover:text-foreground","aria-label":ge,icon:(0,e.jsx)(Oo,{className:"h-5 w-5","aria-hidden":"true"})})}),(0,e.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3 min-w-0",children:[(0,e.jsx)("div",{className:"h-7 w-7 sm:h-8 sm:w-8 rounded-lg bg-gradient-to-br from-primary to-primary/80 flex items-center justify-center shadow-sm shadow-primary/20 flex-shrink-0",children:(0,e.jsx)(We,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4 text-primary-foreground","aria-hidden":"true"})}),(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsx)("h1",{className:"font-semibold text-foreground leading-tight text-sm sm:text-base truncate max-w-[120px] sm:max-w-[170px] md:max-w-[220px] lg:max-w-[180px] xl:max-w-[240px] 2xl:max-w-[360px]",children:t?.name||"Loading…"}),(0,e.jsxs)("div",{className:"hidden xl:flex items-center gap-2 text-xs text-muted-foreground",children:[(0,e.jsxs)("span",{className:"flex items-center gap-1",children:[(0,e.jsx)(Qs,{className:"h-3 w-3","aria-hidden":"true"}),n.length," ",n.length===1?"shot":"shots"]}),(0,e.jsx)("span",{className:"text-border",children:"·"}),(0,e.jsxs)("span",{className:"flex items-center gap-1",children:[(0,e.jsx)(qo,{className:"h-3 w-3","aria-hidden":"true"}),Ac(i)]})]})]})]}),!o&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"w-px h-6 bg-border hidden sm:block max-[1100px]:hidden"}),(0,e.jsxs)("div",{className:"flex items-center gap-1 max-[1100px]:hidden",children:[(0,e.jsxs)("div",{className:"relative",ref:yt("film"),onKeyDown:Hs,children:[_t("film","Film"),be==="film"&&(0,e.jsx)("div",{role:"menu",className:`${Os}
2 left-0 w-56 overflow-hidden`,children:(0,e.jsx)(xt,{groups:bs,onDone:$e})})]}),(0,e.jsxs)("div",{className:"relative",ref:yt("add"),onKeyDown:Hs,children:[_t("add","Add",cs),be==="add"&&(0,e.jsx)("div",{role:"menu",className:`${Os} left-0 w-60 overflow-hidden`,children:(0,e.jsx)(xt,{groups:Ee,onDone:$e})})]}),(0,e.jsxs)(P,{variant:"ghost",size:"sm",className:"px-2.5",onClick:C,children:[(0,e.jsx)(vo,{className:"h-4 w-4","aria-hidden":"true"}),"My files"]}),V&&(0,e.jsxs)(P,{variant:"ghost",size:"sm",className:"px-2.5",onClick:V,"data-tour":"header-ai-director",children:[(0,e.jsx)($t,{className:"h-4 w-4","aria-hidden":"true"}),"AI Director"]})]})]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1 sm:gap-2",children:[o&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(ei,{variant:"warning",className:"h-8 gap-1.5 rounded-lg px-2 text-xs sm:px-2.5",children:[(0,e.jsx)(Js,{"aria-hidden":"true"}),(0,e.jsx)("span",{className:"hidden xl:inline",children:"Read only"})]}),(0,e.jsx)(P,{asChild:!0,size:"sm",className:"px-2 sm:px-3",children:(0,e.jsxs)("a",{href:"/pricing",children:[(0,e.jsx)("span",{className:"hidden xl:inline",children:"Make my own"}),(0,e.jsx)(cs,{className:"h-4 w-4 sm:hidden","aria-hidden":"true"})]})})]}),ot&&(0,e.jsxs)("button",{type:"button",onClick:le,className:"flex h-8 items-center gap-2 px-2.5 rounded-lg border border-warning/25 bg-warning/10 text-warning transition-colors duration-150 text-xs font-medium hover:bg-warning/20 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 select-none flex-shrink-0","aria-label":"Character sheet is generating. Click to open the characters panel.",children:[(0,e.jsxs)("span",{className:"relative flex h-2 w-2 shrink-0",children:[(0,e.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-warning opacity-75"}),(0,e.jsx)("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-warning"})]}),(0,e.jsx)(xe,{className:"h-3.5 w-3.5 animate-spin text-warning/80"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:"Character generating…"}),(0,e.jsx)("span",{className:"sm:hidden",children:"Generating…"})]}),Ye&&!ot&&(0,e.jsxs)("button",{type:"button",onClick:le,className:"flex h-8 items-center gap-2 px-2.5 rounded-lg border border-success/25 bg-success/10 text-success transition-colors duration-150 text-xs font-medium hover:bg-success/20 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 select-none flex-shrink-0","aria-label":"Character sheet is ready. Click to open the characters panel.",children:[(0,e.jsx)(tn,{className:"h-3.5 w-3.5"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:"Character ready"}),(0,e.jsx)("span",{className:"sm:hidden",children:"Ready"})]}),!o&&t?.uuid&&(0,e.jsx)(Id,{projectUuid:t.uuid,current:"advanced",className:"max-[900px]:hidden"}),(0,e.jsxs)("div",{className:"relative max-[1100px]:hidden",ref:yt("view"),onKeyDown:Hs,children:[_t("view","View"),be==="view"&&(0,e.jsx)("div",{role:"menu",className:`${Os} right-0 w-56 overflow-hidden`,children:(0,e.jsx)(xt,{groups:St,onDone:$e})})]}),(0,e.jsx)(Us,{content:"Watch film (full-screen preview)",side:"bottom",children:(0,e.jsxs)(P,{variant:"outline",size:"sm",onClick:_,className:"max-[1100px]:hidden",children:[(0,e.jsx)(So,{className:"h-4 w-4","aria-hidden":"true"}),"Watch film"]})}),!o&&(0,e.jsx)(Dc,{title:"Export film",description:"Save your finished film as a video file (MP4, WebM or MOV). Choose the size and quality.",learnMoreUrl:"/learn/exporting-your-film",side:"bottom",align:"end",children:(0,e.jsxs)(P,{size:"sm",variant:"outline",onClick:A,className:"max-[1100px]:hidden",children:[(0,e.jsx)(ve,{className:"h-4 w-4","aria-hidden":"true"}),"Export film"]})}),(0,e.jsxs)("div",{className:"relative hidden max-[1100px]:block",ref:yt("compact"),onKeyDown:Hs,children:[(0,e.jsx)(P,{variant:"outline",size:"sm",className:"w-8 px-0",onClick:()=>xs("compact"),"aria-label":"More actions","aria-haspopup":"menu","aria-expanded":be==="compact",children:(0,e.jsx)(Yo,{className:"h-4 w-4","aria-hidden":"true"})}),be==="compact"&&(0,e.jsxs)("div",{role:"menu",className:`${Os} right-0 w-[min(18rem,calc(100vw-1rem))] max-h-[70dvh] overflow-y-auto`,children:[vs.length>0&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:Ys,children:"Simple or Advanced"}),(0,e.jsx)(xt,{groups:[vs],onDone:$e}),(0,e.jsx)("div",{role:"separator",className:"h-px bg-border my-1"})]}),!o&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:Ys,children:"Film"}),(0,e.jsx)(xt,{groups:bs,onDone:$e}),(0,e.jsx)("div",{role:"separator",className:"h-px bg-border my-1"}),(0,e.jsx)("div",{className:Ys,children:"Add"}),(0,e.jsx)(xt,{groups:Ee,onDone:$e}),(0,e.jsx)("div",{role:"separator",className:"h-px bg-border my-1"})]}),(0,e.jsx)("div",{className:Ys,children:"View"}),(0,e.jsx)(xt,{groups:[...St,It(!o&&{label:"My files",icon:vo,onSelect:C},V&&{label:"AI Director",icon:$t,onSelect:V},{label:"Watch film",icon:So,onSelect:_},!o&&{label:"Export film",icon:ve,onSelect:A})],onDone:$e}),o&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"h-px bg-border my-1"}),(0,e.jsxs)("a",{href:"/pricing",className:"w-full flex items-center gap-2.5 px-3 py-2 text-sm hover:bg-surface-hover transition-colors duration-150 text-left outline-none focus-visible:bg-secondary",onClick:$e,children:[(0,e.jsx)(cs,{className:"h-4 w-4 text-muted-foreground","aria-hidden":"true"}),"Make my own"]})]})]})]})]})]}),(0,e.jsx)(xr,{open:gs,onOpenChange:Vt,children:(0,e.jsxs)(fr,{children:[(0,e.jsxs)(mr,{children:[(0,e.jsx)(pr,{children:"Leave this film?"}),(0,e.jsx)(gr,{children:"Changes you have not saved may be lost."})]}),(0,e.jsxs)(hr,{children:[(0,e.jsx)(P,{variant:"outline",onClick:()=>Vt(!1),children:"Cancel"}),(0,e.jsx)(P,{variant:"destructive",onClick:wt,children:"Leave film"})]})]})})]})};const ii=(0,r.memo)(Dd);ii.displayName="StoryboardHeader";var li=({frames:t,project:n,readOnly:i}
2)=>{const o=n?.status==="scripting",m=t.filter(x=>x.generating_image),f=t.filter(x=>x.generating_video&&!en(x)),c=t.filter(x=>x.generating_video&&en(x));if(i)return null;const d=[];if(o){const x="Writing your story…";d.push({key:"script",icon:Lt,text:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("span",{className:"inline-block animate-in fade-in slide-in-from-bottom-2 duration-300",children:[x,t.length>0&&` ${F(t.length,"shot")} so far.`]},x),(0,e.jsx)("span",{className:"ml-1.5 opacity-70 font-normal text-sm",children:"This takes several minutes, longer for a long film. You can leave and come back."})]})})}const g=(x,b)=>x.length===1?`Generating the ${b} for shot ${x[0].sequence_order}…`:`Generating ${x.length} ${b}s…`,{step:v}=ai(t);if(m.length>0&&v!=="pictures"){const x=g(m,"storyboard");d.push({key:"image",icon:Lt,text:(0,e.jsx)("span",{className:"inline-block animate-in fade-in slide-in-from-bottom-2 duration-300",children:x},x)})}if(f.length>0&&v!=="clips"){const x=g(f,"video clip");d.push({key:"video",icon:We,text:(0,e.jsx)("span",{className:"inline-block animate-in fade-in slide-in-from-bottom-2 duration-300",children:x},x)})}if(c.length>0&&v!=="clips"){const x=c.length===1?`Making the animation for shot ${c[0].sequence_order}…`:`Making ${c.length} animations…`;d.push({key:"animation",icon:uc,text:(0,e.jsx)("span",{className:"inline-block animate-in fade-in slide-in-from-bottom-2 duration-300",children:x},x)})}return d.length===0?null:(0,e.jsx)(Be,{id:"generation",priority:Oe.generation,label:"Generating",children:(0,e.jsxs)(zc,{size:"line",colorVariant:"sunset",role:"status","aria-live":"polite",className:"flex items-center justify-center gap-4 px-6 py-4 rounded-none border-b border-primary/20 bg-primary/5 backdrop-blur-sm animate-in slide-in-from-top-2 fade-in duration-300",children:[(0,e.jsx)(xe,{className:"h-6 w-6 shrink-0 animate-spin text-primary","aria-hidden":"true"}),(0,e.jsx)("div",{className:"flex flex-col gap-1.5 min-w-0",children:d.map(x=>(0,e.jsxs)("div",{className:"flex items-center gap-2.5 min-w-0",children:[(0,e.jsx)(x.icon,{className:"h-5 w-5 shrink-0 animate-pulse text-primary/80","aria-hidden":"true"}),(0,e.jsx)("span",{className:"truncate font-semibold text-base md:text-lg text-primary",children:x.text})]},x.key))})]})})};li.displayName="GenerationStatusBanner";const $d=(0,r.memo)(li);var Ld=t=>`${Math.floor(t/60)}:${String(Math.max(0,Math.round(t))%60).padStart(2,"0")}`,ci=({scenes:t,planning:n=!1})=>{const i=t?.length??0;return i===0&&!n?null:(0,e.jsx)("div",{className:"absolute inset-0 flex items-center justify-center p-6 pointer-events-none",children:(0,e.jsxs)("div",{role:"status","aria-live":"polite",className:"pointer-events-auto w-full max-w-md rounded-xl border border-border-strong bg-background/95 shadow-xl",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2.5 border-b border-border px-4 py-3",children:[(0,e.jsx)($t,{className:"h-4 w-4 shrink-0 text-primary","aria-hidden":"true"}),(0,e.jsx)("span",{className:"text-sm font-semibold text-foreground",children:"Planning your film"}),i>0&&(0,e.jsxs)("span",{className:"ml-auto text-xs tabular-nums text-muted-foreground",children:[i," ",i===1?"scene":"scenes"," so far"]})]}),i===0&&(0,e.jsxs)("p",{className:"flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground",children:[(0,e.jsx)(xe,{className:"h-3.5 w-3.5 shrink-0 animate-spin motion-reduce:animate-none","aria-hidden":"true"}),"Working out the scenes and shots. Your shots appear here when the plan is ready."]}),(0,e.jsx)("ul",{hidden:i===0,className:"max-h-64 divide-y divide-border/60 overflow-y-auto",children:(t??[]).map((o,m)=>(0,e.jsxs)("li",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5 px-4 py-2 text-sm animate-in fade-in slide-in-from-bottom-1 duration-300",children:[(0,e.jsxs)("span",{className:"font-medium text-foreground",children:["Scene ",o.number]}),o.name&&(0,e.jsxs)("span",{className:"text-muted-foreground",children:["· ",o.name]}),o.time_of_day&&(0,e.jsxs)("span",{className:"text-muted-foreground",children:["· ",o.time_of_day]}),(0,e.jsxs)("span",{className:"ml-auto shrink-0 text-xs tabular-nums text-muted-foreground",children:[o.shots," ",o.shots===1?"shot":"shots"," ·"," ",Ld(o.seconds)]})]},`${o.number}-${m}`))})]})})};ci.displayName="PlanScenesSoFar";const Gd=(0,r.memo)(ci);var di=({frames:t,project:n,readOnly:i}
2)=>{if(i||!n||n.auto_storyboard)return null;const o=t.filter(f=>f.last_failed_generation_job&&!f.has_image);if(o.length===0)return null;const m=o.length<=3?o.map(f=>`#${f.sequence_order}`).join(", "):null;return(0,e.jsx)(Be,{id:"failed-shots",priority:Oe.failures,label:`${F(o.length,"shot")} failed`,children:(0,e.jsxs)(rt,{tone:"warning",icon:(0,e.jsx)(Xs,{}),children:[F(o.length,"shot")," failed to draw",m?` — ${m}`:"","."," ",(0,e.jsx)("span",{className:"text-muted-foreground",children:"Open the shot to see why and retry it."})]})})};di.displayName="FailedShotsNotice";const zd=(0,r.memo)(di);var Vd=({frames:t,readOnly:n})=>{const i=us(m=>m.user?.free_tier?.preview_renderer),o=(0,r.useMemo)(()=>{const m=new Map;for(const d of t){const g=d.active_version?.data?.image_provider_slug;d.active_version?.data?.medium!=="animation"&&(!g||!d.has_image||g===i||m.set(g,(m.get(g)??0)+1))}if(m.size<2)return null;const f=[...m.entries()].sort((d,g)=>g[1]-d[1]),c=f.slice(1);return{main:f[0][0],oddSlugs:c.map(([d])=>d),oddCount:c.reduce((d,[,g])=>d+g,0)}},[t,i]);return n||!o?null:(0,e.jsx)(Wd,{mix:o})},Wd=({mix:t})=>{pd("image");const n=t.oddCount===1?"shot":"shots",i=[...new Set(t.oddSlugs.map(o=>ko(o)))];return(0,e.jsx)(Be,{id:"mixed-renderers",priority:Oe.mixedRenderers,label:`${t.oddCount} ${n} drawn by another model`,children:(0,e.jsxs)(rt,{tone:"warning",icon:(0,e.jsx)(Qs,{}),children:[t.oddCount," ",n," ",t.oddCount===1?"was":"were"," drawn by"," ",i.join(" and "),", not ",ko(t.main),"."," ",(0,e.jsx)("span",{className:"text-muted-foreground",children:"Two models never draw alike. Redraw those shots to match the rest."})]})})};const Bd=(0,r.memo)(Vd);var ui=({project:t,readOnly:n,onApplied:i})=>{const[o,m]=(0,r.useState)(!1),[f,c]=(0,r.useState)(!1),d=ue(_=>_.fetchProject),g=t?.song_resync??null;if(n||f||!t||!g||g.changes.length===0)return null;const v=g.changes.length,x=g.off_sync_frame_ids.length,b=async()=>{m(!0);try{const _=(await bt.resyncSong(t.uuid))?.data?.data??{},A=(_.changed??[]).length,C=_.off_sync_frame_ids??[],D=A===0?"The cuts already follow the song.":`${F(A,"cut")} moved onto the song.`+(C.length>0?` ${F(C.length,"clip")} will need making again so the mouth follows the new cut.`:"");S.success(D),await i(),await d(t.uuid)}catch(_){const A=_;S.error(A.response?.data?.message||"Could not match the cuts. Try again.")}finally{m(!1)}};return(0,e.jsx)(Be,{id:"song-alignment",priority:Oe.songAlignment,label:`${F(v,"cut")} off the song`,children:(0,e.jsxs)(rt,{tone:"attention",icon:(0,e.jsx)(Zl,{}),actions:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(P,{size:"xs",variant:"default",onClick:()=>void b(),disabled:o,children:o?"Matching…":"Match cuts to the song"}),(0,e.jsx)(P,{size:"xs",variant:"ghost",onClick:()=>c(!0),disabled:o,children:"Not now"})]}),children:[F(v,"cut")," don't line up with the song.",x>0&&(0,e.jsxs)("span",{className:"text-muted-foreground",children:[" ",F(x,"clip")," will need making again afterwards."]})]})})};ui.displayName="SongAlignmentNotice";const Od=(0,r.memo)(ui);var Yd=t=>t===1?"shot":"shots";const Hd=({projectUuid:t,pending:n,watchSince:i=null,drawnFrameCount:o,frameCount:m,onGenerating:f,onResolved:c,onOfferShownChange:d,onReview:g})=>{const[v,x]=(0,r.useState)(null),[b,_]=(0,r.useState)(null),[A,C]=(0,r.useState)(0),{showUpgrade:D}=hs(),h=(0,r.useRef)(c);h.current=c,(0,r.useEffect)(()=>{if(!n){x(null);return}let q=!0;return bt.keyFramesStatus(t).then(G=>{if(!q)return;const oe=G.data?.data??null;x(oe),oe&&!oe.pending&&h.current?.()}).catch(()=>{q&&x(null)}),()=>{q=!1}},[t,n,o,m,A]);const p=(0,r.useRef)(n);p.current=n;const T=(0,r.useRef)(null);i!==null&&n&&_o(v)&&(T.current=i),(0,r.useEffect)(()=>{if(i===null)return;let q=!0,G,oe=0;const ie=()=>{const Te=Bc(i,Date.now(),oe);Te!==null&&(G=setTimeout(_e,Te))},_e=async()=>{if(oe+=1,!(!q||T.current===i)){try{const Te=await bt.keyFramesStatus(t);if(!q)return;const at=Te.data?.data??null;_o(at)&&(p.current?x(at):h.current?.())}catch{}q&&ie()}};return ie(),()=>{q=!1,G&&clearTimeout(G)}},[t,i]);const E=(0,r.useCallback)(async()=>{const q=v?.frame_ids??[];if(!(g&&q.length&&!await g(q))){_("generate");try{await bt.generateKeyFrames(t,q),x(null),f?.(),c?.()}catch(G){Dl.isAxiosError(G)&&G.response?.status===409?x(null):S.error("Could not start the storyboards. Try again.")}finally{_(null),C(G=>G+1)}}},[t,f,c,g,v?.frame_ids]),O=(0,r.useCallback)(async()=>{_("skip");try{await bt.skipKeyFrames(t),c?.()}catch{S.error("Could not hide this offer. Try again.")}finally{_(null)}},[t,c]),X=!!n&&!!v?.pending&&v.frame_count>0;if((0,r.useEffect)(()=>(d?.(X),()=>d?.(!1)),[X,d]),!X||!v)return null;const $=v.frame_count,k=Math.max(v.remaining??$,$),V=v.allowance,R=V?.metered&&V.remaining_cents!=null?V.remaining_cents:null,M=R!==null&&R<=0;return(0,e.jsx)(Be,{id:"key-frames",priority:Oe.keyFrames,label:"Generate storyboards",children:(0,e.jsx)(rt,{tone:"attention",icon:(0,e.jsx)(nc,{}),onDismiss:O,dismissDisabled:b!==null,actions:(0,e.jsxs)(e.Fragment,{children:[M?(0,e.jsx)(P,{size:"xs",onClick:()=>D({feature:"key frame generation",message:"Your storyboard is planned and waiting. See plans to draw the rest."}),children:"See plans"}):(0,e.jsxs)(P,{size:"xs",onClick:E,disabled:b!==null,children:[b==="generate"&&(0,e.jsx)(xe,{className:"h-3 w-3 animate-spin","aria-hidden":"true"}
2),"Generate ",$," ",$===1?"storyboard":"storyboards"]}),(0,e.jsx)(P,{variant:"ghost",size:"xs",onClick:O,disabled:b!==null,className:"text-muted-foreground hover:text-foreground",children:"Not now"})]}),children:M?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"font-medium",children:"Your story is ready."})," ",(0,e.jsxs)("span",{className:"text-muted-foreground",children:["This is more than your plan allows this month, so the ",k," ","remaining ",Yd(k)," cannot be drawn yet."]})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("span",{className:"font-medium",children:["Your story is ready."," ",k>$?`Generate storyboards for the next ${$} of ${k} remaining shots?`:`Generate ${k===1?"the remaining storyboard":`storyboards for the ${k} remaining shots`}?`]})," ",(0,e.jsx)("span",{className:"text-muted-foreground",children:"Nothing is generated until you choose."})]})})})};var qd=({text:t})=>(0,e.jsx)("li",{className:"text-sm leading-relaxed text-muted-foreground",children:(0,e.jsx)(Xc,{text:t,mentions:Jc()})});const Kd=({open:t,shots:n,isFixing:i,onClose:o,onFix:m,onOpenShot:f})=>(0,e.jsx)(xr,{open:t,onOpenChange:c=>!c&&o(),children:(0,e.jsxs)(fr,{className:"max-w-xl",children:[(0,e.jsxs)(mr,{children:[(0,e.jsx)(pr,{children:"Shots to fix before drawing"}),(0,e.jsx)(gr,{children:n.length===0?"Every shot is ready to draw.":"We can fix each prompt for you, or you can open the shot and change it yourself."})]}),n.length===0?(0,e.jsxs)("p",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,e.jsx)(tn,{className:"h-4 w-4 text-success","aria-hidden":"true"}),"Nothing left to fix."]}):(0,e.jsx)("ul",{className:"flex flex-col gap-3",children:n.map(c=>(0,e.jsxs)("li",{className:"flex flex-col gap-2 rounded-lg border border-border bg-card p-3",children:[(0,e.jsxs)("span",{className:"text-sm font-semibold text-foreground",children:["Shot ",c.number]}),(0,e.jsx)("ul",{className:"flex list-disc flex-col gap-1 pl-5",children:c.reasons.map(d=>(0,e.jsx)(qd,{text:d},d))}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,e.jsx)(P,{variant:"secondary",size:"xs",onClick:()=>m([c.frame_id]),disabled:i,children:"Fix it for me"}),f&&(0,e.jsx)(P,{variant:"ghost",size:"xs",onClick:()=>{o(),f(c.frame_id)},className:"text-muted-foreground hover:text-foreground",children:"Open shot"})]})]},c.frame_id))}),(0,e.jsxs)(hr,{className:"gap-2",children:[(0,e.jsx)(P,{variant:"outline",onClick:o,children:"Close"}),n.length>0&&(0,e.jsxs)(P,{onClick:()=>m(n.map(c=>c.frame_id)),disabled:i,children:[i&&(0,e.jsx)(xe,{className:"h-4 w-4 animate-spin","aria-hidden":"true"}),i?"Fixing…":n.length===1?"Fix it for me":"Fix all for me"]})]})]})}),Jd=({projectUuid:t,shotCount:n,onWritePrompts:i,isWritingPrompts:o,onOpenShot:m})=>{const f=`studio:legacy-project-dismissed:${t}`,[c,d]=(0,r.useState)(null),[g,v]=(0,r.useState)(!1),[x,b]=(0,r.useState)(()=>{try{return sessionStorage.getItem(f)==="1"}catch{return!1}});(0,r.useEffect)(()=>{if(o)return;let p=!1;return bt.compatibility(t).then(T=>{p||d(T.data.data)}).catch(()=>{}),()=>{p=!0}},[t,n,o]);const _=c?.flagged_shots??[];if(!g&&(x||!c||c.status==="ready"))return null;const A=(0,e.jsx)(Kd,{open:g,shots:c?.status==="ready"?[]:_,isFixing:o,onClose:()=>v(!1),onFix:p=>i(p,!1),onOpenShot:m});if(!c||c.status==="ready"||x)return A;const C=()=>{b(!0);try{sessionStorage.setItem(f,"1")}catch{}},D=c.status==="legacy_read_only",h=(0,e.jsx)(P,{variant:"ghost",size:"xs",onClick:C,leftIcon:(0,e.jsx)(Gt,{className:"h-3.5 w-3.5"}),className:"text-muted-foreground hover:text-foreground",children:"Not now"});return!D&&_.length>0?(0,e.jsxs)(Be,{id:"legacy-project",priority:Oe.legacyProject,label:"Shots to fix",children:[(0,e.jsx)(rt,{icon:(0,e.jsx)(Xl,{}),actions:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(P,{variant:"outline",size:"xs",onClick:()=>v(!0),children:[o&&(0,e.jsx)(xe,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),_.length===1?`Review shot ${_[0].number}`:`Review ${_.length} shots`]}),h]}),children:o?"Fixing the prompts…":c.message}),A]}):(0,e.jsx)(Be,{id:"legacy-project",priority:Oe.legacyProject,label:D?"Older film":"Write full prompts",children:(0,e.jsx)(rt,{icon:(0,e.jsx)(ic,{}),actions:(0,e.jsxs)(e.Fragment,{children:[D?(0,e.jsx)(P,{size:"xs",onClick:()=>
2Ks.visit("/dashboard"),children:"Start a new film"}):(0,e.jsxs)(P,{size:"xs",onClick:()=>i(c.unprepared_frame_ids?.length?c.unprepared_frame_ids:void 0),disabled:o||c.generation_in_progress,children:[o&&(0,e.jsx)(xe,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),o?"Writing prompts…":"Write full prompts"]}),h]}),children:c.message})})},Xd=()=>{const{isFreeTier:t,onTrial:n,trialEndsAt:i,trialPlanType:o}=sn(),{showUpgrade:m}=hs(),f=us(d=>d.user?.free_tier?.projects_limit)===0,c=us(d=>d.user?.free_tier?.trial_required??!1);if(!t||f||c&&!n)return null;if(n){const d=wd(o),g=Sd(i);return(0,e.jsx)(Be,{id:"free-tier",priority:Oe.freeTier,label:"You are on a trial",children:(0,e.jsxs)(rt,{tone:"attention",icon:(0,e.jsx)($t,{}),actions:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(P,{size:"xs",onClick:()=>m({feature:"default"}),leftIcon:(0,e.jsx)(Jo,{className:"h-3 w-3"}),children:["Start ",d," now"]}),(0,e.jsx)(P,{variant:"outline",size:"xs",asChild:!0,children:(0,e.jsx)("a",{href:"/dashboard/settings?tab=billing",children:"Manage trial"})})]}),children:[(0,e.jsx)("span",{className:"font-medium",children:"Your trial covers the storyboard, scene audio and score."})," ",(0,e.jsxs)("span",{className:"text-muted-foreground",children:[g?`Your ${d} plan starts ${g} and unlocks rendering, sound design and export.`:`Your ${d} plan starts when the trial ends and unlocks rendering, sound design and export.`," ",Ao]})]})})}return(0,e.jsx)(Be,{id:"free-tier",priority:Oe.freeTier,label:"You are on the free plan",children:(0,e.jsxs)(rt,{tone:"attention",icon:(0,e.jsx)($t,{}),actions:(0,e.jsx)(P,{size:"xs",onClick:()=>m({feature:"default"}),leftIcon:(0,e.jsx)(Js,{className:"h-3 w-3"}),children:"Unlock the rest"}),children:[(0,e.jsx)("span",{className:"font-medium",children:"The free plan covers your storyboard, scene audio and score."})," ",(0,e.jsxs)("span",{className:"text-muted-foreground",children:["Generating storyboards and video clips, new sound effects and music, and exporting the film need a plan. ",Ao]})]})})};function Qd(t,n=!1){const i=(m,f)=>m?"done":f?"current":"later",o=t.shots>0&&!n;return[{label:"Story",detail:null,state:i(o,n)},{label:"Storyboard",detail:t.pictureShots>0?`${t.withPicture} of ${t.pictureShots}`:null,state:i(o&&t.withPicture===t.pictureShots,o&&t.step==="pictures")},{label:"Video clips",detail:`${t.withClip} of ${t.shots}`,state:i(o&&t.withClip===t.shots,o&&t.step==="clips")},{label:"Sound",detail:"(optional)",state:i(t.hasSound,!1)},{label:"Export",detail:null,state:i(!1,o&&t.step==="finish")}]}var cr=(t,n,i)=>`Generating ${t}s… ${n} of ${i} ready. You can keep working.`;function To(t,n,i,o,m,f){const c=t==="storyboard",d=c?"createPictures":"createClips";if(n===0&&i===0)return{...f,busy:!1};if(o===0)return{message:cr(t,n,m),primary:null,secondary:[],busy:!0};const g=c?`storyboard for the other ${o===1?"shot":`${o} shots`}`:`the other ${F(o,t)}`,v=c?`storyboard for ${F(o,"more shot")}`:F(o,`more ${t}`);return{message:(c?`${n} of ${m} shots have a storyboard.`:`${n} of ${m} video clips are ready.`)+(i>0?` ${i} more on the way.`:""),primary:{label:`Generate ${i>0?v:g}`,action:d},secondary:[],busy:!1}}function Zd(t,n={}){const i=Ud(t,n),o=Math.round(n.runtimeOverSeconds??0);return!i||o<=0?i:{...i,message:`Your film now runs ${F(o,"second")} longer than you approved. ${i.message}`,secondary:[...i.secondary,{label:"Check the length",action:"reviewPlan"}]}}function Ud(t,n={}){const i=t.shots===1,o=t.shots-t.pictureShots,m=t.pictureShots===1?"Your filmed shot has a storyboard.":`All ${t.pictureShots} filmed shots have a storyboard.`,f=`${F(o,"animated shot")} ${o===1?"is":"are"} made by AI from ${o===1?"its":"their"} brief.`;if(n.planApproval==="blocked"&&!n.writingStory)return{message:"The plan for this film has problems, so no shots were written.",primary:{label:"See the problems",action:"reviewPlan"},secondary:[{label:"Write the script again",action:"writeScriptAgain"}],busy:!1};if(t.step==="story")return null;const c=d=>({message:d,primary:null,secondary:[],busy:!0});if(n.writingStory)return c(`Writing your story… ${F(t.shots,"shot")} so far.`);if(n.directorPass==="prep"||n.planApproval==="checking")return{...c("Your AI Director is checking the shots before they are drawn."),secondary:n.directorPass==="prep"?[{label:"Skip",action:"stopDirectorPass"}]:[]};if(n.directorPass==="final")return{...c("Your AI Director is watching the film."),secondary:[{label:"Stop",action:"stopDirectorPass"}]};if(t.step==="pictures"&&(n.freeRunActive||n.pictureRunActive))return c(cr("storyboard",t.withPicture,t.pictureShots));if(t.step==="clips"&&n.clipRunActive)return{...c(cr("video clip",t.withClip,t.shots)),secondary:[{label:"Stop",action:"stopRun"}]};if(n.planApproval==="ready"&&t.step==="pictures")return{message:`Your story has ${F(t.shots,"shot")}. Check ${i?"it":"them"} before the whole film is drawn.`,primary:{label:i?"Check the shot":"Check the shots",action:"reviewPlan"},secondary:[],busy:!1};if(t.step==="pictures"){const d=To("storyboard",t.withPicture,t.creatingPictures,t.needPicture,t.pictureShots,{message:`Your story has ${F(t.shots,"shot")}. Next, generate a storyboard for ${i?"it":t.pictureShots<t.shots?`the ${F(t.pictureShots,"filmed shot")}`:"each shot"}.`,primary:n.drawsItself?{label:"Generate the storyboard",action:"generateStoryboard"}:{label:t.pictureShots===1?"Generate the storyboard":`Generate storyboard for all ${t.pictureShots} shots`,action:"createPictures"},secondary:[{label:"Open shot 1",action:"openFirstShot"}]});return t.needClip>0&&!n.clipRunActive&&(d.secondary=[...d.secondary,{label:`Generate ${F(t.needClip,"video clip")}`,action:"createClips"}]),n.clipRunActive&&(d.secondary=[...d.secondary,{label:"Stop video clips",action:"stopRun"}]),n.pictureOfferShown?{...d,primary:null}:d}return n.planApproval==="ready"&&t.step==="clips"?{message:o?`${m} ${f} Check the shots before the video clips are made.`:`${i?"Your shot has":`All ${t.shots} shots have`} a storyboard. Check ${i?"it":"them"} before the video clips are made.`,primary:{label:i?"Check the shot":"Check the shots",action:"reviewPlan"},secondary:[{label:"Watch storyboard",action:"watch"}],busy:!1}:t.step==="clips"?To("video clip",t.withClip,t.creatingClips,t.needClip,t.shots,{message:o?`${m} ${f} Next, make the video clips and the ${o===1?"animation":"animations"}.`:i?"Your shot has a storyboard. Next, turn it into a video clip.":`All ${t.shots} shots have a storyboard. Next, turn them into video clips.`,primary:{label:o?`Generate ${F(t.pictureShots,"video clip")} and ${F(o,"animation")}`:i?"Generate the video clip":`Generate all ${t.shots} video clips`,action:"createClips"},secondary:[{label:"Watch storyboard",action:"watch"}]}):{message:"Your film is ready to export.",primary:{label:"Export film",action:"export"},secondary:[{label:"Watch film",action:"watch"},...t.hasSound?[]:[{label:"Add voice or music",action:"addSound"}]],busy:!1}}var Eo="text-muted-foreground hover:text-foreground";const eu=t=>{const{frames:n,soundTrackCount:i,onAddSound:o}=t,{isFreeTier:m}=sn(),f=(0,r.useMemo)(()=>ai([...n].sort((b,_)=>b.sequence_order-_.sequence_order),i),[n,i]),c=Zd(f,{freeRunActive:t.freeRunActive,pictureRunActive:t.isCreatingPictures,clipRunActive:t.isCreatingClips,pictureOfferShown:t.pictureOfferShown,writingStory:t.writingStory,drawsItself:t.drawsItself,planApproval:t.planApproval,runtimeOverSeconds:t.runtimeOverSeconds,directorPass:t.directorPass});if(!c)return null;const d=Qd(f,t.writingStory),g=Math.max(0,d.findIndex(b=>b.state==="current")),v={createPictures:t.onCreatePictures,generateStoryboard:()=>t.onGenerateStoryboard?.(),createClips:t.onCreateClips,watch:t.onWatch,export:t.onExport,openFirstShot:()=>f.firstShotNeedingPicture&&t.onOpenShot(f.firstShotNeedingPicture),addSound:()=>{},reviewPlan:()=>t.onReviewPlan?.(),writeScriptAgain:()=>t.onWriteScriptAgain?.(),stopRun:()=>t.onStopRun?.(),stopDirectorPass:()=>t.onStopDirectorPass?.()},x=c.primary;return(0,e.jsxs)("nav",{"aria-label":"Film progress",className:"flex min-h-11 flex-shrink-0 flex-wrap items-center gap-x-4 gap-y-1 border-b border-border bg-card px-2 py-1.5 sm:px-3 lg:px-4",children:[(0,e.jsx)("ol",{className:"hidden items-center gap-1.5 text-xs lg:flex",children:d.map((b,_)=>(0,e.jsxs)(r.Fragment,{children:[_>0&&(0,e.jsx)("li",{"aria-hidden":"true",className:"text-muted-foreground
2/40",children:"·"}),(0,e.jsxs)("li",{"aria-current":b.state==="current"?"step":void 0,className:te("flex h-6 items-center gap-1 whitespace-nowrap rounded-md border border-transparent px-1.5",b.state==="current"&&"border-primary/25 bg-primary/10 text-primary",b.state==="done"&&"text-foreground",b.state==="later"&&"text-muted-foreground"),children:[(0,e.jsx)("span",{className:"tabular-nums",children:_+1}),(0,e.jsx)("span",{className:"font-medium",children:b.label}),b.state==="done"?(0,e.jsx)(tn,{className:"h-3 w-3 text-success",role:"img","aria-label":"done"}):b.detail&&(0,e.jsx)("span",{className:"tabular-nums opacity-80",children:b.detail})]})]},b.label))}),(0,e.jsxs)("p",{className:"text-xs font-medium text-muted-foreground lg:hidden",children:["Step ",g+1," of 5: ",d[g].label]}),(0,e.jsxs)("div",{className:"ml-auto flex min-w-0 flex-wrap items-center gap-2",children:[(0,e.jsxs)("p",{role:"status",className:"flex items-center gap-1.5 text-sm",children:[c.busy&&(0,e.jsx)(xe,{className:"h-3.5 w-3.5 animate-spin text-primary motion-reduce:animate-none","aria-hidden":"true"}),c.message]}),x&&(0,e.jsxs)(P,{size:"sm",onClick:v[x.action],children:[m&&x.action!=="generateStoryboard"&&x.action!=="reviewPlan"&&(0,e.jsx)(Js,{className:"h-4 w-4","aria-hidden":"true"}),x.label]}),c.secondary.map(b=>b.action!=="addSound"?(0,e.jsx)(P,{variant:"ghost",size:"xs",className:Eo,onClick:v[b.action],children:b.label},b.action):o&&(0,e.jsxs)(ni,{children:[(0,e.jsx)(si,{asChild:!0,children:(0,e.jsx)(P,{variant:"ghost",size:"xs",className:Eo,children:b.label})}),(0,e.jsxs)(ti,{align:"end",className:"z-[100]",children:[(0,e.jsx)(ds,{onClick:()=>o("voiceover"),children:"Voice"}),(0,e.jsx)(ds,{onClick:()=>o("music"),children:"Music"}),(0,e.jsx)(ds,{onClick:()=>o("sfx"),children:"Sound effects"})]})]},b.action))]})]})},dr={brightness:1,contrast:1,saturation:1,temperature:0},tu=[{id:"none",name:"None",grade:{...dr,preset:"none"}},{id:"warm",name:"Cinematic Warm",grade:{preset:"warm",brightness:1,contrast:1.08,saturation:1.05,temperature:30}},{id:"cool",name:"Cinematic Cool",grade:{preset:"cool",brightness:1,contrast:1.08,saturation:1.05,temperature:-30}},{id:"teal_orange",name:"Teal & Orange",grade:{preset:"teal_orange",brightness:1,contrast:1.15,saturation:1.2,temperature:18}},{id:"noir",name:"Noir",grade:{preset:"noir",brightness:1,contrast:1.25,saturation:0,temperature:0}},{id:"vintage",name:"Vintage Film",grade:{preset:"vintage",brightness:1.03,contrast:.95,saturation:.85,temperature:22}}];var qs=(t,n,i)=>Math.max(n,Math.min(i,t));function su(t){return t?(t.brightness??1)===1&&(t.contrast??1)===1&&(t.saturation??1)===1&&(t.temperature??0
2)===0:!0}function vr(t){if(!t||su(t))return"";const n=qs(t.brightness??1,.5,1.5),i=qs(t.contrast??1,.5,1.5),o=qs(t.saturation??1,0,2),m=qs(t.temperature??0,-100,100),f=[`brightness(${n})`,`contrast(${i})`,`saturate(${o})`];if(m!==0){const c=Math.min(.35,Math.abs(m)/100*.35),d=m>0?-(m/100)*10:Math.abs(m)/100*14;f.push(`sepia(${c.toFixed(3)})`,`hue-rotate(${d.toFixed(1)}deg)`)}return f.join(" ")}var nu=[{key:"brightness",label:"Brightness",min:.5,max:1.5,step:.01,neutral:1},{key:"contrast",label:"Contrast",min:.5,max:1.5,step:.01,neutral:1},{key:"saturation",label:"Saturation",min:0,max:2,step:.01,neutral:1},{key:"temperature",label:"Temperature",min:-100,max:100,step:1,neutral:0}];const ru=({grade:t,onChange:n,onClose:i})=>{const o=t??dr,m=(c,d)=>typeof o[c]=="number"?o[c]:d,f=(c,d)=>{n({...o,preset:void 0,[c]:d})};return(0,e.jsxs)("div",{className:"w-72 rounded-xl border border-border-strong bg-background p-3 shadow-[var(--shadow-edge),var(--shadow-xl)]",children:[(0,e.jsxs)("div",{className:"mb-3 flex items-center justify-between",children:[(0,e.jsx)("h3",{className:"text-sm font-semibold text-foreground",children:"Color Grade"}),(0,e.jsx)(Zo,{onClick:i,"aria-label":"Close color grade"})]}),(0,e.jsx)("div",{className:"mb-3 grid grid-cols-3 gap-1.5",children:tu.map(c=>{const d=(o.preset??"none")===c.id;return(0,e.jsx)(P,{variant:"outline",size:"xs",onClick:()=>n({...c.grade}),"aria-pressed":d,className:"px-2 text-[11px]",children:c.name},c.id)})}),(0,e.jsx)("div",{className:"space-y-2.5",children:nu.map(c=>{const d=m(c.key,c.neutral);return(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"mb-1 flex items-center justify-between",children:[(0,e.jsx)("label",{className:"text-xs text-muted-foreground",children:c.label}),(0,e.jsx)("span",{className:"text-[11px] tabular-nums text-muted-foreground",children:c.key==="temperature"?Math.round(d):d.toFixed(2)})]}),(0,e.jsx)("input",{type:"range",min:c.min,max:c.max,step:c.step,value:d,onChange:g=>f(c.key,parseFloat(g.target.value)),className:"w-full accent-primary","aria-label":c.label})]},c.key)})}),(0,e.jsxs)("div",{className:"mt-3 flex items-center justify-between",children:[(0,e.jsxs)(P,{variant:"ghost",size:"xs",onClick:()=>n({...dr,preset:"none"}),className:"-ml-2.5 text-muted-foreground hover:text-foreground",children:[(0,e.jsx)(pc,{className:"h-3.5 w-3.5"}),"Reset"]}),(0,e.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:"Preview is approximate · applied at export"})]})]})};function Ro(t,n){const i=t.active_version?.data,o=(i?.script||i?.image_prompt||"").toString();return o?o.slice(0,80):`Shot ${n+1}`}const au=({scenes:t,frames:n,selectedFrameId:i,onJumpToScene:o,onJumpToFrame:m,onClose:f})=>{const[c,d]=(0,r.useState)(""),g=c.trim().toLowerCase(),v=(0,r.useMemo)(()=>g?n.map((b,_)=>({f:b,i:_})).filter(({f:b,i:_})=>Ro(b,_).toLowerCase().includes(g)).slice(0,40):[],[g,n]),x=(0,r.useMemo)(()=>[...t].sort((b,_)=>b.scene_order-_.scene_order),[t]);return(0,e.jsxs)("div",{className:"flex max-h-[70dvh] w-64 flex-col rounded-xl border border-border bg-card shadow-xl",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-3 py-2",children:[(0,e.jsx)($c,{as:"h3",children:"Outline"}),(0,e.jsx)(Zo,{onClick:f,"aria-label":"Close outline"})]}),(0,e.jsx)("div",{className:"border-b border-border p-2",children:(0,e.jsxs)("div",{className:"relative",children:[(0,e.jsx)(ec,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),(0,e.jsx)("input",{value:c,onChange:b=>d(b.target.value),placeholder:"Search shots…","aria-label":"Search shots",className:te(Ic,"h-8 pl-7 pr-2 text-xs")})]})}),(0,e.jsx)("div",{className:"flex-1 overflow-y-auto p-1.5",children:g?v.length===0?(0,e.jsxs)("p",{className:"px-2 py-3 text-xs text-muted-foreground",children:['No shots match "',c,'".']}):v.map(({f:b,i:_})=>(0,e.jsxs)("button",{onClick:()=>m(b.id),className:te("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-xs transition-colors outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",i===b.id?"bg-primary/15 text-primary":"text-foreground hover:bg-surface-hover"),children:[(0,e.jsx)(We,{className:"mt-0.5 h-3 w-3 flex-none text-muted-foreground"}),(0,e.jsx)("span",{className:"line-clamp-2",children:Ro(b,_)})]},b.id)):x.length===0?(0,e.jsx)("p",{className:"px-2 py-3 text-xs text-muted-foreground",children:"No scenes yet. Group shots into scenes to navigate them here."}):x.map(b=>(0,e.jsxs)("button",{onClick:()=>o(b.id),className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs text-foreground transition-colors hover:bg-surface-hover outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",children:[(0,e.jsx)("span",{className:"h-2.5 w-2.5 flex-none rounded-full",style:{backgroundColor:b.color}}),(0,e.jsx)("span",{className:"flex-1 truncate font-medium",children:b.name}),(0,e.jsx)("span",{className:"flex-none tabular-nums text-[10px] text-muted-foreground",children:b.frames_count??0})]},b.id))})]})},ou=(t,n=!0)=>{const i=(0,r.useRef)(t);(0,r.useEffect)(()=>{i.current=t},[t]);const o=(0,r.useCallback)(m=>{if(!(m.target instanceof HTMLInputElement||m.target instanceof HTMLTextAreaElement||m.target?.isContentEditable))for(const f of i.current){const c=m.ke
2y.toLowerCase()===f.key.toLowerCase()||f.key===" "&&m.code==="Space",d=!!f.ctrl===(m.ctrlKey||m.metaKey),g=!!f.shift===m.shiftKey,v=!!f.alt===m.altKey;if(c&&d&&g&&v){m.preventDefault(),f.handler();return}}},[]);(0,r.useEffect)(()=>{if(n)return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[n,o])};function iu(t,n){return t.id===n.id&&t.name===n.name&&t.avatar===n.avatar&&t.color===n.color&&t.cursor?.x===n.cursor?.x&&t.cursor?.y===n.cursor?.y&&t.cursor?.viewport_x===n.cursor?.viewport_x&&t.cursor?.viewport_y===n.cursor?.viewport_y&&t.cursor?.zoom===n.cursor?.zoom&&t.activity?.selected_frame_id===n.activity?.selected_frame_id&&t.activity?.selected_audio_track_id===n.activity?.selected_audio_track_id&&t.activity?.selected_annotation_id===n.activity?.selected_annotation_id&&t.activity?.timeline_position===n.activity?.timeline_position&&t.activity?.is_playing===n.activity?.is_playing&&t.activity?.status===n.activity?.status}function lu(t,n){if(t.size!==n.length)return!1;const i=new Set;return n.every(o=>{if(i.has(o.id))return!1;i.add(o.id);const m=t.get(o.id);return m!==void 0&&iu(m,o)})}const Dt=ur(t=>({users:new Map,isConnected:!1,connectionError:null,setUsers:n=>{t(i=>{if(lu(i.users,n))return i;const o=new Map;return n.forEach(m=>o.set(m.id,m)),{users:o}})},addUser:n=>{t(i=>{const o=new Map(i.users);return o.set(n.id,n),{users:o}})},removeUser:n=>{t(i=>{const o=new Map(i.users);return o.delete(n),{users:o}})},updateCursor:(n,i)=>{t(o=>{const m=o.users.get(n);if(!m)return o;const f=new Map(o.users);return f.set(n,{...m,cursor:i}),{users:f}})},updateActivity:(n,i)=>{t(o=>{const m=o.users.get(n);if(!m)return o;const f=new Map(o.users);return f.set(n,{...m,activity:i}),{users:f}})},setConnected:n=>t({isConnected:n}),setError:n=>t({connectionError:n}),reset:()=>t({users:new Map,isConnected:!1,connectionError:null})}));var cu=5e3;const du=({projectUuid:t,enabled:n=!0})=>{const i=us(C=>C.user),o=Dt(C=>C.users),m=Dt(C=>C.isConnected),f=Dt(C=>C.setUsers),c=Dt(C=>C.setConnected),d=Dt(C=>C.setError),g=Dt(C=>C.reset),v=(0,r.useRef)(null),x=(0,r.useRef)(!1),b=(0,r.useCallback)(async()=>{if(!(!t||!i))try{f(((await Zs.getPresent(t)).data?.data?.users??[]).filter(C=>C.id!==i.id)),x.current||(c(!0),d(null),x.current=!0)}catch{}},[t,i,f,c,d]),_=(0,r.useCallback)(()=>{!n||!t||!i||(b(),v.current=window.setInterval(b,cu))},[n,t,i,b]),A=(0,r.useCallback)(()=>{v.current&&(clearInterval(v.current),v.current=null),t&&x.current&&(Zs.leave(t).catch(()=>{}),x.current=!1),g()},[t,g]);return(0,r.useEffect)(()=>{_();const C=Nc(),D=()=>{if(t&&x.current){const p=Uo.getItem("auth_token");p&&navigator.sendBeacon(`/api/v1/projects/${t}/presence/leave`,new Blob([JSON.stringify({_token:p})],{type:"application/json"}))}},h=()=>{document.visibilityState==="hidden"&&D()};return C?document.addEventListener("visibilitychange",h):window.addEventListener("beforeunload",D),()=>{C?document.removeEventListener("visibilitychange",h):window.removeEventListener("beforeunload",D),A()}},[_,A,t]),{users:(0,r.useMemo)(()=>Array.from(o.values()),[o]),isConnected:m,disconnect:A,reconnect:_}},uu=({projectUuid:t,enabled:n=!0,batchIntervalMs:i=500})=>{const{getViewport:o}=ri(),m=(0,r.useRef)(null),f=(0,r.useRef)(null),c=(0,r.useRef)(null),d=(0,r.useCallback)(async()=>{if(!m.current||!n)return;const x=m.current;if(m.current=null,c.current){const _=Math.abs(x.x-c.current.x),A=Math.abs(x.y-c.current.y);if(_<5&&A<5)return}c.current=x;const b=o();try{await Zs.updateCursor(t,{x:x.x,y:x.y,viewport_x:b.x,viewport_y:b.y,zoom:b.zoom})}catch{}},[n,t,o]),g=(0,r.useCallback)((x,b)=>{m.current={x,y:b},f.current&&clearTimeout(f.current),f.current=window.setTimeout(d,i)},[d,i]),v=(0,r.useCallback)(x=>{if(!n)return;const b=x.currentTarget.getBoundingClientRect(),_=o();g((x.clientX-b.left-_.x)/_.zoom,(x.clientY-b.top-_.y)/_.zoom)},[n,o,g]);return(0,r.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]),{handleMouseMove:v,updateCursor:g}};var mu=({user:t,viewportX:n,viewportY:i,zoom:o})=>t.cursor?(0,e.jsxs)("div",{className:"pointer-events-none fixed z-[9999] transition-transform duration-75",style:{transform:`translate(${t.cursor.x*o+n}px, ${t.cursor.y*o+i}px)`},children:[(0,e.jsx)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",style:{color:t.color},children:(0,e.jsx)("path",{d:"M5.65376 12.4561L5.65376 12.4561L5.65214 12.4506L2.88244 3.79044C2.59442 2.89944 3.49944 2.09442 4.35044 2.48244L4.35044 2.48244L4.35608 2.48486L21.0447 9.7038C21.9048 10.0861 21.8761 11.3071 21.0015 11.6503L21.0014 11.6503L21.0001 11.6508L13.5254 14.5268C13.4253 14.5654 13.3411 14.6369 13.287 14.7294L13.2859 14.7314L9.38603 21.2843C8.9159 22.0752 7.73972 21.9154 7.51197 21.0405L5.65376 12.4561Z",fill:"currentColor",stroke:"white",strokeWidth:"1.5"})}),(0,e.jsx)("div",{className:"absolute left-5 top-5 whitespace-nowrap rounded px-2 py-0.5 text-xs font-medium text-white shadow-sm",style:{backgroundColor:t.color},children:t.name})]}):null;const hu=(0,r.memo)(mu),fu=ur((t,n)=>({annotations:[],selectedAnnotationId:null,isLoading:!1,error:null,fetchAnnotations:async i=>{t({isLoading:!0,error:null});try{t({annotations:(await Ws.list(i)).data.data,isLoading:!1})}catch(o){t({error:o instanceof Error?o.message:"Could not load the notes. Try again.",isLoading:!1})}},createAnnotation:async(i,o)=>{try{const m=(await Ws.create(i,o)).data.data,{annotations:f}=n();return f.find(c=>c.id===m.id)||t({annotations:[...f,m]}),m}catch(m){throw console.error("Failed to create annotation:",m),m}},updateAnnotation:async(i,o)=>{const{annotations:m}=n(),f=m.find(c=>c.id===i);t({annotations:m.map(c=>c.id===i?{...c,...o}:c)});try{await Ws.update(i,o)}catch(c){throw f&&t({annotations:n().annotations.map(d=>d.id===i?f:d)}),c}},deleteAnnotation:async i=>{const{annotations:o,selectedAnnotationId:m}=n(),f=[...o];t({annotations:o.filter(c=>c.id!==i),selectedAnnotationId:m===i?null:m});try{await Ws.delete(i)}catch(c){throw t({annotations:f}),c}},selectAnnotation:i=>{t({selectedAnnotationId:i})},addAnnotation:i=>{const{annotations:o}=n();o.find(m=>m.id===i.id)||t({annotations:[...o,i]})},updateAnnotationLocal:(i,o)=>{t({annotations:n().annotations.map(m=>m.id===i?{...m,...o}:m)})},removeAnnotation:i=>{const{selectedAnnotationId:o}=n();t({annotations:n().annotations.filter(m=>m.id!==i),selectedAnnotationId:o===i?null:o})},batchUpdateLocal:i=>{const{annotations:o}=n(),m=new Map(i.map(f=>[f.id,f]));t({annotations:o.map(f=>m.has(f.id)?{...f,...m.get(f.id)}:f)})},clearAnnotations:()=>{t({annotations:[],selectedAnnotationId:null,error:null})}}));var pu="v1",Po=10,gu=()=>Sc(()=>Uo);const mi=ur()(_c((t,n)=>({hasPrompted:!1,isActive:!1,step:0,completed:!1,startTour:()=>t({hasPrompted:!0,isActive:!0,step:0,completed:!1}),stopTour:()=>t({isActive:!1,hasPrompted:!0,completed:!0}),dismissPrompt:()=>t({hasPrompted:!0,isActive:!1}),nextStep:()=>{const i=n().step;if(i>
2=Po-1){t({isActive:!1,completed:!0,hasPrompted:!0});return}t({step:i+1})},prevStep:()=>{const i=n().step;i<=0||t({step:i-1})},setStep:i=>t({step:Math.max(0,Math.min(Po-1,i))})}),{name:`product-tour-${pu}`,storage:gu(),partialize:t=>({hasPrompted:t.hasPrompted,isActive:t.isActive,step:t.step,completed:t.completed})}));var xu=({data:t})=>{const{annotation:n,isSelected:i,onUpdate:o,onDelete:m,onSelect:f,readOnly:c}=t,[d,g]=(0,r.useState)(!1),[v,x]=(0,r.useState)(n.content||""),b=(0,r.useRef)(null),_=n.style||{},A=_.fontSize||14,C=_.color||"hsl(var(--foreground))",D=_.backgroundColor||"transparent";(0,r.useEffect)(()=>{d&&b.current&&(b.current.focus(),b.current.select())},[d]);const h=()=>{c||g(!0)},p=()=>{g(!1),v!==n.content&&o(n.id,{content:v})},T=E=>{E.key==="Escape"?(x(n.content||""),g(!1)):E.key==="Enter"&&!E.shiftKey&&(E.preventDefault(),p())};return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(br,{minWidth:100,minHeight:30,isVisible:i&&!c,lineClassName:"!border-primary",handleClassName:"!w-2 !h-2 !bg-primary !border-primary"}),(0,e.jsxs)("div",{className:te("group relative cursor-pointer","transition-smooth duration-150",i&&"ring-2 ring-primary ring-offset-1"),style:{width:n.width||200,height:n.height||"auto",minHeight:30,backgroundColor:D,padding:"8px 12px",borderRadius:4},onClick:()=>f(n.id),onDoubleClick:h,children:[!c&&(0,e.jsx)("div",{className:"absolute -left-6 top-1/2 -translate-y-1/2 opacity-0 group-hover:opacity-100 transition-opacity cursor-grab active:cursor-grabbing",children:(0,e.jsx)("div",{className:"p-1 bg-secondary rounded shadow-sm",children:(0,e.jsx)(Ql,{className:"h-3 w-3 text-muted-foreground","aria-hidden":"true"})})}),i&&!c&&(0,e.jsx)("button",{onClick:E=>{E.stopPropagation(),m(n.id)},className:"absolute -top-2 -right-2 w-5 h-5 bg-destructive text-white rounded-full flex items-center justify-center hover:bg-destructive/90 transition-colors z-10 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50","aria-label":"Delete annotation",children:(0,e.jsx)(Gt,{className:"h-3 w-3","aria-hidden":"true"})}),d?(0,e.jsx)("textarea",{ref:b,value:v,onChange:E=>x(E.target.value),onBlur:p,onKeyDown:T,className:"w-full h-full bg-transparent border-none outline-none resize-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40",style:{fontSize:A,color:C,fontWeight:_.fontWeight||"normal",textAlign:_.textAlign||"left"},placeholder:"Type here…","aria-label":"Annotation text",name:"annotation_text",autoComplete:"off"}):(0,e.jsx)("div",{className:te("w-full h-full whitespace-pre-wrap break-words",!v&&"text-muted-foreground italic"),style:{fontSize:A,color:v?C:void 0,fontWeight:_.fontWeight||"normal",textAlign:_.textAlign||"left"},children:v||"Double-click to edit"}),n.creator&&(0,e.jsx)("div",{className:"absolute -bottom-5 left-0 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity",children:n.creator.name})]})]})};const hi=(0,r.memo)(xu);hi.displayName="AnnotationTextNode";var er=[{bg:"hsl(38 92% 90%)",border:"hsl(var(--warning))"},{bg:"hsl(217 91% 90%)",border:"hsl(var(--info))"},{bg:"hsl(160 84% 90%)",border:"hsl(var(--success))"},{bg:"hsl(330 81% 90%)",border:"hsl(330 81% 60%)"},{bg:"hsl(263 70% 90%)",border:"hsl(var(--primary))"},{bg:"hsl(33 90% 90%)",border:"hsl(33 90% 55%)"}],bu=({data:t})=>{const{annotation:n,isSelected:i,onUpdate:o,onDelete:m,onSelect:f,readOnly:c}=t,[d,g]=(0,r.useState)(!1),[v,x]=(0,r.useState)(n.content||""),b=(0,r.useRef)(null),_=n.style||{},A=er[n.id%er.length],C=_.backgroundColor||A.bg,D=_.borderColor||A.border;(0,r.useEffect)(()=>{d&&b.current&&(b.current.focus(),b.current.select())},[d]);const h=()=>{c||g(!0)},p=()=>{g(!1),v!==n.content&&o(n.id,{content:v})},T=E=>{E.key==="Escape"&&(x(n.content||""),g(!1))};return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(br,{minWidth:120,minHeight:80,isVisible:i&&!c,lineClassName:"!border-primary",handleClassName:"!w-2 !h-2 !bg-primary !border-primary"}),(0,e.jsxs)("div",{className:te("group relative cursor-pointer shadow-md","transition-smooth duration-150",i&&"ring-2 ring-primary ring-offset-1 shadow-lg"),style:{width:n.width||180,height:n.height||120,backgroundColor:C,borderLeft:`4px solid ${D}`,borderRadius:4,padding:12},onClick:()=>f(n.id),onDoubleClick:h,children:[(0,e.jsx)("div",{className:"absolute top-0 right-0 w-6 h-6",style:{background:`linear-gradient(135deg, transparent 50%, ${D}30 50%)`}}),i&&!c&&(0,e.jsx)("button",{onClick:E=>{E.stopPropagation(),m(n.id)},className:"absolute -top-2 -right-2 w-5 h-5 bg-destructive text-white rounded-full flex items-center justify-center hover:bg-destructive/90 transition-colors z-10 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50","aria-label":"Delete note",children:(0,e.jsx)(Gt,{className:"h-3 w-3","aria-hidden":"true"})}),i&&!c&&(0,e.jsx)("div",{className:"absolute -bottom-8 left-0 flex gap-1 bg-background rounded-lg shadow-lg p-1 opacity-0 group-hover:opacity-100 transition-opacity",children:er.map((E,O)=>(0,e.jsx)("button",{onClick:X=>{X.stopPropagation(),o(n.id,{style:{..._,backgroundColor:E.bg,borderColor:E.border}})},className:te("w-4 h-4 rounded-full border-2 hover:scale-110 transition-transform",C===E.bg&&"ring-2 ring-primary ring-offset-1"),style:{backgroundColor:E.bg,borderColor:E.border},"aria-label":`Set note color ${E.bg}`,"aria-pressed":C===E.bg},O))}
2),d?(0,e.jsx)("textarea",{ref:b,value:v,onChange:E=>x(E.target.value),onBlur:p,onKeyDown:T,className:"w-full h-full bg-transparent border-none outline-none resize-none text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40",style:{color:"hsl(var(--muted-foreground))"},placeholder:"Add a note…","aria-label":"Sticky note",name:"sticky_note",autoComplete:"off"}):(0,e.jsx)("div",{className:te("w-full h-full text-sm whitespace-pre-wrap break-words overflow-hidden",!v&&"text-gray-400 italic"),style:{color:"hsl(var(--muted-foreground))"},children:v||"Double-click to add note"}),n.creator&&(0,e.jsx)("div",{className:"absolute bottom-1 right-2 text-[10px] opacity-50",style:{color:D},children:n.creator.name})]})]})};const fi=(0,r.memo)(bu);fi.displayName="AnnotationStickyNode";var vu=({data:t})=>{const{annotation:n,isSelected:i,onDelete:o,onSelect:m,readOnly:f}=t,c=n.content||"",d=n.style?.fontSize||32;return(0,e.jsxs)("div",{className:te("group relative cursor-pointer","transition-smooth duration-150",i&&" ring-offset-2 rounded-full"),onClick:()=>m(n.id),children:[i&&!f&&(0,e.jsx)("button",{onClick:g=>{g.stopPropagation(),o(n.id)},className:"absolute -top-2 -right-2 w-5 h-5 bg-destructive text-white rounded-full flex items-center justify-center hover:bg-destructive/90 transition-colors z-10 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50","aria-label":"Delete emoji",children:(0,e.jsx)(Gt,{className:"h-3 w-3","aria-hidden":"true"})}),(0,e.jsx)("div",{className:"select-none hover:scale-110 transition-transform",style:{fontSize:d},children:c}),n.creator&&(0,e.jsx)("div",{className:"absolute -bottom-4 left-1/2 -translate-x-1/2 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap",children:n.creator.name})]})};const pi=(0,r.memo)(vu);pi.displayName="AnnotationEmojiNode";var yu=["hsl(var(--destructive))","hsl(33 90% 55%)","hsl(var(--warning))","hsl(var(--success))","hsl(var(--info))","hsl(var(--primary))","hsl(330 81% 60%)","hsl(var(--muted-foreground))"],wu=({data:t})=>{const{annotation:n,isSelected:i,onUpdate:o,onDelete:m,onSelect:f,readOnly:c}=t,[d,g]=(0,r.useState)(!1),v=n.style||{},x=v.color||"hsl(var(--destructive))",b=v.rotation||0,_=v.strokeWidth||3,A=n.width||120,C=n.height||40,D=h=>{h.stopPropagation();const p=(b+45)%360;o(n.id,{style:{...v,rotation:p}})};return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(br,{minWidth:60,minHeight:20,isVisible:i&&!c,lineClassName:"!border-primary",handleClassName:"!w-2 !h-2 !bg-primary !border-primary",onResize:(h,p)=>{o(n.id,{width:p.width,height:p.height})}}),(0,e.jsxs)("div",{className:te("group relative cursor-pointer","transition-smooth duration-150",i&&"ring-2 ring-primary ring-offset-2 rounded"),style:{width:A,height:C,padding:4},onClick:()=>f(n.id),children:[i&&!c&&(0,e.jsx)("button",{onClick:h=>{h.stopPropagation(),m(n.id)},className:"absolute -top-2 -right-2 w-5 h-5 bg-destructive text-white rounded-full flex items-center justify-center hover:bg-destructive/90 transition-colors z-10 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50","aria-label":"Delete arrow",children:(0,e.jsx)(Gt,{className:"h-3 w-3","aria-hidden":"true"})}),i&&!c&&(0,e.jsx)("button",{onClick:D,onMouseDown:()=>g(!0),onMouseUp:()=>g(!1),onMouseLeave:()=>g(!1),"aria-label":"Rotate arrow",className:te("absolute -top-2 -left-2 w-5 h-5 bg-secondary text-foreground rounded-full flex items-center justify-center hover:bg-secondary-hover transition-colors z-10 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",d&&"bg-primary text-primary-foreground"),children:(0,e.jsx)(rc,{className:"h-3 w-3","aria-hidden":"true"})}),(0,e.jsxs)("svg",{width:"100%",height:"100%",viewBox:`0 0 ${A} ${C}`,style:{transform:`rotate(${b}deg)`,transformOrigin:"center"},children:[(0,e.jsx)("defs",{children:(0,e.jsx)("marker",{id:`arrowhead-${n.id}`,markerWidth:"10",markerHeight:"7",refX:"9",refY:"3.5",orient:"auto",children:(0,e.jsx)("polygon",{points:"0 0, 10 3.5, 0 7",fill:x})})}),(0,e.jsx)("line",{x1:10,y1:C/2,x2:A-15,y2:C/2,stroke:x,strokeWidth:_,strokeLinecap:"round",markerEnd:`url(#arrowhead-${n.id})`})]}),i&&!c&&(0,e.jsx)("div",{className:"absolute top-full left-1/2 -translate-x-1/2 mt-3 flex gap-1.5 bg-card border border-border rounded-xl shadow-xl p-2 z-20",children:yu.map((h,p)=>(0,e.jsx)("button",{onClick:T=>{T.stopPropagation(),o(n.id,{style:{...v,color:h}})},className:te("w-6 h-6 rounded-full hover:scale-110 transition-transform",x===h&&"ring-2 ring-primary ring-offset-2"),style:{backgroundColor:h}},p))}),n.creator&&(0,e.jsx)("div",{className:"absolute -bottom-5 left-1/2 -translate-x-1/2 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap",children:n.creator.name})]})]})};const gi=(0,r.memo)(wu);gi.displayName="AnnotationArrowNode";var Su=[{type:"sticky",icon:Bl,label:"Sticky note",ariaLabel:"Add sticky note",description:"Add a colored sticky note"},{type:"text",icon:bc,label:"Text",ariaLabel:"Add text",description:"Add plain text annotation"},{type:"arrow",icon:Gl,label:"Arrow",ariaLabel:"Add arrow",description:"Add directional arrow"},{type:"emoji",icon:Vl,label:"Emoji",ariaLabel:"Add emoji",description:"Add emoji reaction"}],_u=["👍","👎","❤️","🔥","⭐","✅","❌","💡","🎯","🚀","💪","👀","🤔","😊","🎉","⚠️"],ju=({onAddAnnotation:t,disabled:n,className:i,pendingAnnotationType:o})=>{const[m,f]=(0,r.useState)(!1),c=Su.filter(g=>g.type!=="arrow"),d=g=>{t("emoji",g),f(!1)};return(0,e.jsx)("div",{className:te("flex items-center gap-1 bg-card/95 backdrop-blur-sm border border-border rounded-xl p-1.5 shadow-lg",i),children:c.map(g=>g.type==="emoji"?(0,e.jsxs)("div",{className:"relative",children:[(0,e.jsx)(Us,{content:g.description,side:"bottom",children:(0,e.jsx)(ms,{onClick:()=>f(!m),disabled:n,"aria-label":g.ariaLabel,"aria-expanded":m,"aria-pressed":o===g.type||m,className:"text-muted-foreground hover:text-foreground",icon:(0,e.jsx)(g.icon,{className:"h-4 w-4"})})}),m&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"fixed inset-0 z-40",onClick:()=>f(!1)}),(0,e.jsx)("div",{className:"absolute top-full left-0 mt-2 bg-card border border-border rounded-xl shadow-xl p-3 grid grid-cols-4 gap-2 z-50 min-w-[200px]",children:_u.map((v,x)=>(0,e.jsx)("button",{onClick:()=>d(v),"aria-label":`Add ${v}`,disabled:n,className:te("w-10 h-10 text-2xl rounded-lg hover:bg-surface-hover transition-smooth hover:scale-110 flex items-center justify-center outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50","disabled:opacity-50 disabled:cursor-not-allowed"),children:v},x))})]})]},g.type):(0,e.jsx)(Us,{content:g.description,side:"bottom",children:(0,e.jsx)(ms,{onClick:()=>t(g.type),disabled:n,"aria-label":g.ariaLabel,"aria-pressed":o===g.type,className:"text-muted-foreground hover:text-foreground",icon:(0,e.jsx)(g.icon,{className:"h-4 w-4"})})},g.type))})};const xi=(0,r.memo)(ju);xi.displayName="AnnotationToolbar";function Cu(){const[t,n]=(0,r.useState)(null),{showUpgrade:i}=hs(),o=(0,r.useRef)(!0),m=(0,r.useCallback)(async()=>{try{const d=(await Qo.allowance()).data?.data??null;return o.current&&n(d),d}catch{return null}},[]);(0,r.useEffect)(()=>
2(o.current=!0,m(),()=>{o.current=!1}),[m]);const f=d=>!!d?.metered&&d.remaining_cents!=null&&d.remaining_cents<=0,c=(0,r.useCallback)(async d=>f(await m()??t)?(i({feature:d,message:"You have used this month's generation budget. Add budget or upgrade to keep generating."}),!0):!1,[m,t,i]);return{allowance:t,exhausted:f(t),blockIfExhausted:c,refreshAllowance:m}}var Fo="ai_animation",Nu={open:!1,title:"",scope:"",shotIds:[],estimate:null,error:null},ku={in_progress:t=>`${t} ${t===1?"is":"are"} still generating`,has_video:t=>`${t} already ${t===1?"has":"have"} a video clip`,no_image:t=>`${t} ${t===1?"has":"have"} no storyboard picture`,no_prompt:t=>`${t} ${t===1?"has":"have"} no video prompt yet`};function Mo(t){const n=new Map;for(const{reason:i}of t.excluded)n.set(i,(n.get(i)??0)+1);return[...n.entries()].map(([i,o])=>ku[i]?.(o)??`${o}`).join(" · ")}function Au(t){const n=new Map;for(const m of t)n.set(m.duration_seconds,(n.get(m.duration_seconds)??0)+1);const i=[...n.entries()].sort((m,f)=>f[1]-m[1]),o=i.slice(0,3).map(([m,f])=>`${f} ${f===1?"shot":"shots"} of ${m} sec`);return i.length>3&&o.push(`${i.length-3} more lengths`),o.join(" · ")}var Io=t=>t.reduce((n,i)=>n+i.duration_seconds,0);function tr(t){const n=Math.round(t);if(n<60)return`${n} sec`;const i=Math.floor(n/60),o=n%60;return o===0?`${i} min`:`${i} min ${o} sec`}function Tu(){const[t,n]=(0,r.useState)(Nu),i=(0,r.useRef)(null),o=(0,r.useRef)(0),{showUpgrade:m}=hs(),f=(0,r.useCallback)(V=>{i.current?.(V),i.current=null,o.current++,n(R=>({...R,open:!1}))},[]),c=(0,r.useCallback)(V=>{i.current?.(null);const R=++o.current;n({...V,open:!1,estimate:null,error:null});const M=window.setTimeout(()=>{o.current===R&&n(q=>({...q,open:!0}))},600);return Qo.videoEstimate(V.shotIds).then(q=>{if(window.clearTimeout(M),o.current!==R)return;const G=q.data.data;if(G.fits&&G.excluded.length===0&&!G.unavailable&&G.shots>0){f(G.affordable_frame_ids);return}n(oe=>({...oe,estimate:G,open:!0}))}).catch(q=>{if(window.clearTimeout(M),o.current!==R)return;const G=q?.response,oe=G?.status??500,ie=!G||oe>=500||oe===422||oe===429;n(_e=>({..._e,open:!0,error:{message:ie?"This run could not be checked against your plan.":G?.data?.message??"This run could not be checked against your plan.",canProceed:ie}}))}),new Promise(q=>{i.current=q})},[f]),{estimate:d,error:g,shotIds:v}=t,x=d?.shots??v.length,b=d?.frames.filter(V=>V.provider_slug===Fo).length??0,_=d?.frames.find(V=>V.provider_slug!==Fo)?.provider_name,A=d?.excluded.length??0,C=d?.unavailable??null,D=!!d&&(!!C||d.shots===0),h=d?.fits??!1,p=!!d&&!D&&!h,T=d?.affordable_count??0,E=d?Io(d.frames):0,O=d?Io(d.frames.slice(0,T)):0,X=()=>{if(!d)return;const V=Math.max(0,d.unaffordable_cents-d.funding.wallet_balance_after_cents);f(null),m({feature:"generate-video",upgrade:d.upgrade??void 0,initialAmountCents:d.funding.wallet_usable?Math.max(1e3,Math.ceil(V/100)*100):void 0,message:`This run is ${tr(E)} of film across ${F(d.shots,"shot")}, and your plan allows ${T===0?"none of it":`the first ${F(T,"shot")}`} this month. See plans to make the rest.`})},$="See plans",k=d?.stopped_reason!=="wallet_overage_disabled";return{confirmBulkVideoRun:c,bulkVideoCostDialog:(0,e.jsx)(xr,{open:t.open,onOpenChange:V=>!V&&f(null),children:(0,e.jsxs)(fr,{className:"max-w-md gap-5",children:[(0,e.jsxs)(mr,{children:[(0,e.jsx)(pr,{children:t.title}),(0,e.jsx)(gr,{children:x===0&&A>0?(0,e.jsxs)(e.Fragment,{children:["None of the"," ",F(d?.requested_shots??v.length,"shot")," ",t.scope," can make a video clip right now."]}):(0,e.jsxs)(e.Fragment,{children:[F(x,"shot")," ",t.scope,". Each one is made at the length you set for it",_&&b<x?`, by the ${_} video model.`:".",b>0&&` The AI animates ${b===x?b===1?"it":`all ${b}`:F(b,"shot")}.`]})})]}),(0,e.jsxs)("dl",{className:"grid grid-cols-[1fr_auto] gap-x-4 gap-y-2 rounded-lg border border-border bg-background px-4 py-3 text-sm","aria-busy":!d&&!g,children:[(0,e.jsx)("dt",{className:"text-muted-foreground",children:"Shots"}),(0,e.jsx)("dd",{className:"text-right font-mono tabular-nums",children:x}),d&&A>0&&(0,e.jsxs)("dd",{className:"col-span-2 -mt-1 text-right text-xs text-muted-foreground",children:[A," skipped: ",Mo(d)]}),(0,e.jsx)("dt",{className:"text-muted-foreground",children:"Film made"}),(0,e.jsx)("dd",{className:"text-right font-mono tabular-nums",children:d&&!C?tr(E):g||C?"—":(0,e.jsx)("span",{className:"inline-block h-4 w-14 animate-pulse rounded bg-muted align-middle motion-reduce:animate-none"})}),d&&d.frames.length>0&&(0,e.jsx)("dd",{className:"col-span-2 -mt-1 text-right text-xs text-muted-foreground",children:Au(d.frames)}),d&&p&&T>0&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("dt",{className:"border-t border-border pt-2 text-muted-foreground",children:"Made this month"}),(0,e.jsxs)("dd",{className:"border-t border-border pt-2 text-right font-mono tabular-nums",children:[F(T,"shot")," · ",tr(O)]})]})]}),D&&d&&(0,e.jsxs)("div",{role:"status",className:"flex gap-2.5 rounded-md border border-warning/40 bg-warning-muted px-3 py-2.5 text-sm",children:[(0,e.jsx)(Xs,{className:"mt-0.5 h-4 w-4 shrink-0 text-warning","aria-hidden":"true"}),(0,e.jsx)("p",{children:C?C.message:`None of these shots can be generated: ${Mo(d)}.`})]}),p&&d&&(0,e.jsxs)("div",{role:"status",className:"flex gap-2.5 rounded-md border border-warning/40 bg-warning-muted px-3 py-2.5 text-sm",children:[(0,e.jsx)(Xs,{className:"mt-0.5 h-4 w-4 shrink-0 text-warning","aria-hidden":"true"}),(0,e.jsxs)("p",{children:[T===0?"This is more than your plan allows this month. Nothing will be made.":`This is more than your plan allows this month. The first ${F(T,"shot")} will be made. The other ${d.shots-T} will not start.`,d.stopped_reason==="subscription_required"&&" Making video clips needs an active plan."]})]}),g&&(0,e.jsxs)("p",{role:"alert",className:"text-sm text-muted-foreground",children:[g.message,g.canProceed&&" Each shot is still checked as it is sent, and the run stops when your plan runs out for this month."]}),(0,e.jsxs)(hr,{className:"flex-col-reverse gap-2 sm:flex-row sm:flex-wrap sm:justify-end sm:space-x-0",children:[(0,e.jsx)(P,{variant:"outline",onClick:()=>f(null),children:"Cancel"}),p&&d&&k&&(0,e.jsx)(P,{variant:T===0?"default":"secondary",onClick:X,children:$}),d&&!D&&h&&(0,e.jsxs)(P,{onClick:()=>f(d.affordable_frame_ids),children:["Generate ",F(d.shots,"video clip")]}),p&&d&&T>0&&(0,e.jsxs)(P,{onClick:()=>f(d.affordable_frame_ids),children:["Generate the first ",T]}),!d&&!g&&(0,e.jsxs)(P,{isLoading:!0,disabled:!0,children:["Generate ",F(x,"video clip")]}),g?.canProceed&&(0,e.jsxs)(P,{onClick:()=>f(v),children:["Generate ",F(x,"video clip")]})]})]})})}}const Eu=t=>["completed","failed","cancelled"].includes(t.status);function bi(t,n,i=[]){return[...i,...(t.metadata?.notes??[]).map(o=>{const m=n(o.frame_id);return m?`Shot ${m}: ${o.message}`:o.message}
2)].filter(Boolean).join(" ")}function Ru(t,{noun:n,shotNumber:i,notes:o=[]}){const m=t.batch_stats?.total_frames??t.metadata?.total_frames??0,f=t.batch_stats?.completed??0,c=t.batch_stats?.failed??0,d=bi(t,i,o),g=d===""?"":` ${d}`;if(t.metadata?.stopped_reason==="allowance_exhausted"){const v=t.metadata.not_generated??Math.max(0,m-f);return{tone:"warning",budgetStop:!0,message:f===0?`This is more than your plan allows this month, so none of the ${F(m,n)} could start.${g}`:`Generated ${f} of ${F(m,n)}. This is more than your plan allows this month, so the other ${v} did not start.${g}`}}return t.status==="cancelled"?{tone:"info",budgetStop:!1,message:`Stopped. ${f} of ${F(m,n)} generated.${g}`}:t.status==="failed"?{tone:"error",budgetStop:!1,message:`This run stopped before it finished. ${f} of ${F(m,n)} generated. Generate again to make the rest.${g}`}:f<m||c>0||d!==""?{tone:"warning",budgetStop:!1,message:`Generated ${f} of ${F(m,n)}.${c>0?` ${c} could not be generated.`:""}${g}`}:{tone:"success",budgetStop:!1,message:m===1?`Generated the ${n}.`:`Generated all ${F(m,n)}.`}}const Pu=({steps:t,startStep:n,endStep:i,finalStepAction:o="stop",finalStepLabel:m})=>{const{isActive:f,step:c,nextStep:d,prevStep:g,stopTour:v}=mi(),[x,b]=(0,r.useState)(null),_=c-n,A=f&&c>=n&&c<=i,C=_>=0&&_<t.length?t[_]:null;(0,r.useEffect)(()=>{if(!A||!C){b(null);return}const O=()=>{const k=document.querySelector(C.selector);if(!k){b(null);return}k.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"}),b(k.getBoundingClientRect())},X=k=>{const V=document.querySelector(C.selector);if(V&&k.target instanceof Node&&V.contains(k.target)){if(C.autoAdvanceOnClick===!1)return;c===i?o==="next"?d():v():d()}},$=window.requestAnimationFrame(O);return window.addEventListener("resize",O),window.addEventListener("scroll",O,!0),document.addEventListener("click",X,!0),()=>{window.cancelAnimationFrame($),window.removeEventListener("resize",O),window.removeEventListener("scroll",O,!0),document.removeEventListener("click",X,!0)}},[C,i,o,A,d,c,v]);const D=(0,r.useMemo)(()=>{if(!x)return{top:"20px",right:"20px"};const O=360,X=window.innerWidth,$=window.innerHeight;let k=x.right+16,V=x.top;return k+O>X-16&&(k=Math.max(16,x.left-O-16)),V=Math.max(16,Math.min(V,$-220)),{left:`${k}px`,top:`${V}px`}},[x]);if(!A||!C)return null;const h=c===n,p=c===i,T=()=>{const O=C?document.querySelector(C.selector):null;O&&!C?.noClickOnNext&&O.click(),p?o==="next"?d():v():d()},E=p?m??(o==="next"?"Next":"Finish"):"Next";return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"fixed inset-0 bg-black/60 z-[1200] pointer-events-none"}),x&&(0,e.jsx)("div",{className:"fixed z-[1201] rounded-xl border-2 border-primary pointer-events-none",style:{top:`${x.top-6}px`,left:`${x.left-6}px`,width:`${x.width+12}px`,height:`${x.height+12}px`,boxShadow:"0 0 0 2px rgba(255,255,255,0.15)"}}),(0,e.jsxs)("div",{className:"fixed z-[1202] w-[min(360px,calc(100vw-32px))] rounded-xl border border-border bg-card shadow-2xl p-4 space-y-3",style:D,children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-xs text-primary font-medium uppercase tracking-wide",children:"Product Tour"}),(0,e.jsx)("h3",{className:"text-base font-semibold text-foreground",children:C.title}),(0,e.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:C.description})]}),!x&&(0,e.jsx)("p",{className:"text-xs text-warning",children:"This step target is not visible yet. Complete the previous action, then click Next."}),(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsxs)("span",{className:"text-xs text-muted-foreground",children:["Step ",c+1," of 10"]}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(P,{variant:"ghost",size:"sm",onClick:v,children:"Stop Tour"}),(0,e.jsx)(P,{variant:"outline",size:"sm",onClick:g,disabled:h,children:"Prev"}),(0,e.jsx)(P,{size:"sm",onClick:T,children:E})]})]})]})]})};var Fu=({id:t,sourceX:n,sourceY:i,targetX:o,targetY:m,sourcePosition:f,targetPosition:c,style:d,data:g})=>{const[v,x,b]=id({sourceX:n,sourceY:i,targetX:o,targetY:m,sourcePosition:f,targetPosition:c}),_=g?.transitionType||"cut",A=_!=="cut",C=A?vd(_):null;return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(od,{id:t,path:v,style:d}),A&&C&&(0,e.jsx)("foreignObject",{x:x-16,y:b-16,width:32,height:32,className:"pointer-events-auto overflow-visible",children:(0,e.jsx)("button",{onClick:D=>{D.stopPropagation(),g?.onTransitionClick?.()},className:"w-6 h-6 rounded-full bg-primary/90 hover:bg-primary flex items-center justify-center shadow-sm transition-colors outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",title:`${C.name} (${g?.transitionDuration??.5}s)`,children:(0,e.jsx)(Ol,{className:"h-3 w-3 text-white"})})})]})},Mu=Fu,Iu=["#6366f1","#f59e0b","#10b981","#ef4444","#8b5cf6","#ec4899","#06b6d4","#f97316"];function sr(t){const n=Math.floor(t/60),i=Math.round(t%60);return n>0?`${n}m ${i}s`:`${i}s`}var Du=({data:t})=>{const{scene:n,isCollapsed:i,frameCount:o,durationSeconds:m,readOnly:f,progress:c,onToggleCollapse:d,onRename:g,onChangeColor:v,onDelete:x,onSelectAllFrames:b,onGenerateSceneImages:_,onGenerateSceneVideos:A}=t,[C,D]=(0,r.useState)(!1),[h,p]=(0,r.useState)(n.name),[T,E]=(0,r.useState)(!1),O
2=(0,r.useRef)(null),X=(0,r.useRef)(null);(0,r.useEffect)(()=>{C&&O.current&&(O.current.focus(),O.current.select())},[C]),(0,r.useEffect)(()=>{if(!T)return;const M=q=>{X.current&&!X.current.contains(q.target)&&E(!1)};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[T]);const $=(0,r.useCallback)(M=>{f||(M.stopPropagation(),p(n.name),D(!0))},[f,n.name]),k=(0,r.useCallback)(()=>{D(!1);const M=h.trim();M&&M!==n.name?g(n.id,M):p(n.name)},[h,n.name,n.id,g]),V=(0,r.useCallback)(M=>{M.key==="Enter"?k():M.key==="Escape"&&(D(!1),p(n.name))},[k,n.name]),R=(0,e.jsxs)("div",{className:te("flex items-center gap-2 px-3 select-none"),style:{height:40},onDoubleClick:$,children:[(0,e.jsx)(ms,{size:"icon-sm",onClick:M=>{M.stopPropagation(),d(n.id)},"aria-label":i?"Expand scene":"Collapse scene","aria-expanded":!i,className:"nodrag h-6 w-6 rounded-md text-muted-foreground hover:text-foreground",icon:i?(0,e.jsx)(vc,{className:"w-4 h-4"}):(0,e.jsx)(Bo,{className:"w-4 h-4"})}),(0,e.jsx)("div",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{backgroundColor:n.color}}),C?(0,e.jsx)("input",{ref:O,value:h,onChange:M=>p(M.target.value),onBlur:k,onKeyDown:V,className:"nodrag flex-1 min-w-0 bg-secondary border border-border-strong rounded-md px-1.5 py-0.5 text-sm text-foreground font-medium outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",maxLength:100}):(0,e.jsx)("span",{className:"flex-1 min-w-0 truncate text-sm font-medium text-foreground",children:n.name}),c&&(0,e.jsxs)(ei,{variant:"primary",className:"gap-1.5 animate-pulse",children:[(0,e.jsx)(xe,{className:"w-3 h-3 animate-spin"}),(0,e.jsxs)("span",{children:[c.type==="images"?"Storyboards":"Video clips"," ",c.current,"/",c.total]}),!f&&t.onStopRun&&(0,e.jsx)("button",{type:"button",onClick:M=>{M.stopPropagation(),t.onStopRun?.(n.id)},className:"nodrag ml-1 rounded-md px-1 text-primary underline-offset-2 hover:underline outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",children:"Stop"})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1 text-xs text-muted-foreground flex-shrink-0",children:[(0,e.jsx)(We,{className:"w-3 h-3"}),(0,e.jsx)("span",{children:o})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1 text-xs text-muted-foreground flex-shrink-0",children:[(0,e.jsx)(qo,{className:"w-3 h-3"}),(0,e.jsx)("span",{children:sr(m)})]}),!f&&(_||A)&&(0,e.jsxs)(ni,{children:[(0,e.jsx)(si,{asChild:!0,children:(0,e.jsx)(ms,{type:"button",size:"icon-sm",onClick:M=>M.stopPropagation(),className:"nodrag nopan text-muted-foreground hover:text-foreground",title:"Scene options","aria-label":"Scene options",icon:(0,e.jsx)(Yo,{className:"w-4 h-4"})})}),(0,e.jsxs)(ti,{align:"end",className:"w-52 z-[9999]",children:[_&&(0,e.jsxs)(ds,{className:"cursor-pointer text-xs",onClick:M=>{M.stopPropagation(),_(n.id)},children:[(0,e.jsx)(Lt,{className:"w-3.5 h-3.5 mr-2 text-amber-400 flex-shrink-0"}),"Draw storyboards for all shots"]}),A&&(0,e.jsxs)(ds,{className:"cursor-pointer text-xs",onClick:M=>{M.stopPropagation(),A(n.id)},children:[(0,e.jsx)(We,{className:"w-3.5 h-3.5 mr-2 text-blue-400 flex-shrink-0"}),"Make video clips for all shots"]})]})]})]});return f?(0,e.jsxs)("div",{className:te("rounded-lg border transition-all w-full",i?"bg-card/80":"bg-card/40"),style:{borderColor:`${n.color}33`,borderTopColor:n.color,borderTopWidth:2},children:[R,i&&(0,e.jsx)("div",{className:"px-3 pb-2",children:(0,e.jsxs)("p",{className:"text-xs text-muted-foreground italic",children:[o," shots · ",sr(m)]})})]}):(0,e.jsxs)(hd,{children:[(0,e.jsx)(dd,{asChild:!0,children:(0,e.jsxs)("div",{className:te("rounded-lg border transition-all w-full",i?"bg-card/80":"bg-card/40"),style:{borderColor:`${n.color}33`,borderTopColor:n.color,borderTopWidth:2},children:[R,i&&(0,e.jsx)("div",{className:"px-3 pb-2",children:(0,e.jsxs)("p",{className:"text-xs text-muted-foreground italic",children:[o," shots · ",sr(m)]})})]})}),(0,e.jsxs)(ud,{className:"w-56",children:[(0,e.jsx)(md,{className:"text-xs text-muted-foreground",children:n.name}),(0,e.jsx)(Qn,{}),_&&(0,e.jsxs)(Mt,{onClick:()=>_(n.id),children:[(0,e.jsx)(Lt,{className:"w-4 h-4 mr-2 text-amber-400"}),"Draw storyboards for all shots"]}),A&&(0,e.jsxs)(Mt,{onClick:()=>A(n.id),children:[(0,e.jsx)(We,{className:"w-4 h-4 mr-2 text-blue-400"}),"Make video clips for all shots"]}),(_||A)&&(0,e.jsx)(Qn,{}),(0,e.jsxs)(Mt,{onClick:()=>{p(n.name),D(!0)},children:[(0,e.jsx)(oc,{className:"w-4 h-4 mr-2"}),"Rename scene"]}),(0,e.jsxs)(Mt,{onClick:()=>E(!T),children:[(0,e.jsx)(Xo,{className:"w-4 h-4 mr-2"}),"Change color"]}),(0,e.jsxs)(Mt,{onClick:()=>b(n.id),children:[(0,e.jsx)(Ll,{className:"w-4 h-4 mr-2"}),"Select all shots"]}),(0,e.jsx)(Qn,{}),(0,e.jsxs)(Mt,{onClick:()=>x(n.id),className:"text-destructive focus:text-destructive",children:[(0,e.jsx)(Ho,{className:"w-4 h-4 mr-2"}),"Delete scene"]})]}),T&&(0,e.jsx)("div",{ref:X,className:"absolute top-full left-3 mt-1 p-2 bg-popover border border-border rounded-lg shadow-xl z-50 flex gap-1.5",children:Iu.map(M=>(0,e.jsx)("button",{onClick:()=>{v(n.id,M),E(!1)},className:te("w-6 h-6 rounded-full border-2 transition-transform hover:scale-110 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",n.color===M?"border-white scale-110":"border-transparent"),style:{backgroundColor:M}},M))})]})};const $u=(0,r.memo)(Du);var Lu=(0,r.lazy)(()=>K(()=>import("./TransitionPicker.BauYrp91.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]))),Gu=(0,r.lazy)(()=>K(()=>import("./FramePairEditor.C5GYFgik.js"),__vite__mapDeps([21,1,2,3,4,5,6,7,8,9,22,23,24,25])).then(t=>({default:t.FramePairEditor}))),zu=(0,r.lazy)(()=>K(()=>import("./MotionEditor.CyEx2Eo8.js"),__vite__mapDeps([26,1,2,3,4,5,6,7,8,9,27,11,12,17,10,13,14,15,28,29,30,31,16,32,33,19,34,35,36,37,38,25,39,40,22,41,20,42,43,44,24,45,46,47,48,49,50,51,52,53,54,55,56,57,58,23,59,60,61,62,63,64])).then(t=>({default:t.MotionEditor}))),Vu=(0,r.lazy)(()=>K(()=>import("./AnimationEditor.BF-0lfx5.js"),__vite__mapDeps([65,1,2,3,4,5,6,7,8,9,27,11,12,17,10,13,14,15,16,32,30,34,35,36,37,38,25,41,20,42,43,44,24,45,19,31,46,53,55,66,56,23,59,51])).then(t=>({default:t.AnimationEditor}))),Wu=(0,r.lazy)(()=>K(()=>import("./TimelineEditor.qDd7h1nG.js"),__vite__mapDeps([67,1,2,3,4,5,6,7,8,9,68,27,11,12,17,10,13,14,15,28,16,32,30,33,19,34,35,36,37,38,25,55,56,69,70,71])).then(t=>({default:t.TimelineEditor}))),Bu=(0,r.lazy)(()=>K(()=>import("./FrameEditorSidebar.Duq-I0lF.js"),__vite__mapDeps([72,1,2,3,4,5,6,7,8,9,27,11,12,17,10,13,73,28,15,74,75,34,35,36,37,38,25,39,44,24,45,55,32,30,76,14,77,29,31,78,40,22,19,20,79,80,56,81,82])).then(t=>({default:t.FrameEditorSidebar}))),Ou=(0,r.lazy)(()=>K(()=>import("./AudioTrackEditorSidebar.C31xXGHn.js"),__vite__mapDeps([83,1,2,3,4,5,6,7,8,9,27,11,12,17,10,13,77,16,32,30,80,55,35,31])).then(t=>({default:t.AudioTrackEditorSidebar}))),Yu=(0,r.lazy)(()=>K(()=>import("./ExportModal.Mj-YrjKy.js"),__vite__mapDeps([84,1,2,3,4,5,6,7,8,9,27,11,12,17,10,13,14,15,77,29,30,31,32,85,55,19,25,86,38,87,76])).then(t=>({default:t.ExportModal}))),Hu=(0,r.lazy)(()=>K(()=>import("./AudioGenerationModal.Bvs-C8vH.js"),__vite__mapDeps([88,1,2,3,4,5,6,7,8,9,27,11,12,17,10,13,14,15,77,29,30,31,16,80,35,19,36,59])).then(t=>({default:t.AudioGenerationModal}))),qu=(0,r.lazy)(()=>K(()=>import("./MusicGenerationModal.3M7beR6F.js"),__vite__mapDeps([89,1,2,3,4,5,6,7,8,9,27,11,12,17,10,13,14,15,77,29,30,31,16,19,37,59])).then(t=>({default:t.MusicGenerationModal}))),Ku=(0,r.lazy)(()=>K(()=>import("./AssetGalleryModal.DBIZWl9v.js"),__vite__mapDeps([90,27,2,3,4,5,11,12,7,17,10,13,14,15,29,1,6,8,9,30,31,32,91,55,19,36,24,92])).then(t=>({default:t.AssetGalleryModal}))),Ju=(0,r.lazy)(()=>K(()=>import("./ImportAssetsModal.CAdyaFRA.js"),__vite__mapDeps([93,1,2,3,4,5,6,7,8,9,11,12,14,15,19,31])).then(t=>({default:t.ImportAssetsModal}))),Xu=(0,r.lazy)(()=>K(()=>import("./ShareModal.D9N4WEer.js"),__vite__mapDeps([94,1,2,3,4,5,6,7,8,9,11,12,14,15,19,31])).then(t=>({default:t.ShareModal}))),Qu=(0,r.lazy)(()=>K(()=>import("./PreviewModal.DPdhlJFJ.js"),__vite__mapDeps([95,1,2,3,4,5,6,7,8,9,34,35,36,37,38,25,96,18,81,97,86,71,62])).then(t=>({default:t.PreviewModal}))),Zu=(0,r.lazy)(()=>K(()=>import("./ConnectChatGptModal.DyTYlJ-k.js"),__vite__mapDeps([98,2,3,4,5,11,12,7,14,15,6,99,1,8,9,100,19,20])).then(t=>({default:t.ConnectChatGptModal}))),Uu=(0,r.lazy)(()=>K(()=>import("./StoryDialog.BRy-LCta.js"),__vite__mapDeps([101,1,2,3,4,5,6,7,8,9,11,12,14,15,19,31,37,25])).then(t=>({default:t.StoryDialog}
2))),em=(0,r.lazy)(()=>K(()=>import("./FilmLookDialog.C-5jROuI.js"),__vite__mapDeps([102,1,2,3,4,5,6,7,8,9,27,11,12,17,10,13,14,15,29,30,31,32,91,55,19,36,24,92,103,35,25,52,45])).then(t=>({default:t.FilmLookDialog}))),tm=(0,r.lazy)(()=>K(()=>import("./LocationPanel.BIYbZa-u.js"),__vite__mapDeps([104,1,2,3,4,5,6,7,8,9,11,12,14,15,105,45,48,19,49])).then(t=>({default:t.LocationPanel}))),sm=(0,r.lazy)(()=>K(()=>import("./CharacterPanel.CkgJkpn9.js"),__vite__mapDeps([106,1,2,3,4,5,6,7,8,9,27,11,12,17,14,15,32,30,107,108,55,35,19,24,92,109,41,20,79,31,36,82,110,49])).then(t=>({default:t.CharacterPanel}))),nm=(0,r.lazy)(()=>K(()=>import("./CastingBanner.Dk5V0MLe.js"),__vite__mapDeps([111,1,2,3,4,5,6,7,8,9])).then(t=>({default:t.CastingBanner}))),nr="The script is still being written. Add shots after it finishes.",Do=t=>t instanceof Element&&t.closest('[role="dialog"]')!==null,rm=(0,r.lazy)(()=>K(()=>import("./CastSetupModal.DHx49JhQ.js"),__vite__mapDeps([112,27,2,3,4,5,11,12,7,17,14,15,32,30,6,8,113,1,9,109,41,20,79,55,19,31,36,82,24,110,105,45,48,49,35])).then(t=>({default:t.CastSetupModal}))),am=(0,r.lazy)(()=>K(()=>import("./AutoStoryboardBanner.CbTmov-Y.js"),__vite__mapDeps([114,1,2,3,4,5,6,7,8,9,115,116,59,71,117])).then(t=>({default:t.AutoStoryboardBanner}))),om=(0,r.lazy)(()=>K(()=>import("./FilmPlanReviewDialog.Dn1C9kk2.js"),__vite__mapDeps([118,1,2,3,4,5,6,7,8,9,11,12,14,15,41,20,43,44,24,45,19,31,25,61])).then(t=>({default:t.FilmPlanReviewDialog}))),im=(0,r.lazy)(()=>K(()=>import("./CharacterReviewBanner.S305396r.js"),__vite__mapDeps([119,1,2,3,4,5,6,7,8,9,115,35,116])).then(t=>({default:t.CharacterReviewBanner}))),lm=(0,r.lazy)(()=>K(()=>import("./ScriptLengthBanner.Chf6bBEc.js"),__vite__mapDeps([120,6,5,4,7,2,3,116,1,8,9])).then(t=>({default:t.ScriptLengthBanner}))),cm=(0,r.lazy)(()=>K(()=>import("./DirectorAvatar.r9U0J-HX.js"),__vite__mapDeps([121,1,2,3,4,5,6,7,8,9,122,25,76,87])).then(t=>({default:t.DirectorAvatar}))),dm=(0,r.lazy)(()=>K(()=>import("./DirectorPanel.CZzcRZsP.js"),__vite__mapDeps([123,1,2,3,4,5,6,7,8,9,122,25,76,85,34,35,36,37,38,53,24,51,45,87])).then(t=>({default:t.DirectorPanel}))),um=(0,r.lazy)(()=>K(()=>import("./PreviewPanel.DJ9O7shr.js"),__vite__mapDeps([124,1,2,3,4,5,6,7,8,9,34,35,36,37,38,25,96,18,66,62])).then(t=>({default:t.PreviewPanel}))),vi="Already generating. You can keep working.";function $o(t){const n=(0,r.useRef)(!1);return(0,r.useCallback)(async()=>{if(n.current){S.info(vi);return}n.current=!0;try{await t()}finally{n.current=!1}},[t])}function Lo(t,n){if(t.length===0)return null;let i=0;for(const f of t){const c=i;if(i+=or(f.duration_seconds),n<i){const d=n-c,g=f.active_version?.data?.video_trim_start_ms||0;return{id:f.id,frame:f,videoUrl:f.active_version?.data?.generated_video_url,t
2imeInFrame:d,videoTimeWithTrim:d+g/1e3}}}const o=t[t.length-1],m=o?.active_version?.data?.video_trim_start_ms||0;return o?{id:o.id,frame:o,videoUrl:o.active_version?.data?.generated_video_url,timeInFrame:0,videoTimeWithTrim:m/1e3}:null}var mm=t=>(0,e.jsx)(Wu,{...t,subscribeToTime:oi,getInitialTime:lr}),hm=t=>{const n=J(o=>o.currentTime),i=J(o=>vr(o.grade));return(0,e.jsx)(um,{...t,currentTime:n,gradeFilter:i})},fm=t=>{const n=J(i=>vr(i.grade));return(0,e.jsx)(Qu,{...t,gradeFilter:n})},pm=t=>{const n=J(i=>i.grade);return(0,e.jsx)(ru,{...t,grade:n})},Se=()=>(0,e.jsxs)("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50",role:"status","aria-live":"polite",children:[(0,e.jsx)(xe,{className:"h-8 w-8 animate-spin text-primary","aria-hidden":"true"}),(0,e.jsx)("span",{className:"sr-only",children:"Loading…"})]}),Go=()=>(0,e.jsx)("div",{className:"w-full sm:w-96 border-l border-border bg-card h-full animate-pulse shadow-xl"}),gm=()=>(0,e.jsx)("div",{className:"w-full sm:w-80 border-l border-border bg-card h-full animate-pulse shadow-xl"}),xm={frameNode:fd,sceneGroup:$u,annotationText:hi,annotationSticky:fi,annotationEmoji:pi,annotationArrow:gi},bm={transition:Mu},rr={mobile:{cardWidth:140,cardHeight:130,hGap:30,vGap:30,gridCols:2},tablet:{cardWidth:170,cardHeight:155,hGap:45,vGap:40,gridCols:3},desktop:{cardWidth:200,cardHeight:180,hGap:60,vGap:40,gridCols:5}},vm=1/30,zo=1e3,ym=2e3,wm=["image","video"],Sm=120*1e3,_m=()=>{if(typeof window>"u")return"line";try{return localStorage.getItem("storyboard-layout")||"line"}catch{return"line"}},jm=t=>{try{localStorage.setItem("storyboard-layout",t)}catch{}},ar=900*1e3,Vo=20*1e3,Cm=t=>{if(t)return!0;if(typeof window>"u")return!1;try{return localStorage.getItem("storyboard-preview-panel")==="true"}catch{return!1}},Nm=t=>{try{localStorage.setItem("storyboard-preview-panel",String(t))}catch{}},km=({projectUuid:t,readOnly:n=!1})=>{const{user:i}=us(),o=jd(),m=_d(),f=o?rr.mobile:m?rr.tablet:rr.desktop,{cardWidth:c,hGap:d,vGap:g,gridCols:v}=f,x=ls(s=>s.isOpen&&s.projectUuid===t),b=ls(s=>s.close),_=()=>ls.getState().open(t);(0,r.useEffect)(()=>()=>{Yc.getState().reset(),ls.getState().reset()},[t]);const{isTourActive:A,tourStep:C,setStep:D}=mi(Xn(s=>({isTourActive:s.isActive,tourStep:s.step,setStep:s.setStep}))),{currentProject:h,frames:p,selectedFrameId:T,selectedFrameIds:E,isLoading:O,error:X,audioTracks:$,fetchProject:k,fetchPublicProject:V,selectFrame:R,toggleFrameSelection:M,selectFrameRange:q,clearFrameSelection:G,deleteSelectedFrames:oe,createFrame:ie,deleteFrame:_e,duplicateFrame:Te,reorderFrames:at,fetchAudioTracks:je,setLaneMuted:fs,updateAudioTrack:De,deleteAudioTrack:zt,updateProject:ot,updateFrame:Ye,setFrameTransition:ps,fetchFrameHistory:He,fetchFrames:W,scenes:le,fetchScenes:gs,createScene:Vt,updateScene:be,deleteScene:vt,assignFramesToScene:Wt,reorderScenes:yt,toggleSceneCollapse:xs,autoDetectScenes:$e}=ue(Xn(s=>({currentProject:s.currentProject,frames:s.frames,selectedFrameId:s.selectedFrameId,selectedFrameIds:s.selectedFrameIds,isLoading:s.isLoading,error:s.error,audioTracks:s.audioTracks,scenes:s.scenes,fetchProject:s.fetchProject,fetchPublicProject:s.fetchPublicProject,selectFrame:s.selectFrame,toggleFrameSelection:s.toggleFrameSelection,selectFrameRange:s.selectFrameRange,clearFrameSelection:s.clearFrameSelection,deleteSelectedFrames:s.deleteSelectedFrames,createFrame:s.createFrame,deleteFrame:s.deleteFrame,duplicateFrame:s.duplicateFrame,reorderFrames:s.reorderFrames,fetchAudioTracks:s.fetchAudioTracks,setLaneMuted:s.setLaneMuted,updateAudioTrack:s.updateAudioTrack,deleteAudioTrack:s.deleteAudioTrack,updateProject:s.updateProject,updateFrame:s.updateFrame,setFrameTransition:s.setFrameTransition,fetchFrameHistory:s.fetchFrameHistory,fetchFrames:s.fetchFrames,fetchScenes:s.fetchScenes,createScene:s.createScene,updateScene:s.updateScene,deleteScene:s.deleteScene,assignFramesToScene:s.assignFramesToScene,reorderScenes:s.reorderScenes,toggleSceneCollapse:s.toggleSceneCollapse,autoDetectScenes:s.autoDetectScenes}))),nn=i?.is_impersonating,wt=h?.aspect_ratio??null,ge=jc(f,kc(wt)),{confirm:ve}=Rc(),{confirmBulkVideoRun:Bt,bulkVideoCostDialog:bs}=Tu(),{showUpgrade:Ot}=hs(),{confirmReviewShots:Ee,reviewShotsDialog:vs}=Zc(),{prepare:St,isPreparing:_t}=bd(t),{blockIfExhausted:se}=Cu(),{blockIfFree:re}=sn(),{duplicate:qe,duplicatingUuid:ys}=kd(),yi=[{title:"Timeline",description:"This is your timeline. Playback and clip timing are controlled here.",selector:'[data-tour="timeline-root"]'},{title:"Canvas",description:"This canvas is your visual storyboard workspace.",selector:'[data-tour="canvas-root"]'},{title:"Add",description:"Use Add to put a new shot, voice or music in your film.",selector:'[data-tour="header-add-frame"]',noClickOnNext:!0},{title:"Shot card",description:"This is a shot card. Each card is one shot in your film.",selector:'[data-tour="frame-node"]'},{title:"Shot editor panel",description:"This right panel lets you edit prompts, media, and shot details.",selector:'[data-tour="frame-sidebar"]'},{title:"Draw storyboard",description:"Click Draw storyboard to open the storyboard picture editor for this shot. Try it — close the editor when done and continue.",selector:'[data-tour="frame-generate-image"]',autoAdvanceOnClick:!1,noClickOnNext:!0},{title:"Make video clip",description:"Click Make video clip to open the video clip editor for this shot. Explore it — close when done and continue.",selector:'[data-tour="frame-generate-video"]',autoAdvanceOnClick:!1,noClickOnNext:!0},{title:"Close panel",description:"Click this X to close the shot editor when you are done.",selector:'[data-tour="frame-sidebar-close"]'},{title:"AI Director",description:"If you get stuck, open AI Director at the top of the screen for help.",selector:'[data-tour="header-ai-director"]'}],[rn,an,wi]=sd([]),[Si,Yt,_i]=rd([]),[yr,Ht]=(0,r.useState)(!1),[wr,Sr]=(0,r.useState)(!1),_r=J(s=>s.showCharacterPanel),ji=J(s=>s.showLocationPanel),Ci=Zn(s=>s.open),[jr,Cr]=(0,r.useState)(!1);(0,r.useEffect)(()=>()=>Zn.getState().closeLook(),[]);const ws=J(s=>s.setShowLocationPanel),jt=J(s=>s.setShowCharacterPanel),[Nr,Ni]=(0,r.useState)({id:null,nonce:0}),on=ir(s=>s.fetchCharacters);(0,r.useEffect)(()=>{t&&on(t).catch(()=>{})},[t,on]);const kr=h?.locations,Ar=Lc(s=>s.seed);(0,r.useEffect)(()=>{t&&Ar(t,kr)},[t,kr,Ar]);const Ct=ir(s=>s.managerOpenCharacterId),Tr=(0,r.useRef)(Ct);(0,r.useEffect)(()=>
2{Ct!=null&&Ct!==Tr.current&&(Tr.current=Ct,Ni(s=>({id:Ct,nonce:s.nonce+1})),jt(!0))},[Ct]);const[ln,Ss]=(0,r.useState)(!1),Ce=(0,r.useRef)(null);(0,r.useEffect)(()=>()=>{Ce.current&&(clearInterval(Ce.current),Ce.current=null)},[]);const[cn,qt]=(0,r.useState)(null),[_s,ki]=(0,r.useState)({}),Er=J(s=>s.setGrade),Ai=J(s=>!!vr(s.grade)),dn=J(s=>s.showGradePanel),Rr=J(s=>s.setShowGradePanel),un=J(s=>s.showOutline),Pr=J(s=>s.setShowOutline),Kt=(0,r.useRef)(null);(0,r.useEffect)(()=>{Er(h?.grade??null)},[h?.uuid,h?.grade]);const Ti=(0,r.useCallback)(s=>{Er(s),Kt.current&&clearTimeout(Kt.current),Kt.current=setTimeout(()=>{t&&ot(t,{grade:s}).catch(()=>{S.error("Could not save the color grade. Try again.")})},600)},[t,ot]);(0,r.useEffect)(()=>()=>{Kt.current&&clearTimeout(Kt.current)},[]);const[it,Le]=(0,r.useState)(null),[lt,Re]=(0,r.useState)(void 0),[ct,Ei]=(0,r.useState)(!1),[Pe,Jt]=(0,r.useState)(null),mn=ls(s=>s.projectUuid===t&&Hc(s.turn)),hn=(0,r.useRef)(null),[Ri,Pi]=(0,r.useState)(!1),[Fr,fn]=(0,r.useState)(!1);(0,r.useEffect)(()=>n?void 0:Mc.register(()=>fn(!0)),[n]);const fe=it?p.find(s=>s.id===it)??null:null,Xt=en(fe),Mr=(0,r.useMemo)(()=>{if(!fe)return[];const s=[],a=!!fe.active_version?.data?.generated_image_url,l=!!fe.active_version?.data?.generated_video_url;return a&&s.push(1),l&&s.push(2),s},[fe]),[Ir,Dr]=(0,r.useState)(null),[$r,Lr]=(0,r.useState)(!1),[Gr,dt]=(0,r.useState)(!1),[ut,Nt]=(0,r.useState)("browse"),[zr,Vr]=(0,r.useState)(!1),[Wr,Br]=(0,r.useState)(!1),[Or,Yr]=(0,r.useState)(!1),[Hr,Qt]=(0,r.useState)(!1),[kt,pn]=(0,r.useState)(null),[Fe,ye]=(0,r.useState)(null),Ne=(0,r.useRef)(0),qr=(0,r.useRef)(0),gn=J(s=>s.setCurrentTime),Q=J(s=>s.isPlaying),js=J(s=>s.setIsPlaying),Fi=J(s=>s.zoom),Mi=J(s=>s.setZoom),Cs=J(s=>s.masterVolume),Kr=J(s=>s.setMasterVolume),{sceneAudioEnabled:xn,toggleSceneAudio:bn}=yd(),vn=J(s=>s.isLooping),Ii=J(s=>s.setIsLooping),[Di,$i]=(0,r.useState)(!1),[Ke,At]=(0,r.useState)(null),[Jr,Xr]=(0,r.useState)(new Set),[Qr,Li]=(0,r.useState)(new Set),[Ns,ks]=(0,r.useState)(!1),pe=J(s=>s.layout),yn=J(s=>s.setLayout),[Zt,Ut]=(0,r.useState)(()=>!!n),As=!n&&!!h?.cast_review_pending,[me,Zr]=(0,r.useState)(null),[wn,Ts]=(0,r.useState)(null),[es,Ur]=(0,r.useState)(null),ea=(0,r.useRef)(!1),[ta,Gi]=(0,r.useState)(!1),zi=h?.name?h.name:n?"Shared film":"Storyboard",Vi=n?"A shared film storyboard made in M Studio.":"Make, edit and export your film's storyboard.",Tt=(0,r.useRef)(null),Sn=(0,r.useRef)(null),ke=(0,r.useRef)(new Map),Es=(0,r.useRef)(!1),Ge=(0,r.useRef)(new Map),Je=(0,r.useRef)(new Set),Et=(0,r.useRef)(!1),Wi=(0,r.useRef)(s=>{Et.current=s}),Xe=(0,r.useRef)(new Map),_n=(0,r.useRef)(""),sa=(0,r.useRef)(0),ze=(0,r.useRef)(null),jn=(0,r.useRef)(null),{setCenter:mt,getZoom:ht,getViewport:ts,screenToFlowPosition:na,fitView:Rt,getNodes:ra}=ri(),[aa,ss]=(0,r.useState)(!1),Cn=(0,r.useRef)(!1),Bi=(0,r.useCallback)(s=>{R(s),Rt({nodes:[{id:`frame-${s}`}],duration:400,maxZoom:1.2,padding:.3})},[R,Rt]),Oi=(0,r.useCallback)(s=>{const a=p.filter(l=>l.scene_id===s).map(l=>({id:`frame-${l.id}`}));a.length>0&&Rt({nodes:a,duration:400,padding:.2,maxZoom:1.2})},[p,Rt]),Rs=(0,r.useCallback)(s=>{const a=new Audio(s);return a.preload="auto",a.crossOrigin="anonymous",a.setAttribute("playsinline","true"),a},[]),Ps=(0,r.useCallback)((s,a)=>{s.src!==a&&(s.src=a,s.load())},[]),oa=(0,r.useCallback)(()=>{Es.current||$.forEach(s=>{const a=s.asset?.s3_url||s.s3_url||s.generated_audio_url;if(!a)return;let l=ke.current.get(s.id);l||(l=Rs(a),ke.current.set(s.id,l)),Ps(l,a);const u=l.muted,w=l.volume;l.muted=!0,l.volume=0;try{const y=l.play();y&&y.then(()=>{Es.current=!0,l.pause(),Number.isFinite(l.currentTime)&&(l.currentTime=0)}).catch(()=>{})}catch{}finally{l.muted=u,l.volume=w}})},[$,Rs,Ps]),Me=(0,r.useCallback)(s=>{Ne.current=s,qr.current=s,gn(s)},[]);(0,r.useEffect)(()=>{$i(!0)},[]),(0,r.useEffect)(()=>{if(typeof window>"u")return;const s=new URLSearchParams(window.location.search).get("preview");Gi(s==="true"||s==="1")},[]),(0,r.useEffect)(()=>{if(n){Ut(!0);return}yn(_m()),Ut(Cm(!1))},[n,yn,Ut]),(0,r.useEffect)(()=>()=>J.getState().resetStoryboardUi(),[]);const{users:Nn,isConnected:Tm}=du({projectUuid:t,enabled:!n}),{handleMouseMove:ia}=uu({projectUuid:t,enabled:!n}),la=(0,r.useMemo)(()=>{const s=new Map;for(const a of Nn){const l=a.activity?.selected_frame_id;l&&(s.has(l)||s.set(l,[]),s.get(l).push(a))}return s},[Nn]),Yi=(0,r.useCallback)(s=>
2{ia(s),Ts(me?{x:s.clientX,y:s.clientY}:null)},[ia,me]),Hi=(0,r.useCallback)(()=>{Ts(null)},[]),{annotations:ca,selectedAnnotationId:ft,fetchAnnotations:da,createAnnotation:ua,updateAnnotation:ma,deleteAnnotation:ha,selectAnnotation:Qe}=fu(Xn(s=>({annotations:s.annotations,selectedAnnotationId:s.selectedAnnotationId,fetchAnnotations:s.fetchAnnotations,createAnnotation:s.createAnnotation,updateAnnotation:s.updateAnnotation,deleteAnnotation:s.deleteAnnotation,selectAnnotation:s.selectAnnotation}))),ns=(0,r.useCallback)((s=!1)=>{if(n)return;const a=Date.now(),l=Q?zo:ym,u=a-sa.current;if(!s&&u<l){ze.current===null&&(ze.current=window.setTimeout(()=>{ze.current=null,jn.current?.(!0)},l-u));return}ze.current!==null&&(window.clearTimeout(ze.current),ze.current=null),sa.current=a,Zs.updateActivity(t,{selected_frame_id:T??null,selected_audio_track_id:Fe?.id??null,selected_annotation_id:ft??null,timeline_position:Ne.current,is_playing:Q,status:"active"}).catch(()=>{})},[n,Q,t,T,Fe?.id,ft]);jn.current=ns,(0,r.useEffect)(()=>{ns()},[ns]),(0,r.useEffect)(()=>{if(n||!Q)return;const s=window.setInterval(()=>jn.current?.(),zo);return()=>window.clearInterval(s)},[n,Q]),(0,r.useEffect)(()=>()=>{ze.current!==null&&(window.clearTimeout(ze.current),ze.current=null)},[]);const Ze=(0,r.useRef)([]),qi=50,Fs=(0,r.useCallback)(s=>{Ze.current.push(s),Ze.current.length>qi&&Ze.current.shift()},[]),fa=(0,r.useCallback)(async()=>{const s=Ze.current.pop();if(!s){S.info("Nothing to undo.");return}try{s.type==="audio_update"?(await De(s.trackId,s.previousData),S.success("Audio track change undone.")):s.type==="frame_duration"&&(await Ye(s.frameId,{duration_seconds:s.previousDuration}),S.success("Shot length change undone."))}catch(a){console.error("Undo failed:",a),S.error("Could not undo. Try again."),Ze.current.push(s)}},[De,Ye]),Ki=s=>{yn(s),jm(s),Xe.current.clear()},kn=!n&&h?.uuid===t&&Cd(h);(0,r.useEffect)(()=>{kn&&Ks.visit(`/dashboard/projects/${t}/setup`,{replace:!0})},[kn,t]),(0,r.useEffect)(()=>{n?V(t):(k(t),W(t),gs(t),da(t))},[t,k,V,W,gs,da,n]),(0,r.useEffect)(()=>{!n||!ta||ea.current||O||p.length===0||(Qt(!0),ea.current=!0)},[n,ta,O,p.length]);const Ue=p.some(s=>s.generating_image||s.generating_video),Ms=(0,r.useRef)(Ue);Ms.current=Ue;const ee=h?.status==="scripting";(0,r.useEffect)(()=>{if(Pe!==null){if(ee){Jt(null);return}Ue||p.length!==0&&(p.some(s=>!s.has_image)||Jt(null))}},[Pe,ee,Ue,p]);const pa=(0,r.useRef)(!1);(0,r.useEffect)(()=>{pa.current&&!ct&&Jt(null),pa.current=ct},[ct]);const[Ji,ga]=(0,r.useState)(null),xa=(0,r.useRef)({scripting:!1});(0,r.useEffect)(()=>{const s=h?.uuid,a=xa.current;a.uuid!==s?ga(null):a.scripting&&!ee&&ga(Date.now()),xa.current={uuid:s,scripting:ee}},[h?.uuid,ee]);const An=!!h?.auto_storyboard&&h.status==="draft"&&!h.cast_review_pending,pt=An&&h?.cast_pass_running===!0,Tn=An&&h?.cast_pass_running!==!1,[Is,Xi]=(0,r.useState)(null),ba=(0,r.useRef)(!1);(0,r.useEffect)(()=>{ba.current&&!pt&&Xi(Date.now()),ba.current=pt},[pt]);const va=An&&h?.cast_pass_running===!1&&Is!==null&&!h?.error_message&&!h?.needs_script,rs=h?.director_pass?.turn_id??null,ya=h?.plan_approval==="checking";(0,r.useEffect)(()=>{if(n||rs===null&&!ya)return;const s=setInterval(()=>k(t),5e3);return()=>clearInterval(s)},[n,rs,ya,t,k]);const Qi=(0,r.useCallback)(async()=>{if(rs!==null){try{await Tc.stopTurn(t,rs)}catch{}k(t)}},[rs,t,k]);(0,r.useEffect)(()=>{if(n||!va||Is===null)return;const s=setInterval(()=>{if(Date.now()-Is>Sm){clearInterval(s);return}k(t)},15e3);return()=>clearInterval(s)},[n,va,Is,t,k]),(0,r.useEffect)(()=>{if(n)return;const s=mn||Pe!==null&&Date.now()-Pe<ar;if(!ee&&!Ue&&!Tn&&!ct&&!s)return;let a=0;const l=setInterval(()=>{a+=1;const u=mn||Pe!==null&&Date.now()-Pe<ar,w=Oc(a,{project:ee||Tn||u,frames:ee||Ms.current||ct||u});w.project&&k(t),w.frames&&W(t),w.audio&&je(t)},3e3);return()=>clearInterval(l)},[n,ee,Tn,Ue,ct,Pe,mn,t,k,W,je]);const En=(0,r.useRef)(!1);(0,r.useEffect)(()=>{if(n)return;const s=ee||Ue;if(En.current&&!s){const a=setTimeout(()=>{je(t),W(t)},2500);return En.current=s,()=>clearTimeout(a)}En.current=s},[n,ee,Ue,t,je,W]),(0,r.useEffect)(()=>{const s=async a=>{window.history.pushState(null,"",window.location.href),await ve({title:"Leave this film?",description:"Changes you have not saved may be lost.",confirmText:"Leave film",cancelText:"Stay",variant:"destructive"})&&(window.removeEventListener("popstate",s),window.history.back())};return window.history.pushState(null,"",window.location.href),window.addEventListener("popstate",s),(
2)=>{window.removeEventListener("popstate",s)}},[]);const Ie=(0,r.useCallback)(s=>pe==="line"?{x:s*(c+d)+50,y:50}:{x:s%v*(c+d)+50,y:Math.floor(s/v)*(ge+g)+50},[pe,c,ge,d,g,v]),Ae=J(s=>Q?Lo(p,s.currentTime)?.id??null:null),wa=(0,r.useRef)(null),Sa=(0,r.useRef)(null),_a=(0,r.useRef)(null),Rn=(0,r.useRef)(null),ja=(0,r.useRef)(null),Ca=(0,r.useRef)(null),Na=(0,r.useRef)(null),ka=(0,r.useRef)(null),Aa=(0,r.useRef)(null),Ta=(0,r.useRef)(null),Ea=(0,r.useRef)(null),Pn=(0,r.useRef)(null),Ra=(0,r.useRef)(null),Pa=(0,r.useRef)(null),Pt=(0,r.useRef)(new Map);(0,r.useEffect)(()=>{const s=Pt.current;return()=>{s.forEach(a=>clearInterval(a.timer)),s.clear()}},[]);const Fa=(0,r.useRef)(new Set),et=(0,r.useCallback)((s,a)=>{Fa.current.add(s);const l=Pt.current.get(s);if(l)return a&&l.listeners.push(a),l.done;const u=a?[a]:[];let w,y=0;const N=new Promise(I=>{const ne=async()=>{try{const Y=(await is.get(s)).data?.data;if(y>=2&&S.success("Reconnected."),y=0,!Y)return;u.forEach(Z=>Z(Y)),Eu(Y)?(clearInterval(w),Pt.current.delete(s),await W(t),I(Y)):Ms.current||W(t)}catch(Y){const Z=Y?.response?.status;if(Z===403||Z===404){clearInterval(w),Pt.current.delete(s),I(null);return}y++,y===2&&S.error("Connection lost. The run keeps going on our side, and this page reconnects on its own.")}};w=setInterval(ne,5e3),ne()});return w&&Pt.current.set(s,{timer:w,done:N,listeners:u}),N},[t,W]),tt=(0,r.useCallback)((s,a,l,u=[])=>{const w=[...ue.getState().frames].sort((N,I)=>N.sequence_order-I.sequence_order).map(N=>N.id),y=Ru(s,{noun:a,notes:u,shotNumber:N=>{const I=w.indexOf(N);return I>=0?I+1:void 0}});S[y.tone](y.message,l),y.budgetStop&&Ot({feature:a==="video clip"?"generate-video":"generate-image",message:"This is more than your plan allows this month. See plans to make the rest."})},[Ot]);(0,r.useEffect)(()=>{for(const s of h?.live_runs??[])if(!(Fa.current.has(s.job_id)||s.kind==="pictures"&&Ce.current)){if(s.kind==="clips"){qt(s.job_id),et(s.job_id).then(a=>{qt(l=>l===s.job_id?null:l),a&&tt(a,"video clip","Video clips")});continue}Ss(!0),et(s.job_id).then(a=>{Ss(!1),a&&(a.batch_stats?tt(a,"storyboard","Storyboards"):a.status==="completed"?S.success("The storyboards run finished."):a.status==="failed"&&S.error(a.error_message||a.user_error?.message||"The storyboards run stopped before it finished."))})}},[h?.live_runs,et,tt]);const st=(0,r.useCallback)((s,a)=>ki(l=>{const u={...l};return a?u[s]=a:delete u[s],u}),[]),Fn=(0,r.useCallback)(async s=>{try{const{data:a}=await is.cancel(s),l=a?.message;typeof l=="string"&&l&&S.info(l)}catch{S.error("Could not stop this run. Try again.")}},[]),Ma=(0,r.useCallback)(s=>{const a=_s[s]?.jobId;a&&Fn(a)},[_s,Fn]),Ds=(0,r.useCallback)(async s=>{try{return{jobId:(await s()).data.job_id,started:!0}}catch(a){const l=a,u=l?.response;return u?.status===409&&u.data?.job_id?{jobId:u.data.job_id,started:!1}:(l?.config?.suppressErrorToast||S.error(u?.data?.message||"Could not start. Try again."),null)}},[]),Ia=(0,r.useCallback)(async s=>{if(!t||p.length===0)return;const a=le.find(Y=>Y.id===s),l=p.filter(Y=>Y.scene_id===s);if(l.length===0){S.info("This scene has no shots.");return}const u=a?.name||"Scene";if(!await Ee({kind:"pictures",frameIds:l.map(Y=>Y.id)}))return;const w=await Ds(()=>gt.generateAllFrames(t,{generate_end_frames:!1,frame_ids:l.map(Y=>Y.id)}));if(!w)return;const{jobId:y,started:N}=w;if(!N){S.info("Storyboards are already being made for this film. Try this scene again when they are done.");return}S.info(`Drawing the storyboard for ${u}. You can keep working, or close this page.`);const I=l.length;st(s,{type:"images",current:0,total:I,jobId:y});const ne=await et(y,Y=>st(s,{type:"images",current:Y.batch_stats?.completed??0,total:Y.batch_stats?.total_frames??I,jobId:y}));st(s,null),ne&&tt(ne,"storyboard","Scene storyboard")},[t,p,le,Ee,Ds,et,st,tt]),$s=(0,r.useCallback)(async({title:s,scope:a,frameIds:l,sceneId:u})=>{if(!t)return;const w=Co(l);if(w.ready.length===0){S.info(w.skipped??"No shots to make.");return}const y=await Bt({title:s,scope:a,shotIds:w.ready.map(H=>H.id)});if(!y||y.length===0||!await Ee({kind:"clips",frameIds:y}))return;const{ready:N,skipped:I}=Co(y),ne=[w.skipped,I].filter(H=>H!==null);if(N.length===0){S.info(ne.join(" ")||"No shots to make.");return}const Y=await Ds(()=>gt.generateAllVideos(t,N.map(H=>H.id)));if(!Y)return;const{jobId:Z,started:ce}
2=Y,U=N.length,we=ce||!Pt.current.has(Z);if(qt(Z),!ce){S.info("Video clips are already being generated for this film. You can stop them from the bar at the top, then try again.");const H=await et(Z);qt(de=>de===Z?null:de),H&&we&&tt(H,"video clip",s);return}S.info(`Making ${F(U,"video clip")}. You can keep working, or close this page.`),u!==void 0&&st(u,{type:"videos",current:0,total:U,jobId:Z});const Ve=await et(Z,H=>{u!==void 0&&st(u,{type:"videos",current:H.batch_stats?.completed??0,total:H.batch_stats?.total_frames??U,jobId:Z})});qt(H=>H===Z?null:H),u!==void 0&&st(u,null),Ve&&we&&tt(Ve,"video clip",s,ne)},[t,Bt,Ee,Ds,et,st,tt]),Da=(0,r.useCallback)(async s=>{if(!t||p.length===0)return;const a=le.find(N=>N.id===s);await W(t);const l=ue.getState().frames.filter(N=>N.scene_id===s);if(l.length===0){S.info("This scene has no shots.");return}const u=jo(l),w=u.length>0?u:l.filter(N=>!N.generating_video);if(w.length===0){S.info("Every shot in this scene is already making a video clip.");return}const y=a?.name||"Scene";await $s({title:`Make video clips for ${y}?`,scope:`in ${y}`,frameIds:w.map(N=>N.id),sceneId:s})},[t,p,le,W,$s]),$a=(0,r.useRef)(null),La=(0,r.useRef)(null),Ga=(0,r.useRef)(null),za=(0,r.useRef)(null),Va=(0,r.useRef)(null),Wa=(0,r.useRef)(null),Ba=(0,r.useRef)(null),Oa=(0,r.useRef)(null);(0,r.useEffect)(()=>{const s=Ae?Lo(p,lr())?.videoTimeWithTrim:void 0;if(p.length===0&&h?.status==="scripting"){const j=h.total_frames??0;an([...Array.from({length:j},(L,B)=>({id:`skeleton-${B}`,type:"frameNode",position:Ie(B),data:{isSkeleton:!0,isGeneratingScript:!0,frame:null,isSelected:!1,cardWidth:c,aspectRatio:wt,onSelect:()=>{}},draggable:!1,selectable:!1}))]),Yt([]);return}const a=h?.status==="scripting"?h.total_frames??p.length:p.length,l=Math.max(0,a-p.length),u=Array.from({length:l},(j,L)=>{const B=p.length+L;return{id:`skeleton-${B}`,type:"frameNode",position:Ie(B),data:{isSkeleton:!0,isGeneratingScript:!0,frame:null,isSelected:!1,cardWidth:c,aspectRatio:wt,onSelect:()=>{}},draggable:!1,selectable:!1}}),w=new Map,y=[];for(const j of p)if(j.scene_id){const L=w.get(j.scene_id)||[];L.push(j),w.set(j.scene_id,L)}else y.push(j);const N=(j,L,B)=>({scene:j,isCollapsed:B,frameCount:L.length,durationSeconds:L.reduce((z,ae)=>z+ae.duration_seconds,0),readOnly:n,progress:_s[j.id]??null,onStopRun:z=>Wa.current?.(z),onToggleCollapse:z=>$a.current?.(z),onRename:(z,ae)=>La.current?.(z,ae),onChangeColor:(z,ae)=>Ga.current?.(z,ae),onDelete:z=>za.current?.(z),onSelectAllFrames:z=>Va.current?.(z),onGenerateSceneImages:z=>Ba.current?.(z),onGenerateSceneVideos:z=>Oa.current?.(z)}),I=Ec(p),ne=j=>{const L=j.last_failed_generation_job,B=L?.error_message&&!Jr.has(L.id)&&!j.generating_image&&!j.generating_video,z=!B&&!j.generating_image&&!j.generating_video&&j.last_run_note&&!Qr.has(`${j.last_run_note.run_id}:${j.id}`)?j.last_run_note:null;return{frame:j,isSelected:E.includes(j.id),isPlaying:Ae===j.id,videoCurrentTime:Ae===j.id?s:void 0,isGeneratingImage:j.generating_image,isGeneratingVideo:j.generating_video,isDeleting:Ke===j.id,lastFailedError:B?L.error_message:z?.message??null,lastFailedUserError:B?L.user_error:z?.user_error??null,lastFailedType:B?L.type:z?.type??null,lastFailedProvider:B?L.provider_slug:null,presentUsers:la.get(j.id)??[],sharedPromptOpening:I,onSelect:ae=>wa.current?.(j.id,ae),onInsertAfter:()=>Sa.current?.(j.sequence_order),onInsertPunctuation:ae=>_a.current?.(j.sequence_order,ae),onAddTransition:()=>Rn.current?.(j.id),onEditImage:()=>ja.current?.(j),onGenerateImage:n?void 0:()=>Ca.current?.(j),onGenerateVideo:()=>Na.current?.(j),onRetryGeneration:L?()=>Ea.current?.(L.id,j):void 0,onDismissError:B?()=>Xr(ae=>new Set([...ae,L.id])):z?()=>Li(ae=>new Set([...ae,`${z.run_id}:${j.id}`])):void 0,onViewHistory:()=>ka.current?.(j),onDuplicate:()=>Aa.current?.(j),onDelete:()=>Ta.current?.(j),onVideoBuffering:Ae===j.id?Wi.current:void 0,previewPanelActive:Zt,cardWidth:c,aspectRatio:wt}},Y=[],Z=[],ce=16,U=48,we=ge+85,Ve=70;let H=50,de=50;const mo=le.map(j=>`${j.id}:${j.is_collapsed}`).join(",");_n.current&&_n.current!==mo&&Xe.current.clear(),_n.current=mo;const kl=[...le].sort((j,L)=>j.scene_order-L.scene_order);for(const j of kl){const L=w.get(j.id)||[];if(L.length===0)continue;const B=j.is_collapsed,z=`scene-${j.id}`;if(B)Y.push({id:z,type:"sceneGroup",position:Xe.current.get(z)??(pe==="line"?{x:H,y:50}:{x:50,y:de}),data:N(j,L,!0),draggable:!1,style:{width:c+ce*2,height:Ve,zIndex:0}}),pe==="line"?H+=c+ce*2+d:de+=Ve+g;else{const ae=pe==="line"?L.length:Math.min(v,L.length),as=pe==="line"?1:Math.ceil(L.length/v),fo=ae*(c+d)-d+ce*2,po=as*(we+g)-g+U+ce;Y.push({id:z,type:"sceneGroup",position:Xe.current.get(z)??(pe==="line"?{x:H,y:50}:{x:50,y:de}),data:N(j,L,!1),draggable:!1,style:{width:fo,height:po,zIndex:0}}
2),L.forEach((go,Jn)=>{const Fl=pe==="line"?Jn*(c+d)+ce:Jn%v*(c+d)+ce,Ml=pe==="line"?U:Math.floor(Jn/v)*(we+g)+U,xo=`frame-${go.id}`;Z.push({id:xo,type:"frameNode",position:Xe.current.get(xo)??{x:Fl,y:Ml},parentId:z,extent:"parent",data:ne(go),draggable:!1,zIndex:1})}),pe==="line"?H+=fo+d:de+=po+g}}let Al=0;const Tl=y.map(j=>{const L=`frame-${j.id}`,B=Al++;return{id:L,type:"frameNode",position:Xe.current.get(L)??(pe==="line"?{x:H+B*(c+d),y:50}:{x:B%v*(c+d)+50,y:de+Math.floor(B/v)*(we+g)}),data:ne(j),draggable:!1}}),ho=[...Y,...Z,...Tl],El=p.length>1?p.slice(0,-1).map((j,L)=>{const B=p[L+1],z=j.scene_id&&le.find(as=>as.id===j.scene_id)?.is_collapsed,ae=B.scene_id&&le.find(as=>as.id===B.scene_id)?.is_collapsed;return z&&ae&&j.scene_id===B.scene_id?null:{id:`edge-${j.id}-${B.id}`,source:z?`scene-${j.scene_id}`:`frame-${j.id}`,target:ae?`scene-${B.scene_id}`:`frame-${B.id}`,type:"transition",animated:!1,style:{stroke:"hsl(var(--border))"},data:{transitionType:j.transition_type||"cut",transitionDuration:j.transition_duration||.5,onTransitionClick:()=>Rn.current?.(j.id)}}}).filter(Boolean):[],Rl=ca.map(j=>{const L={sticky:"annotationSticky",emoji:"annotationEmoji",arrow:"annotationArrow",text:"annotationText"}[j.type]||"annotationText";return{id:`annotation-${j.id}`,type:L,position:{x:j.position_x,y:j.position_y},data:{annotation:j,isSelected:ft===j.id,onUpdate:(B,z)=>Pn.current?.(B,z),onDelete:B=>Ra.current?.(B),onSelect:B=>Pa.current?.(B),readOnly:n},draggable:!n,selectable:!0,style:{zIndex:j.z_index||1e3}}}),Pl=[...ho,...u,...Rl];ho.length===0&&p.length>0||(an(Pl),Yt(El))},[p,le,h,E,Ae,Ke,Jr,Qr,la,ca,ft,n,_s,an,Yt,Ie]);const Mn=(0,r.useMemo)(()=>rn.filter(s=>s.id.startsWith("frame-")||s.id.startsWith("skeleton-")).length,[rn]),Ya=(0,r.useRef)(0);(0,r.useEffect)(()=>{const s=Ya.current;Ya.current=Mn,s===0&&Mn>0&&(Cn.current=!1,ss(!0))},[Mn]);const Ha=(0,r.useRef)(ee);(0,r.useEffect)(()=>{const s=Ha.current;Ha.current=ee,s&&!ee&&!Cn.current&&ss(!0)},[ee]),(0,r.useEffect)(()=>{if(!aa)return;let s=0,a=0;const l=()=>{const u=ra().filter(y=>y.id.startsWith("frame-")||y.id.startsWith("skeleton-")).slice(0,pe==="line"?5:15),w=u.filter(y=>y.width&&y.height);if(a+=1,w.length===0){a<60?s=requestAnimationFrame(l):ss(!1);return}if(w.length<u.length&&a<30){s=requestAnimationFrame(l);return}Rt({nodes:w.map(y=>({id:y.id})),padding:.05,maxZoom:o?.6:m?.8:1,duration:0}),ss(!1)};return s=requestAnimationFrame(l),()=>cancelAnimationFrame(s)},[aa,ra,Rt,pe,o,m]);const Zi=(0,r.useCallback)(s=>{s&&(Cn.current=!0,ss(!1))},[]),Ui=(0,r.useCallback)(s=>Yt(a=>td(s,a)),[Yt]),el=(0,r.useCallback)(async(s,a)=>{if(!a.id.startsWith("annotation-"))return;const l=parseInt(a.id.replace("annotation-",""),10);Pn.current?.(l,{position_x:a.position.x,position_y:a.position.y})},[]),tl=(0,r.useCallback)(async(s,a)=>{const l=a==="fade"?{script:"Fade to black",image_prompt:"a pure black frame",motion_prompt:"fade to black"}:{script:"Title card",image_prompt:'Pure black background with elegant, minimal white title text: "YOUR TITLE"',motion_prompt:"fade in and fade out"},u=await ie(t,s+1);await Ye(u.id,{duration_seconds:3,data:l}),R(u.id),a==="title"?S.info('Title card added. Replace "YOUR TITLE" in the Picture prompt, then draw it.'):S.info("Fade shot added. Draw its storyboard and make its video clip when ready.")},[t,ie,Ye,R]),qa=(0,r.useCallback)(async s=>{const a=s+1,l=ie(t,a),u=ue.getState().frames,w=u.findIndex(N=>N.sequence_order===a&&N.id<0);if(w!==-1){R(u[w].id);const N=Ie(w);mt(N.x+c/2,N.y+ge/2,{duration:300,zoom:ht()})}const y=await l;y&&w!==-1&&y.id!==u[w].id&&R(y.id)},[t,ie,R,Ie,mt,ht,c,ge]),sl=(0,r.useCallback)(async(s,a)=>{const l=p.findIndex(y=>y.id===s);if(l===-1||l===a)return;const u=[...p],[w]=u.splice(l,1);u.splice(a,0,w),await at(t,u.map((y,N)=>({id:y.id,sequence_order:N+1})))},[p,t,at]),Ft=(0,r.useCallback)((s,a)=>{const l=s.active_version?.data,u=!!l?.generated_image_url,w=!!l?.image_accepted,y=!!l?.generated_video_url;let N=1;a?N=a:y||u&&w?N=2:N=1,Le(s.id),Re(N)},[]),nl=(0,r.useCallback)((s,a)=>{h&&Zr({type:s,content:a})},[h]);(0,r.useEffect)(()=>{me||Ts(null)},[me]);const Ka=(0,r.useCallback)(async(s,a,l,u)=>{try{const w=u??{sticky:"New note",emoji:"👍",text:"Add text here",arrow:""}[l]??"",y={sticky:{width:180,height:120},text:{width:200,height:100},arrow:{width:120,height:40}}[l]||{};Ur({x:s,y:a,type:l,content:w}),await ua(t,{type:l,content:w,position_x:s,position_y:a,width:y.width,height:y.height})}catch(w){console.error("Error creating annotation:",w),S.error("Could not add the note. Try again.")}finally{Ur(null)}},[t,ua]),Ja=(0,r.useCallback)(async(s,a)=>{await ma(s,a)},[ma]),Ls=(0,r.useCallback)(async s=>{await ha(s)},[ha]),Xa=(0,r.useCallback)(s=>
2{Qe(s),R(null),ye(null)},[Qe,R]);(0,r.useEffect)(()=>{if(n||!ft)return;const s=a=>{if(a.key==="Delete"||a.key==="Backspace"){if(a.target instanceof HTMLInputElement||a.target instanceof HTMLTextAreaElement||Do(a.target))return;a.preventDefault(),Ls(ft)}};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[ft,n,Ls]);const rl=(0,r.useCallback)(async s=>{if(me){const a=na({x:s.clientX,y:s.clientY});Zr(null),await Ka(a.x,a.y,me.type,me.content);return}Qe(null),G(),ye(null)},[me,na,Ka,Qe,G]);(0,r.useEffect)(()=>{wa.current=(s,a)=>{if(!s){G();return}if(a?.shiftKey)q(s);else if(a?.metaKey||a?.ctrlKey)M(s);else{const l=p.find(u=>u.id===s);l&&Ft(l)}if(s){const l=p.findIndex(u=>u.id===s);if(l>=0){let u=0;for(let w=0;w<l;w++)u+=or(p[w].duration_seconds);Ne.current=u,gn(u)}}},Sa.current=qa,_a.current=tl,Rn.current=s=>{pn(s)},ja.current=Ft,Ca.current=s=>{Ft(s,1)},Pn.current=Ja,Ra.current=Ls,Pa.current=Xa,$a.current=s=>{Xe.current.clear(),xs(s)},La.current=(s,a)=>{be(s,{name:a})},Ga.current=(s,a)=>{be(s,{color:a})},za.current=async s=>{const a=ue.getState().scenes.find(u=>u.id===s),l=p.filter(u=>u.scene_id===s).length;await ve({title:a?.name?`Delete the scene "${a.name}"?`:"Delete this scene?",description:l>0?`Its ${l===1?"shot stays":`${l} shots stay`} on the board, no longer grouped. The scene's name, color and description are lost. You can't undo this.`:"The scene's name, color and description are lost. You can't undo this.",cancelText:"Cancel",confirmText:"Delete scene",variant:"destructive"})&&vt(s)},Va.current=s=>{const a=p.filter(l=>l.scene_id===s).map(l=>l.id);G();for(const l of a)M(l)},Ba.current=Ia,Oa.current=Da,Wa.current=Ma},[R,M,q,G,qa,Ft,Ja,Ls,Xa,Ia,Da,Ma,p,ve]);const In=(0,r.useCallback)(async s=>{await k(t),it&&He(it)},[t,k,it,He]),Gs=(0,r.useCallback)(s=>{Le(s.id),Re(2)},[]),nt=(0,r.useCallback)(async s=>{const a=()=>ue.getState().frames.find(u=>u.id===s);let l=a();if(l||(await W(t).catch(()=>{}),l=a()),!l){S.info("That shot is no longer in this film. Pick a shot on the board.");return}Le(s),Re(Un(l)?2:1)},[W,t]),Qa=(0,r.useRef)(new Map),Dn=(0,r.useRef)(!0);(0,r.useEffect)(()=>(Dn.current=!0,()=>{Dn.current=!1}),[]);const Za=(0,r.useCallback)((s,a)=>
2{if(!Dn.current)return;const l=ue.getState().frames.find(u=>u.id===s);l&&(Qa.current.set(s,Td(l,a)),W(t))},[W,t]),$n=(0,r.useCallback)(s=>Kc(()=>nt(s)),[nt]);(0,r.useEffect)(()=>{const s=Qa.current,a={workflowFrameId:it,workflowStep:Xt?2:lt,selectedFrameId:T};for(const[l,u]of s){if(Ed(l,a)){s.delete(l);continue}const w=p.find(ne=>ne.id===l),y=Pd(u,w);if(y==="running"){u.seenRunning=!0;continue}if(y==="waiting")continue;s.delete(l);const N=`Shot ${qc(p,l).shotNumber??""}`.trim(),I=en(w)?"animation":"video clip";y==="ready"?S.successWithAction(`${N}'s ${I} is ready.`,{label:"Open",onClick:()=>$n(l)},{duration:Vo}):y==="failed"&&S.errorWithAction(Md(w)??`Something went wrong with this ${I}.`,{label:"Open shot",onClick:()=>$n(l)},{title:`${N}'s ${I} did not finish`,duration:Vo})}},[p,it,lt,Xt,T,$n]);const Ln=(0,r.useCallback)(s=>{const a=ue.getState().frames.find(l=>l.id===s);a&&(Re(l=>l===2&&Un(a)?2:1),Le(s))},[]),Ua=(0,r.useCallback)(async s=>{await k(t),Re(s)},[k,t]),Gn=async()=>{if(!Ns){if(ee){S.error(nr);return}try{ks(!0);const s=ie(t,(p.length>0?Math.max(...p.map(y=>y.sequence_order)):0)+1),a=ue.getState().frames,l=a.length-1,u=a[l];if(u){R(u.id);const y=Ie(l);mt(y.x+c/2,y.y+ge/2,{duration:300,zoom:ht()})}const w=await s;w&&u&&w.id!==u.id&&R(w.id)}catch(s){console.error("Error adding frame:",s),os(s)||S.error(s.response?.data?.message||"Could not add the shot. Try again.")}finally{ks(!1)}}},zs=p.find(s=>s.id===T);(0,r.useEffect)(()=>{A&&C<2&&D(2)},[A,C,h,D]),(0,r.useEffect)(()=>{A&&C===5&&T&&D(6)},[A,C,T,D]),(0,r.useEffect)(()=>{if(!Q||!Ae||Ae===Sn.current)return;Sn.current=Ae,Et.current=!1;const s=p.findIndex(u=>u.id===Ae);if(s===-1)return;const a=`frame-${Ae}`,l=Xe.current.get(a)??Ie(s);mt(l.x+c/2,l.y+ge/2,{duration:300,zoom:ht()})},[Ae,Q,p,Ie,mt,ht,c,ge]),(0,r.useEffect)(()=>{Q||(Sn.current=null,Et.current=!1)},[Q]);const he=(0,r.useMemo)(()=>Pc(p),[p]),al=(0,r.useMemo)(()=>p.filter(s=>s.has_image||s.has_video||!!s.active_version?.data?.generated_image_url).length,[p]);(0,r.useEffect)(()=>{if(!Q||he<=0)return;let s=performance.now();const a=l=>{const u=(l-s)/1e3;if(s=l,Et.current){Tt.current=requestAnimationFrame(a);return}let w=Math.min(Ne.current+u,he);w>=he&&(vn?w=0:(js(!1),w=he)),Ne.current=w,(w===0||w>=he||w-qr.current>=vm)&&Me(w),Tt.current=requestAnimationFrame(a)};return Tt.current=requestAnimationFrame(a),()=>{Tt.current&&(cancelAnimationFrame(Tt.current),Tt.current=null)}},[Q,he,vn,Me]),(0,r.useEffect)(()=>{Ne.current>he&&(Me(he),js(!1))},[he,Me]);const ol=(0,r.useCallback)(s=>{if(s==="scene"){bn();return}const a=$.filter(l=>l.track_type===s);a.length!==0&&fs(t,s,!a.every(l=>l.is_muted)).catch(()=>{})},[$,t,fs,bn]),eo=(0,r.useRef)(new Map);(0,r.useEffect)(()=>{eo.current=xd(p)},[p]);const zn=(0,r.useCallback)(s=>{const a=s*1e3,l=$.some(u=>u.is_solo);$.forEach(u=>{const w=u.asset?.s3_url||u.s3_url||u.generated_audio_url;if(u.is_muted||!w||l&&!u.is_solo||u.track_type==="scene"&&!xn||gd(u,eo.current)){const we=ke.current.get(u.id);we&&!we.paused&&(we.pause(),Ge.current.delete(u.id));return}const y=u.trim_start_ms||0,N=u.trim_end_ms||0,I=u.duration_ms,ne=u.original_duration_ms||u.asset?.duration_ms||u.duration_ms+(u.trim_start_ms||0)+(u.trim_end_ms||0),Y=u.start_time_ms||0,Z=Y+I,ce=a>=Y&&a<Z;let U=ke.current.get(u.id);if(ce&&Q){U?Ps(U,w):(U=Rs(w),ke.current.set(u.id,U));const we=typeof u.volume=="string"?parseFloat(u.volume):u.volume??1;U.volume=Math.max(0,Math.min(1,we*Cs));const Ve=(a-Y)/1e3+y/1e3;if(Ve>=(ne-N)/1e3){U.paused||(U.pause(),Ge.current.delete(u.id));return}if(Math.abs(U.currentTime-Ve)>.1&&!Je.current.has(u.id))try{Je.current.add(u.id);const H=U,de=()=>{Je.current.delete(u.id),H.removeEventListener("seeked",de)};H.addEventListener("seeked",de),H.currentTime=Ve,setTimeout(()=>{Je.current.delete(u.id),H.removeEventListener("seeked",de)},500)}catch{Je.current.delete(u.id)}if(U.paused&&Es.current&&!Ge.current.has(u.id)){const H=U.play();H&&(Ge.current.set(u.id,H),H.then(()=>{Ge.current.delete(u.id)}).catch(de=>{Ge.current.delete(u.id),de.name!=="AbortError"&&de.name!=="NotAllowedError"&&console.warn("Audio play failed:",de)}))}}else U&&!U.paused&&(U.pause(),Ge.current.delete(u.id),Je.current.delete(u.id))}),Q||ke.current.forEach((u,w)=>{u.paused||u.pause(),Ge.current.delete(w),Je.current.delete(w)})},[Q,$,Cs,xn,Rs,Ps]);(0,r.useEffect)(()=>(zn(lr()),oi(zn)),[zn]),(0,r.useEffect)(()=>()=>{ke.current.forEach(s=>{s.pause(),s.src=""}),ke.current.clear(),Ge.current.clear(),Je.current.clear()},[]),(0,r.useEffect)(()=>{const s=new Set($.map(a=>a.id));ke.current.forEach((a,l)=>{s.has(l)||(a.pause(),a.src="",ke.current.delete(l))})},[$]),(0,r.useEffect)(()=>{const s=a=>
2{if((a.ctrlKey||a.metaKey)&&a.key==="z"&&!a.shiftKey){const l=a.target;if(l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.isContentEditable||Do(l))return;a.preventDefault(),fa()}};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[fa]);const Vn=(0,r.useCallback)(()=>{if(he<=0){S.info("Nothing to play yet.");return}Es.current||oa(),js(s=>{!s&&Ne.current>=he&&Me(0);const a=!s;return a&&!Zt&&Ut(!0),a}),Q||R(null)},[he,Me,oa,Zt,Q,R]),Wn=(0,r.useCallback)(()=>{Me(Ne.current),js(!1),Et.current=!1},[Me]),to=(0,r.useCallback)(s=>{const a=isNaN(s)?0:s;ke.current.forEach(l=>{l.paused||l.pause()}),Me(a),ns()},[Me,ns]),il=(0,r.useCallback)(s=>{R(s.id),ye(null),Qe(null);const a=p.findIndex(l=>l.id===s.id);if(a>=0){let l=0;for(let u=0;u<a;u++)l+=or(p[u].duration_seconds);Ne.current=l,gn(l)}},[R,Qe,p]),ll=(0,r.useCallback)(s=>{ye(s),R(null),Qe(null)},[R,Qe]),cl=(0,r.useCallback)(s=>{const a=$.find(u=>u.id===s.id),l=a?{type:"audio_update",trackId:s.id,previousData:{start_time_ms:a.start_time_ms,trim_start_ms:a.trim_start_ms,trim_end_ms:a.trim_end_ms}}:null;l&&Fs(l),De(s.id,s).catch(()=>{Ze.current=Ze.current.filter(u=>u!==l),ye(u=>u?.id===s.id&&a?a:u),ue.setState(u=>({audioTracks:[...u.audioTracks]})),je(t)}),Fe?.id===s.id&&ye(s)},[$,Fs,De,Fe,je,t]),dl=s=>{const a={...s};delete a.start_time_ms,De(s.id,a),ye(s),k(t)},ul=s=>{zt(s),Fe?.id===s&&ye(null)},ml=s=>{je(t),ye(s)},hl=(0,r.useCallback)(s=>{zt(s),Fe?.id===s&&ye(null)},[zt,Fe?.id]),Bn=(0,r.useCallback)(s=>{s==="custom"?(Nt("custom"),dt(!0)):s==="music"?(Nt("music"),dt(!0)):Dr(s)},[]),fl=(0,r.useCallback)(()=>{Nt("frame"),dt(!0)},[]),so=(0,r.useCallback)(()=>{Lr(!0)},[]),no=async()=>{await k(t)},pl=async(s,a)=>{if(h)try{const l=s.duration_ms||6e4;await Cc.create(t,{track_type:a,asset_id:s.id,name:s.original_name||s.filename,start_time_ms:0,duration_ms:l,original_duration_ms:l,volume:a==="music"?.7:1}),await k(t),S.success(a==="music"?"Music track added.":"Audio track added.")}catch(l){console.error(`Error adding ${a} audio track:`,l),os(l)||S.error(l.response?.data?.message||`Could not add the ${a} track. Try again.`)}},gl=(0,r.useCallback)(async s=>{if(!h||Ns)return;if(ee){S.error(nr);return}const a=s.category==="video";if(!a&&s.category!=="image"){S.error("Only a picture or a video can be added as a shot.");return}try{ks(!0);const l=ie(t,(p.length>0?Math.max(...p.map(I=>I.sequence_order)):0)+1),u=ue.getState().frames,w=u.length-1,y=u[w];if(y){R(y.id);const I=Ie(w);mt(I.x+c/2,I.y+ge/2,{duration:300,zoom:ht()})}const N=await l;if(N){if(a){const I=(await gt.setDirectVideo(N.id,{asset_id:s.id})).data?.asset_duration_ms;if(I&&I>0){const ne=Math.min(60,Math.max(.1,Number((I/1e3).toFixed(2))));await gt.update(N.id,{duration_seconds:ne,change_summary:"Duration matched to uploaded clip"})}}else await gt.setDirectImage(N.id,{asset_id:s.id});await k(t),R(N.id),S.success(a?"Video clip added as a shot.":"Shot added from My files.")}}catch(l){console.error("Error adding frame from assets:",l),os(l)||S.error(l.response?.data?.message||"Could not add the shot from My files. Try again.")}finally{ks(!1),dt(!1),Nt("browse")}},[h,Ns,ee,p,ie,t,R,Ie,mt,ht,c,ge,k]),xl=async s=>{if(h)try{await ot(h.uuid,{ripple_edit_enabled:s})}catch(a){console.error(a),S.error("Could not update the ripple edit. Try again.")}},bl=(0,r.useCallback)(async(s,a)=>{const l=p.find(u=>u.id===s);l&&Fs({type:"frame_duration",frameId:s,previousDuration:l.duration_seconds});try{await Ye(s,{duration_seconds:a})}catch(u){console.error(u),S.error("Could not change the shot length. Try again."),Ze.current.pop()}},[p,Fs,Ye]),ro=async()=>{try{await k(t),S.success("Film saved.")}catch(s){console.error(s),S.error("Could not save the film. Try again.")}},ao=(0,r.useCallback)(()=>{Ut(s=>{const a=!s;return Nm(a),a})},[]),On=(0,r.useCallback)(()=>{re("export")||Ht(!0)},[re]),vl=(0,r.useCallback)(()=>dt(!0),[]),oo=(0,r.useCallback)(()=>Vr(!0),[]),Yn=h?.uuid,Vs=h?.name,yl=(0,r.useCallback)(async()=>{if(!Yn||Vs===void 0)return;const s=S.loading("Copying shots, cast, audio and files.",`Duplicating "${Vs}"`);let a=null;try{a=await qe({uuid:Yn,name:Vs})}finally{S.dismiss(s)}if(!a)return;const l=Nd(a);S.successWithAction(`"${a.name}" has the same shots, cast, audio and files. You are still in the original.`,{label:"Open copy",onClick:()=>{Ks.visit(l)}},{title:"Film duplicated"})},[Yn,Vs,qe]),wl=(0,r.useCallback)(()=>Yr(!0),[]),Sl=(0,r.useCallback)(()=>ws(s=>!s),[ws]),_l=(0,r.useCallback)(()=>jt(s=>!s),[]),jl=(0,r.useCallback)(async()=>
2{if(!t||p.length===0)return;if(ln){S.info(vi);return}const s=p.filter(Qc),a=s.map(u=>u.id);if(s.every(u=>u.generating_image)){S.info(p.some(u=>u.generating_image)?"Every shot has a storyboard or one on its way.":p.some(u=>!u.active_version?.data?.generated_image_url)?"Write what each shot shows first. A shot with no words gets no storyboard.":"Every shot already has a storyboard.");return}if(re("generate-image")||await se("storyboard image generation")||!await Ee({kind:"pictures",frameIds:a}))return;Ce.current&&(clearInterval(Ce.current),Ce.current=null);const l=()=>{Ce.current&&(clearInterval(Ce.current),Ce.current=null),Ss(!1)};Ss(!0);try{const u=await gt.generateAllKeyframes(t,{storyboard_panels:!0});if(!u.data?.success){l();return}S.success("Generating storyboards. You can keep working.");const w=u.data.job_id;Ce.current=setInterval(async()=>{try{const y=(await is.get(w)).data?.data;if(!y)return;if(y.status==="completed"){const N=y.metadata?.frames_with_images??null,I=y.metadata?.frames_missing_images??0;if(l(),await W(t),I>0){const ne=[...ue.getState().frames].sort((Z,ce)=>Z.sequence_order-ce.sequence_order).map(Z=>Z.id),Y=bi(y,Z=>{const ce=ne.indexOf(Z);return ce>=0?ce+1:void 0});S.warning(`Generated ${N==null?"some storyboards":F(N,"storyboard")}. ${F(I,"shot")} still ${I===1?"needs":"need"} a storyboard.${Y===""?"":` ${Y}`}`,"Partly done")}else S.success("All storyboards are ready.");return}if(y.status==="failed"||y.status==="cancelled"){l(),await W(t),S.error(y.error_message||y.user_error?.message||"Could not generate the storyboards.");return}Ms.current||await W(t)}catch{}},5e3)}catch(u){l(),os(u)||S.error(u.response?.status===402?"This is more than your plan allows this month.":u.response?.data?.message||"Could not start the storyboards. Try again.")}},[t,p,ln,W,Ee,se,re]),Cl=(0,r.useCallback)(async()=>{if(hn.current){hn.current();return}try{(await bt.startAutoStoryboard(t)).data?.data?.phase==="script"?k(t):W(t)}catch(s){const a=s,l=a.response?.status;l!==409&&l!==402&&S.error(a.response?.data?.message??"Could not start the storyboard. Try again.")}},[t,k,W]),io=$o(jl),lo=$o((0,r.useCallback)(async()=>{if(!t||p.length===0)return;await W(t);const s=ue.getState().frames,a=jo(s);if(a.length===0){S.info(s.some(Un)?"Every shot with a storyboard already has a video clip or is generating one.":"Generate the storyboard first. A video clip starts from it.");return}re("generate-video")||await $s({title:"Make all video clips?",scope:"with a storyboard but no video clip yet",frameIds:a.map(l=>l.id)})},[t,p,re,W,$s])),co=()=>{if(p.length===0){S.info("Add a shot first.");return}Qt(!0)},Hn=(0,r.useCallback)(async()=>{if(!(n||Ke)){if(E.length>1){if(!await ve({title:`Delete ${F(E.length,"shot")}?`,description:"Their storyboard pictures, video clips and script leave the film. You can't undo this.",confirmText:`Delete ${F(E.length,"shot")}`,cancelText:"Cancel",variant:"destructive"}))return;At(E[0]),S.info(`Deleting ${F(E.length,"shot")}…`);try{await oe(t),S.success(`${F(E.length,"shot")} deleted.`)}catch(s){console.error("Error deleting frames:",s),S.error("Could not delete the shots. Try again.")}finally{At(null)}return}if(T&&p.find(s=>s.id===T)){At(T),S.info("Deleting shot…");try{await _e(T),R(null),S.success("Shot deleted.")}catch(s){console.error("Error deleting frame:",s),S.error("Could not delete the shot. Try again.")}finally{At(null)}}}},[T,E,p,_e,oe,R,n,Ke,ve,t]),qn=(0,r.useCallback)(async s=>{if(!(n||Ke)&&await ve({title:`Delete shot ${s.sequence_order}?`,description:"Its storyboard picture, video clip and script leave the film. You can't undo this.",confirmText:"Delete shot",cancelText:"Cancel",variant:"destructive"})){At(s.id),S.info("Deleting shot…");try{await _e(s.id),T===s.id&&R(null),S.success("Shot deleted.")}catch(a){console.error("Error deleting frame:",a),S.error("Could not delete the shot. Try again.")}finally{At(null)}}},[_e,R,T,n,Ke]),Kn=(0,r.useCallback)(async s=>{if(!n){S.info("Duplicating shot…");try{const a=await Te(s.id);S.success(`Shot duplicated as shot ${a.sequence_order}.`)}catch(a){console.error("Error duplicating frame:",a),S.error("Could not duplicate the shot. Try again.")}}},[Te,n]),uo=(0,r.useCallback)(async(s,a)=>
2{if(!n)try{S.info("Trying again…"),(await is.retry(s,()=>ve({title:"Try again?",description:"The last try got no answer in time, and you were not charged for it. Try again now?",confirmText:"Try again",cancelText:"Cancel"})))?.data.data?.job_id&&(S.success("Started again."),Xr(l=>{const u=new Set(l);return u.delete(s),u}),h&&await W(h.uuid))}catch(l){const u=l.response?.data?.message||"Could not try again. Try again later.";S.error(u)}},[n,h,W,ve]);(0,r.useEffect)(()=>{Na.current=s=>Gs(s),Ea.current=(s,a)=>uo(s,a),ka.current=s=>R(s.id),Aa.current=s=>Kn(s),Ta.current=s=>qn(s)},[Gs,uo,R,Kn,qn]);const Nl=(0,r.useCallback)(async s=>{if(!n){if(!s.active_version?.data?.generated_video_url){S.error("This shot has no video clip to reverse.");return}S.info("Reversing the video clip…");try{const a=await gt.reverseVideo(s.id),l=a.data?.job_id||a.data?.data?.job?.id||a.data?.data?.job_id;if(!l)throw new Error("No job returned");const u=150;let w=0,y=!1;const N=setInterval(async()=>{if(w++,w>u){clearInterval(N),y||S.error("Reversing the video clip took too long. Try again.");return}try{const I=(await is.get(l)).data?.data;I?.status==="completed"?(y=!0,clearInterval(N),await k(t),S.success("Video clip reversed.")):I?.status==="failed"&&(y=!0,clearInterval(N),S.error(I?.user_error?.message||"Could not reverse the video clip. Try again."))}catch(I){console.error("Error polling job:",I)}},2e3)}catch(a){console.error("Error reversing video:",a),os(a)||S.error(a.response?.data?.message||"Could not reverse the video clip. Try again.")}}},[n,k,t]);if(ou([{key:" ",handler:()=>Q?Wn():Vn()},{key:"s",ctrl:!0,handler:ro},{key:"Delete",handler:Hn},{key:"Backspace",handler:Hn}],!n),O&&!h||kn)return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Bs,{title:"Loading film",noIndex:!0}),(0,e.jsxs)("main",{id:"main-content",className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/80 backdrop-blur-md",children:[(0,e.jsxs)("div",{className:"text-center max-w-md",children:[(0,e.jsxs)("div",{className:"relative mb-8",children:[(0,e.jsx)("div",{className:"w-24 h-24 mx-auto rounded-2xl bg-gradient-to-br from-primary to-primary/80 flex items-center justify-center shadow-2xl shadow-primary/30",children:(0,e.jsx)(Lt,{className:"h-12 w-12 text-primary-foreground animate-pulse","aria-hidden":"true"})}),(0,e.jsx)("div",{className:"absolute inset-0 animate-spin",style:{animationDuration:"3s"},children:(0,e.jsx)("div",{className:"absolute top-0 left-1/2 -translate-x-1/2 -translate-y-2 w-3 h-3 rounded-full bg-primary"})}),(0,e.jsx)("div",{className:"absolute inset-0 animate-spin",style:{animationDuration:"4s",animationDirection:"reverse"},children:(0,e.jsx)("div",{className:"absolute bottom-0 left-1/2 -translate-x-1/2 translate-y-2 w-2 h-2 rounded-full bg-primary/70"})})]}),(0,e.jsx)("h2",{className:"text-2xl font-bold mb-3 text-white",children:"Loading film"}),(0,e.jsx)("p",{className:"text-sm text-muted-foreground mb-8",children:"Opening your film…"}),(0,e.jsx)("div",{className:"w-full h-1.5 bg-secondary/50 rounded-full overflow-hidden",children:(0,e.jsx)("div",{className:"h-full bg-gradient-to-r from-primary to-primary/80 rounded-full animate-progress",style:{animation:"progress 2.5s ease-in-out infinite"}})})]}),(0,e.jsx)("style",{children:`
3                      @keyframes progress {
4                          0% { width: 0%; margin-left: 0; }
5                          50% { width: 60%; margin-left: 20%; }
6                          100% { width: 0%; margin-left: 100%; }
7                      }
8                  `})]})]});if(!O&&!h&&X&&X!=="PROJECT_NOT_FOUND"){const s=X.includes("took too long"),a=X.includes("too often");return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Bs,{title:"Could not load film",noIndex:!0}),(0,e.jsx)("main",{id:"main-content",className:"min-h-screen bg-background flex items-center justify-center px-4",children:(0,e.jsxs)("div",{className:"max-w-md mx-auto text-center",children:[(0,e.jsx)("div",{className:"w-24 h-24 mx-auto rounded-full bg-destructive/10 flex items-center justify-center mb-8",children:(0,e.jsx)(Xs,{className:"w-12 h-12 text-destructive/70","aria-hidden":"true"})}),(0,e.jsx)("h1",{className:"text-2xl sm:text-3xl font-bold text-foreground mb-4",children:s?"Your film took too long to load":"Could not load your film"}),(0,e.jsx)("p",{className:"text-muted-foreground mb-8 max-w-sm mx-auto",children:s?"It did n
8ot open in time. This is usually brief, so try again.":a?"Your film is being refreshed too often right now. Wait a moment, then try again.":"Something stopped your film from opening. Try again, or go back to your films."}),(0,e.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3 justify-center",children:[(0,e.jsxs)("button",{onClick:()=>{ue.getState().fetchProject(t)},className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-xl font-semibold hover:bg-primary/90 transition-colors",children:[(0,e.jsx)(cc,{className:"w-5 h-5","aria-hidden":"true"}),"Try again"]}),(0,e.jsxs)("a",{href:"/dashboard",className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-secondary text-foreground rounded-xl font-semibold hover:bg-secondary/80 transition-colors",children:[(0,e.jsx)(wo,{className:"w-5 h-5","aria-hidden":"true"}),"Back to my films"]})]})]})})]})}return!O&&!h&&(X==="PROJECT_NOT_FOUND"||n)?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Bs,{title:"Film not found",noIndex:!0}),(0,e.jsx)("main",{id:"main-content",className:"min-h-screen bg-background flex items-center justify-center px-4",children:(0,e.jsxs)("div",{className:"max-w-2xl mx-auto text-center",children:[(0,e.jsxs)("div",{className:"relative mb-8",children:[(0,e.jsx)("div",{className:"text-[10rem] font-bold text-primary/10 select-none leading-none",children:"404"}),(0,e.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,e.jsx)("div",{className:"w-28 h-28 rounded-full bg-primary/10 flex items-center justify-center animate-pulse",children:(0,e.jsx)(We,{className:"w-14 h-14 text-primary/50","aria-hidden":"true"})})})]}),(0,e.jsx)("h1",{className:"text-3xl sm:text-4xl font-bold text-foreground mb-4",children:"Film not found"}),(0,e.jsx)("p",{className:"text-lg text-muted-foreground mb-8 max-w-md mx-auto",children:n?"This film does not exist or is no longer shared.":"This film does not exist or was deleted."}),(0,e.jsxs)("div",{className:"flex flex-col sm:flex-row gap-4 justify-center mb-12",children:[(0,e.jsxs)("a",{href:"/dashboard",className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-xl font-semibold hover:bg-primary/90 transition-colors",children:[(0,e.jsx)(wo,{className:"w-5 h-5","aria-hidden":"true"}),"Back to my films"]}),(0,e.jsxs)("button",{onClick:()=>window.history.back(),className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-secondary text-foreground rounded-xl font-semibold hover:bg-secondary/80 transition-colors",children:[(0,e.jsx)(Oo,{className:"w-5 h-5","aria-hidden":"true"}),"Go back"]})]}),(0,e.jsxs)("div",{className:"border-t border-border pt-8",children:[(0,e.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:"You may be looking for:"}),(0,e.jsxs)("div",{className:"flex flex-wrap justify-center gap-4",children:[(0,e.jsx)("a",{href:"/demo",className:"text-primary hover:underline text-sm",children:"Example films"}),(0,e.jsx)("span",{className:"text-border",children:"•"}),(0,e.jsx)("a",{href:"/pricing",className:"text-primary hover:underline text-sm",children:"Pricing"}),(0,e.jsx)("span",{className:"text-border",children:"•"}),(0,e.jsx)(Il,{href:"/login",className:"text-primary hover:underline text-sm",children:"Log in"}),(0,e.jsx)("span",{className:"text-border",children:"•"}),(0,e.jsx)("a",{href:"/dashboard",className:"text-primary hover:underline text-sm",children:"My films"})]})]})]})})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Bs,{title:zi,description:Vi,noIndex:!0}),bs,vs,(0,e.jsxs)("main",{id:"main-content",className:te("flex flex-col bg-background overflow-hidden",nn?"h-[calc(100vh-40px)] mt-10":"h-screen"),children:[(0,e.jsx)(ii,{currentProject:h,frames:p,totalDuration:he,readOnly:n,layout:pe,onLayoutChange:Ki,onAddFrame:Gn,onAddFrameFromAssets:n?void 0:fl,isAddingFrame:Ns,addFrameDisabled:ee,addFrameDisabledReason:nr,onSaveProject:ro,onPreview:co,onExport:On,onOpenAssetLibrary:vl,onOpenShareModal:oo,onDuplicateProject:n?void 0:yl,isDuplicatingProject:!!h&&ys===h.uuid,onOpenConnectGuide:wl,onOpenImportAssets:n?void 0:()=>Br(!0),onAddAudioTrack:n?void 0:Bn,onOpenAssistant:n?void 0:_,onOpenDirector:n?void 0:_,onOpenQuickShot:n?void 0:()=>Sr(!0),onWritePrompts:n?void 0:()=>void St(),isWritingPrompts:_t,onToggleCharacters:_l,showCharacters:_r,onToggleLocations:n?void 0:Sl,onOpenFilmLook:n?void 0:Zn.getState().openLook,onOpenStory:n?void 0:()=>Cr(!0),onTogglePreviewPanel:ao,showPreviewPanel:Zt}),!n&&(0,e.jsx)(eu,{frames:p,soundTrackCount:$.length,isCreatingPictures:ln||!!h?.auto_storyboard&&Pe!==null&&Date.now()-Pe<ar&&h.plan_approval!=="ready"&&h.plan_approval!=="checking"&&h.plan_approval!=="blocked",isCreatingClips:cn!==null,onStopRun:()=>{cn&&Fn(cn)},freeRunActive:ct,pictureOfferShown:Ri,writingStory:ee,drawsItself:!!h?.auto_storyboard,planApproval:h?.plan_approval,runtimeOverSeconds:h?.plan_runtime_over_seconds,directorPass:h?.director_pass?.kind??null,onStopDirectorPass:()=>void Qi(),onReviewPlan:()=>fn(!0),onWriteScriptAgain:async()=>{const s=p.length>0;if(!(s&&!await ve({title:"Write the script again?",description:"A new plan replaces the shots on the board. They are saved in Versions first, so you can bring them back. Nothing is drawn until you check it.",confirmText:"Write it again",cancelText:"Cancel"}))){try{await ue.getState().generateScript(t,s)}catch{return}k(t)}},onCreatePictures:io,onGenerateStoryboard:Cl,onCreateClips:lo,onOpenShot:nt,onWatch:co,onExport:On,onAddSound:Bn}),(0,e.jsxs)(Vc,{children:[(0,e.jsx)(Wc,{}),(0,e.jsx)($d,{frames:p,project:h,readOnly:n}),(0,e.jsx)(zd,{frames:p,project:h,readOnly:n}),(0,e.jsx)(Bd,{frames:p,readOnly:n}),(0,e.jsx)(Od,{project:h,readOnly:n,onApplied:()=>W(t)}),!n&&h&&(0,e.jsx)(Jd,{projectUuid:h.uuid,shotCount:p.length,onWritePrompts:(s,a)=>void St(s,void 0,void 0,{askFirst:a}),isWritingPrompts:_t,onOpenShot:nt}),!n&&h&&!h.cast_review_pending&&(0,e.jsx)(r.Suspense,{fallback:null,children:(0,e.jsx)(nm,{projectUuid:h.uuid,onOpenManager:()=>jt(!0)})}),!n&&h&&!h.cast_review_pending&&(0,e.jsx)(r.Suspense,{fallback:null,children:(0,e.jsx)(im,{projectUuid:h.uuid,onOpenManager:()=>jt(!0)})}),!n&&h?.auto_storyboard&&(0,e.jsx)(r.Suspense,{fallback:null,children:(0,e.jsx)(am,{projectUuid:h.uuid,castReviewPending:h.cast_review_pending,castPassRunning:pt,frames:p,onRunStarted:()=>{Jt(Date.now()),W(t)},onScriptStarted:()=>k(t),onShare:oo,onRunningChange:Ei,runAskedAt:Pe,startRef:hn})}),!n&&(0,e.jsx)(Xd,{}),!n&&h&&(0,e.jsx)(Hd,{projectUuid:h.uuid,pending:h.key_frames_pending,watchSince:h.auto_storyboard?null:Ji,drawnFrameCount:al,frameCount:p.length,onGenerating:()=>W(t),onResolved:()=>k(t),onOfferShownChange:Pi,onReview:s=>Ee({kind:"pictures",frameIds:s})}),!n&&h&&(!!h.script_truncated_at_frame||!!h.script_source_exhausted)&&(0,e.jsx)(r.Suspense,{fallback:null,children:(0,e.jsx)(lm,{projectUuid:h.uuid,truncatedAtFrame:h.script_truncated_at_frame,targetFrames:h.total_frames,sourceExhausted:h.script_source_exhausted,deliveredSeconds:h.calculated_duration_seconds,requestedSeconds:h.duration_seconds??(h.duration_minutes?h.duration_minutes*60:null)})})]}),(0,e.jsxs)("div",{className:"flex-1 flex flex-col relative min-h-0 overflow-hidden",children:[(0,e.jsxs)("div",{className:"flex-1 flex flex-row min-h-0 overflow-hidden",children:[(0,e.jsxs)("div",{className:te("flex-1 min-h-0 relative overflow-hidden",me&&"cursor-none"),"data-tour":"canvas-root",onMouseMove:Yi,onMouseLeave:Hi,children:[(0,e.jsxs)(cd,{nodes:rn,edges:Si,onNodesChange:wi,onEdgesChange:_i,onConnect:Ui,onNodeDragStop:el,onPaneClick:rl,onMoveStart:Zi,nodeTypes:xm,edgeTypes:bm,snapToGri
8d:!0,snapGrid:[20,20],minZoom:.1,maxZoom:2,defaultViewport:{x:0,y:0,zoom:1},onlyRenderVisibleElements:!Q||p.length>80,nodesDraggable:!n&&!me,nodesConnectable:!1,elementsSelectable:!me,deleteKeyCode:As?null:"Backspace",className:"react-flow-canvas",proOptions:{hideAttribution:!0},children:[!Q&&(0,e.jsx)(ad,{variant:ld.Dots,gap:24,size:1.5,color:"hsl(var(--border))",className:"opacity-50"}),(0,e.jsx)(No,{position:"top-right",className:"!m-3 !z-50",children:(0,e.jsxs)("div",{className:"flex flex-row items-start gap-2",children:[!n&&(0,e.jsxs)("div",{className:"relative flex flex-col items-end",children:[(0,e.jsxs)(P,{variant:"outline",size:"sm",onClick:()=>Rr(s=>!s),className:`px-2.5 text-xs shadow-lg ${dn||Ai?"border-primary/40 bg-primary/10 text-primary hover:border-primary/50 hover:bg-primary/15":"bg-card"}`,title:"Color look for the whole film","aria-expanded":dn,children:[(0,e.jsx)(yc,{className:"h-3.5 w-3.5"}),"Color"]}),dn&&(0,e.jsx)("div",{className:"absolute top-full right-0 mt-2 z-50",children:(0,e.jsx)(pm,{onChange:Ti,onClose:()=>Rr(!1)})})]}),(0,e.jsxs)("div",{className:"relative flex flex-col items-end",children:[(0,e.jsxs)(P,{variant:"outline",size:"sm",onClick:()=>Pr(s=>!s),className:`px-2.5 text-xs shadow-lg ${un?"border-primary/40 bg-primary/10 text-primary hover:border-primary/50 hover:bg-primary/15":"bg-card"}`,title:"Jump to a scene or find a shot","aria-expanded":un,children:[(0,e.jsx)(tc,{className:"h-3.5 w-3.5"}),"Scenes"]}),un&&(0,e.jsx)("div",{className:"absolute top-full right-0 mt-2 z-50",children:(0,e.jsx)(au,{scenes:le,frames:p,selectedFrameId:T,onJumpToScene:Oi,onJumpToFrame:Bi,onClose:()=>Pr(!1)})})]})]})}),(0,e.jsx)(nd,{className:"!bg-card !border !border-border !rounded-lg !shadow-lg overflow-hidden",showInteractive:!1}),!o&&!Q&&(0,e.jsx)(Uc,{className:"!bg-card !border !border-border !rounded-xl !shadow-lg op
8acity-50 transition-opacity duration-200 hover:opacity-100 focus-within:opacity-100",maskColor:"hsl(0 0% 0% / 0.7)",nodeColor:"hsl(var(--primary))",nodeBorderRadius:8}),!x&&!n&&(0,e.jsx)(No,{position:"bottom-right",className:`!m-3 ${!o&&!Q?"!mr-[228px]":""}`,children:(0,e.jsx)(r.Suspense,{fallback:null,children:(0,e.jsx)(cm,{onOpen:_,projectUuid:t})})}),!n&&(0,e.jsx)("div",{className:"absolute top-4 left-4 z-10",children:(0,e.jsx)(xi,{onAddAnnotation:nl,pendingAnnotationType:me?.type})})]}),E.length>1&&!n&&(0,e.jsxs)("div",{className:"absolute bottom-6 left-1/2 -translate-x-1/2 z-50 flex items-center gap-3 bg-card border border-border rounded-xl shadow-2xl px-4 py-2.5 animate-in slide-in-from-bottom-4 fade-in duration-200",children:[(0,e.jsxs)("span",{className:"text-sm font-medium text-muted-foreground",children:[E.length," frames selected"]}),(0,e.jsx)("div",{className:"w-px h-5 bg-border"}),(0,e.jsxs)(P,{variant:"outline",size:"sm",onClick:async()=>{const s=p.findIndex(y=>E.includes(y.id)),a=[...le].sort((y,N)=>y.scene_order-N.scene_order);let l=1;if(s>0){const y=p[s-1],N=y.scene_id?a.find(I=>I.id===y.scene_id):null;l=N?N.scene_order+1:a.length>0?a[a.length-1].scene_order+1:1}const u=a.filter(y=>y.scene_order>=l).map(y=>({id:y.id,scene_order:y.scene_order+1}));u.length>0&&await yt(t,u);const w=await Vt(t,{name:`Scene ${le.length+1}`,scene_order:l});w&&(await Wt(w.id,E),G(),S.success(`${F(E.length,"shot")} grouped into "${w.name}".`))},children:[(0,e.jsx)(Qs,{className:"h-3.5 w-3.5"}),"Group into scene"]}),(0,e.jsxs)(P,{variant:"destructive",size:"sm",onClick:Hn,disabled:!!Ke,children:[Ke?(0,e.jsx)(xe,{className:"h-3.5 w-3.5 animate-spin"}):(0,e.jsx)(Ho,{className:"h-3.5 w-3.5"}),"Delete"]}),(0,e.jsx)("button",{onClick:()=>G(),className:"p-1 rounded-md hover:bg-muted text-muted-foreground hover:text-foreground transition-colors","aria-label":"Clear selection",children:(0,e.jsx)(Gt,{className:"h-4 w-4"})})]}),me&&wn&&(0,e.jsx)("div",{className:"fixed z-[10000] pointer-events-none",style:{left:wn.x,top:wn.y,transform:"translate(-50%, -50%)"},children:me.type==="emoji"?(0,e.jsx)("div",{className:"text-4xl opacity-80",children:me.content||"👍"}):(0,e.jsx)("div",{className:"w-8 h-8 bg-primary/30 border-2 border-primary rounded flex items-center justify-center",children:(0,e.jsx)("span",{className:"text-xs font-medium text-primary",children:"+"})})}),es&&(0,e.jsx)("div",{className:"absolute z-[10000] pointer-events-none",style:{left:es.x*ts().zoom+ts().x,top:es.y*ts().zoom+ts().y,transform:"translate(-50%, -50%)"},children:(0,e.jsxs)("div",{className:"relative",children:[es.type==="emoji"?(0,e.jsx)("div",{className:"text-4xl opacity-40",children:es.content||"👍"}):(0,e.jsx)("div",{className:"w-8 h-8 bg-primary/20 border-2 border-primary/40 rounded flex items-center justify-center",children:(0,e.jsx)("span",{className:"text-xs font-medium text-primary/60",children:"+"})}),(0,e.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,e.jsx)("div",{className:"w-6 h-6 border-2 border-primary border-t-transparent rounded-full animate-spin"})})]})}),!n&&Nn.map(s=>{const a=ts();return(0,e.jsx)(hu,{user:s,viewportX:a.x,viewportY:a.y,zoom:a.zoom},s.id)}),p.length===0&&pt&&(0,e.jsx)("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:(0,e.jsxs)("div",{className:"text-center",role:"status",children:[(0,e.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-secondary/50 flex items-center justify-center mx-auto mb-4",children:(0,e.jsx)(xe,{className:"h-8 w-8 text-muted-foreground/70 motion-safe:animate-spin","aria-hidden":"true"})}),(0,e.jsx)("h3",{className:"text-lg font-medium text-muted-foreground mb-2",children:"Casting your film…"}),(0,e.jsx)("p",{className:"text-sm text-muted-foreground/70 mb-4",children:"Reading your story for its characters. Your cast opens here in a few seconds."}),!n&&(0,e.jsxs)(P,{variant:"ghost",size:"sm",onClick:Gn,className:"pointer-events-auto",children:[(0,e.jsx)(cs,{className:"h-4 w-4","aria-hidden":"true"}),"Add a shot yourself"]})]})}),p.length===0&&As&&(0,e.jsx)("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:(0,e.jsxs)("div",{className:"text-center",role:"status",children:[(0,e.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-secondary/50 flex items-center justify-center mx-auto mb-4",children:(0,e.jsx)(Ko,{className:"h-8 w-8 text-muted-foreground
8/70","aria-hidden":"true"})}),(0,e.jsx)("h3",{className:"text-lg font-medium text-muted-foreground mb-2",children:"Your cast is ready"}),(0,e.jsx)("p",{className:"text-sm text-muted-foreground/70",children:"Write your film, then check its shots before anything is drawn."})]})}),p.length===0&&!As&&(0,e.jsx)(Gd,{scenes:h?.plan_progress,planning:h?.status==="scripting"&&!pt&&!h?.plan_written}),p.length===0&&!pt&&!As&&h?.status!=="scripting"&&(0,e.jsx)("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:(0,e.jsxs)("div",{className:"text-center",children:[(0,e.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-secondary/50 flex items-center justify-center mx-auto mb-4",children:(0,e.jsx)(Qs,{className:"h-8 w-8 text-muted-foreground/50","aria-hidden":"true"})}),(0,e.jsx)("h3",{className:"text-lg font-medium text-muted-foreground mb-2",children:n?"No shots in this film":"No shots yet"}),(0,e.jsx)("p",{className:"text-sm text-muted-foreground/70 mb-4",children:n?"This film has no shots to show.":"Add your first shot to start your storyboard."}),!n&&(0,e.jsxs)(P,{onClick:Gn,className:"pointer-events-auto",children:[(0,e.jsx)(cs,{className:"h-4 w-4","aria-hidden":"true"}),"Add first shot"]})]})})]}),Zt&&p.length>0&&(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)("div",{className:"w-[380px] border-l border-border bg-card animate-pulse shrink-0"}),children:(0,e.jsx)(hm,{frames:p,isPlaying:Q,totalDuration:he,masterVolume:Cs,selectedFrameId:T,onPlay:Vn,onPause:Wn,onTimeChange:to,onMasterVolumeChange:Kr,onVideoBuffering:s=>{Et.current=s},onClose:ao})})]}),(0,e.jsx)("div",{className:"flex-shrink-0","data-tour":"timeline-root",children:Di?(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)("div",{className:"h-48 bg-background-elevated animate-pulse"}),children:(0,e.jsx)(mm,{frames:p,scenes:le,audioTracks:$,duration:he,isPlaying:Q,onTimeChange:to,onPlay:Vn,onPause:Wn,onFrameSelect:il,onAudioTrackUpdate:n?void 0:cl,onAudioTrackDelete:n?void 0:hl,onAudioTrackSelect:n?void 0:ll,onAddAudioTrack:n?void 0:Bn,onGenerateMusic:n?void 0:so,onFrameReorder:n?void 0:sl,onFrameDurationChange:n?void 0:bl,selectedFrameId:T||void 0,selectedAudioTrackId:Fe?.id,zoom:Fi,onZoomChange:Mi,masterVolume:Cs,onMasterVolumeChange:Kr,sceneAudioEnabled:xn,onToggleSceneAudio:bn,onToggleLaneMute:n?void 0:ol,rippleEnabled:h?.ripple_edit_enabled,onRippleChange:n?void 0:xl,isLooping:vn,onLoopToggle:Ii,readOnly:n,onOpenImageEditor:n?void 0:Ft,onOpenVideoEditor:n?void 0:Gs,onDuplicateFrame:n?void 0:Kn,onDeleteFrame:n?void 0:qn,onReverseVideo:n?void 0:Nl,onOpenAssistant:_})}):(0,e.jsx)("div",{className:"h-48 bg-background-elevated animate-pulse"})}),_r&&h&&!n&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"fixed inset-0 bg-black/50 z-40 lg:hidden",onClick:()=>jt(!1)}),(0,e.jsx)("div",{className:"absolute top-0 right-0 bottom-0 z-40 w-full sm:w-80 animate-fade-in",children:(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)("div",{className:"w-full h-full bg-card border-l border-border animate-pulse"}),children:(0,e.jsx)(sm,{projectUuid:t,onClose:()=>jt(!1),focusCharacterId:Nr.id,focusNonce:Nr.nonce})})})]}),ji&&h&&!n&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"fixed inset-0 bg-black/50 z-40 lg:hidden",onClick:()=>ws(!1)}),(0,e.jsx)("div",{className:"absolute top-0 right-0 bottom-0 z-40 w-full sm:w-80 animate-fade-in",children:(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)("div",{className:"w-full h-full bg-card border-l border-border animate-pulse"}),children:(0,e.jsx)(tm,{projectUuid:t,onClose:()=>ws(!1)})})})]}),jr&&h&&!n&&(0,e.jsx)(r.Suspense,{fallback:null,children:(0,e.jsx)(Uu,{projectUuid:t,open:jr,onClose:()=>Cr(!1),onRewritten:()=>{Le(null),Re(void 0),R(null),k(t)}})}),Ci&&h&&!n&&(0,e.jsx)(r.Suspense,{fallback:null,children:(0,e.jsx)(em,{projectUuid:t,aspectRatio:h.aspect_ratio,onRewritten:()=>{Le(null),Re(void 0),R(null),k(t)}})}),zs&&!n&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"fixed inset-0 bg-black/50 z-40 lg:hidden",onClick:()=>R(null)}),(0,e.jsx)("div",{className:"absolute top-0 right-0 bottom-0 z-50 w-full sm:w-96 animate-fade-in",children:(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Go,{}),children:(0,e.jsx)(Bu,{frame:zs,onClose:()=>R(null),onOpenImageEditor:()=>Ft(zs,1),onOpenVideoEditor:()=>Gs(zs)})})})]}),Fe&&!n&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"fixed inset-0 bg-black/50 z-40 lg:hidden",onClick:()=>ye(null)}),(0,e.jsx)("div",{className:"absolute top-0 right-0 bottom-0 z-50 w-full sm:w-80 animate-fade-in",children:(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(gm,{}),children:(0,e.jsx)(Ou,{track:Fe,onClose:()=>ye(null),onTrackUpdated:dl,onTrackDeleted:ul,onTrackDuplicated:ml})})})]}),x&&!n&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"fixed inset-0 bg-black/50 z-40 lg:hidden",onClick:b}),(0,e.jsx)("div",{className:"absolute top-0 right-0 bottom-0 z-50 w-full sm:w-[440px] animate-fade-in",children:(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Go,{}),children:(0,e.jsx)(dm,{projectUuid:t,onClose:b,onOpenShot:nt})})})]})]})]}),yr&&(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Se,{}),children:(0,e.jsx)(Yu,{projectUuid:t,isOpen:yr,onClose:()=>Ht(!1),onOpenShot:s=>{Ht(!1),nt(s)},onCreateMissingPictures:()=>{Ht(!1),io()},onCreateMissingClips:()=>{Ht(!1),lo()}})}),fe&&lt&&Xt&&(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Se,{}),children:(0,e.jsx)(Vu,{frame:fe,projectUuid:t,onClose:()=>{Le(null),Re(void 0)},onSave:In,onSwitchFrame:Ln,onLeaveWhileRunning:Za},fe.id)}),fe&&lt===1&&!Xt&&(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Se,{}),children:(0,e.jsx)(Gu,{frame:fe,projectUuid:t,projectAspectRatio:h?.aspect_ratio,isOpen:!0,whichFrame:"start",currentStep:lt,completedSteps:Mr,onNavigateToStep:Ua,onClose:()=>{Le(null),Re(void 0)},onSave:In,onSwitchFrame:Ln},fe.id)}),fe&&lt===2&&!Xt&&(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Se,{}),children:(0,e.jsx)(zu,{frame:fe,projectUuid:t,isOpen:!0,currentStep:lt,completedSteps:Mr,onNavigateToStep:Ua,onClose:()=>{Le(null),Re(void 0)},onSave:In,onSwitchFrame:Ln,onLeaveWhileRunning:Za},fe.id)}),Ir&&h&&(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Se,{}),children:(0,e.jsx)(Hu,{projectId:h.id,projectUuid:t,frameId:T||void 0,type:Ir,isOpen:!0,onClose:()=>Dr(null),onGenerated:no,initialStartTimeMs:Math.round(Ne.current*1e3)})}),$r&&h&&(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Se,{}),children:(0,e.jsx)(qu,{projectId:h.id,isOpen:$r,onClose:()=>Lr(!1),onGenerated:no,initialStartTimeMs:Math.round(Ne.current*1e3)})}),Gr&&(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Se,{}),children:(0,e.jsx)(Ku,{projectUuid:t,isOpen:Gr,onClose:()=>{dt(!1),Nt("browse")},categoryFilter:ut==="music"||ut==="custom"?"audio":ut==="frame"?wm:"all",onAssetSelect:ut==="music"||ut==="custom"?s=>{pl(s,ut),dt(!1),Nt("browse")}:ut==="frame"?gl:void 0,onGenerateMusic:so})}),zr&&(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Se,{}),children:(0,e.jsx)(Xu,{projectUuid:t,projectName:h?.name||"Film",isOpen:zr,onClose:()=>Vr(!1)})}),Wr&&(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Se,{}),children:(0,e.jsx)(Ju,{projectUuid:t,isOpen:Wr,onClose:()=>Br(!1),onImportSuccess:()=>{t&&on(t)}})}),Or&&(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Se,{}),children:(0,e.jsx)(Zu,{open:Or,onOpenChange:Yr,projectName:h?.name})}),Hr&&(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Se,{}),children:(0,e.jsx)(fm,{frames:p,audioTracks:$,isOpen:Hr,onClose:()=>Qt(!1),onOpenShot:n?void 0:s=>{Qt(!1),nt(s)},onExport:n?void 0:()=>{Qt(!1),On()}})}),kt!==null&&(0,e.jsx)(r.Suspense,{fallback:(0,e.jsx)(Se,{}),children:(0,e.jsx)(Lu,{open:kt!==null,onOpenChange:s=>{s||pn(null)},currentType:p.find(s=>s.id===kt)?.transition_type||"cut",currentDuration:p.find(s=>s.id===kt)?.transition_duration||.5,onApply:(s,a)=>{kt&&ps(kt,s,a),pn(null)}})}),!n&&h&&Fr&&(0,e.jsx)(r.Suspense,{fallback:null,children:(0,e.jsx)(om,{projectUuid:h.uuid,open:Fr,drawsItself:!!h.auto_
8storyboard,onClose:()=>fn(!1),onChanged:()=>{Jt(Date.now()),k(t),W(t)},onOpenShot:nt,onWriteDescriptions:s=>void St(s)})}),!n&&h?.cast_review_pending&&(0,e.jsx)(r.Suspense,{fallback:null,children:(0,e.jsx)(rm,{projectUuid:h.uuid,onStarted:()=>{k(t),W(t)},onDismissed:()=>k(t),onRefresh:()=>k(t)})}),!(A&&C>=5&&C<=9&&!T)&&(0,e.jsx)(Pu,{steps:yi,startStep:2,endStep:10}),wr&&(0,e.jsx)(Ad,{isOpen:wr,onClose:()=>Sr(!1),projectUuid:t,projectAspectRatio:h?.aspect_ratio})]})};const Am=({projectUuid:t,readOnly:n=!1})=>(0,e.jsx)(Fc,{children:(0,e.jsx)(ed,{children:(0,e.jsx)(km,{projectUuid:t,readOnly:n})})});var Wh=Am;export{Am as StoryboardCanvas,Wh 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.