1import{j as e}from"./query-CHDd9xWM.js";import{f as Ee,r as o}from"./react-vendor-iR8l3MlE.js";import{a as Re,u as Pe,d as $e,s as m,j as Fe,f as Le,X as Ue,k as ne,h as Ae,D as Te,l as Ie,m as Ve,n as Ge,o as Oe}from"./index-QkQHgx4Z.js";import{u as qe,S as Me}from"./StudioPlanGate-ZdMNJTTV.js";import{u as Ye}from"./useTargetUser-CxFQnumS.js";import{u as ze}from"./useCreditGate-DVqAiy-2.js";import{u as Be}from"./ThemeToggle-1m08e_W7.js";import{A as We}from"./AppLayout3-CTI9xvYs.js";import{A as He,b as Je,c as Ke,d as Qe,e as Xe,f as Ze,g as et,h as tt}from"./alert-dialog-D0YdPlJ8.js";import{V as p}from"./video-presets-B8meWGAu.js";import{j as st}from"./jet-director-ChwaDwNP.js";import{V as rt}from"./video-DdNdld-4.js";import{I as ce}from"./image-BWSpvyh2.js";import{F as at}from"./folder-CCfwFCJk.js";import{D as ot}from"./download-C71vJRNS.js";import{T as lt}from"./trash-2-BaJzVAPR.js";import"./radix-DFsJdaPX.js";import"./supabase-92svyh75.js";import"./charts-ROjd8s19.js";import"./motion--e7AmMHx.js";import"./PaidFeatureGate-BJjPxAmd.js";import"./useAdmin-B76xPrYc.js";import"./feature-gates-CK3Zovmi.js";import"./zap-DOnnGFKd.js";import"./sun-GqUDPmK2.js";import"./scroll-area-WFUhVwGV.js";import"./bell-DvlGxNjD.js";import"./megaphone-Bc-bPFYk.js";import"./settings-B-Ekg2Wq.js";import"./Messenger-C1LAec33.js";import"./textarea-V3ptMj4z.js";import"./arrow-up-CAO02EsK.js";import"./message-square-DUJyyXLe.js";import"./en-US-C5RZswbt.js";import"./users-jRa2RaTL.js";import"./file-text-BPfaR0N5.js";import"./index-Dzzq0hvN.js";import"./external-link-yZcfNfn1.js";import"./gift-B6BXdscY.js";import"./user-h38L-V2d.js";import"./folder-open-0lJ3znjg.js";import"./plus-bkD7-Vn4.js";import"./format-CZaY-Cw5.js";import"./link-CBUaYhHk.js";import"./search-Cr-fd5Qe.js";import"./disc-3-CK__ICjk.js";import"./calendar-BqiZCOQP.js";import"./list-music-BRblp0st.js";import"./chart-column-B7crDsh2.js";import"./message-circle-DahbXiEe.js";import"./circle-help-BhYL9tyG.js";import"./chevron-up-C1fRqr1H.js";const R={fontFamily:"'General Sans', system-ui, sans-serif"},w="#8B5CF6",de=[{seconds:6,cost:80,note:"1080p"},{seconds:10,cost:120,note:"768p"}];function os(){var oe,le;const{user:d}=Re(),ue=qe(),{targetUserId:me}=Ye(),u=me||(d==null?void 0:d.id),{toast:c}=Pe(),{gate:M,CreditGate:pe}=ze(),{theme:xe}=$e(),n=xe==="dark",[Y]=Ee(),z=(()=>{const t=Y.get("preset");return t&&p.some(r=>r.id===t)?t:p[0].id})(),[N,fe]=o.useState(z),x=p.find(t=>t.id===N)||p[0],[k,B]=o.useState(Y.get("prompt")||((oe=p.find(t=>t.id===z))==null?void 0:oe.prompt)||""),W=o.useRef(!1),[f,he]=o.useState(6),P=((le=de.find(t=>t.seconds===f))==null?void 0:le.cost)??80,[g,D]=o.useState(!1),$=o.useRef(null);o.useEffect(()=>{if(!g)return;const t=s=>{$.current&&!$.current.contains(s.target)&&D(!1)},r=s=>{s.key==="Escape"&&D(!1)};return document.addEventListener("mousedown",t),document.addEventListener("keydown",r),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("keydown",r)}},[g]);const[F,L]=o.useState(null),[H,U]=o.useState(null),[J,ge]=o.useState([]),[ye,A]=o.useState(!1),[T,K]=o.useState(""),[be,Q]=o.use
1State(!0),[y,X]=o.useState(!1),[je,S]=o.useState(""),[_,I]=o.useState(0),[b,C]=o.useState(null),[Z,ee]=o.useState([]),[V,te]=o.useState(!0),[G,O]=o.useState(null),[q,se]=o.useState(!1),{remaining:re}=Be();o.useEffect(()=>{if(!y)return;const t=Date.now(),r=15e4,s=window.setInterval(()=>{const l=Date.now()-t,h=95*(1-Math.exp(-l/(r/2.2)));I(v=>Math.max(v,Math.min(95,h)))},400);return()=>window.clearInterval(s)},[y]);const ve=t=>{fe(t);const r=p.find(s=>s.id===t);r&&!W.current&&B(r.prompt)};o.useEffect(()=>{!d||!u||(Q(!0),m.from("releases").select("id, song_title, artist_name, artwork_url").eq("user_id",u).order("release_date",{ascending:!1}).then(({data:t})=>{ge(t||[]),Q(!1)}))},[d,u]);const j=o.useCallback(async()=>{if(!u)return;te(!0);const{data:t}=await m.from("video_generations").select("id, prediction_id, status, style, video_url, created_at").eq("user_id",u).neq("style","spotify-canvas").order("created_at",{ascending:!1}).limit(24);ee((t||[]).filter(r=>!!r.video_url)),te(!1)},[u]);o.useEffect(()=>{j()},[j]);const we=o.useCallback(async t=>{if(!u)return;const{error:r}=await m.from("video_generations").delete().eq("id",t).eq("user_id",u);if(r){c({title:"Delete failed",description:r.message,variant:"destructive"});return}ee(s=>s.filter(l=>l.id!==t)),c({title:"Video deleted"})},[u,c]),Ne=async t=>{var ie;const r=(ie=t.target.files)==null?void 0:ie[0];if(!r||!d)return;if(!r.type.startsWith("image/")){c({title:"Invalid file",variant:"destructive"});return}if(r.size>10*1024*1024){c({title:"File too large (max 10MB)",variant:"destructive"});return}U(URL.createObjectURL(r));const s=r.name.split(".").pop(),l=`video-frames/${d.id}/${Date.now()}.${s}`,{data:h,error:v}=await m.storage.from("gallery").upload(l,r,{contentType:r.type});if(t.target.value="",v){c({title:"Upload failed",variant:"destructive"});return}const{data:Ce}=m.storage.from("gallery").getPublicUrl(h.path);L(Ce.publicUrl)},ke=()=>{L(null),U(null)},ae=o.useCallback(async t=>{const r=Date.now()+48e4;for(;Date.now()<r;){try{await m.functions.invoke("generate-video",{body:{action:"poll",predictionId:t}})}catch{}const{data:s}=await m.from("video_generations").select("status, video_url, error_message").eq("prediction_id",t).maybeSingle();if(s){if((s.status==="succeeded"||s.status==="completed")&&s.video_url)return s.video_url;if(s.status==="failed"||s.status==="canceled")throw new Error(s.error_message||"Video generation failed.")}await new Promise(l=>setTimeout(l,5e3))}throw new Error("Still rendering. Your video will appear here once it finishes.")},[]),De=o.useCallback(async()=>{if(!d)return;if(!k.trim()){c({title:"Describe your video first"});return}if(await M(P,"Generate Video",{confirm:!0})){X(!0),C(null),I(2),S("Starting your videoâ¦");try{const r={prompt:k,style:x.style,duration:f,noRelease:!0};F&&(r.artworkUrl=F);const{data:s,error:l}=await m.functions.invoke("generate-video",{body:r});if(l)throw l;if(s!=null&&s.error)throw new Error(s.error);const h=s==null?void 0:s.predictionId;if(!h)throw new Error("No prediction ID returned");S(`Rendering your ${f} second clip⦠this may take 2â5 minutes`);const v=await ae(h);I(100),C(v),S(""),c({title:"Video ready"}),window.dispatchEvent(new Event("credits-updated")),j()}catch(r){c({title:"Video generation failed",description:r instanceof Error?r.message:"Please try again.",variant:"destructive"}),S("")}finally{X(!1),j()}}},[d,k,M,P,x.style,f,F,ae,c,j]),Se=async t=>{try{const s=await(await fetch(t,{mode:"cors"})).blob(),l=document.createElement("a");l.href=URL.createObjectURL(s),l.download=`video-${Date.now()}.mp4`,l.click(),URL.revokeObjectURL(l.href)}catch{c({title:"Download failed",variant:"destructive"})}},a=t=>n?`rgba(255,255,255,${t})`:`rgba(10,10,16,${t})`,i=a(.1),_e=n?"rgba(255,255,255,0.04)":"#ffffff",E="text-[12.5px] font-medium mb-2";return ue?e.jsx(Me,{featureName:"Video Studio",title:"Media Generator / Video Studio"}):e.jsxs(We,{title:"Media Generator / Video Studio",titleIcon:e.jsx(rt,{className:"h-5 w-5",strokeWidth:1.5}),fullWidth:!0,noPadding:!0,compactThroughTablet:!0,children:[pe,e.jsx("div",{className:"min-h-[calc(100vh-4rem)] w-full",style:{...R,background:n?"hsl(225 10% 7%)":"hsl(0 0% 98%)",color:a(.9)}
1,children:e.jsxs("div",{className:"mx-auto max-w-[1500px] grid grid-cols-1 lg:grid-cols-[minmax(300px,380px)_minmax(0,1fr)]",children:[e.jsxs("div",{className:"px-5 py-7 lg:min-h-[calc(100vh-4rem)] flex flex-col gap-5",style:{borderRight:`1px solid ${i}`},children:[e.jsxs("div",{ref:$,className:"relative",children:[e.jsx("p",{className:E,style:{color:a(.9)},children:"Style"}),e.jsxs("button",{type:"button",onClick:()=>D(t=>!t),"aria-expanded":g,"aria-haspopup":"listbox",className:"w-full flex items-center gap-3 rounded-xl px-2.5 py-2.5 text-left",style:{border:`1px solid ${i}`,background:n?"rgba(255,255,255,0.03)":"#fff"},children:[e.jsx("video",{src:x.video,poster:x.poster,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,preload:"metadata",className:"h-12 w-[27px] shrink-0 rounded-md object-cover bg-black"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-[13.5px] truncate",style:{color:a(.9)},children:x.label}),e.jsx("span",{className:"block text-[11.5px] truncate",style:{color:a(.45)},children:x.description})]}),e.jsx(Fe,{className:"h-4 w-4 shrink-0 transition-transform",style:{color:a(.45),transform:g?"rotate(180deg)":"none"}})]}),g&&e.jsx("div",{role:"listbox",className:"absolute z-30 left-0 right-0 mt-2 rounded-xl p-2.5 shadow-xl",style:{border:`1px solid ${i}`,background:n?"hsl(225 10% 11%)":"#ffffff"},children:e.jsx("div",{className:"grid grid-cols-3 gap-2.5 max-h-[420px] overflow-y-auto",children:p.map(t=>e.jsxs("button",{type:"button",role:"option","aria-selected":t.id===N,onClick:()=>{ve(t.id),D(!1)},className:"relative text-left rounded-xl overflow-hidden",style:{border:`1px solid ${t.id===N?a(.35):i}`},children:[e.jsx("video",{src:t.video,poster:t.poster,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,preload:"metadata",className:"w-full aspect-[9/16] object-cover bg-black"}),e.jsx("span",{className:"block px-2 py-1.5 text-[11.5px] truncate",children:t.label}),t.id===N&&e.jsx("span",{className:"absolute top-1.5 right-1.5 h-4 w-4 rounded-full flex items-center justify-center",style:{background:w},children:e.jsx(Le,{className:"h-3 w-3 text-white"})})]},t.id))})})]}),e.jsxs("div",{children:[e.jsx("p",{className:E,style:{color:a(.9)},children:"Length"}),e.jsx("div",{className:"grid grid-cols-2 gap-2.5",children:de.map(t=>{const r=t.seconds===f;return e.jsxs("button",{type:"button",onClick:()=>he(t.seconds),className:"rounded-xl px-3 py-2.5 text-left",style:{border:`1px solid ${r?w:i}`,background:r?"rgba(139,92,246,0.08)":n?"rgba(255,255,255,0.03)":"#fff"},children:[e.jsxs("span",{className:"block text-[13.5px] font-medium",style:{color:a(.9)},children:[t.seconds," seconds"]}),e.jsxs("span",{className:"block text-[11.5px]",style:{color:a(.45)},children:[t.note," · ",t.cost," credits"]})]},t.seconds)})})]}),e.jsxs("div",{children:[e.jsx("p",{className:E,style:{color:a(.9)},children:"Cover art / first frame (optional)"}),H?e.jsxs("div",{className:"relative inline-block rounded-xl overflow-hidden",style:{border:`1px solid ${i}`},children:[e.jsx("img",{src:H,alt:"First frame",className:"w-full max-w-[180px] aspect-square object-cover"}),e.jsx("button",{type:"button",onClick:ke,"aria-label":"Remove image",className:"absolute top-2 right-2 h-7 w-7 rounded-full flex items-center justify-center",style:{background:"rgba(0,0,0,0.55)"},children:e.jsx(Ue,{className:"h-4 w-4 text-white"})})]}):e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("label",{className:"flex flex-col items-center justify-center gap-3 rounded-2xl py-8 px-4 cursor-pointer",style:{background:n?"rgba(255,255,255,0.04)":"#F3F5F7",border:`1px solid ${i}`},children:[e.jsx("span",{className:"h-11 w-12 rounded-xl flex items-center justify-center",style:{background:n?"rgba(255,255,255,0.05)":"#EAECEF",border:`1px solid ${a(.08)}`},children:e.jsx(ce,{className:"h-5 w-5",style:{color:a(.5)}})}),e.jsx("span",{className:"text-[13.5px] text-center",style:{color:a(.85)},children:"Upload your cover"}),e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:Ne})]}),e.jsxs("button",{type:"button",onClick:()=>{K(""),A(!0)},className:"w-full h-full flex flex-col items-center justify-center gap-3 rounded-2xl py-8 px-4",style:{background:n?"rgba(255,255,255,0.04)":"#F3F5F7",border:`1px solid ${i}`},children:[e.jsx("span",{className:"h-11 w-12 rounded-xl flex items-center justify-center",style:{background:n?"rgba(255,255,255,0.05)":"#EAECEF",border:`1px solid ${a(.08)}`},children:e.jsx(at,{className:"h-5 w-5",style:{color:a(.5)}})}),e.jsx("span",{className:"text-[13.5px] text-center",style:{color:a(.85)},children:"Select from release"})]})]})]}),e.jsxs("div",{className:"mt-auto",children:[e.jsx("p",{className:E,style:{color:a(.9)}
1,children:"Describe your video"}),e.jsx("textarea",{value:k,onChange:t=>{W.current=!0,B(t.target.value)},rows:4,placeholder:"Slow cinematic push-in on the artwork, moody lighting, drifting haze",className:"w-full rounded-xl px-3 py-2.5 text-[13.5px] leading-relaxed bg-transparent outline-none resize-none",style:{border:`1px solid ${i}`,color:a(.9)}}),e.jsxs("div",{className:"mt-3 flex items-end justify-between gap-3",children:[e.jsxs("span",{className:"text-[12.5px]",style:{color:a(.5)},children:[f,"s · 9:16 · ",P," credits",re>0?` · ${re} left`:""]}),e.jsx("button",{type:"button",onClick:De,disabled:y,className:"rounded-lg px-5 py-2.5 text-[15px] font-semibold text-white disabled:opacity-60 shrink-0",style:{background:w},children:y?"Generatingâ¦":"Generate"})]})]})]}),e.jsx("div",{className:"px-6 lg:px-9 py-8",children:y||b?e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"relative w-full max-w-[300px] rounded-2xl overflow-hidden flex items-center justify-center bg-black",style:{aspectRatio:"9 / 16",border:`1px solid ${i}`},children:b?e.jsx("video",{src:b,controls:!0,autoPlay:!0,loop:!0,playsInline:!0,className:"h-full w-full object-cover"}):e.jsxs("div",{className:"flex w-full flex-col items-center gap-3 px-6 text-center",children:[e.jsx(ne,{className:"h-7 w-7 animate-spin",style:{color:w}}),e.jsxs("div",{className:"w-full max-w-[220px]",children:[e.jsx("div",{className:"h-1.5 w-full overflow-hidden rounded-full bg-white/12",children:e.jsx("div",{className:"h-full rounded-full transition-[width] duration-500 ease-out",style:{width:`${_}%`,background:w}})}),e.jsxs("div",{className:"mt-2 flex items-center justify-between text-[11px] text-white/50",children:[e.jsx("span",{children:_<8?"Queued":_<92?"Rendering":"Finishing"}),e.jsxs("span",{children:[Math.round(_),"%"]})]})]}),e.jsx("p",{className:"text-[13px] text-white/70",children:je||"Rendering your videoâ¦"})]})}),b&&e.jsxs("div",{className:"mt-4 flex items-center gap-2.5",children:[e.jsx("button",{type:"button",onClick:()=>C(null),className:"rounded-full px-4 py-2 text-[13px] font-semibold text-white transition-[filter] duration-200 hover:brightness-110",style:{background:"#6B2FFA"},children:"Back"}),e.jsxs("button",{type:"button",onClick:()=>Se(b),className:"rounded-full px-4 py-2 text-[13px] font-medium flex items-center gap-2",style:{background:_e,border:`1px solid ${i}`,color:a(.85)},children:[e.jsx(ot,{className:"h-4 w-4"})," Download"]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-[26px] md:text-[30px] font-semibold tracking-[-0.02em]",children:"Your videos"}),e.jsx("p",{className:"mt-1 text-[13.5px]",style:{color:a(.5)},children:"Every promo clip you have generated in the studio"}),e.jsxs("div",{className:"mt-6 grid grid-cols-2 sm:grid-cols-3 xl:grid-cols-5 gap-4",children:[V&&Array.from({length:5}).map((t,r)=>e.jsx("div",{className:"rounded-2xl animate-pulse",style:{aspectRatio:"9/16",background:a(.06)}},r)),!V&&Z.map(t=>e.jsxs("div",{className:"relative group rounded-2xl overflow-hidden bg-black",style:{aspectRatio:"9/16",border:`1px solid ${i}`},children:[e.jsxs("button",{type:"button",onClick:()=>C(t.video_url),className:"block w-full h-full","aria-label":"Open video",children:[e.jsx("video",{src:t.video_url||void 0,muted:!0,loop:!0,playsInline:!0,preload:"metadata",className:"h-full w-full object-cover"}),e.jsx("span",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("span",{className:"h-9 w-9 rounded-full flex items-center justify-center",style:{background:"rgba(0,0,0,0.45)"},children:e.jsx(Ae,{className:"h-4 w-4 text-white"})})})]}),e.jsx("button",{type:"button",onClick:r=>{r.stopPropagation(),O(t.id)},"aria-label":"Delete video",className:"absolute top-2 right-2 h-7 w-7 rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 focus:opacity-100 transition-opacity",style:{background:"rgba(0,0,0,0.55)"},children:e.jsx(lt,{className:"h-3.5 w-3.5 text-white"})})]},t.id))]}),!V&&Z.length===0&&e.jsxs("div",{className:"mt-6 rounded-2xl px-6 py-10 text-center",style:{border:`1px dashed ${a(.16)}`},children:[e.jsx("img",{src:st,alt:"","aria-hidden":"true",className:"mx-auto mb-3 h-24 w-24 object-contain select-none pointer-events-none animate-[jet-direct_3.6s_ease-in-out_infinite]"}),e.jsx("p",{className:"text-[15px] font-medium",children:"No videos yet"}),e.jsx("p",{className:"mt-1 text-[13px]",style:{color:a(.5)},children:"Pick a style, add your cover and hit Generate. Jet is ready to direct."}),e.jsx("style",{children:"@keyframes jet-direct{0%,100%{transform:translateY(0) rotate(-2deg)}50%{transform:translateY(-6px) rotate(2deg)}}"})]})]})})]})}),e.jsx(He,{open:!!G,onOpenChange:t=>{t||O(null)},children:e.jsxs(Je,{children:[e.jsxs(Ke,{children:[e.jsx(Qe,{children:"Delete this video?"}),e.jsx(Xe,{children:"This video will be removed from your videos. This cannot be undone."})]}),e.jsxs(Ze,{children:[e.jsx(et,{disabled:q,children:"Cancel"}),e.jsx(tt,{disabled:q,onClick:async t=>{t.preventDefault(),G&&(se(!0),await we(G),se(!1),O(null))},children:q?"Deletingâ¦":"Delete"})]})]})}),e.jsx(Te,{open:ye,onOpenChange:A,children:e.jsxs(Ie,{className:"max-w-3xl max-h-[85vh] flex flex-col p-0 gap-0",children:[e.jsxs(Ve,{className:"px-6 pt-6 pb-4",children:[e.jsx(Ge,{style:R,children:"Select from release"}),e.jsx(Oe,{children:"Pick a release and we'll use its cover as the first frame."})]}),e.jsx("div",{className:"px-6 pb-4",children:e.jsx("input",{autoFocus:!0,value:T,onChange:t=>K(t.target.value),placeholder:"Search releases",className:"w-full rounded-xl px-3.5 py-2.5 text-[14px] outline-none",style:{...R,background:n?"rgba(255,255,255,0.05)":"#F3F5F7",border:`1px solid ${i}`,color:a(.9)}
1})}),e.jsx("div",{className:"px-6 pb-6 overflow-y-auto",children:be?e.jsx("div",{className:"py-12 flex justify-center",children:e.jsx(ne,{className:"h-5 w-5 animate-spin",style:{color:a(.4)}})}):(()=>{const t=T.trim().toLowerCase(),r=J.filter(s=>!t||(s.song_title||"").toLowerCase().includes(t)||(s.artist_name||"").toLowerCase().includes(t));return J.length===0?e.jsx("p",{className:"py-10 text-center text-[13.5px]",style:{color:a(.55)},children:"No releases yet. Create a release first, or upload a cover."}):r.length===0?e.jsxs("p",{className:"py-10 text-center text-[13.5px]",style:{color:a(.55)},children:['No releases match "',T,'".']}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:r.map(s=>e.jsxs("button",{type:"button",onClick:()=>{s.artwork_url&&(L(s.artwork_url),U(s.artwork_url)),A(!1)},disabled:!s.artwork_url,className:"text-left rounded-xl overflow-hidden transition-transform hover:-translate-y-0.5 disabled:opacity-40 disabled:hover:translate-y-0",style:{border:`1px solid ${i}`},children:[s.artwork_url?e.jsx("img",{src:s.artwork_url,alt:s.song_title,className:"w-full aspect-square object-cover bg-black"}):e.jsx("div",{className:"w-full aspect-square flex items-center justify-center",style:{background:n?"rgba(255,255,255,0.05)":"#EAECEF"},children:e.jsx(ce,{className:"h-6 w-6",style:{color:a(.35)}})}),e.jsx("span",{className:"block px-2.5 pt-2 text-[12.5px] font-medium truncate",style:{...R,color:a(.9)},children:s.song_title||"Untitled"}),e.jsx("span",{className:"block px-2.5 pb-2 text-[11.5px] truncate",style:{color:a(.5)},children:s.artwork_url?s.artist_name||"":"No cover art"})]},s.id))})})()})]})})]})}export{os 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.