1import{a as e}from"./rolldown-runtime-BEU_UCik.js";import{r}from"./vendor-auth-DAuWozuU.js";import{h as t,m as s,t as n}from"./chunk-62JRHF6Z-D9puh-us.js";import{t as i}from"./index.esm-BEieHnny.js";import{a as o,i as a,n as d,t as l}from"./vendor-query-Ct_3YD9H.js";import{t as c}from"./index.es-BTkwoywu.js";import{On as p,_ as u,cn as m,jn as x,jt as g,tn as b,vn as f}from"./solid-CGJw0jLI.js";import{n as h}from"./dist-C1LyjCEA.js";import{t as j}from"./Loading-XkN6_W9E.js";import{t as y}from"./ErrorDisplay-CSn8m05Q.js";import{t as v}from"./FieldError-7uZChftY.js";import"./FieldError-Ch_lZYe_.js";import{f as w}from"./validation-DxexLepU.js";import{i as N}from"./ConditionEdit-D5oXoH0Y.js";import{t as k}from"./SectionHeader-KYcI_tQ1.js";import{t as C}from"./conditionGroupService-HoeUFf9P.js";var F=e(r()),D=o(),E=({isOpen:e,groupName:r,onClose:t,onConfirm:s,isDeleting:n})=>{const i=(0,F.useRef)(null),o=(0,F.useRef)(null),a=(0,F.useRef)(t),d=(0,F.useRef)(n);if((0,F.useEffect)(()=>{a.current=t,d.current=n},[t,n]),(0,F.useLayoutEffect)(()=>{const r=i.current;if(!r||!e)return;r.open||r.showModal();const t=()=>{a.current()},s=e=>{d.current&&e.preventDefault()};return r.addEventListener("close",t),r.addEventListener("cancel",s),()=>{r.removeEventListener("close",t),r.removeEventListener("cancel",s)}},[e]),!e)return null;return(0,D.jsx)("dialog",{ref:i,className:"w-full max-w-md p-0 dark:bg-[#1f2937] bg-white text-gray-200 border border-gray-700 rounded-lg shadow-2xl overflow-hidden font-sans focus:outline-none backdrop:bg-black/70 backdrop:backdrop-blur-sm animate-in fade-in duration-200",onMouseDown:e=>{o.current=e.target},onClick:e=>{const r=i.current;if(!r||n)return;const t=o.current;if(o.current=null,null!==t&&t!==r)return;if(e.target!==r)return;if(0===e.clientX&&0===e.clientY)return;const s=r.getBoundingClientRect();s.top<=e.clientY&&e.clientY<=s.top+s.height&&s.left<=e.clientX&&e.clientX<=s.left+s.width||r.close()},"data-testid":"delete-group-dialog","aria-labelledby":"delete-group-title",children:(0,D.jsxs)("div",{className:"w-full flex flex-col",children:[(0,D.jsx)("div",{className:"p-6 pb-2",children:(0,D.jsx)("h2",{id:"delete-group-title",className:"text-xl font-semibold dark:text-white text-gray-700 mb-1",children:"Delete Condition Group"})}),(0,D.jsx)("div",{className:"p-6 pt-2 space-y-4",children:(0,D.jsxs)("p",{className:"text-sm dark:text-gray-300 text-gray-700 leading-relaxed",children:["Delete the condition group"," ",(0,D.jsx)("span",{className:"font-bold dark:text-white text-gray-700",children:r}),"? This action"," ",(0,D.jsx)("span",{className:"font-bold dark:text-white text-gray-700",children:"cannot be undone"}),"."]})}),(0,D.jsxs)("div",{className:"p-4 dark:bg-[#374151]/50 bg-white border-t border-gray-700 flex justify-end gap-3",children:[(0,D.jsx)("button",{type:"button",onClick:()=>i.current?.close(),disabled:n,className:"px-4 py-2 dark:bg-[#4b5563] bg-gray-200 dark:hover:bg-[#586376] hover:bg-gray-300 dark:text-white text-gray-700 rounded-md text-sm font-medium transition-colors disabled:opacity-50",children:"Cancel"}),(0,D.jsx)("button",{type:"button",onClick:s,disabled:n,className:"px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-md text-sm font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:n?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(c,{icon:m,spin:!0,className:"text-xs"})," ","Deleting..."]}):"Delete Group"})]})]})})};function G(){const{groupId:e}
1=t(),r=s(),o=a(),[m,G]=(0,F.useState)({name:"",description:""}),[S,_]=(0,F.useState)(!1),R=(0,F.useRef)(!1),{errors:q,validate:I,clearField:L}=w(N),{data:Q,isPending:A,error:K}=d({queryKey:["conditionGroup",e],queryFn:({signal:r})=>C.get(e,r),enabled:!!e});(0,F.useEffect)(()=>{Q&&!R.current&&(R.current=!0,G({name:Q.name||"",description:Q.description||""}))},[Q]);const P=()=>{o.invalidateQueries({queryKey:["conditionGroups"]}),o.invalidateQueries({queryKey:["conditionCategories"]})},{mutate:O,isPending:X}=l({mutationFn:r=>C.update(e,r),onSuccess:r=>{h.success("Condition group updated"),r&&"object"==typeof r&&o.setQueryData(["conditionGroup",e],e=>({...e,...r})),P()},onError:e=>{const r=e?.response?.data?.name,t=Array.isArray(r)?r[0]:r;h.error(t||"Failed to update condition group")},retry:!1}),{mutate:Y,isPending:B}=l({mutationFn:()=>C.generateDescription(e),onSuccess:e=>{G(r=>({...r,description:e?.description||""})),L("description")},onError:e=>{h.error(e?.response?.data?.detail||"Failed to generate a description")},retry:!1}),{mutate:H,isPending:M}=l({mutationFn:()=>C.remove(e),onSuccess:()=>{h.success("Condition group deleted"),o.removeQueries({queryKey:["conditionGroup",e]}
1),P(),r("/condition-groups",{replace:!0})},onError:e=>{_(!1),h.error(e?.response?.data?.detail||"Failed to delete condition group")},retry:!1}),z=e=>{const{name:r,value:t}=e.target;G(e=>({...e,[r]:t})),L(r)},J=(Q?.condition_count??0)>0;return A?(0,D.jsx)(j,{}):K?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(i,{children:(0,D.jsx)("title",{children:"Condition Group Settings | Idea Evolver"})}),(0,D.jsx)(y,{error:K})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(i,{children:(0,D.jsx)("title",{children:`${Q?.name||"Condition Group"} Settings | Idea Evolver`})}),(0,D.jsx)("div",{className:"admin-page cluster-edit page-base "+(X?"animate-pulse":""),children:(0,D.jsxs)("form",{onSubmit:e=>{e.preventDefault();const r=I(m);r&&O({name:r.name,description:r.description})},className:"space-y-4 flex flex-col",children:[(0,D.jsxs)("div",{children:[(0,D.jsxs)("h1",{className:"flex items-center gap-2 text-2xl text-deep-space dark:text-[#C0D7ED] font-bold mb-4",children:[Q?.name||"Condition Group"," Settings"]}),(0,D.jsxs)("section",{className:"page-section-3 p-4",children:[(0,D.jsx)(k,{title:"General Info",icon:g}),(0,D.jsxs)("div",{className:"p-4 pt-0 flex flex-col gap-4",children:[(0,D.jsxs)("div",{className:"form-group w-full flex flex-col",children:[(0,D.jsx)("label",{className:"form-label",htmlFor:"name",children:"Name"}),(0,D.jsx)("input",{className:"py-2 px-4 rounded text-lg",type:"text",id:"name",name:"name",value:m.name,onChange:z,autoCorrect:"off",autoComplete:"off","data-1p-ignore":!0,"aria-invalid":!!q.name||void 0,"aria-describedby":q.name?"name-error":void 0}),(0,D.jsx)(v,{id:"name-error",error:q.name})]}),(0,D.jsxs)("div",{className:"form-group w-full flex flex-col",children:[(0,D.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,D.jsx)("label",{className:"form-label !mb-0",htmlFor:"description",children:"Description"}),(0,D.jsx)("button",{type:"button",onClick:()=>Y(),disabled:B,className:"py-1 px-2 my-0.5 mr-1.5 rounded text-[10px] font-bold uppercase tracking-widest text-solar-700 dark:text-blue-400 hover:bg-solar-600/10 dark:hover:bg-trusty-blue/15 focus:outline-none focus-visible:ring-2 focus-visible:ring-solar-600 dark:focus-visible:ring-trusty-blue transition flex items-center gap-2 disabled:opacity-60 disabled:cursor-not-allowed",children:B?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(c,{icon:u,className:"animate-spin"}),(0,D.jsx)("span",{children:"Generating..."})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(c,{icon:p}),(0,D.jsx)("span",{children:"Generate with AI"})]})})]}),(0,D.jsx)("textarea",{className:"py-2 px-4 rounded text-lg resize-none",id:"description",name:"description",rows:5,value:m.description,onChange:z,placeholder:"Describe this condition group, or generate a draft with AI",disabled:B,"aria-invalid":!!q.description||void 0,"aria-describedby":q.description?"description-error":void 0}),(0,D.jsx)(v,{id:"description-error",error:q.description})]})]})]})]}),(0,D.jsxs)("div",{className:"flex flex-col md:flex-row md:justify-between gap-3",children:[(0,D.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,D.jsxs)("button",{type:"button",onClick:()=>_(!0),disabled:M||J,"aria-describedby":J?"delete-help":void 0,className:"px-4 py-2 bg-transparent border border-red-500/40 rounded-lg text-xs font-bold uppercase tracking-widest text-red-600 dark:text-red-400 hover:bg-red-600 hover:text-white hover:border-red-600 transition flex items-center gap-2 disabled:opacity-40 disabled:cursor-not-allowed w-fit",children:[(0,D.jsx)(c,{icon:f}),(0,D.jsx)("span",{children:"Delete Group"})]}),J&&(0,D.jsxs)("p",{id:"delete-help",className:"text-xs text-deep-space/70 dark:text-gray-400",children:["Reassign this group's ",Q.condition_count," ",1===Q.condition_count?"condition":"conditions"," ","before deleting it."]})]}),(0,D.jsxs)("div",{className:"flex justify-end gap-3",children:[(0,D.jsxs)(n,{to:"/condition-groups",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,D.jsx)(c,{icon:x}),(0,D.jsx)("span",{children:"Cancel"})]}),(0,D.jsx)("button",{type:"submit",disabled:X,className:"px-6 py-2 bg-solar-600 dar
1k: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:X?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(c,{icon:u,className:"animate-spin"}),(0,D.jsx)("span",{children:"Saving..."})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(c,{icon:b}),(0,D.jsx)("span",{children:"Save Changes"})]})})]})]})]})}),(0,D.jsx)(E,{isOpen:S,groupName:Q?.name,onClose:()=>_(!1),onConfirm:()=>H(),isDeleting:M})]})}export{G 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.