1import{r as pe}from"./rolldown-runtime.C1f3BsDW.js";import"./inertia.BE4YqsTM.js";import"./http.DWpeO7Ui.js";import{I as Ne,Qr as ye,l as Se,lr as Me,wr as we,wt as oe}from"./icons.ChOq_Y4q.js";import{t as _e}from"./react-core.CAMe6Z4j.js";import"./utils.CgzVjNgC.js";import"./state.L8kQliOB.js";import{B as F,Q as Ie,Tt as N,jt as ne,k as ie}from"./entry-client.DX3aUoe5.js";import{n as ce,r as Te}from"./input.GzdAc1Aj.js";import"./dist.CoNAZqlp.js";import"./dist.DxccqHSW.js";import"./dist.D4237Rk6.js";import"./dist.BhzTvz6X.js";import"./dist.zmknLG-d.js";import"./es2015.Cr2X04_P.js";import"./dist.DbqQa_sy.js";import{a as ke,n as Ce,o as Ae,t as Fe}from"./dialog.Bb7MGeDP.js";import"./dist.D4LCotyC.js";import"./dist.C1cc-Zbw.js";import{a as D,i as E,n as G,r as y,t as P}from"./select.vYEvBl4E.js";import{t as c}from"./label.D8t8fk_6.js";import{t as De}from"./slider.BZoarXCr.js";import{n as Ee}from"./useFreeTierGate.CwupVhTY.js";import{t as Ge}from"./switch.D3Vh3rjF.js";var a=pe(ye(),1),e=pe(_e(),1),B=o=>{const r=Math.floor(o/1e3),n=Math.floor(r/60),d=r%60,i=Math.floor(o%1e3/10);return`${n.toString().padStart(2,"0")}:${d.toString().padStart(2,"0")}.${i.toString().padStart(2,"0")}`},de=o=>{const r=o.match(/^(\d{1,2}):(\d{2})(?:\.(\d{1,2}))?$/);if(!r)return null;const n=parseInt(r[1],10),d=parseInt(r[2],10),i=r[3]?parseInt(r[3].padEnd(2,"0"),10)*10:0;return d>=60?null:(n*60+d)*1e3+i},$=1e3,me=10,ue=240,L=o=>{if(o<60)return`${o}s`;const r=Math.floor(o/60),n=o%60;return n===0?`${r}:00`:`${r}:${String(n).padStart(2,"0")}`};const Pe=({projectId:o,isOpen:r,onClose:n,onGenerated:d,initialStartTimeMs:i=0})=>{const[m,R]=(0,a.useState)(""),[S,V]=(0,a.useState)(30),[U,M]=(0,a.useState)(""),[w,X]=(0,a.useState)(""),[q,z]=(0,a.useState)(null),[H,J]=(0,a.useState)(""),[K,Q]=(0,a.useState)(!1),[O,_]=(0,a.useState)([]),[W,I]=(0,a.useState)([]),[Y,x]=(0,a.useState)(!1),[Z,h]=(0,a.useState)(!1),[ee,se]=(0,a.useState)(!1),[te,T]=(0,a.useState)(i),[ae,f]=(0,a.useState)(B(i)),{isFreeTier:re,blockIfFree:xe}=Ee(),[l,u]=(0,a.useState)(!1),[p,k]=(0,a.useState)(!1),[C,j]=(0,a.useState)(null),[le,A]=(0,a.useState)(0);(0,a.useEffect)(()=>{r&&(T(i),f(B(i)))},[r,i]),(0,a.useEffect)(()=>{r&&!re&&he()},[r,re]);const he=async()=>{se(!0);try{console.log("[Music Models] Fetching models...");let s=await F.getMusicModels("modelslab_song_generation");console.log("[Music Models] ModelsLab response:",s.data);let t=s.data?.data;!t?.supports_model_selection&&!t?.supports_style_selection&&(console.log("[Music Models] Trying default provider..."),s=await F.getMusicModels(),t=s.data?.data),t?.supports_model_selection||t?.supp
1orts_style_selection?(console.log("[Music Models] Provider supports selection:",t),_(t.models||[]),I(t.styles||[]),x(t.supports_model_selection),h(t.supports_style_selection),M(t.default_model||t.models?.[0]?.id||"")):(console.log("[Music Models] Provider does not support selection"),x(!1),h(!1),_([]),I([]))}catch(s){console.error("[Music Models] Failed to fetch music models:",s),x(!1),h(!1)}finally{se(!1)}};(0,a.useEffect)(()=>{if(!C)return;const s=300;let t=0;const g=setInterval(async()=>{if(t++,t>s){clearInterval(g),u(!1),j(null),N.error("This took too long. Try again.");return}try{const v=await Ie.get(C),b=v.data?.data||v.data;b.status==="completed"?(clearInterval(g),u(!1),j(null),k(!0),d(),setTimeout(()=>{k(!1),n()},1200)):b.status==="failed"?(clearInterval(g),u(!1),j(null),N.error(b.user_error?.message||"Could not make the music. Try again.")):A(b.progress||0)}catch(v){console.error("Error polling job status:",v)}},2e3);return()=>clearInterval(g)},[C,d,n]);const fe=()=>{!l&&!p&&(R(""),V(30),M(""),X(""),z(null),J(""),Q(!1),A(0),k(!1),T(0),f("00:00.00"),_([]),I([]),x(!1),h(!1),n())},je=s=>{f(s);const t=de(s);t!==null&&T(t)},ge=()=>{de(ae)===null&&f(B(te))},ve=async()=>{if(!xe("generate-music")){if(!m.trim()){N.error("Describe the music you want.");return}u(!0),A(0);try{const s=await F.generateMusic({project_id:o,prompt:m.trim(),duration_seconds:S,start_time_ms:te,model:Y?U:void 0,style:Z&&w?w:void 0,tempo:q||void 0,key:H||void 0,instrumental:K}),t=s.data?.data?.job_id||s.data?.job_id;if(t)j(t);else throw new Error("No job ID returned")}catch(s){console.error("Generation error:",s),u(!1);const t=s;N.error(t.response?.data?.message||"Could not start the music. Try again.")}}},be=["C major","G major","D major","A major","E major","B major","F# major","C minor","G minor","D minor","A minor","E minor","B minor","F# minor","F major","Bb major","Eb major","Ab major","Db major","Gb major","F minor","Bb minor","Eb minor","Ab minor","Db minor","Gb minor"];return r?(0,e.jsx)(Fe,{open:r,onOpenChange:n,children:(0,e.jsxs)(Ce,{className:"max-w-lg p-0 overflow-hidden overflow-y-auto",children:[(0,e.jsx)(ke,{className:"",children:(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("div",{className:"h-8 w-8 rounded-lg flex items-center justify-center ",children:(0,e.jsx)(oe,{className:"h-4 w-4 text-primary","aria-hidden":"true"})}),(0,e.jsxs)("div",{children:[(0,e.jsx)(Ae,{className:"font-semibold mb-2",children:"Make music"}),(0,e.jsx)("p",{className:"text-xs mt-1 text-muted-foreground",children:"Make music for your film"})]})]})}),(0,e.jsxs)("div",{className:"mt-4 space-y-4 p-4",children:[(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsxs)(c,{htmlFor:"music-prompt",className:"flex items-center gap-2",children:[(0,e.jsx)(Se,{className:"h-4 w-4 text-muted-foreground"}),"Describe the music"]}),(0,e.jsxs)("span",{className:ne("text-xs",m.length>$?"text-destructive":"text-muted-foreground"),children:[m.length," / ",$]})]}),(0,e.jsx)(Te,{id:"music-prompt",name:"music_prompt",placeholder:`Describe the music you want⦠2e.g., Upbeat electronic dance track with energetic synths and driving bass, perfect for a workout montage`,value:m,onChange:s=>R(s.target.value.slice(0,$)),rows:4,disabled:l,className:"resize-none",autoComplete:"off"})]}),Y&&O.length>0&&(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)(c,{htmlFor:"music-model",className:"flex items-center gap-2",children:[(0,e.jsx)(Ne,{className:"h-4 w-4 text-muted-foreground"}),"Model"]}),(0,e.jsxs)(P,{value:U,onValueChange:M,disabled:l||ee,children:[(0,e.jsx)(E,{id:"music-model",children:(0,e.jsx)(D,{placeholder:"Select a model"})}),(0,e.jsx)(G,{children:O.map(s=>(0,e.jsx)(y,{value:s.id,children:(0,e.jsxs)("div",{className:"flex flex-col items-start",children:[(0,e.jsx)("span",{className:"font-medium",children:s.name}),(0,e.jsx)("span",{className:"text-xs text-muted-foreground",children:s.description})]})},s.id))})]})]}),Z&&W.length>0&&(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)(c,{htmlFor:"music-style",children:"Style / Genre"}),(0,e.jsxs)(P,{value:w,onValueChange:X,disabled:l||ee,children:[(0,e.jsx)(E,{id:"music-style",children:(0,e.jsx)(D,{placeholder:"Select a style (optional)"})}),(0,e.jsx)(G,{children:W.map(s=>(0,e.jsx)(y,{value:s.id,children:(0,e.jsxs)("div",{className:"flex flex-col items-start",children:[(0,e.jsx)("span",{className:"font-medium",children:s.name}),(0,e.jsx)("span",{className:"text-xs text-muted-foreground",children:s.description})]})},s.id))})]})]}),(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsx)(c,{id:"music-duration-label",children:"Duration"}),(0,e.jsx)("span",{className:"text-sm font-medium tabular-nums",children:L(S)})]}),(0,e.jsx)(De,{min:me,max:ue,step:5,value:[S],onValueChange:([s])=>V(s),disabled:l,className:"w-full","aria-labelledby":"music-duration-label"}),(0,e.jsxs)("div",{className:"flex justify-between text-xs text-muted-foreground",children:[(0,e.jsx)("span",{children:L(me)}),(0,e.jsxs)("span",{children:[L(ue)," max"]})]})]}),(0,e.jsxs)("div",{className:"space-y-3 border rounded-lg p-3 bg-secondary/20",children:[(0,e.jsx)("p",{className:"text-sm font-medium",children:"Advanced Options"}),(0,e.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsx)(c,{htmlFor:"music-tempo",className:"text-xs",children:"Tempo (BPM)"}),(0,e.jsx)(ce,{id:"music-tempo",type:"number",min:60,max:200,value:q||"",onChange:s=>{const t=parseInt(s.target.value);z(isNaN(t)?null:t)},placeholder:"120",disabled:l,className:"h-8"})]}),(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsx)(c,{htmlFor:"music-key",className:"text-xs",children:"Musical key"}),(0,e.jsxs)(P,{value:H||"auto",onValueChange:s=>J(s==="auto"?"":s),disabled:l,children:[(0,e.jsx)(E,{id:"music-key",className:"h-8",children:(0,e.jsx)(D,{placeholder:"Auto"})}),(0,e.jsxs)(G,{children:[(0,e.jsx)(y,{value:"auto",children:"Auto (Automatic)"}),be.map(s=>(0,e.jsx)(y,{value:s,children:s},s))]})]})]})]}),(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsxs)("div",{className:"space-y-0.5",children:[(0,e.jsx)(c,{htmlFor:"instrumental",className:"text-sm",children:"Instrumental only"}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:"Generate music without vocals"})]}),(0,e.jsx)(Ge,{id:"instrumental",checked:K,onCheckedChange:Q,disabled:l})]})]}),(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(Me,{className:"h-4 w-4 text-muted-foreground","aria-hidden":"true"}),(0,e.jsx)(c,{htmlFor:"timeline-position",children:"Timeline Position"})]}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(ce,{id:"timeline-position",name:"timeline_position",type:"text",value:ae,onChange:s=>je(s.target.value),onBlur:ge,disabled:l,placeholder:"e.g. 00:02.5â¦",className:"w-28 text-center font-mono"}),(0,e.jsx)("span",{className:"text-xs text-muted-foreground",children:"(Format: MM:SS.ms)"})]})]}),l&&(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between text-sm",children:[(0,e.jsx)("span",{className:"text-muted-foreground",children:"Making the musicâ¦"}),(0,e.jsxs)("span",{className:"font-medium",children:[le,"%"]})]}),(0,e.jsx)("div",{className:"h-2 bg-secondary rounded-full overflow-hidden",children:(0,e.jsx)("div",{className:"h-full transition-smooth duration-300 bg-primary",style:{width:`${Math.max(le,10)}%`}})}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:"Music can take 1â2 minutesâ¦"})]})]}),(0,e.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border bg-secondary/30",children:[(0,e.jsx)(ie,{variant:"ghost",onClick:fe,disabled:l||p,children:"Cancel"}),(0,e.jsx)(ie,{onClick:ve,disabled:l||p||!m.trim(),className:ne("transition-smooth duration-300",p?"bg-success hover:bg-success min-w-[120px]":l?"min-w-[140px]":"bg-primary"),children:p?(0,e.jsxs)("div",{className:"flex items-center gap-2 animate-in fade-in zoom-in duration-300",children:[(0,e.jsx)("div",{className:"h-5 w-5 rounded-full bg-white/20 flex items-center justify-center",children:(0,e.jsx)(we,{className:"h-3.5 w-3.5 text-white","aria-hidden":"true"})}),(0,e.jsx)("span",{children:"Done"})]}):l?(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsxs)("div",{className:"relative h-5 w-5",children:[(0,e.jsx)("div",{className:"absolute inset-0 rounded-full border-2 border-white/30"}),(0,e.jsx)("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-white animate-spin"})]}),(0,e.jsx)("span",{children:"Makingâ¦"})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(oe,{className:"h-4 w-4","aria-hidden":"true"}),"Make music"]})})]})]})}):null};var ns=Pe;export{Pe as MusicGenerationModal,ns 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.