import{r as e,t}from"./jsx-runtime-DAs1UGHr.js";import{t as n}from"./react-DxF41JXl.js";import{n as r,s as i}from"./chunk-EPOLDU6W-CNaCjKeI.js";import"./use-runtime-config-D_-Z8FUB.js";import"./use-api-BAbm8GVs.js";import{n as a}from"./use-user-BydImGZB.js";import"./toast-context-val-CcPDsXTx.js";import{t as o}from"./page-container-DV9_twon.js";import"./entity-service-D6-I4F0h.js";import{i as s,n as c,r as l,t as u}from"./search-input-DVDKmJAY.js";import"./use-toast-CpnYXdO8.js";import{i as d,n as f,r as p,t as m}from"./use-user-prompt-permissions-XTSblT8y.js";var h=e(n(),1),g=e(t(),1);const _=({currentUser:e})=>{let t=`flex flex-row p-1 hover:bg-table-row-hover dark:hover:bg-table-row-hover transition-colors duration-150 border-b border-btn-secondary-border dark:border-btn-secondary-border-dark`,n=`w-1/3 font-semibold text-text-primary dark:text-text-primary-dark`;return(0,g.jsx)(`div`,{className:`flex flex-col text-sm`,children:(0,g.jsxs)(`div`,{className:`divide-y divide-btn-secondary-border dark:divide-btn-secondary-border-dark`,children:[[{label:`Display Name`,value:e.display_name},{label:`Username`,value:e.username}].map(({label:e,value:r})=>(0,g.jsxs)(`div`,{className:t,children:[(0,g.jsx)(`div`,{className:n,children:e}),(0,g.jsx)(`div`,{className:`w-2/3 text-ui-text dark:text-ui-text-dark font-mono break-all`,children:r||`N/A`})]},e)),(0,g.jsxs)(`div`,{className:t,children:[(0,g.jsx)(`div`,{className:n,children:`Groups`}),(0,g.jsx)(`div`,{className:`w-2/3`,children:e.groups&&e.groups.length>0?(0,g.jsx)(`div`,{className:`flex flex-wrap gap-2 py-0.5`,children:e.groups.map(e=>(0,g.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium bg-btn-secondary-bg dark:bg-btn-secondary-bg-dark text-text-primary dark:text-text-primary-dark border border-btn-secondary-border dark:border-btn-secondary-border-dark`,children:e.group_name},e.id))}):(0,g.jsx)(`p`,{className:`italic text-text-primary dark:text-text-primary-dark opacity-60`,children:`This user is not a member of any groups.`})})]}),e.is_admin&&(0,g.jsx)(`div`,{className:`p-1 bg-logo/5`,children:(0,g.jsx)(`p`,{className:`text-logo font-medium`,children:`You have administrator privileges. Additional management options are available to you.`})})]})})},v=()=>{let{tab:e=`info`}=i(),{currentUser:t,isLoading:n,error:v}=a(),y=t?.username||null,b={info:null,experiments:p({username:y}),models:f({username:y}),prompts:m({username:y})}[e]||null,{searchTerm:x,submittedTerm:S,handleInputChange:C,handleSearchSubmit:w,handleClearSearch:T}=s();(0,h.useEffect)(()=>{T()},[e,T]);let E=[{id:`info`,label:`Info`},{id:`experiments`,label:`Experiments`},{id:`prompts`,label:`Prompts`},{id:`models`,label:`Models`}],D=[{header:`Name`,render:e=>e.name},{header:`Permission`,render:e=>e.permission},{header:`Kind`,render:e=>e.kind}],O=n||(b?.isLoading??!1),k=v||(b?.error??null),A=b?.permissions.filter(e=>e.name.toLowerCase().includes(S.toLowerCase()))??[];return(0,g.jsxs)(o,{title:`User Page`,children:[t&&(0,g.jsx)(d,{username:t.username,passwordExpiration:t.password_expiration}),(0,g.jsx)(`div`,{className:`flex space-x-4 border-b border-btn-secondary-border dark:border-btn-secondary-border-dark mb-3`,children:E.map(t=>(0,g.jsx)(r,{to:`/user/${t.id}`,className:`py-2 px-4 border-b-2 font-medium text-sm transition-colors duration-200 ${e===t.id?`border-btn-primary text-btn-primary dark:border-btn-primary-dark dark:text-btn-primary-dark`:`border-transparent text-text-primary dark:text-text-primary-dark hover:text-text-primary-hover dark:hover:text-text-primary-hover-dark hover:border-btn-secondary-border dark:hover:border-btn-secondary-border-dark`}`,children:t.label},t.id))}),(0,g.jsx)(c,{isLoading:O&&(!t||e!==`info`&&!b?.permissions),loadingText:`Loading information...`,error:k,onRetry:e===`info`?void 0:b?.refresh}),!O&&!k&&t&&(0,g.jsxs)(g.Fragment,{children:[e===`info`&&(0,g.jsx)(_,{currentUser:t}),e!==`info`&&b&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`mb-2`,children:(0,g.jsx)(u,{value:x,onInputChange:C,onSubmit:w,onClear:T,placeholder:`Search ${e}...`})}),(0,g.jsx)(l,{mode:`object`,data:A,columns:D,searchTerm:S})]})]})]})};var y=v;export{v as UserPage,y as default};