import{d as pe,b as fe,n as me,o as _e,s as o,e as n,D as be,r as l,i as x,t as z,z as B,a as v,p as ge,v as m,m as p,j as a,k as h,h as A,f as L,w as ze,g as he,l as De,A as we,y as xe}from"./DatabaseSelector-cHiExdDo.js";import{s as N}from"./class-QkZ203tr.js";var ye=p('<label for="audio-url" class="svelte-dpm9lz">Audio URL (.mp3 or .wav)</label> <input id="audio-url" type="url" placeholder="https://example.com/audio.mp3" required="" class="svelte-dpm9lz"/>',1),Fe=p('<div class="file-info svelte-dpm9lz"><span class="file-name svelte-dpm9lz"> </span> <span class="file-size svelte-dpm9lz"> </span> <button type="button" class="clear-btn svelte-dpm9lz">Remove</button></div>'),Se=p('<p class="drop-text svelte-dpm9lz">Drag & drop an audio file here</p> <p class="drop-subtext svelte-dpm9lz">or</p> <label class="browse-btn svelte-dpm9lz">Browse files <input type="file" accept="audio/*" hidden=""/></label>',1),ke=p("<div><!></div>"),Be=p("<option> </option>"),Ue=p('<label for="collection-select" class="svelte-dpm9lz">Collection (optional)</label> <select id="collection-select" class="collection-select svelte-dpm9lz"><option>No collection</option><!></select>',1),Pe=p('<p class="error svelte-dpm9lz"> </p>'),Re=p('<p class="success svelte-dpm9lz"> </p>'),Ae=p('<main><h1>New transcription</h1> <!> <div class="mode-toggle svelte-dpm9lz"><button>URL</button> <button>File upload</button></div> <form class="svelte-dpm9lz"><!> <!> <button type="submit" class="svelte-dpm9lz"> </button></form> <!> <!></main>');function Le(J,Q){fe(Q,!0);const V=me({baseUrl:"/"}),T=_e().collections??[];let f=m("url"),y=m(""),F=m(""),i=m(null),S=m(!1),k=m(!1),d=m(null),U=m(null);function X(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function C(e){if(!e.type.startsWith("audio/")){l(d,"Please select an audio file");return}l(i,e,!0),l(d,null)}function Y(e){e.preventDefault(),l(S,!1);const t=e.dataTransfer?.files[0];t&&C(t)}function Z(e){e.preventDefault(),l(S,!0)}function $(e){e.preventDefault(),l(S,!1)}function ee(e){const r=e.currentTarget.files?.[0];r&&C(r)}function te(e){return new Promise((t,r)=>{const s=new FileReader;s.onload=()=>{const _=s.result;t(_.split(",")[1])},s.onerror=r,s.readAsDataURL(e)})}async function ae(e){e.preventDefault(),l(d,null),l(U,null),l(k,!0);try{let t;if(a(f)==="file"&&a(i)){const _=await te(a(i));t={database:A.selectedDatabase,file_data:_,filename:a(i).name,content_type:a(i).type||"audio/mpeg"}}else t={database:A.selectedDatabase,url:a(F)};a(y)&&(t.collection_id=Number(a(y)));const{data:r,error:s}=await V.POST("/-/api/scribe/new",{body:t});if(s){l(d,s.error??"Unknown error",!0);return}window.location.href=`/${A.selectedDatabase}/-/scribe/transcription/${r.id}`}catch(t){l(d,t.message,!0)}finally{l(k,!1)}}var I=Ae(),E=o(n(I),2);be(E,{});var O=o(E,2),P=n(O);let j;P.__click=()=>{l(f,"url"),l(d,null)};var q=o(P,2);let K;q.__click=()=>{l(f,"file"),l(d,null)};var R=o(O,2),M=n(R);{var le=e=>{var t=ye(),r=o(L(t),2);ze(r,()=>a(F),s=>l(F,s)),v(e,t)},re=e=>{var t=ke();let r;var s=n(t);{var _=u=>{var c=Fe(),b=n(c),g=n(b),w=o(b,2),de=n(w),ue=o(w,2);ue.__click=()=>{l(i,null)},z(ve=>{h(g,a(i).name),h(de,ve)},[()=>X(a(i).size)]),v(u,c)},D=u=>{var c=Se(),b=o(L(c),4),g=o(n(b));g.__change=ee,v(u,c)};x(s,u=>{a(i)?u(_):u(D,!1)})}z(()=>r=N(t,1,"drop-zone svelte-dpm9lz",null,r,{dragging:a(S),"has-file":a(i)!==null})),B("drop",t,Y),B("dragover",t,Z),B("dragleave",t,$),v(e,t)};x(M,e=>{a(f)==="url"?e(le):e(re,!1)})}var W=o(M,2);{var se=e=>{var t=Ue(),r=o(L(t),2),s=n(r);s.value=s.__value="";var _=o(s);he(_,17,()=>T,De,(D,u)=>{var c=Be(),b=n(c),g={};z(w=>{h(b,a(u).name),g!==(g=w)&&(c.value=(c.__value=w)??"")},[()=>String(a(u).id)]),v(D,c)}),we(r,()=>a(y),D=>l(y,D)),v(e,t)};x(W,e=>{T.length>0&&e(se)})}var G=o(W,2),oe=n(G),H=o(R,2);{var ne=e=>{var t=Pe(),r=n(t);z(()=>h(r,a(d))),v(e,t)};x(H,e=>{a(d)&&e(ne)})}var ie=o(H,2);{var ce=e=>{var t=Re(),r=n(t);z(()=>h(r,a(U))),v(e,t)};x(ie,e=>{a(U)&&e(ce)})}z(()=>{j=N(P,1,"mode-btn svelte-dpm9lz",null,j,{active:a(f)==="url"}),K=N(q,1,"mode-btn svelte-dpm9lz",null,K,{active:a(f)==="file"}),G.disabled=a(k)||a(f)==="file"&&!a(i)||a(f)==="url"&&!a(F),h(oe,a(k)?"Submitting…":"Submit")}),B("submit",R,ae),v(J,I),ge()}pe(["click","change"]);xe(Le,{target:document.getElementById("app-root")});
