@adonis-agora/authkit-server 0.37.0 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -134,4 +134,4 @@ Error generating stack: `+e.message+`
|
|
|
134
134
|
0% { background-position: 200% 0; }
|
|
135
135
|
100% { background-position: -200% 0; }
|
|
136
136
|
}
|
|
137
|
-
`,document.head.appendChild(t)}}function SV({lines:e=3,lastWidth:t=`60%`}){return(0,I.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:Array.from({length:e}).map((n,r)=>(0,I.jsx)(xV,{width:r===e-1?t:`100%`,height:13},r))})}function CV(){return(0,I.jsxs)(`div`,{style:{background:`var(--bg2)`,border:`1px solid var(--line)`,borderRadius:`var(--radius)`,padding:`14px 16px`,display:`flex`,flexDirection:`column`,gap:8},children:[(0,I.jsx)(xV,{width:80,height:11}),(0,I.jsx)(xV,{width:60,height:28,borderRadius:8}),(0,I.jsx)(xV,{width:100,height:11})]})}function wV({count:e=6,columns:t=3}){return(0,I.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:`repeat(${t}, 1fr)`,gap:12},children:Array.from({length:e}).map((e,t)=>(0,I.jsx)(CV,{},t))})}function TV({rows:e=5,cols:t=4}){return(0,I.jsxs)(`div`,{style:{padding:`0 0 8px`},children:[(0,I.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:`repeat(${t}, 1fr)`,gap:12,padding:`10px 16px`,borderBottom:`1px solid var(--line)`},children:Array.from({length:t}).map((e,t)=>(0,I.jsx)(xV,{height:11,width:`50%`},t))}),Array.from({length:e}).map((e,n)=>(0,I.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:`repeat(${t}, 1fr)`,gap:12,padding:`12px 16px`,borderBottom:`1px solid var(--line)`},children:Array.from({length:t}).map((e,n)=>(0,I.jsx)(xV,{height:13,width:n===0?`80%`:n===t-1?`40%`:`65%`},n))},n))]})}function EV({rows:e=5,cols:t=4}){return(0,I.jsxs)(`div`,{style:{background:`var(--bg2)`,border:`1px solid var(--line)`,borderRadius:`var(--radius)`,overflow:`hidden`},children:[(0,I.jsx)(`div`,{style:{padding:`12px 16px`,borderBottom:`1px solid var(--line)`},children:(0,I.jsx)(xV,{width:200,height:13})}),(0,I.jsx)(TV,{rows:e,cols:t})]})}function DV(){return(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:20},children:[(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12},children:[(0,I.jsx)(xV,{width:44,height:44,borderRadius:`50%`}),(0,I.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,gap:6},children:[(0,I.jsx)(xV,{width:`60%`,height:14}),(0,I.jsx)(xV,{width:`40%`,height:11})]})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,I.jsx)(xV,{width:80,height:10}),(0,I.jsx)(xV,{height:32,borderRadius:8})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,I.jsx)(xV,{width:80,height:10}),(0,I.jsx)(SV,{lines:3,lastWidth:`50%`})]})]})}function OV(e){return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function kV(e){return e.includes(`login`)||e.includes(`signin`)?`badge-green`:e.includes(`fail`)||e.includes(`error`)||e.includes(`locked`)?`badge-red`:e.includes(`register`)||e.includes(`signup`)?`badge-accent`:e.includes(`settings`)||e.includes(`admin`)?`badge-amber`:`badge-muted`}function AV(){let{data:e,isLoading:t,error:n,refetch:r}=ut(Xs());return(0,I.jsx)(yV,{isLoading:t,error:n,onRetry:r,skeleton:(0,I.jsx)(wV,{count:6,columns:3}),children:e&&(0,I.jsxs)(`div`,{className:`cards`,children:[(0,I.jsxs)(`div`,{className:`card c-accent`,children:[(0,I.jsx)(`div`,{className:`card-label`,children:`Total Users`}),(0,I.jsx)(`div`,{className:`card-value`,children:e.usersTotal.toLocaleString()}),(0,I.jsx)(`div`,{className:`card-hint`,children:`registered accounts`})]}),(0,I.jsxs)(`div`,{className:`card c-green`,children:[(0,I.jsx)(`div`,{className:`card-label`,children:`Active Sessions`}),(0,I.jsx)(`div`,{className:`card-value`,children:(e.activeSessions??0).toLocaleString()}),(0,I.jsx)(`div`,{className:`card-hint`,children:`currently logged in`})]}),(0,I.jsxs)(`div`,{className:`card c-amber`,children:[(0,I.jsx)(`div`,{className:`card-label`,children:`MAU`}),(0,I.jsx)(`div`,{className:`card-value`,children:e.mau.toLocaleString()}),(0,I.jsx)(`div`,{className:`card-hint`,children:`monthly active users`})]}),(0,I.jsxs)(`div`,{className:`card`,children:[(0,I.jsx)(`div`,{className:`card-label`,children:`Sign-ins`}),(0,I.jsx)(`div`,{className:`card-value`,style:{color:`var(--text)`},children:e.signInsTotal.toLocaleString()}),(0,I.jsxs)(`div`,{className:`card-hint`,children:[`last `,e.windowDays,` days`]})]}),(0,I.jsxs)(`div`,{className:`card c-blue`,children:[(0,I.jsx)(`div`,{className:`card-label`,children:`Sign-ups`}),(0,I.jsx)(`div`,{className:`card-value`,children:e.signUpsTotal.toLocaleString()}),(0,I.jsx)(`div`,{className:`card-hint`,children:`new registrations`})]}),(0,I.jsxs)(`div`,{className:`card`,children:[(0,I.jsx)(`div`,{className:`card-label`,children:`OAuth Clients`}),(0,I.jsx)(`div`,{className:`card-value`,style:{color:`var(--text)`},children:e.clientsCount.toLocaleString()}),(0,I.jsx)(`div`,{className:`card-hint`,children:`OIDC clients`})]})]})})}function jV({title:e}){return(0,I.jsxs)(`div`,{className:`panel`,children:[(0,I.jsx)(`div`,{className:`panel-head`,children:(0,I.jsx)(`h3`,{children:e})}),(0,I.jsx)(`div`,{className:`panel-body`,style:{paddingBottom:4},children:(0,I.jsx)(xV,{height:60,borderRadius:8})})]})}function MV(){let{data:e,isLoading:t,error:n,refetch:r}=ut(Xs());return(0,I.jsx)(yV,{isLoading:t,error:n,onRetry:r,skeleton:(0,I.jsx)(jV,{title:`Sign-ins / day`}),children:e&&(0,I.jsxs)(`div`,{className:`panel`,children:[(0,I.jsxs)(`div`,{className:`panel-head`,children:[(0,I.jsx)(`h3`,{children:`Sign-ins / day`}),(0,I.jsxs)(`span`,{className:`meta`,children:[`last `,e.windowDays,`d`]})]}),(0,I.jsx)(`div`,{className:`panel-body`,style:{paddingBottom:`4px`},children:e.signInsPerDay.length>0?(0,I.jsx)(pV,{data:e.signInsPerDay,color:`var(--accent)`,label:`sign-ins`}):(0,I.jsx)(`div`,{style:{height:60,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`var(--faint)`,fontSize:12},children:`No data yet`})})]})})}function NV(){let{data:e,isLoading:t,error:n,refetch:r}=ut(Xs());return(0,I.jsx)(yV,{isLoading:t,error:n,onRetry:r,skeleton:(0,I.jsx)(jV,{title:`Sign-ups / day`}),children:e&&(0,I.jsxs)(`div`,{className:`panel`,children:[(0,I.jsxs)(`div`,{className:`panel-head`,children:[(0,I.jsx)(`h3`,{children:`Sign-ups / day`}),(0,I.jsxs)(`span`,{className:`meta`,children:[`last `,e.windowDays,`d`]})]}),(0,I.jsx)(`div`,{className:`panel-body`,style:{paddingBottom:`4px`},children:e.signUpsPerDay.length>0?(0,I.jsx)(pV,{data:e.signUpsPerDay,color:`var(--green)`,label:`sign-ups`}):(0,I.jsx)(`div`,{style:{height:60,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`var(--faint)`,fontSize:12},children:`No data yet`})})]})})}function PV(){let{data:e,isLoading:t,error:n,refetch:r}=ut(Xs());return(0,I.jsx)(yV,{isLoading:t,error:n,onRetry:r,skeleton:(0,I.jsx)(EV,{rows:5,cols:4}),children:e&&e.auditSupported&&e.recentEvents.length>0&&(0,I.jsxs)(`div`,{className:`panel`,children:[(0,I.jsxs)(`div`,{className:`panel-head`,children:[(0,I.jsx)(`h3`,{children:`Recent Events`}),(0,I.jsxs)(`span`,{className:`meta`,children:[e.auditTotal.toLocaleString(),` total`]})]}),(0,I.jsx)(`div`,{className:`panel-body`,style:{padding:0},children:(0,I.jsxs)(`table`,{children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`Type`}),(0,I.jsx)(`th`,{children:`Account`}),(0,I.jsx)(`th`,{children:`IP`}),(0,I.jsx)(`th`,{children:`When`})]})}),(0,I.jsx)(`tbody`,{children:e.recentEvents.map(e=>(0,I.jsxs)(`tr`,{className:`static`,style:{cursor:`default`},children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`badge ${kV(e.type)}`,children:e.type})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:`11.5px`},children:e.email??e.accountId??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`code`,children:e.ip??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:`11px`,color:`var(--faint)`},children:e.createdAt?OV(e.createdAt):`—`})})]},e.id))})]})})]})})}function FV(){return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header`,children:[(0,I.jsx)(`div`,{className:`page-title`,children:`Overview`}),(0,I.jsx)(`div`,{className:`page-sub`,children:`Identity provider metrics`})]}),(0,I.jsx)(AV,{}),(0,I.jsxs)(`div`,{className:`grid-2`,style:{marginTop:16},children:[(0,I.jsx)(MV,{}),(0,I.jsx)(NV,{})]}),(0,I.jsx)(`div`,{style:{marginTop:16},children:(0,I.jsx)(PV,{})})]})}function IV({open:e,onClose:t,title:n,children:r,footer:i,large:a}){return(0,F.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),e?(0,I.jsx)(`div`,{className:`modal-overlay`,onClick:t,children:(0,I.jsxs)(`div`,{className:`modal${a?` modal-lg`:``}`,onClick:e=>e.stopPropagation(),children:[(0,I.jsxs)(`div`,{className:`modal-head`,children:[(0,I.jsx)(`h2`,{children:n}),(0,I.jsx)(`button`,{className:`modal-close`,onClick:t,children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M3 3l10 10M13 3L3 13`,strokeLinecap:`round`})})})]}),(0,I.jsx)(`div`,{className:`modal-body`,children:r}),i&&(0,I.jsx)(`div`,{className:`modal-foot`,children:i})]})}):null}function LV(e,t){let[n,r]=(0,F.useState)(e);return(0,F.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function RV({open:e,onClose:t,title:n,children:r}){return(0,F.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),e?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`drawer-overlay`,onClick:t}),(0,I.jsxs)(`div`,{className:`drawer`,children:[(0,I.jsxs)(`div`,{className:`drawer-head`,children:[(0,I.jsx)(`h2`,{children:n}),(0,I.jsx)(`button`,{className:`modal-close`,onClick:t,children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M3 3l10 10M13 3L3 13`,strokeLinecap:`round`})})})]}),(0,I.jsx)(`div`,{className:`drawer-body`,children:r})]})]}):null}function zV({page:e,total:t,perPage:n,onPage:r}){let i=Math.ceil(t/n);return i<=1?null:(0,I.jsxs)(`div`,{className:`pagination`,children:[(0,I.jsxs)(`span`,{className:`pag-info`,children:[(e-1)*n+1,`–`,Math.min(e*n,t),` of `,t]}),(0,I.jsx)(`button`,{className:`btn btn-sm`,disabled:e<=1,onClick:()=>r(e-1),children:(0,I.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M10 12L6 8l4-4`,strokeLinecap:`round`,strokeLinejoin:`round`})})}),(0,I.jsxs)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:`11px`,color:`var(--muted)`},children:[e,` / `,i]}),(0,I.jsx)(`button`,{className:`btn btn-sm`,disabled:e>=i,onClick:()=>r(e+1),children:(0,I.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M6 12l4-4-4-4`,strokeLinecap:`round`,strokeLinejoin:`round`})})})]})}function BV({search:e,page:t,onPage:n,onSelectUser:r}){let{data:i,isLoading:a,error:o,refetch:s}=ut(Zs({search:e,page:t,limit:20})),c=i?.data??[],l=i?.total??0;return(0,I.jsxs)(I.Fragment,{children:[!a&&!o&&(0,I.jsx)(`div`,{style:{marginBottom:4},children:(0,I.jsxs)(`span`,{className:`page-sub`,style:{fontSize:12,color:`var(--faint)`},children:[l.toLocaleString(),` accounts`]})}),(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(yV,{isLoading:a,error:o,onRetry:s,skeleton:(0,I.jsx)(EV,{rows:6,cols:3}),children:c.length===0?(0,I.jsxs)(`div`,{className:`empty-state`,children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,I.jsx)(`circle`,{cx:`12`,cy:`8`,r:`4`}),(0,I.jsx)(`path`,{d:`M4 20c0-4.42 3.58-8 8-8s8 3.58 8 8`})]}),(0,I.jsx)(`h4`,{children:`No users found`}),(0,I.jsx)(`p`,{children:e?`Try a different search term`:`No accounts registered yet`})]}):(0,I.jsxs)(`div`,{className:`tbl-wrap`,children:[(0,I.jsxs)(`table`,{children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`User`}),(0,I.jsx)(`th`,{children:`Roles`}),(0,I.jsx)(`th`,{children:`Status`})]})}),(0,I.jsx)(`tbody`,{children:c.map(e=>(0,I.jsxs)(`tr`,{onClick:()=>r(e.id),children:[(0,I.jsx)(`td`,{children:(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10},children:[(0,I.jsx)(`div`,{className:`avatar`,style:{width:26,height:26,fontSize:10},children:e.email.slice(0,2).toUpperCase()}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{style:{color:`var(--text)`,fontWeight:500,fontSize:12.5},children:e.email}),e.name&&(0,I.jsx)(`div`,{style:{color:`var(--faint)`,fontSize:11},children:e.name})]})]})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`div`,{style:{display:`flex`,gap:4,flexWrap:`wrap`},children:e.globalRoles.length===0?(0,I.jsx)(`span`,{className:`badge badge-muted`,children:`no roles`}):e.globalRoles.map(e=>(0,I.jsx)(`span`,{className:`badge badge-accent`,children:e},e))})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`badge ${e.disabled?`badge-red`:`badge-green`}`,children:e.disabled?`disabled`:`active`})})]},e.id))})]}),(0,I.jsx)(`div`,{style:{padding:`0 16px 12px`},children:(0,I.jsx)(zV,{page:t,total:l,perPage:20,onPage:n})})]})})})]})}function VV({userId:e,onMutated:t,onClose:n}){let r=Ic(),i=Ye(),{data:a,isLoading:o,error:s,refetch:c}=ut(Qs(e)),l=dt(nc(e)),u=dt(rc(e)),d=dt(ic(e)),f=dt(ac(e)),p=dt(oc(e)),m=ut({...Oc(e),enabled:!1});async function h(){if(a)try{a.disabled?(await u.mutateAsync(),r.success(`User enabled`)):(await l.mutateAsync(),r.success(`User disabled`)),i.invalidateQueries({queryKey:H.admin.user(e)}),t()}catch(e){r.error(e instanceof Error?e.message:String(e))}}async function g(){try{await d.mutateAsync(),r.success(`Reset email sent`)}catch(e){r.error(e instanceof Error?e.message:String(e))}}async function _(){if(a&&confirm(`Delete user ${a.email}? This cannot be undone.`))try{await f.mutateAsync(),r.success(`User deleted`),n(),t()}catch(e){r.error(e instanceof Error?e.message:String(e))}}async function v(){if(a&&confirm(`Disconnect ${a.email} from all devices? Every active session and grant will be revoked.`))try{let t=await p.mutateAsync();r.success(`Disconnected from all devices${typeof t?.revoked==`number`?` (${t.revoked} sessions)`:``}`),i.invalidateQueries({queryKey:H.admin.userSessions(e)})}catch(e){r.error(e instanceof Error?e.message:String(e))}}async function y(){try{let e=await m.refetch();if(e.data){let t=e.data.url;typeof t==`string`?window.open(t,`_blank`):r.error(`Impersonation URL not available`)}}catch(e){r.error(e instanceof Error?e.message:`Impersonation not available`)}}return(0,I.jsx)(yV,{isLoading:o,error:s,onRetry:c,skeleton:(0,I.jsx)(`div`,{children:(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12,marginBottom:16},children:[(0,I.jsx)(`div`,{style:{width:44,height:44,borderRadius:`50%`,background:`var(--bg3)`,backgroundImage:`linear-gradient(90deg, var(--bg3) 0%, var(--bg2) 40%, var(--bg3) 100%)`,backgroundSize:`200% 100%`,animation:`sk-shimmer 1.6s ease-in-out infinite`}}),(0,I.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,gap:6},children:[(0,I.jsx)(`div`,{style:{height:14,width:`60%`,borderRadius:6,background:`var(--bg3)`,backgroundImage:`linear-gradient(90deg, var(--bg3) 0%, var(--bg2) 40%, var(--bg3) 100%)`,backgroundSize:`200% 100%`,animation:`sk-shimmer 1.6s ease-in-out infinite`}}),(0,I.jsx)(`div`,{style:{height:11,width:`40%`,borderRadius:6,background:`var(--bg3)`,backgroundImage:`linear-gradient(90deg, var(--bg3) 0%, var(--bg2) 40%, var(--bg3) 100%)`,backgroundSize:`200% 100%`,animation:`sk-shimmer 1.6s ease-in-out infinite`}})]})]})}),children:a&&(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12,marginBottom:16},children:[(0,I.jsx)(`div`,{className:`avatar`,style:{width:44,height:44,fontSize:15},children:a.email.slice(0,2).toUpperCase()}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{style:{fontWeight:600,fontSize:14},children:a.email}),a.name&&(0,I.jsx)(`div`,{style:{color:`var(--faint)`,fontSize:12},children:a.name}),(0,I.jsx)(`div`,{style:{marginTop:4},children:(0,I.jsx)(`span`,{className:`badge ${a.disabled?`badge-red`:`badge-green`}`,children:a.disabled?`disabled`:`active`})})]})]}),(0,I.jsxs)(`div`,{className:`code`,style:{fontSize:11,padding:`6px 10px`},children:[`ID: `,a.id]}),(0,I.jsxs)(`div`,{style:{marginTop:16},children:[(0,I.jsx)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:8},children:`Actions`}),(0,I.jsxs)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:6},children:[(0,I.jsx)(`button`,{className:`btn btn-sm ${a.disabled?``:`btn-danger`}`,onClick:h,disabled:l.isPending||u.isPending,children:a.disabled?`Enable account`:`Disable account`}),(0,I.jsx)(`button`,{className:`btn btn-sm`,onClick:g,disabled:d.isPending,children:`Reset password`}),(0,I.jsx)(`button`,{className:`btn btn-sm`,onClick:y,disabled:m.isFetching,children:`Impersonate`}),(0,I.jsx)(`button`,{className:`btn btn-sm btn-danger`,onClick:v,disabled:p.isPending,children:`Disconnect all devices`}),(0,I.jsx)(`button`,{className:`btn btn-sm btn-danger`,onClick:_,disabled:f.isPending,children:`Delete user`})]})]})]})})}function HV({userId:e,onMutated:t}){let n=Ic(),r=Ye(),{data:i,isLoading:a,error:o,refetch:s}=ut(Qs(e)),c=dt(tc(e)),[l,u]=(0,F.useState)([]);(0,F.useEffect)(()=>{i&&u(i.globalRoles)},[i]);let d=e=>{u(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])};async function f(){try{await c.mutateAsync({globalRoles:l}),n.success(`Roles updated`),r.invalidateQueries({queryKey:H.admin.user(e)}),t()}catch(e){n.error(e instanceof Error?e.message:String(e))}}return(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:8},children:`Global Roles`}),(0,I.jsx)(yV,{isLoading:a,error:o,onRetry:s,skeleton:(0,I.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[1,2].map(e=>(0,I.jsx)(`div`,{style:{height:20,borderRadius:6,background:`var(--bg3)`,backgroundImage:`linear-gradient(90deg, var(--bg3) 0%, var(--bg2) 40%, var(--bg3) 100%)`,backgroundSize:`200% 100%`,animation:`sk-shimmer 1.6s ease-in-out infinite`}},e))}),children:i&&(0,I.jsxs)(I.Fragment,{children:[l.length===0&&(0,I.jsx)(`div`,{style:{fontSize:12,color:`var(--faint)`,marginBottom:8},children:`No roles assigned`}),i.globalRoles.map(e=>(0,I.jsxs)(`label`,{className:`checkbox-row`,children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:l.includes(e),onChange:()=>d(e)}),(0,I.jsx)(`div`,{children:(0,I.jsx)(`div`,{className:`chk-label`,children:e})})]},e)),(0,I.jsx)(`button`,{className:`btn btn-primary btn-sm`,style:{marginTop:10},onClick:f,disabled:c.isPending,children:c.isPending?(0,I.jsx)(`span`,{className:`spinner sm`}):`Save roles`})]})})]})}function UV({userId:e}){let{data:t,isLoading:n,error:r,refetch:i}=ut($s(e)),a=t?.sessions??[];return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:8},children:[`Sessions `,!n&&!r?`(${a.length})`:``]}),(0,I.jsx)(yV,{isLoading:n,error:r,onRetry:i,skeleton:(0,I.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[1,2].map(e=>(0,I.jsx)(`div`,{style:{height:44,borderRadius:8,background:`var(--bg3)`,backgroundImage:`linear-gradient(90deg, var(--bg3) 0%, var(--bg2) 40%, var(--bg3) 100%)`,backgroundSize:`200% 100%`,animation:`sk-shimmer 1.6s ease-in-out infinite`}},e))}),children:a.length===0?(0,I.jsx)(`div`,{style:{fontSize:12,color:`var(--faint)`},children:`No active sessions`}):a.map(e=>(0,I.jsxs)(`div`,{className:`panel`,style:{marginBottom:8,padding:`10px 12px`},children:[(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,fontSize:12},children:[(0,I.jsxs)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 16 16`,fill:`none`,stroke:`var(--muted)`,strokeWidth:`1.6`,children:[(0,I.jsx)(`rect`,{x:`1.5`,y:`3.5`,width:`13`,height:`9`,rx:`1.5`}),(0,I.jsx)(`circle`,{cx:`8`,cy:`8.5`,r:`2`})]}),(0,I.jsx)(`span`,{style:{color:`var(--text)`,fontWeight:500},children:e.browser??`Unknown browser`}),(0,I.jsx)(`span`,{style:{color:`var(--faint)`},children:e.os}),(0,I.jsx)(`span`,{className:`code ml-auto`,children:e.ip??`—`})]}),e.location&&(0,I.jsx)(`div`,{style:{fontSize:11,color:`var(--faint)`,marginTop:4},children:e.location})]},e.id))})]})}function WV({userId:e,onClose:t,onMutated:n}){let{data:r}=ut(Qs(e));return(0,I.jsx)(RV,{open:!0,onClose:t,title:r?.email??`User detail`,children:(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:20},children:[(0,I.jsx)(VV,{userId:e,onMutated:n,onClose:t}),(0,I.jsx)(HV,{userId:e,onMutated:n}),(0,I.jsx)(UV,{userId:e})]})})}function GV(){let e=Ic(),t=Ye(),[n,r]=Jc(`page`,Bc.withDefault(1)),[i,a]=Jc(`q`,zc.withDefault(``)),[o,s]=Jc(`user`),c=LV(i,300),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)({email:``,name:``,password:``,invite:!1}),p=dt(ec());async function m(n){n.preventDefault();try{await p.mutateAsync({email:d.email,name:d.name||void 0,password:d.password||void 0,invite:d.invite}),t.invalidateQueries({queryKey:H.admin.users()}),e.success(`User created`),u(!1),f({email:``,name:``,password:``,invite:!1})}catch(t){e.error(t instanceof Error?t.message:String(t))}}return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header-row`,children:[(0,I.jsx)(`div`,{children:(0,I.jsx)(`div`,{className:`page-title`,children:`Users`})}),(0,I.jsx)(`div`,{className:`page-actions`,children:(0,I.jsxs)(`button`,{className:`btn btn-primary`,onClick:()=>u(!0),children:[(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M8 2v12M2 8h12`,strokeLinecap:`round`})}),`New User`]})})]}),(0,I.jsx)(`div`,{className:`panel`,style:{marginBottom:0},children:(0,I.jsx)(`div`,{className:`panel-head`,children:(0,I.jsxs)(`div`,{className:`search-input`,style:{flex:1,maxWidth:320},children:[(0,I.jsxs)(`svg`,{className:`search-ico`,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,children:[(0,I.jsx)(`circle`,{cx:`7`,cy:`7`,r:`4.5`}),(0,I.jsx)(`path`,{d:`M10 10l3 3`,strokeLinecap:`round`})]}),(0,I.jsx)(`input`,{className:`input`,placeholder:`Search by email or name…`,value:i,onChange:e=>{a(e.target.value),r(1)}})]})})}),(0,I.jsx)(BV,{search:c,page:n,onPage:r,onSelectUser:s,onInvalidate:()=>t.invalidateQueries({queryKey:H.admin.users()})}),(0,I.jsx)(IV,{open:l,onClose:()=>u(!1),title:`Create User`,footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`btn`,onClick:()=>u(!1),children:`Cancel`}),(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:m,disabled:p.isPending,children:p.isPending?(0,I.jsx)(`span`,{className:`spinner sm`}):`Create User`})]}),children:(0,I.jsxs)(`form`,{onSubmit:m,children:[(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Email *`}),(0,I.jsx)(`input`,{className:`input`,type:`email`,required:!0,value:d.email,onChange:e=>f(t=>({...t,email:e.target.value})),placeholder:`user@example.com`})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Name`}),(0,I.jsx)(`input`,{className:`input`,value:d.name,onChange:e=>f(t=>({...t,name:e.target.value})),placeholder:`Full name (optional)`})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Password`}),(0,I.jsx)(`input`,{className:`input`,type:`password`,value:d.password,onChange:e=>f(t=>({...t,password:e.target.value})),placeholder:`Leave blank to send invite`})]}),(0,I.jsxs)(`label`,{className:`checkbox-row`,children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:d.invite,onChange:e=>f(t=>({...t,invite:e.target.checked}))}),(0,I.jsx)(`span`,{className:`chk-label`,children:`Send invitation email`})]})]})}),o&&(0,I.jsx)(WV,{userId:o,onClose:()=>s(null),onMutated:()=>t.invalidateQueries({queryKey:H.admin.users()})})]})}var KV=20;function qV({page:e,onPage:t}){let{data:n,isLoading:r,error:i,refetch:a}=ut(sc()),o=n?.sessions??[],s=o.length,c=o.slice((e-1)*KV,e*KV);return(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(yV,{isLoading:r,error:i,onRetry:a,skeleton:(0,I.jsx)(EV,{rows:8,cols:6}),children:c.length===0?(0,I.jsxs)(`div`,{className:`empty-state`,children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,I.jsx)(`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`}),(0,I.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]}),(0,I.jsx)(`h4`,{children:`No active sessions`}),(0,I.jsx)(`p`,{children:`No users are currently logged in`})]}):(0,I.jsxs)(`div`,{className:`tbl-wrap`,children:[(0,I.jsxs)(`table`,{children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`Account`}),(0,I.jsx)(`th`,{children:`Browser / OS`}),(0,I.jsx)(`th`,{children:`IP`}),(0,I.jsx)(`th`,{children:`Location`}),(0,I.jsx)(`th`,{children:`Login`}),(0,I.jsx)(`th`,{children:`Methods`})]})}),(0,I.jsx)(`tbody`,{children:c.map(e=>(0,I.jsxs)(`tr`,{style:{cursor:`default`},children:[(0,I.jsx)(`td`,{children:(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:2},children:[e.email&&(0,I.jsx)(`span`,{style:{fontSize:12,fontWeight:500,color:`var(--text)`},children:e.email}),(0,I.jsx)(`span`,{className:`mono text-sm`,style:{color:e.email?`var(--faint)`:void 0},children:e.accountId})]})}),(0,I.jsx)(`td`,{children:(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,I.jsx)(`span`,{style:{color:`var(--text)`,fontWeight:500,fontSize:12},children:e.browser??`—`}),(0,I.jsx)(`span`,{style:{color:`var(--faint)`,fontSize:11},children:e.os??``})]})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`code`,children:e.ip??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontSize:11.5,color:`var(--muted)`},children:e.location??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:11,color:`var(--faint)`},children:e.loginTs?new Date(e.loginTs).toLocaleString():`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`div`,{style:{display:`flex`,gap:4,flexWrap:`wrap`},children:e.amr.length===0?(0,I.jsx)(`span`,{className:`badge badge-muted`,children:`—`}):e.amr.map(e=>(0,I.jsx)(`span`,{className:`badge badge-muted`,children:e},e))})})]},e.id))})]}),(0,I.jsx)(`div`,{style:{padding:`0 16px 12px`},children:(0,I.jsx)(zV,{page:e,total:s,perPage:KV,onPage:t})})]})})})}function JV(){let{data:e}=ut(sc());return e?.sessions.length??0}function YV(){let e=Ic(),t=Ye(),[n,r]=Jc(`page`,Bc.withDefault(1)),i=JV(),a=dt(cc());async function o(){if(confirm(`Revoke ALL active sessions? All users will be logged out.`))try{let n=await a.mutateAsync();e.success(`Revoked ${n.revoked??0} sessions`),t.invalidateQueries({queryKey:H.admin.sessions()})}catch(t){e.error(t instanceof Error?t.message:String(t))}}return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header-row`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,children:`Sessions`}),(0,I.jsxs)(`div`,{className:`page-sub`,children:[i.toLocaleString(),` active sessions`]})]}),(0,I.jsx)(`div`,{className:`page-actions`,children:(0,I.jsxs)(`button`,{className:`btn btn-danger`,onClick:o,disabled:a.isPending,children:[a.isPending?(0,I.jsx)(`span`,{className:`spinner sm`}):(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,children:(0,I.jsx)(`path`,{d:`M4 4l8 8M12 4l-8 8`,strokeLinecap:`round`})}),`Revoke All`]})})]}),(0,I.jsx)(qV,{page:n,onPage:r})]})}function XV(){return(0,I.jsxs)(`div`,{style:{background:`var(--bg2)`,border:`1px solid var(--line)`,borderRadius:`var(--radius)`,padding:`14px 16px`,display:`flex`,flexDirection:`column`,gap:8},children:[(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,I.jsx)(xV,{width:`30%`,height:13}),(0,I.jsx)(xV,{width:60,height:18,borderRadius:20})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,I.jsx)(xV,{width:100,height:18,borderRadius:20}),(0,I.jsx)(xV,{width:80,height:18,borderRadius:20})]}),(0,I.jsx)(xV,{width:`50%`,height:11})]})}function ZV(){return(0,I.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:[1,2,3].map(e=>(0,I.jsx)(XV,{},e))})}function QV({onEdit:e,onDelete:t,onRegenerate:n}){let{data:r,isLoading:i,error:a,refetch:o}=ut(lc()),s=r?.data??[],c=r?.canList??!0;return(0,I.jsx)(yV,{isLoading:i,error:a,onRetry:o,skeleton:(0,I.jsx)(ZV,{}),children:c?s.length===0?(0,I.jsxs)(`div`,{className:`empty-state`,children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,I.jsx)(`path`,{d:`M18 13l4-3.5L18 6`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,I.jsx)(`path`,{d:`M22 9.5H9M6 5H4a1 1 0 00-1 1v12a1 1 0 001 1h2`,strokeLinecap:`round`})]}),(0,I.jsx)(`h4`,{children:`No clients yet`}),(0,I.jsx)(`p`,{children:`Create an OAuth 2.0 / OIDC client to get started`})]}):(0,I.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:s.map(r=>(0,I.jsx)(`div`,{className:`panel`,style:{padding:`14px 16px`},children:(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`flex-start`,gap:14},children:[(0,I.jsxs)(`div`,{style:{flex:1},children:[(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:6},children:[(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontWeight:600,fontSize:13,color:`var(--text)`},children:r.clientId}),(0,I.jsx)(`span`,{className:`badge ${r.confidential?`badge-accent`:`badge-muted`}`,children:r.confidential?`confidential`:`public`})]}),(0,I.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:4,marginBottom:6},children:r.grants.map(e=>(0,I.jsx)(`span`,{className:`badge badge-muted`,children:e},e))}),r.redirectUris.length>0&&(0,I.jsx)(`div`,{style:{fontSize:11,color:`var(--faint)`,display:`flex`,flexWrap:`wrap`,gap:4},children:r.redirectUris.map(e=>(0,I.jsx)(`span`,{className:`code`,children:e},e))})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6,flexShrink:0},children:[(0,I.jsx)(`button`,{className:`btn btn-sm`,onClick:()=>e(r),children:`Edit`}),(0,I.jsx)(`button`,{className:`btn btn-sm`,onClick:()=>n(r),title:`Regenerate secret`,children:(0,I.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,children:[(0,I.jsx)(`path`,{d:`M2 8a6 6 0 016-6 6 6 0 014.24 1.76L14 5`,strokeLinecap:`round`}),(0,I.jsx)(`path`,{d:`M14 2v3h-3M14 8a6 6 0 01-6 6 6 6 0 01-4.24-1.76L2 11`,strokeLinecap:`round`}),(0,I.jsx)(`path`,{d:`M2 14v-3h3`,strokeLinecap:`round`})]})}),(0,I.jsx)(`button`,{className:`btn btn-sm btn-danger`,onClick:()=>t(r),children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,children:(0,I.jsx)(`path`,{d:`M2 4.5h12M5.5 4.5V3h5v1.5M10.5 4.5v8a1 1 0 01-1 1h-3a1 1 0 01-1-1v-8`,strokeLinecap:`round`})})})]})]})},r.clientId))}):(0,I.jsx)(`div`,{className:`error-box`,children:`Client store does not support listing (no dynamic registration adapter configured).`})})}function $V(){let{data:e}=ut(lc());return e?.data.length??0}var eH=[`authorization_code`,`refresh_token`,`client_credentials`,`implicit`],tH=[`client_secret_basic`,`client_secret_post`,`none`];function nH(){return{clientIdOverride:``,redirectUris:[],postLogoutRedirectUris:[],grantTypes:[`authorization_code`,`refresh_token`],tokenEndpointAuthMethod:`client_secret_basic`,backchannelLogoutUri:``,backchannelLogoutSessionRequired:!1}}function rH(){let e=Ic(),t=Ye(),n=V(),r=$V(),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(null),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(nH()),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(``),g=dt(uc()),_=dt(dc(o?.clientId??``));function v(){d(nH()),p(``),h(``),a(!0)}function y(e){d({clientIdOverride:``,redirectUris:[...e.redirectUris],postLogoutRedirectUris:[...e.postLogoutRedirectUris],grantTypes:[...e.grants],tokenEndpointAuthMethod:e.tokenEndpointAuthMethod,backchannelLogoutUri:e.backchannelLogoutUri??``,backchannelLogoutSessionRequired:e.backchannelLogoutSessionRequired}),p(``),h(``),s(e)}function b(e){let t=e===`redirect`?f.trim():m.trim();t&&(e===`redirect`?(d(e=>({...e,redirectUris:[...e.redirectUris,t]})),p(``)):(d(e=>({...e,postLogoutRedirectUris:[...e.postLogoutRedirectUris,t]})),h(``)))}function x(e,t){d(e===`redirect`?e=>({...e,redirectUris:e.redirectUris.filter((e,n)=>n!==t)}):e=>({...e,postLogoutRedirectUris:e.postLogoutRedirectUris.filter((e,n)=>n!==t)}))}function S(e){d(t=>({...t,grantTypes:t.grantTypes.includes(e)?t.grantTypes.filter(t=>t!==e):[...t.grantTypes,e]}))}async function C(n){n.preventDefault();try{let n={clientId:u.clientIdOverride||void 0,redirectUris:u.redirectUris,postLogoutRedirectUris:u.postLogoutRedirectUris,grantTypes:u.grantTypes,tokenEndpointAuthMethod:u.tokenEndpointAuthMethod,backchannelLogoutUri:u.backchannelLogoutUri||void 0,backchannelLogoutSessionRequired:u.backchannelLogoutSessionRequired},r=await g.mutateAsync(n);t.invalidateQueries({queryKey:H.admin.clients()}),a(!1),r.clientSecret?l({clientId:r.clientId,secret:r.clientSecret}):e.success(`Client ${r.clientId} created`)}catch(t){e.error(t instanceof Error?t.message:String(t))}}async function w(n){if(n.preventDefault(),o)try{await _.mutateAsync({redirectUris:u.redirectUris,postLogoutRedirectUris:u.postLogoutRedirectUris,grantTypes:u.grantTypes,tokenEndpointAuthMethod:u.tokenEndpointAuthMethod,backchannelLogoutUri:u.backchannelLogoutUri||void 0,backchannelLogoutSessionRequired:u.backchannelLogoutSessionRequired}),t.invalidateQueries({queryKey:H.admin.clients()}),e.success(`Client updated`),s(null)}catch(t){e.error(t instanceof Error?t.message:String(t))}}async function T(r){if(confirm(`Delete client ${r.clientId}?`))try{await n.admin.clients.remove(r.clientId),t.invalidateQueries({queryKey:H.admin.clients()}),e.success(`Client deleted`)}catch(t){e.error(t instanceof Error?t.message:String(t))}}async function E(t){if(confirm(`Regenerate secret for ${t.clientId}? Existing secret will stop working.`))try{let r=await n.admin.clients.regenerateSecret(t.clientId);r.clientSecret?l({clientId:r.clientId,secret:r.clientSecret}):e.info(`No secret returned (public client)`)}catch(t){e.error(t instanceof Error?t.message:String(t))}}let D=()=>(0,I.jsxs)(`form`,{onSubmit:o?w:C,children:[!o&&(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Client ID (optional — auto-generated if blank)`}),(0,I.jsx)(`input`,{className:`input input-mono`,value:u.clientIdOverride,onChange:e=>d(t=>({...t,clientIdOverride:e.target.value})),placeholder:`my-app (auto if blank)`})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Grant Types`}),(0,I.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:6,marginTop:4},children:eH.map(e=>(0,I.jsxs)(`label`,{className:`checkbox-row`,style:{padding:`4px 0`},children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:u.grantTypes.includes(e),onChange:()=>S(e)}),(0,I.jsx)(`span`,{className:`chk-label mono`,children:e})]},e))})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Token Endpoint Auth Method`}),(0,I.jsx)(`select`,{className:`input`,value:u.tokenEndpointAuthMethod,onChange:e=>d(t=>({...t,tokenEndpointAuthMethod:e.target.value})),children:tH.map(e=>(0,I.jsx)(`option`,{value:e,children:e},e))})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Redirect URIs`}),u.redirectUris.map((e,t)=>(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6,marginBottom:4},children:[(0,I.jsx)(`input`,{className:`input input-mono`,value:e,readOnly:!0,style:{flex:1}}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-danger`,onClick:()=>x(`redirect`,t),children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M3 3l10 10M13 3L3 13`,strokeLinecap:`round`})})})]},t)),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,I.jsx)(`input`,{className:`input input-mono`,value:f,onChange:e=>p(e.target.value),placeholder:`https://app.example.com/callback`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),b(`redirect`))}}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-sm`,onClick:()=>b(`redirect`),children:`Add`})]})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Post-Logout Redirect URIs`}),u.postLogoutRedirectUris.map((e,t)=>(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6,marginBottom:4},children:[(0,I.jsx)(`input`,{className:`input input-mono`,value:e,readOnly:!0,style:{flex:1}}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-danger`,onClick:()=>x(`logout`,t),children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M3 3l10 10M13 3L3 13`,strokeLinecap:`round`})})})]},t)),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,I.jsx)(`input`,{className:`input input-mono`,value:m,onChange:e=>h(e.target.value),placeholder:`https://app.example.com/logged-out`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),b(`logout`))}}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-sm`,onClick:()=>b(`logout`),children:`Add`})]})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Backchannel Logout URI`}),(0,I.jsx)(`input`,{className:`input input-mono`,value:u.backchannelLogoutUri,onChange:e=>d(t=>({...t,backchannelLogoutUri:e.target.value})),placeholder:`https://app.example.com/backchannel-logout`})]}),(0,I.jsxs)(`label`,{className:`checkbox-row`,children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:u.backchannelLogoutSessionRequired,onChange:e=>d(t=>({...t,backchannelLogoutSessionRequired:e.target.checked}))}),(0,I.jsx)(`span`,{className:`chk-label`,children:`Require session ID in backchannel logout`})]})]});return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header-row`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,children:`OAuth Clients`}),(0,I.jsxs)(`div`,{className:`page-sub`,children:[r,` dynamic clients`]})]}),(0,I.jsx)(`div`,{className:`page-actions`,children:(0,I.jsxs)(`button`,{className:`btn btn-primary`,onClick:v,children:[(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M8 2v12M2 8h12`,strokeLinecap:`round`})}),`New Client`]})})]}),(0,I.jsx)(QV,{onEdit:y,onDelete:T,onRegenerate:E}),(0,I.jsx)(IV,{open:i,onClose:()=>a(!1),title:`New OAuth Client`,large:!0,footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`btn`,onClick:()=>a(!1),children:`Cancel`}),(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:C,disabled:g.isPending,children:g.isPending?(0,I.jsx)(`span`,{className:`spinner sm`}):`Create Client`})]}),children:(0,I.jsx)(D,{})}),(0,I.jsx)(IV,{open:!!o,onClose:()=>s(null),title:`Edit — ${o?.clientId}`,large:!0,footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`btn`,onClick:()=>s(null),children:`Cancel`}),(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:w,disabled:_.isPending,children:_.isPending?(0,I.jsx)(`span`,{className:`spinner sm`}):`Save Changes`})]}),children:(0,I.jsx)(D,{})}),(0,I.jsxs)(IV,{open:!!c,onClose:()=>l(null),title:`Client Secret — Save Now`,footer:(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:()=>l(null),children:`I've saved it`}),children:[(0,I.jsx)(`div`,{className:`error-box`,style:{background:`var(--amber-soft)`,borderColor:`rgba(255,180,84,0.3)`,color:`var(--amber)`},children:`This secret will not be shown again. Copy it now.`}),(0,I.jsxs)(`div`,{className:`secret-box`,style:{marginTop:12},children:[(0,I.jsx)(`small`,{children:`Client ID`}),c?.clientId]}),(0,I.jsxs)(`div`,{className:`secret-box`,children:[(0,I.jsx)(`small`,{children:`Client Secret`}),c?.secret]}),(0,I.jsxs)(`button`,{className:`btn btn-sm`,style:{marginTop:4},onClick:()=>navigator.clipboard.writeText(c?.secret??``),children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,children:[(0,I.jsx)(`rect`,{x:`5`,y:`5`,width:`9`,height:`9`,rx:`1.5`}),(0,I.jsx)(`path`,{d:`M3.5 11H3a1.5 1.5 0 01-1.5-1.5V3A1.5 1.5 0 013 1.5h6.5A1.5 1.5 0 0111 3v.5`,strokeLinecap:`round`})]}),`Copy secret`]})]})]})}var iH=`ADMIN`;function aH({onEdit:e,onDelete:t,onUnavailable:n}){let[r,i]=(0,F.useState)(!1),{data:a,isLoading:o,error:s,refetch:c}=ut({...fc(),retry:(e,t)=>t&&typeof t==`object`&&`status`in t&&t.status===404?(r||(i(!0),n()),!1):e<1}),l=a?.data??[];return(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(yV,{isLoading:o,error:s&&!(typeof s==`object`&&`status`in s&&s.status===404)?s:void 0,onRetry:c,skeleton:(0,I.jsx)(EV,{rows:4,cols:4}),children:l.length===0?(0,I.jsxs)(`div`,{className:`empty-state`,children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,I.jsx)(`circle`,{cx:`12`,cy:`8`,r:`4`}),(0,I.jsx)(`path`,{d:`M2 20a10 10 0 0120 0`})]}),(0,I.jsx)(`h4`,{children:`No roles yet`}),(0,I.jsx)(`p`,{children:`Create roles to assign permissions to users`})]}):(0,I.jsx)(`div`,{className:`tbl-wrap`,children:(0,I.jsxs)(`table`,{children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`Name`}),(0,I.jsx)(`th`,{children:`Description`}),(0,I.jsx)(`th`,{children:`Type`}),(0,I.jsx)(`th`,{style:{width:80}})]})}),(0,I.jsx)(`tbody`,{children:l.map(n=>(0,I.jsxs)(`tr`,{style:{cursor:`default`},children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontWeight:600,color:n.name===iH?`var(--accent)`:`var(--text)`},children:n.name})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{color:`var(--muted)`,fontSize:12},children:n.description??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`badge ${`builtin`in n&&n.builtin?`badge-accent`:`badge-muted`}`,children:`builtin`in n&&n.builtin?`built-in`:`custom`})}),(0,I.jsx)(`td`,{className:`no-click`,style:{textAlign:`right`},children:(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6,justifyContent:`flex-end`},children:[(0,I.jsx)(`button`,{className:`btn btn-sm`,onClick:()=>e(n),children:`Edit`}),n.name!==iH&&(0,I.jsx)(`button`,{className:`btn btn-sm btn-danger`,onClick:()=>t(n),children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,children:(0,I.jsx)(`path`,{d:`M2 4.5h12M5.5 4.5V3h5v1.5M10.5 4.5v8a1 1 0 01-1 1h-3a1 1 0 01-1-1v-8`,strokeLinecap:`round`})})})]})})]},n.name))})]})})})})}function oH(){let e=Ic(),t=Ye(),n=V(),[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(null),[s,c]=(0,F.useState)({name:``,description:``}),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(!1),p=dt(pc());async function m(n){n.preventDefault(),u(!0);try{await p.mutateAsync({name:s.name.trim().toUpperCase(),description:s.description||void 0}),t.invalidateQueries({queryKey:H.admin.roles()}),e.success(`Role created`),i(!1),c({name:``,description:``})}catch(t){e.error(t instanceof Error?t.message:String(t))}finally{u(!1)}}async function h(r){if(r.preventDefault(),a){u(!0);try{await n.admin.roles.update(a.name,{description:s.description||void 0}),t.invalidateQueries({queryKey:H.admin.roles()}),e.success(`Role updated`),o(null)}catch(t){e.error(t instanceof Error?t.message:String(t))}finally{u(!1)}}}async function g(r){if(confirm(`Delete role ${r.name}?`))try{await n.admin.roles.remove(r.name),t.invalidateQueries({queryKey:H.admin.roles()}),e.success(`Role deleted`)}catch(t){e.error(t instanceof Error?t.message:String(t))}}return d?(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,style:{marginBottom:8},children:`Roles`}),(0,I.jsxs)(`div`,{className:`error-box`,children:[`Role catalog requires the `,(0,I.jsx)(`code`,{children:`auth_settings`}),` table (runtime settings). Run the migration to enable this feature.`]})]}):(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header-row`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,children:`Roles`}),(0,I.jsx)(`div`,{className:`page-sub`,children:`Global role catalog`})]}),(0,I.jsx)(`div`,{className:`page-actions`,children:(0,I.jsxs)(`button`,{className:`btn btn-primary`,onClick:()=>{c({name:``,description:``}),i(!0)},children:[(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M8 2v12M2 8h12`,strokeLinecap:`round`})}),`New Role`]})})]}),(0,I.jsx)(aH,{onEdit:e=>{o(e),c({name:e.name,description:e.description??``})},onDelete:g,onUnavailable:()=>f(!0)}),(0,I.jsx)(IV,{open:r,onClose:()=>i(!1),title:`New Role`,footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`btn`,onClick:()=>i(!1),children:`Cancel`}),(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:m,disabled:l,children:l?(0,I.jsx)(`span`,{className:`spinner sm`}):`Create Role`})]}),children:(0,I.jsxs)(`form`,{onSubmit:m,children:[(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Name * (uppercase)`}),(0,I.jsx)(`input`,{className:`input input-mono`,required:!0,value:s.name,onChange:e=>c(t=>({...t,name:e.target.value.toUpperCase()})),placeholder:`EDITOR`}),(0,I.jsx)(`div`,{className:`hint`,children:`Letters, digits, underscore. E.g. ADMIN, CONTENT_MANAGER`})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Description`}),(0,I.jsx)(`input`,{className:`input`,value:s.description,onChange:e=>c(t=>({...t,description:e.target.value})),placeholder:`Can edit content`})]})]})}),(0,I.jsx)(IV,{open:!!a,onClose:()=>o(null),title:`Edit Role — ${a?.name}`,footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`btn`,onClick:()=>o(null),children:`Cancel`}),(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:h,disabled:l,children:l?(0,I.jsx)(`span`,{className:`spinner sm`}):`Save`})]}),children:(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Description`}),(0,I.jsx)(`input`,{className:`input`,value:s.description,onChange:e=>c(t=>({...t,description:e.target.value}))})]})})]})}function sH({onPick:e,placeholder:t}){let[n,r]=(0,F.useState)(``),i=LV(n,250),a=ut({...Zs({search:i,limit:6}),enabled:i.trim().length>=2}),o=a.data?.data??[];return(0,I.jsxs)(`div`,{style:{position:`relative`},children:[(0,I.jsx)(`input`,{className:`input`,value:n,onChange:e=>r(e.target.value),placeholder:t??`Search user by email or name…`,autoFocus:!0}),i.trim().length>=2&&(0,I.jsx)(`div`,{style:{position:`absolute`,top:`100%`,left:0,right:0,zIndex:30,marginTop:4,background:`var(--panel, var(--bg))`,border:`1px solid var(--line)`,borderRadius:6,overflow:`hidden`,boxShadow:`0 8px 24px rgba(0,0,0,0.25)`},children:a.isLoading?(0,I.jsx)(`div`,{style:{padding:`8px 12px`,fontSize:12,color:`var(--faint)`},children:`Searching…`}):o.length===0?(0,I.jsx)(`div`,{style:{padding:`8px 12px`,fontSize:12,color:`var(--faint)`},children:`No users match.`}):o.map(t=>(0,I.jsxs)(`button`,{type:`button`,onClick:()=>e({id:t.id,email:t.email,name:t.name}),style:{display:`block`,width:`100%`,textAlign:`left`,padding:`8px 12px`,background:`none`,border:`none`,cursor:`pointer`,color:`var(--text)`,fontSize:12.5},onMouseEnter:e=>e.currentTarget.style.background=`var(--line)`,onMouseLeave:e=>e.currentTarget.style.background=`none`,children:[(0,I.jsx)(`span`,{style:{fontWeight:600},children:t.name??t.email}),t.name&&(0,I.jsx)(`span`,{style:{color:`var(--muted)`,marginLeft:8},children:t.email})]},t.id))})]})}function cH({user:e,onClear:t}){return(0,I.jsxs)(`span`,{className:`badge badge-muted`,style:{display:`inline-flex`,alignItems:`center`,gap:6},children:[e.name?`${e.name} · `:``,e.email,(0,I.jsx)(`button`,{type:`button`,onClick:t,style:{background:`none`,border:`none`,cursor:`pointer`,color:`inherit`,padding:0,lineHeight:1},"aria-label":`Clear selected user`,children:`×`})]})}function lH({label:e,hint:t,children:n}){return(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10},children:[(0,I.jsxs)(`div`,{style:{flex:1},children:[(0,I.jsx)(`div`,{style:{fontSize:12,fontWeight:500,color:`var(--text)`},children:e}),t&&(0,I.jsx)(`div`,{style:{fontSize:11,color:`var(--faint)`},children:t})]}),n]})}function uH({checked:e,onChange:t}){return(0,I.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e,onClick:()=>t(!e),style:{position:`relative`,width:36,height:20,borderRadius:999,border:`none`,cursor:`pointer`,background:e?`var(--accent)`:`var(--line)`,transition:`background 0.15s`},children:(0,I.jsx)(`span`,{style:{position:`absolute`,top:2,left:e?18:2,width:16,height:16,borderRadius:`50%`,background:`#fff`,transition:`left 0.15s`}})})}function dH({values:e,onChange:t,locked:n=[],placeholder:r}){let[i,a]=(0,F.useState)(``);function o(){let n=i.trim();!n||e.includes(n)||(t([...e,n]),a(``))}return(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:6},children:[(0,I.jsx)(`div`,{style:{display:`flex`,gap:6,flexWrap:`wrap`},children:e.map(r=>(0,I.jsxs)(`span`,{className:`badge badge-muted`,style:{display:`inline-flex`,alignItems:`center`,gap:5},children:[r,!n.includes(r)&&(0,I.jsx)(`button`,{type:`button`,onClick:()=>t(e.filter(e=>e!==r)),style:{background:`none`,border:`none`,cursor:`pointer`,color:`inherit`,padding:0,lineHeight:1},"aria-label":`Remove ${r}`,children:`×`})]},r))}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,I.jsx)(`input`,{className:`input`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),o())},placeholder:r??`add…`,style:{maxWidth:160}}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:o,children:`Add`})]})]})}var fH=[`organizations_policy`,`roles_catalog`],pH={organizations_policy:{en:`Organizations policy`,pt:`Política de organizações`},roles_catalog:{en:`Roles catalog`,pt:`Catálogo de papéis`}},mH=[`owner`,`admin`,`member`];function hH(e){let t=e??{};return{allowSelfCreate:!!t.allowSelfCreate,invitationTtlHours:Number(t.invitationTtlHours)||168,roles:Array.isArray(t.roles)&&t.roles.length?t.roles.map(String):mH}}function gH(e){let t=e??{};return{roles:(Array.isArray(t.roles)&&t.roles.length?t.roles:[{name:`ADMIN`,description:`Full access to the admin console`}]).map(e=>({name:String(e.name),description:e.description?String(e.description):void 0}))}}function _H({orgId:e}){let t=Ic(),n=Ye(),{data:r,isLoading:i}=ut({...Tc(e),retry:!1}),{data:a}=ut({...Tc(null),retry:!1}),o=dt(Ec(e)),s=dt(Dc(e)),[c,l]=(0,F.useState)(null),u=r?.data??[],d=a?.data??[];function f(e){return u.find(t=>t.key===e)??null}function p(e){return d.find(t=>t.key===e)??null}async function m(r,i){try{await o.mutateAsync({key:r,value:i}),n.invalidateQueries({queryKey:H.admin.settings(e)}),t.success(`Setting saved for this organization`),l(null)}catch(e){t.error(e instanceof Error?e.message:`Failed to save setting`)}}async function h(r){try{await s.mutateAsync(r),n.invalidateQueries({queryKey:H.admin.settings(e)}),t.success(`Organization setting removed (falls back to global)`)}catch(e){t.error(e instanceof Error?e.message:`Failed to remove setting`)}}return i?null:(0,I.jsxs)(`div`,{style:{borderTop:`1px solid var(--line)`,paddingTop:16},children:[(0,I.jsx)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:12},children:`Organization Settings`}),(0,I.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:fH.map(e=>{let t=f(e),n=p(e),r=pH[e],i=t?{text:`from org`,color:`var(--accent, #4f46e5)`}:n?{text:`from global`,color:`var(--muted)`}:{text:`default`,color:`var(--faint)`},a=c===e,u=t?.value??n?.value??null;return(0,I.jsxs)(`div`,{style:{background:`var(--surface, var(--bg))`,border:`1px solid var(--line)`,borderRadius:6,padding:`10px 12px`},children:[(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:a?10:0},children:[(0,I.jsxs)(`div`,{style:{flex:1},children:[(0,I.jsx)(`div`,{style:{fontSize:12,fontWeight:600,color:`var(--text)`},children:r.en}),(0,I.jsx)(`div`,{style:{fontSize:11,color:`var(--muted)`},children:r.pt})]}),(0,I.jsx)(`span`,{style:{fontSize:10,padding:`2px 6px`,borderRadius:4,background:`transparent`,border:`1px solid ${i.color}`,color:i.color,fontWeight:600},children:i.text}),!a&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>l(e),children:t?`Edit`:`Override`}),t&&(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>h(e),disabled:s.isPending,style:{color:`var(--danger, #e53e3e)`},title:`Remove org override (falls back to global)`,children:`Reset`})]})]}),e===`organizations_policy`&&(a?(0,I.jsx)(bH,{initial:hH(u),saving:o.isPending,onSave:t=>m(e,t),onCancel:()=>l(null)}):(0,I.jsx)(vH,{value:hH(u)})),e===`roles_catalog`&&(a?(0,I.jsx)(xH,{initial:gH(u),saving:o.isPending,onSave:t=>m(e,t),onCancel:()=>l(null)}):(0,I.jsx)(yH,{value:gH(u)}))]},e)})})]})}function vH({value:e}){return(0,I.jsxs)(`div`,{style:{marginTop:8,display:`flex`,gap:6,flexWrap:`wrap`},children:[(0,I.jsxs)(`span`,{className:`badge badge-muted`,children:[`self-create: `,e.allowSelfCreate?`on`:`off`]}),(0,I.jsxs)(`span`,{className:`badge badge-muted`,children:[`invite TTL: `,e.invitationTtlHours,`h`]}),e.roles.map(e=>(0,I.jsx)(`span`,{className:`badge badge-muted`,children:e},e))]})}function yH({value:e}){return(0,I.jsx)(`div`,{style:{marginTop:8,display:`flex`,gap:6,flexWrap:`wrap`},children:e.roles.map(e=>(0,I.jsx)(`span`,{className:`badge badge-muted`,title:e.description??``,children:e.name},e.name))})}function bH({initial:e,saving:t,onSave:n,onCancel:r}){let[i,a]=(0,F.useState)(e.allowSelfCreate),[o,s]=(0,F.useState)(e.invitationTtlHours),[c,l]=(0,F.useState)(e.roles);return(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,I.jsx)(lH,{label:`Allow self-create`,hint:`Members can create their own organizations`,children:(0,I.jsx)(uH,{checked:i,onChange:a})}),(0,I.jsx)(lH,{label:`Invitation TTL`,hint:`Hours before a pending invitation expires`,children:(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6},children:[(0,I.jsx)(`input`,{className:`input`,type:`number`,min:1,value:o,onChange:e=>s(Number(e.target.value)),style:{width:80}}),(0,I.jsx)(`span`,{style:{fontSize:11,color:`var(--faint)`},children:`h`})]})}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{style:{fontSize:12,fontWeight:500,color:`var(--text)`,marginBottom:6},children:`Organization roles`}),(0,I.jsx)(dH,{values:c,onChange:l,locked:[`owner`],placeholder:`new role…`})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,I.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,disabled:t,onClick:()=>n({allowSelfCreate:i,invitationTtlHours:o,roles:c}),children:t?`Saving…`:`Save`}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:r,children:`Cancel`})]})]})}function xH({initial:e,saving:t,onSave:n,onCancel:r}){let[i,a]=(0,F.useState)(e.roles.map(e=>({name:e.name,description:e.description??``}))),[o,s]=(0,F.useState)(``),[c,l]=(0,F.useState)(``);function u(){let e=o.trim().toUpperCase();!e||i.some(t=>t.name===e)||(a([...i,{name:e,description:c.trim()}]),s(``),l(``))}return(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[i.map((e,t)=>(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6,alignItems:`center`},children:[(0,I.jsx)(`span`,{className:`badge badge-muted`,style:{minWidth:70,justifyContent:`center`},children:e.name}),(0,I.jsx)(`input`,{className:`input`,value:e.description,onChange:e=>a(i.map((n,r)=>r===t?{...n,description:e.target.value}:n)),placeholder:`description…`,style:{flex:1}}),e.name!==`ADMIN`&&(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,style:{color:`var(--danger, #e53e3e)`},onClick:()=>a(i.filter((e,n)=>n!==t)),children:`×`})]},e.name)),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,I.jsx)(`input`,{className:`input`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),u())},placeholder:`ROLE_NAME`,style:{width:130}}),(0,I.jsx)(`input`,{className:`input`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),u())},placeholder:`description…`,style:{flex:1}}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:u,children:`Add`})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,I.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,disabled:t,onClick:()=>n({roles:i.map(e=>({name:e.name,description:e.description||void 0}))}),children:t?`Saving…`:`Save`}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:r,children:`Cancel`})]})]})}function SH({value:e,onChange:t}){return(0,I.jsx)(`select`,{className:`input`,value:e,onChange:e=>t(e.target.value),style:{width:110},children:(mH.includes(e)?mH:[...mH,e]).map(e=>(0,I.jsx)(`option`,{value:e,children:e},e))})}function CH({orgId:e,onDone:t}){let n=Ic(),r=Ye(),[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(`member`),c=dt(yc(e));async function l(a){if(a.preventDefault(),i)try{await c.mutateAsync({accountId:i.id,role:o}),r.invalidateQueries({queryKey:H.admin.org(e)}),r.invalidateQueries({queryKey:H.admin.orgs()}),n.success(`${i.email} added as ${o}`),t()}catch(e){n.error(e instanceof Error?e.message:`Failed to add member`)}}return(0,I.jsx)(`form`,{onSubmit:l,style:{display:`flex`,flexDirection:`column`,gap:8},children:i?(0,I.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,flexWrap:`wrap`},children:[(0,I.jsx)(cH,{user:i,onClear:()=>a(null)}),(0,I.jsx)(SH,{value:o,onChange:s}),(0,I.jsx)(`button`,{type:`submit`,className:`btn btn-primary btn-sm`,disabled:c.isPending,children:c.isPending?`Adding…`:`Add member`}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:t,children:`Cancel`})]}):(0,I.jsxs)(`div`,{children:[(0,I.jsx)(sH,{onPick:a}),(0,I.jsx)(`div`,{style:{marginTop:6,display:`flex`,justifyContent:`flex-end`},children:(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:t,children:`Cancel`})})]})})}function wH({orgId:e,onDone:t}){let n=Ic(),r=Ye(),[i,a]=(0,F.useState)(``),[o,s]=(0,F.useState)(`member`),c=dt(Sc(e));async function l(s){if(s.preventDefault(),i.trim())try{await c.mutateAsync({email:i.trim(),role:o}),r.invalidateQueries({queryKey:H.admin.org(e)}),n.success(`Invitation sent`),a(``),t()}catch(e){n.error(e instanceof Error?e.message:`Failed to create invitation`)}}return(0,I.jsxs)(`form`,{onSubmit:l,style:{display:`flex`,gap:8,alignItems:`flex-end`,flexWrap:`wrap`},children:[(0,I.jsxs)(`div`,{style:{flex:1,minWidth:180},children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Email`}),(0,I.jsx)(`input`,{className:`input`,type:`email`,value:i,onChange:e=>a(e.target.value),placeholder:`user@example.com`,required:!0})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Role`}),(0,I.jsx)(SH,{value:o,onChange:s})]}),(0,I.jsx)(`button`,{type:`submit`,className:`btn btn-primary btn-sm`,disabled:c.isPending,children:c.isPending?`Sending…`:`Invite`}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:t,children:`Cancel`})]})}function TH({orgId:e,member:t}){let n=Ic(),r=Ye(),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(t.role),c=dt(bc(e,t.accountId)),l=dt(xc(e,t.accountId));async function u(){try{await c.mutateAsync(),r.invalidateQueries({queryKey:H.admin.org(e)}),r.invalidateQueries({queryKey:H.admin.orgs()}),n.success(`Member removed`)}catch(e){n.error(e instanceof Error?e.message:`Failed to remove member`)}}async function d(t){t.preventDefault();try{await l.mutateAsync(o),r.invalidateQueries({queryKey:H.admin.org(e)}),n.success(`Role updated`),a(!1)}catch(e){n.error(e instanceof Error?e.message:`Failed to update role`)}}return(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`6px 0`,borderBottom:`1px solid var(--line)`},children:[(0,I.jsx)(`div`,{className:`avatar`,style:{width:24,height:24,fontSize:9},children:(t.email??`?`).slice(0,2).toUpperCase()}),(0,I.jsx)(`div`,{style:{flex:1},children:(0,I.jsx)(`div`,{style:{fontSize:12,color:`var(--text)`},children:t.email??t.accountId})}),i?(0,I.jsxs)(`form`,{onSubmit:d,style:{display:`flex`,gap:4},children:[(0,I.jsx)(`input`,{className:`input`,value:o,onChange:e=>s(e.target.value),style:{width:80,padding:`2px 6px`,fontSize:11}}),(0,I.jsx)(`button`,{type:`submit`,className:`btn btn-primary btn-sm`,disabled:l.isPending,children:`✓`}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>a(!1),children:`✕`})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`badge badge-muted`,title:`Click to change role`,onClick:()=>a(!0),style:{cursor:`pointer`,background:`none`,border:`1px solid var(--line)`},children:t.role}),(0,I.jsx)(`button`,{className:`icon-btn`,title:`Remove member`,onClick:u,disabled:c.isPending,style:{color:`var(--danger, #e53e3e)`,fontSize:13},children:`✕`})]})]})}function EH({orgId:e,invitation:t}){let n=Ic(),r=Ye(),i=dt(Cc(e,t.id));async function a(){try{await i.mutateAsync(),r.invalidateQueries({queryKey:H.admin.org(e)}),n.success(`Invitation revoked`)}catch(e){n.error(e instanceof Error?e.message:`Failed to revoke invitation`)}}return(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`6px 0`,borderBottom:`1px solid var(--line)`},children:[(0,I.jsx)(`div`,{style:{flex:1,fontSize:12,color:`var(--muted)`},children:t.email}),(0,I.jsx)(`span`,{className:`badge badge-amber`,children:t.role}),(0,I.jsx)(`button`,{className:`icon-btn`,title:`Revoke invitation`,onClick:a,disabled:i.isPending,style:{color:`var(--danger, #e53e3e)`,fontSize:13},children:`✕`})]})}var DH=20;function OH(e){return e.toLowerCase().normalize(`NFD`).replace(/[̀-ͯ]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function kH({open:e,onClose:t,onCreated:n}){let r=Ic(),i=Ye(),[a,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(null),p=dt(gc());function m(e){o(e),l||c(OH(e))}async function h(e){if(e.preventDefault(),!(!a.trim()||!s.trim()||!d))try{await p.mutateAsync({name:a.trim(),slug:s.trim(),ownerAccountId:d.id}),i.invalidateQueries({queryKey:H.admin.orgs()}),r.success(`Organization created`),o(``),c(``),f(null),u(!1),n()}catch(e){r.error(e instanceof Error?e.message:`Failed to create organization`)}}return e?(0,I.jsx)(`div`,{className:`modal-backdrop`,onClick:t,children:(0,I.jsxs)(`div`,{className:`modal`,onClick:e=>e.stopPropagation(),children:[(0,I.jsxs)(`div`,{className:`modal-head`,children:[(0,I.jsx)(`span`,{children:`New Organization`}),(0,I.jsx)(`button`,{className:`icon-btn`,onClick:t,children:`✕`})]}),(0,I.jsxs)(`form`,{onSubmit:h,style:{display:`flex`,flexDirection:`column`,gap:14},children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Name`}),(0,I.jsx)(`input`,{className:`input`,value:a,onChange:e=>m(e.target.value),placeholder:`Acme Inc.`,required:!0})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Slug`}),(0,I.jsx)(`input`,{className:`input`,value:s,onChange:e=>{c(e.target.value),u(!0)},placeholder:`acme-inc`,required:!0})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Owner`}),d?(0,I.jsx)(cH,{user:d,onClear:()=>f(null)}):(0,I.jsx)(sH,{onPick:f,placeholder:`Search the initial owner by email…`})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:8,justifyContent:`flex-end`,marginTop:4},children:[(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:t,children:`Cancel`}),(0,I.jsx)(`button`,{type:`submit`,className:`btn btn-primary`,disabled:p.isPending,children:p.isPending?`Creating…`:`Create`})]})]})]})}):null}function AH({search:e,page:t,onPage:n,onSelectOrg:r,onUnavailable:i,onCreateClick:a}){let[o,s]=(0,F.useState)(!1),{data:c,isLoading:l,error:u,refetch:d}=ut({...mc(),retry:(e,t)=>t&&typeof t==`object`&&`status`in t&&t.status===404?(o||(s(!0),i()),!1):e<1}),f=c?.data??[],p=e?f.filter(t=>t.name.toLowerCase().includes(e.toLowerCase())||t.slug.toLowerCase().includes(e.toLowerCase())):f,m=p.length,h=p.slice((t-1)*DH,t*DH),g=u&&typeof u==`object`&&`status`in u&&u.status===404;return(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(yV,{isLoading:l,error:u&&!g?u:void 0,onRetry:d,skeleton:(0,I.jsx)(EV,{rows:6,cols:4}),children:h.length===0?(0,I.jsxs)(`div`,{className:`empty-state`,children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,I.jsx)(`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1`}),(0,I.jsx)(`rect`,{x:`3`,y:`14`,width:`7`,height:`7`,rx:`1`}),(0,I.jsx)(`rect`,{x:`14`,y:`3`,width:`7`,height:`7`,rx:`1`}),(0,I.jsx)(`path`,{d:`M17.5 14v7M14 17.5h7`,strokeLinecap:`round`})]}),(0,I.jsx)(`h4`,{children:`No organizations`}),(0,I.jsx)(`p`,{children:e?`No results for your search`:`No organizations created yet`}),!e&&(0,I.jsx)(`button`,{className:`btn btn-primary`,style:{marginTop:12},onClick:a,children:`New organization`})]}):(0,I.jsxs)(`div`,{className:`tbl-wrap`,children:[(0,I.jsxs)(`table`,{children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`Name`}),(0,I.jsx)(`th`,{children:`Slug`}),(0,I.jsx)(`th`,{children:`Members`}),(0,I.jsx)(`th`,{children:`Created`})]})}),(0,I.jsx)(`tbody`,{children:h.map(e=>(0,I.jsxs)(`tr`,{onClick:()=>r(e.id),children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(`b`,{children:e.name})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`code`,children:e.slug})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`mono text-sm`,children:e.memberCount??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:11,color:`var(--faint)`},children:e.createdAt?new Date(e.createdAt).toLocaleDateString():`—`})})]},e.id))})]}),(0,I.jsx)(`div`,{style:{padding:`0 16px 12px`},children:(0,I.jsx)(zV,{page:t,total:m,perPage:DH,onPage:n})})]})})})}function jH({orgId:e,currentName:t,currentLogoUrl:n,onDone:r}){let i=Ic(),a=Ye(),[o,s]=(0,F.useState)(t),[c,l]=(0,F.useState)(n??``),u=dt(_c(e));async function d(t){t.preventDefault();try{await u.mutateAsync({name:o.trim()||void 0,logoUrl:c.trim()||null}),a.invalidateQueries({queryKey:H.admin.orgs()}),a.invalidateQueries({queryKey:H.admin.org(e)}),i.success(`Organization updated`),r()}catch(e){i.error(e instanceof Error?e.message:`Failed to update organization`)}}return(0,I.jsxs)(`form`,{onSubmit:d,style:{display:`flex`,flexDirection:`column`,gap:10},children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Name`}),(0,I.jsx)(`input`,{className:`input`,value:o,onChange:e=>s(e.target.value)})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Logo URL`}),(0,I.jsx)(`input`,{className:`input`,value:c,onChange:e=>l(e.target.value),placeholder:`https://…`})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,I.jsx)(`button`,{type:`submit`,className:`btn btn-primary btn-sm`,disabled:u.isPending,children:u.isPending?`Saving…`:`Save`}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:r,children:`Cancel`})]})]})}function MH({orgId:e,onDeleted:t}){let n=Ic(),r=Ye(),{data:i,isLoading:a,error:o,refetch:s}=ut(hc(e)),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(!1),[m,h]=(0,F.useState)(!1),g=dt(vc(e));async function _(){try{await g.mutateAsync(),r.invalidateQueries({queryKey:H.admin.orgs()}),n.success(`Organization deleted`),t()}catch(e){n.error(e instanceof Error?e.message:`Failed to delete organization`)}}return(0,I.jsx)(yV,{isLoading:a,error:o,onRetry:s,skeleton:(0,I.jsx)(DV,{}),children:i&&(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:20},children:[(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:8,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,I.jsx)(`span`,{children:`Info`}),!c&&(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>l(!0),children:`Edit`})]}),c?(0,I.jsx)(jH,{orgId:e,currentName:i.name,currentLogoUrl:i.logoUrl,onDone:()=>l(!1)}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`code`,children:i.id}),(0,I.jsx)(`div`,{style:{marginTop:6,fontSize:12},children:(0,I.jsx)(`span`,{className:`badge badge-muted`,children:i.slug})})]})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:8,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,I.jsxs)(`span`,{children:[`Members (`,i.members.length,`)`]}),!u&&(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>d(!0),children:`+ Add`})]}),u&&(0,I.jsx)(`div`,{style:{marginBottom:10},children:(0,I.jsx)(CH,{orgId:e,onDone:()=>d(!1)})}),i.members.map(t=>(0,I.jsx)(TH,{orgId:e,member:t},t.accountId))]}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:8,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,I.jsxs)(`span`,{children:[`Pending Invitations (`,i.pendingInvitations.length,`)`]}),!f&&(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>p(!0),children:`+ Invite`})]}),f&&(0,I.jsx)(`div`,{style:{marginBottom:10},children:(0,I.jsx)(wH,{orgId:e,onDone:()=>p(!1)})}),i.pendingInvitations.length===0&&!f&&(0,I.jsx)(`div`,{style:{fontSize:12,color:`var(--faint)`},children:`No pending invitations`}),i.pendingInvitations.map(t=>(0,I.jsx)(EH,{orgId:e,invitation:t},t.id))]}),(0,I.jsx)(_H,{orgId:e}),(0,I.jsxs)(`div`,{style:{borderTop:`1px solid var(--line)`,paddingTop:16},children:[(0,I.jsx)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--danger, #e53e3e)`,fontWeight:600,marginBottom:8},children:`Danger Zone`}),m?(0,I.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,fontSize:13},children:[(0,I.jsx)(`span`,{style:{color:`var(--muted)`},children:`Delete this organization?`}),(0,I.jsx)(`button`,{className:`btn btn-danger btn-sm`,onClick:_,disabled:g.isPending,children:g.isPending?`Deleting…`:`Yes, delete`}),(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>h(!1),children:`Cancel`})]}):(0,I.jsx)(`button`,{className:`btn btn-danger btn-sm`,onClick:()=>h(!0),children:`Delete organization`})]})]})})}function NH({orgId:e,onClose:t}){let{data:n}=ut(hc(e));return(0,I.jsx)(RV,{open:!0,onClose:t,title:n?.name??`Organization`,children:(0,I.jsx)(MH,{orgId:e,onDeleted:t})})}function PH(e){let{data:t}=ut(mc()),n=t?.data??[];return(e?n.filter(t=>t.name.toLowerCase().includes(e.toLowerCase())||t.slug.toLowerCase().includes(e.toLowerCase())):n).length}function FH(){let[e,t]=Jc(`page`,Bc.withDefault(1)),[n,r]=Jc(`q`,zc.withDefault(``)),[i,a]=Jc(`org`),o=LV(n,300),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(!1),d=PH(o);return s?(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,style:{marginBottom:8},children:`Organizations`}),(0,I.jsx)(`div`,{className:`error-box`,children:`Organizations are not enabled in this AuthKit installation.`})]}):(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header-row`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,children:`Organizations`}),(0,I.jsxs)(`div`,{className:`page-sub`,children:[d.toLocaleString(),` orgs`]})]}),(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:()=>u(!0),children:`New organization`})]}),(0,I.jsx)(`div`,{className:`panel`,style:{marginBottom:0},children:(0,I.jsx)(`div`,{className:`panel-head`,children:(0,I.jsxs)(`div`,{className:`search-input`,style:{flex:1,maxWidth:300},children:[(0,I.jsxs)(`svg`,{className:`search-ico`,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,children:[(0,I.jsx)(`circle`,{cx:`7`,cy:`7`,r:`4.5`}),(0,I.jsx)(`path`,{d:`M10 10l3 3`,strokeLinecap:`round`})]}),(0,I.jsx)(`input`,{className:`input`,placeholder:`Search organizations…`,value:n,onChange:e=>{r(e.target.value),t(1)}})]})})}),(0,I.jsx)(AH,{search:o,page:e,onPage:t,onSelectOrg:a,onUnavailable:()=>c(!0),onCreateClick:()=>u(!0)}),i&&(0,I.jsx)(NH,{orgId:i,onClose:()=>a(null)}),(0,I.jsx)(kH,{open:l,onClose:()=>u(!1),onCreated:()=>u(!1)})]})}function IH(e){return e.includes(`login`)||e.includes(`signin`)||e.includes(`success`)?`badge-green`:e.includes(`fail`)||e.includes(`error`)||e.includes(`locked`)||e.includes(`block`)?`badge-red`:e.includes(`register`)||e.includes(`signup`)||e.includes(`created`)?`badge-accent`:e.includes(`settings`)||e.includes(`admin`)||e.includes(`updated`)?`badge-amber`:`badge-muted`}var LH=30;function RH({typeFilter:e,page:t,onPage:n,selected:r,onSelect:i,onUnavailable:a}){let[o,s]=(0,F.useState)(!1),{data:c,isLoading:l,error:u,refetch:d}=ut({...wc({type:e||void 0,page:t,limit:LH}),retry:(e,t)=>t&&typeof t==`object`&&`status`in t&&t.status===404?(o||(s(!0),a()),!1):e<1}),f=c?.data??[],p=c?.total??0,m=u&&typeof u==`object`&&`status`in u&&u.status===404;return(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(yV,{isLoading:l,error:u&&!m?u:void 0,onRetry:d,skeleton:(0,I.jsx)(EV,{rows:8,cols:4}),children:f.length===0?(0,I.jsxs)(`div`,{className:`empty-state`,children:[(0,I.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:(0,I.jsx)(`path`,{d:`M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2`,strokeLinecap:`round`})}),(0,I.jsx)(`h4`,{children:`No events found`}),(0,I.jsx)(`p`,{children:e?`No events match this filter`:`No audit events recorded yet`})]}):(0,I.jsxs)(`div`,{className:`tbl-wrap`,children:[(0,I.jsxs)(`table`,{children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`Type`}),(0,I.jsx)(`th`,{children:`Account`}),(0,I.jsx)(`th`,{children:`IP`}),(0,I.jsx)(`th`,{children:`When`})]})}),(0,I.jsx)(`tbody`,{children:f.map(e=>(0,I.jsxs)(`tr`,{onClick:()=>i(r?.id===e.id?null:e),children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`badge ${IH(e.type)}`,children:e.type})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:11.5},children:e.email??e.accountId??(0,I.jsx)(`span`,{style:{color:`var(--faint)`},children:`—`})})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`code`,children:e.ip??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:11,color:`var(--faint)`},children:e.createdAt?new Date(e.createdAt).toLocaleString():`—`})})]},e.id))})]}),(0,I.jsx)(`div`,{style:{padding:`0 16px 12px`},children:(0,I.jsx)(zV,{page:t,total:p,perPage:LH,onPage:n})})]})})})}function zH({event:e,onClose:t}){return(0,I.jsxs)(`div`,{className:`panel`,style:{padding:`14px 16px`},children:[(0,I.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:10},children:[(0,I.jsx)(`div`,{style:{fontWeight:600,fontSize:13},children:`Event Detail`}),(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:t,children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M3 3l10 10M13 3L3 13`,strokeLinecap:`round`})})})]}),(0,I.jsx)(`pre`,{style:{fontFamily:`var(--mono)`,fontSize:11.5,color:`var(--muted)`,overflow:`auto`,lineHeight:1.6},children:JSON.stringify(e,null,2)})]})}var BH=[``,`login.success`,`login.failed`,`login.mfa_required`,`logout`,`register`,`password_reset`,`settings.updated`,`client.created`,`client.deleted`,`account.disabled`,`account.enabled`];function VH(){let[e,t]=Jc(`page`,Bc.withDefault(1)),[n,r]=Jc(`type`,zc.withDefault(``)),[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(!1);return o?(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,style:{marginBottom:8},children:`Audit Log`}),(0,I.jsx)(`div`,{className:`error-box`,children:`Audit log is not configured. Add an audit sink to your AuthKit config.`})]}):(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-header-row`,children:(0,I.jsx)(`div`,{children:(0,I.jsx)(`div`,{className:`page-title`,children:`Audit Log`})})}),(0,I.jsx)(`div`,{className:`panel`,style:{marginBottom:0},children:(0,I.jsx)(`div`,{className:`panel-head`,children:(0,I.jsx)(`select`,{className:`input`,style:{width:240},value:n,onChange:e=>{r(e.target.value),t(1)},children:BH.map(e=>(0,I.jsx)(`option`,{value:e,children:e||`All event types`},e))})})}),(0,I.jsx)(RH,{typeFilter:n,page:e,onPage:t,selected:i,onSelect:a,onUnavailable:()=>s(!0)}),i&&(0,I.jsx)(`div`,{style:{marginTop:12},children:(0,I.jsx)(zH,{event:i,onClose:()=>a(null)})})]})}function HH(){let e=Ic(),t=Ye(),{data:n,isLoading:r,error:i,refetch:a}=ut({...kc(),retry:(e,t)=>t&&typeof t==`object`&&`status`in t&&t.status===501?!1:e<1}),o=dt(Ac()),s=dt(Ec()),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(null),m=i&&typeof i==`object`&&`status`in i&&i.status===501;if(m)return(0,I.jsxs)(`div`,{className:`error-box`,children:[`Rotação indisponível: o `,(0,I.jsx)(`code`,{children:`jwks`}),` não é `,(0,I.jsx)(`code`,{children:`managed`}),` com um `,(0,I.jsx)(`code`,{children:`store`}),` persistente (ex.: `,(0,I.jsx)(`code`,{children:`{ source: 'managed', store: { driver: 'lucid' } }`}),`). Chaves inline (`,(0,I.jsx)(`code`,{children:`source: 'jwks'`}),`) não rotacionam.`]});let h=n?.policy,g=c??h?.maxAgeDays??90,_=u??h?.keep??2;async function v(n){p(`policy`);try{let r={enabled:n.enabled??h?.enabled??!1,maxAgeDays:n.maxAgeDays??g,keep:n.keep??_};await s.mutateAsync({key:`key_rotation`,value:r}),t.invalidateQueries({queryKey:H.admin.keys()}),l(null),d(null),e.success(`Política de rotação salva`)}catch(t){e.error(t instanceof Error?t.message:String(t))}finally{p(null)}}async function y(n){let r=n?`Isso DESABILITA todas as chaves atuais e cria uma nova. Tokens já emitidos deixam de validar imediatamente. Continuar?`:`Rotacionar agora? Uma chave nova vira a ativa; as antigas continuam validando (janela de grace).`;if(window.confirm(r)){p(n?`retire`:`rotate`);try{let r=await o.mutateAsync(n?{retire:!0}:{keep:_});t.invalidateQueries({queryKey:H.admin.keys()}),e.success(`Rotacionado. Nova chave: ${r.newKid.slice(0,8)}…`)}catch(t){e.error(t instanceof Error?t.message:String(t))}finally{p(null)}}}return(0,I.jsx)(yV,{isLoading:r,error:m?void 0:i,onRetry:a,skeleton:(0,I.jsx)(xV,{width:`100%`,height:220}),children:n&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`panel`,style:{marginBottom:16},children:(0,I.jsx)(`div`,{className:`panel-body`,children:(0,I.jsxs)(`div`,{className:`settings-row`,children:[(0,I.jsxs)(`div`,{className:`settings-info`,children:[(0,I.jsx)(`div`,{className:`settings-key`,children:`Chave de assinatura ativa`}),(0,I.jsx)(`div`,{style:{fontFamily:`var(--mono)`,fontSize:12},children:n.keys.find(e=>e.active)?.kid??`—`})]}),(0,I.jsxs)(`div`,{className:`settings-info`,style:{textAlign:`right`},children:[(0,I.jsxs)(`div`,{className:`settings-desc`,children:[`Idade: `,n.ageDays,` dia(s)`]}),(0,I.jsxs)(`div`,{className:`settings-desc`,children:[`Próxima rotação: `,n.nextRotationInDays===null?`— (auto off)`:`~${n.nextRotationInDays} dia(s)`]})]})]})})}),(0,I.jsxs)(`div`,{className:`settings-section`,children:[(0,I.jsx)(`div`,{className:`settings-section-head`,children:(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{children:`Rotação automática`}),(0,I.jsx)(`p`,{style:{marginTop:2},children:`Gera uma chave nova quando a ativa passa da idade máxima; mantém as N mais recentes (janela de grace).`})]})}),(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsxs)(`div`,{className:`panel-body`,style:{padding:0},children:[(0,I.jsxs)(`div`,{className:`settings-row`,children:[(0,I.jsxs)(`div`,{className:`settings-info`,children:[(0,I.jsx)(`div`,{className:`settings-key`,children:`Habilitar rotação agendada`}),(0,I.jsx)(`div`,{className:`settings-desc`,children:`key_rotation.enabled`})]}),(0,I.jsx)(`div`,{className:`settings-control`,children:(0,I.jsxs)(`label`,{className:`toggle`,children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:!!h?.enabled,disabled:f===`policy`,onChange:e=>v({enabled:e.target.checked})}),(0,I.jsx)(`div`,{className:`toggle-track`}),(0,I.jsx)(`div`,{className:`toggle-thumb`})]})})]}),(0,I.jsxs)(`div`,{className:`settings-row`,children:[(0,I.jsxs)(`div`,{className:`settings-info`,children:[(0,I.jsx)(`div`,{className:`settings-key`,children:`Idade máxima (dias)`}),(0,I.jsx)(`div`,{className:`settings-desc`,children:`key_rotation.maxAgeDays`})]}),(0,I.jsxs)(`div`,{className:`settings-control`,children:[(0,I.jsx)(`input`,{className:`input input-mono`,type:`number`,style:{width:90,textAlign:`right`},value:String(g),onChange:e=>l(Number(e.target.value))}),c!==null&&(0,I.jsx)(`button`,{className:`btn btn-primary btn-sm`,disabled:f===`policy`,onClick:()=>v({maxAgeDays:g}),children:`Save`})]})]}),(0,I.jsxs)(`div`,{className:`settings-row`,children:[(0,I.jsxs)(`div`,{className:`settings-info`,children:[(0,I.jsx)(`div`,{className:`settings-key`,children:`Manter N chaves (grace)`}),(0,I.jsx)(`div`,{className:`settings-desc`,children:`key_rotation.keep`})]}),(0,I.jsxs)(`div`,{className:`settings-control`,children:[(0,I.jsx)(`input`,{className:`input input-mono`,type:`number`,style:{width:90,textAlign:`right`},value:String(_),onChange:e=>d(Number(e.target.value))}),u!==null&&(0,I.jsx)(`button`,{className:`btn btn-primary btn-sm`,disabled:f===`policy`,onClick:()=>v({keep:_}),children:`Save`})]})]})]})})]}),(0,I.jsxs)(`div`,{className:`settings-section`,children:[(0,I.jsx)(`div`,{className:`settings-section-head`,children:(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{children:`Chaves no keyset`}),(0,I.jsx)(`p`,{style:{marginTop:2},children:`A primeira é a ativa (assina); as demais ainda validam tokens (grace).`})]})}),(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(`div`,{className:`panel-body`,style:{padding:0},children:n.keys.map(e=>(0,I.jsx)(`div`,{className:`settings-row`,children:(0,I.jsxs)(`div`,{className:`settings-info`,children:[(0,I.jsxs)(`div`,{className:`settings-key`,style:{fontFamily:`var(--mono)`,fontSize:12},children:[e.kid,(0,I.jsx)(`span`,{className:`settings-badge`,style:e.active?{background:`var(--accent-soft, rgba(99,102,241,0.12))`,color:`var(--accent, #6366f1)`}:void 0,children:e.active?`ativa`:`grace`})]}),(0,I.jsxs)(`div`,{className:`settings-desc`,children:[e.alg,` · `,e.ageDays,` dia(s)`]})]})},e.kid))})})]}),(0,I.jsxs)(`div`,{className:`settings-section`,children:[(0,I.jsx)(`div`,{className:`settings-section-head`,children:(0,I.jsx)(`div`,{children:(0,I.jsx)(`h3`,{children:`Ações`})})}),(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsxs)(`div`,{className:`panel-body`,style:{display:`flex`,gap:12,flexWrap:`wrap`},children:[(0,I.jsx)(`button`,{className:`btn btn-primary`,disabled:!!f,onClick:()=>y(!1),children:f===`rotate`?(0,I.jsx)(`span`,{className:`spinner sm`}):`Rotacionar agora`}),(0,I.jsx)(`button`,{className:`btn btn-ghost`,disabled:!!f,onClick:()=>y(!0),style:{color:`var(--danger, #e5484d)`,borderColor:`var(--danger, #e5484d)`},children:f===`retire`?(0,I.jsx)(`span`,{className:`spinner sm`}):`Desabilitar todas + criar nova`})]})})]})]})})}function UH(){return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header`,children:[(0,I.jsx)(`div`,{className:`page-title`,children:`Signing Keys`}),(0,I.jsx)(`div`,{className:`page-sub`,children:`Chaves JWKS de assinatura — rotação, grace e status. Mudanças aplicam ao vivo.`})]}),(0,I.jsx)(HH,{})]})}function WH({rowCount:e=4}){return(0,I.jsx)(`div`,{style:{background:`var(--bg2)`,border:`1px solid var(--line)`,borderRadius:`var(--radius)`,overflow:`hidden`},children:Array.from({length:e}).map((t,n)=>(0,I.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,padding:`14px 16px`,borderBottom:n<e-1?`1px solid var(--line)`:void 0,gap:16},children:[(0,I.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,gap:6},children:[(0,I.jsx)(xV,{width:`40%`,height:13}),(0,I.jsx)(xV,{width:`70%`,height:11})]}),(0,I.jsx)(xV,{width:44,height:24,borderRadius:12})]},n))})}function GH({section:e,onUnavailable:t}){let n=Ic(),r=Ye(),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)({}),[c,l]=(0,F.useState)(new Set),[u,d]=(0,F.useState)({}),{data:f,isLoading:p,error:m,refetch:h}=ut({...Tc(),retry:(e,n)=>n&&typeof n==`object`&&`status`in n&&n.status===404?(i||(a(!0),t()),!1):e<1}),g=f?.data??[],_=f?.locked??[];(0,F.useEffect)(()=>{if(!f)return;let e={};for(let t of f.data)e[t.key]=t.value;s(e),l(new Set)},[f]);let v=dt(Ec()),y=dt(Dc());function b(e,t){if(e in o)return o[e];let n=g.find(t=>t.key===e);return n?n.value:t.defaultValue}function x(e){return!g.some(t=>t.key===e)}function S(e,t){s(n=>({...n,[e]:t})),l(t=>new Set([...t,e]))}async function C(e){d(t=>({...t,[e]:!0}));try{let t=o[e];await v.mutateAsync({key:e,value:t}),r.invalidateQueries({queryKey:H.admin.settings()}),l(t=>{let n=new Set(t);return n.delete(e),n}),n.success(`Saved: ${e}`)}catch(e){n.error(e instanceof Error?e.message:String(e))}finally{d(t=>({...t,[e]:!1}))}}async function w(e){d(t=>({...t,[e]:!0}));try{await y.mutateAsync(e),r.invalidateQueries({queryKey:H.admin.settings()}),s(t=>{let n={...t};return delete n[e],n}),l(t=>{let n=new Set(t);return n.delete(e),n}),n.success(`Reset to default: ${e}`)}catch(e){n.error(e instanceof Error?e.message:String(e))}finally{d(t=>({...t,[e]:!1}))}}let T=m&&typeof m==`object`&&`status`in m&&m.status===404,E=m&&!T?m:void 0;return(0,I.jsxs)(`div`,{className:`settings-section`,children:[(0,I.jsx)(`div`,{className:`settings-section-head`,children:(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{children:e.title}),(0,I.jsx)(`p`,{style:{marginTop:2},children:e.description})]})}),(0,I.jsx)(yV,{isLoading:p,error:E,onRetry:h,skeleton:(0,I.jsx)(WH,{rowCount:e.keys.length}),children:(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(`div`,{className:`panel-body`,style:{padding:0},children:e.keys.map(e=>{let t=b(e.key,e),n=x(e.key),r=c.has(e.key),i=u[e.key],a=_.includes(e.key);return(0,I.jsxs)(`div`,{className:`settings-row`,style:a?{opacity:.85}:void 0,children:[(0,I.jsxs)(`div`,{className:`settings-info`,children:[(0,I.jsxs)(`div`,{className:`settings-key`,children:[e.label,a?(0,I.jsxs)(`span`,{className:`settings-badge`,title:`Definido via defineConfig() — gerenciado no código, não editável aqui`,style:{background:`var(--accent-soft, rgba(99,102,241,0.12))`,color:`var(--accent, #6366f1)`,borderColor:`rgba(99,102,241,0.3)`,display:`inline-flex`,alignItems:`center`,gap:4},children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 16 16`,width:`10`,height:`10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,"aria-hidden":!0,children:[(0,I.jsx)(`rect`,{x:`3`,y:`7`,width:`10`,height:`7`,rx:`1.5`}),(0,I.jsx)(`path`,{d:`M5 7V5a3 3 0 016 0v2`,strokeLinecap:`round`})]}),`definido via config`]}):(0,I.jsx)(`span`,{className:`settings-badge`,children:n?`default`:`custom`}),r&&!a&&(0,I.jsx)(`span`,{className:`settings-badge`,style:{background:`var(--amber-soft)`,color:`var(--amber)`,borderColor:`rgba(255,180,84,0.3)`},children:`unsaved`})]}),(0,I.jsx)(`div`,{className:`settings-desc`,children:e.description}),a&&(0,I.jsxs)(`div`,{className:`settings-desc`,style:{color:`var(--accent, #6366f1)`,marginTop:2},children:[`Travado no `,(0,I.jsx)(`code`,{children:`defineConfig()`}),`. Remova de lá para editar pela UI.`]}),(0,I.jsx)(`div`,{style:{fontSize:10.5,color:`var(--faint)`,fontFamily:`var(--mono)`,marginTop:2},children:e.key})]}),(0,I.jsxs)(`div`,{className:`settings-control`,children:[e.type===`boolean`?(0,I.jsxs)(`label`,{className:`toggle`,children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:!!t,disabled:a,onChange:t=>S(e.key,t.target.checked)}),(0,I.jsx)(`div`,{className:`toggle-track`}),(0,I.jsx)(`div`,{className:`toggle-thumb`})]}):e.type===`number`?(0,I.jsx)(`input`,{className:`input input-mono`,type:`number`,style:{width:90,textAlign:`right`},value:String(t??e.defaultValue??0),disabled:a,onChange:t=>S(e.key,Number(t.target.value))}):(0,I.jsx)(`input`,{className:`input`,style:{width:200},value:String(t??e.defaultValue??``),disabled:a,onChange:t=>S(e.key,t.target.value)}),r&&!a&&(0,I.jsx)(`button`,{className:`btn btn-primary btn-sm`,disabled:i,onClick:()=>C(e.key),children:i?(0,I.jsx)(`span`,{className:`spinner sm`}):`Save`}),!n&&!r&&!a&&(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,disabled:i,onClick:()=>w(e.key),title:`Reset to default`,children:(0,I.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,children:[(0,I.jsx)(`path`,{d:`M2 8a6 6 0 016-6 6 6 0 014.24 1.76L14 5`,strokeLinecap:`round`}),(0,I.jsx)(`path`,{d:`M14 2v3h-3`,strokeLinecap:`round`})]})})]})]},e.key)})})})})]})}var KH=[{title:`Authentication`,description:`Control sign-in and sign-up behavior`,keys:[{key:`auth.allow_registration`,label:`Allow Registration`,description:`New users can self-register`,type:`boolean`,defaultValue:!0},{key:`auth.allow_password_login`,label:`Password Login`,description:`Users can log in with email + password`,type:`boolean`,defaultValue:!0},{key:`auth.allow_magic_link`,label:`Magic Link`,description:`Enable passwordless login via email link`,type:`boolean`,defaultValue:!1},{key:`auth.require_email_verification`,label:`Require Email Verification`,description:`New accounts must verify email before logging in`,type:`boolean`,defaultValue:!1},{key:`auth.allow_social_login`,label:`Social Login`,description:`Enable OAuth social providers`,type:`boolean`,defaultValue:!1},{key:`auth.social_auto_link`,label:`Auto-link Social Accounts`,description:`Automatically link social logins to existing accounts by email`,type:`boolean`,defaultValue:!1}]},{title:`Security`,description:`Password rules, MFA, and account protection`,keys:[{key:`security.require_mfa`,label:`Require MFA`,description:`All users must set up multi-factor authentication`,type:`boolean`,defaultValue:!1},{key:`security.allow_totp`,label:`Allow TOTP`,description:`Enable TOTP authenticator app as MFA method`,type:`boolean`,defaultValue:!0},{key:`security.allow_webauthn`,label:`Allow WebAuthn`,description:`Enable passkeys and hardware security keys`,type:`boolean`,defaultValue:!1},{key:`security.password_min_length`,label:`Password Min Length`,description:`Minimum password length requirement`,type:`number`,defaultValue:8},{key:`security.password_block_common`,label:`Block Common Passwords`,description:`Reject passwords from the common passwords list`,type:`boolean`,defaultValue:!0},{key:`security.max_login_attempts`,label:`Max Login Attempts`,description:`Lock account after N failed login attempts (0 = disabled)`,type:`number`,defaultValue:5},{key:`security.lockout_duration_minutes`,label:`Lockout Duration (minutes)`,description:`How long an account stays locked after too many failures`,type:`number`,defaultValue:30},{key:`security.sudo_grace_seconds`,label:`Sudo Grace Period (seconds)`,description:`How long sudo mode stays active after password confirmation`,type:`number`,defaultValue:900}]},{title:`Sessions`,description:`Session lifetime and cookie behavior`,keys:[{key:`sessions.max_age_days`,label:`Session Max Age (days)`,description:`Session expires after N days of inactivity`,type:`number`,defaultValue:30},{key:`sessions.idle_timeout_minutes`,label:`Idle Timeout (minutes)`,description:`Log out after N minutes of inactivity (0 = disabled)`,type:`number`,defaultValue:0},{key:`sessions.allow_multiple`,label:`Allow Multiple Sessions`,description:`Users can be logged in from multiple devices`,type:`boolean`,defaultValue:!0}]},{title:`Communications`,description:`Email and notification settings`,keys:[{key:`email.from_name`,label:`From Name`,description:`Sender name for transactional emails`,type:`string`,defaultValue:`AuthKit`},{key:`email.from_address`,label:`From Address`,description:`Sender email address`,type:`string`,defaultValue:``},{key:`email.login_notify`,label:`Login Notifications`,description:`Send email when a new login is detected from an unknown device`,type:`boolean`,defaultValue:!1},{key:`email.password_reset_expiry_minutes`,label:`Reset Link Expiry (minutes)`,description:`How long password reset links are valid`,type:`number`,defaultValue:60}]},{title:`Advanced`,description:`Rate limiting, CORS, and advanced options`,keys:[{key:`rate_limit.login_per_minute`,label:`Login Rate Limit (per minute)`,description:`Max login attempts per IP per minute`,type:`number`,defaultValue:10},{key:`rate_limit.register_per_hour`,label:`Register Rate Limit (per hour)`,description:`Max registrations per IP per hour`,type:`number`,defaultValue:5},{key:`advanced.debug_mode`,label:`Debug Mode`,description:`Enable verbose error messages (never enable in production)`,type:`boolean`,defaultValue:!1},{key:`advanced.trusted_proxies`,label:`Trusted Proxies`,description:`Comma-separated list of trusted proxy IPs for IP detection`,type:`string`,defaultValue:``}]}];function qH(){let[e,t]=(0,F.useState)(!1);return e?(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,style:{marginBottom:8},children:`Settings`}),(0,I.jsxs)(`div`,{className:`error-box`,children:[`Runtime settings require the `,(0,I.jsx)(`code`,{children:`auth_settings`}),` table. Run the migration to enable this feature.`]})]}):(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header`,children:[(0,I.jsx)(`div`,{className:`page-title`,children:`Settings`}),(0,I.jsx)(`div`,{className:`page-sub`,children:`Runtime configuration — changes take effect immediately`})]}),KH.map(e=>(0,I.jsx)(GH,{section:e,onUnavailable:()=>t(!0)},e.title))]})}var JH={overview:`Overview`,users:`Users`,sessions:`Sessions`,clients:`OAuth Clients`,roles:`Roles`,orgs:`Organizations`,audit:`Audit Log`,keys:`Signing Keys`,settings:`Settings`};function YH(){let{route:e}=Xc();switch(e){case`overview`:return(0,I.jsx)(FV,{});case`users`:return(0,I.jsx)(GV,{});case`sessions`:return(0,I.jsx)(YV,{});case`clients`:return(0,I.jsx)(rH,{});case`roles`:return(0,I.jsx)(oH,{});case`orgs`:return(0,I.jsx)(FH,{});case`audit`:return(0,I.jsx)(VH,{});case`keys`:return(0,I.jsx)(UH,{});case`settings`:return(0,I.jsx)(qH,{});default:return(0,I.jsx)(FV,{})}}function XH(){let{route:e}=Xc();return(0,I.jsxs)(`div`,{className:`app-shell`,children:[(0,I.jsx)($c,{}),(0,I.jsxs)(`main`,{className:`main`,children:[(0,I.jsx)(el,{title:JH[e]??`AuthKit Admin`}),(0,I.jsx)(`div`,{className:`content`,children:(0,I.jsx)(F.Suspense,{fallback:(0,I.jsx)(`div`,{className:`loading-row`,children:(0,I.jsx)(`div`,{className:`spinner lg`})}),children:(0,I.jsx)(YH,{})})})]})]})}var ZH=document.getElementById(`root`);if(!ZH)throw Error(`Root element not found`);var QH=Ys();(0,ft.createRoot)(ZH).render((0,I.jsx)(F.StrictMode,{children:(0,I.jsx)(Xe,{client:QH,children:(0,I.jsx)(Js,{children:(0,I.jsx)(Zt,{children:(0,I.jsx)(Mc,{children:(0,I.jsx)(Fc,{children:(0,I.jsx)(XH,{})})})})})})}));
|
|
137
|
+
`,document.head.appendChild(t)}}function SV({lines:e=3,lastWidth:t=`60%`}){return(0,I.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:Array.from({length:e}).map((n,r)=>(0,I.jsx)(xV,{width:r===e-1?t:`100%`,height:13},r))})}function CV(){return(0,I.jsxs)(`div`,{style:{background:`var(--bg2)`,border:`1px solid var(--line)`,borderRadius:`var(--radius)`,padding:`14px 16px`,display:`flex`,flexDirection:`column`,gap:8},children:[(0,I.jsx)(xV,{width:80,height:11}),(0,I.jsx)(xV,{width:60,height:28,borderRadius:8}),(0,I.jsx)(xV,{width:100,height:11})]})}function wV({count:e=6,columns:t=3}){return(0,I.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:`repeat(${t}, 1fr)`,gap:12},children:Array.from({length:e}).map((e,t)=>(0,I.jsx)(CV,{},t))})}function TV({rows:e=5,cols:t=4}){return(0,I.jsxs)(`div`,{style:{padding:`0 0 8px`},children:[(0,I.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:`repeat(${t}, 1fr)`,gap:12,padding:`10px 16px`,borderBottom:`1px solid var(--line)`},children:Array.from({length:t}).map((e,t)=>(0,I.jsx)(xV,{height:11,width:`50%`},t))}),Array.from({length:e}).map((e,n)=>(0,I.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:`repeat(${t}, 1fr)`,gap:12,padding:`12px 16px`,borderBottom:`1px solid var(--line)`},children:Array.from({length:t}).map((e,n)=>(0,I.jsx)(xV,{height:13,width:n===0?`80%`:n===t-1?`40%`:`65%`},n))},n))]})}function EV({rows:e=5,cols:t=4}){return(0,I.jsxs)(`div`,{style:{background:`var(--bg2)`,border:`1px solid var(--line)`,borderRadius:`var(--radius)`,overflow:`hidden`},children:[(0,I.jsx)(`div`,{style:{padding:`12px 16px`,borderBottom:`1px solid var(--line)`},children:(0,I.jsx)(xV,{width:200,height:13})}),(0,I.jsx)(TV,{rows:e,cols:t})]})}function DV(){return(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:20},children:[(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12},children:[(0,I.jsx)(xV,{width:44,height:44,borderRadius:`50%`}),(0,I.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,gap:6},children:[(0,I.jsx)(xV,{width:`60%`,height:14}),(0,I.jsx)(xV,{width:`40%`,height:11})]})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,I.jsx)(xV,{width:80,height:10}),(0,I.jsx)(xV,{height:32,borderRadius:8})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,I.jsx)(xV,{width:80,height:10}),(0,I.jsx)(SV,{lines:3,lastWidth:`50%`})]})]})}function OV(e){return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function kV(e){return e.includes(`login`)||e.includes(`signin`)?`badge-green`:e.includes(`fail`)||e.includes(`error`)||e.includes(`locked`)?`badge-red`:e.includes(`register`)||e.includes(`signup`)?`badge-accent`:e.includes(`settings`)||e.includes(`admin`)?`badge-amber`:`badge-muted`}function AV(){let{data:e,isLoading:t,error:n,refetch:r}=ut(Xs());return(0,I.jsx)(yV,{isLoading:t,error:n,onRetry:r,skeleton:(0,I.jsx)(wV,{count:6,columns:3}),children:e&&(0,I.jsxs)(`div`,{className:`cards`,children:[(0,I.jsxs)(`div`,{className:`card c-accent`,children:[(0,I.jsx)(`div`,{className:`card-label`,children:`Total Users`}),(0,I.jsx)(`div`,{className:`card-value`,children:e.usersTotal.toLocaleString()}),(0,I.jsx)(`div`,{className:`card-hint`,children:`registered accounts`})]}),(0,I.jsxs)(`div`,{className:`card c-green`,children:[(0,I.jsx)(`div`,{className:`card-label`,children:`Active Sessions`}),(0,I.jsx)(`div`,{className:`card-value`,children:(e.activeSessions??0).toLocaleString()}),(0,I.jsx)(`div`,{className:`card-hint`,children:`currently logged in`})]}),(0,I.jsxs)(`div`,{className:`card c-amber`,children:[(0,I.jsx)(`div`,{className:`card-label`,children:`MAU`}),(0,I.jsx)(`div`,{className:`card-value`,children:e.mau.toLocaleString()}),(0,I.jsx)(`div`,{className:`card-hint`,children:`monthly active users`})]}),(0,I.jsxs)(`div`,{className:`card`,children:[(0,I.jsx)(`div`,{className:`card-label`,children:`Sign-ins`}),(0,I.jsx)(`div`,{className:`card-value`,style:{color:`var(--text)`},children:e.signInsTotal.toLocaleString()}),(0,I.jsxs)(`div`,{className:`card-hint`,children:[`last `,e.windowDays,` days`]})]}),(0,I.jsxs)(`div`,{className:`card c-blue`,children:[(0,I.jsx)(`div`,{className:`card-label`,children:`Sign-ups`}),(0,I.jsx)(`div`,{className:`card-value`,children:e.signUpsTotal.toLocaleString()}),(0,I.jsx)(`div`,{className:`card-hint`,children:`new registrations`})]}),(0,I.jsxs)(`div`,{className:`card`,children:[(0,I.jsx)(`div`,{className:`card-label`,children:`OAuth Clients`}),(0,I.jsx)(`div`,{className:`card-value`,style:{color:`var(--text)`},children:e.clientsCount.toLocaleString()}),(0,I.jsx)(`div`,{className:`card-hint`,children:`OIDC clients`})]})]})})}function jV({title:e}){return(0,I.jsxs)(`div`,{className:`panel`,children:[(0,I.jsx)(`div`,{className:`panel-head`,children:(0,I.jsx)(`h3`,{children:e})}),(0,I.jsx)(`div`,{className:`panel-body`,style:{paddingBottom:4},children:(0,I.jsx)(xV,{height:60,borderRadius:8})})]})}function MV(){let{data:e,isLoading:t,error:n,refetch:r}=ut(Xs());return(0,I.jsx)(yV,{isLoading:t,error:n,onRetry:r,skeleton:(0,I.jsx)(jV,{title:`Sign-ins / day`}),children:e&&(0,I.jsxs)(`div`,{className:`panel`,children:[(0,I.jsxs)(`div`,{className:`panel-head`,children:[(0,I.jsx)(`h3`,{children:`Sign-ins / day`}),(0,I.jsxs)(`span`,{className:`meta`,children:[`last `,e.windowDays,`d`]})]}),(0,I.jsx)(`div`,{className:`panel-body`,style:{paddingBottom:`4px`},children:e.signInsPerDay.length>0?(0,I.jsx)(pV,{data:e.signInsPerDay,color:`var(--accent)`,label:`sign-ins`}):(0,I.jsx)(`div`,{style:{height:60,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`var(--faint)`,fontSize:12},children:`No data yet`})})]})})}function NV(){let{data:e,isLoading:t,error:n,refetch:r}=ut(Xs());return(0,I.jsx)(yV,{isLoading:t,error:n,onRetry:r,skeleton:(0,I.jsx)(jV,{title:`Sign-ups / day`}),children:e&&(0,I.jsxs)(`div`,{className:`panel`,children:[(0,I.jsxs)(`div`,{className:`panel-head`,children:[(0,I.jsx)(`h3`,{children:`Sign-ups / day`}),(0,I.jsxs)(`span`,{className:`meta`,children:[`last `,e.windowDays,`d`]})]}),(0,I.jsx)(`div`,{className:`panel-body`,style:{paddingBottom:`4px`},children:e.signUpsPerDay.length>0?(0,I.jsx)(pV,{data:e.signUpsPerDay,color:`var(--green)`,label:`sign-ups`}):(0,I.jsx)(`div`,{style:{height:60,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`var(--faint)`,fontSize:12},children:`No data yet`})})]})})}function PV(){let{data:e,isLoading:t,error:n,refetch:r}=ut(Xs());return(0,I.jsx)(yV,{isLoading:t,error:n,onRetry:r,skeleton:(0,I.jsx)(EV,{rows:5,cols:4}),children:e&&e.auditSupported&&e.recentEvents.length>0&&(0,I.jsxs)(`div`,{className:`panel`,children:[(0,I.jsxs)(`div`,{className:`panel-head`,children:[(0,I.jsx)(`h3`,{children:`Recent Events`}),(0,I.jsxs)(`span`,{className:`meta`,children:[e.auditTotal.toLocaleString(),` total`]})]}),(0,I.jsx)(`div`,{className:`panel-body`,style:{padding:0},children:(0,I.jsxs)(`table`,{children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`Type`}),(0,I.jsx)(`th`,{children:`Account`}),(0,I.jsx)(`th`,{children:`IP`}),(0,I.jsx)(`th`,{children:`When`})]})}),(0,I.jsx)(`tbody`,{children:e.recentEvents.map(e=>(0,I.jsxs)(`tr`,{className:`static`,style:{cursor:`default`},children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`badge ${kV(e.type)}`,children:e.type})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:`11.5px`},children:e.email??e.accountId??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`code`,children:e.ip??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:`11px`,color:`var(--faint)`},children:e.createdAt?OV(e.createdAt):`—`})})]},e.id))})]})})]})})}function FV(){return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header`,children:[(0,I.jsx)(`div`,{className:`page-title`,children:`Overview`}),(0,I.jsx)(`div`,{className:`page-sub`,children:`Identity provider metrics`})]}),(0,I.jsx)(AV,{}),(0,I.jsxs)(`div`,{className:`grid-2`,style:{marginTop:16},children:[(0,I.jsx)(MV,{}),(0,I.jsx)(NV,{})]}),(0,I.jsx)(`div`,{style:{marginTop:16},children:(0,I.jsx)(PV,{})})]})}function IV({open:e,onClose:t,title:n,children:r,footer:i,large:a}){return(0,F.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),e?(0,I.jsx)(`div`,{className:`modal-overlay`,onClick:t,children:(0,I.jsxs)(`div`,{className:`modal${a?` modal-lg`:``}`,onClick:e=>e.stopPropagation(),children:[(0,I.jsxs)(`div`,{className:`modal-head`,children:[(0,I.jsx)(`h2`,{children:n}),(0,I.jsx)(`button`,{className:`modal-close`,onClick:t,children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M3 3l10 10M13 3L3 13`,strokeLinecap:`round`})})})]}),(0,I.jsx)(`div`,{className:`modal-body`,children:r}),i&&(0,I.jsx)(`div`,{className:`modal-foot`,children:i})]})}):null}function LV(e,t){let[n,r]=(0,F.useState)(e);return(0,F.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function RV({open:e,onClose:t,title:n,children:r}){return(0,F.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),e?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`drawer-overlay`,onClick:t}),(0,I.jsxs)(`div`,{className:`drawer`,children:[(0,I.jsxs)(`div`,{className:`drawer-head`,children:[(0,I.jsx)(`h2`,{children:n}),(0,I.jsx)(`button`,{className:`modal-close`,onClick:t,children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M3 3l10 10M13 3L3 13`,strokeLinecap:`round`})})})]}),(0,I.jsx)(`div`,{className:`drawer-body`,children:r})]})]}):null}function zV({page:e,total:t,perPage:n,onPage:r}){let i=Math.ceil(t/n);return i<=1?null:(0,I.jsxs)(`div`,{className:`pagination`,children:[(0,I.jsxs)(`span`,{className:`pag-info`,children:[(e-1)*n+1,`–`,Math.min(e*n,t),` of `,t]}),(0,I.jsx)(`button`,{className:`btn btn-sm`,disabled:e<=1,onClick:()=>r(e-1),children:(0,I.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M10 12L6 8l4-4`,strokeLinecap:`round`,strokeLinejoin:`round`})})}),(0,I.jsxs)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:`11px`,color:`var(--muted)`},children:[e,` / `,i]}),(0,I.jsx)(`button`,{className:`btn btn-sm`,disabled:e>=i,onClick:()=>r(e+1),children:(0,I.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M6 12l4-4-4-4`,strokeLinecap:`round`,strokeLinejoin:`round`})})})]})}function BV({search:e,page:t,onPage:n,onSelectUser:r}){let{data:i,isLoading:a,error:o,refetch:s}=ut(Zs({search:e,page:t,limit:20})),c=i?.data??[],l=i?.total??0;return(0,I.jsxs)(I.Fragment,{children:[!a&&!o&&(0,I.jsx)(`div`,{style:{marginBottom:4},children:(0,I.jsxs)(`span`,{className:`page-sub`,style:{fontSize:12,color:`var(--faint)`},children:[l.toLocaleString(),` accounts`]})}),(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(yV,{isLoading:a,error:o,onRetry:s,skeleton:(0,I.jsx)(EV,{rows:6,cols:3}),children:c.length===0?(0,I.jsxs)(`div`,{className:`empty-state`,children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,I.jsx)(`circle`,{cx:`12`,cy:`8`,r:`4`}),(0,I.jsx)(`path`,{d:`M4 20c0-4.42 3.58-8 8-8s8 3.58 8 8`})]}),(0,I.jsx)(`h4`,{children:`No users found`}),(0,I.jsx)(`p`,{children:e?`Try a different search term`:`No accounts registered yet`})]}):(0,I.jsxs)(`div`,{className:`tbl-wrap`,children:[(0,I.jsxs)(`table`,{children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`User`}),(0,I.jsx)(`th`,{children:`Roles`}),(0,I.jsx)(`th`,{children:`Status`})]})}),(0,I.jsx)(`tbody`,{children:c.map(e=>(0,I.jsxs)(`tr`,{onClick:()=>r(e.id),children:[(0,I.jsx)(`td`,{children:(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10},children:[(0,I.jsx)(`div`,{className:`avatar`,style:{width:26,height:26,fontSize:10},children:e.email.slice(0,2).toUpperCase()}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{style:{color:`var(--text)`,fontWeight:500,fontSize:12.5},children:e.email}),e.name&&(0,I.jsx)(`div`,{style:{color:`var(--faint)`,fontSize:11},children:e.name})]})]})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`div`,{style:{display:`flex`,gap:4,flexWrap:`wrap`},children:e.globalRoles.length===0?(0,I.jsx)(`span`,{className:`badge badge-muted`,children:`no roles`}):e.globalRoles.map(e=>(0,I.jsx)(`span`,{className:`badge badge-accent`,children:e},e))})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`badge ${e.disabled?`badge-red`:`badge-green`}`,children:e.disabled?`disabled`:`active`})})]},e.id))})]}),(0,I.jsx)(`div`,{style:{padding:`0 16px 12px`},children:(0,I.jsx)(zV,{page:t,total:l,perPage:20,onPage:n})})]})})})]})}function VV({userId:e,onMutated:t,onClose:n}){let r=Ic(),i=Ye(),{data:a,isLoading:o,error:s,refetch:c}=ut(Qs(e)),l=dt(nc(e)),u=dt(rc(e)),d=dt(ic(e)),f=dt(ac(e)),p=dt(oc(e)),m=ut({...Oc(e),enabled:!1});async function h(){if(a)try{a.disabled?(await u.mutateAsync(),r.success(`User enabled`)):(await l.mutateAsync(),r.success(`User disabled`)),i.invalidateQueries({queryKey:H.admin.user(e)}),t()}catch(e){r.error(e instanceof Error?e.message:String(e))}}async function g(){try{await d.mutateAsync(),r.success(`Reset email sent`)}catch(e){r.error(e instanceof Error?e.message:String(e))}}async function _(){if(a&&confirm(`Delete user ${a.email}? This cannot be undone.`))try{await f.mutateAsync(),r.success(`User deleted`),n(),t()}catch(e){r.error(e instanceof Error?e.message:String(e))}}async function v(){if(a&&confirm(`Disconnect ${a.email} from all devices? Every active session and grant will be revoked.`))try{let t=await p.mutateAsync();r.success(`Disconnected from all devices${typeof t?.revoked==`number`?` (${t.revoked} sessions)`:``}`),i.invalidateQueries({queryKey:H.admin.userSessions(e)})}catch(e){r.error(e instanceof Error?e.message:String(e))}}async function y(){try{let e=await m.refetch();if(e.data){let t=e.data.url;typeof t==`string`?window.open(t,`_blank`):r.error(`Impersonation URL not available`)}}catch(e){r.error(e instanceof Error?e.message:`Impersonation not available`)}}return(0,I.jsx)(yV,{isLoading:o,error:s,onRetry:c,skeleton:(0,I.jsx)(`div`,{children:(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12,marginBottom:16},children:[(0,I.jsx)(`div`,{style:{width:44,height:44,borderRadius:`50%`,background:`var(--bg3)`,backgroundImage:`linear-gradient(90deg, var(--bg3) 0%, var(--bg2) 40%, var(--bg3) 100%)`,backgroundSize:`200% 100%`,animation:`sk-shimmer 1.6s ease-in-out infinite`}}),(0,I.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,gap:6},children:[(0,I.jsx)(`div`,{style:{height:14,width:`60%`,borderRadius:6,background:`var(--bg3)`,backgroundImage:`linear-gradient(90deg, var(--bg3) 0%, var(--bg2) 40%, var(--bg3) 100%)`,backgroundSize:`200% 100%`,animation:`sk-shimmer 1.6s ease-in-out infinite`}}),(0,I.jsx)(`div`,{style:{height:11,width:`40%`,borderRadius:6,background:`var(--bg3)`,backgroundImage:`linear-gradient(90deg, var(--bg3) 0%, var(--bg2) 40%, var(--bg3) 100%)`,backgroundSize:`200% 100%`,animation:`sk-shimmer 1.6s ease-in-out infinite`}})]})]})}),children:a&&(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12,marginBottom:16},children:[(0,I.jsx)(`div`,{className:`avatar`,style:{width:44,height:44,fontSize:15},children:a.email.slice(0,2).toUpperCase()}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{style:{fontWeight:600,fontSize:14},children:a.email}),a.name&&(0,I.jsx)(`div`,{style:{color:`var(--faint)`,fontSize:12},children:a.name}),(0,I.jsx)(`div`,{style:{marginTop:4},children:(0,I.jsx)(`span`,{className:`badge ${a.disabled?`badge-red`:`badge-green`}`,children:a.disabled?`disabled`:`active`})})]})]}),(0,I.jsxs)(`div`,{className:`code`,style:{fontSize:11,padding:`6px 10px`},children:[`ID: `,a.id]}),(0,I.jsxs)(`div`,{style:{marginTop:16},children:[(0,I.jsx)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:8},children:`Actions`}),(0,I.jsxs)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:6},children:[(0,I.jsx)(`button`,{className:`btn btn-sm ${a.disabled?``:`btn-danger`}`,onClick:h,disabled:l.isPending||u.isPending,children:a.disabled?`Enable account`:`Disable account`}),(0,I.jsx)(`button`,{className:`btn btn-sm`,onClick:g,disabled:d.isPending,children:`Reset password`}),(0,I.jsx)(`button`,{className:`btn btn-sm`,onClick:y,disabled:m.isFetching,children:`Impersonate`}),(0,I.jsx)(`button`,{className:`btn btn-sm btn-danger`,onClick:v,disabled:p.isPending,children:`Disconnect all devices`}),(0,I.jsx)(`button`,{className:`btn btn-sm btn-danger`,onClick:_,disabled:f.isPending,children:`Delete user`})]})]})]})})}function HV({userId:e,onMutated:t}){let n=Ic(),r=Ye(),{data:i,isLoading:a,error:o,refetch:s}=ut(Qs(e)),c=dt(tc(e)),[l,u]=(0,F.useState)([]);(0,F.useEffect)(()=>{i&&u(i.globalRoles)},[i]);let d=e=>{u(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])};async function f(){try{await c.mutateAsync({globalRoles:l}),n.success(`Roles updated`),r.invalidateQueries({queryKey:H.admin.user(e)}),t()}catch(e){n.error(e instanceof Error?e.message:String(e))}}return(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:8},children:`Global Roles`}),(0,I.jsx)(yV,{isLoading:a,error:o,onRetry:s,skeleton:(0,I.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[1,2].map(e=>(0,I.jsx)(`div`,{style:{height:20,borderRadius:6,background:`var(--bg3)`,backgroundImage:`linear-gradient(90deg, var(--bg3) 0%, var(--bg2) 40%, var(--bg3) 100%)`,backgroundSize:`200% 100%`,animation:`sk-shimmer 1.6s ease-in-out infinite`}},e))}),children:i&&(0,I.jsxs)(I.Fragment,{children:[l.length===0&&(0,I.jsx)(`div`,{style:{fontSize:12,color:`var(--faint)`,marginBottom:8},children:`No roles assigned`}),i.globalRoles.map(e=>(0,I.jsxs)(`label`,{className:`checkbox-row`,children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:l.includes(e),onChange:()=>d(e)}),(0,I.jsx)(`div`,{children:(0,I.jsx)(`div`,{className:`chk-label`,children:e})})]},e)),(0,I.jsx)(`button`,{className:`btn btn-primary btn-sm`,style:{marginTop:10},onClick:f,disabled:c.isPending,children:c.isPending?(0,I.jsx)(`span`,{className:`spinner sm`}):`Save roles`})]})})]})}function UV({userId:e}){let{data:t,isLoading:n,error:r,refetch:i}=ut($s(e)),a=t?.sessions??[];return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:8},children:[`Sessions `,!n&&!r?`(${a.length})`:``]}),(0,I.jsx)(yV,{isLoading:n,error:r,onRetry:i,skeleton:(0,I.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[1,2].map(e=>(0,I.jsx)(`div`,{style:{height:44,borderRadius:8,background:`var(--bg3)`,backgroundImage:`linear-gradient(90deg, var(--bg3) 0%, var(--bg2) 40%, var(--bg3) 100%)`,backgroundSize:`200% 100%`,animation:`sk-shimmer 1.6s ease-in-out infinite`}},e))}),children:a.length===0?(0,I.jsx)(`div`,{style:{fontSize:12,color:`var(--faint)`},children:`No active sessions`}):a.map(e=>(0,I.jsxs)(`div`,{className:`panel`,style:{marginBottom:8,padding:`10px 12px`},children:[(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,fontSize:12},children:[(0,I.jsxs)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 16 16`,fill:`none`,stroke:`var(--muted)`,strokeWidth:`1.6`,children:[(0,I.jsx)(`rect`,{x:`1.5`,y:`3.5`,width:`13`,height:`9`,rx:`1.5`}),(0,I.jsx)(`circle`,{cx:`8`,cy:`8.5`,r:`2`})]}),(0,I.jsx)(`span`,{style:{color:`var(--text)`,fontWeight:500},children:e.browser??`Unknown browser`}),(0,I.jsx)(`span`,{style:{color:`var(--faint)`},children:e.os}),(0,I.jsx)(`span`,{className:`code ml-auto`,children:e.ip??`—`})]}),e.location&&(0,I.jsx)(`div`,{style:{fontSize:11,color:`var(--faint)`,marginTop:4},children:e.location})]},e.id))})]})}function WV({userId:e,onClose:t,onMutated:n}){let{data:r}=ut(Qs(e));return(0,I.jsx)(RV,{open:!0,onClose:t,title:r?.email??`User detail`,children:(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:20},children:[(0,I.jsx)(VV,{userId:e,onMutated:n,onClose:t}),(0,I.jsx)(HV,{userId:e,onMutated:n}),(0,I.jsx)(UV,{userId:e})]})})}function GV(){let e=Ic(),t=Ye(),[n,r]=Jc(`page`,Bc.withDefault(1)),[i,a]=Jc(`q`,zc.withDefault(``)),[o,s]=Jc(`user`),c=LV(i,300),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)({email:``,name:``,password:``,invite:!1}),p=dt(ec());async function m(n){n.preventDefault();try{await p.mutateAsync({email:d.email,name:d.name||void 0,password:d.password||void 0,invite:d.invite}),t.invalidateQueries({queryKey:H.admin.users()}),e.success(`User created`),u(!1),f({email:``,name:``,password:``,invite:!1})}catch(t){e.error(t instanceof Error?t.message:String(t))}}return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header-row`,children:[(0,I.jsx)(`div`,{children:(0,I.jsx)(`div`,{className:`page-title`,children:`Users`})}),(0,I.jsx)(`div`,{className:`page-actions`,children:(0,I.jsxs)(`button`,{className:`btn btn-primary`,onClick:()=>u(!0),children:[(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M8 2v12M2 8h12`,strokeLinecap:`round`})}),`New User`]})})]}),(0,I.jsx)(`div`,{className:`panel`,style:{marginBottom:0},children:(0,I.jsx)(`div`,{className:`panel-head`,children:(0,I.jsxs)(`div`,{className:`search-input`,style:{flex:1,maxWidth:320},children:[(0,I.jsxs)(`svg`,{className:`search-ico`,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,children:[(0,I.jsx)(`circle`,{cx:`7`,cy:`7`,r:`4.5`}),(0,I.jsx)(`path`,{d:`M10 10l3 3`,strokeLinecap:`round`})]}),(0,I.jsx)(`input`,{className:`input`,placeholder:`Search by email or name…`,value:i,onChange:e=>{a(e.target.value),r(1)}})]})})}),(0,I.jsx)(BV,{search:c,page:n,onPage:r,onSelectUser:s,onInvalidate:()=>t.invalidateQueries({queryKey:H.admin.users()})}),(0,I.jsx)(IV,{open:l,onClose:()=>u(!1),title:`Create User`,footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`btn`,onClick:()=>u(!1),children:`Cancel`}),(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:m,disabled:p.isPending,children:p.isPending?(0,I.jsx)(`span`,{className:`spinner sm`}):`Create User`})]}),children:(0,I.jsxs)(`form`,{onSubmit:m,children:[(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Email *`}),(0,I.jsx)(`input`,{className:`input`,type:`email`,required:!0,value:d.email,onChange:e=>f(t=>({...t,email:e.target.value})),placeholder:`user@example.com`})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Name`}),(0,I.jsx)(`input`,{className:`input`,value:d.name,onChange:e=>f(t=>({...t,name:e.target.value})),placeholder:`Full name (optional)`})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Password`}),(0,I.jsx)(`input`,{className:`input`,type:`password`,value:d.password,onChange:e=>f(t=>({...t,password:e.target.value})),placeholder:`Leave blank to send invite`})]}),(0,I.jsxs)(`label`,{className:`checkbox-row`,children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:d.invite,onChange:e=>f(t=>({...t,invite:e.target.checked}))}),(0,I.jsx)(`span`,{className:`chk-label`,children:`Send invitation email`})]})]})}),o&&(0,I.jsx)(WV,{userId:o,onClose:()=>s(null),onMutated:()=>t.invalidateQueries({queryKey:H.admin.users()})})]})}var KV=20;function qV({page:e,onPage:t}){let{data:n,isLoading:r,error:i,refetch:a}=ut(sc()),o=n?.sessions??[],s=o.length,c=o.slice((e-1)*KV,e*KV);return(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(yV,{isLoading:r,error:i,onRetry:a,skeleton:(0,I.jsx)(EV,{rows:8,cols:6}),children:c.length===0?(0,I.jsxs)(`div`,{className:`empty-state`,children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,I.jsx)(`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`}),(0,I.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]}),(0,I.jsx)(`h4`,{children:`No active sessions`}),(0,I.jsx)(`p`,{children:`No users are currently logged in`})]}):(0,I.jsxs)(`div`,{className:`tbl-wrap`,children:[(0,I.jsxs)(`table`,{children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`Account`}),(0,I.jsx)(`th`,{children:`Browser / OS`}),(0,I.jsx)(`th`,{children:`IP`}),(0,I.jsx)(`th`,{children:`Location`}),(0,I.jsx)(`th`,{children:`Login`}),(0,I.jsx)(`th`,{children:`Methods`})]})}),(0,I.jsx)(`tbody`,{children:c.map(e=>(0,I.jsxs)(`tr`,{style:{cursor:`default`},children:[(0,I.jsx)(`td`,{children:(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:2},children:[e.email&&(0,I.jsx)(`span`,{style:{fontSize:12,fontWeight:500,color:`var(--text)`},children:e.email}),(0,I.jsx)(`span`,{className:`mono text-sm`,style:{color:e.email?`var(--faint)`:void 0},children:e.accountId})]})}),(0,I.jsx)(`td`,{children:(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,I.jsx)(`span`,{style:{color:`var(--text)`,fontWeight:500,fontSize:12},children:e.browser??`—`}),(0,I.jsx)(`span`,{style:{color:`var(--faint)`,fontSize:11},children:e.os??``})]})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`code`,children:e.ip??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontSize:11.5,color:`var(--muted)`},children:e.location??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:11,color:`var(--faint)`},children:e.loginTs?new Date(e.loginTs).toLocaleString():`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`div`,{style:{display:`flex`,gap:4,flexWrap:`wrap`},children:e.amr.length===0?(0,I.jsx)(`span`,{className:`badge badge-muted`,children:`—`}):e.amr.map(e=>(0,I.jsx)(`span`,{className:`badge badge-muted`,children:e},e))})})]},e.id))})]}),(0,I.jsx)(`div`,{style:{padding:`0 16px 12px`},children:(0,I.jsx)(zV,{page:e,total:s,perPage:KV,onPage:t})})]})})})}function JV(){let{data:e}=ut(sc());return e?.sessions.length??0}function YV(){let e=Ic(),t=Ye(),[n,r]=Jc(`page`,Bc.withDefault(1)),i=JV(),a=dt(cc());async function o(){if(confirm(`Revoke ALL active sessions? All users will be logged out.`))try{let n=await a.mutateAsync();e.success(`Revoked ${n.revoked??0} sessions`),t.invalidateQueries({queryKey:H.admin.sessions()})}catch(t){e.error(t instanceof Error?t.message:String(t))}}return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header-row`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,children:`Sessions`}),(0,I.jsxs)(`div`,{className:`page-sub`,children:[i.toLocaleString(),` active sessions`]})]}),(0,I.jsx)(`div`,{className:`page-actions`,children:(0,I.jsxs)(`button`,{className:`btn btn-danger`,onClick:o,disabled:a.isPending,children:[a.isPending?(0,I.jsx)(`span`,{className:`spinner sm`}):(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,children:(0,I.jsx)(`path`,{d:`M4 4l8 8M12 4l-8 8`,strokeLinecap:`round`})}),`Revoke All`]})})]}),(0,I.jsx)(qV,{page:n,onPage:r})]})}function XV(){return(0,I.jsxs)(`div`,{style:{background:`var(--bg2)`,border:`1px solid var(--line)`,borderRadius:`var(--radius)`,padding:`14px 16px`,display:`flex`,flexDirection:`column`,gap:8},children:[(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,I.jsx)(xV,{width:`30%`,height:13}),(0,I.jsx)(xV,{width:60,height:18,borderRadius:20})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,I.jsx)(xV,{width:100,height:18,borderRadius:20}),(0,I.jsx)(xV,{width:80,height:18,borderRadius:20})]}),(0,I.jsx)(xV,{width:`50%`,height:11})]})}function ZV(){return(0,I.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:[1,2,3].map(e=>(0,I.jsx)(XV,{},e))})}function QV({onEdit:e,onDelete:t,onRegenerate:n}){let{data:r,isLoading:i,error:a,refetch:o}=ut(lc()),s=r?.data??[],c=r?.canList??!0;return(0,I.jsx)(yV,{isLoading:i,error:a,onRetry:o,skeleton:(0,I.jsx)(ZV,{}),children:c?s.length===0?(0,I.jsxs)(`div`,{className:`empty-state`,children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,I.jsx)(`path`,{d:`M18 13l4-3.5L18 6`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,I.jsx)(`path`,{d:`M22 9.5H9M6 5H4a1 1 0 00-1 1v12a1 1 0 001 1h2`,strokeLinecap:`round`})]}),(0,I.jsx)(`h4`,{children:`No clients yet`}),(0,I.jsx)(`p`,{children:`Create an OAuth 2.0 / OIDC client to get started`})]}):(0,I.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:s.map(r=>(0,I.jsx)(`div`,{className:`panel`,style:{padding:`14px 16px`},children:(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`flex-start`,gap:14},children:[(0,I.jsxs)(`div`,{style:{flex:1},children:[(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:6},children:[(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontWeight:600,fontSize:13,color:`var(--text)`},children:r.clientId}),(0,I.jsx)(`span`,{className:`badge ${r.confidential?`badge-accent`:`badge-muted`}`,children:r.confidential?`confidential`:`public`})]}),(0,I.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:4,marginBottom:6},children:r.grants.map(e=>(0,I.jsx)(`span`,{className:`badge badge-muted`,children:e},e))}),r.redirectUris.length>0&&(0,I.jsx)(`div`,{style:{fontSize:11,color:`var(--faint)`,display:`flex`,flexWrap:`wrap`,gap:4},children:r.redirectUris.map(e=>(0,I.jsx)(`span`,{className:`code`,children:e},e))})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6,flexShrink:0},children:[(0,I.jsx)(`button`,{className:`btn btn-sm`,onClick:()=>e(r),children:`Edit`}),(0,I.jsx)(`button`,{className:`btn btn-sm`,onClick:()=>n(r),title:`Regenerate secret`,children:(0,I.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,children:[(0,I.jsx)(`path`,{d:`M2 8a6 6 0 016-6 6 6 0 014.24 1.76L14 5`,strokeLinecap:`round`}),(0,I.jsx)(`path`,{d:`M14 2v3h-3M14 8a6 6 0 01-6 6 6 6 0 01-4.24-1.76L2 11`,strokeLinecap:`round`}),(0,I.jsx)(`path`,{d:`M2 14v-3h3`,strokeLinecap:`round`})]})}),(0,I.jsx)(`button`,{className:`btn btn-sm btn-danger`,onClick:()=>t(r),children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,children:(0,I.jsx)(`path`,{d:`M2 4.5h12M5.5 4.5V3h5v1.5M10.5 4.5v8a1 1 0 01-1 1h-3a1 1 0 01-1-1v-8`,strokeLinecap:`round`})})})]})]})},r.clientId))}):(0,I.jsx)(`div`,{className:`error-box`,children:`Client store does not support listing (no dynamic registration adapter configured).`})})}function $V(){let{data:e}=ut(lc());return e?.data.length??0}var eH=[`authorization_code`,`refresh_token`,`client_credentials`,`implicit`],tH=[`client_secret_basic`,`client_secret_post`,`none`];function nH(){return{clientIdOverride:``,redirectUris:[],postLogoutRedirectUris:[],grantTypes:[`authorization_code`,`refresh_token`],tokenEndpointAuthMethod:`client_secret_basic`,backchannelLogoutUri:``,backchannelLogoutSessionRequired:!1}}function rH(){let e=Ic(),t=Ye(),n=V(),r=$V(),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(null),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(nH()),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(``),g=dt(uc()),_=dt(dc(o?.clientId??``));function v(){d(nH()),p(``),h(``),a(!0)}function y(e){d({clientIdOverride:``,redirectUris:[...e.redirectUris],postLogoutRedirectUris:[...e.postLogoutRedirectUris],grantTypes:[...e.grants],tokenEndpointAuthMethod:e.tokenEndpointAuthMethod,backchannelLogoutUri:e.backchannelLogoutUri??``,backchannelLogoutSessionRequired:e.backchannelLogoutSessionRequired}),p(``),h(``),s(e)}function b(e){let t=e===`redirect`?f.trim():m.trim();t&&(e===`redirect`?(d(e=>({...e,redirectUris:[...e.redirectUris,t]})),p(``)):(d(e=>({...e,postLogoutRedirectUris:[...e.postLogoutRedirectUris,t]})),h(``)))}function x(e,t){d(e===`redirect`?e=>({...e,redirectUris:e.redirectUris.filter((e,n)=>n!==t)}):e=>({...e,postLogoutRedirectUris:e.postLogoutRedirectUris.filter((e,n)=>n!==t)}))}function S(e){d(t=>({...t,grantTypes:t.grantTypes.includes(e)?t.grantTypes.filter(t=>t!==e):[...t.grantTypes,e]}))}async function C(n){n.preventDefault();try{let n={clientId:u.clientIdOverride||void 0,redirectUris:u.redirectUris,postLogoutRedirectUris:u.postLogoutRedirectUris,grantTypes:u.grantTypes,tokenEndpointAuthMethod:u.tokenEndpointAuthMethod,backchannelLogoutUri:u.backchannelLogoutUri||void 0,backchannelLogoutSessionRequired:u.backchannelLogoutSessionRequired},r=await g.mutateAsync(n);t.invalidateQueries({queryKey:H.admin.clients()}),a(!1),r.clientSecret?l({clientId:r.clientId,secret:r.clientSecret}):e.success(`Client ${r.clientId} created`)}catch(t){e.error(t instanceof Error?t.message:String(t))}}async function w(n){if(n.preventDefault(),o)try{await _.mutateAsync({redirectUris:u.redirectUris,postLogoutRedirectUris:u.postLogoutRedirectUris,grantTypes:u.grantTypes,tokenEndpointAuthMethod:u.tokenEndpointAuthMethod,backchannelLogoutUri:u.backchannelLogoutUri||void 0,backchannelLogoutSessionRequired:u.backchannelLogoutSessionRequired}),t.invalidateQueries({queryKey:H.admin.clients()}),e.success(`Client updated`),s(null)}catch(t){e.error(t instanceof Error?t.message:String(t))}}async function T(r){if(confirm(`Delete client ${r.clientId}?`))try{await n.admin.clients.remove(r.clientId),t.invalidateQueries({queryKey:H.admin.clients()}),e.success(`Client deleted`)}catch(t){e.error(t instanceof Error?t.message:String(t))}}async function E(t){if(confirm(`Regenerate secret for ${t.clientId}? Existing secret will stop working.`))try{let r=await n.admin.clients.regenerateSecret(t.clientId);r.clientSecret?l({clientId:r.clientId,secret:r.clientSecret}):e.info(`No secret returned (public client)`)}catch(t){e.error(t instanceof Error?t.message:String(t))}}let D=()=>(0,I.jsxs)(`form`,{onSubmit:o?w:C,children:[!o&&(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Client ID (optional — auto-generated if blank)`}),(0,I.jsx)(`input`,{className:`input input-mono`,value:u.clientIdOverride,onChange:e=>d(t=>({...t,clientIdOverride:e.target.value})),placeholder:`my-app (auto if blank)`})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Grant Types`}),(0,I.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:6,marginTop:4},children:eH.map(e=>(0,I.jsxs)(`label`,{className:`checkbox-row`,style:{padding:`4px 0`},children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:u.grantTypes.includes(e),onChange:()=>S(e)}),(0,I.jsx)(`span`,{className:`chk-label mono`,children:e})]},e))})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Token Endpoint Auth Method`}),(0,I.jsx)(`select`,{className:`input`,value:u.tokenEndpointAuthMethod,onChange:e=>d(t=>({...t,tokenEndpointAuthMethod:e.target.value})),children:tH.map(e=>(0,I.jsx)(`option`,{value:e,children:e},e))})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Redirect URIs`}),u.redirectUris.map((e,t)=>(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6,marginBottom:4},children:[(0,I.jsx)(`input`,{className:`input input-mono`,value:e,readOnly:!0,style:{flex:1}}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-danger`,onClick:()=>x(`redirect`,t),children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M3 3l10 10M13 3L3 13`,strokeLinecap:`round`})})})]},t)),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,I.jsx)(`input`,{className:`input input-mono`,value:f,onChange:e=>p(e.target.value),placeholder:`https://app.example.com/callback`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),b(`redirect`))}}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-sm`,onClick:()=>b(`redirect`),children:`Add`})]})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Post-Logout Redirect URIs`}),u.postLogoutRedirectUris.map((e,t)=>(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6,marginBottom:4},children:[(0,I.jsx)(`input`,{className:`input input-mono`,value:e,readOnly:!0,style:{flex:1}}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-danger`,onClick:()=>x(`logout`,t),children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M3 3l10 10M13 3L3 13`,strokeLinecap:`round`})})})]},t)),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,I.jsx)(`input`,{className:`input input-mono`,value:m,onChange:e=>h(e.target.value),placeholder:`https://app.example.com/logged-out`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),b(`logout`))}}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-sm`,onClick:()=>b(`logout`),children:`Add`})]})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Backchannel Logout URI`}),(0,I.jsx)(`input`,{className:`input input-mono`,value:u.backchannelLogoutUri,onChange:e=>d(t=>({...t,backchannelLogoutUri:e.target.value})),placeholder:`https://app.example.com/backchannel-logout`})]}),(0,I.jsxs)(`label`,{className:`checkbox-row`,children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:u.backchannelLogoutSessionRequired,onChange:e=>d(t=>({...t,backchannelLogoutSessionRequired:e.target.checked}))}),(0,I.jsx)(`span`,{className:`chk-label`,children:`Require session ID in backchannel logout`})]})]});return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header-row`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,children:`OAuth Clients`}),(0,I.jsxs)(`div`,{className:`page-sub`,children:[r,` dynamic clients`]})]}),(0,I.jsx)(`div`,{className:`page-actions`,children:(0,I.jsxs)(`button`,{className:`btn btn-primary`,onClick:v,children:[(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M8 2v12M2 8h12`,strokeLinecap:`round`})}),`New Client`]})})]}),(0,I.jsx)(QV,{onEdit:y,onDelete:T,onRegenerate:E}),(0,I.jsx)(IV,{open:i,onClose:()=>a(!1),title:`New OAuth Client`,large:!0,footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`btn`,onClick:()=>a(!1),children:`Cancel`}),(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:C,disabled:g.isPending,children:g.isPending?(0,I.jsx)(`span`,{className:`spinner sm`}):`Create Client`})]}),children:(0,I.jsx)(D,{})}),(0,I.jsx)(IV,{open:!!o,onClose:()=>s(null),title:`Edit — ${o?.clientId}`,large:!0,footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`btn`,onClick:()=>s(null),children:`Cancel`}),(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:w,disabled:_.isPending,children:_.isPending?(0,I.jsx)(`span`,{className:`spinner sm`}):`Save Changes`})]}),children:(0,I.jsx)(D,{})}),(0,I.jsxs)(IV,{open:!!c,onClose:()=>l(null),title:`Client Secret — Save Now`,footer:(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:()=>l(null),children:`I've saved it`}),children:[(0,I.jsx)(`div`,{className:`error-box`,style:{background:`var(--amber-soft)`,borderColor:`rgba(255,180,84,0.3)`,color:`var(--amber)`},children:`This secret will not be shown again. Copy it now.`}),(0,I.jsxs)(`div`,{className:`secret-box`,style:{marginTop:12},children:[(0,I.jsx)(`small`,{children:`Client ID`}),c?.clientId]}),(0,I.jsxs)(`div`,{className:`secret-box`,children:[(0,I.jsx)(`small`,{children:`Client Secret`}),c?.secret]}),(0,I.jsxs)(`button`,{className:`btn btn-sm`,style:{marginTop:4},onClick:()=>navigator.clipboard.writeText(c?.secret??``),children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,children:[(0,I.jsx)(`rect`,{x:`5`,y:`5`,width:`9`,height:`9`,rx:`1.5`}),(0,I.jsx)(`path`,{d:`M3.5 11H3a1.5 1.5 0 01-1.5-1.5V3A1.5 1.5 0 013 1.5h6.5A1.5 1.5 0 0111 3v.5`,strokeLinecap:`round`})]}),`Copy secret`]})]})]})}var iH=`ADMIN`;function aH({onEdit:e,onDelete:t,onUnavailable:n}){let[r,i]=(0,F.useState)(!1),{data:a,isLoading:o,error:s,refetch:c}=ut({...fc(),retry:(e,t)=>t&&typeof t==`object`&&`status`in t&&t.status===404?(r||(i(!0),n()),!1):e<1}),l=a?.data??[];return(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(yV,{isLoading:o,error:s&&!(typeof s==`object`&&`status`in s&&s.status===404)?s:void 0,onRetry:c,skeleton:(0,I.jsx)(EV,{rows:4,cols:4}),children:l.length===0?(0,I.jsxs)(`div`,{className:`empty-state`,children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,I.jsx)(`circle`,{cx:`12`,cy:`8`,r:`4`}),(0,I.jsx)(`path`,{d:`M2 20a10 10 0 0120 0`})]}),(0,I.jsx)(`h4`,{children:`No roles yet`}),(0,I.jsx)(`p`,{children:`Create roles to assign permissions to users`})]}):(0,I.jsx)(`div`,{className:`tbl-wrap`,children:(0,I.jsxs)(`table`,{children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`Name`}),(0,I.jsx)(`th`,{children:`Description`}),(0,I.jsx)(`th`,{children:`Type`}),(0,I.jsx)(`th`,{style:{width:80}})]})}),(0,I.jsx)(`tbody`,{children:l.map(n=>(0,I.jsxs)(`tr`,{style:{cursor:`default`},children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontWeight:600,color:n.name===iH?`var(--accent)`:`var(--text)`},children:n.name})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{color:`var(--muted)`,fontSize:12},children:n.description??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`badge ${`builtin`in n&&n.builtin?`badge-accent`:`badge-muted`}`,children:`builtin`in n&&n.builtin?`built-in`:`custom`})}),(0,I.jsx)(`td`,{className:`no-click`,style:{textAlign:`right`},children:(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6,justifyContent:`flex-end`},children:[(0,I.jsx)(`button`,{className:`btn btn-sm`,onClick:()=>e(n),children:`Edit`}),n.name!==iH&&(0,I.jsx)(`button`,{className:`btn btn-sm btn-danger`,onClick:()=>t(n),children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,children:(0,I.jsx)(`path`,{d:`M2 4.5h12M5.5 4.5V3h5v1.5M10.5 4.5v8a1 1 0 01-1 1h-3a1 1 0 01-1-1v-8`,strokeLinecap:`round`})})})]})})]},n.name))})]})})})})}function oH(){let e=Ic(),t=Ye(),n=V(),[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(null),[s,c]=(0,F.useState)({name:``,description:``}),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(!1),p=dt(pc());async function m(n){n.preventDefault(),u(!0);try{await p.mutateAsync({name:s.name.trim().toUpperCase(),description:s.description||void 0}),t.invalidateQueries({queryKey:H.admin.roles()}),e.success(`Role created`),i(!1),c({name:``,description:``})}catch(t){e.error(t instanceof Error?t.message:String(t))}finally{u(!1)}}async function h(r){if(r.preventDefault(),a){u(!0);try{await n.admin.roles.update(a.name,{description:s.description||void 0}),t.invalidateQueries({queryKey:H.admin.roles()}),e.success(`Role updated`),o(null)}catch(t){e.error(t instanceof Error?t.message:String(t))}finally{u(!1)}}}async function g(r){if(confirm(`Delete role ${r.name}?`))try{await n.admin.roles.remove(r.name),t.invalidateQueries({queryKey:H.admin.roles()}),e.success(`Role deleted`)}catch(t){e.error(t instanceof Error?t.message:String(t))}}return d?(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,style:{marginBottom:8},children:`Roles`}),(0,I.jsxs)(`div`,{className:`error-box`,children:[`Role catalog requires the `,(0,I.jsx)(`code`,{children:`auth_settings`}),` table (runtime settings). Run the migration to enable this feature.`]})]}):(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header-row`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,children:`Roles`}),(0,I.jsx)(`div`,{className:`page-sub`,children:`Global role catalog`})]}),(0,I.jsx)(`div`,{className:`page-actions`,children:(0,I.jsxs)(`button`,{className:`btn btn-primary`,onClick:()=>{c({name:``,description:``}),i(!0)},children:[(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M8 2v12M2 8h12`,strokeLinecap:`round`})}),`New Role`]})})]}),(0,I.jsx)(aH,{onEdit:e=>{o(e),c({name:e.name,description:e.description??``})},onDelete:g,onUnavailable:()=>f(!0)}),(0,I.jsx)(IV,{open:r,onClose:()=>i(!1),title:`New Role`,footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`btn`,onClick:()=>i(!1),children:`Cancel`}),(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:m,disabled:l,children:l?(0,I.jsx)(`span`,{className:`spinner sm`}):`Create Role`})]}),children:(0,I.jsxs)(`form`,{onSubmit:m,children:[(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Name * (uppercase)`}),(0,I.jsx)(`input`,{className:`input input-mono`,required:!0,value:s.name,onChange:e=>c(t=>({...t,name:e.target.value.toUpperCase()})),placeholder:`EDITOR`}),(0,I.jsx)(`div`,{className:`hint`,children:`Letters, digits, underscore. E.g. ADMIN, CONTENT_MANAGER`})]}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Description`}),(0,I.jsx)(`input`,{className:`input`,value:s.description,onChange:e=>c(t=>({...t,description:e.target.value})),placeholder:`Can edit content`})]})]})}),(0,I.jsx)(IV,{open:!!a,onClose:()=>o(null),title:`Edit Role — ${a?.name}`,footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`btn`,onClick:()=>o(null),children:`Cancel`}),(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:h,disabled:l,children:l?(0,I.jsx)(`span`,{className:`spinner sm`}):`Save`})]}),children:(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{children:`Description`}),(0,I.jsx)(`input`,{className:`input`,value:s.description,onChange:e=>c(t=>({...t,description:e.target.value}))})]})})]})}function sH({onPick:e,placeholder:t}){let[n,r]=(0,F.useState)(``),i=LV(n,250),a=ut({...Zs({search:i,limit:6}),enabled:i.trim().length>=2}),o=a.data?.data??[];return(0,I.jsxs)(`div`,{style:{position:`relative`},children:[(0,I.jsx)(`input`,{className:`input`,value:n,onChange:e=>r(e.target.value),placeholder:t??`Search user by email or name…`,autoFocus:!0}),i.trim().length>=2&&(0,I.jsx)(`div`,{style:{position:`absolute`,top:`100%`,left:0,right:0,zIndex:30,marginTop:4,background:`var(--panel, var(--bg))`,border:`1px solid var(--line)`,borderRadius:6,overflow:`hidden`,boxShadow:`0 8px 24px rgba(0,0,0,0.25)`},children:a.isLoading?(0,I.jsx)(`div`,{style:{padding:`8px 12px`,fontSize:12,color:`var(--faint)`},children:`Searching…`}):o.length===0?(0,I.jsx)(`div`,{style:{padding:`8px 12px`,fontSize:12,color:`var(--faint)`},children:`No users match.`}):o.map(t=>(0,I.jsxs)(`button`,{type:`button`,onClick:()=>e({id:t.id,email:t.email,name:t.name}),style:{display:`block`,width:`100%`,textAlign:`left`,padding:`8px 12px`,background:`none`,border:`none`,cursor:`pointer`,color:`var(--text)`,fontSize:12.5},onMouseEnter:e=>e.currentTarget.style.background=`var(--line)`,onMouseLeave:e=>e.currentTarget.style.background=`none`,children:[(0,I.jsx)(`span`,{style:{fontWeight:600},children:t.name??t.email}),t.name&&(0,I.jsx)(`span`,{style:{color:`var(--muted)`,marginLeft:8},children:t.email})]},t.id))})]})}function cH({user:e,onClear:t}){return(0,I.jsxs)(`span`,{className:`badge badge-muted`,style:{display:`inline-flex`,alignItems:`center`,gap:6},children:[e.name?`${e.name} · `:``,e.email,(0,I.jsx)(`button`,{type:`button`,onClick:t,style:{background:`none`,border:`none`,cursor:`pointer`,color:`inherit`,padding:0,lineHeight:1},"aria-label":`Clear selected user`,children:`×`})]})}function lH({label:e,hint:t,children:n}){return(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10},children:[(0,I.jsxs)(`div`,{style:{flex:1},children:[(0,I.jsx)(`div`,{style:{fontSize:12,fontWeight:500,color:`var(--text)`},children:e}),t&&(0,I.jsx)(`div`,{style:{fontSize:11,color:`var(--faint)`},children:t})]}),n]})}function uH({checked:e,onChange:t}){return(0,I.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e,onClick:()=>t(!e),style:{position:`relative`,width:36,height:20,borderRadius:999,border:`none`,cursor:`pointer`,background:e?`var(--accent)`:`var(--line)`,transition:`background 0.15s`},children:(0,I.jsx)(`span`,{style:{position:`absolute`,top:2,left:e?18:2,width:16,height:16,borderRadius:`50%`,background:`#fff`,transition:`left 0.15s`}})})}function dH({values:e,onChange:t,locked:n=[],placeholder:r}){let[i,a]=(0,F.useState)(``);function o(){let n=i.trim();!n||e.includes(n)||(t([...e,n]),a(``))}return(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:6},children:[(0,I.jsx)(`div`,{style:{display:`flex`,gap:6,flexWrap:`wrap`},children:e.map(r=>(0,I.jsxs)(`span`,{className:`badge badge-muted`,style:{display:`inline-flex`,alignItems:`center`,gap:5},children:[r,!n.includes(r)&&(0,I.jsx)(`button`,{type:`button`,onClick:()=>t(e.filter(e=>e!==r)),style:{background:`none`,border:`none`,cursor:`pointer`,color:`inherit`,padding:0,lineHeight:1},"aria-label":`Remove ${r}`,children:`×`})]},r))}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,I.jsx)(`input`,{className:`input`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),o())},placeholder:r??`add…`,style:{maxWidth:160}}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:o,children:`Add`})]})]})}var fH=[`organizations_policy`,`roles_catalog`],pH={organizations_policy:{en:`Organizations policy`,pt:`Política de organizações`},roles_catalog:{en:`Roles catalog`,pt:`Catálogo de papéis`}},mH=[`owner`,`admin`,`member`];function hH(e){let t=e??{};return{allowSelfCreate:!!t.allowSelfCreate,invitationTtlHours:Number(t.invitationTtlHours)||168,roles:Array.isArray(t.roles)&&t.roles.length?t.roles.map(String):mH}}function gH(e){let t=e??{};return{roles:(Array.isArray(t.roles)&&t.roles.length?t.roles:[{name:`ADMIN`,description:`Full access to the admin console`}]).map(e=>({name:String(e.name),description:e.description?String(e.description):void 0}))}}function _H({orgId:e}){let t=Ic(),n=Ye(),{data:r,isLoading:i}=ut({...Tc(e),retry:!1}),{data:a}=ut({...Tc(null),retry:!1}),o=dt(Ec(e)),s=dt(Dc(e)),[c,l]=(0,F.useState)(null),u=r?.data??[],d=a?.data??[];function f(e){return u.find(t=>t.key===e)??null}function p(e){return d.find(t=>t.key===e)??null}async function m(r,i){try{await o.mutateAsync({key:r,value:i}),n.invalidateQueries({queryKey:H.admin.settings(e)}),t.success(`Setting saved for this organization`),l(null)}catch(e){t.error(e instanceof Error?e.message:`Failed to save setting`)}}async function h(r){try{await s.mutateAsync(r),n.invalidateQueries({queryKey:H.admin.settings(e)}),t.success(`Organization setting removed (falls back to global)`)}catch(e){t.error(e instanceof Error?e.message:`Failed to remove setting`)}}return i?null:(0,I.jsxs)(`div`,{style:{borderTop:`1px solid var(--line)`,paddingTop:16},children:[(0,I.jsx)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:12},children:`Organization Settings`}),(0,I.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:fH.map(e=>{let t=f(e),n=p(e),r=pH[e],i=t?{text:`from org`,color:`var(--accent, #4f46e5)`}:n?{text:`from global`,color:`var(--muted)`}:{text:`default`,color:`var(--faint)`},a=c===e,u=t?.value??n?.value??null;return(0,I.jsxs)(`div`,{style:{background:`var(--surface, var(--bg))`,border:`1px solid var(--line)`,borderRadius:6,padding:`10px 12px`},children:[(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:a?10:0},children:[(0,I.jsxs)(`div`,{style:{flex:1},children:[(0,I.jsx)(`div`,{style:{fontSize:12,fontWeight:600,color:`var(--text)`},children:r.en}),(0,I.jsx)(`div`,{style:{fontSize:11,color:`var(--muted)`},children:r.pt})]}),(0,I.jsx)(`span`,{style:{fontSize:10,padding:`2px 6px`,borderRadius:4,background:`transparent`,border:`1px solid ${i.color}`,color:i.color,fontWeight:600},children:i.text}),!a&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>l(e),children:t?`Edit`:`Override`}),t&&(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>h(e),disabled:s.isPending,style:{color:`var(--danger, #e53e3e)`},title:`Remove org override (falls back to global)`,children:`Reset`})]})]}),e===`organizations_policy`&&(a?(0,I.jsx)(bH,{initial:hH(u),saving:o.isPending,onSave:t=>m(e,t),onCancel:()=>l(null)}):(0,I.jsx)(vH,{value:hH(u)})),e===`roles_catalog`&&(a?(0,I.jsx)(xH,{initial:gH(u),saving:o.isPending,onSave:t=>m(e,t),onCancel:()=>l(null)}):(0,I.jsx)(yH,{value:gH(u)}))]},e)})})]})}function vH({value:e}){return(0,I.jsxs)(`div`,{style:{marginTop:8,display:`flex`,gap:6,flexWrap:`wrap`},children:[(0,I.jsxs)(`span`,{className:`badge badge-muted`,children:[`self-create: `,e.allowSelfCreate?`on`:`off`]}),(0,I.jsxs)(`span`,{className:`badge badge-muted`,children:[`invite TTL: `,e.invitationTtlHours,`h`]}),e.roles.map(e=>(0,I.jsx)(`span`,{className:`badge badge-muted`,children:e},e))]})}function yH({value:e}){return(0,I.jsx)(`div`,{style:{marginTop:8,display:`flex`,gap:6,flexWrap:`wrap`},children:e.roles.map(e=>(0,I.jsx)(`span`,{className:`badge badge-muted`,title:e.description??``,children:e.name},e.name))})}function bH({initial:e,saving:t,onSave:n,onCancel:r}){let[i,a]=(0,F.useState)(e.allowSelfCreate),[o,s]=(0,F.useState)(e.invitationTtlHours),[c,l]=(0,F.useState)(e.roles);return(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,I.jsx)(lH,{label:`Allow self-create`,hint:`Members can create their own organizations`,children:(0,I.jsx)(uH,{checked:i,onChange:a})}),(0,I.jsx)(lH,{label:`Invitation TTL`,hint:`Hours before a pending invitation expires`,children:(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6},children:[(0,I.jsx)(`input`,{className:`input`,type:`number`,min:1,value:o,onChange:e=>s(Number(e.target.value)),style:{width:80}}),(0,I.jsx)(`span`,{style:{fontSize:11,color:`var(--faint)`},children:`h`})]})}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{style:{fontSize:12,fontWeight:500,color:`var(--text)`,marginBottom:6},children:`Organization roles`}),(0,I.jsx)(dH,{values:c,onChange:l,locked:[`owner`],placeholder:`new role…`})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,I.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,disabled:t,onClick:()=>n({allowSelfCreate:i,invitationTtlHours:o,roles:c}),children:t?`Saving…`:`Save`}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:r,children:`Cancel`})]})]})}function xH({initial:e,saving:t,onSave:n,onCancel:r}){let[i,a]=(0,F.useState)(e.roles.map(e=>({name:e.name,description:e.description??``}))),[o,s]=(0,F.useState)(``),[c,l]=(0,F.useState)(``);function u(){let e=o.trim().toUpperCase();!e||i.some(t=>t.name===e)||(a([...i,{name:e,description:c.trim()}]),s(``),l(``))}return(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[i.map((e,t)=>(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6,alignItems:`center`},children:[(0,I.jsx)(`span`,{className:`badge badge-muted`,style:{minWidth:70,justifyContent:`center`},children:e.name}),(0,I.jsx)(`input`,{className:`input`,value:e.description,onChange:e=>a(i.map((n,r)=>r===t?{...n,description:e.target.value}:n)),placeholder:`description…`,style:{flex:1}}),e.name!==`ADMIN`&&(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,style:{color:`var(--danger, #e53e3e)`},onClick:()=>a(i.filter((e,n)=>n!==t)),children:`×`})]},e.name)),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,I.jsx)(`input`,{className:`input`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),u())},placeholder:`ROLE_NAME`,style:{width:130}}),(0,I.jsx)(`input`,{className:`input`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),u())},placeholder:`description…`,style:{flex:1}}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:u,children:`Add`})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,I.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,disabled:t,onClick:()=>n({roles:i.map(e=>({name:e.name,description:e.description||void 0}))}),children:t?`Saving…`:`Save`}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:r,children:`Cancel`})]})]})}function SH({value:e,onChange:t}){return(0,I.jsx)(`select`,{className:`input`,value:e,onChange:e=>t(e.target.value),style:{width:110},children:(mH.includes(e)?mH:[...mH,e]).map(e=>(0,I.jsx)(`option`,{value:e,children:e},e))})}function CH({orgId:e,onDone:t}){let n=Ic(),r=Ye(),[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(`member`),c=dt(yc(e));async function l(a){if(a.preventDefault(),i)try{await c.mutateAsync({accountId:i.id,role:o}),r.invalidateQueries({queryKey:H.admin.org(e)}),r.invalidateQueries({queryKey:H.admin.orgs()}),n.success(`${i.email} added as ${o}`),t()}catch(e){n.error(e instanceof Error?e.message:`Failed to add member`)}}return(0,I.jsx)(`form`,{onSubmit:l,style:{display:`flex`,flexDirection:`column`,gap:8},children:i?(0,I.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,flexWrap:`wrap`},children:[(0,I.jsx)(cH,{user:i,onClear:()=>a(null)}),(0,I.jsx)(SH,{value:o,onChange:s}),(0,I.jsx)(`button`,{type:`submit`,className:`btn btn-primary btn-sm`,disabled:c.isPending,children:c.isPending?`Adding…`:`Add member`}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:t,children:`Cancel`})]}):(0,I.jsxs)(`div`,{children:[(0,I.jsx)(sH,{onPick:a}),(0,I.jsx)(`div`,{style:{marginTop:6,display:`flex`,justifyContent:`flex-end`},children:(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:t,children:`Cancel`})})]})})}function wH({orgId:e,onDone:t}){let n=Ic(),r=Ye(),[i,a]=(0,F.useState)(``),[o,s]=(0,F.useState)(`member`),c=dt(Sc(e));async function l(s){if(s.preventDefault(),i.trim())try{await c.mutateAsync({email:i.trim(),role:o}),r.invalidateQueries({queryKey:H.admin.org(e)}),n.success(`Invitation sent`),a(``),t()}catch(e){n.error(e instanceof Error?e.message:`Failed to create invitation`)}}return(0,I.jsxs)(`form`,{onSubmit:l,style:{display:`flex`,gap:8,alignItems:`flex-end`,flexWrap:`wrap`},children:[(0,I.jsxs)(`div`,{style:{flex:1,minWidth:180},children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Email`}),(0,I.jsx)(`input`,{className:`input`,type:`email`,value:i,onChange:e=>a(e.target.value),placeholder:`user@example.com`,required:!0})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Role`}),(0,I.jsx)(SH,{value:o,onChange:s})]}),(0,I.jsx)(`button`,{type:`submit`,className:`btn btn-primary btn-sm`,disabled:c.isPending,children:c.isPending?`Sending…`:`Invite`}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:t,children:`Cancel`})]})}function TH({orgId:e,member:t}){let n=Ic(),r=Ye(),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(t.role),c=dt(bc(e,t.accountId)),l=dt(xc(e,t.accountId));async function u(){try{await c.mutateAsync(),r.invalidateQueries({queryKey:H.admin.org(e)}),r.invalidateQueries({queryKey:H.admin.orgs()}),n.success(`Member removed`)}catch(e){n.error(e instanceof Error?e.message:`Failed to remove member`)}}async function d(t){t.preventDefault();try{await l.mutateAsync(o),r.invalidateQueries({queryKey:H.admin.org(e)}),n.success(`Role updated`),a(!1)}catch(e){n.error(e instanceof Error?e.message:`Failed to update role`)}}return(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`6px 0`,borderBottom:`1px solid var(--line)`},children:[(0,I.jsx)(`div`,{className:`avatar`,style:{width:24,height:24,fontSize:9},children:(t.email??`?`).slice(0,2).toUpperCase()}),(0,I.jsx)(`div`,{style:{flex:1},children:(0,I.jsx)(`div`,{style:{fontSize:12,color:`var(--text)`},children:t.email??t.accountId})}),i?(0,I.jsxs)(`form`,{onSubmit:d,style:{display:`flex`,gap:4},children:[(0,I.jsx)(`input`,{className:`input`,value:o,onChange:e=>s(e.target.value),style:{width:80,padding:`2px 6px`,fontSize:11}}),(0,I.jsx)(`button`,{type:`submit`,className:`btn btn-primary btn-sm`,disabled:l.isPending,children:`✓`}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>a(!1),children:`✕`})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{className:`badge badge-muted`,title:`Click to change role`,onClick:()=>a(!0),style:{cursor:`pointer`,background:`none`,border:`1px solid var(--line)`},children:t.role}),(0,I.jsx)(`button`,{className:`icon-btn`,title:`Remove member`,onClick:u,disabled:c.isPending,style:{color:`var(--danger, #e53e3e)`,fontSize:13},children:`✕`})]})]})}function EH({orgId:e,invitation:t}){let n=Ic(),r=Ye(),i=dt(Cc(e,t.id));async function a(){try{await i.mutateAsync(),r.invalidateQueries({queryKey:H.admin.org(e)}),n.success(`Invitation revoked`)}catch(e){n.error(e instanceof Error?e.message:`Failed to revoke invitation`)}}return(0,I.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`6px 0`,borderBottom:`1px solid var(--line)`},children:[(0,I.jsx)(`div`,{style:{flex:1,fontSize:12,color:`var(--muted)`},children:t.email}),(0,I.jsx)(`span`,{className:`badge badge-amber`,children:t.role}),(0,I.jsx)(`button`,{className:`icon-btn`,title:`Revoke invitation`,onClick:a,disabled:i.isPending,style:{color:`var(--danger, #e53e3e)`,fontSize:13},children:`✕`})]})}var DH=20;function OH(e){return e.toLowerCase().normalize(`NFD`).replace(/[̀-ͯ]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function kH({open:e,onClose:t,onCreated:n}){let r=Ic(),i=Ye(),[a,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(null),p=dt(gc());function m(e){o(e),l||c(OH(e))}async function h(e){if(e.preventDefault(),!(!a.trim()||!s.trim()||!d))try{await p.mutateAsync({name:a.trim(),slug:s.trim(),ownerAccountId:d.id}),i.invalidateQueries({queryKey:H.admin.orgs()}),r.success(`Organization created`),o(``),c(``),f(null),u(!1),n()}catch(e){r.error(e instanceof Error?e.message:`Failed to create organization`)}}return e?(0,I.jsx)(`div`,{className:`modal-backdrop`,onClick:t,children:(0,I.jsxs)(`div`,{className:`modal`,onClick:e=>e.stopPropagation(),children:[(0,I.jsxs)(`div`,{className:`modal-head`,children:[(0,I.jsx)(`span`,{children:`New Organization`}),(0,I.jsx)(`button`,{className:`icon-btn`,onClick:t,children:`✕`})]}),(0,I.jsxs)(`form`,{onSubmit:h,style:{display:`flex`,flexDirection:`column`,gap:14},children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Name`}),(0,I.jsx)(`input`,{className:`input`,value:a,onChange:e=>m(e.target.value),placeholder:`Acme Inc.`,required:!0})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Slug`}),(0,I.jsx)(`input`,{className:`input`,value:s,onChange:e=>{c(e.target.value),u(!0)},placeholder:`acme-inc`,required:!0})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Owner`}),d?(0,I.jsx)(cH,{user:d,onClear:()=>f(null)}):(0,I.jsx)(sH,{onPick:f,placeholder:`Search the initial owner by email…`})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:8,justifyContent:`flex-end`,marginTop:4},children:[(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:t,children:`Cancel`}),(0,I.jsx)(`button`,{type:`submit`,className:`btn btn-primary`,disabled:p.isPending,children:p.isPending?`Creating…`:`Create`})]})]})]})}):null}function AH({search:e,page:t,onPage:n,onSelectOrg:r,onUnavailable:i,onCreateClick:a}){let[o,s]=(0,F.useState)(!1),{data:c,isLoading:l,error:u,refetch:d}=ut({...mc(),retry:(e,t)=>t&&typeof t==`object`&&`status`in t&&t.status===404?(o||(s(!0),i()),!1):e<1}),f=c?.data??[],p=e?f.filter(t=>t.name.toLowerCase().includes(e.toLowerCase())||t.slug.toLowerCase().includes(e.toLowerCase())):f,m=p.length,h=p.slice((t-1)*DH,t*DH),g=u&&typeof u==`object`&&`status`in u&&u.status===404;return(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(yV,{isLoading:l,error:u&&!g?u:void 0,onRetry:d,skeleton:(0,I.jsx)(EV,{rows:6,cols:4}),children:h.length===0?(0,I.jsxs)(`div`,{className:`empty-state`,children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,I.jsx)(`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1`}),(0,I.jsx)(`rect`,{x:`3`,y:`14`,width:`7`,height:`7`,rx:`1`}),(0,I.jsx)(`rect`,{x:`14`,y:`3`,width:`7`,height:`7`,rx:`1`}),(0,I.jsx)(`path`,{d:`M17.5 14v7M14 17.5h7`,strokeLinecap:`round`})]}),(0,I.jsx)(`h4`,{children:`No organizations`}),(0,I.jsx)(`p`,{children:e?`No results for your search`:`No organizations created yet`}),!e&&(0,I.jsx)(`button`,{className:`btn btn-primary`,style:{marginTop:12},onClick:a,children:`New organization`})]}):(0,I.jsxs)(`div`,{className:`tbl-wrap`,children:[(0,I.jsxs)(`table`,{children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`Name`}),(0,I.jsx)(`th`,{children:`Slug`}),(0,I.jsx)(`th`,{children:`Members`}),(0,I.jsx)(`th`,{children:`Created`})]})}),(0,I.jsx)(`tbody`,{children:h.map(e=>(0,I.jsxs)(`tr`,{onClick:()=>r(e.id),children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(`b`,{children:e.name})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`code`,children:e.slug})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`mono text-sm`,children:e.memberCount??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:11,color:`var(--faint)`},children:e.createdAt?new Date(e.createdAt).toLocaleDateString():`—`})})]},e.id))})]}),(0,I.jsx)(`div`,{style:{padding:`0 16px 12px`},children:(0,I.jsx)(zV,{page:t,total:m,perPage:DH,onPage:n})})]})})})}function jH({orgId:e,currentName:t,currentLogoUrl:n,onDone:r}){let i=Ic(),a=Ye(),[o,s]=(0,F.useState)(t),[c,l]=(0,F.useState)(n??``),u=dt(_c(e));async function d(t){t.preventDefault();try{await u.mutateAsync({name:o.trim()||void 0,logoUrl:c.trim()||null}),a.invalidateQueries({queryKey:H.admin.orgs()}),a.invalidateQueries({queryKey:H.admin.org(e)}),i.success(`Organization updated`),r()}catch(e){i.error(e instanceof Error?e.message:`Failed to update organization`)}}return(0,I.jsxs)(`form`,{onSubmit:d,style:{display:`flex`,flexDirection:`column`,gap:10},children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Name`}),(0,I.jsx)(`input`,{className:`input`,value:o,onChange:e=>s(e.target.value)})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`field-label`,children:`Logo URL`}),(0,I.jsx)(`input`,{className:`input`,value:c,onChange:e=>l(e.target.value),placeholder:`https://…`})]}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,I.jsx)(`button`,{type:`submit`,className:`btn btn-primary btn-sm`,disabled:u.isPending,children:u.isPending?`Saving…`:`Save`}),(0,I.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:r,children:`Cancel`})]})]})}function MH({orgId:e,onDeleted:t}){let n=Ic(),r=Ye(),{data:i,isLoading:a,error:o,refetch:s}=ut(hc(e)),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(!1),[m,h]=(0,F.useState)(!1),g=dt(vc(e));async function _(){try{await g.mutateAsync(),r.invalidateQueries({queryKey:H.admin.orgs()}),n.success(`Organization deleted`),t()}catch(e){n.error(e instanceof Error?e.message:`Failed to delete organization`)}}return(0,I.jsx)(yV,{isLoading:a,error:o,onRetry:s,skeleton:(0,I.jsx)(DV,{}),children:i&&(0,I.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:20},children:[(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:8,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,I.jsx)(`span`,{children:`Info`}),!c&&(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>l(!0),children:`Edit`})]}),c?(0,I.jsx)(jH,{orgId:e,currentName:i.name,currentLogoUrl:i.logoUrl,onDone:()=>l(!1)}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`code`,children:i.id}),(0,I.jsx)(`div`,{style:{marginTop:6,fontSize:12},children:(0,I.jsx)(`span`,{className:`badge badge-muted`,children:i.slug})})]})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:8,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,I.jsxs)(`span`,{children:[`Members (`,i.members.length,`)`]}),!u&&(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>d(!0),children:`+ Add`})]}),u&&(0,I.jsx)(`div`,{style:{marginBottom:10},children:(0,I.jsx)(CH,{orgId:e,onDone:()=>d(!1)})}),i.members.map(t=>(0,I.jsx)(TH,{orgId:e,member:t},t.accountId))]}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--faint)`,fontWeight:600,marginBottom:8,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,I.jsxs)(`span`,{children:[`Pending Invitations (`,i.pendingInvitations.length,`)`]}),!f&&(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>p(!0),children:`+ Invite`})]}),f&&(0,I.jsx)(`div`,{style:{marginBottom:10},children:(0,I.jsx)(wH,{orgId:e,onDone:()=>p(!1)})}),i.pendingInvitations.length===0&&!f&&(0,I.jsx)(`div`,{style:{fontSize:12,color:`var(--faint)`},children:`No pending invitations`}),i.pendingInvitations.map(t=>(0,I.jsx)(EH,{orgId:e,invitation:t},t.id))]}),(0,I.jsx)(_H,{orgId:e}),(0,I.jsxs)(`div`,{style:{borderTop:`1px solid var(--line)`,paddingTop:16},children:[(0,I.jsx)(`div`,{style:{fontSize:10.5,letterSpacing:`0.12em`,textTransform:`uppercase`,color:`var(--danger, #e53e3e)`,fontWeight:600,marginBottom:8},children:`Danger Zone`}),m?(0,I.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,fontSize:13},children:[(0,I.jsx)(`span`,{style:{color:`var(--muted)`},children:`Delete this organization?`}),(0,I.jsx)(`button`,{className:`btn btn-danger btn-sm`,onClick:_,disabled:g.isPending,children:g.isPending?`Deleting…`:`Yes, delete`}),(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>h(!1),children:`Cancel`})]}):(0,I.jsx)(`button`,{className:`btn btn-danger btn-sm`,onClick:()=>h(!0),children:`Delete organization`})]})]})})}function NH({orgId:e,onClose:t}){let{data:n}=ut(hc(e));return(0,I.jsx)(RV,{open:!0,onClose:t,title:n?.name??`Organization`,children:(0,I.jsx)(MH,{orgId:e,onDeleted:t})})}function PH(e){let{data:t}=ut(mc()),n=t?.data??[];return(e?n.filter(t=>t.name.toLowerCase().includes(e.toLowerCase())||t.slug.toLowerCase().includes(e.toLowerCase())):n).length}function FH(){let[e,t]=Jc(`page`,Bc.withDefault(1)),[n,r]=Jc(`q`,zc.withDefault(``)),[i,a]=Jc(`org`),o=LV(n,300),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(!1),d=PH(o);return s?(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,style:{marginBottom:8},children:`Organizations`}),(0,I.jsx)(`div`,{className:`error-box`,children:`Organizations are not enabled in this AuthKit installation.`})]}):(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header-row`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,children:`Organizations`}),(0,I.jsxs)(`div`,{className:`page-sub`,children:[d.toLocaleString(),` orgs`]})]}),(0,I.jsx)(`button`,{className:`btn btn-primary`,onClick:()=>u(!0),children:`New organization`})]}),(0,I.jsx)(`div`,{className:`panel`,style:{marginBottom:0},children:(0,I.jsx)(`div`,{className:`panel-head`,children:(0,I.jsxs)(`div`,{className:`search-input`,style:{flex:1,maxWidth:300},children:[(0,I.jsxs)(`svg`,{className:`search-ico`,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,children:[(0,I.jsx)(`circle`,{cx:`7`,cy:`7`,r:`4.5`}),(0,I.jsx)(`path`,{d:`M10 10l3 3`,strokeLinecap:`round`})]}),(0,I.jsx)(`input`,{className:`input`,placeholder:`Search organizations…`,value:n,onChange:e=>{r(e.target.value),t(1)}})]})})}),(0,I.jsx)(AH,{search:o,page:e,onPage:t,onSelectOrg:a,onUnavailable:()=>c(!0),onCreateClick:()=>u(!0)}),i&&(0,I.jsx)(NH,{orgId:i,onClose:()=>a(null)}),(0,I.jsx)(kH,{open:l,onClose:()=>u(!1),onCreated:()=>u(!1)})]})}function IH(e){return e.includes(`login`)||e.includes(`signin`)||e.includes(`success`)?`badge-green`:e.includes(`fail`)||e.includes(`error`)||e.includes(`locked`)||e.includes(`block`)?`badge-red`:e.includes(`register`)||e.includes(`signup`)||e.includes(`created`)?`badge-accent`:e.includes(`settings`)||e.includes(`admin`)||e.includes(`updated`)?`badge-amber`:`badge-muted`}var LH=30;function RH({typeFilter:e,page:t,onPage:n,selected:r,onSelect:i,onUnavailable:a}){let[o,s]=(0,F.useState)(!1),{data:c,isLoading:l,error:u,refetch:d}=ut({...wc({type:e||void 0,page:t,limit:LH}),retry:(e,t)=>t&&typeof t==`object`&&`status`in t&&t.status===404?(o||(s(!0),a()),!1):e<1}),f=c?.data??[],p=c?.total??0,m=u&&typeof u==`object`&&`status`in u&&u.status===404;return(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(yV,{isLoading:l,error:u&&!m?u:void 0,onRetry:d,skeleton:(0,I.jsx)(EV,{rows:8,cols:4}),children:f.length===0?(0,I.jsxs)(`div`,{className:`empty-state`,children:[(0,I.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:(0,I.jsx)(`path`,{d:`M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2`,strokeLinecap:`round`})}),(0,I.jsx)(`h4`,{children:`No events found`}),(0,I.jsx)(`p`,{children:e?`No events match this filter`:`No audit events recorded yet`})]}):(0,I.jsxs)(`div`,{className:`tbl-wrap`,children:[(0,I.jsxs)(`table`,{children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{children:`Type`}),(0,I.jsx)(`th`,{children:`Account`}),(0,I.jsx)(`th`,{children:`IP`}),(0,I.jsx)(`th`,{children:`When`})]})}),(0,I.jsx)(`tbody`,{children:f.map(e=>(0,I.jsxs)(`tr`,{onClick:()=>i(r?.id===e.id?null:e),children:[(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`badge ${IH(e.type)}`,children:e.type})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:11.5},children:e.email??e.accountId??(0,I.jsx)(`span`,{style:{color:`var(--faint)`},children:`—`})})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{className:`code`,children:e.ip??`—`})}),(0,I.jsx)(`td`,{children:(0,I.jsx)(`span`,{style:{fontFamily:`var(--mono)`,fontSize:11,color:`var(--faint)`},children:e.createdAt?new Date(e.createdAt).toLocaleString():`—`})})]},e.id))})]}),(0,I.jsx)(`div`,{style:{padding:`0 16px 12px`},children:(0,I.jsx)(zV,{page:t,total:p,perPage:LH,onPage:n})})]})})})}function zH({event:e,onClose:t}){return(0,I.jsxs)(`div`,{className:`panel`,style:{padding:`14px 16px`},children:[(0,I.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:10},children:[(0,I.jsx)(`div`,{style:{fontWeight:600,fontSize:13},children:`Event Detail`}),(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:t,children:(0,I.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,I.jsx)(`path`,{d:`M3 3l10 10M13 3L3 13`,strokeLinecap:`round`})})})]}),(0,I.jsx)(`pre`,{style:{fontFamily:`var(--mono)`,fontSize:11.5,color:`var(--muted)`,overflow:`auto`,lineHeight:1.6},children:JSON.stringify(e,null,2)})]})}var BH=[``,`login.success`,`login.failed`,`login.mfa_required`,`logout`,`register`,`password_reset`,`settings.updated`,`client.created`,`client.deleted`,`account.disabled`,`account.enabled`];function VH(){let[e,t]=Jc(`page`,Bc.withDefault(1)),[n,r]=Jc(`type`,zc.withDefault(``)),[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(!1);return o?(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,style:{marginBottom:8},children:`Audit Log`}),(0,I.jsx)(`div`,{className:`error-box`,children:`Audit log is not configured. Add an audit sink to your AuthKit config.`})]}):(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-header-row`,children:(0,I.jsx)(`div`,{children:(0,I.jsx)(`div`,{className:`page-title`,children:`Audit Log`})})}),(0,I.jsx)(`div`,{className:`panel`,style:{marginBottom:0},children:(0,I.jsx)(`div`,{className:`panel-head`,children:(0,I.jsx)(`select`,{className:`input`,style:{width:240},value:n,onChange:e=>{r(e.target.value),t(1)},children:BH.map(e=>(0,I.jsx)(`option`,{value:e,children:e||`All event types`},e))})})}),(0,I.jsx)(RH,{typeFilter:n,page:e,onPage:t,selected:i,onSelect:a,onUnavailable:()=>s(!0)}),i&&(0,I.jsx)(`div`,{style:{marginTop:12},children:(0,I.jsx)(zH,{event:i,onClose:()=>a(null)})})]})}function HH(){let e=Ic(),t=Ye(),{data:n,isLoading:r,error:i,refetch:a}=ut({...kc(),retry:(e,t)=>t&&typeof t==`object`&&`status`in t&&t.status===501?!1:e<1}),o=dt(Ac()),s=dt(Ec()),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(null),m=i&&typeof i==`object`&&`status`in i&&i.status===501;if(m)return(0,I.jsxs)(`div`,{className:`error-box`,children:[`Rotação indisponível: o `,(0,I.jsx)(`code`,{children:`jwks`}),` não é `,(0,I.jsx)(`code`,{children:`managed`}),` com um `,(0,I.jsx)(`code`,{children:`store`}),` persistente (ex.: `,(0,I.jsx)(`code`,{children:`{ source: 'managed', store: { driver: 'lucid' } }`}),`). Chaves inline (`,(0,I.jsx)(`code`,{children:`source: 'jwks'`}),`) não rotacionam.`]});let h=n?.policy,g=c??h?.maxAgeDays??90,_=u??h?.keep??2;async function v(n){p(`policy`);try{let r={enabled:n.enabled??h?.enabled??!1,maxAgeDays:n.maxAgeDays??g,keep:n.keep??_};await s.mutateAsync({key:`key_rotation`,value:r}),t.invalidateQueries({queryKey:H.admin.keys()}),l(null),d(null),e.success(`Política de rotação salva`)}catch(t){e.error(t instanceof Error?t.message:String(t))}finally{p(null)}}async function y(n){let r=n?`Isso DESABILITA todas as chaves atuais e cria uma nova. Tokens já emitidos deixam de validar imediatamente. Continuar?`:`Rotacionar agora? Uma chave nova vira a ativa; as antigas continuam validando (janela de grace).`;if(window.confirm(r)){p(n?`retire`:`rotate`);try{let r=await o.mutateAsync(n?{retire:!0}:{keep:_});t.invalidateQueries({queryKey:H.admin.keys()}),e.success(`Rotacionado. Nova chave: ${r.newKid.slice(0,8)}…`)}catch(t){e.error(t instanceof Error?t.message:String(t))}finally{p(null)}}}return(0,I.jsx)(yV,{isLoading:r,error:m?void 0:i,onRetry:a,skeleton:(0,I.jsx)(xV,{width:`100%`,height:220}),children:n&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`panel`,style:{marginBottom:16},children:(0,I.jsx)(`div`,{className:`panel-body`,children:(0,I.jsxs)(`div`,{className:`settings-row`,children:[(0,I.jsxs)(`div`,{className:`settings-info`,children:[(0,I.jsx)(`div`,{className:`settings-key`,children:`Chave de assinatura ativa`}),(0,I.jsx)(`div`,{style:{fontFamily:`var(--mono)`,fontSize:12},children:n.keys.find(e=>e.active)?.kid??`—`})]}),(0,I.jsxs)(`div`,{className:`settings-info`,style:{textAlign:`right`},children:[(0,I.jsxs)(`div`,{className:`settings-desc`,children:[`Idade: `,n.ageDays,` dia(s)`]}),(0,I.jsxs)(`div`,{className:`settings-desc`,children:[`Próxima rotação: `,n.nextRotationInDays===null?`— (auto off)`:`~${n.nextRotationInDays} dia(s)`]})]})]})})}),(0,I.jsxs)(`div`,{className:`settings-section`,children:[(0,I.jsx)(`div`,{className:`settings-section-head`,children:(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{children:`Rotação automática`}),(0,I.jsx)(`p`,{style:{marginTop:2},children:`Gera uma chave nova quando a ativa passa da idade máxima; mantém as N mais recentes (janela de grace).`})]})}),(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsxs)(`div`,{className:`panel-body`,style:{padding:0},children:[(0,I.jsxs)(`div`,{className:`settings-row`,children:[(0,I.jsxs)(`div`,{className:`settings-info`,children:[(0,I.jsx)(`div`,{className:`settings-key`,children:`Habilitar rotação agendada`}),(0,I.jsx)(`div`,{className:`settings-desc`,children:`key_rotation.enabled`})]}),(0,I.jsx)(`div`,{className:`settings-control`,children:(0,I.jsxs)(`label`,{className:`toggle`,children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:!!h?.enabled,disabled:f===`policy`,onChange:e=>v({enabled:e.target.checked})}),(0,I.jsx)(`div`,{className:`toggle-track`}),(0,I.jsx)(`div`,{className:`toggle-thumb`})]})})]}),(0,I.jsxs)(`div`,{className:`settings-row`,children:[(0,I.jsxs)(`div`,{className:`settings-info`,children:[(0,I.jsx)(`div`,{className:`settings-key`,children:`Idade máxima (dias)`}),(0,I.jsx)(`div`,{className:`settings-desc`,children:`key_rotation.maxAgeDays`})]}),(0,I.jsxs)(`div`,{className:`settings-control`,children:[(0,I.jsx)(`input`,{className:`input input-mono`,type:`number`,style:{width:90,textAlign:`right`},value:String(g),onChange:e=>l(Number(e.target.value))}),c!==null&&(0,I.jsx)(`button`,{className:`btn btn-primary btn-sm`,disabled:f===`policy`,onClick:()=>v({maxAgeDays:g}),children:`Save`})]})]}),(0,I.jsxs)(`div`,{className:`settings-row`,children:[(0,I.jsxs)(`div`,{className:`settings-info`,children:[(0,I.jsx)(`div`,{className:`settings-key`,children:`Manter N chaves (grace)`}),(0,I.jsx)(`div`,{className:`settings-desc`,children:`key_rotation.keep`})]}),(0,I.jsxs)(`div`,{className:`settings-control`,children:[(0,I.jsx)(`input`,{className:`input input-mono`,type:`number`,style:{width:90,textAlign:`right`},value:String(_),onChange:e=>d(Number(e.target.value))}),u!==null&&(0,I.jsx)(`button`,{className:`btn btn-primary btn-sm`,disabled:f===`policy`,onClick:()=>v({keep:_}),children:`Save`})]})]})]})})]}),(0,I.jsxs)(`div`,{className:`settings-section`,children:[(0,I.jsx)(`div`,{className:`settings-section-head`,children:(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{children:`Chaves no keyset`}),(0,I.jsx)(`p`,{style:{marginTop:2},children:`A primeira é a ativa (assina); as demais ainda validam tokens (grace).`})]})}),(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(`div`,{className:`panel-body`,style:{padding:0},children:n.keys.map(e=>(0,I.jsx)(`div`,{className:`settings-row`,children:(0,I.jsxs)(`div`,{className:`settings-info`,children:[(0,I.jsxs)(`div`,{className:`settings-key`,style:{fontFamily:`var(--mono)`,fontSize:12},children:[e.kid,(0,I.jsx)(`span`,{className:`settings-badge`,style:e.active?{background:`var(--accent-soft, rgba(99,102,241,0.12))`,color:`var(--accent, #6366f1)`}:void 0,children:e.active?`ativa`:`grace`})]}),(0,I.jsxs)(`div`,{className:`settings-desc`,children:[e.alg,` · `,e.ageDays,` dia(s)`]})]})},e.kid))})})]}),(0,I.jsxs)(`div`,{className:`settings-section`,children:[(0,I.jsx)(`div`,{className:`settings-section-head`,children:(0,I.jsx)(`div`,{children:(0,I.jsx)(`h3`,{children:`Ações`})})}),(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsxs)(`div`,{className:`panel-body`,style:{display:`flex`,gap:12,flexWrap:`wrap`},children:[(0,I.jsx)(`button`,{className:`btn btn-primary`,disabled:!!f,onClick:()=>y(!1),children:f===`rotate`?(0,I.jsx)(`span`,{className:`spinner sm`}):`Rotacionar agora`}),(0,I.jsx)(`button`,{className:`btn btn-ghost`,disabled:!!f,onClick:()=>y(!0),style:{color:`var(--danger, #e5484d)`,borderColor:`var(--danger, #e5484d)`},children:f===`retire`?(0,I.jsx)(`span`,{className:`spinner sm`}):`Desabilitar todas + criar nova`})]})})]})]})})}function UH(){return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header`,children:[(0,I.jsx)(`div`,{className:`page-title`,children:`Signing Keys`}),(0,I.jsx)(`div`,{className:`page-sub`,children:`Chaves JWKS de assinatura — rotação, grace e status. Mudanças aplicam ao vivo.`})]}),(0,I.jsx)(HH,{})]})}function WH({rowCount:e=4}){return(0,I.jsx)(`div`,{style:{background:`var(--bg2)`,border:`1px solid var(--line)`,borderRadius:`var(--radius)`,overflow:`hidden`},children:Array.from({length:e}).map((t,n)=>(0,I.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,padding:`14px 16px`,borderBottom:n<e-1?`1px solid var(--line)`:void 0,gap:16},children:[(0,I.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,gap:6},children:[(0,I.jsx)(xV,{width:`40%`,height:13}),(0,I.jsx)(xV,{width:`70%`,height:11})]}),(0,I.jsx)(xV,{width:44,height:24,borderRadius:12})]},n))})}function GH(){return(0,I.jsxs)(`span`,{className:`settings-badge`,title:`Definido via defineConfig() — gerenciado no código, não editável aqui`,style:{background:`var(--accent-soft, rgba(99,102,241,0.12))`,color:`var(--accent, #6366f1)`,borderColor:`rgba(99,102,241,0.3)`,display:`inline-flex`,alignItems:`center`,gap:4},children:[(0,I.jsxs)(`svg`,{viewBox:`0 0 16 16`,width:`10`,height:`10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,"aria-hidden":!0,children:[(0,I.jsx)(`rect`,{x:`3`,y:`7`,width:`10`,height:`7`,rx:`1.5`}),(0,I.jsx)(`path`,{d:`M5 7V5a3 3 0 016 0v2`,strokeLinecap:`round`})]}),`definido via config`]})}function KH({section:e,onUnavailable:t}){let n=Ic(),r=Ye(),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(null),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(!1),{data:f,isLoading:p,error:m,refetch:h}=ut({...Tc(),retry:(e,n)=>n&&typeof n==`object`&&`status`in n&&n.status===404?(i||(a(!0),t()),!1):e<1}),g=f?.data??[],_=(f?.locked??[]).includes(e.settingKey),v=g.find(t=>t.key===e.settingKey),y=!v,b=v&&typeof v.value==`object`&&v.value!==null&&!Array.isArray(v.value)?v.value:{},x=o??b;(0,F.useEffect)(()=>{s(null),l(!1)},[f]);let S=dt(Ec()),C=dt(Dc());function w(e){return e.field in x?x[e.field]:e.defaultValue}function T(e,t){s(n=>({...n??b,[e.field]:t})),l(!0)}async function E(){d(!0);try{let t={...x};for(let n of e.fields)n.field in t||(t[n.field]=n.defaultValue);await S.mutateAsync({key:e.settingKey,value:t}),r.invalidateQueries({queryKey:H.admin.settings()}),l(!1),n.success(`Salvo: ${e.settingKey}`)}catch(e){n.error(e instanceof Error?e.message:String(e))}finally{d(!1)}}async function D(){d(!0);try{await C.mutateAsync(e.settingKey),r.invalidateQueries({queryKey:H.admin.settings()}),s(null),l(!1),n.success(`Voltou ao default: ${e.settingKey}`)}catch(e){n.error(e instanceof Error?e.message:String(e))}finally{d(!1)}}let O=m&&typeof m==`object`&&`status`in m&&m.status===404,k=m&&!O?m:void 0;return(0,I.jsxs)(`div`,{className:`settings-section`,children:[(0,I.jsxs)(`div`,{className:`settings-section-head`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`h3`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[e.title,_&&(0,I.jsx)(GH,{}),!_&&!y&&(0,I.jsx)(`span`,{className:`settings-badge`,children:`custom`}),c&&!_&&(0,I.jsx)(`span`,{className:`settings-badge`,style:{background:`var(--amber-soft)`,color:`var(--amber)`,borderColor:`rgba(255,180,84,0.3)`},children:`unsaved`})]}),(0,I.jsx)(`p`,{style:{marginTop:2},children:e.description}),_&&(0,I.jsxs)(`p`,{style:{marginTop:4,color:`var(--accent, #6366f1)`,fontSize:12},children:[`Travado no `,(0,I.jsx)(`code`,{children:`defineConfig()`}),` — o config tem prioridade sobre o runtime. Remova de lá para editar por aqui.`]}),(0,I.jsx)(`div`,{style:{fontSize:10.5,color:`var(--faint)`,fontFamily:`var(--mono)`,marginTop:2},children:e.settingKey})]}),!_&&(0,I.jsxs)(`div`,{className:`settings-control`,style:{gap:8},children:[c&&(0,I.jsx)(`button`,{className:`btn btn-primary btn-sm`,disabled:u,onClick:E,children:u?(0,I.jsx)(`span`,{className:`spinner sm`}):`Salvar`}),!y&&!c&&(0,I.jsx)(`button`,{className:`btn btn-ghost btn-sm`,disabled:u,onClick:D,title:`Voltar ao default`,children:(0,I.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,children:[(0,I.jsx)(`path`,{d:`M2 8a6 6 0 016-6 6 6 0 014.24 1.76L14 5`,strokeLinecap:`round`}),(0,I.jsx)(`path`,{d:`M14 2v3h-3`,strokeLinecap:`round`})]})})]})]}),(0,I.jsx)(yV,{isLoading:p,error:k,onRetry:h,skeleton:(0,I.jsx)(WH,{rowCount:e.fields.length}),children:(0,I.jsx)(`div`,{className:`panel`,children:(0,I.jsx)(`div`,{className:`panel-body`,style:{padding:0},children:e.fields.map(e=>{let t=w(e);return(0,I.jsxs)(`div`,{className:`settings-row`,style:_?{opacity:.85}:void 0,children:[(0,I.jsxs)(`div`,{className:`settings-info`,children:[(0,I.jsx)(`div`,{className:`settings-key`,children:e.label}),(0,I.jsx)(`div`,{className:`settings-desc`,children:e.description})]}),(0,I.jsx)(`div`,{className:`settings-control`,children:e.type===`boolean`?(0,I.jsxs)(`label`,{className:`toggle`,children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:!!t,disabled:_,onChange:t=>T(e,t.target.checked)}),(0,I.jsx)(`div`,{className:`toggle-track`}),(0,I.jsx)(`div`,{className:`toggle-thumb`})]}):e.type===`number`?(0,I.jsx)(`input`,{className:`input input-mono`,type:`number`,style:{width:90,textAlign:`right`},value:String(t??e.defaultValue??0),disabled:_,onChange:t=>T(e,Number(t.target.value))}):(0,I.jsx)(`input`,{className:`input`,style:{width:220},value:String(t??e.defaultValue??``),disabled:_,onChange:t=>T(e,t.target.value)})})]},e.field)})})})})]})}var qH=[{title:`Métodos de login`,description:`Quais métodos a tela de login oferece. Travável via defineConfig({ authMethods }).`,settingKey:`auth_methods`,fields:[{field:`password`,label:`Senha`,description:`Login por e-mail + senha`,type:`boolean`,defaultValue:!0},{field:`magicLink`,label:`Magic link`,description:`Login por link enviado no e-mail (requer mail + passwordless.magicLink)`,type:`boolean`,defaultValue:!1},{field:`passkey`,label:`Passkey`,description:`Entrar com passkey (WebAuthn) antes da senha`,type:`boolean`,defaultValue:!1},{field:`forgotPassword`,label:`Esqueci a senha`,description:`Link de reset (só aparece com senha ligada)`,type:`boolean`,defaultValue:!0},{field:`passkeyAutofill`,label:`Autofill de passkey`,description:`Sugestões de passkey no input de e-mail (conditional mediation)`,type:`boolean`,defaultValue:!0}]},{title:`Cadastro`,description:`Cadastro público (self-service).`,settingKey:`registration`,fields:[{field:`enabled`,label:`Permitir cadastro`,description:`Novos usuários podem se cadastrar sozinhos`,type:`boolean`,defaultValue:!0}]},{title:`Verificação de e-mail`,description:`Exigir e-mail verificado para logar.`,settingKey:`require_verified_email`,fields:[{field:`enabled`,label:`Exigir e-mail verificado`,description:`Bloqueia login de contas com e-mail não verificado`,type:`boolean`,defaultValue:!1},{field:`graceDays`,label:`Dias de graça`,description:`Permite login não-verificado por N dias após o cadastro (0 = sem graça)`,type:`number`,defaultValue:0}]},{title:`Manutenção`,description:`Modo manutenção — bloqueia login de contas comuns (admin segue entrando).`,settingKey:`maintenance_mode`,fields:[{field:`enabled`,label:`Modo manutenção`,description:`Telas de login/signup mostram página de manutenção`,type:`boolean`,defaultValue:!1},{field:`message`,label:`Mensagem`,description:`Texto exibido na página de manutenção (vazio = default)`,type:`string`,defaultValue:``}]},{title:`Bloqueio por falha (lockout)`,description:`Trava a conta após tentativas de login falhas.`,settingKey:`lockout`,fields:[{field:`enabled`,label:`Ligar lockout`,description:`Trava a conta após muitas falhas de senha`,type:`boolean`,defaultValue:!1},{field:`maxAttempts`,label:`Máx. tentativas`,description:`Falhas antes de travar`,type:`number`,defaultValue:5},{field:`windowSec`,label:`Janela (s)`,description:`Janela em que as falhas contam`,type:`number`,defaultValue:900},{field:`baseLockoutSec`,label:`Trava base (s)`,description:`Duração inicial da trava (backoff exponencial)`,type:`number`,defaultValue:60},{field:`maxLockoutSec`,label:`Trava máx. (s)`,description:`Teto da duração da trava`,type:`number`,defaultValue:3600}]},{title:`TTL dos tokens`,description:`Tempo de vida dos tokens OIDC (segundos).`,settingKey:`token_ttl`,fields:[{field:`accessTokenSec`,label:`Access token (s)`,description:`Validade do access token`,type:`number`,defaultValue:3600},{field:`idTokenSec`,label:`ID token (s)`,description:`Validade do ID token`,type:`number`,defaultValue:3600},{field:`refreshTokenSec`,label:`Refresh token (s)`,description:`Validade do refresh token`,type:`number`,defaultValue:2592e3}]}];function JH(){let[e,t]=(0,F.useState)(!1);return e?(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`page-title`,style:{marginBottom:8},children:`Settings`}),(0,I.jsxs)(`div`,{className:`error-box`,children:[`Runtime settings exigem a tabela `,(0,I.jsx)(`code`,{children:`auth_settings`}),`. Rode a migration para habilitar.`]})]}):(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`page-header`,children:[(0,I.jsx)(`div`,{className:`page-title`,children:`Settings`}),(0,I.jsxs)(`div`,{className:`page-sub`,children:[`Configuração de runtime — mudanças valem na hora. Settings definidas no `,(0,I.jsx)(`code`,{children:`defineConfig()`}),` ficam travadas (config > runtime).`]})]}),qH.map(e=>(0,I.jsx)(KH,{section:e,onUnavailable:()=>t(!0)},e.settingKey))]})}var YH={overview:`Overview`,users:`Users`,sessions:`Sessions`,clients:`OAuth Clients`,roles:`Roles`,orgs:`Organizations`,audit:`Audit Log`,keys:`Signing Keys`,settings:`Settings`};function XH(){let{route:e}=Xc();switch(e){case`overview`:return(0,I.jsx)(FV,{});case`users`:return(0,I.jsx)(GV,{});case`sessions`:return(0,I.jsx)(YV,{});case`clients`:return(0,I.jsx)(rH,{});case`roles`:return(0,I.jsx)(oH,{});case`orgs`:return(0,I.jsx)(FH,{});case`audit`:return(0,I.jsx)(VH,{});case`keys`:return(0,I.jsx)(UH,{});case`settings`:return(0,I.jsx)(JH,{});default:return(0,I.jsx)(FV,{})}}function ZH(){let{route:e}=Xc();return(0,I.jsxs)(`div`,{className:`app-shell`,children:[(0,I.jsx)($c,{}),(0,I.jsxs)(`main`,{className:`main`,children:[(0,I.jsx)(el,{title:YH[e]??`AuthKit Admin`}),(0,I.jsx)(`div`,{className:`content`,children:(0,I.jsx)(F.Suspense,{fallback:(0,I.jsx)(`div`,{className:`loading-row`,children:(0,I.jsx)(`div`,{className:`spinner lg`})}),children:(0,I.jsx)(XH,{})})})]})]})}var QH=document.getElementById(`root`);if(!QH)throw Error(`Root element not found`);var $H=Ys();(0,ft.createRoot)(QH).render((0,I.jsx)(F.StrictMode,{children:(0,I.jsx)(Xe,{client:$H,children:(0,I.jsx)(Js,{children:(0,I.jsx)(Zt,{children:(0,I.jsx)(Mc,{children:(0,I.jsx)(Fc,{children:(0,I.jsx)(ZH,{})})})})})})}));
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
9
9
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
10
10
|
<link href="https://fonts.googleapis.com/css2?family=Sora:wght@400;500;600;700&family=JetBrains+Mono:ital,wght@0,400;0,500;0,600;1,400&display=swap" rel="stylesheet">
|
|
11
|
-
<script type="module" crossorigin src="/__AUTHKIT_BASE__/assets/index-
|
|
11
|
+
<script type="module" crossorigin src="/__AUTHKIT_BASE__/assets/index-BmI_J87g.js"></script>
|
|
12
12
|
<link rel="stylesheet" crossorigin href="/__AUTHKIT_BASE__/assets/index-DTSmD4RU.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonis-agora/authkit-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "AdonisJS OIDC/OAuth2 provider (Identity Provider) toolkit: ejectable auth server with sessions, rate-limiting, MFA/TOTP, audit log, federated logout and OpenTelemetry metrics.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dudousxd",
|