1import{a as e}from"./rolldown-runtime-BEU_UCik.js";import{n as r,r as t}from"./vendor-auth-DAuWozuU.js";import{h as o,t as a}from"./chunk-62JRHF6Z-D9puh-us.js";import{t as s}from"./index.esm-BEieHnny.js";import{a as n,i,n as l}from"./vendor-query-Ct_3YD9H.js";import{n as d}from"./axiosInstance-DrZDrJAX.js";import{t as c}from"./index.es-BTkwoywu.js";import{n as m}from"./LeaderboardContext-9wS7-paG.js";import{n as u}from"./ThemeManager-ILkyB1Q0.js";import{t as p}from"./clsx-BUm1h715.js";import{At as g,Ft as f,Mn as x,_ as h,mn as y,nn as j}from"./solid-CofuJNaU.js";import{h as b,ht as v}from"./free-solid-svg-icons-BD_SwYKY.js";import{n as w}from"./dist-C1LyjCEA.js";import{t as k}from"./conditionService-7pRn7dab.js";import{t as N}from"./spinner-f5EoijQJ.js";import{t as _}from"./Loading-XkN6_W9E.js";import{t as C}from"./ErrorDisplay-wA_eppWS.js";import{t as F}from"./ParticleField-DD4MFwoQ.js";import{t as E}from"./FieldError-7uZChftY.js";import"./FieldError-Ch_lZYe_.js";import{t as S}from"./KeywordField-B-Isio6O.js";import{f as R}from"./validation-DxexLepU.js";import{n as K}from"./ConditionEdit-D5oXoH0Y.js";import{t as q}from"./SectionHeader-KYcI_tQ1.js";import{t as A}from"./getAuthHeaders-DG_TIw8t.js";/* empty css */var I=e(t());var T=n();function D({onClose:e,onRegen:r,prompt:t}){const[o,a]=(0,I.useState)(t||""),s=(0,I.useRef)(null),n=(0,I.useRef)(null),i=(0,I.useRef)(e);(0,I.useEffect)(()=>{i.current=e},[e]);(0,I.useLayoutEffect)(()=>{const e=s.current;if(!e)return;e.open||e.showModal();const r=()=>{i.current()};return e.addEventListener("close",r),()=>{e.removeEventListener("close",r)}},[]);return(0,T.jsxs)("dialog",{ref:s,className:"max-h-[85vh] w-[calc(100%-2rem)] md:w-4/6 mx-auto flex flex-col overflow-hidden bg-white dark:bg-[#010011] rounded-lg border-0 p-0 shadow-2xl focus:outline-none backdrop:bg-black/75 backdrop:backdrop-blur-sm animate-in fade-in duration-200",onMouseDown:e=>{n.current=e.target},onClick:e=>{const r=s.current;if(!r)return;const t=n.current;if(n.current=null,null!==t&&t!==r)return;if(e.target!==r)return;if(0===e.clientX&&0===e.clientY)return;const o=r.getBoundingClientRect();o.top<=e.clientY&&e.clientY<=o.top+o.height&&o.left<=e.clientX&&e.clientX<=o.left+o.width||r.close()},"data-testid":"regen-modal-backdrop","aria-labelledby":"image-gen-modal-title",children:[(0,T.jsx)("button",{type:"button",className:"absolute top-4 right-4 h-8 w-8 text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300 text-2xl transition-colors focus:outline-none",onClick:()=>s.current?.close(),"aria-label":"Close Modal",children:"Ã"}),(0,T.jsxs)("div",{className:"page-section-3 w-full flex flex-col overflow-hidden",children:[(0,T.jsx)("h2",{id:"image-gen-modal-title",className:"section-header-2",children:"Regenerate Image"}),(0,T.jsxs)("div",{className:"p-4 pt-0 flex flex-col gap-4 flex-1 overflow-y-auto",children:[(0,T.jsx)("label",{className:"sr-only",htmlFor:"prompt",children:"Prompt"}),(0,T.jsx)("textarea",{name:"prompt",id:"prompt",className:"p-4 form-group flex-1 resize-none",rows:"10",placeholder:"Enter a new prompt to regenerate the image",value:o,onChange:e=>a(e.target.value)}),(0,T.jsx)("button",{type:"button",className:"px-4 py-2 rounded self-end grad-btn primary",onClick:async()=>{await r(o),s.current?.close()},children:"Regenerate"})]})]})]})}function G({src:e,className:t,imgClassName:o,conditionId:a,prompt:s}){const{refetch:n}=m(),{theme:i}=u(),[l,g]=(0,I.useState)(s||""),[f,x]=(0,I.useState)(!1);(0,I.useEffect)(()=>{g(s||"")},[s]);const{frames:h,setFrames:y,loading:j,imageError:w,regen:k,cancelRef:_}=function({conditionId:e,onSuccess:t}){const{getAccessTokenSilently:o}=r(),[a,s]=(0,I.useState)([]),[n,i]=(0,I.useState)(!1),[l,c]=(0,I.useState)(null),m=(0,I.useRef)(null);return{frames:a,setFrames:s,loading:n,imageError:l,resetError:function(){c(null)},regen:function(r){m.current?.(),c(null),i(!0),s([{index:0,image:null,type:"initial"}]);let a=!1;const n=new AbortController,l=`${d()}/condition/${e}/regenerate/`;function u(){a=!0,n.abort()}return(async()=>{try{const e=await A(o);if(a)return;const d=await fetch(l,{method:"POST",headers:e,body:JSON.stringify({prompt:r}),signal:n.signal});if(!d.ok)throw new Error(`Image stream error: ${d.status}`);const m=d.body.getReader(),u=new TextDecoder;let p="";for(;!a;){const{done:e,value:r}=await m.read();if(e||a)break;p+=u.decode(r,{stream:!0});const o=p.split("\n");p=o.pop();for(const n of o)if(n.startsWith("data:"))try{const e=JSON.parse(n.replace(/^data:\s*/,""));if("failure"===e.type)return c(new Error(e.openai_response||"Unknown error")),void i(!1);e.image&&!a&&s(r=>[...r,{index:e.index,image:e.image,type:e.type}]),"final"===e.type&&(i(!1),a||t?.())}catch{}}}catch(e){"AbortError"===e.name||a||(c(e),i(!1))}})(),m.current=u,u},cancelRef:m}}({conditionId:a,onSuccess:n});(0,I.useEffect)(()=>()=>_.current?.(),[_]);const C=h[h.length-1]??{},E=C.image||e||null,S="final"===C.type;return(0,I.useEffect)(()=>{S||y(r=>{if(0===r.length)return e?r:[{index:0,image:null,type:"initial"}];const t=[...r];return"initial"===t[t.length-1]?.type&&(t[t.length-1]={...t[t.length-1],image:null}),t})},[S]),(0,I.useEffect)(()=>{e&&y(e=>1===e.length&&"initial"===e[0].type?[]:e)},[e]),w?(0,T.jsx)("div",{className:"md:row-span-full text-center bg-black/50 text-red-500 aspect-square w-full md:h-[212px] md:w-[212px] p-4 border border-red-500 rounded rounded-br-lg grid place-items-center",children:(0,T.jsxs)("div",{className:"space-y-4",children:[(0,T.jsx)(c,{icon:v,size:"2xl"}),(0,T.jsx)("h3",{className:"font-bold",children:"Failed to load image stream"}),(0,T.jsx)("p",{className:"font-mono",children:w.message||C.openai_response||"An unknown error occurred."})]})}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)("div",{className:p("relative",t),children:[E?(0,T.jsx)("img",{className:o,src:E,alt:`Generated image for condition ${a}`},E):(0,T.jsx)(F,{className:o}),(0,T.jsx)("button",{type:"button",className:p("regen text-black",j?"pointer-events-none":"pointer-events-auto"),onClick:()=>x(!0),disabled:j,children:j?(0,T.jsx)("img",{src:N,alt:"Loading...",className:"hx4 w-4 invert"}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(c,{icon:b,size:"xs"}),(0,T.jsx)("span",{children:"Generate image"})]})})]}),f&&(0,T.jsx)(D,{onClose:()=>x(!1),onRegen:function(e){g(e),k(e)},prompt:l})]})}var $=async({queryKey:e,signal:r})=>{const[,t]=e;return k.get(t,r)},L=async({signal:e})=>await k.getCategories(e)||[];function M(){const{conditionId:e}=o(),r=i(),{condition:t,loading:n,error:d}=(e=>{const{data:r,error:t,isPending:o}=l({queryKey:["adminCondition",e],queryFn:$,enabled:!!e,staleTime:3e4,gcTime:3e5});return{condition:r,loading:o&&!!e,error:t??null}})(e),{categories:m,loading:u,error:p}=(()=>{const{data:e,error:r,isPending:t}=l({queryKey:["conditionCategories"],queryFn:L,gcTime:6e5});return{categories:e??[],loading:t,error:r??null}})(),b=p?"Failed to load condition groups":void 0,[v,N]=(0,I.useState)(!1),{errors:F,validate:A,clearField:D}=R(K),[M,Q]=(0,I.useState)({name:"",alt_keywords:[],root_keywords:[],negative_words:[],category:"",image:null,fileToUpload:null,
1scheduled_refresh:"never"}),B=m.some(e=>e.uuid===M.category);(0,I.useEffect)(()=>{t&&Q({name:t.name||"",image:t.image||"",alt_keywords:(t.alt_keywords||[]).filter(Boolean),root_keywords:(t.root_keywords||[]).filter(Boolean),negative_words:(t.negative_words||[]).filter(Boolean),category:t.condition_category||"",scheduled_refresh:t.scheduled_refresh||"never"})},[t]);const P=e=>{const{name:r,value:t}=e.target;Q(e=>({...e,[r]:t})),D(r)},z=(e,r)=>{r.trim()&&Q(t=>{const o=t[e]||[],a=r.trim().toLowerCase();return o.some(e=>e.toLowerCase()===a)?t:{...t,[e]:[...o,r.trim()]}})},U=(e,r)=>{Q(t=>({...t,[e]:t[e].filter((e,t)=>t!==r)}))};return n?(0,T.jsx)(_,{}):d?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(s,{children:(0,T.jsx)("title",{children:"Edit Condition | Genti"})}),(0,T.jsx)(C,{error:d})]}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(s,{children:(0,T.jsx)("title",{children:`${t?.name||"Condition"} Condition Settings | Genti`})}),(0,T.jsx)("div",{className:"admin-page cluster-edit page-base "+(v?"animate-pulse":""),children:(0,T.jsxs)("form",{onSubmit:async o=>{o.preventDefault();const a=A(M);if(!a)return;N(!0);const s=new FormData;s.append("name",a.name),a.acronym&&s.append("acronym",a.acronym),["alt_keywords","root_keywords","negative_words"].forEach(e=>{const r=a[e]||[];r.length>0?r.forEach(r=>s.append(e,r)):s.append(e,"")}),M.fileToUpload instanceof File&&s.append("image",M.fileToUpload),s.append("condition_category",a.category),s.append("scheduled_refresh",a.scheduled_refresh);try{await k.update(t.uuid,s,{headers:{"Content-Type":"multipart/form-data"}}),w.success("Condition updated successfully"),r.invalidateQueries({queryKey:["adminCondition",e]}
1),r.invalidateQueries({queryKey:["condition",e]}),r.invalidateQueries({queryKey:["conditionGroups"]}),r.invalidateQueries({queryKey:["conditionGroup"]}),r.invalidateQueries({queryKey:["conditionGroupDrugs"]})}catch(n){console.error("Error updating condition:",n),w.error("Failed to update condition")}finally{N(!1)}},className:"space-y-4 flex flex-col",children:[(0,T.jsxs)("div",{children:[(0,T.jsxs)("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between gap-4 mb-6",children:[(0,T.jsxs)("h1",{className:"flex items-center gap-2 text-2xl text-deep-space dark:text-[#C0D7ED] font-bold",children:[t?.name||"Condition"," Condition Settings"]}),(0,T.jsxs)(a,{to:`/watchlist/${e}`,className:"px-4 py-2 bg-transparent border border-solar-300 dark:border-trusty-blue/50 rounded-lg text-xs font-bold uppercase tracking-widest text-deep-space dark:text-white hover:bg-solar-600 hover:text-white hover:border-solar-600 dark:hover:bg-trusty-blue dark:hover:border-trusty-blue transition flex items-center gap-2 no-underline w-fit",children:[(0,T.jsx)(c,{icon:f}),(0,T.jsx)("span",{children:"Watchlist"})]})]}),(0,T.jsxs)("section",{className:"page-section-3 p-4",children:[(0,T.jsx)(q,{title:"General Info",icon:g}),(0,T.jsxs)("div",{className:"p-4 pt-0 grid md:grid-cols-[228px_1fr] gap-4",children:[(0,T.jsx)(G,{className:"md:col-start-1 md:row-span-2 self-start rounded overflow-hidden",imgClassName:"w-full aspect-square object-cover",src:M.image,conditionId:e,prompt:t.image_prompt}),(0,T.jsxs)("div",{className:"form-group w-full flex flex-col md:col-start-2",children:[(0,T.jsx)("label",{className:"form-label",htmlFor:"name",children:"Name"}),(0,T.jsx)("input",{className:"py-2 px-4 rounded text-lg",type:"text",id:"name",name:"name",value:M.name,onChange:P,autoCorrect:"off",autoComplete:"off","data-1p-ignore":!0,"aria-invalid":!!F.name||void 0,"aria-describedby":F.name?"name-error":void 0}),(0,T.jsx)(E,{id:"name-error",error:F.name})]}),(0,T.jsxs)("div",{className:"w-full md:col-start-2 grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,T.jsxs)("div",{className:"form-group flex flex-col",children:[(0,T.jsx)("label",{className:"form-label",htmlFor:"category",children:"Condition Group"}
1),(0,T.jsxs)("select",{className:"min-h-[60px] py-2 px-4 rounded text-lg",id:"category",name:"category",value:M.category,onChange:P,disabled:u||!!b,"aria-describedby":b?"category-error":void 0,children:[(0,T.jsx)("option",{value:"",children:u?"Loading groups...":"No Group"}),M.category&&!B&&(0,T.jsx)("option",{value:M.category,children:"Current group"}),m.map(e=>(0,T.jsx)("option",{value:e.uuid,children:e.name},e.uuid))]}),(0,T.jsx)(E,{id:"category-error",error:b})]}),(0,T.jsxs)("div",{className:"form-group flex flex-col",children:[(0,T.jsx)("label",{className:"form-label",htmlFor:"scheduled_refresh",children:"Scheduled Refresh"}),(0,T.jsx)("select",{className:"min-h-[60px] py-2 px-4 rounded text-lg",id:"scheduled_refresh",name:"scheduled_refresh",value:M.scheduled_refresh,onChange:P,children:[{value:"never",label:"Never"},{value:"yearly",label:"Yearly"},{value:"quarterly",label:"Quarterly"},{value:"monthly",label:"Monthly"},{value:"weekly",label:"Weekly"},{value:"daily",label:"Daily"}].map(e=>(0,T.jsx)("option",{value:e.value,children:e.label},e.value))})]})]})]})]})]}),(0,T.jsxs)("section",{className:"page-section-3 p-4",children:[(0,T.jsx)(q,{title:"Keywords",icon:y}),(0,T.jsxs)("div",{className:"p-4 flex flex-col gap-4",children:[(0,T.jsx)(S,{label:"Alternate Names (50k keywords)",placeholder:"Add Alternate Names",list:M.alt_keywords||[],type:"alt_keywords",onAdd:z,children:M.alt_keywords?.map((e,r)=>(0,T.jsx)(S.KeywordItem,{onRemove:()=>U("alt_keywords",r),children:e},`alt_keywords-${r}`))}),(0,T.jsx)(S,{label:"Root Keywords (5k keywords each)",placeholder:"Add Root Keywords",list:M.root_keywords||[],type:"root_keywords",onAdd:z,children:M.root_keywords?.map((e,r)=>(0,T.jsx)(S.KeywordItem,{onRemove:()=>U("root_keywords",r),children:e},`root_keywords-${r}`))}),(0,T.jsx)(S,{label:"Negative Keywords",placeholder:"Add Top Negative Keyword",list:M.negative_words||[],type:"negative_words",onAdd:z,children:M.negative_words?.map((e,r)=>(0,T.jsx)(S.KeywordItem,{onRemove:()=>U("negative_words",r),children:e},`negative_words-${r}`))})]})]}),(0,T.jsxs)("div",{className:"flex justify-end gap-3",children:[(0,T.jsxs)(a,{to:`/clusters/${e}`,className:"px-4 py-2 bg-transparent border border-solar-300 dark:border-trusty-blue/50 rounded-lg text-xs font-bold uppercase tracking-widest text-deep-space dark:text-white hover:bg-deep-space hover:text-white transition flex items-center gap-2 no-underline",children:[(0,T.jsx)(c,{icon:x}),(0,T.jsx)("span",{children:"Cancel"})]}),(0,T.jsx)("button",{type:"submit",disabled:v,className:"px-6 py-2 bg-solar-600 dark:bg-blue-600 border border-solar-700 dark:border-trusty-blue/50 rounded-lg text-xs text-white font-bold uppercase tracking-widest hover:bg-solar-700 dark:hover:bg-trusty-blue transition shadow-[0_0_15px_rgba(234,88,12,0.3)] dark:shadow-[0_0_15px_rgba(59,130,246,0.4)] disabled:opacity-70 disabled:cursor-not-allowed flex items-center gap-2",children:v?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(c,{icon:h,className:"animate-spin"}),(0,T.jsx)("span",{children:"Saving..."})]}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(c,{icon:j}),(0,T.jsx)("span",{children:"Save Changes"})]})})]})]})})]})}export{M 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.