1import{r as s,m as ee,j as t}from"./index-CWRjl4JA.js";import{S as F,d as i,m as te}from"./search-D5hIV8JX.js";import{a as oe,d as H,G as ie,P as re,D as ne}from"./index-BBZtD5O_.js";import{P as A}from"./plus-Bes0d3Z9.js";import{X as _}from"./x-Bavcg-4I.js";import{T as se}from"./trash-2-COhisFdH.js";import{L as ae}from"./loader-circle-Dp0B0-z9.js";const ce=te(["to{transform:rotate(360deg);}"]),de=i.div.withConfig({displayName:"Backdrop",componentId:"sc-isuu2j-0"})(["position:absolute;inset:0;z-index:999;background:",";backdrop-filter:blur(6px);opacity:",";visibility:",";pointer-events:",";transition:opacity 0.25s ease,visibility 0.25s ease;"],({theme:e})=>e.windowBg,({$isopen:e})=>e?1:0,({$isopen:e})=>e?"visible":"hidden",({$isopen:e})=>e?"auto":"none"),le=i.aside.withConfig({displayName:"PromptLibraryPane",componentId:"sc-isuu2j-1"})(["position:absolute;inset:0 0 0 auto;z-index:1000;width:min(460px,100%);box-sizing:border-box;display:flex;flex-direction:column;overflow:hidden;background:",";color:",";border-left:1px solid ",";box-shadow:",";font-family:",";transform:",";visibility:",";transition:transform 0.3s cubic-bezier(0.4,0,0.2,1),visibility 0.3s ease;*,*::before,*::after{box-sizing:border-box;}@media (max-width:600px){width:100%;border-left:none;}"],({theme:e})=>e.background,({theme:e})=>e.textPrimary,({theme:e})=>e.border,({theme:e})=>e.shadowMd,({theme:e})=>e.fonts.body,({$isopen:e})=>e?"translateX(0)":"translateX(100%)",({$isopen:e})=>e?"visible":"hidden"),pe=i.header.withConfig({displayName:"Header",componentId:"sc-isuu2j-2"})(["flex-shrink:0;display:flex;align-items:flex-start;justify-content:space-between;gap:20px;padding:28px 28px 24px;background:",";border-bottom:1px solid ",";@media (max-width:600px){padding:22px 20px 20px;}"],({theme:e})=>e.background,({theme:e})=>e.border),me=i.div.withConfig({displayName:"HeaderCopy",componentId:"sc-isuu2j-3"})(["min-width:0;"]),xe=i.div.withConfig({displayName:"Eyebrow",componentId:"sc-isuu2j-4"})(["display:flex;align-items:center;gap:7px;margin-bottom:8px;color:",";font-size:11px;font-weight:650;letter-spacing:0.12em;text-transform:uppercase;svg{width:14px;height:14px;}"],({theme:e})=>e.accent),ue=i.h2.withConfig({displayName:"Title",componentId:"sc-isuu2j-5"})(["margin:0;color:",";font-family:",";font-size:29px;font-weight:600;line-height:1.1;letter-spacing:-0.02em;"],({theme:e})=>e.textPrimary,({theme:e})=>e.fonts.heading),he=i.p.withConfig({displayName:"Subtitle",componentId:"sc-isuu2j-6"})(["max-width:280px;margin:8px 0 0;color:",";font-size:13px;line-height:1.55;"],({theme:e})=>e.textSecondary),ge=i.div.withConfig({displayName:"HeaderActions",componentId:"sc-isuu2j-7"})(["display:flex;align-items:center;gap:8px;flex-shrink:0;"]),fe=i.button.withConfig({displayName:"IconButton",componentId:"sc-isuu2j-8"})(["width:36px;height:36px;display:inline-flex;align-items:center;justify-content:center;padding:0;background:transparent;color:",";border:1px solid transparent;border-radius:8px;cursor:pointer;transition:color 0.2s ease,background 0.2s ease,border-color 0.2s ease;svg{width:18px;height:18px;}&:hover{color:",";background:",";border-color:",";}&:focus-visible{outline:2px solid ",";outline-offset:2px;}"],({theme:e})=>e.textSecondary,({theme:e})=>e.textPrimary,({theme:e})=>e.buttonSecondaryHoverBg,({theme:e})=>e.border,({theme:e})=>e.accent),be=i.button.withConfig({displayName:"NewPromptButton",componentId:"sc-isuu2j-9"})(["height:36px;display:inline-flex;align-items:center;justify-content:center;gap:7px;padding:0 13px;background:",";color:",";border:1px solid ",";border-radius:8px;cursor:pointer;font-family:inherit;font-size:13px;font-weight:600;transition:background 0.2s ease,border-color 0.2s ease,transform 0.2s ease;svg{width:16px;height:16px;}&:hover{background:",";border-color:",";}&:active{transform:translateY(1px);}&:focus-visible{outline:2px solid ",";outline-offset:2px;}@media (max-width:440px){width:36px;padding:0;span{display:none;}}"],({theme:e})=>e.accentGradient,({theme:e})=>e.btnPrimaryText,({theme:e})=>e.accent,({theme:e})=>e.accentDark,({theme:e})=>e.accentDark,({theme:e})=>e.accent),ye=i.div.withConfig({displayName:"ScrollArea",componentId:"sc-isuu2j-10"})(["flex:1;min-height:0;overflow-y:auto;overscroll-behavior:contain;scrollbar-width:thin;scrollbar-color:"," transparent;&::-webkit-scrollbar{width:7px;}&::-webkit-scrollbar-track{background:transparent;}&::-webkit-scrollbar-thumb{background:",";border-radius:999px;}"],({theme:e})=>e.borderHover,({theme:e})=>e.borderHover),we=i.form.withConfig({displayName:"Composer",componentId:"sc-isuu2j-11"})(["padding:24px 28px 26px;background:",";border-bottom:1px solid ",";@media (max-width:600px){padding:22px 20px 24px;}"],({theme:e})=>e.surface,({theme:e})=>e.border),je=i.div.withConfig({displayName:"ComposerHeader",componentId:"sc-isuu2j-12"})(["margin-bottom:22px;"]),ve=i.h3.withConfig({displayName:"ComposerTitle",componentId:"sc-isuu2j-13"})(["margin:0;color:",";font-size:15px;font-weight:650;"],({theme:e})=>e.textPrimary),Ce=i.p.withConfig({displayName:"ComposerDescription",componentId:"sc-isuu2j-14"})(["margin:5px 0 0;color:",";font-size:12px;line-height:1.5;"],({theme:e})=>e.textSecondary),R=i.label.withConfig({displayName:"Field",componentId:"sc-isuu2j-15"})(["display:block;& + &{margin-top:22px;}"]),G=i.span.withConfig({displayName:"FieldLabel",componentId:"sc-isuu2j-16"})(["display:block;margin-bottom:7px;color:",";font-size:11px;font-weight:650;letter-spacing:0.08em;text-transform:uppercase;"],({theme:e})=>e.textSecondary),ke=i.input.withConfig({displayName:"Input",componentId:"sc-isuu2j-17"})(["width:100%;padding:4px 0 10px;background:transparent;color:",";caret-color:",";border:none;border-bottom:1px solid ",";border-radius:0;font-family:inherit;font-size:15px;line-height:1.5;transition:border-color 0.2s ease;&::placeholder{color:",";}&:hover{border-color:",";}&:focus{outline:none;border-color:",";}"],({theme:e})=>e.textPrimary,({theme:e})=>e.accent,({theme:e})=>e.border,({theme:e})=>e.textTertiary,({theme:e})=>e.borderHover,({theme:e})=>e.accent),Ie=i.textarea.withConfig({displayName:"Textarea",componentId:"sc-isuu2j-18"})(["width:100%;min-height:112px;padding:4px 0 10px;resize:vertical;background:transparent;color:",";caret-color:",";border:none;border-bottom:1px solid ",";border-radius:0;font-family:inherit;font-size:14px;line-height:1.65;transition:border-color 0.2s ease;&::placeholder{color:",";}&:hover{border-color:",";}&:focus{outline:none;border-color:",";}"],({theme:e})=>e.textPrimary,({theme:e})=>e.accent,({theme:e})=>e.border,({theme:e})=>e.textTertiary,({theme:e})=>e.borderHover,({theme:e})=>e.accent),K=i.div.withConfig({displayName:"FieldFooter",componentId:"sc-isuu2j-19"})(["display:flex;justify-content:flex-end;margin-top:7px;"]),M=i.span.withConfig({displayName:"CharacterCount",componentId:"sc-isuu2j-20"})(["color:",";font-size:11px;"],({theme:e})=>e.textTertiary),Se=i.p.withConfig({displayName:"FormError",componentId:"sc-isuu2j-21"})(["margin:16px 0 0;color:",";font-size:12px;line-height:1.5;"],({theme:e})=>e.danger),Ne=i.div.withConfig({displayName:"ComposerActions",componentId:"sc-isuu2j-22"})(["display:flex;justify-content:flex-end;
1gap:10px;margin-top:22px;"]),Pe=i.button.withConfig({displayName:"SecondaryButton",componentId:"sc-isuu2j-23"})(["min-height:36px;padding:0 14px;background:transparent;color:",";border:1px solid ",";border-radius:8px;cursor:pointer;font-family:inherit;font-size:13px;font-weight:550;transition:color 0.2s ease,background 0.2s ease,border-color 0.2s ease;&:hover{color:",";background:",";border-color:",";}&:focus-visible{outline:2px solid ",";outline-offset:2px;}"],({theme:e})=>e.textSecondary,({theme:e})=>e.border,({theme:e})=>e.textPrimary,({theme:e})=>e.buttonSecondaryHoverBg,({theme:e})=>e.borderHover,({theme:e})=>e.accent),Te=i.button.withConfig({displayName:"PrimaryButton",componentId:"sc-isuu2j-24"})(["min-height:36px;display:inline-flex;align-items:center;justify-content:center;gap:7px;padding:0 15px;background:",";color:",";border:1px solid ",";border-radius:8px;cursor:pointer;font-family:inherit;font-size:13px;font-weight:650;transition:background 0.2s ease,border-color 0.2s ease,opacity 0.2s ease;svg{width:15px;height:15px;}&:hover:not(:disabled){background:",";border-color:",";}&:disabled{cursor:not-allowed;opacity:0.5;}&:focus-visible{outline:2px solid ",";outline-offset:2px;}"],({theme:e})=>e.accentGradient,({theme:e})=>e.btnPrimaryText,({theme:e})=>e.accent,({theme:e})=>e.accentDark,({theme:e})=>e.accentDark,({theme:e})=>e.accent),Le=i.div.withConfig({displayName:"SearchRegion",componentId:"sc-isuu2j-25"})(["padding:20px 28px 0;@media (max-width:600px){padding:18px 20px 0;}"]),ze=i.div.withConfig({displayName:"SearchLine",componentId:"sc-isuu2j-26"})(["display:flex;align-items:center;gap:10px;padding-bottom:11px;border-bottom:1px solid ",";color:",";transition:color 0.2s ease,border-color 0.2s ease;svg{width:17px;height:17px;flex-shrink:0;}&:focus-within{color:",";border-color:",";}"],({theme:e})=>e.border,({theme:e})=>e.textSecondary,({theme:e})=>e.accent,({theme:e})=>e.accent),Be=i.input.withConfig({displayName:"SearchInput",componentId:"sc-isuu2j-27"})(["width:100%;min-width:0;padding:0;background:transparent;color:",";caret-color:",";border:none;font-family:inherit;font-size:14px;&::placeholder{color:",";}&:focus{outline:none;}"],({theme:e})=>e.textPrimary,({theme:e})=>e.accent,({theme:e})=>e.textTertiary),Ee=i.button.withConfig({displayName:"ClearSearchButton",componentId:"sc-isuu2j-28"})(["display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;padding:3px;background:transparent;color:",";border:none;border-radius:4px;cursor:pointer;svg{width:15px;height:15px;}&:hover{color:",";}&:focus-visible{outline:2px solid ",";outline-offset:2px;}"],({theme:e})=>e.textTertiary,({theme:e})=>e.textPrimary,({theme:e})=>e.accent),De=i.div.withConfig({displayName:"ListHeading",componentId:"sc-isuu2j-29"})(["display:flex;align-items:baseline;justify-content:space-between;gap:16px;padding:24px 28px 12px;@media (max-width:600px){padding:22px 20px 12px;}"]),Fe=i.h3.withConfig({displayName:"ListTitle",componentId:"sc-isuu2j-30"})(["margin:0;color:",";font-size:13px;font-weight:650;letter-spacing:0.02em;"],({theme:e})=>e.textPrimary),He=i.span.withConfig({displayName:"PromptCount",componentId:"sc-isuu2j-31"})(["flex-shrink:0;color:",";font-size:12px;"],({theme:e})=>e.textTertiary),Ae=i.ul.withConfig({displayName:"PromptList",componentId:"sc-isuu2j-32"})(["list-style:none;padding:0;margin:0;"]),_e=i.li.withConfig({displayName:"PromptRow",componentId:"sc-isuu2j-33"})(["display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;border-top:1px solid ",";transition:background 0.2s ease;&:hover,&:focus-within{background:",";}&:last-child{border-bottom:1px solid ",";}"],({theme:e})=>e.border,({theme:e})=>e.buttonSecondaryHoverBg,({theme:e})=>e.border),Re=i.button.withConfig({displayName:"PromptSelectButton",componentId:"sc-isuu2j-34"})(["min-width:0;display:block;padding:17px 12px 17px 28px;background:transparent;color:inherit;border:none;cursor:pointer;text-align:left;@media (max-width:600px){padding-left:20px;}&:focus{outline:none;}&:focus-visible{outline:2px solid ",";outline-offset:-2px;}"],({theme:e})=>e.accent),Ge=i.span.withConfig({displayName:"PromptName",componentId:"sc-isuu2j-35"})(["display:block;overflow:hidden;margin-bottom:5px;color:",";font-size:14px;font-weight:600;line-height:1.35;text-overflow:ellipsis;white-space:nowrap;"],({theme:e})=>e.textPrimary),Ke=i.span.withConfig({displayName:"PromptPreview",componentId:"sc-isuu2j-36"})(["display:-webkit-box;overflow:hidden;color:",";font-size:12px;font-weight:400;line-height:1.5;-webkit-box-orient:vertical;-webkit-line-clamp:2;"],({theme:e})=>e.textSecondary),Me=i.button.withConfig({displayName:"DeleteButton",componentId:"sc-isuu2j-37"})(["width:36px;height:36px;display:inline-flex;align-items:center;justify-content:center;margin-right:18px;padding:0;background:transparent;color:",";border:1px solid transparent;border-radius:7px;cursor:pointer;transition:color 0.2s ease,background 0.2s ease,border-color 0.2s ease,opacity 0.2s ease;svg{width:16px;height:16px;}&:hover:not(:disabled){color:",";background:",";border-color:",";}
1&:disabled{cursor:not-allowed;opacity:0.5;}&:focus-visible{outline:2px solid ",";outline-offset:2px;}@media (max-width:600px){margin-right:12px;}"],({theme:e})=>e.textTertiary,({theme:e})=>e.danger,({theme:e})=>e.buttonSecondaryBg,({theme:e})=>e.border,({theme:e})=>e.danger),C=i(ae).withConfig({displayName:"LoaderIcon",componentId:"sc-isuu2j-38"})(["animation:"," 0.8s linear infinite;"],ce),$=i.div.withConfig({displayName:"StateContainer",componentId:"sc-isuu2j-39"})(["display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:260px;padding:48px 28px;text-align:center;"]),U=i.div.withConfig({displayName:"StateIcon",componentId:"sc-isuu2j-40"})(["display:flex;align-items:center;justify-content:center;margin-bottom:16px;color:",";svg{width:26px;height:26px;}"],({theme:e})=>e.textTertiary),X=i.h4.withConfig({displayName:"StateTitle",componentId:"sc-isuu2j-41"})(["margin:0;color:",";font-size:14px;font-weight:650;"],({theme:e})=>e.textPrimary),$e=i.p.withConfig({displayName:"StateDescription",componentId:"sc-isuu2j-42"})(["max-width:270px;margin:7px 0 0;color:",";font-size:12px;line-height:1.6;"],({theme:e})=>e.textSecondary),Ue=i.div.withConfig({displayName:"ErrorMessage",componentId:"sc-isuu2j-43"})(["margin:18px 28px 0;padding:12px 0;color:",";border-bottom:1px solid ",";font-size:12px;line-height:1.5;@media (max-width:600px){margin-right:20px;margin-left:20px;}"],({theme:e})=>e.danger,({theme:e})=>e.border),Xe=i.footer.withConfig({displayName:"Footer",componentId:"sc-isuu2j-44"})(["flex-shrink:0;padding:13px 28px;background:",";color:",";border-top:1px solid ",";font-size:11px;line-height:1.5;@media (max-width:600px){padding-right:20px;padding-left:20px;}"],({theme:e})=>e.background,({theme:e})=>e.textTertiary,({theme:e})=>e.border),Oe=({isOpen:e,onClose:l,onSelectPrompt:y})=>{const{supabase:m}=oe(),k=s.useRef(null),[w,j]=s.useState([]),[x,I]=s.useState(""),[u,S]=s.useState(""),[c,N]=s.useState(""),[p,h]=s.useState(!1),[V,P]=s.useState(!1),[d,T]=s.useState(!1),[v,L]=s.useState(null),[z,g]=s.useState(""),[B,f]=s.useState("");s.useEffect(()=>{if(!e)return;let o=!0;return(async()=>{P(!0),g("");try{const a=await ie(m,"/prompt_library");o&&j(Array.isArray(a==null?void 0:a.prompts)?a.prompts:[])}catch(a){console.error("Failed to fetch prompt library:",a),o&&g("The prompt library could not be loaded. Please try again.")}finally{o&&P(!1)}})(),()=>{o=!1}},[e,m]),s.useEffect(()=>{if(!e)return;const o=document.getElementById("layout-content"),r=o.style.overflow;return o.style.overflow="hidden",()=>{o.style.overflow=r}},[e]),s.useEffect(()=>{if(!e)return;const o=r=>{r.key==="Escape"&&(p?h(!1):l==null||l())};return window.addEventListener("keydown",o),()=>{window.removeEventListener("keydown",o)}},[e,p,l]),s.useEffect(()=>{if(!p)return;const o=window.setTimeout(()=>{var r;(r=k.current)==null||r.focus()},100);return()=>window.clearTimeout(o)},[p]);const b=s.useMemo(()=>{const o=c.trim().toLowerCase();return o?w.filter(r=>{const a=String((r==null?void 0:r.name)||"").toLowerCase(),n=String((r==null?void 0:r.content)||"").toLowerCase();return a.includes(o)||n.includes(o)}):w},[w,c]),E=x.trim().length>0&&u.trim().length>0,W=()=>{f(""),h(!0)},Y=()=>{f(""),h(!1)},D=async o=>{o==null||o.preventDefault();const r=x.trim(),a=u.trim();if(!(!r||!a||d)){T(!0),f("");try{const n=await re(m,"/prompt_library",{name:r,content:a});if(!(n!=null&&n.success))throw new Error((n==null?void 0:n.message)||"Unable to save prompt.");const Z=n.prompt||{_id:n.id,name:r,content:a};j(O=>[Z,...O]),I(""),S(""),h(!1)}catch(n){console.error("Failed to add prompt:",n),f((n==null?void 0:n.message)||"The prompt could not be saved.")}finally{T(!1)}}},q=async o=>{if(!(!o||v)){L(o),g("");try{const r=await ne(m,`/prompt_library/${o}`);if(!(r!=null&&r.success))throw new Error((r==null?void 0:r.message)||"Unable to delete prompt.");j(a=>a.filter(n=>n._id!==o))}catch(r){console.error("Failed to remove prompt:",r),g((r==null?void 0:r.message)||"The prompt could not be deleted.")}finally{L(null)}}},J=o=>{y==null||y(o)},Q=o=>{o.key==="Enter"&&(o.metaKey||o.ctrlKey)&&E&&(o.preventDefault(),D())};return ee.createPortal(t.jsxs(t.Fragment,{children:[t.jsx(de,{$isopen:e,onClick:l,"aria-hidden":"true"}),t.jsxs(le,{$isopen:e,"aria-hidden":!e,"aria-label":"Prompt library","aria-modal":"true",role:"dialog",children:[t.jsxs(pe,{children:[t.jsxs(me,{children:[t.jsxs(xe,{children:[t.jsx(H,{}),"Prompt tools"]}),t.jsx(ue,{children:"Prompt library"}),t.jsx(he,{children:"Save reusable instructions and insert them whenever you need them."})]}),t.jsxs(ge,{children:[t.jsxs(be,{type:"button",onClick:W,"aria-label":"Create a new prompt",children:[t.jsx(A,{}),t.jsx("span",{children:"New"})]}),t.jsx(fe,{type:"button",onClick:l,"aria-label":"Close prompt library",title:"Close",children:t.jsx(_,{})})]})]}),t.jsxs(ye,{children:[p&&t.jsxs(we,{onSubmit:D,children:[t.jsxs(je,{children:[t.jsx(ve,{children:"Create a new prompt"}),t.jsx(Ce,{children:"Give it a clear name so it is easy to find later."})]}),t.jsxs(R,{children:[t.jsx(G,{children:"Prompt name"}),t.jsx(ke,{ref:k,type:"text",value:x,onChange:o=>I(o.target.value),placeholder:"For example: Summarize this judgment",maxLength:100,disabled:d}),t.jsx(K,{children:t.jsxs(M,{children:[x.length,"/100"]})})]}),t.jsxs(R,{children:[t.jsx(G,{children:"Instructions"}),t.jsx(Ie,{value:u,onChange:o=>S(o.target.value),onKeyDown:Q,placeholder:"Write the complete prompt you want to reuse...",maxLength:5e3,disabled:d}),t.jsx(K,{children:t.jsxs(M,{children:[u.length,"/5000"]})})]}),B&&t.jsx(Se,{role:"alert",children:B}),t.jsxs(Ne,{children:[t.jsx(Pe,{type:"button",onClick:Y,disabled:d,children:"Cancel"}),t.jsxs(Te,{type:"submit",disabled:!E||d,children:[d?t.jsx(C,{}):t.jsx(A,{}),d?"Saving":"Save prompt"]})]})]}),t.jsx(Le,{children:t.jsxs(ze,{children:[t.jsx(F,{}),t.jsx(Be,{type:"search",value:c,onChange:o=>N(o.target.value),placeholder:"Search saved prompts","aria-label":"Search saved prompts"}),c&&t.jsx(Ee,{type:"button",onClick:()=>N(""),"aria-label":"Clear search",children:t.jsx(_,{})})]})}),z&&t.jsx(Ue,{role:"alert",children:z}),t.jsxs(De,{children:[t.jsx(Fe,{children:"Saved prompts"}),t.jsxs(He,{children:[b.length," ",b.length===1?"prompt":"prompts"]})]}),V?t.jsxs($,{children:[t.jsx(U,{children:t.jsx(C,{})}),t.jsx(X,{children:"Loading prompts"})]}):b.length>0?t.jsx(Ae,{children:b.map(o=>t.jsxs(_e,{children:[t.jsxs(Re,{type:"button",onClick:()=>J(o.content),"aria-label":`Use prompt: ${o.name}`,children:[t.jsx(Ge,{children:o.name}),t.jsx(Ke,{children:o.content})]}),t.jsx(Me,{type:"button",onClick:()=>q(o._id),disabled:v===o._id,"aria-label":`Delete prompt: ${o.name}`,title:"Delete prompt",children:v===o._id?t.jsx(C,{}):t.jsx(se,{})})]},o._id))}):t.jsxs($,{children:[t.jsx(U,{children:c?t.jsx(F,{}):t.jsx(H,{})}),t.jsx(X,{children:c?"No matching prompts":"No saved prompts yet"}),t.jsx($e,{children:c?"Try a different name or phrase.":"Create your first reusable prompt using the New button above."})]})]}),t.jsx(Xe,{children:"Select a saved prompt to insert it into your current message."})]})]}),document.getElementById("app-frame"))};export{Oe 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.