import{j as e,r as x,t as P}from"./index-gX9iSPDQ.js";import{u as L,r as D,q as M,V as z,t as J,v as K,x as B,y as j,I as $,z as G,J as Q}from"./index-IxgnfODg.js";import{B as v}from"./createLucideIcon-W0Ra_zwb.js";import{u as W,C as I,b as A,c as V,d as q,a as H}from"./index-BIG1Xq_V.js";import{z as g,u as X,s as Y,F as Z,a as b,b as w,c as S,d as k,I as ee,f as re,e as C}from"./index-Cc5_sMEQ.js";import{S as N,a as O,b as E,c as U,d as R}from"./select-CKazIOen.js";import{u as se}from"./useMutation-DC5Y5oj9.js";import{R as oe}from"./refresh-ccw-DxZh10-m.js";import{L as te}from"./loader-circle-BohTAJjK.js";import"./apiConstants-BiX1T2IA.js";import"./Combination-BtzWoF87.js";import"./index-DmVJm5MZ.js";const ae=g.object({audioFile:g.instanceof(File),promptCategory:g.string({required_error:"Please select a prompt category."}),promptSubcategory:g.string({required_error:"Please select a prompt subcategory."})}),ne="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",_=[],T={allowDangerousHtml:!0},le=/^(https?|ircs?|mailto|xmpp)$/i,ie=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function ce(s){const o=de(s),l=me(s);return ue(o.runSync(o.parse(l),l),s)}function de(s){const o=s.rehypePlugins||_,l=s.remarkPlugins||_,d=s.remarkRehypeOptions?{...s.remarkRehypeOptions,...T}:T;return L().use(D).use(l).use(M,d).use(o)}function me(s){const o=s.children||"",l=new z;return typeof o=="string"&&(l.value=o),l}function ue(s,o){const l=o.allowedElements,d=o.allowElement,i=o.components,m=o.disallowedElements,u=o.skipHtml,y=o.unwrapDisallowed,p=o.urlTransform||pe;for(const t of ie)Object.hasOwn(o,t.from)&&J("Unexpected `"+t.from+"` prop, "+(t.to?"use `"+t.to+"` instead":"remove it")+" (see <"+ne+"#"+t.id+"> for more info)");return K(s,f),B(s,{Fragment:e.Fragment,components:i,ignoreInvalidStyle:!0,jsx:e.jsx,jsxs:e.jsxs,passKeys:!0,passNode:!0});function f(t,n,c){if(t.type==="raw"&&c&&typeof n=="number")return u?c.children.splice(n,1):c.children[n]={type:"text",value:t.value},n;if(t.type==="element"){let r;for(r in j)if(Object.hasOwn(j,r)&&Object.hasOwn(t.properties,r)){const a=t.properties[r],h=j[r];(h===null||h.includes(t.tagName))&&(t.properties[r]=p(String(a||""),r,t))}}if(t.type==="element"){let r=l?!l.includes(t.tagName):m?m.includes(t.tagName):!1;if(!r&&d&&typeof n=="number"&&(r=!d(t,n,c)),r&&c&&typeof n=="number")return y&&t.children?c.children.splice(n,1,...t.children):c.children.splice(n,1),n}}}function pe(s){const o=s.indexOf(":"),l=s.indexOf("?"),d=s.indexOf("#"),i=s.indexOf("/");return o===-1||i!==-1&&o>i||l!==-1&&o>l||d!==-1&&o>d||le.test(s.slice(0,o))?s:""}function fe(){const[s,o]=x.useState(null),[l,d]=x.useState(null),i=X({resolver:Y(ae)}),{data:m,isLoading:u,refetch:y}=W({queryKey:["sonic-brief","prompts"],queryFn:Q,select:r=>r.data}),{mutateAsync:p,isPending:f}=se({mutationKey:["sonic-brief/upload-audio"],mutationFn:async r=>await $(r.audioFile,r.promptCategory,r.promptSubcategory),onSuccess:r=>P.success(`File uploaded successfully! Job ID: ${r.job_id}`),onError:()=>P.error("There was an error uploading your file. Please try again.")}),t=x.useCallback(async r=>{await p(r),i.reset({audioFile:void 0,promptCategory:"",promptSubcategory:""})},[i,p]),n=m==null?void 0:m.find(r=>r.category_id===s),c=n==null?void 0:n.subcategories.find(r=>r.subcategory_id===l);return e.jsx(Z,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(t),className:"space-y-8",children:[e.jsx(b,{control:i.control,name:"audioFile",render:({field:r})=>e.jsxs(w,{children:[e.jsx(S,{children:"Audio File"}),e.jsx(k,{children:e.jsx(ee,{type:"file",accept:"audio/*",onChange:a=>{var F;const h=(F=a.target.files)==null?void 0:F[0];r.onChange(h)}})}),e.jsx(re,{children:"Upload an audio file (no size limit)"}),e.jsx(C,{})]})}),e.jsx(b,{control:i.control,name:"promptCategory",render:({field:r})=>e.jsxs(w,{children:[e.jsx(S,{children:"Prompt Category"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(N,{value:s||"",onValueChange:a=>{r.onChange(a),o(a),d(null),i.setValue("promptSubcategory","")},disabled:u,children:[e.jsx(k,{children:e.jsx(O,{children:e.jsx(E,{placeholder:"Select a category"})})}),e.jsx(U,{children:m==null?void 0:m.map(a=>e.jsx(R,{value:a.category_id,children:a.category_name},a.category_id))})]}),e.jsxs(v,{type:"button",variant:"outline",onClick:()=>y(),disabled:u,children:[e.jsx(oe,{className:"mr-2 h-4 w-4"}),u?"Refreshing...":"Refresh"]})]}),e.jsx(C,{})]})}),e.jsx(b,{control:i.control,name:"promptSubcategory",render:({field:r})=>e.jsxs(w,{children:[e.jsx(S,{children:"Prompt Subcategory"}),e.jsxs(N,{value:l||"",onValueChange:a=>{r.onChange(a),d(a)},disabled:!s,children:[e.jsx(k,{children:e.jsx(O,{children:e.jsx(E,{placeholder:"Select a subcategory"})})}),e.jsx(U,{children:n==null?void 0:n.subcategories.map(a=>e.jsx(R,{value:a.subcategory_id,children:a.subcategory_name},a.subcategory_id))})]}),e.jsx(C,{})]})}),c&&e.jsxs(I,{children:[e.jsxs(A,{children:[e.jsx(V,{className:"font-bold",children:c.subcategory_name}),e.jsx(q,{children:"Prompt details for the selected subcategory"})]}),e.jsx(H,{className:"max-h-60 overflow-auto p-4",children:Object.entries(c.prompts).map(([r,a])=>e.jsxs("div",{className:"mb-4",children:[e.jsx("h4",{className:"text-lg font-semibold",children:r}),e.jsx(ce,{remarkPlugins:[G],children:a})]},r))})]}),e.jsx(v,{type:"submit",disabled:f||!i.formState.isValid,children:f?e.jsx(te,{className:"mr-2 h-4 w-4 animate-spin"}):"Upload and Process"})]})})}const ve=function(){return e.jsxs("div",{className:"flex-1 space-y-4 p-4 pt-6 md:p-8",children:[e.jsx("h2",{className:"text-3xl font-bold tracking-tight",children:"Audio Upload"}),e.jsxs(I,{children:[e.jsxs(A,{children:[e.jsx(V,{children:"Upload Audio File"}),e.jsx(q,{children:"Upload an audio file and select prompts for processing"})]}),e.jsx(H,{children:e.jsx(fe,{})})]})]})};export{ve as component};
