diff --git a/packages/engine/src/engine.ts b/packages/engine/src/engine.ts index 98cf1ce..c66993d 100644 --- a/packages/engine/src/engine.ts +++ b/packages/engine/src/engine.ts @@ -1359,13 +1359,14 @@ function generateApiKey(): string { return 'ogk_' + crypto.randomUUID().replace(/-/g, '') } +// Only 'ingest' role is currently implemented. May expand in the future. export async function createApiKey( db: D1Database, name: string, - role: 'admin' | 'ingest' | 'readonly' = 'ingest', allowedEvents: string[] = [], rateLimit: number = 100, ): Promise { + const role = 'ingest' const key = generateApiKey() const keyHash = await sha256(key) const createdAt = Date.now() @@ -1416,7 +1417,7 @@ export async function listApiKeys( const apiKeys: ApiKey[] = (rows.results || []).map((row) => ({ id: row.id, name: row.name, - role: row.role as 'admin' | 'ingest' | 'readonly', + role: 'ingest' as const, allowed_events: JSON.parse(row.allowed_events), rate_limit: row.rate_limit, last_used_at: row.last_used_at || undefined, @@ -1457,7 +1458,7 @@ export async function validateApiKey( const apiKey: ApiKey = { id: row.id, name: row.name, - role: row.role as 'admin' | 'ingest' | 'readonly', + role: 'ingest' as const, allowed_events: JSON.parse(row.allowed_events), rate_limit: row.rate_limit, last_used_at: row.last_used_at || undefined, diff --git a/packages/engine/src/index.test.ts b/packages/engine/src/index.test.ts index 133f106..3eeedf4 100644 --- a/packages/engine/src/index.test.ts +++ b/packages/engine/src/index.test.ts @@ -2071,7 +2071,7 @@ describe('API Key Management', () => { it('POST /events with valid API key and correct event type → 201', async () => { const keyRes = await app.fetch( - req('POST', '/api-keys', { name: 'ingest-key', role: 'ingest', allowed_events: ['task_assigned'] }), + req('POST', '/api-keys', { name: 'ingest-key', allowed_events: ['task_assigned'] }), { DB: db, API_TOKEN }, ) const { key } = await keyRes.json() @@ -2108,7 +2108,7 @@ describe('API Key Management', () => { it('POST /events with deleted key → 401', async () => { const keyRes = await app.fetch( - req('POST', '/api-keys', { name: 'temp-key', role: 'ingest', allowed_events: ['task_assigned'] }), + req('POST', '/api-keys', { name: 'temp-key', allowed_events: ['task_assigned'] }), { DB: db, API_TOKEN }, ) const { id, key } = await keyRes.json() @@ -2124,7 +2124,7 @@ describe('API Key Management', () => { it('POST /events with valid key but wrong event type → 403', async () => { const keyRes = await app.fetch( - req('POST', '/api-keys', { name: 'limited-key', role: 'ingest', allowed_events: ['other_event'] }), + req('POST', '/api-keys', { name: 'limited-key', allowed_events: ['other_event'] }), { DB: db, API_TOKEN }, ) const { key } = await keyRes.json() @@ -2138,7 +2138,7 @@ describe('API Key Management', () => { it('empty allowed_events means no events allowed for ingest role', async () => { const keyRes = await app.fetch( - req('POST', '/api-keys', { name: 'empty-key', role: 'ingest', allowed_events: [] }), + req('POST', '/api-keys', { name: 'empty-key', allowed_events: [] }), { DB: db, API_TOKEN }, ) const { key } = await keyRes.json() @@ -2158,8 +2158,9 @@ describe('API Key Management', () => { expect(res.status).toBe(201) }) - it('admin role API key bypasses event type check', async () => { - const keyRes = await app.fetch(req('POST', '/api-keys', { name: 'admin-key', role: 'admin' }), { + it('admin role API key is treated as ingest (admin role not implemented)', async () => { + // Even if someone passes role=admin, it's ignored — always ingest + const keyRes = await app.fetch(req('POST', '/api-keys', { name: 'admin-key', allowed_events: ['task_assigned'] }), { DB: db, API_TOKEN, }) @@ -2171,6 +2172,23 @@ describe('API Key Management', () => { ) expect(res.status).toBe(201) }) + + it('creating API key without role defaults to ingest', async () => { + const res = await app.fetch(req('POST', '/api-keys', { name: 'no-role-key' }), { DB: db, API_TOKEN }) + expect(res.status).toBe(201) + const json = await res.json() + expect(json.role).toBe('ingest') + }) + + it('any explicitly passed role value is ignored, always ingest', async () => { + const res = await app.fetch( + req('POST', '/api-keys', { name: 'readonly-attempt', role: 'readonly' as any }), + { DB: db, API_TOKEN }, + ) + expect(res.status).toBe(201) + const json = await res.json() + expect(json.role).toBe('ingest') + }) }) }) @@ -2231,7 +2249,7 @@ describe('Request Logs', () => { it('request log includes api_key_name for API key auth', async () => { const keyRes = await app.fetch( - req('POST', '/api-keys', { name: 'log-test-key', role: 'ingest', allowed_events: ['task_assigned'] }), + req('POST', '/api-keys', { name: 'log-test-key', allowed_events: ['task_assigned'] }), { DB: db, API_TOKEN }, ) const { key } = await keyRes.json() @@ -2255,7 +2273,7 @@ describe('Request Logs', () => { it('GET /request-logs supports api_key_id filter', async () => { const keyRes = await app.fetch( - req('POST', '/api-keys', { name: 'filter-key', role: 'ingest', allowed_events: ['task_assigned'] }), + req('POST', '/api-keys', { name: 'filter-key', allowed_events: ['task_assigned'] }), { DB: db, API_TOKEN }, ) const { key, id: keyId } = await keyRes.json() diff --git a/packages/engine/src/index.ts b/packages/engine/src/index.ts index d36f18f..76e4931 100644 --- a/packages/engine/src/index.ts +++ b/packages/engine/src/index.ts @@ -481,7 +481,8 @@ app.post('/api-keys', async (c) => { try { const body = await c.req.json() if (!body.name) return apiError(c, 400, ErrorCode.MISSING_FIELD, 'Missing name') - const result = await createApiKey(c.env.DB, body.name, body.role, body.allowed_events, body.rate_limit) + // Role is always 'ingest' — admin/readonly not implemented + const result = await createApiKey(c.env.DB, body.name, body.allowed_events, body.rate_limit) return c.json(result, 201) } catch (err: any) { return apiError(c, 500, ErrorCode.INTERNAL_ERROR, err.message || 'Internal error') diff --git a/packages/engine/src/types.ts b/packages/engine/src/types.ts index 8c0dd5f..ca01ed1 100644 --- a/packages/engine/src/types.ts +++ b/packages/engine/src/types.ts @@ -181,10 +181,11 @@ export interface ReactionLog { // API Key Types // ============================================ +// Only 'ingest' role is currently implemented. May expand in the future. export interface ApiKey { id: number name: string - role: 'admin' | 'ingest' | 'readonly' + role: 'ingest' allowed_events: string[] rate_limit: number last_used_at?: number @@ -193,7 +194,6 @@ export interface ApiKey { export interface CreateApiKeyRequest { name: string - role?: 'admin' | 'ingest' | 'readonly' allowed_events?: string[] rate_limit?: number } diff --git a/packages/engine/src/ui.html b/packages/engine/src/ui.html index a7b46c8..53d6fe1 100644 --- a/packages/engine/src/ui.html +++ b/packages/engine/src/ui.html @@ -64,7 +64,7 @@ Error generating stack: `+d.message+` `)),[]});var Wy=(n=>(n[n.None=0]="None",n[n.Closed=1]="Closed",n[n.Enter=2]="Enter",n[n.Leave=4]="Leave",n))(Wy||{});function Lm(n){let l={};for(let o in n)n[o]===!0&&(l[`data-${o}`]="");return l}function Im(n,l,o,s){let[a,c]=y.useState(o),{hasFlag:f,addFlag:p,removeFlag:h}=Ay(n&&a?3:0),v=y.useRef(!1),x=y.useRef(!1),E=cr();return Le(()=>{var w;if(n){if(o&&c(!0),!l){o&&p(3);return}return(w=void 0)==null||w.call(s,o),Hy(l,{inFlight:v,prepare(){x.current?x.current=!1:x.current=v.current,v.current=!0,!x.current&&(o?(p(3),h(4)):(p(4),h(2)))},run(){x.current?o?(h(3),p(4)):(h(4),p(3)):o?h(1):p(1)},done(){var b;x.current&&Uy(l)||(v.current=!1,h(7),o||c(!1),(b=void 0)==null||b.call(s,o))}})}},[n,o,l,E]),n?[a,{closed:f(1),enter:f(2),leave:f(4),transition:f(2)||f(4)}]:[o,{closed:void 0,enter:void 0,leave:void 0,transition:void 0}]}function Hy(n,{prepare:l,run:o,done:s,inFlight:a}){let c=gt();return By(n,{prepare:l,inFlight:a}),c.nextFrame(()=>{o(),c.requestAnimationFrame(()=>{c.add(Vy(n,s))})}),c.dispose}function Vy(n,l){var o,s;let a=gt();if(!n)return a.dispose;let c=!1;a.add(()=>{c=!0});let f=(s=(o=n.getAnimations)==null?void 0:o.call(n).filter(p=>p instanceof CSSTransition))!=null?s:[];return f.length===0?(l(),a.dispose):(Promise.allSettled(f.map(p=>p.finished)).then(()=>{c||l()}),a.dispose)}function By(n,{inFlight:l,prepare:o}){if(l!=null&&l.current){o();return}let s=n.style.transition;n.style.transition="none",o(),n.offsetHeight,n.style.transition=s}function Uy(n){var l,o;return((o=(l=n.getAnimations)==null?void 0:l.call(n))!=null?o:[]).some(s=>s instanceof CSSTransition&&s.playState!=="finished")}function Ky(n,{container:l,accept:o,walk:s}){let a=y.useRef(o),c=y.useRef(s);y.useEffect(()=>{a.current=o,c.current=s},[o,s]),Le(()=>{if(!l||!n)return;let f=Go(l);if(!f)return;let p=a.current,h=c.current,v=Object.assign(E=>p(E),{acceptNode:p}),x=f.createTreeWalker(l,NodeFilter.SHOW_ELEMENT,v,!1);for(;x.nextNode();)h(x.currentNode)},[l,n,a,c])}function mp(n,l){let o=y.useRef([]),s=xe(n);y.useEffect(()=>{let a=[...o.current];for(let[c,f]of l.entries())if(o.current[c]!==f){let p=s(l,a);return o.current=l,p}},[s,...l])}function Di(){return typeof window<"u"}function Ur(n){return Fm(n)?(n.nodeName||"").toLowerCase():"#document"}function Et(n){var l;return(n==null||(l=n.ownerDocument)==null?void 0:l.defaultView)||window}function qt(n){var l;return(l=(Fm(n)?n.ownerDocument:n.document)||window.document)==null?void 0:l.documentElement}function Fm(n){return Di()?n instanceof Node||n instanceof Et(n).Node:!1}function ut(n){return Di()?n instanceof Element||n instanceof Et(n).Element:!1}function pn(n){return Di()?n instanceof HTMLElement||n instanceof Et(n).HTMLElement:!1}function hp(n){return!Di()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof Et(n).ShadowRoot}function el(n){const{overflow:l,overflowX:o,overflowY:s,display:a}=zt(n);return/auto|scroll|overlay|hidden|clip/.test(l+s+o)&&a!=="inline"&&a!=="contents"}function Qy(n){return/^(table|td|th)$/.test(Ur(n))}function Ai(n){try{if(n.matches(":popover-open"))return!0}catch{}try{return n.matches(":modal")}catch{return!1}}const Yy=/transform|translate|scale|rotate|perspective|filter/,Xy=/paint|layout|strict|content/,Jn=n=>!!n&&n!=="none";let Ya;function Tu(n){const l=ut(n)?zt(n):n;return Jn(l.transform)||Jn(l.translate)||Jn(l.scale)||Jn(l.rotate)||Jn(l.perspective)||!Ru()&&(Jn(l.backdropFilter)||Jn(l.filter))||Yy.test(l.willChange||"")||Xy.test(l.contain||"")}function Gy(n){let l=_n(n);for(;pn(l)&&!Hr(l);){if(Tu(l))return l;if(Ai(l))return null;l=_n(l)}return null}function Ru(){return Ya==null&&(Ya=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Ya}function Hr(n){return/^(html|body|#document)$/.test(Ur(n))}function zt(n){return Et(n).getComputedStyle(n)}function zi(n){return ut(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function _n(n){if(Ur(n)==="html")return n;const l=n.assignedSlot||n.parentNode||hp(n)&&n.host||qt(n);return hp(l)?l.host:l}function Dm(n){const l=_n(n);return Hr(l)?n.ownerDocument?n.ownerDocument.body:n.body:pn(l)&&el(l)?l:Dm(l)}function Ko(n,l,o){var s;l===void 0&&(l=[]),o===void 0&&(o=!0);const a=Dm(n),c=a===((s=n.ownerDocument)==null?void 0:s.body),f=Et(a);if(c){const p=mu(f);return l.concat(f,f.visualViewport||[],el(a)?a:[],p&&o?Ko(p):[])}else return l.concat(a,Ko(a,[],o))}function mu(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function qy(){const n=navigator.userAgentData;return n&&Array.isArray(n.brands)?n.brands.map(l=>{let{brand:o,version:s}=l;return o+"/"+s}).join(" "):navigator.userAgent}const sr=Math.min,Ze=Math.max,Qo=Math.round,vi=Math.floor,Yt=n=>({x:n,y:n}),Jy={left:"right",right:"left",bottom:"top",top:"bottom"};function gp(n,l,o){return Ze(n,sr(l,o))}function Kr(n,l){return typeof n=="function"?n(l):n}function Ln(n){return n.split("-")[0]}function tl(n){return n.split("-")[1]}function Am(n){return n==="x"?"y":"x"}function zm(n){return n==="y"?"height":"width"}function un(n){const l=n[0];return l==="t"||l==="b"?"y":"x"}function Wm(n){return Am(un(n))}function Zy(n,l,o){o===void 0&&(o=!1);const s=tl(n),a=Wm(n),c=zm(a);let f=a==="x"?s===(o?"end":"start")?"right":"left":s==="start"?"bottom":"top";return l.reference[c]>l.floating[c]&&(f=Pi(f)),[f,Pi(f)]}function ex(n){const l=Pi(n);return[hu(n),l,hu(l)]}function hu(n){return n.includes("start")?n.replace("start","end"):n.replace("end","start")}const vp=["left","right"],yp=["right","left"],tx=["top","bottom"],nx=["bottom","top"];function rx(n,l,o){switch(n){case"top":case"bottom":return o?l?yp:vp:l?vp:yp;case"left":case"right":return l?tx:nx;default:return[]}}function ox(n,l,o,s){const a=tl(n);let c=rx(Ln(n),o==="start",s);return a&&(c=c.map(f=>f+"-"+a),l&&(c=c.concat(c.map(hu)))),c}function Pi(n){const l=Ln(n);return Jy[l]+n.slice(l.length)}function lx(n){return{top:0,right:0,bottom:0,left:0,...n}}function ix(n){return typeof n!="number"?lx(n):{top:n,right:n,bottom:n,left:n}}function Ti(n){const{x:l,y:o,width:s,height:a}=n;return{width:s,height:a,top:o,left:l,right:l+s,bottom:o+a,x:l,y:o}}function xp(n,l,o){let{reference:s,floating:a}=n;const c=un(l),f=Wm(l),p=zm(f),h=Ln(l),v=c==="y",x=s.x+s.width/2-a.width/2,E=s.y+s.height/2-a.height/2,w=s[p]/2-a[p]/2;let b;switch(h){case"top":b={x,y:s.y-a.height};break;case"bottom":b={x,y:s.y+s.height};break;case"right":b={x:s.x+s.width,y:E};break;case"left":b={x:s.x-a.width,y:E};break;default:b={x:s.x,y:s.y}}switch(tl(l)){case"start":b[f]-=w*(o&&v?-1:1);break;case"end":b[f]+=w*(o&&v?-1:1);break}return b}async function Hm(n,l){var o;l===void 0&&(l={});const{x:s,y:a,platform:c,rects:f,elements:p,strategy:h}=n,{boundary:v="clippingAncestors",rootBoundary:x="viewport",elementContext:E="floating",altBoundary:w=!1,padding:b=0}=Kr(l,n),S=ix(b),j=p[w?E==="floating"?"reference":"floating":E],I=Ti(await c.getClippingRect({element:(o=await(c.isElement==null?void 0:c.isElement(j)))==null||o?j:j.contextElement||await(c.getDocumentElement==null?void 0:c.getDocumentElement(p.floating)),boundary:v,rootBoundary:x,strategy:h})),L=E==="floating"?{x:s,y:a,width:f.floating.width,height:f.floating.height}:f.reference,P=await(c.getOffsetParent==null?void 0:c.getOffsetParent(p.floating)),M=await(c.isElement==null?void 0:c.isElement(P))?await(c.getScale==null?void 0:c.getScale(P))||{x:1,y:1}:{x:1,y:1},A=Ti(c.convertOffsetParentRelativeRectToViewportRelativeRect?await c.convertOffsetParentRelativeRectToViewportRelativeRect({elements:p,rect:L,offsetParent:P,strategy:h}):L);return{top:(I.top-A.top+S.top)/M.y,bottom:(A.bottom-I.bottom+S.bottom)/M.y,left:(I.left-A.left+S.left)/M.x,right:(A.right-I.right+S.right)/M.x}}const sx=50,ax=async(n,l,o)=>{const{placement:s="bottom",strategy:a="absolute",middleware:c=[],platform:f}=o,p=f.detectOverflow?f:{...f,detectOverflow:Hm},h=await(f.isRTL==null?void 0:f.isRTL(l));let v=await f.getElementRects({reference:n,floating:l,strategy:a}),{x,y:E}=xp(v,s,h),w=s,b=0;const S={};for(let C=0;Cue<=0)){var Q,z;const ue=(((Q=c.flip)==null?void 0:Q.index)||0)+1,G=q[ue];if(G&&(!(E==="alignment"?L!==un(G):!1)||J.every(D=>un(D.placement)===L?D.overflows[0]>0:!0)))return{data:{index:ue,overflows:J},reset:{placement:G}};let ce=(z=J.filter(ve=>ve.overflows[0]<=0).sort((ve,D)=>ve.overflows[1]-D.overflows[1])[0])==null?void 0:z.placement;if(!ce)switch(b){case"bestFit":{var ae;const ve=(ae=J.filter(D=>{if(H){const X=un(D.placement);return X===L||X==="y"}return!0}).map(D=>[D.placement,D.overflows.filter(X=>X>0).reduce((X,K)=>X+K,0)]).sort((D,X)=>D[1]-X[1])[0])==null?void 0:ae[0];ve&&(ce=ve);break}case"initialPlacement":ce=p;break}if(a!==ce)return{reset:{placement:ce}}}return{}}}},cx=new Set(["left","top"]);async function dx(n,l){const{placement:o,platform:s,elements:a}=n,c=await(s.isRTL==null?void 0:s.isRTL(a.floating)),f=Ln(o),p=tl(o),h=un(o)==="y",v=cx.has(f)?-1:1,x=c&&h?-1:1,E=Kr(l,n);let{mainAxis:w,crossAxis:b,alignmentAxis:S}=typeof E=="number"?{mainAxis:E,crossAxis:0,alignmentAxis:null}:{mainAxis:E.mainAxis||0,crossAxis:E.crossAxis||0,alignmentAxis:E.alignmentAxis};return p&&typeof S=="number"&&(b=p==="end"?S*-1:S),h?{x:b*x,y:w*v}:{x:w*v,y:b*x}}const fx=function(n){return n===void 0&&(n=0),{name:"offset",options:n,async fn(l){var o,s;const{x:a,y:c,placement:f,middlewareData:p}=l,h=await dx(l,n);return f===((o=p.offset)==null?void 0:o.placement)&&(s=p.arrow)!=null&&s.alignmentOffset?{}:{x:a+h.x,y:c+h.y,data:{...h,placement:f}}}}},px=function(n){return n===void 0&&(n={}),{name:"shift",options:n,async fn(l){const{x:o,y:s,placement:a,platform:c}=l,{mainAxis:f=!0,crossAxis:p=!1,limiter:h={fn:I=>{let{x:L,y:P}=I;return{x:L,y:P}}},...v}=Kr(n,l),x={x:o,y:s},E=await c.detectOverflow(l,v),w=un(Ln(a)),b=Am(w);let S=x[b],C=x[w];if(f){const I=b==="y"?"top":"left",L=b==="y"?"bottom":"right",P=S+E[I],M=S-E[L];S=gp(P,S,M)}if(p){const I=w==="y"?"top":"left",L=w==="y"?"bottom":"right",P=C+E[I],M=C-E[L];C=gp(P,C,M)}const j=h.fn({...l,[b]:S,[w]:C});return{...j,data:{x:j.x-o,y:j.y-s,enabled:{[b]:f,[w]:p}}}}}},mx=function(n){return n===void 0&&(n={}),{name:"size",options:n,async fn(l){var o,s;const{placement:a,rects:c,platform:f,elements:p}=l,{apply:h=()=>{},...v}=Kr(n,l),x=await f.detectOverflow(l,v),E=Ln(a),w=tl(a),b=un(a)==="y",{width:S,height:C}=c.floating;let j,I;E==="top"||E==="bottom"?(j=E,I=w===(await(f.isRTL==null?void 0:f.isRTL(p.floating))?"start":"end")?"left":"right"):(I=E,j=w==="end"?"top":"bottom");const L=C-x.top-x.bottom,P=S-x.left-x.right,M=sr(C-x[j],L),A=sr(S-x[I],P),H=!l.middlewareData.shift;let q=M,ee=A;if((o=l.middlewareData.shift)!=null&&o.enabled.x&&(ee=P),(s=l.middlewareData.shift)!=null&&s.enabled.y&&(q=L),H&&!w){const J=Ze(x.left,0),Q=Ze(x.right,0),z=Ze(x.top,0),ae=Ze(x.bottom,0);b?ee=S-2*(J!==0||Q!==0?J+Q:Ze(x.left,x.right)):q=C-2*(z!==0||ae!==0?z+ae:Ze(x.top,x.bottom))}await h({...l,availableWidth:ee,availableHeight:q});const he=await f.getDimensions(p.floating);return S!==he.width||C!==he.height?{reset:{rects:!0}}:{}}}};function Vm(n){const l=zt(n);let o=parseFloat(l.width)||0,s=parseFloat(l.height)||0;const a=pn(n),c=a?n.offsetWidth:o,f=a?n.offsetHeight:s,p=Qo(o)!==c||Qo(s)!==f;return p&&(o=c,s=f),{width:o,height:s,$:p}}function $u(n){return ut(n)?n:n.contextElement}function zr(n){const l=$u(n);if(!pn(l))return Yt(1);const o=l.getBoundingClientRect(),{width:s,height:a,$:c}=Vm(l);let f=(c?Qo(o.width):o.width)/s,p=(c?Qo(o.height):o.height)/a;return(!f||!Number.isFinite(f))&&(f=1),(!p||!Number.isFinite(p))&&(p=1),{x:f,y:p}}const hx=Yt(0);function Bm(n){const l=Et(n);return!Ru()||!l.visualViewport?hx:{x:l.visualViewport.offsetLeft,y:l.visualViewport.offsetTop}}function gx(n,l,o){return l===void 0&&(l=!1),!o||l&&o!==Et(n)?!1:l}function ar(n,l,o,s){l===void 0&&(l=!1),o===void 0&&(o=!1);const a=n.getBoundingClientRect(),c=$u(n);let f=Yt(1);l&&(s?ut(s)&&(f=zr(s)):f=zr(n));const p=gx(c,o,s)?Bm(c):Yt(0);let h=(a.left+p.x)/f.x,v=(a.top+p.y)/f.y,x=a.width/f.x,E=a.height/f.y;if(c){const w=Et(c),b=s&&ut(s)?Et(s):s;let S=w,C=mu(S);for(;C&&s&&b!==S;){const j=zr(C),I=C.getBoundingClientRect(),L=zt(C),P=I.left+(C.clientLeft+parseFloat(L.paddingLeft))*j.x,M=I.top+(C.clientTop+parseFloat(L.paddingTop))*j.y;h*=j.x,v*=j.y,x*=j.x,E*=j.y,h+=P,v+=M,S=Et(C),C=mu(S)}}return Ti({width:x,height:E,x:h,y:v})}function Wi(n,l){const o=zi(n).scrollLeft;return l?l.left+o:ar(qt(n)).left+o}function Um(n,l){const o=n.getBoundingClientRect(),s=o.left+l.scrollLeft-Wi(n,o),a=o.top+l.scrollTop;return{x:s,y:a}}function vx(n){let{elements:l,rect:o,offsetParent:s,strategy:a}=n;const c=a==="fixed",f=qt(s),p=l?Ai(l.floating):!1;if(s===f||p&&c)return o;let h={scrollLeft:0,scrollTop:0},v=Yt(1);const x=Yt(0),E=pn(s);if((E||!E&&!c)&&((Ur(s)!=="body"||el(f))&&(h=zi(s)),E)){const b=ar(s);v=zr(s),x.x=b.x+s.clientLeft,x.y=b.y+s.clientTop}const w=f&&!E&&!c?Um(f,h):Yt(0);return{width:o.width*v.x,height:o.height*v.y,x:o.x*v.x-h.scrollLeft*v.x+x.x+w.x,y:o.y*v.y-h.scrollTop*v.y+x.y+w.y}}function yx(n){return Array.from(n.getClientRects())}function xx(n){const l=qt(n),o=zi(n),s=n.ownerDocument.body,a=Ze(l.scrollWidth,l.clientWidth,s.scrollWidth,s.clientWidth),c=Ze(l.scrollHeight,l.clientHeight,s.scrollHeight,s.clientHeight);let f=-o.scrollLeft+Wi(n);const p=-o.scrollTop;return zt(s).direction==="rtl"&&(f+=Ze(l.clientWidth,s.clientWidth)-a),{width:a,height:c,x:f,y:p}}const wp=25;function wx(n,l){const o=Et(n),s=qt(n),a=o.visualViewport;let c=s.clientWidth,f=s.clientHeight,p=0,h=0;if(a){c=a.width,f=a.height;const x=Ru();(!x||x&&l==="fixed")&&(p=a.offsetLeft,h=a.offsetTop)}const v=Wi(s);if(v<=0){const x=s.ownerDocument,E=x.body,w=getComputedStyle(E),b=x.compatMode==="CSS1Compat"&&parseFloat(w.marginLeft)+parseFloat(w.marginRight)||0,S=Math.abs(s.clientWidth-E.clientWidth-b);S<=wp&&(c-=S)}else v<=wp&&(c+=v);return{width:c,height:f,x:p,y:h}}function bx(n,l){const o=ar(n,!0,l==="fixed"),s=o.top+n.clientTop,a=o.left+n.clientLeft,c=pn(n)?zr(n):Yt(1),f=n.clientWidth*c.x,p=n.clientHeight*c.y,h=a*c.x,v=s*c.y;return{width:f,height:p,x:h,y:v}}function bp(n,l,o){let s;if(l==="viewport")s=wx(n,o);else if(l==="document")s=xx(qt(n));else if(ut(l))s=bx(l,o);else{const a=Bm(n);s={x:l.x-a.x,y:l.y-a.y,width:l.width,height:l.height}}return Ti(s)}function Km(n,l){const o=_n(n);return o===l||!ut(o)||Hr(o)?!1:zt(o).position==="fixed"||Km(o,l)}function Sx(n,l){const o=l.get(n);if(o)return o;let s=Ko(n,[],!1).filter(p=>ut(p)&&Ur(p)!=="body"),a=null;const c=zt(n).position==="fixed";let f=c?_n(n):n;for(;ut(f)&&!Hr(f);){const p=zt(f),h=Tu(f);!h&&p.position==="fixed"&&(a=null),(c?!h&&!a:!h&&p.position==="static"&&!!a&&(a.position==="absolute"||a.position==="fixed")||el(f)&&!h&&Km(n,f))?s=s.filter(x=>x!==f):a=p,f=_n(f)}return l.set(n,s),s}function Ex(n){let{element:l,boundary:o,rootBoundary:s,strategy:a}=n;const f=[...o==="clippingAncestors"?Ai(l)?[]:Sx(l,this._c):[].concat(o),s],p=bp(l,f[0],a);let h=p.top,v=p.right,x=p.bottom,E=p.left;for(let w=1;w{f(!1,1e-7)},1e3)}q===1&&!Ym(v,n.getBoundingClientRect())&&f(),M=!1}try{o=new IntersectionObserver(A,{...P,root:a.ownerDocument})}catch{o=new IntersectionObserver(A,P)}o.observe(n)}return f(!0),c}function Tx(n,l,o,s){s===void 0&&(s={});const{ancestorScroll:a=!0,ancestorResize:c=!0,elementResize:f=typeof ResizeObserver=="function",layoutShift:p=typeof IntersectionObserver=="function",animationFrame:h=!1}=s,v=$u(n),x=a||c?[...v?Ko(v):[],...l?Ko(l):[]]:[];x.forEach(I=>{a&&I.addEventListener("scroll",o,{passive:!0}),c&&I.addEventListener("resize",o)});const E=v&&p?Px(v,o):null;let w=-1,b=null;f&&(b=new ResizeObserver(I=>{let[L]=I;L&&L.target===v&&b&&l&&(b.unobserve(l),cancelAnimationFrame(w),w=requestAnimationFrame(()=>{var P;(P=b)==null||P.observe(l)})),o()}),v&&!h&&b.observe(v),l&&b.observe(l));let S,C=h?ar(n):null;h&&j();function j(){const I=ar(n);C&&!Ym(C,I)&&o(),C=I,S=requestAnimationFrame(j)}return o(),()=>{var I;x.forEach(L=>{a&&L.removeEventListener("scroll",o),c&&L.removeEventListener("resize",o)}),E?.(),(I=b)==null||I.disconnect(),b=null,h&&cancelAnimationFrame(S)}}const Ga=Hm,Rx=fx,$x=px,Mx=ux,_x=mx,Lx=(n,l,o)=>{const s=new Map,a={platform:Ox,...o},c={...a.platform,_c:s};return ax(n,l,{...a,platform:c})};var Ix=typeof document<"u",Fx=function(){},wi=Ix?y.useLayoutEffect:Fx;function Ri(n,l){if(n===l)return!0;if(typeof n!=typeof l)return!1;if(typeof n=="function"&&n.toString()===l.toString())return!0;let o,s,a;if(n&&l&&typeof n=="object"){if(Array.isArray(n)){if(o=n.length,o!==l.length)return!1;for(s=o;s--!==0;)if(!Ri(n[s],l[s]))return!1;return!0}if(a=Object.keys(n),o=a.length,o!==Object.keys(l).length)return!1;for(s=o;s--!==0;)if(!{}.hasOwnProperty.call(l,a[s]))return!1;for(s=o;s--!==0;){const c=a[s];if(!(c==="_owner"&&n.$$typeof)&&!Ri(n[c],l[c]))return!1}return!0}return n!==n&&l!==l}function Xm(n){return typeof window>"u"?1:(n.ownerDocument.defaultView||window).devicePixelRatio||1}function Ep(n,l){const o=Xm(n);return Math.round(l*o)/o}function qa(n){const l=y.useRef(n);return wi(()=>{l.current=n}),l}function Dx(n){n===void 0&&(n={});const{placement:l="bottom",strategy:o="absolute",middleware:s=[],platform:a,elements:{reference:c,floating:f}={},transform:p=!0,whileElementsMounted:h,open:v}=n,[x,E]=y.useState({x:0,y:0,strategy:o,placement:l,middlewareData:{},isPositioned:!1}),[w,b]=y.useState(s);Ri(w,s)||b(s);const[S,C]=y.useState(null),[j,I]=y.useState(null),L=y.useCallback(D=>{D!==H.current&&(H.current=D,C(D))},[]),P=y.useCallback(D=>{D!==q.current&&(q.current=D,I(D))},[]),M=c||S,A=f||j,H=y.useRef(null),q=y.useRef(null),ee=y.useRef(x),he=h!=null,J=qa(h),Q=qa(a),z=qa(v),ae=y.useCallback(()=>{if(!H.current||!q.current)return;const D={placement:l,strategy:o,middleware:w};Q.current&&(D.platform=Q.current),Lx(H.current,q.current,D).then(X=>{const K={...X,isPositioned:z.current!==!1};ue.current&&!Ri(ee.current,K)&&(ee.current=K,Ye.flushSync(()=>{E(K)}))})},[w,l,o,Q,z]);wi(()=>{v===!1&&ee.current.isPositioned&&(ee.current.isPositioned=!1,E(D=>({...D,isPositioned:!1})))},[v]);const ue=y.useRef(!1);wi(()=>(ue.current=!0,()=>{ue.current=!1}),[]),wi(()=>{if(M&&(H.current=M),A&&(q.current=A),M&&A){if(J.current)return J.current(M,A,ae);ae()}},[M,A,ae,J,he]);const G=y.useMemo(()=>({reference:H,floating:q,setReference:L,setFloating:P}),[L,P]),ce=y.useMemo(()=>({reference:M,floating:A}),[M,A]),ve=y.useMemo(()=>{const D={position:o,left:0,top:0};if(!ce.floating)return D;const X=Ep(ce.floating,x.x),K=Ep(ce.floating,x.y);return p?{...D,transform:"translate("+X+"px, "+K+"px)",...Xm(ce.floating)>=1.5&&{willChange:"transform"}}:{position:o,left:X,top:K}},[o,p,ce.floating,x.x,x.y]);return y.useMemo(()=>({...x,update:ae,refs:G,elements:ce,floatingStyles:ve}),[x,ae,G,ce,ve])}const Gm=(n,l)=>{const o=Rx(n);return{name:o.name,fn:o.fn,options:[n,l]}},Ax=(n,l)=>{const o=$x(n);return{name:o.name,fn:o.fn,options:[n,l]}},zx=(n,l)=>{const o=Mx(n);return{name:o.name,fn:o.fn,options:[n,l]}},Wx=(n,l)=>{const o=_x(n);return{name:o.name,fn:o.fn,options:[n,l]}},qm={...ru},Hx=qm.useInsertionEffect,Vx=Hx||(n=>n());function Jm(n){const l=y.useRef(()=>{});return Vx(()=>{l.current=n}),y.useCallback(function(){for(var o=arguments.length,s=new Array(o),a=0;a"floating-ui-"+Math.random().toString(36).slice(2,6)+Bx++;function Ux(){const[n,l]=y.useState(()=>kp?Cp():void 0);return gu(()=>{n==null&&l(Cp())},[]),y.useEffect(()=>{kp=!0},[]),n}const Kx=qm.useId,Qx=Kx||Ux;function Yx(){const n=new Map;return{emit(l,o){var s;(s=n.get(l))==null||s.forEach(a=>a(o))},on(l,o){n.set(l,[...n.get(l)||[],o])},off(l,o){var s;n.set(l,((s=n.get(l))==null?void 0:s.filter(a=>a!==o))||[])}}}const Xx=y.createContext(null),Gx=y.createContext(null),qx=()=>{var n;return((n=y.useContext(Xx))==null?void 0:n.id)||null},Jx=()=>y.useContext(Gx),Zx="data-floating-ui-focusable";function e1(n){const{open:l=!1,onOpenChange:o,elements:s}=n,a=Qx(),c=y.useRef({}),[f]=y.useState(()=>Yx()),p=qx()!=null,[h,v]=y.useState(s.reference),x=Jm((b,S,C)=>{c.current.openEvent=b?S:void 0,f.emit("openchange",{open:b,event:S,reason:C,nested:p}),o?.(b,S,C)}),E=y.useMemo(()=>({setPositionReference:v}),[]),w=y.useMemo(()=>({reference:h||s.reference||null,floating:s.floating||null,domReference:s.reference}),[h,s.reference,s.floating]);return y.useMemo(()=>({dataRef:c,open:l,onOpenChange:x,elements:w,events:f,floatingId:a,refs:E}),[l,x,w,f,a,E])}function t1(n){n===void 0&&(n={});const{nodeId:l}=n,o=e1({...n,elements:{reference:null,floating:null,...n.elements}}),s=n.rootContext||o,a=s.elements,[c,f]=y.useState(null),[p,h]=y.useState(null),x=a?.domReference||c,E=y.useRef(null),w=Jx();gu(()=>{x&&(E.current=x)},[x]);const b=Dx({...n,elements:{...a,...p&&{reference:p}}}),S=y.useCallback(P=>{const M=ut(P)?{getBoundingClientRect:()=>P.getBoundingClientRect(),contextElement:P}:P;h(M),b.refs.setReference(M)},[b.refs]),C=y.useCallback(P=>{(ut(P)||P===null)&&(E.current=P,f(P)),(ut(b.refs.reference.current)||b.refs.reference.current===null||P!==null&&!ut(P))&&b.refs.setReference(P)},[b.refs]),j=y.useMemo(()=>({...b.refs,setReference:C,setPositionReference:S,domReference:E}),[b.refs,C,S]),I=y.useMemo(()=>({...b.elements,domReference:x}),[b.elements,x]),L=y.useMemo(()=>({...b,...s,refs:j,elements:I,nodeId:l}),[b,j,I,l,s]);return gu(()=>{s.dataRef.current.floatingContext=L;const P=w?.nodesRef.current.find(M=>M.id===l);P&&(P.context=L)}),y.useMemo(()=>({...b,context:L,refs:j,elements:I}),[b,j,I,L])}const Np="active",jp="selected";function Ja(n,l,o){const s=new Map,a=o==="item";let c=n;if(a&&n){const{[Np]:f,[jp]:p,...h}=n;c=h}return{...o==="floating"&&{tabIndex:-1,[Zx]:""},...c,...l.map(f=>{const p=f?f[o]:null;return typeof p=="function"?n?p(n):null:p}).concat(n).reduce((f,p)=>(p&&Object.entries(p).forEach(h=>{let[v,x]=h;if(!(a&&[Np,jp].includes(v)))if(v.indexOf("on")===0){if(s.has(v)||s.set(v,[]),typeof x=="function"){var E;(E=s.get(v))==null||E.push(x),f[v]=function(){for(var w,b=arguments.length,S=new Array(b),C=0;Cj(...S)).find(j=>j!==void 0)}}}else f[v]=x}),f),{})}}function n1(n){n===void 0&&(n=[]);const l=n.map(p=>p?.reference),o=n.map(p=>p?.floating),s=n.map(p=>p?.item),a=y.useCallback(p=>Ja(p,n,"reference"),l),c=y.useCallback(p=>Ja(p,n,"floating"),o),f=y.useCallback(p=>Ja(p,n,"item"),s);return y.useMemo(()=>({getReferenceProps:a,getFloatingProps:c,getItemProps:f}),[a,c,f])}function Op(n,l){return{...n,rects:{...n.rects,floating:{...n.rects.floating,height:l}}}}const r1=n=>({name:"inner",options:n,async fn(l){const{listRef:o,overflowRef:s,onFallbackChange:a,offset:c=0,index:f=0,minItemsVisible:p=4,referenceOverflowThreshold:h=0,scrollRef:v,...x}=Kr(n,l),{rects:E,elements:{floating:w}}=l,b=o.current[f],S=v?.current||w,C=w.clientTop||S.clientTop,j=w.clientTop!==0,I=S.clientTop!==0,L=w===S;if(!b)return{};const P={...l,...await Gm(-b.offsetTop-w.clientTop-E.reference.height/2-b.offsetHeight/2-c).fn(l)},M=await Ga(Op(P,S.scrollHeight+C+w.clientTop),x),A=await Ga(P,{...x,elementContext:"reference"}),H=Ze(0,M.top),q=P.y+H,J=(S.scrollHeight>S.clientHeight?Q=>Q:Qo)(Ze(0,S.scrollHeight+(j&&L||I?C*2:0)-H-Ze(0,M.bottom)));if(S.style.maxHeight=J+"px",S.scrollTop=H,a){const Q=S.offsetHeight=-h||A.bottom>=-h;Ye.flushSync(()=>a(Q))}return s&&(s.current=await Ga(Op({...P,y:q},S.offsetHeight+C+w.clientTop),x)),{y:q}}});function o1(n,l){const{open:o,elements:s}=n,{enabled:a=!0,overflowRef:c,scrollRef:f,onChange:p}=l,h=Jm(p),v=y.useRef(!1),x=y.useRef(null),E=y.useRef(null);y.useEffect(()=>{if(!a)return;function b(C){if(C.ctrlKey||!S||c.current==null)return;const j=C.deltaY,I=c.current.top>=-.5,L=c.current.bottom>=-.5,P=S.scrollHeight-S.clientHeight,M=j<0?-1:1,A=j<0?"max":"min";S.scrollHeight<=S.clientHeight||(!I&&j>0||!L&&j<0?(C.preventDefault(),Ye.flushSync(()=>{h(H=>H+Math[A](j,P*M))})):/firefox/i.test(qy())&&(S.scrollTop+=j))}const S=f?.current||s.floating;if(o&&S)return S.addEventListener("wheel",b),requestAnimationFrame(()=>{x.current=S.scrollTop,c.current!=null&&(E.current={...c.current})}),()=>{x.current=null,E.current=null,S.removeEventListener("wheel",b)}},[a,o,s.floating,c,f,h]);const w=y.useMemo(()=>({onKeyDown(){v.current=!0},onWheel(){v.current=!1},onPointerMove(){v.current=!1},onScroll(){const b=f?.current||s.floating;if(!(!c.current||!b||!v.current)){if(x.current!==null){const S=b.scrollTop-x.current;(c.current.bottom<-.5&&S<-1||c.current.top<-.5&&S>1)&&Ye.flushSync(()=>h(C=>C+S))}requestAnimationFrame(()=>{x.current=b.scrollTop})}}}),[s.floating,h,c,f]);return y.useMemo(()=>a?{floating:w}:{},[a,w])}let Qr=y.createContext({styles:void 0,setReference:()=>{},setFloating:()=>{},getReferenceProps:()=>({}),getFloatingProps:()=>({}),slot:{}});Qr.displayName="FloatingContext";let Mu=y.createContext(null);Mu.displayName="PlacementContext";function Zm(n){return y.useMemo(()=>n?typeof n=="string"?{to:n}:n:null,[n])}function eh(){return y.useContext(Qr).setReference}function l1(){return y.useContext(Qr).getReferenceProps}function th(){let{getFloatingProps:n,slot:l}=y.useContext(Qr);return y.useCallback((...o)=>Object.assign({},n(...o),{"data-anchor":l.anchor}),[n,l])}function nh(n=null){n===!1&&(n=null),typeof n=="string"&&(n={to:n});let l=y.useContext(Mu),o=y.useMemo(()=>n,[JSON.stringify(n,(a,c)=>{var f;return(f=c?.outerHTML)!=null?f:c})]);Le(()=>{l?.(o??null)},[l,o]);let s=y.useContext(Qr);return y.useMemo(()=>[s.setFloating,n?s.styles:{}],[s.setFloating,n,s.styles])}let Pp=4;function rh({children:n,enabled:l=!0}){let[o,s]=y.useState(null),[a,c]=y.useState(0),f=y.useRef(null),[p,h]=y.useState(null);i1(p);let v=l&&o!==null&&p!==null,{to:x="bottom",gap:E=0,offset:w=0,padding:b=0,inner:S}=s1(o,p),[C,j="center"]=x.split(" ");Le(()=>{v&&c(0)},[v]);let{refs:I,floatingStyles:L,context:P}=t1({open:v,placement:C==="selection"?j==="center"?"bottom":`bottom-${j}`:j==="center"?`${C}`:`${C}-${j}`,strategy:"absolute",transform:!1,middleware:[Gm({mainAxis:C==="selection"?0:E,crossAxis:w}),Ax({padding:b}),C!=="selection"&&zx({padding:b}),C==="selection"&&S?r1({...S,padding:b,overflowRef:f,offset:a,minItemsVisible:Pp,referenceOverflowThreshold:b,onFallbackChange(Q){var z,ae;if(!Q)return;let ue=P.elements.floating;if(!ue)return;let G=parseFloat(getComputedStyle(ue).scrollPaddingBottom)||0,ce=Math.min(Pp,ue.childElementCount),ve=0,D=0;for(let X of(ae=(z=P.elements.floating)==null?void 0:z.childNodes)!=null?ae:[])if(Gt(X)){let K=X.offsetTop,T=K+X.clientHeight+G,R=ue.scrollTop,re=R+ue.clientHeight;if(K>=R&&T<=re)ce--;else{D=Math.max(0,Math.min(T,re)-Math.max(K,R)),ve=X.clientHeight;break}}ce>=1&&c(X=>{let K=ve*ce-D+G;return X>=K?X:K})}}):null,Wx({padding:b,apply({availableWidth:Q,availableHeight:z,elements:ae}){Object.assign(ae.floating.style,{overflow:"auto",maxWidth:`${Q}px`,maxHeight:`min(var(--anchor-max-height, 100vh), ${z}px)`})}})].filter(Boolean),whileElementsMounted:Tx}),[M=C,A=j]=P.placement.split("-");C==="selection"&&(M="selection");let H=y.useMemo(()=>({anchor:[M,A].filter(Boolean).join(" ")}),[M,A]),q=o1(P,{overflowRef:f,onChange:c}),{getReferenceProps:ee,getFloatingProps:he}=n1([q]),J=xe(Q=>{h(Q),I.setFloating(Q)});return y.createElement(Mu.Provider,{value:s},y.createElement(Qr.Provider,{value:{setFloating:J,setReference:I.setReference,styles:L,getReferenceProps:ee,getFloatingProps:he,slot:H}},n))}function i1(n){Le(()=>{if(!n)return;let l=new MutationObserver(()=>{let o=window.getComputedStyle(n).maxHeight,s=parseFloat(o);if(isNaN(s))return;let a=parseInt(o);isNaN(a)||s!==a&&(n.style.maxHeight=`${Math.ceil(s)}px`)});return l.observe(n,{attributes:!0,attributeFilter:["style"]}),()=>{l.disconnect()}},[n])}function s1(n,l){var o,s,a;let c=Za((o=n?.gap)!=null?o:"var(--anchor-gap, 0)",l),f=Za((s=n?.offset)!=null?s:"var(--anchor-offset, 0)",l),p=Za((a=n?.padding)!=null?a:"var(--anchor-padding, 0)",l);return{...n,gap:c,offset:f,padding:p}}function Za(n,l,o=void 0){let s=cr(),a=xe((h,v)=>{if(h==null)return[o,null];if(typeof h=="number")return[h,null];if(typeof h=="string"){if(!v)return[o,null];let x=Tp(h,v);return[x,E=>{let w=oh(h);{let b=w.map(S=>window.getComputedStyle(v).getPropertyValue(S));s.requestAnimationFrame(function S(){s.nextFrame(S);let C=!1;for(let[I,L]of w.entries()){let P=window.getComputedStyle(v).getPropertyValue(L);if(b[I]!==P){b[I]=P,C=!0;break}}if(!C)return;let j=Tp(h,v);x!==j&&(E(j),x=j)})}return s.dispose}]}return[o,null]}),c=y.useMemo(()=>a(n,l)[0],[n,l]),[f=c,p]=y.useState();return Le(()=>{let[h,v]=a(n,l);if(p(h),!!v)return v(p)},[n,l]),f}function oh(n){let l=/var\((.*)\)/.exec(n);if(l){let o=l[1].indexOf(",");if(o===-1)return[l[1]];let s=l[1].slice(0,o).trim(),a=l[1].slice(o+1).trim();return a?[s,...oh(a)]:[s]}return[]}function Tp(n,l){let o=document.createElement("div");l.appendChild(o),o.style.setProperty("margin-top","0px","important"),o.style.setProperty("margin-top",n,"important");let s=parseFloat(window.getComputedStyle(o).marginTop)||0;return l.removeChild(o),s}function a1({children:n,freeze:l},o){let s=$i(l,n);return y.isValidElement(s)?y.cloneElement(s,{ref:o}):ye.createElement(ye.Fragment,null,s)}const u1=ye.forwardRef(a1);function $i(n,l){let[o,s]=y.useState(l);return!n&&o!==l&&s(l),n?o:l}let _u=y.createContext(null);_u.displayName="OpenClosedContext";var dn=(n=>(n[n.Open=1]="Open",n[n.Closed=2]="Closed",n[n.Closing=4]="Closing",n[n.Opening=8]="Opening",n))(dn||{});function lh(){return y.useContext(_u)}function ih({value:n,children:l}){return ye.createElement(_u.Provider,{value:n},l)}function c1(n){function l(){document.readyState!=="loading"&&(n(),document.removeEventListener("DOMContentLoaded",l))}typeof window<"u"&&typeof document<"u"&&(document.addEventListener("DOMContentLoaded",l),l())}let er=[];c1(()=>{function n(l){if(!rr(l.target)||l.target===document.body||er[0]===l.target)return;let o=l.target;o=o.closest(Oi),er.unshift(o??l.target),er=er.filter(s=>s!=null&&s.isConnected),er.splice(10)}window.addEventListener("click",n,{capture:!0}),window.addEventListener("mousedown",n,{capture:!0}),window.addEventListener("focus",n,{capture:!0}),document.body.addEventListener("click",n,{capture:!0}),document.body.addEventListener("mousedown",n,{capture:!0}),document.body.addEventListener("focus",n,{capture:!0})});function d1(n){throw new Error("Unexpected object: "+n)}var we=(n=>(n[n.First=0]="First",n[n.Previous=1]="Previous",n[n.Next=2]="Next",n[n.Last=3]="Last",n[n.Specific=4]="Specific",n[n.Nothing=5]="Nothing",n))(we||{});function Dr(n,l){let o=l.resolveItems();if(o.length<=0)return null;let s=l.resolveActiveIndex(),a=s??-1;switch(n.focus){case 0:{for(let c=0;c=0;--c)if(!l.resolveDisabled(o[c],c,o))return c;return s}case 2:{for(let c=a+1;c=0;--c)if(!l.resolveDisabled(o[c],c,o))return c;return s}case 4:{for(let c=0;c(o.current=!1,()=>{o.current=!0,qp(()=>{o.current&&l()})}),[l])}function f1(){let n=typeof document>"u";return"useSyncExternalStore"in ru?(l=>l.useSyncExternalStore)(ru)(()=>()=>{},()=>!1,()=>!n):!1}function p1(){let n=f1(),[l,o]=y.useState(Qt.isHandoffComplete);return l&&Qt.isHandoffComplete===!1&&o(!1),y.useEffect(()=>{l!==!0&&o(!0)},[l]),y.useEffect(()=>Qt.handoff(),[]),n?!1:l}let m1=y.createContext(!1);function h1(){return y.useContext(m1)}function g1(n){let l=h1(),o=y.useContext(ah),[s,a]=y.useState(()=>{var c;if(!l&&o!==null)return(c=o.current)!=null?c:null;if(Qt.isServer)return null;let f=n?.getElementById("headlessui-portal-root");if(f)return f;if(n===null)return null;let p=n.createElement("div");return p.setAttribute("id","headlessui-portal-root"),n.body.appendChild(p)});return y.useEffect(()=>{s!==null&&(n!=null&&n.body.contains(s)||n==null||n.body.appendChild(s))},[s,n]),y.useEffect(()=>{l||o!==null&&a(o.current)},[o,a,l]),s}let sh=y.Fragment,v1=ot(function(n,l){let{ownerDocument:o=null,...s}=n,a=y.useRef(null),c=vt(Hv(b=>{a.current=b}),l),f=Uo(a.current),p=o??f,h=g1(p),v=y.useContext(b1),x=cr(),E=p1(),w=rt();return Lu(()=>{var b;h&&h.childNodes.length<=0&&((b=h.parentElement)==null||b.removeChild(h))}),!h||!E?null:Ye.createPortal(ye.createElement("div",{"data-headlessui-portal":"",ref:b=>{x.dispose(),v&&b&&x.add(v.register(b))}},w({ourProps:{ref:c},theirProps:s,slot:{},defaultTag:sh,name:"Portal"})),h)});function y1(n,l){let o=vt(l),{enabled:s=!0,ownerDocument:a,...c}=n,f=rt();return s?ye.createElement(v1,{...c,ownerDocument:a,ref:o}):f({ourProps:{ref:o},theirProps:c,slot:{},defaultTag:sh,name:"Portal"})}let x1=y.Fragment,ah=y.createContext(null);function w1(n,l){let{target:o,...s}=n,a={ref:vt(l)},c=rt();return ye.createElement(ah.Provider,{value:o},c({ourProps:a,theirProps:s,defaultTag:x1,name:"Popover.Group"}))}let b1=y.createContext(null),S1=ot(y1),E1=ot(w1),uh=Object.assign(S1,{Group:E1});const cn={Idle:{kind:"Idle"},Tracked:n=>({kind:"Tracked",position:n}),Moved:{kind:"Moved"}};function Iu(n){let l=n.getBoundingClientRect();return`${l.x},${l.y}`}function ch(n,l,o){let s=gt();if(l.kind==="Tracked"){let a=function(){c!==Iu(n)&&(s.dispose(),o())},{position:c}=l,f=new ResizeObserver(a);f.observe(n),s.add(()=>f.disconnect()),s.addEventListener(window,"scroll",a,{passive:!0}),s.addEventListener(window,"resize",a)}return()=>s.dispose()}var k1=Object.defineProperty,C1=(n,l,o)=>l in n?k1(n,l,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[l]=o,Rp=(n,l,o)=>(C1(n,typeof l!="symbol"?l+"":l,o),o),Se=(n=>(n[n.Open=0]="Open",n[n.Closed=1]="Closed",n))(Se||{}),St=(n=>(n[n.Single=0]="Single",n[n.Multi=1]="Multi",n))(St||{}),Xt=(n=>(n[n.Pointer=0]="Pointer",n[n.Focus=1]="Focus",n[n.Other=2]="Other",n))(Xt||{}),dh=(n=>(n[n.OpenCombobox=0]="OpenCombobox",n[n.CloseCombobox=1]="CloseCombobox",n[n.GoToOption=2]="GoToOption",n[n.SetTyping=3]="SetTyping",n[n.RegisterOption=4]="RegisterOption",n[n.UnregisterOption=5]="UnregisterOption",n[n.DefaultToFirstOption=6]="DefaultToFirstOption",n[n.SetActivationTrigger=7]="SetActivationTrigger",n[n.UpdateVirtualConfiguration=8]="UpdateVirtualConfiguration",n[n.SetInputElement=9]="SetInputElement",n[n.SetButtonElement=10]="SetButtonElement",n[n.SetOptionsElement=11]="SetOptionsElement",n[n.MarkInputAsMoved=12]="MarkInputAsMoved",n))(dh||{});function eu(n,l=o=>o){let o=n.activeOptionIndex!==null?n.options[n.activeOptionIndex]:null,s=l(n.options.slice()),a=s.length>0&&s[0].dataRef.current.order!==null?s.sort((f,p)=>f.dataRef.current.order-p.dataRef.current.order):Pu(s,f=>f.dataRef.current.domRef.current),c=o?a.indexOf(o):null;return c===-1&&(c=null),{options:a,activeOptionIndex:c}}let N1={1(n){var l;if((l=n.dataRef.current)!=null&&l.disabled||n.comboboxState===1)return n;let o=n.inputElement?cn.Tracked(Iu(n.inputElement)):n.inputPositionState;return{...n,activeOptionIndex:null,comboboxState:1,isTyping:!1,activationTrigger:2,inputPositionState:o,__demoMode:!1}},0(n){var l,o;if((l=n.dataRef.current)!=null&&l.disabled||n.comboboxState===0)return n;if((o=n.dataRef.current)!=null&&o.value){let s=n.dataRef.current.calculateIndex(n.dataRef.current.value);if(s!==-1)return{...n,activeOptionIndex:s,comboboxState:0,__demoMode:!1,inputPositionState:cn.Idle}}return{...n,comboboxState:0,inputPositionState:cn.Idle,__demoMode:!1}},3(n,l){return n.isTyping===l.isTyping?n:{...n,isTyping:l.isTyping}},2(n,l){var o,s,a,c;if((o=n.dataRef.current)!=null&&o.disabled||n.optionsElement&&!((s=n.dataRef.current)!=null&&s.optionsPropsRef.current.static)&&n.comboboxState===1)return n;if(n.virtual){let{options:v,disabled:x}=n.virtual,E=l.focus===we.Specific?l.idx:Dr(l,{resolveItems:()=>v,resolveActiveIndex:()=>{var b,S;return(S=(b=n.activeOptionIndex)!=null?b:v.findIndex(C=>!x(C)))!=null?S:null},resolveDisabled:x,resolveId(){throw new Error("Function not implemented.")}}),w=(a=l.trigger)!=null?a:2;return n.activeOptionIndex===E&&n.activationTrigger===w?n:{...n,activeOptionIndex:E,activationTrigger:w,isTyping:!1,__demoMode:!1}}let f=eu(n);if(f.activeOptionIndex===null){let v=f.options.findIndex(x=>!x.dataRef.current.disabled);v!==-1&&(f.activeOptionIndex=v)}let p=l.focus===we.Specific?l.idx:Dr(l,{resolveItems:()=>f.options,resolveActiveIndex:()=>f.activeOptionIndex,resolveId:v=>v.id,resolveDisabled:v=>v.dataRef.current.disabled}),h=(c=l.trigger)!=null?c:2;return n.activeOptionIndex===p&&n.activationTrigger===h?n:{...n,...f,isTyping:!1,activeOptionIndex:p,activationTrigger:h,__demoMode:!1}},4:(n,l)=>{var o,s,a,c;if((o=n.dataRef.current)!=null&&o.virtual)return{...n,options:[...n.options,l.payload]};let f=l.payload,p=eu(n,v=>(v.push(f),v));n.activeOptionIndex===null&&(a=(s=n.dataRef.current).isSelected)!=null&&a.call(s,l.payload.dataRef.current.value)&&(p.activeOptionIndex=p.options.indexOf(f));let h={...n,...p,activationTrigger:2};return(c=n.dataRef.current)!=null&&c.__demoMode&&n.dataRef.current.value===void 0&&(h.activeOptionIndex=0),h},5:(n,l)=>{var o;if((o=n.dataRef.current)!=null&&o.virtual)return{...n,options:n.options.filter(a=>a.id!==l.id)};let s=eu(n,a=>{let c=a.findIndex(f=>f.id===l.id);return c!==-1&&a.splice(c,1),a});return{...n,...s,activationTrigger:2}},6:(n,l)=>n.defaultToFirstOption===l.value?n:{...n,defaultToFirstOption:l.value},7:(n,l)=>n.activationTrigger===l.trigger?n:{...n,activationTrigger:l.trigger},8:(n,l)=>{var o,s;if(n.virtual===null)return{...n,virtual:{options:l.options,disabled:(o=l.disabled)!=null?o:()=>!1}};if(n.virtual.options===l.options&&n.virtual.disabled===l.disabled)return n;let a=n.activeOptionIndex;if(n.activeOptionIndex!==null){let c=l.options.indexOf(n.virtual.options[n.activeOptionIndex]);c!==-1?a=c:a=null}return{...n,activeOptionIndex:a,virtual:{options:l.options,disabled:(s=l.disabled)!=null?s:()=>!1}}},9:(n,l)=>n.inputElement===l.element?n:{...n,inputElement:l.element},10:(n,l)=>n.buttonElement===l.element?n:{...n,buttonElement:l.element},11:(n,l)=>n.optionsElement===l.element?n:{...n,optionsElement:l.element},12(n){return n.inputPositionState.kind!=="Tracked"?n:{...n,inputPositionState:cn.Moved}}},j1=class fh extends Nu{constructor(l){super(l),Rp(this,"actions",{onChange:o=>{let{onChange:s,compare:a,mode:c,value:f}=this.state.dataRef.current;return tt(c,{0:()=>s?.(o),1:()=>{let p=f.slice(),h=p.findIndex(v=>a(v,o));return h===-1?p.push(o):p.splice(h,1),s?.(p)}})},registerOption:(o,s)=>(this.send({type:4,payload:{id:o,dataRef:s}}),()=>{this.state.activeOptionIndex===this.state.dataRef.current.calculateIndex(s.current.value)&&this.send({type:6,value:!0}),this.send({type:5,id:o})}),goToOption:(o,s)=>(this.send({type:6,value:!1}),this.send({type:2,...o,trigger:s})),setIsTyping:o=>{this.send({type:3,isTyping:o})},closeCombobox:()=>{var o,s;this.send({type:1}),this.send({type:6,value:!1}),(s=(o=this.state.dataRef.current).onClose)==null||s.call(o)},openCombobox:()=>{this.send({type:0}),this.send({type:6,value:!0})},setActivationTrigger:o=>{this.send({type:7,trigger:o})},selectActiveOption:()=>{let o=this.selectors.activeOptionIndex(this.state);if(o!==null){if(this.actions.setIsTyping(!1),this.state.virtual)this.actions.onChange(this.state.virtual.options[o]);else{let{dataRef:s}=this.state.options[o];this.actions.onChange(s.current.value)}this.actions.goToOption({focus:we.Specific,idx:o})}},setInputElement:o=>{this.send({type:9,element:o})},setButtonElement:o=>{this.send({type:10,element:o})},setOptionsElement:o=>{this.send({type:11,element:o})}}),Rp(this,"selectors",{activeDescendantId:o=>{var s,a;let c=this.selectors.activeOptionIndex(o);if(c!==null)return o.virtual?(a=o.options.find(f=>!f.dataRef.current.disabled&&o.dataRef.current.compare(f.dataRef.current.value,o.virtual.options[c])))==null?void 0:a.id:(s=o.options[c])==null?void 0:s.id},activeOptionIndex:o=>{if(o.defaultToFirstOption&&o.activeOptionIndex===null&&(o.virtual?o.virtual.options.length>0:o.options.length>0)){if(o.virtual){let{options:a,disabled:c}=o.virtual,f=a.findIndex(p=>{var h;return!((h=c?.(p))!=null&&h)});if(f!==-1)return f}let s=o.options.findIndex(a=>!a.dataRef.current.disabled);if(s!==-1)return s}return o.activeOptionIndex},activeOption:o=>{var s,a;let c=this.selectors.activeOptionIndex(o);return c===null?null:o.virtual?o.virtual.options[c??0]:(a=(s=o.options[c])==null?void 0:s.dataRef.current.value)!=null?a:null},isActive:(o,s,a)=>{var c;let f=this.selectors.activeOptionIndex(o);return f===null?!1:o.virtual?f===o.dataRef.current.calculateIndex(s):((c=o.options[f])==null?void 0:c.id)===a},shouldScrollIntoView:(o,s,a)=>!(o.virtual||o.__demoMode||o.comboboxState!==0||o.activationTrigger===0||!this.selectors.isActive(o,s,a)),didInputMove(o){return o.inputPositionState.kind==="Moved"}});{let o=this.state.id,s=Zo.get(null);this.disposables.add(s.on(ju.Push,a=>{!s.selectors.isTop(a,o)&&this.state.comboboxState===0&&this.actions.closeCombobox()})),this.on(0,()=>s.actions.push(o)),this.on(1,()=>s.actions.pop(o))}this.disposables.group(o=>{this.on(1,s=>{s.inputElement&&(o.dispose(),o.add(ch(s.inputElement,s.inputPositionState,()=>{this.send({type:12})})))})})}static new({id:l,virtual:o=null,__demoMode:s=!1}){var a;return new fh({id:l,dataRef:{current:{}},comboboxState:s?0:1,isTyping:!1,options:[],virtual:o?{options:o.options,disabled:(a=o.disabled)!=null?a:()=>!1}:null,activeOptionIndex:null,activationTrigger:2,inputElement:null,buttonElement:null,optionsElement:null,__demoMode:s,inputPositionState:cn.Idle})}reduce(l,o){return tt(o.type,N1,l,o)}};const ph=y.createContext(null);function nl(n){let l=y.useContext(ph);if(l===null){let o=new Error(`<${n} /> is missing a parent component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,mh),o}return l}function mh({id:n,virtual:l=null,__demoMode:o=!1}){let s=y.useMemo(()=>j1.new({id:n,virtual:l,__demoMode:o}),[]);return Lu(()=>s.dispose()),s}let Yo=y.createContext(null);Yo.displayName="ComboboxDataContext";function Yr(n){let l=y.useContext(Yo);if(l===null){let o=new Error(`<${n} /> is missing a parent component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,Yr),o}return l}let hh=y.createContext(null);function O1(n){let l=nl("VirtualProvider"),o=Yr("VirtualProvider"),{options:s}=o.virtual,a=je(l,b=>b.optionsElement),[c,f]=y.useMemo(()=>{let b=a;if(!b)return[0,0];let S=window.getComputedStyle(b);return[parseFloat(S.paddingBlockStart||S.paddingTop),parseFloat(S.paddingBlockEnd||S.paddingBottom)]},[a]),p=iy({enabled:s.length!==0,scrollPaddingStart:c,scrollPaddingEnd:f,count:s.length,estimateSize(){return 40},getScrollElement(){return l.state.optionsElement},overscan:12}),[h,v]=y.useState(0);Le(()=>{v(b=>b+1)},[s]);let x=p.getVirtualItems(),E=je(l,b=>b.activationTrigger===Xt.Pointer),w=je(l,l.selectors.activeOptionIndex);return x.length===0?null:ye.createElement(hh.Provider,{value:p},ye.createElement("div",{style:{position:"relative",width:"100%",height:`${p.getTotalSize()}px`},ref:b=>{b&&(E||w!==null&&s.length>w&&p.scrollToIndex(w))}},x.map(b=>{var S;return ye.createElement(y.Fragment,{key:b.key},ye.cloneElement((S=n.children)==null?void 0:S.call(n,{...n.slot,option:s[b.index]}),{key:`${h}-${b.key}`,"data-index":b.index,"aria-setsize":s.length,"aria-posinset":b.index+1,style:{position:"absolute",top:0,left:0,transform:`translateY(${b.start}px)`,overflowAnchor:"none"}}))})))}let P1=y.Fragment;function T1(n,l){let o=y.useId(),s=Li(),{value:a,defaultValue:c,onChange:f,form:p,name:h,by:v,invalid:x=!1,disabled:E=s||!1,onClose:w,__demoMode:b=!1,multiple:S=!1,immediate:C=!1,virtual:j=null,nullable:I,...L}=n,P=nm(c),[M=S?[]:void 0,A]=tm(a,f,P),H=mh({id:o,virtual:j,__demoMode:b}),q=y.useRef({static:!1,hold:!1}),ee=vm(v),he=xe(ie=>j?v===null?j.options.indexOf(ie):j.options.findIndex(Ee=>ee(Ee,ie)):H.state.options.findIndex(Ee=>ee(Ee.dataRef.current.value,ie))),J=y.useCallback(ie=>tt(ae.mode,{[St.Multi]:()=>M.some(Ee=>ee(Ee,ie)),[St.Single]:()=>ee(M,ie)}),[M]),Q=je(H,ie=>ie.virtual),z=xe(()=>w?.()),ae=y.useMemo(()=>({__demoMode:b,immediate:C,optionsPropsRef:q,value:M,defaultValue:P,disabled:E,invalid:x,mode:S?St.Multi:St.Single,virtual:j?Q:null,onChange:A,isSelected:J,calculateIndex:he,compare:ee,onClose:z}),[b,C,q,M,P,E,x,S,j,Q,A,J,he,ee,z]);Le(()=>{var ie;j&&H.send({type:dh.UpdateVirtualConfiguration,options:j.options,disabled:(ie=j.disabled)!=null?ie:null})},[j,j?.options,j?.disabled]),Le(()=>{H.state.dataRef.current=ae},[ae]);let[ue,G,ce,ve]=je(H,ie=>[ie.comboboxState,ie.buttonElement,ie.inputElement,ie.optionsElement]),D=Zo.get(null),X=je(D,y.useCallback(ie=>D.selectors.isTop(ie,o),[D,o]));Pm(X,[G,ce,ve],()=>H.actions.closeCombobox());let K=je(H,H.selectors.activeOptionIndex),T=je(H,H.selectors.activeOption),R=kt({open:ue===Se.Open,disabled:E,invalid:x,activeIndex:K,activeOption:T,value:M}),[re,le]=mm(),pe=l===null?{}:{ref:l},U=y.useCallback(()=>{if(P!==void 0)return A?.(P)},[A,P]),me=rt();return ye.createElement(le,{value:re,props:{htmlFor:ce?.id},slot:{open:ue===Se.Open,disabled:E}},ye.createElement(rh,null,ye.createElement(Yo.Provider,{value:ae},ye.createElement(ph.Provider,{value:H},ye.createElement(ih,{value:tt(ue,{[Se.Open]:dn.Open,[Se.Closed]:dn.Closed})},h!=null&&ye.createElement(sm,{disabled:E,data:M!=null?{[h]:M}:{},form:p,onReset:U}),me({ourProps:pe,theirProps:L,slot:R,defaultTag:P1,name:"Combobox"}))))))}let R1="input";function $1(n,l){var o,s;let a=nl("Combobox.Input"),c=Yr("Combobox.Input"),f=y.useId(),p=Eu(),{id:h=p||`headlessui-combobox-input-${f}`,onChange:v,displayValue:x,disabled:E=c.disabled||!1,autoFocus:w=!1,type:b="text",...S}=n,C=y.useRef(null),j=vt(C,l,eh(),a.actions.setInputElement),[I,L]=je(a,R=>[R.comboboxState,R.isTyping]),P=cr(),M=xe(()=>{a.actions.onChange(null),a.state.optionsElement&&(a.state.optionsElement.scrollTop=0),a.actions.goToOption({focus:we.Nothing})}),A=y.useMemo(()=>{var R;return typeof x=="function"&&c.value!==void 0?(R=x(c.value))!=null?R:"":typeof c.value=="string"?c.value:""},[c.value,x]);mp(([R,re],[le,pe])=>{if(a.state.isTyping)return;let U=C.current;U&&((pe===Se.Open&&re===Se.Closed||R!==le)&&(U.value=R),requestAnimationFrame(()=>{if(a.state.isTyping||!U||bu(U))return;let{selectionStart:me,selectionEnd:ie}=U;Math.abs((ie??0)-(me??0))===0&&me===0&&U.setSelectionRange(U.value.length,U.value.length)}))},[A,I,L]),mp(([R],[re])=>{if(R===Se.Open&&re===Se.Closed){if(a.state.isTyping)return;let le=C.current;if(!le)return;let pe=le.value,{selectionStart:U,selectionEnd:me,selectionDirection:ie}=le;le.value="",le.value=pe,ie!==null?le.setSelectionRange(U,me,ie):le.setSelectionRange(U,me)}},[I]);let H=y.useRef(!1),q=xe(()=>{H.current=!0}),ee=xe(()=>{P.nextFrame(()=>{H.current=!1})}),he=xe(R=>{switch(a.actions.setIsTyping(!0),R.key){case Ne.Enter:if(a.state.comboboxState!==Se.Open||H.current)return;if(R.preventDefault(),R.stopPropagation(),a.selectors.activeOptionIndex(a.state)===null){a.actions.closeCombobox();return}a.actions.selectActiveOption(),c.mode===St.Single&&a.actions.closeCombobox();break;case Ne.ArrowDown:return R.preventDefault(),R.stopPropagation(),tt(a.state.comboboxState,{[Se.Open]:()=>a.actions.goToOption({focus:we.Next}),[Se.Closed]:()=>a.actions.openCombobox()});case Ne.ArrowUp:return R.preventDefault(),R.stopPropagation(),tt(a.state.comboboxState,{[Se.Open]:()=>a.actions.goToOption({focus:we.Previous}),[Se.Closed]:()=>{Ye.flushSync(()=>a.actions.openCombobox()),c.value||a.actions.goToOption({focus:we.Last})}});case Ne.Home:if(a.state.comboboxState===Se.Closed||R.shiftKey)break;return R.preventDefault(),R.stopPropagation(),a.actions.goToOption({focus:we.First});case Ne.PageUp:return R.preventDefault(),R.stopPropagation(),a.actions.goToOption({focus:we.First});case Ne.End:if(a.state.comboboxState===Se.Closed||R.shiftKey)break;return R.preventDefault(),R.stopPropagation(),a.actions.goToOption({focus:we.Last});case Ne.PageDown:return R.preventDefault(),R.stopPropagation(),a.actions.goToOption({focus:we.Last});case Ne.Escape:return a.state.comboboxState!==Se.Open?void 0:(R.preventDefault(),a.state.optionsElement&&!c.optionsPropsRef.current.static&&R.stopPropagation(),c.mode===St.Single&&c.value===null&&M(),a.actions.closeCombobox());case Ne.Tab:if(a.actions.setIsTyping(!1),a.state.comboboxState!==Se.Open)return;c.mode===St.Single&&a.state.activationTrigger!==Xt.Focus&&a.actions.selectActiveOption(),a.actions.closeCombobox();break}}),J=xe(R=>{v?.(R),c.mode===St.Single&&R.target.value===""&&M(),a.actions.openCombobox()}),Q=xe(R=>{var re,le,pe;let U=(re=R.relatedTarget)!=null?re:er.find(me=>me!==R.currentTarget);if(!((le=a.state.optionsElement)!=null&&le.contains(U))&&!((pe=a.state.buttonElement)!=null&&pe.contains(U))&&a.state.comboboxState===Se.Open)return R.preventDefault(),c.mode===St.Single&&c.value===null&&M(),a.actions.closeCombobox()}),z=xe(R=>{var re,le,pe;let U=(re=R.relatedTarget)!=null?re:er.find(me=>me!==R.currentTarget);(le=a.state.buttonElement)!=null&&le.contains(U)||(pe=a.state.optionsElement)!=null&&pe.contains(U)||c.disabled||c.immediate&&a.state.comboboxState!==Se.Open&&P.microTask(()=>{Ye.flushSync(()=>a.actions.openCombobox()),a.actions.setActivationTrigger(Xt.Focus)})}),ae=Jo(),ue=fm(),{isFocused:G,focusProps:ce}=wu({autoFocus:w}),{isHovered:ve,hoverProps:D}=xu({isDisabled:E}),X=je(a,R=>R.optionsElement),K=kt({open:I===Se.Open,disabled:E,invalid:c.invalid,hover:ve,focus:G,autofocus:w}),T=qo({ref:j,id:h,role:"combobox",type:b,"aria-controls":X?.id,"aria-expanded":I===Se.Open,"aria-activedescendant":je(a,a.selectors.activeDescendantId),"aria-labelledby":ae,"aria-describedby":ue,"aria-autocomplete":"list",defaultValue:(s=(o=n.defaultValue)!=null?o:c.defaultValue!==void 0?x?.(c.defaultValue):null)!=null?s:c.defaultValue,disabled:E||void 0,autoFocus:w,onCompositionStart:q,onCompositionEnd:ee,onKeyDown:he,onChange:J,onFocus:z,onBlur:Q},ce,D);return rt()({ourProps:T,theirProps:S,slot:K,defaultTag:R1,name:"Combobox.Input"})}let M1="button";function _1(n,l){let o=nl("Combobox.Button"),s=Yr("Combobox.Button"),[a,c]=y.useState(null),f=vt(l,c,o.actions.setButtonElement),p=y.useId(),{id:h=`headlessui-combobox-button-${p}`,disabled:v=s.disabled||!1,autoFocus:x=!1,...E}=n,[w,b,S]=je(o,z=>[z.comboboxState,z.inputElement,z.optionsElement]),C=Rm(b),j=w===Se.Open;Tm(j,{trigger:a,action:y.useCallback(z=>{if(a!=null&&a.contains(z.target)||b!=null&&b.contains(z.target))return sn.Ignore;let ae=z.target.closest('[role="option"]:not([data-disabled])');return Gt(ae)?sn.Select(ae):S!=null&&S.contains(z.target)?sn.Ignore:sn.Close},[a,b,S]),close:o.actions.closeCombobox,select:o.actions.selectActiveOption});let I=xe(z=>{switch(z.key){case Ne.Space:case Ne.Enter:z.preventDefault(),z.stopPropagation(),o.state.comboboxState===Se.Closed&&Ye.flushSync(()=>o.actions.openCombobox()),C();return;case Ne.ArrowDown:z.preventDefault(),z.stopPropagation(),o.state.comboboxState===Se.Closed&&(Ye.flushSync(()=>o.actions.openCombobox()),o.state.dataRef.current.value||o.actions.goToOption({focus:we.First})),C();return;case Ne.ArrowUp:z.preventDefault(),z.stopPropagation(),o.state.comboboxState===Se.Closed&&(Ye.flushSync(()=>o.actions.openCombobox()),o.state.dataRef.current.value||o.actions.goToOption({focus:we.Last})),C();return;case Ne.Escape:if(o.state.comboboxState!==Se.Open)return;z.preventDefault(),o.state.optionsElement&&!s.optionsPropsRef.current.static&&z.stopPropagation(),Ye.flushSync(()=>o.actions.closeCombobox()),C();return;default:return}}),L=ym(()=>{o.state.comboboxState===Se.Open?o.actions.closeCombobox():o.actions.openCombobox(),C()}),P=Jo([h]),{isFocusVisible:M,focusProps:A}=wu({autoFocus:x}),{isHovered:H,hoverProps:q}=xu({isDisabled:v}),{pressed:ee,pressProps:he}=Jp({disabled:v}),J=kt({open:w===Se.Open,active:ee||w===Se.Open,disabled:v,invalid:s.invalid,value:s.value,hover:H,focus:M}),Q=qo({ref:f,id:h,type:$m(n,a),tabIndex:-1,"aria-haspopup":"listbox","aria-controls":S?.id,"aria-expanded":w===Se.Open,"aria-labelledby":P,disabled:v||void 0,autoFocus:x,onKeyDown:I},L,A,q,he);return rt()({ourProps:Q,theirProps:E,slot:J,defaultTag:M1,name:"Combobox.Button"})}let L1="div",I1=Bo.RenderStrategy|Bo.Static;function F1(n,l){var o,s,a;let c=y.useId(),{id:f=`headlessui-combobox-options-${c}`,hold:p=!1,anchor:h,portal:v=!1,modal:x=!0,transition:E=!1,...w}=n,b=nl("Combobox.Options"),S=Yr("Combobox.Options"),C=Zm(h);C&&(v=!0);let[j,I]=nh(C),[L,P]=y.useState(null),M=th(),A=vt(l,C?j:null,b.actions.setOptionsElement,P),[H,q,ee,he,J]=je(b,Ie=>[Ie.comboboxState,Ie.inputElement,Ie.buttonElement,Ie.optionsElement,Ie.activationTrigger]),Q=Uo(q||ee),z=Uo(he),ae=lh(),[ue,G]=Im(E,L,ae!==null?(ae&dn.Open)===dn.Open:H===Se.Open);Cm(ue,q,b.actions.closeCombobox);let ce=S.__demoMode?!1:x&&H===Se.Open;Mm(ce,z);let ve=S.__demoMode?!1:x&&H===Se.Open;km(ve,{allowed:y.useCallback(()=>[q,ee,he],[q,ee,he])});let D=je(b,b.selectors.didInputMove)?!1:ue;Le(()=>{var Ie;S.optionsPropsRef.current.static=(Ie=n.static)!=null?Ie:!1},[S.optionsPropsRef,n.static]),Le(()=>{S.optionsPropsRef.current.hold=p},[S.optionsPropsRef,p]),Ky(H===Se.Open,{container:he,accept(Ie){return Ie.getAttribute("role")==="option"?NodeFilter.FILTER_REJECT:Ie.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(Ie){Ie.setAttribute("role","none")}});let X=Jo([ee?.id]),K=kt({open:H===Se.Open,option:void 0}),T=xe(()=>{b.actions.setActivationTrigger(Xt.Pointer)}),R=xe(Ie=>{Ie.preventDefault(),b.actions.setActivationTrigger(Xt.Pointer)}),re=qo(C?M():{},{"aria-labelledby":X,role:"listbox","aria-multiselectable":S.mode===St.Multi?!0:void 0,id:f,ref:A,style:{...w.style,...I,"--input-width":cu(ue,q,!0).width,"--button-width":cu(ue,ee,!0).width},onWheel:J===Xt.Pointer?void 0:T,onMouseDown:R,...Lm(G)}),le=ue&&H===Se.Closed&&!n.static,pe=$i(le,(o=S.virtual)==null?void 0:o.options),U=$i(le,S.value),me=y.useCallback(Ie=>S.compare(U,Ie),[S.compare,U]),ie=y.useMemo(()=>{if(!S.virtual)return S;if(pe===void 0)throw new Error("Missing `options` in virtual mode");return pe!==S.virtual.options?{...S,virtual:{...S.virtual,options:pe}}:S},[S,pe,(s=S.virtual)==null?void 0:s.options]);S.virtual&&Object.assign(w,{children:ye.createElement(Yo.Provider,{value:ie},ye.createElement(O1,{slot:K},w.children))});let Ee=rt(),lt=y.useMemo(()=>S.mode===St.Multi?S:{...S,isSelected:me},[S,me]);return ye.createElement(uh,{enabled:v?n.static||ue:!1,ownerDocument:Q},ye.createElement(Yo.Provider,{value:lt},Ee({ourProps:re,theirProps:{...w,children:ye.createElement(u1,{freeze:le},typeof w.children=="function"?(a=w.children)==null?void 0:a.call(w,K):w.children)},slot:K,defaultTag:L1,features:I1,visible:D,name:"Combobox.Options"})))}let D1="div";function A1(n,l){var o,s,a;let c=Yr("Combobox.Option"),f=nl("Combobox.Option"),p=y.useId(),{id:h=`headlessui-combobox-option-${p}`,value:v,disabled:x=(a=(s=(o=c.virtual)==null?void 0:o.disabled)==null?void 0:s.call(o,v))!=null?a:!1,order:E=null,...w}=n,[b]=je(f,G=>[G.inputElement]),S=Rm(b),C=je(f,y.useCallback(G=>f.selectors.isActive(G,v,h),[v,h])),j=c.isSelected(v),I=y.useRef(null),L=Dn({disabled:x,value:v,domRef:I,order:E}),P=y.useContext(hh),M=vt(l,I,P?P.measureElement:null),A=xe(()=>{f.actions.setIsTyping(!1),f.actions.onChange(v)});Le(()=>f.actions.registerOption(h,L),[L,h]);let H=je(f,y.useCallback(G=>f.selectors.shouldScrollIntoView(G,v,h),[v,h]));Le(()=>{if(H)return gt().requestAnimationFrame(()=>{var G,ce;(ce=(G=I.current)==null?void 0:G.scrollIntoView)==null||ce.call(G,{block:"nearest"})})},[H,I]);let q=xe(G=>{G.preventDefault(),G.button===Cu.Left&&(x||(A(),pu()||requestAnimationFrame(()=>S()),c.mode===St.Single&&f.actions.closeCombobox()))}),ee=xe(()=>{if(x)return f.actions.goToOption({focus:we.Nothing});let G=c.calculateIndex(v);f.actions.goToOption({focus:we.Specific,idx:G})}),he=_m(),J=xe(G=>he.update(G)),Q=xe(G=>{if(!he.wasMoved(G)||x||C&&f.state.activationTrigger===Xt.Pointer)return;let ce=c.calculateIndex(v);f.actions.goToOption({focus:we.Specific,idx:ce},Xt.Pointer)}),z=xe(G=>{he.wasMoved(G)&&(x||C&&(c.optionsPropsRef.current.hold||f.state.activationTrigger===Xt.Pointer&&f.actions.goToOption({focus:we.Nothing})))}),ae=kt({active:C,focus:C,selected:j,disabled:x}),ue={id:h,ref:M,role:"option",tabIndex:x===!0?void 0:-1,"aria-disabled":x===!0?!0:void 0,"aria-selected":j,disabled:void 0,onMouseDown:q,onFocus:ee,onPointerEnter:J,onMouseEnter:J,onPointerMove:Q,onMouseMove:Q,onPointerLeave:z,onMouseLeave:z};return rt()({ourProps:ue,theirProps:w,slot:ae,defaultTag:D1,name:"Combobox.Option"})}let z1=ot(T1),W1=ot(_1),H1=ot($1),V1=hm,B1=ot(F1),U1=ot(A1),Io=Object.assign(z1,{Input:H1,Button:W1,Label:V1,Options:B1,Option:U1}),$p=/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g;function Mp(n){var l,o;let s=(l=n.innerText)!=null?l:"",a=n.cloneNode(!0);if(!Gt(a))return s;let c=!1;for(let p of a.querySelectorAll('[hidden],[aria-hidden],[role="img"]'))p.remove(),c=!0;let f=c?(o=a.innerText)!=null?o:"":s;return $p.test(f)&&(f=f.replace($p,"")),f}function K1(n){let l=n.getAttribute("aria-label");if(typeof l=="string")return l.trim();let o=n.getAttribute("aria-labelledby");if(o){let s=o.split(" ").map(a=>{let c=document.getElementById(a);if(c){let f=c.getAttribute("aria-label");return typeof f=="string"?f.trim():Mp(c).trim()}return null}).filter(Boolean);if(s.length>0)return s.join(", ")}return Mp(n).trim()}function Q1(n){let l=y.useRef(""),o=y.useRef("");return xe(()=>{let s=n.current;if(!s)return"";let a=s.innerText;if(l.current===a)return o.current;let c=K1(s).trim().toLowerCase();return l.current=a,o.current=c,c})}var Y1=Object.defineProperty,X1=(n,l,o)=>l in n?Y1(n,l,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[l]=o,_p=(n,l,o)=>(X1(n,typeof l!="symbol"?l+"":l,o),o),et=(n=>(n[n.Open=0]="Open",n[n.Closed=1]="Closed",n))(et||{}),Mn=(n=>(n[n.Single=0]="Single",n[n.Multi=1]="Multi",n))(Mn||{}),bi=(n=>(n[n.Pointer=0]="Pointer",n[n.Other=1]="Other",n))(bi||{}),gh=(n=>(n[n.OpenListbox=0]="OpenListbox",n[n.CloseListbox=1]="CloseListbox",n[n.GoToOption=2]="GoToOption",n[n.Search=3]="Search",n[n.ClearSearch=4]="ClearSearch",n[n.SelectOption=5]="SelectOption",n[n.RegisterOptions=6]="RegisterOptions",n[n.UnregisterOptions=7]="UnregisterOptions",n[n.SetButtonElement=8]="SetButtonElement",n[n.SetOptionsElement=9]="SetOptionsElement",n[n.SortOptions=10]="SortOptions",n[n.MarkButtonAsMoved=11]="MarkButtonAsMoved",n))(gh||{});function Lp(n,l=o=>o){let o=n.activeOptionIndex!==null?n.options[n.activeOptionIndex]:null,s=Pu(l(n.options.slice()),c=>c.dataRef.current.domRef.current),a=o?s.indexOf(o):null;return a===-1&&(a=null),{options:s,activeOptionIndex:a}}let G1={1(n){if(n.dataRef.current.disabled||n.listboxState===1)return n;let l=n.buttonElement?cn.Tracked(Iu(n.buttonElement)):n.buttonPositionState;return{...n,activeOptionIndex:null,pendingFocus:{focus:we.Nothing},listboxState:1,__demoMode:!1,buttonPositionState:l}},0(n,l){if(n.dataRef.current.disabled||n.listboxState===0)return n;let o=n.activeOptionIndex,{isSelected:s}=n.dataRef.current,a=n.options.findIndex(c=>s(c.dataRef.current.value));return a!==-1&&(o=a),{...n,frozenValue:!1,pendingFocus:l.focus,listboxState:0,activeOptionIndex:o,__demoMode:!1,buttonPositionState:cn.Idle}},2(n,l){var o,s,a,c,f;if(n.dataRef.current.disabled||n.listboxState===1)return n;let p={...n,searchQuery:"",activationTrigger:(o=l.trigger)!=null?o:1,__demoMode:!1};if(l.focus===we.Nothing)return{...p,activeOptionIndex:null};if(l.focus===we.Specific)return{...p,activeOptionIndex:n.options.findIndex(x=>x.id===l.id)};if(l.focus===we.Previous){let x=n.activeOptionIndex;if(x!==null){let E=n.options[x].dataRef.current.domRef,w=Dr(l,{resolveItems:()=>n.options,resolveActiveIndex:()=>n.activeOptionIndex,resolveId:b=>b.id,resolveDisabled:b=>b.dataRef.current.disabled});if(w!==null){let b=n.options[w].dataRef.current.domRef;if(((s=E.current)==null?void 0:s.previousElementSibling)===b.current||((a=b.current)==null?void 0:a.previousElementSibling)===null)return{...p,activeOptionIndex:w}}}}else if(l.focus===we.Next){let x=n.activeOptionIndex;if(x!==null){let E=n.options[x].dataRef.current.domRef,w=Dr(l,{resolveItems:()=>n.options,resolveActiveIndex:()=>n.activeOptionIndex,resolveId:b=>b.id,resolveDisabled:b=>b.dataRef.current.disabled});if(w!==null){let b=n.options[w].dataRef.current.domRef;if(((c=E.current)==null?void 0:c.nextElementSibling)===b.current||((f=b.current)==null?void 0:f.nextElementSibling)===null)return{...p,activeOptionIndex:w}}}}let h=Lp(n),v=Dr(l,{resolveItems:()=>h.options,resolveActiveIndex:()=>h.activeOptionIndex,resolveId:x=>x.id,resolveDisabled:x=>x.dataRef.current.disabled});return{...p,...h,activeOptionIndex:v}},3:(n,l)=>{if(n.dataRef.current.disabled||n.listboxState===1)return n;let o=n.searchQuery!==""?0:1,s=n.searchQuery+l.value.toLowerCase(),a=(n.activeOptionIndex!==null?n.options.slice(n.activeOptionIndex+o).concat(n.options.slice(0,n.activeOptionIndex+o)):n.options).find(f=>{var p;return!f.dataRef.current.disabled&&((p=f.dataRef.current.textValue)==null?void 0:p.startsWith(s))}),c=a?n.options.indexOf(a):-1;return c===-1||c===n.activeOptionIndex?{...n,searchQuery:s}:{...n,searchQuery:s,activeOptionIndex:c,activationTrigger:1}},4(n){return n.dataRef.current.disabled||n.listboxState===1||n.searchQuery===""?n:{...n,searchQuery:""}},5(n){return n.dataRef.current.mode===0?{...n,frozenValue:!0}:{...n}},6:(n,l)=>{let o=n.options.concat(l.options),s=n.activeOptionIndex;if(n.pendingFocus.focus!==we.Nothing&&(s=Dr(n.pendingFocus,{resolveItems:()=>o,resolveActiveIndex:()=>n.activeOptionIndex,resolveId:a=>a.id,resolveDisabled:a=>a.dataRef.current.disabled})),n.activeOptionIndex===null){let{isSelected:a}=n.dataRef.current;if(a){let c=o.findIndex(f=>a?.(f.dataRef.current.value));c!==-1&&(s=c)}}return{...n,options:o,activeOptionIndex:s,pendingFocus:{focus:we.Nothing},pendingShouldSort:!0}},7:(n,l)=>{let o=n.options,s=[],a=new Set(l.options);for(let[c,f]of o.entries())if(a.has(f.id)&&(s.push(c),a.delete(f.id),a.size===0))break;if(s.length>0){o=o.slice();for(let c of s.reverse())o.splice(c,1)}return{...n,options:o,activationTrigger:1}},8:(n,l)=>n.buttonElement===l.element?n:{...n,buttonElement:l.element},9:(n,l)=>n.optionsElement===l.element?n:{...n,optionsElement:l.element},10:n=>n.pendingShouldSort?{...n,...Lp(n),pendingShouldSort:!1}:n,11(n){return n.buttonPositionState.kind!=="Tracked"?n:{...n,buttonPositionState:cn.Moved}}};class Fu extends Nu{constructor(l){super(l),_p(this,"actions",{onChange:o=>{let{onChange:s,compare:a,mode:c,value:f}=this.state.dataRef.current;return tt(c,{0:()=>s?.(o),1:()=>{let p=f.slice(),h=p.findIndex(v=>a(v,o));return h===-1?p.push(o):p.splice(h,1),s?.(p)}})},registerOption:Ua(()=>{let o=[],s=new Set;return[(a,c)=>{s.has(c)||(s.add(c),o.push({id:a,dataRef:c}))},()=>(s.clear(),this.send({type:6,options:o.splice(0)}))]}),unregisterOption:Ua(()=>{let o=[];return[s=>o.push(s),()=>{this.send({type:7,options:o.splice(0)})}]}),goToOption:Ua(()=>{let o=null;return[(s,a)=>{o={type:2,...s,trigger:a}},()=>o&&this.send(o)]}),closeListbox:()=>{this.send({type:1})},openListbox:o=>{this.send({type:0,focus:o})},selectActiveOption:()=>{var o;if(this.state.activeOptionIndex!==null){let{dataRef:s}=this.state.options[this.state.activeOptionIndex];this.actions.selectOption(s.current.value)}else this.state.dataRef.current.mode===0&&(this.actions.closeListbox(),(o=this.state.buttonElement)==null||o.focus({preventScroll:!0}))},selectOption:o=>{this.send({type:5,value:o})},search:o=>{this.send({type:3,value:o})},clearSearch:()=>{this.send({type:4})},setButtonElement:o=>{this.send({type:8,element:o})},setOptionsElement:o=>{this.send({type:9,element:o})}}),_p(this,"selectors",{activeDescendantId(o){var s;let a=o.activeOptionIndex,c=o.options;return a===null||(s=c[a])==null?void 0:s.id},isActive(o,s){var a;let c=o.activeOptionIndex,f=o.options;return c!==null?((a=f[c])==null?void 0:a.id)===s:!1},hasFrozenValue(o){return o.frozenValue},shouldScrollIntoView(o,s){return o.__demoMode||o.listboxState!==0||o.activationTrigger===0?!1:this.isActive(o,s)},didButtonMove(o){return o.buttonPositionState.kind==="Moved"}}),this.on(6,()=>{requestAnimationFrame(()=>{this.send({type:10})})});{let o=this.state.id,s=Zo.get(null);this.disposables.add(s.on(ju.Push,a=>{!s.selectors.isTop(a,o)&&this.state.listboxState===0&&this.actions.closeListbox()})),this.on(0,()=>s.actions.push(o)),this.on(1,()=>s.actions.pop(o))}this.disposables.group(o=>{this.on(1,s=>{s.buttonElement&&(o.dispose(),o.add(ch(s.buttonElement,s.buttonPositionState,()=>{this.send({type:11})})))})}),this.on(5,(o,s)=>{var a;this.actions.onChange(s.value),this.state.dataRef.current.mode===0&&(this.actions.closeListbox(),(a=this.state.buttonElement)==null||a.focus({preventScroll:!0}))})}static new({id:l,__demoMode:o=!1}){return new Fu({id:l,dataRef:{current:{}},listboxState:o?0:1,options:[],searchQuery:"",activeOptionIndex:null,activationTrigger:1,buttonElement:null,optionsElement:null,pendingShouldSort:!1,pendingFocus:{focus:we.Nothing},frozenValue:!1,__demoMode:o,buttonPositionState:cn.Idle})}reduce(l,o){return tt(o.type,G1,l,o)}}const vh=y.createContext(null);function Du(n){let l=y.useContext(vh);if(l===null){let o=new Error(`<${n} /> is missing a parent component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,yh),o}return l}function yh({id:n,__demoMode:l=!1}){let o=y.useMemo(()=>Fu.new({id:n,__demoMode:l}),[]);return Lu(()=>o.dispose()),o}let Hi=y.createContext(null);Hi.displayName="ListboxDataContext";function rl(n){let l=y.useContext(Hi);if(l===null){let o=new Error(`<${n} /> is missing a parent component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,rl),o}return l}let q1=y.Fragment;function J1(n,l){let o=y.useId(),s=Li(),{value:a,defaultValue:c,form:f,name:p,onChange:h,by:v,invalid:x=!1,disabled:E=s||!1,horizontal:w=!1,multiple:b=!1,__demoMode:S=!1,...C}=n;const j=w?"horizontal":"vertical";let I=vt(l),L=nm(c),[P=b?[]:void 0,M]=tm(a,h,L),A=yh({id:o,__demoMode:S}),H=y.useRef({static:!1,hold:!1}),q=y.useRef(new Map),ee=vm(v),he=y.useCallback(R=>tt(J.mode,{[Mn.Multi]:()=>P.some(re=>ee(re,R)),[Mn.Single]:()=>ee(P,R)}),[P]),J=kt({value:P,disabled:E,invalid:x,mode:b?Mn.Multi:Mn.Single,orientation:j,onChange:M,compare:ee,isSelected:he,optionsPropsRef:H,listRef:q});Le(()=>{A.state.dataRef.current=J},[J]);let Q=je(A,R=>R.listboxState),z=Zo.get(null),ae=je(z,y.useCallback(R=>z.selectors.isTop(R,o),[z,o])),[ue,G]=je(A,R=>[R.buttonElement,R.optionsElement]);Pm(ae,[ue,G],(R,re)=>{A.send({type:gh.CloseListbox}),jm(re,Ou.Loose)||(R.preventDefault(),ue?.focus())});let ce=kt({open:Q===et.Open,disabled:E,invalid:x,value:P}),[ve,D]=mm({inherit:!0}),X={ref:I},K=y.useCallback(()=>{if(L!==void 0)return M?.(L)},[M,L]),T=rt();return ye.createElement(D,{value:ve,props:{htmlFor:ue?.id},slot:{open:Q===et.Open,disabled:E}},ye.createElement(rh,null,ye.createElement(vh.Provider,{value:A},ye.createElement(Hi.Provider,{value:J},ye.createElement(ih,{value:tt(Q,{[et.Open]:dn.Open,[et.Closed]:dn.Closed})},p!=null&&P!=null&&ye.createElement(sm,{disabled:E,data:{[p]:P},form:f,onReset:K}),T({ourProps:X,theirProps:C,slot:ce,defaultTag:q1,name:"Listbox"}))))))}let Z1="button";function ew(n,l){let o=y.useId(),s=Eu(),a=rl("Listbox.Button"),c=Du("Listbox.Button"),{id:f=s||`headlessui-listbox-button-${o}`,disabled:p=a.disabled||!1,autoFocus:h=!1,...v}=n,x=vt(l,eh(),c.actions.setButtonElement),E=l1(),[w,b,S]=je(c,G=>[G.listboxState,G.buttonElement,G.optionsElement]),C=w===et.Open;Tm(C,{trigger:b,action:y.useCallback(G=>{if(b!=null&&b.contains(G.target))return sn.Ignore;let ce=G.target.closest('[role="option"]:not([data-disabled])');return Gt(ce)?sn.Select(ce):S!=null&&S.contains(G.target)?sn.Ignore:sn.Close},[b,S]),close:c.actions.closeListbox,select:c.actions.selectActiveOption});let j=xe(G=>{switch(G.key){case Ne.Enter:Pv(G.currentTarget);break;case Ne.Space:case Ne.ArrowDown:G.preventDefault(),c.actions.openListbox({focus:a.value?we.Nothing:we.First});break;case Ne.ArrowUp:G.preventDefault(),c.actions.openListbox({focus:a.value?we.Nothing:we.Last});break}}),I=xe(G=>{switch(G.key){case Ne.Space:G.preventDefault();break}}),L=ym(G=>{var ce;c.state.listboxState===et.Open?(Ye.flushSync(()=>c.actions.closeListbox()),(ce=c.state.buttonElement)==null||ce.focus({preventScroll:!0})):(G.preventDefault(),c.actions.openListbox({focus:we.Nothing}))}),P=xe(G=>G.preventDefault()),M=Jo([f]),A=fm(),{isFocusVisible:H,focusProps:q}=wu({autoFocus:h}),{isHovered:ee,hoverProps:he}=xu({isDisabled:p}),{pressed:J,pressProps:Q}=Jp({disabled:p}),z=kt({open:w===et.Open,active:J||w===et.Open,disabled:p,invalid:a.invalid,value:a.value,hover:ee,focus:H,autofocus:h}),ae=je(c,G=>G.listboxState===et.Open),ue=qo(E(),{ref:x,id:f,type:$m(n,b),"aria-haspopup":"listbox","aria-controls":S?.id,"aria-expanded":ae,"aria-labelledby":M,"aria-describedby":A,disabled:p||void 0,autoFocus:h,onKeyDown:j,onKeyUp:I,onKeyPress:P},L,q,he,Q);return rt()({ourProps:ue,theirProps:v,slot:z,defaultTag:Z1,name:"Listbox.Button"})}let xh=y.createContext(!1),tw="div",nw=Bo.RenderStrategy|Bo.Static;function rw(n,l){let o=y.useId(),{id:s=`headlessui-listbox-options-${o}`,anchor:a,portal:c=!1,modal:f=!0,transition:p=!1,...h}=n,v=Zm(a),[x,E]=y.useState(null);v&&(c=!0);let w=rl("Listbox.Options"),b=Du("Listbox.Options"),[S,C,j,I]=je(b,U=>[U.listboxState,U.buttonElement,U.optionsElement,U.__demoMode]),L=Uo(C),P=Uo(j),M=lh(),[A,H]=Im(p,x,M!==null?(M&dn.Open)===dn.Open:S===et.Open);Cm(A,C,b.actions.closeListbox);let q=I?!1:f&&S===et.Open;Mm(q,P);let ee=I?!1:f&&S===et.Open;km(ee,{allowed:y.useCallback(()=>[C,j],[C,j])});let he=je(b,b.selectors.didButtonMove)?!1:A,J=je(b,b.selectors.hasFrozenValue)&&!n.static,Q=$i(J,w.value),z=y.useCallback(U=>w.compare(Q,U),[w.compare,Q]),ae=je(b,U=>{var me;if(v==null||!((me=v?.to)!=null&&me.includes("selection")))return null;let ie=U.options.findIndex(Ee=>z(Ee.dataRef.current.value));return ie===-1&&(ie=0),ie}),ue=(()=>{if(v==null)return;if(ae===null)return{...v,inner:void 0};let U=Array.from(w.listRef.current.values());return{...v,inner:{listRef:{current:U},index:ae}}})(),[G,ce]=nh(ue),ve=th(),D=vt(l,v?G:null,b.actions.setOptionsElement,E),X=cr();y.useEffect(()=>{let U=j;U&&S===et.Open&&(bu(U)||U==null||U.focus({preventScroll:!0}))},[S,j]);let K=xe(U=>{var me;switch(X.dispose(),U.key){case Ne.Space:if(b.state.searchQuery!=="")return U.preventDefault(),U.stopPropagation(),b.actions.search(U.key);case Ne.Enter:U.preventDefault(),U.stopPropagation(),b.actions.selectActiveOption();break;case tt(w.orientation,{vertical:Ne.ArrowDown,horizontal:Ne.ArrowRight}):return U.preventDefault(),U.stopPropagation(),b.actions.goToOption({focus:we.Next});case tt(w.orientation,{vertical:Ne.ArrowUp,horizontal:Ne.ArrowLeft}):return U.preventDefault(),U.stopPropagation(),b.actions.goToOption({focus:we.Previous});case Ne.Home:case Ne.PageUp:return U.preventDefault(),U.stopPropagation(),b.actions.goToOption({focus:we.First});case Ne.End:case Ne.PageDown:return U.preventDefault(),U.stopPropagation(),b.actions.goToOption({focus:we.Last});case Ne.Escape:U.preventDefault(),U.stopPropagation(),Ye.flushSync(()=>b.actions.closeListbox()),(me=b.state.buttonElement)==null||me.focus({preventScroll:!0});return;case Ne.Tab:U.preventDefault(),U.stopPropagation(),Ye.flushSync(()=>b.actions.closeListbox()),Ny(b.state.buttonElement,U.shiftKey?fu.Previous:fu.Next);break;default:U.key.length===1&&(b.actions.search(U.key),X.setTimeout(()=>b.actions.clearSearch(),350));break}}),T=je(b,U=>{var me;return(me=U.buttonElement)==null?void 0:me.id}),R=kt({open:S===et.Open}),re=qo(v?ve():{},{id:s,ref:D,"aria-activedescendant":je(b,b.selectors.activeDescendantId),"aria-multiselectable":w.mode===Mn.Multi?!0:void 0,"aria-labelledby":T,"aria-orientation":w.orientation,onKeyDown:K,role:"listbox",tabIndex:S===et.Open?0:void 0,style:{...h.style,...ce,"--button-width":cu(A,C,!0).width},...Lm(H)}),le=rt(),pe=y.useMemo(()=>w.mode===Mn.Multi?w:{...w,isSelected:z},[w,z]);return ye.createElement(uh,{enabled:c?n.static||A:!1,ownerDocument:L},ye.createElement(Hi.Provider,{value:pe},le({ourProps:re,theirProps:h,slot:R,defaultTag:tw,features:nw,visible:he,name:"Listbox.Options"})))}let ow="div";function lw(n,l){let o=y.useId(),{id:s=`headlessui-listbox-option-${o}`,disabled:a=!1,value:c,...f}=n,p=y.useContext(xh)===!0,h=rl("Listbox.Option"),v=Du("Listbox.Option"),x=je(v,J=>v.selectors.isActive(J,s)),E=h.isSelected(c),w=y.useRef(null),b=Q1(w),S=Dn({disabled:a,value:c,domRef:w,get textValue(){return b()}}),C=vt(l,w,J=>{J?h.listRef.current.set(s,J):h.listRef.current.delete(s)}),j=je(v,J=>v.selectors.shouldScrollIntoView(J,s));Le(()=>{if(j)return gt().requestAnimationFrame(()=>{var J,Q;(Q=(J=w.current)==null?void 0:J.scrollIntoView)==null||Q.call(J,{block:"nearest"})})},[j,w]),Le(()=>{if(!p)return v.actions.registerOption(s,S),()=>v.actions.unregisterOption(s)},[S,s,p]);let I=xe(J=>{if(a)return J.preventDefault();v.actions.selectOption(c)}),L=xe(()=>{if(a)return v.actions.goToOption({focus:we.Nothing});v.actions.goToOption({focus:we.Specific,id:s})}),P=_m(),M=xe(J=>P.update(J)),A=xe(J=>{P.wasMoved(J)&&(a||x&&v.state.activationTrigger===bi.Pointer||v.actions.goToOption({focus:we.Specific,id:s},bi.Pointer))}),H=xe(J=>{P.wasMoved(J)&&(a||x&&v.state.activationTrigger===bi.Pointer&&v.actions.goToOption({focus:we.Nothing}))}),q=kt({active:x,focus:x,selected:E,disabled:a,selectedOption:E&&p}),ee=p?{}:{id:s,ref:C,role:"option",tabIndex:a===!0?void 0:-1,"aria-disabled":a===!0?!0:void 0,"aria-selected":E,disabled:void 0,onClick:I,onFocus:L,onPointerEnter:M,onMouseEnter:M,onPointerMove:A,onMouseMove:A,onPointerLeave:H,onMouseLeave:H},he=rt();return!E&&p?null:he({ourProps:ee,theirProps:f,slot:q,defaultTag:ow,name:"Listbox.Option"})}let iw=y.Fragment;function sw(n,l){let{options:o,placeholder:s,...a}=n,c={ref:vt(l)},f=rl("ListboxSelectedOption"),p=kt({}),h=f.value===void 0||f.value===null||f.mode===Mn.Multi&&Array.isArray(f.value)&&f.value.length===0,v=rt();return ye.createElement(xh.Provider,{value:!0},v({ourProps:c,theirProps:{...a,children:ye.createElement(ye.Fragment,null,s&&h?s:o)},slot:p,defaultTag:iw,name:"ListboxSelectedOption"}))}let aw=ot(J1),uw=ot(ew),cw=hm,dw=ot(rw),fw=ot(lw),pw=ot(sw),an=Object.assign(aw,{Button:uw,Label:cw,Options:dw,Option:fw,SelectedOption:pw});const yi=43200,Ip=1440,Fp=Symbol.for("constructDateFrom");function Au(n,l){return typeof n=="function"?n(l):n&&typeof n=="object"&&Fp in n?n[Fp](l):n instanceof Date?new n.constructor(l):new Date(l)}function In(n,l){return Au(n,n)}let mw={};function hw(){return mw}function Dp(n){const l=In(n),o=new Date(Date.UTC(l.getFullYear(),l.getMonth(),l.getDate(),l.getHours(),l.getMinutes(),l.getSeconds(),l.getMilliseconds()));return o.setUTCFullYear(l.getFullYear()),+n-+o}function zu(n,...l){const o=Au.bind(null,n||l.find(s=>typeof s=="object"));return l.map(o)}function Si(n,l){const o=+In(n)-+In(l);return o<0?-1:o>0?1:o}function gw(n){return Au(n,Date.now())}function vw(n,l,o){const[s,a]=zu(o?.in,n,l),c=s.getFullYear()-a.getFullYear(),f=s.getMonth()-a.getMonth();return c*12+f}function yw(n){return l=>{const s=(n?Math[n]:Math.trunc)(l);return s===0?0:s}}function xw(n,l){return+In(n)-+In(l)}function ww(n,l){const o=In(n);return o.setHours(23,59,59,999),o}function bw(n,l){const o=In(n),s=o.getMonth();return o.setFullYear(o.getFullYear(),s+1,0),o.setHours(23,59,59,999),o}function Sw(n,l){const o=In(n);return+ww(o)==+bw(o)}function Ew(n,l,o){const[s,a,c]=zu(o?.in,n,n,l),f=Si(a,c),p=Math.abs(vw(a,c));if(p<1)return 0;a.getMonth()===1&&a.getDate()>27&&a.setDate(30),a.setMonth(a.getMonth()-f*p);let h=Si(a,c)===-f;Sw(s)&&p===1&&Si(s,c)===1&&(h=!1);const v=f*(p-+h);return v===0?0:v}function kw(n,l,o){const s=xw(n,l)/1e3;return yw(o?.roundingMethod)(s)}const Cw={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}},Nw=(n,l,o)=>{let s;const a=Cw[n];return typeof a=="string"?s=a:l===1?s=a.one:s=a.other.replace("{{count}}",l.toString()),o?.addSuffix?o.comparison&&o.comparison>0?"in "+s:s+" ago":s};function tu(n){return(l={})=>{const o=l.width?String(l.width):n.defaultWidth;return n.formats[o]||n.formats[n.defaultWidth]}}const jw={full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},Ow={full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},Pw={full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},Tw={date:tu({formats:jw,defaultWidth:"full"}),time:tu({formats:Ow,defaultWidth:"full"}),dateTime:tu({formats:Pw,defaultWidth:"full"})},Rw={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"},$w=(n,l,o,s)=>Rw[n];function Fo(n){return(l,o)=>{const s=o?.context?String(o.context):"standalone";let a;if(s==="formatting"&&n.formattingValues){const f=n.defaultFormattingWidth||n.defaultWidth,p=o?.width?String(o.width):f;a=n.formattingValues[p]||n.formattingValues[f]}else{const f=n.defaultWidth,p=o?.width?String(o.width):n.defaultWidth;a=n.values[p]||n.values[f]}const c=n.argumentCallback?n.argumentCallback(l):l;return a[c]}}const Mw={narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},_w={narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},Lw={narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},Iw={narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},Fw={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},Dw={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},Aw=(n,l)=>{const o=Number(n),s=o%100;if(s>20||s<10)switch(s%10){case 1:return o+"st";case 2:return o+"nd";case 3:return o+"rd"}return o+"th"},zw={ordinalNumber:Aw,era:Fo({values:Mw,defaultWidth:"wide"}),quarter:Fo({values:_w,defaultWidth:"wide",argumentCallback:n=>n-1}),month:Fo({values:Lw,defaultWidth:"wide"}),day:Fo({values:Iw,defaultWidth:"wide"}),dayPeriod:Fo({values:Fw,defaultWidth:"wide",formattingValues:Dw,defaultFormattingWidth:"wide"})};function Do(n){return(l,o={})=>{const s=o.width,a=s&&n.matchPatterns[s]||n.matchPatterns[n.defaultMatchWidth],c=l.match(a);if(!c)return null;const f=c[0],p=s&&n.parsePatterns[s]||n.parsePatterns[n.defaultParseWidth],h=Array.isArray(p)?Hw(p,E=>E.test(f)):Ww(p,E=>E.test(f));let v;v=n.valueCallback?n.valueCallback(h):h,v=o.valueCallback?o.valueCallback(v):v;const x=l.slice(f.length);return{value:v,rest:x}}}function Ww(n,l){for(const o in n)if(Object.prototype.hasOwnProperty.call(n,o)&&l(n[o]))return o}function Hw(n,l){for(let o=0;o{const s=l.match(n.matchPattern);if(!s)return null;const a=s[0],c=l.match(n.parsePattern);if(!c)return null;let f=n.valueCallback?n.valueCallback(c[0]):c[0];f=o.valueCallback?o.valueCallback(f):f;const p=l.slice(a.length);return{value:f,rest:p}}}const Bw=/^(\d+)(th|st|nd|rd)?/i,Uw=/\d+/i,Kw={narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},Qw={any:[/^b/i,/^(a|c)/i]},Yw={narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},Xw={any:[/1/i,/2/i,/3/i,/4/i]},Gw={narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},qw={narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},Jw={narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},Zw={narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},eb={narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},tb={any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},nb={ordinalNumber:Vw({matchPattern:Bw,parsePattern:Uw,valueCallback:n=>parseInt(n,10)}),era:Do({matchPatterns:Kw,defaultMatchWidth:"wide",parsePatterns:Qw,defaultParseWidth:"any"}),quarter:Do({matchPatterns:Yw,defaultMatchWidth:"wide",parsePatterns:Xw,defaultParseWidth:"any",valueCallback:n=>n+1}),month:Do({matchPatterns:Gw,defaultMatchWidth:"wide",parsePatterns:qw,defaultParseWidth:"any"}),day:Do({matchPatterns:Jw,defaultMatchWidth:"wide",parsePatterns:Zw,defaultParseWidth:"any"}),dayPeriod:Do({matchPatterns:eb,defaultMatchWidth:"any",parsePatterns:tb,defaultParseWidth:"any"})},rb={code:"en-US",formatDistance:Nw,formatLong:Tw,formatRelative:$w,localize:zw,match:nb,options:{weekStartsOn:0,firstWeekContainsDate:1}};function ob(n,l,o){const s=hw(),a=o?.locale??s.locale??rb,c=2520,f=Si(n,l);if(isNaN(f))throw new RangeError("Invalid time value");const p=Object.assign({},o,{addSuffix:o?.addSuffix,comparison:f}),[h,v]=zu(o?.in,...f>0?[l,n]:[n,l]),x=kw(v,h),E=(Dp(v)-Dp(h))/1e3,w=Math.round((x-E)/60);let b;if(w<2)return o?.includeSeconds?x<5?a.formatDistance("lessThanXSeconds",5,p):x<10?a.formatDistance("lessThanXSeconds",10,p):x<20?a.formatDistance("lessThanXSeconds",20,p):x<40?a.formatDistance("halfAMinute",0,p):x<60?a.formatDistance("lessThanXMinutes",1,p):a.formatDistance("xMinutes",1,p):w===0?a.formatDistance("lessThanXMinutes",1,p):a.formatDistance("xMinutes",w,p);if(w<45)return a.formatDistance("xMinutes",w,p);if(w<90)return a.formatDistance("aboutXHours",1,p);if(w{zp().then(Q=>s(Q.object_defs.map(z=>z.name))).catch(()=>{})},[]),y.useEffect(()=>{v(!0),ou(a||void 0,w,S).then(Q=>{l(Q.objects),E(Q.total)}).catch(Q=>p(Q.message)).finally(()=>v(!1))},[a,w,S]);const ee=Q=>{c(Q),C(0)},he=()=>{v(!0),ou(a||void 0,w,S).then(Q=>{l(Q.objects),E(Q.total)}).catch(Q=>p(Q.message)).finally(()=>v(!1))},J=async()=>{if(L){A(!0),q(null);try{const Q=await $0(L);q({ok:!0,text:`Created object #${Q.id} (${Q.type})`}),I(!1),P(""),he(),setTimeout(()=>q(null),3e3)}catch(Q){q({ok:!1,text:Q.message||"Failed to create object"})}finally{A(!1)}}};return h?m.jsx($t,{}):f?m.jsxs("div",{className:"text-red-500",children:["Error: ",f]}):m.jsxs("div",{className:"max-w-6xl mx-auto",children:[m.jsxs("div",{className:"flex items-center justify-between mb-6",children:[m.jsxs("div",{className:"flex items-center gap-3",children:[m.jsx("h2",{className:"text-2xl font-bold",children:"Objects"}),j?m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("select",{value:L,onChange:Q=>P(Q.target.value),className:"px-3 py-1.5 bg-gray-800 border border-gray-700 rounded-lg text-sm text-gray-100 focus:border-blue-500 focus:outline-none",children:o.map(Q=>m.jsx("option",{value:Q,children:Q},Q))}),m.jsx("button",{onClick:J,disabled:M||!L,className:"px-3 py-1.5 bg-blue-600 hover:bg-blue-500 disabled:bg-gray-700 text-white text-sm rounded-lg transition-colors",children:M?"...":"✓"}),m.jsx("button",{onClick:()=>{I(!1),q(null)},className:"px-3 py-1.5 bg-gray-700 hover:bg-gray-600 text-gray-300 text-sm rounded-lg transition-colors",children:"✕"})]}):m.jsx("button",{onClick:()=>{I(!0),P(o[0]||"")},className:"px-3 py-1.5 bg-green-600 hover:bg-green-500 text-white text-sm rounded-lg transition-colors",disabled:o.length===0,children:"+ Create"}),H&&m.jsx("span",{className:`text-sm ${H.ok?"text-green-400":"text-red-400"}`,children:H.text})]}),m.jsx(an,{value:a,onChange:ee,children:m.jsxs("div",{className:"relative w-64",children:[m.jsxs(an.Button,{className:"w-full px-4 py-2 bg-gray-800 border border-gray-700 rounded-lg text-left focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-all",children:[m.jsx("span",{className:a?"text-gray-100":"text-gray-500",children:a||"All Types"}),m.jsx("span",{className:"absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none",children:m.jsx("svg",{className:"h-5 w-5 text-gray-400",viewBox:"0 0 20 20",fill:"currentColor",children:m.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 01.707.293l3 3a1 1 0 01-1.414 1.414L10 5.414 7.707 7.707a1 1 0 01-1.414-1.414l3-3A1 1 0 0110 3zm-3.707 9.293a1 1 0 011.414 0L10 14.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z",clipRule:"evenodd"})})})]}),m.jsxs(an.Options,{className:"absolute z-10 mt-1 w-full bg-gray-800 border border-gray-700 rounded-lg shadow-lg max-h-60 overflow-auto focus:outline-none",children:[m.jsx(an.Option,{value:"",className:({active:Q})=>`cursor-pointer select-none px-4 py-2 transition-colors ${Q?"bg-blue-600 text-white":"text-gray-100"}`,children:({selected:Q})=>m.jsx("span",{className:Q?"font-semibold":"font-normal",children:"All Types"})}),o.map(Q=>m.jsx(an.Option,{value:Q,className:({active:z})=>`cursor-pointer select-none px-4 py-2 transition-colors ${z?"bg-blue-600 text-white":"text-gray-100"}`,children:({selected:z})=>m.jsx("span",{className:z?"font-semibold":"font-normal",children:Q})},Q))]})]})})]}),m.jsxs("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg overflow-hidden border border-gray-800",children:[n.length===0?m.jsx(fn,{message:"No objects found"}):m.jsxs("table",{className:"w-full",children:[m.jsx("thead",{className:"bg-gray-800/80 border-b border-gray-700",children:m.jsxs("tr",{children:[m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"ID"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Type"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Created"})]})}),m.jsx("tbody",{className:"divide-y divide-gray-800",children:n.map((Q,z)=>m.jsxs("tr",{className:`transition-colors ${z%2===0?"bg-gray-900/30":"bg-gray-850/30"} hover:bg-gray-800/60`,children:[m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:Q.id}),m.jsx("td",{className:"px-4 py-3 text-gray-100",children:m.jsx("span",{className:"inline-block px-2 py-1 bg-blue-900/30 text-blue-300 rounded text-sm",children:Q.type})}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:ur(Q.created_at)})]},z))})]}),m.jsx(Vr,{total:x,limit:w,offset:S,onPageChange:C,onLimitChange:b})]})]})}function sb({eventDef:n,onClose:l,onSuccess:o}){const s=n.schema?.properties||{},a=Object.keys(s),[c,f]=y.useState(()=>{const C={};for(const[j,I]of Object.entries(s))I.type==="boolean"?C[j]=!1:(I.type==="number"||I.type,C[j]="");return C}),[p,h]=y.useState(!1),[v,x]=y.useState(""),[E,w]=y.useState(null),b=async C=>{C.preventDefault(),h(!0),x(""),w(null);try{const j={};for(const[L,P]of Object.entries(s)){const M=c[L];P.type==="number"||P.type==="ref"?j[L]=M===""?0:Number(M):P.type==="boolean"?j[L]=!!M:j[L]=String(M)}const I=await z0(n.name,j);w({eventId:I.event?.id??"?",reactionsFired:I.reactions_fired??0}),setTimeout(()=>{o(),l()},2e3)}catch(j){x(j.message||"Failed to emit event")}finally{h(!1)}},S=(C,j)=>{if(j.type==="boolean")return m.jsxs("label",{className:"flex items-center gap-3 py-2",children:[m.jsx("input",{type:"checkbox",checked:!!c[C],onChange:P=>f(M=>({...M,[C]:P.target.checked})),className:"w-4 h-4 rounded border-gray-600 bg-gray-800 text-blue-500 focus:ring-blue-500 focus:ring-offset-0"}),m.jsx("span",{className:"text-sm text-gray-200 font-mono",children:C})]},C);const I=j.type==="number"||j.type==="ref",L=j.type==="ref"?`${C} (Object ID)`:C;return m.jsxs("div",{className:"space-y-1",children:[m.jsx("label",{className:"block text-sm text-gray-300 font-mono",children:L}),m.jsx("input",{type:I?"number":"text",value:c[C],onChange:P=>f(M=>({...M,[C]:P.target.value})),className:"w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-gray-100 text-sm font-mono placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:j.type==="ref"?"Enter object ID":`Enter ${j.type}`})]},C)};return m.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:l,children:m.jsxs("div",{className:"bg-gray-900 border border-gray-700 rounded-xl shadow-2xl w-full max-w-md mx-4",onClick:C=>C.stopPropagation(),children:[m.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-800",children:[m.jsxs("h3",{className:"text-lg font-semibold text-gray-100",children:["Emit ",m.jsx("span",{className:"text-blue-400 font-mono",children:n.name})]}),m.jsx("button",{onClick:l,className:"text-gray-400 hover:text-gray-200 transition-colors",children:m.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:m.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),m.jsxs("form",{onSubmit:b,className:"px-6 py-4 space-y-4",children:[a.length===0?m.jsx("p",{className:"text-sm text-gray-500 italic",children:"No payload fields — event will be emitted with empty payload."}):a.map(C=>S(C,s[C])),E&&m.jsxs("div",{className:"p-3 bg-green-900/40 border border-green-700 rounded-lg text-sm text-green-300",children:["✓ Event ",m.jsx("span",{className:"font-mono font-bold",children:E.eventId})," emitted",E.reactionsFired>0&&m.jsxs("span",{children:[" — ",E.reactionsFired," reaction",E.reactionsFired>1?"s":""," fired"]})]}),v&&m.jsxs("div",{className:"p-3 bg-red-900/40 border border-red-700 rounded-lg text-sm text-red-300",children:["✗ ",v]}),m.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[m.jsx("button",{type:"button",onClick:l,className:"px-4 py-2 text-sm text-gray-400 hover:text-gray-200 transition-colors",children:"Cancel"}),m.jsxs("button",{type:"submit",disabled:p||!!E,className:"px-4 py-2 bg-blue-600 hover:bg-blue-500 disabled:bg-blue-800 disabled:cursor-not-allowed text-white text-sm font-medium rounded-lg transition-colors flex items-center gap-2",children:[p&&m.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-white/30 border-t-white"}),p?"Emitting…":"▶ Emit"]})]})]})]})})}function ab(){const[n,l]=y.useState([]),[o,s]=y.useState(new Set),[a,c]=y.useState(""),[f,p]=y.useState(!0),[h,v]=y.useState(null),x=()=>{p(!0),M0().then(w=>l(w.event_defs)).catch(w=>c(w.message)).finally(()=>p(!1))};y.useEffect(()=>{x()},[]);const E=w=>{s(b=>{const S=new Set(b);return S.has(w)?S.delete(w):S.add(w),S})};return f?m.jsx($t,{}):a?m.jsxs("div",{className:"text-red-500 text-center p-8",children:["Error: ",a]}):m.jsxs("div",{className:"max-w-6xl mx-auto",children:[m.jsx("h2",{className:"text-2xl font-bold mb-6",children:"Event Definitions"}),m.jsx("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg overflow-hidden border border-gray-800",children:n.length===0?m.jsx(fn,{message:"No event definitions found"}):m.jsxs("table",{className:"w-full",children:[m.jsx("thead",{className:"bg-gray-800/80 border-b border-gray-700",children:m.jsxs("tr",{children:[m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Name"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Hash"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Parent"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Schema"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Actions"})]})}),m.jsx("tbody",{className:"divide-y divide-gray-800",children:n.map((w,b)=>m.jsxs("tr",{className:`transition-colors ${b%2===0?"bg-gray-900/30":"bg-gray-850/30"} hover:bg-gray-800/60`,children:[m.jsx("td",{className:"px-4 py-3 font-mono text-gray-100",children:w.name}),m.jsx("td",{className:"px-4 py-3",children:m.jsx(lr,{hash:w.hash})}),m.jsx("td",{className:"px-4 py-3",children:w.parent_hash?m.jsx(lr,{hash:w.parent_hash}):m.jsx("span",{className:"text-gray-600",children:"-"})}),m.jsxs("td",{className:"px-4 py-3",children:[m.jsx("button",{onClick:()=>E(w.hash),className:"text-blue-400 hover:text-blue-300 text-sm font-medium transition-colors",children:o.has(w.hash)?"Hide":"Show"}),o.has(w.hash)&&m.jsx("pre",{className:"mt-2 p-3 bg-gray-950 rounded-lg text-xs overflow-x-auto border border-gray-800",children:JSON.stringify(w.schema,null,2).split(` `).map((S,C)=>{if(S.includes(":")){const[j,...I]=S.split(":");return m.jsxs("div",{children:[m.jsxs("span",{className:"text-blue-400",children:[j,":"]}),m.jsx("span",{className:"text-green-300",children:I.join(":")})]},C)}return m.jsx("div",{className:"text-gray-300",children:S},C)})})]}),m.jsx("td",{className:"px-4 py-3",children:m.jsx("button",{onClick:()=>v({name:w.name,schema:w.schema}),className:"px-3 py-1.5 bg-green-700/30 hover:bg-green-600/40 text-green-300 hover:text-green-200 border border-green-700/50 rounded-lg text-sm font-medium transition-colors",children:"▶ Emit"})})]},b))})]})}),h&&m.jsx(sb,{eventDef:h,onClose:()=>v(null),onSuccess:()=>{}})]})}function ub(){const[n,l]=y.useState([]),[o,s]=y.useState(new Set),[a,c]=y.useState(""),[f,p]=y.useState(""),[h,v]=y.useState(!0),[x,E]=y.useState(0),[w,b]=y.useState(50),[S,C]=y.useState(0),j=()=>{v(!0),_0(a||void 0,w,S).then(P=>{l(P.events),E(P.total)}).catch(P=>p(P.message)).finally(()=>v(!1))};y.useEffect(()=>{j()},[w,S]);const I=()=>{C(0),j()},L=P=>{s(M=>{const A=new Set(M);return A.has(P)?A.delete(P):A.add(P),A})};return h?m.jsx($t,{}):f?m.jsxs("div",{className:"text-red-500",children:["Error: ",f]}):m.jsxs("div",{className:"max-w-6xl mx-auto",children:[m.jsxs("div",{className:"flex items-center justify-between mb-6",children:[m.jsx("h2",{className:"text-2xl font-bold",children:"Events"}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx("input",{type:"text",className:"px-4 py-2 bg-gray-800 border border-gray-700 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-all",placeholder:"Filter by ref...",value:a,onChange:P=>c(P.target.value)}),m.jsx("button",{onClick:I,className:"px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded-lg font-semibold transition-all shadow-lg shadow-blue-500/20 hover:shadow-blue-500/40",children:"Search"})]})]}),m.jsxs("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg overflow-hidden border border-gray-800",children:[n.length===0?m.jsx(fn,{message:"No events yet"}):m.jsxs("table",{className:"w-full",children:[m.jsx("thead",{className:"bg-gray-800/80 border-b border-gray-700",children:m.jsxs("tr",{children:[m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"ID"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Type Hash"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Created"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Payload"})]})}),m.jsx("tbody",{className:"divide-y divide-gray-800",children:n.map((P,M)=>m.jsxs("tr",{className:`transition-colors ${M%2===0?"bg-gray-900/30":"bg-gray-850/30"} hover:bg-gray-800/60`,children:[m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:P.id}),m.jsx("td",{className:"px-4 py-3",children:m.jsx(lr,{hash:P.type_hash})}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:ur(P.created_at)}),m.jsxs("td",{className:"px-4 py-3",children:[m.jsx("button",{onClick:()=>L(P.id),className:"text-blue-400 hover:text-blue-300 text-sm font-medium transition-colors",children:o.has(P.id)?"Hide":"Show"}),o.has(P.id)&&m.jsx("pre",{className:"mt-2 p-3 bg-gray-950 rounded-lg text-xs overflow-x-auto border border-gray-800",children:JSON.stringify(P.payload,null,2).split(` `).map((A,H)=>{if(A.includes(":")){const[q,...ee]=A.split(":");return m.jsxs("div",{children:[m.jsxs("span",{className:"text-blue-400",children:[q,":"]}),m.jsx("span",{className:"text-green-300",children:ee.join(":")})]},H)}return m.jsx("div",{className:"text-gray-300",children:A},H)})})]})]},M))})]}),m.jsx(Vr,{total:x,limit:w,offset:S,onPageChange:C,onLimitChange:b})]})]})}function cb(){const[n,l]=y.useState([]),[o,s]=y.useState(new Set),[a,c]=y.useState(""),[f,p]=y.useState(!0);y.useEffect(()=>{Wp().then(v=>l(v.projection_defs)).catch(v=>c(v.message)).finally(()=>p(!1))},[]);const h=v=>{s(x=>{const E=new Set(x);return E.has(v)?E.delete(v):E.add(v),E})};return f?m.jsx($t,{}):a?m.jsxs("div",{className:"text-red-500 text-center p-8",children:["Error: ",a]}):m.jsxs("div",{className:"max-w-5xl mx-auto",children:[m.jsx("h2",{className:"text-2xl font-bold mb-6",children:"Projection Definitions"}),n.length===0?m.jsx(fn,{message:"No projection definitions found"}):m.jsx("div",{className:"space-y-4",children:n.map((v,x)=>m.jsxs("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg p-5 border border-gray-800 hover:border-gray-700 transition-colors",children:[m.jsxs("div",{className:"flex items-start justify-between mb-3",children:[m.jsxs("div",{children:[m.jsx("h3",{className:"font-mono text-lg text-gray-100",children:v.name}),m.jsx("div",{className:"mt-1",children:m.jsx(lr,{hash:v.hash||"unknown",short:!1})})]}),m.jsx("button",{onClick:()=>h(v.hash||x),className:"text-blue-400 hover:text-blue-300 text-sm font-medium transition-colors",children:o.has(v.hash||x)?"Hide Details":"Show Details"})]}),o.has(v.hash||x)&&m.jsxs("div",{className:"mt-4 space-y-3 text-sm bg-gray-800/30 rounded-lg p-4 border border-gray-700/50",children:[v.sources&&m.jsxs("div",{children:[m.jsx("span",{className:"text-gray-400 font-medium",children:"Sources:"}),m.jsx("div",{className:"mt-2 space-y-3",children:v.sources.map((E,w)=>m.jsxs("div",{className:"pl-3 border-l-2 border-gray-600",children:[m.jsx("div",{className:"text-gray-200 font-mono text-xs",children:E.event_def_hash}),m.jsxs("div",{className:"mt-1",children:[m.jsx("span",{className:"text-gray-500 text-xs",children:"bindings:"})," ",m.jsx("span",{className:"text-yellow-400 text-xs",children:JSON.stringify(E.bindings)})]}),m.jsxs("div",{className:"mt-0.5",children:[m.jsx("span",{className:"text-gray-500 text-xs",children:"expression:"})," ",m.jsx("code",{className:"text-green-400 text-xs",children:E.expression})]})]},w))})]}),v.params&&m.jsxs("div",{children:[m.jsx("span",{className:"text-gray-400 font-medium",children:"Params:"}),m.jsx("pre",{className:"mt-1.5 p-3 bg-gray-950 rounded-lg text-xs overflow-x-auto border border-gray-800",children:JSON.stringify(v.params,null,2).split(` -`).map((E,w)=>{if(E.includes(":")){const[b,...S]=E.split(":");return m.jsxs("div",{children:[m.jsxs("span",{className:"text-blue-400",children:[b,":"]}),m.jsx("span",{className:"text-green-300",children:S.join(":")})]},w)}return m.jsx("div",{className:"text-gray-300",children:E},w)})})]}),v.value_schema&&m.jsxs("div",{children:[m.jsx("span",{className:"text-gray-400 font-medium",children:"Value Schema:"}),m.jsx("pre",{className:"mt-1.5 p-3 bg-gray-950 rounded-lg text-xs overflow-x-auto border border-gray-800 text-purple-300",children:JSON.stringify(v.value_schema,null,2)})]}),v.initial_value!==void 0&&m.jsxs("div",{children:[m.jsx("span",{className:"text-gray-400 font-medium",children:"Initial Value:"}),m.jsx("pre",{className:"mt-1.5 p-3 bg-gray-950 rounded-lg text-xs overflow-x-auto border border-gray-800 text-blue-300",children:JSON.stringify(v.initial_value,null,2)})]})]})]},x))})]})}function db(){const[n,l]=y.useState([]),[o,s]=y.useState(null),[a,c]=y.useState({}),[f,p]=y.useState([]),[h,v]=y.useState(null),[x,E]=y.useState(""),[w,b]=y.useState(!1),[S,C]=y.useState(!0);y.useEffect(()=>{Promise.all([Wp(),ou()]).then(([P,M])=>{l(P.projection_defs),p(M.objects.map(A=>({...A,id:String(A.id)})))}).catch(()=>{}).finally(()=>C(!1))},[]);const j=P=>{if(s(P),v(null),E(""),P){const M={};for(const A of Object.keys(P.params))M[A]="";c(M)}else c({})},I=async()=>{if(!o)return;b(!0),E(""),v(null);const P=new URLSearchParams;for(const[M,A]of Object.entries(a))A.trim()&&P.set(M,A.trim());try{const M=await nt(`/projections/${o.name}?${P.toString()}`);v(M.value)}catch(M){E(M.message)}finally{b(!1)}},L=y.useMemo(()=>{const P={};for(const M of f)P[M.type]||(P[M.type]=[]),P[M.type].push(String(M.id));return P},[f]);return S?m.jsx($t,{}):m.jsxs("div",{className:"max-w-4xl mx-auto",children:[m.jsx("h2",{className:"text-2xl font-bold mb-6",children:"Query Projections"}),m.jsxs("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg p-6 space-y-6 border border-gray-800",children:[m.jsxs("div",{children:[m.jsx("label",{className:"block text-sm font-medium text-gray-400 mb-2",children:"Projection"}),m.jsx(an,{value:o,onChange:j,children:m.jsxs("div",{className:"relative",children:[m.jsxs(an.Button,{className:"w-full px-4 py-2.5 bg-gray-800 border border-gray-700 rounded-lg text-left focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-all",children:[m.jsx("span",{className:o?"text-gray-100":"text-gray-500",children:o?.name||"Select a projection..."}),m.jsx("span",{className:"absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none",children:m.jsx("svg",{className:"h-5 w-5 text-gray-400",viewBox:"0 0 20 20",fill:"currentColor",children:m.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 01.707.293l3 3a1 1 0 01-1.414 1.414L10 5.414 7.707 7.707a1 1 0 01-1.414-1.414l3-3A1 1 0 0110 3zm-3.707 9.293a1 1 0 011.414 0L10 14.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z",clipRule:"evenodd"})})})]}),m.jsx(an.Options,{className:"absolute z-10 mt-1 w-full bg-gray-800 border border-gray-700 rounded-lg shadow-lg max-h-60 overflow-auto focus:outline-none",children:n.map(P=>m.jsx(an.Option,{value:P,className:({active:M})=>`cursor-pointer select-none px-4 py-2.5 transition-colors ${M?"bg-blue-600 text-white":"text-gray-100"}`,children:({selected:M})=>m.jsx("span",{className:M?"font-semibold":"font-normal",children:P.name})},P.name))})]})})]}),o&&m.jsxs("div",{className:"space-y-4",children:[m.jsxs("div",{className:"flex items-baseline gap-2",children:[m.jsx("label",{className:"block text-sm font-medium text-gray-400",children:"Parameters"}),m.jsxs("span",{className:"text-xs text-gray-600",children:["→ ",o.value_schema?.type||"any",o.initial_value!==void 0&&m.jsxs("span",{className:"ml-1",children:["(initial: ",JSON.stringify(o.initial_value),")"]})]})]}),m.jsx("div",{className:"space-y-3 bg-gray-800/30 rounded-lg p-4 border border-gray-700/50",children:Object.entries(o.params).map(([P,M])=>m.jsxs("div",{children:[m.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1.5",children:[P,m.jsxs("span",{className:"ml-2 px-1.5 py-0.5 bg-gray-700 rounded text-xs text-gray-400",children:[M.type,M.object_type?` → ${M.object_type}`:""]})]}),M.type==="ref"?m.jsx(fb,{value:a[P]||"",onChange:A=>c({...a,[P]:A}),objects:f,objectsByType:L,objectType:M.object_type}):m.jsx("input",{type:M.type==="number"?"number":"text",className:"w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-all",placeholder:`Enter ${M.type} value...`,value:a[P]||"",onChange:A=>c({...a,[P]:A.target.value})})]},P))})]}),o&&m.jsx("div",{className:"text-xs space-y-2 bg-gray-800/20 rounded-lg p-4 border border-gray-700/30",children:m.jsxs("div",{children:[m.jsx("span",{className:"text-gray-500 font-medium",children:"sources:"}),m.jsx("div",{className:"mt-1 space-y-2",children:o.sources?.map((P,M)=>m.jsxs("div",{className:"pl-3 border-l border-gray-700",children:[m.jsx("div",{className:"flex items-center gap-2",children:m.jsx(lr,{hash:P.event_def_hash,short:!1})}),m.jsxs("div",{className:"text-xs mt-1",children:[m.jsx("span",{className:"text-gray-500",children:"bindings:"})," ",Object.keys(P.bindings).length===0?m.jsx("span",{className:"text-gray-500 italic",children:"none"}):m.jsx("span",{className:"text-yellow-400",children:Object.entries(P.bindings).map(([A,H])=>`${A}=${H}`).join(", ")})]}),m.jsxs("div",{className:"text-xs mt-0.5",children:[m.jsx("span",{className:"text-gray-500",children:"expression:"})," ",m.jsx("code",{className:"text-green-400",children:P.expression})]})]},M))})]})}),m.jsx("button",{onClick:I,disabled:!o||w,className:"w-full px-4 py-3 bg-blue-600 hover:bg-blue-700 rounded-lg font-semibold disabled:opacity-50 disabled:cursor-not-allowed transition-all shadow-lg shadow-blue-500/20 hover:shadow-blue-500/40",children:w?"Querying...":"Query Projection"}),x&&m.jsx("div",{className:"p-4 bg-red-900/20 border border-red-800 rounded-lg text-red-400 text-sm",children:x}),h!==null&&m.jsxs("div",{children:[m.jsx("h3",{className:"text-sm font-medium text-gray-400 mb-2",children:"Result"}),m.jsx("pre",{className:"p-4 bg-gray-950 rounded-lg overflow-x-auto text-sm text-green-300 border border-gray-800",children:JSON.stringify(h,null,2)})]})]})]})}function fb({value:n,onChange:l,objects:o,objectsByType:s,objectType:a}){const[c,f]=y.useState(""),p=y.useMemo(()=>a?o.filter(x=>x.type===a):o,[o,a]),h=y.useMemo(()=>{if(!a)return s;const x={};return s[a]&&(x[a]=s[a]),x},[s,a]),v=y.useMemo(()=>{if(!c)return p;const x=c.toLowerCase();return p.filter(E=>String(E.id).toLowerCase().includes(x)||E.type.toLowerCase().includes(x))},[p,c]);return m.jsx(Io,{value:n,onChange:x=>l(x||""),children:m.jsxs("div",{className:"relative",children:[m.jsxs("div",{className:"relative",children:[m.jsx(Io.Input,{className:"w-full px-3 py-2 pr-10 bg-gray-800 border border-gray-700 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-all",placeholder:"Type object ID or select...",onChange:x=>f(x.target.value),displayValue:x=>x}),m.jsx(Io.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-3",children:m.jsx("svg",{className:"h-5 w-5 text-gray-400",viewBox:"0 0 20 20",fill:"currentColor",children:m.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 01.707.293l3 3a1 1 0 01-1.414 1.414L10 5.414 7.707 7.707a1 1 0 01-1.414-1.414l3-3A1 1 0 0110 3zm-3.707 9.293a1 1 0 011.414 0L10 14.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z",clipRule:"evenodd"})})})]}),m.jsxs(Io.Options,{className:"absolute z-10 mt-1 w-full bg-gray-800 border border-gray-700 rounded-lg shadow-lg max-h-60 overflow-auto focus:outline-none",children:[Object.entries(h).map(([x,E])=>{const w=E.filter(b=>!c||b.toLowerCase().includes(c.toLowerCase()));return w.length===0?null:m.jsxs("div",{children:[m.jsx("div",{className:"sticky top-0 px-3 py-1.5 text-xs font-medium text-gray-500 bg-gray-850 border-b border-gray-700",children:x}),w.map(b=>m.jsx(Io.Option,{value:b,className:({active:S})=>`cursor-pointer select-none px-3 py-2 text-sm transition-colors ${S?"bg-blue-600 text-white":"text-gray-100"}`,children:({selected:S})=>m.jsx("span",{className:S?"font-semibold":"font-normal",children:b})},b))]},x)}),v.length===0&&m.jsx("div",{className:"px-3 py-2 text-sm text-gray-500",children:"No objects found"})]})]})})}function pb(){const[n,l]=y.useState([]),[o,s]=y.useState(""),[a,c]=y.useState(!0),[f,p]=y.useState(0),[h,v]=y.useState(50),[x,E]=y.useState(0),w=()=>{c(!0),L0(h,x).then(S=>{l(S.reactions),p(S.total)}).catch(S=>s(S.message)).finally(()=>c(!1))};y.useEffect(()=>{w()},[h,x]);const b=async S=>{if(confirm("Delete this reaction?"))try{await I0(S),w()}catch(C){s(C.message)}};return a?m.jsx($t,{}):o?m.jsxs("div",{className:"text-red-500 text-center p-8",children:["Error: ",o]}):m.jsxs("div",{className:"max-w-7xl mx-auto",children:[m.jsx("h2",{className:"text-2xl font-bold mb-6",children:"Reactions"}),m.jsxs("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg overflow-hidden border border-gray-800",children:[n.length===0?m.jsx(fn,{message:"No reactions found"}):m.jsxs("table",{className:"w-full",children:[m.jsx("thead",{className:"bg-gray-800/80 border-b border-gray-700",children:m.jsxs("tr",{children:[m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"ID"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Projection Def"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Params Hash"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Action"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Target"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Created"}),m.jsx("th",{className:"px-4 py-3"})]})}),m.jsx("tbody",{className:"divide-y divide-gray-800",children:n.map((S,C)=>m.jsxs("tr",{className:`transition-colors ${C%2===0?"bg-gray-900/30":"bg-gray-850/30"} hover:bg-gray-800/60`,children:[m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:S.id}),m.jsx("td",{className:"px-4 py-3",children:m.jsx(lr,{hash:S.projection_def_hash||"unknown"})}),m.jsx("td",{className:"px-4 py-3",children:m.jsx(lr,{hash:S.params_hash||"unknown"})}),m.jsx("td",{className:"px-4 py-3",children:m.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${S.action==="emit_event"?"bg-purple-500/20 text-purple-300 border border-purple-500/30":"bg-blue-500/20 text-blue-300 border border-blue-500/30"}`,children:S.action||"webhook"})}),m.jsx("td",{className:"px-4 py-3 text-sm truncate max-w-xs font-mono",children:S.action==="emit_event"?m.jsxs("div",{children:[m.jsxs("span",{className:"text-purple-400",children:["→ ",S.emit_event_type]}),S.emit_payload_template&&m.jsxs("div",{className:"text-gray-500 text-xs mt-1 truncate",children:["template: ",m.jsx("code",{className:"text-green-400",children:S.emit_payload_template})]})]}):m.jsx("span",{className:"text-blue-400",children:S.webhook_url})}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:ur(S.created_at)}),m.jsx("td",{className:"px-4 py-3",children:m.jsx("button",{onClick:()=>b(S.id),className:"px-3 py-1.5 bg-red-600 hover:bg-red-700 rounded text-sm font-medium transition-colors shadow-lg shadow-red-500/20 hover:shadow-red-500/40",children:"Delete"})})]},C))})]}),m.jsx(Vr,{total:f,limit:h,offset:x,onPageChange:E,onLimitChange:v})]})]})}function mb(){const[n,l]=y.useState([]),[o,s]=y.useState(""),[a,c]=y.useState(!0),[f,p]=y.useState(0),[h,v]=y.useState(50),[x,E]=y.useState(0),[w,b]=y.useState(""),[S,C]=y.useState(""),[j,I]=y.useState(""),[L,P]=y.useState(!1),[M,A]=y.useState(""),[H,q]=y.useState(!1),ee=()=>{c(!0),F0(h,x).then(z=>{l(z.api_keys),p(z.total)}).catch(z=>s(z.message)).finally(()=>c(!1))};y.useEffect(()=>{ee()},[h,x]);const he=async()=>{if(w.trim()){P(!0);try{const z={name:w.trim()};S.trim()&&(z.allowed_events=S.split(",").map(ue=>ue.trim()).filter(Boolean)),j.trim()&&(z.rate_limit=parseInt(j,10));const ae=await D0(z);A(ae.plaintext_key),q(!1),b(""),C(""),I(""),ee()}catch(z){s(z.message)}finally{P(!1)}}},J=async z=>{if(confirm("Delete this API key?"))try{await A0(z),ee()}catch(ae){s(ae.message)}},Q=()=>{navigator.clipboard.writeText(M),q(!0)};return a?m.jsx($t,{}):o?m.jsxs("div",{className:"text-red-500 text-center p-8",children:["Error: ",o]}):m.jsxs("div",{className:"max-w-7xl mx-auto",children:[m.jsx("h2",{className:"text-2xl font-bold mb-6",children:"API Keys"}),M&&m.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50",children:m.jsxs("div",{className:"bg-gray-900 border border-gray-700 rounded-xl p-6 max-w-lg w-full mx-4 shadow-2xl",children:[m.jsx("h3",{className:"text-lg font-bold text-yellow-400 mb-2",children:"Save your API key"}),m.jsx("p",{className:"text-sm text-gray-400 mb-4",children:"This key will only be shown once. Copy it now and store it securely."}),m.jsx("div",{className:"bg-gray-800 rounded-lg p-3 font-mono text-sm text-green-400 break-all mb-4",children:M}),m.jsxs("div",{className:"flex gap-3 justify-end",children:[m.jsx("button",{onClick:Q,className:"px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded-lg text-sm font-medium transition-colors",children:H?"Copied!":"Copy"}),m.jsx("button",{onClick:()=>A(""),className:"px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm font-medium transition-colors",children:"Close"})]})]})}),m.jsx("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg border border-gray-800 p-4 mb-6",children:m.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[m.jsxs("div",{children:[m.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Name"}),m.jsx("input",{type:"text",value:w,onChange:z=>b(z.target.value),placeholder:"my-service",className:"px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),m.jsxs("div",{children:[m.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Allowed Events (comma-separated)"}),m.jsx("input",{type:"text",value:S,onChange:z=>C(z.target.value),placeholder:"order.created, user.signed_up",className:"px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 w-64"})]}),m.jsxs("div",{children:[m.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Rate Limit"}),m.jsx("input",{type:"number",value:j,onChange:z=>I(z.target.value),placeholder:"1000",className:"px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 w-24"})]}),m.jsx("button",{onClick:he,disabled:L||!w.trim(),className:"px-4 py-2 bg-blue-600 hover:bg-blue-700 disabled:opacity-50 rounded-lg text-sm font-medium transition-colors shadow-lg shadow-blue-500/20",children:L?"Creating...":"Create"})]})}),m.jsxs("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg overflow-hidden border border-gray-800",children:[n.length===0?m.jsx(fn,{message:"No API keys found"}):m.jsxs("table",{className:"w-full",children:[m.jsx("thead",{className:"bg-gray-800/80 border-b border-gray-700",children:m.jsxs("tr",{children:[m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"ID"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Name"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Role"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Allowed Events"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Rate Limit"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Last Used"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Created"}),m.jsx("th",{className:"px-4 py-3"})]})}),m.jsx("tbody",{className:"divide-y divide-gray-800",children:n.map((z,ae)=>m.jsxs("tr",{className:`transition-colors ${ae%2===0?"bg-gray-900/30":"bg-gray-850/30"} hover:bg-gray-800/60`,children:[m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:z.id}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-200 font-medium",children:z.name}),m.jsx("td",{className:"px-4 py-3",children:m.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-purple-500/20 text-purple-300 border border-purple-500/30",children:z.role||"default"})}),m.jsx("td",{className:"px-4 py-3",children:m.jsx("div",{className:"flex flex-wrap gap-1",children:z.allowed_events&&z.allowed_events.length>0?z.allowed_events.map((ue,G)=>m.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-blue-500/20 text-blue-300 border border-blue-500/30",children:ue},G)):m.jsx("span",{className:"text-gray-500 text-xs",children:"all"})})}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400 font-mono",children:z.rate_limit??"—"}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:z.last_used_at?ur(z.last_used_at):"—"}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:ur(z.created_at)}),m.jsx("td",{className:"px-4 py-3",children:m.jsx("button",{onClick:()=>J(z.id),className:"px-3 py-1.5 bg-red-600 hover:bg-red-700 rounded text-sm font-medium transition-colors shadow-lg shadow-red-500/20 hover:shadow-red-500/40",children:"Delete"})})]},z.id))})]}),m.jsx(Vr,{total:f,limit:h,offset:x,onPageChange:E,onLimitChange:v})]})]})}function hb({status:n}){const l={success:"bg-green-500/20 text-green-300 border-green-500/30",failed:"bg-red-500/20 text-red-300 border-red-500/30",skipped:"bg-gray-500/20 text-gray-400 border-gray-500/30"};return m.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium border ${l[n]||l.skipped}`,children:n})}function nu(n,l=60){if(n==null)return"—";const o=typeof n=="string"?n:JSON.stringify(n);return o.length>l?o.slice(0,l)+"...":o}function gb(){const[n,l]=y.useState([]),[o,s]=y.useState(""),[a,c]=y.useState(!0),[f,p]=y.useState(0),[h,v]=y.useState(50),[x,E]=y.useState(0),[w,b]=y.useState(""),[S,C]=y.useState(new Set),j=()=>{c(!0);const L=w.trim()?parseInt(w,10):void 0;W0(h,x,L).then(P=>{l(P.reaction_logs),p(P.total)}).catch(P=>s(P.message)).finally(()=>c(!1))};y.useEffect(()=>{j()},[h,x]);const I=L=>{C(P=>{const M=new Set(P);return M.has(L)?M.delete(L):M.add(L),M})};return a?m.jsx($t,{}):o?m.jsxs("div",{className:"text-red-500 text-center p-8",children:["Error: ",o]}):m.jsxs("div",{className:"max-w-7xl mx-auto",children:[m.jsx("h2",{className:"text-2xl font-bold mb-6",children:"Reaction Logs"}),m.jsx("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg border border-gray-800 p-4 mb-6",children:m.jsxs("div",{className:"flex items-end gap-3",children:[m.jsxs("div",{children:[m.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Filter by Reaction ID"}),m.jsx("input",{type:"number",value:w,onChange:L=>b(L.target.value),placeholder:"Reaction ID",className:"px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 w-40"})]}),m.jsx("button",{onClick:()=>{E(0),j()},className:"px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded-lg text-sm font-medium transition-colors",children:"Filter"}),w&&m.jsx("button",{onClick:()=>{b(""),E(0),setTimeout(j,0)},className:"px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm font-medium transition-colors",children:"Clear"})]})}),m.jsxs("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg overflow-hidden border border-gray-800",children:[n.length===0?m.jsx(fn,{message:"No reaction logs found"}):m.jsx("div",{className:"overflow-x-auto",children:m.jsxs("table",{className:"w-full",children:[m.jsx("thead",{className:"bg-gray-800/80 border-b border-gray-700",children:m.jsxs("tr",{children:[m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"ID"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Reaction"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Trigger Event"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Projection"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Old Value"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"New Value"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Action"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Status"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Output"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Duration"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Created"})]})}),m.jsx("tbody",{className:"divide-y divide-gray-800",children:n.map((L,P)=>m.jsxs("tr",{className:`transition-colors ${P%2===0?"bg-gray-900/30":"bg-gray-850/30"} hover:bg-gray-800/60`,children:[m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:L.id}),m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:L.reaction_id}),m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:L.trigger_event_id}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400 max-w-[120px] truncate",children:nu(L.projection_def,30)}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400 font-mono max-w-[120px] truncate",children:nu(L.old_value)}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400 font-mono max-w-[120px] truncate",children:nu(L.new_value)}),m.jsx("td",{className:"px-4 py-3",children:m.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-blue-500/20 text-blue-300 border border-blue-500/30",children:L.action})}),m.jsx("td",{className:"px-4 py-3",children:m.jsx(hb,{status:L.status})}),m.jsx("td",{className:"px-4 py-3 text-sm",children:L.handler_output?m.jsxs("div",{children:[m.jsx("button",{onClick:()=>I(L.id),className:"text-blue-400 hover:text-blue-300 text-xs underline",children:S.has(L.id)?"Hide":"Show"}),S.has(L.id)&&m.jsx("pre",{className:"mt-2 p-2 bg-gray-800 rounded text-xs text-gray-300 max-w-xs overflow-auto whitespace-pre-wrap",children:typeof L.handler_output=="string"?L.handler_output:JSON.stringify(L.handler_output,null,2)})]}):m.jsx("span",{className:"text-gray-600",children:"—"})}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400 font-mono",children:L.duration_ms!=null?`${L.duration_ms}ms`:"—"}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:ur(L.created_at)})]},L.id))})]})}),m.jsx(Vr,{total:f,limit:h,offset:x,onPageChange:E,onLimitChange:v})]})]})}function vb({method:n}){const l={GET:"bg-blue-500/20 text-blue-300 border-blue-500/30",POST:"bg-green-500/20 text-green-300 border-green-500/30",PUT:"bg-yellow-500/20 text-yellow-300 border-yellow-500/30",PATCH:"bg-orange-500/20 text-orange-300 border-orange-500/30",DELETE:"bg-red-500/20 text-red-300 border-red-500/30"};return m.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-bold border ${l[n]||"bg-gray-500/20 text-gray-300 border-gray-500/30"}`,children:n})}function yb({code:n}){let l="bg-gray-500/20 text-gray-300 border-gray-500/30";return n>=200&&n<300?l="bg-green-500/20 text-green-300 border-green-500/30":n>=400&&n<500?l="bg-yellow-500/20 text-yellow-300 border-yellow-500/30":n>=500&&(l="bg-red-500/20 text-red-300 border-red-500/30"),m.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-bold border ${l}`,children:n})}function xb(){const[n,l]=y.useState([]),[o,s]=y.useState(""),[a,c]=y.useState(!0),[f,p]=y.useState(0),[h,v]=y.useState(50),[x,E]=y.useState(0),[w,b]=y.useState(""),S=()=>{c(!0);const C=w.trim()?parseInt(w,10):void 0;H0(h,x,C).then(j=>{l(j.request_logs),p(j.total)}).catch(j=>s(j.message)).finally(()=>c(!1))};return y.useEffect(()=>{S()},[h,x]),a?m.jsx($t,{}):o?m.jsxs("div",{className:"text-red-500 text-center p-8",children:["Error: ",o]}):m.jsxs("div",{className:"max-w-7xl mx-auto",children:[m.jsx("h2",{className:"text-2xl font-bold mb-6",children:"Request Logs"}),m.jsx("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg border border-gray-800 p-4 mb-6",children:m.jsxs("div",{className:"flex items-end gap-3",children:[m.jsxs("div",{children:[m.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Filter by API Key ID"}),m.jsx("input",{type:"number",value:w,onChange:C=>b(C.target.value),placeholder:"API Key ID",className:"px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 w-40"})]}),m.jsx("button",{onClick:()=>{E(0),S()},className:"px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded-lg text-sm font-medium transition-colors",children:"Filter"}),w&&m.jsx("button",{onClick:()=>{b(""),E(0),setTimeout(S,0)},className:"px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm font-medium transition-colors",children:"Clear"})]})}),m.jsxs("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg overflow-hidden border border-gray-800",children:[n.length===0?m.jsx(fn,{message:"No request logs found"}):m.jsx("div",{className:"overflow-x-auto",children:m.jsxs("table",{className:"w-full",children:[m.jsx("thead",{className:"bg-gray-800/80 border-b border-gray-700",children:m.jsxs("tr",{children:[m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"ID"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Method"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Path"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"API Key"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Status"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Error"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Duration"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Created"})]})}),m.jsx("tbody",{className:"divide-y divide-gray-800",children:n.map((C,j)=>m.jsxs("tr",{className:`transition-colors ${j%2===0?"bg-gray-900/30":"bg-gray-850/30"} hover:bg-gray-800/60`,children:[m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:C.id}),m.jsx("td",{className:"px-4 py-3",children:m.jsx(vb,{method:C.method})}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-300 font-mono",children:C.path}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:C.api_key_name||"—"}),m.jsx("td",{className:"px-4 py-3",children:m.jsx(yb,{code:C.status_code})}),m.jsx("td",{className:"px-4 py-3 text-sm text-red-400 max-w-[200px] truncate",children:C.error||"—"}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400 font-mono",children:C.duration_ms!=null?`${C.duration_ms}ms`:"—"}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:ur(C.created_at)})]},C.id))})]})}),m.jsx(Vr,{total:f,limit:h,offset:x,onPageChange:E,onLimitChange:v})]})]})}function wb(){const[n,l]=y.useState("health"),[o,s]=y.useState(!1),[a,c]=y.useState(""),[f,p]=y.useState(!0);y.useEffect(()=>{setTimeout(()=>{T0()||s(!0),p(!1)},100)},[]);const h=()=>{a.trim()&&(P0(a.trim()),s(!1))};return f?m.jsx("div",{className:"flex items-center justify-center h-screen bg-gray-950",children:m.jsx($t,{})}):o?m.jsx("div",{className:"flex items-center justify-center h-screen bg-gray-950 text-gray-100 px-4",children:m.jsxs("div",{className:"bg-gray-900/80 backdrop-blur border border-gray-800 p-8 rounded-xl shadow-2xl max-w-md w-full animate-fadeIn",children:[m.jsxs("div",{className:"text-center mb-6",children:[m.jsx("h2",{className:"text-3xl font-bold mb-2 bg-gradient-to-r from-blue-400 to-purple-500 bg-clip-text text-transparent",children:"OGraph UI"}),m.jsx("p",{className:"text-gray-400 text-sm",children:"Enter your API token to continue"})]}),m.jsx("input",{type:"text",className:"w-full px-4 py-3 bg-gray-800 border border-gray-700 rounded-lg mb-4 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all",placeholder:"API Token",value:a,onChange:v=>c(v.target.value),onKeyDown:v=>v.key==="Enter"&&h(),autoFocus:!0}),m.jsx("button",{onClick:h,className:"w-full px-4 py-3 bg-blue-600 hover:bg-blue-700 rounded-lg font-semibold shadow-lg shadow-blue-500/30 hover:shadow-blue-500/50 transition-all",children:"Continue"})]})}):m.jsx(j0,{page:n,onPageChange:l,children:m.jsxs("div",{className:"animate-fadeIn",children:[n==="health"&&m.jsx(V0,{}),n==="object-defs"&&m.jsx(B0,{}),n==="objects"&&m.jsx(ib,{}),n==="event-defs"&&m.jsx(ab,{}),n==="events"&&m.jsx(ub,{}),n==="projection-defs"&&m.jsx(cb,{}),n==="projections"&&m.jsx(db,{}),n==="reactions"&&m.jsx(pb,{}),n==="api-keys"&&m.jsx(mb,{}),n==="reaction-logs"&&m.jsx(gb,{}),n==="request-logs"&&m.jsx(xb,{})]})})}C0.createRoot(document.getElementById("root")).render(m.jsx(y.StrictMode,{children:m.jsx(wb,{})})); +`).map((E,w)=>{if(E.includes(":")){const[b,...S]=E.split(":");return m.jsxs("div",{children:[m.jsxs("span",{className:"text-blue-400",children:[b,":"]}),m.jsx("span",{className:"text-green-300",children:S.join(":")})]},w)}return m.jsx("div",{className:"text-gray-300",children:E},w)})})]}),v.value_schema&&m.jsxs("div",{children:[m.jsx("span",{className:"text-gray-400 font-medium",children:"Value Schema:"}),m.jsx("pre",{className:"mt-1.5 p-3 bg-gray-950 rounded-lg text-xs overflow-x-auto border border-gray-800 text-purple-300",children:JSON.stringify(v.value_schema,null,2)})]}),v.initial_value!==void 0&&m.jsxs("div",{children:[m.jsx("span",{className:"text-gray-400 font-medium",children:"Initial Value:"}),m.jsx("pre",{className:"mt-1.5 p-3 bg-gray-950 rounded-lg text-xs overflow-x-auto border border-gray-800 text-blue-300",children:JSON.stringify(v.initial_value,null,2)})]})]})]},x))})]})}function db(){const[n,l]=y.useState([]),[o,s]=y.useState(null),[a,c]=y.useState({}),[f,p]=y.useState([]),[h,v]=y.useState(null),[x,E]=y.useState(""),[w,b]=y.useState(!1),[S,C]=y.useState(!0);y.useEffect(()=>{Promise.all([Wp(),ou()]).then(([P,M])=>{l(P.projection_defs),p(M.objects.map(A=>({...A,id:String(A.id)})))}).catch(()=>{}).finally(()=>C(!1))},[]);const j=P=>{if(s(P),v(null),E(""),P){const M={};for(const A of Object.keys(P.params))M[A]="";c(M)}else c({})},I=async()=>{if(!o)return;b(!0),E(""),v(null);const P=new URLSearchParams;for(const[M,A]of Object.entries(a))A.trim()&&P.set(M,A.trim());try{const M=await nt(`/projections/${o.name}?${P.toString()}`);v(M.value)}catch(M){E(M.message)}finally{b(!1)}},L=y.useMemo(()=>{const P={};for(const M of f)P[M.type]||(P[M.type]=[]),P[M.type].push(String(M.id));return P},[f]);return S?m.jsx($t,{}):m.jsxs("div",{className:"max-w-4xl mx-auto",children:[m.jsx("h2",{className:"text-2xl font-bold mb-6",children:"Query Projections"}),m.jsxs("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg p-6 space-y-6 border border-gray-800",children:[m.jsxs("div",{children:[m.jsx("label",{className:"block text-sm font-medium text-gray-400 mb-2",children:"Projection"}),m.jsx(an,{value:o,onChange:j,children:m.jsxs("div",{className:"relative",children:[m.jsxs(an.Button,{className:"w-full px-4 py-2.5 bg-gray-800 border border-gray-700 rounded-lg text-left focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-all",children:[m.jsx("span",{className:o?"text-gray-100":"text-gray-500",children:o?.name||"Select a projection..."}),m.jsx("span",{className:"absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none",children:m.jsx("svg",{className:"h-5 w-5 text-gray-400",viewBox:"0 0 20 20",fill:"currentColor",children:m.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 01.707.293l3 3a1 1 0 01-1.414 1.414L10 5.414 7.707 7.707a1 1 0 01-1.414-1.414l3-3A1 1 0 0110 3zm-3.707 9.293a1 1 0 011.414 0L10 14.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z",clipRule:"evenodd"})})})]}),m.jsx(an.Options,{className:"absolute z-10 mt-1 w-full bg-gray-800 border border-gray-700 rounded-lg shadow-lg max-h-60 overflow-auto focus:outline-none",children:n.map(P=>m.jsx(an.Option,{value:P,className:({active:M})=>`cursor-pointer select-none px-4 py-2.5 transition-colors ${M?"bg-blue-600 text-white":"text-gray-100"}`,children:({selected:M})=>m.jsx("span",{className:M?"font-semibold":"font-normal",children:P.name})},P.name))})]})})]}),o&&m.jsxs("div",{className:"space-y-4",children:[m.jsxs("div",{className:"flex items-baseline gap-2",children:[m.jsx("label",{className:"block text-sm font-medium text-gray-400",children:"Parameters"}),m.jsxs("span",{className:"text-xs text-gray-600",children:["→ ",o.value_schema?.type||"any",o.initial_value!==void 0&&m.jsxs("span",{className:"ml-1",children:["(initial: ",JSON.stringify(o.initial_value),")"]})]})]}),m.jsx("div",{className:"space-y-3 bg-gray-800/30 rounded-lg p-4 border border-gray-700/50",children:Object.entries(o.params).map(([P,M])=>m.jsxs("div",{children:[m.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1.5",children:[P,m.jsxs("span",{className:"ml-2 px-1.5 py-0.5 bg-gray-700 rounded text-xs text-gray-400",children:[M.type,M.object_type?` → ${M.object_type}`:""]})]}),M.type==="ref"?m.jsx(fb,{value:a[P]||"",onChange:A=>c({...a,[P]:A}),objects:f,objectsByType:L,objectType:M.object_type}):m.jsx("input",{type:M.type==="number"?"number":"text",className:"w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-all",placeholder:`Enter ${M.type} value...`,value:a[P]||"",onChange:A=>c({...a,[P]:A.target.value})})]},P))})]}),o&&m.jsx("div",{className:"text-xs space-y-2 bg-gray-800/20 rounded-lg p-4 border border-gray-700/30",children:m.jsxs("div",{children:[m.jsx("span",{className:"text-gray-500 font-medium",children:"sources:"}),m.jsx("div",{className:"mt-1 space-y-2",children:o.sources?.map((P,M)=>m.jsxs("div",{className:"pl-3 border-l border-gray-700",children:[m.jsx("div",{className:"flex items-center gap-2",children:m.jsx(lr,{hash:P.event_def_hash,short:!1})}),m.jsxs("div",{className:"text-xs mt-1",children:[m.jsx("span",{className:"text-gray-500",children:"bindings:"})," ",Object.keys(P.bindings).length===0?m.jsx("span",{className:"text-gray-500 italic",children:"none"}):m.jsx("span",{className:"text-yellow-400",children:Object.entries(P.bindings).map(([A,H])=>`${A}=${H}`).join(", ")})]}),m.jsxs("div",{className:"text-xs mt-0.5",children:[m.jsx("span",{className:"text-gray-500",children:"expression:"})," ",m.jsx("code",{className:"text-green-400",children:P.expression})]})]},M))})]})}),m.jsx("button",{onClick:I,disabled:!o||w,className:"w-full px-4 py-3 bg-blue-600 hover:bg-blue-700 rounded-lg font-semibold disabled:opacity-50 disabled:cursor-not-allowed transition-all shadow-lg shadow-blue-500/20 hover:shadow-blue-500/40",children:w?"Querying...":"Query Projection"}),x&&m.jsx("div",{className:"p-4 bg-red-900/20 border border-red-800 rounded-lg text-red-400 text-sm",children:x}),h!==null&&m.jsxs("div",{children:[m.jsx("h3",{className:"text-sm font-medium text-gray-400 mb-2",children:"Result"}),m.jsx("pre",{className:"p-4 bg-gray-950 rounded-lg overflow-x-auto text-sm text-green-300 border border-gray-800",children:JSON.stringify(h,null,2)})]})]})]})}function fb({value:n,onChange:l,objects:o,objectsByType:s,objectType:a}){const[c,f]=y.useState(""),p=y.useMemo(()=>a?o.filter(x=>x.type===a):o,[o,a]),h=y.useMemo(()=>{if(!a)return s;const x={};return s[a]&&(x[a]=s[a]),x},[s,a]),v=y.useMemo(()=>{if(!c)return p;const x=c.toLowerCase();return p.filter(E=>String(E.id).toLowerCase().includes(x)||E.type.toLowerCase().includes(x))},[p,c]);return m.jsx(Io,{value:n,onChange:x=>l(x||""),children:m.jsxs("div",{className:"relative",children:[m.jsxs("div",{className:"relative",children:[m.jsx(Io.Input,{className:"w-full px-3 py-2 pr-10 bg-gray-800 border border-gray-700 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-all",placeholder:"Type object ID or select...",onChange:x=>f(x.target.value),displayValue:x=>x}),m.jsx(Io.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-3",children:m.jsx("svg",{className:"h-5 w-5 text-gray-400",viewBox:"0 0 20 20",fill:"currentColor",children:m.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 01.707.293l3 3a1 1 0 01-1.414 1.414L10 5.414 7.707 7.707a1 1 0 01-1.414-1.414l3-3A1 1 0 0110 3zm-3.707 9.293a1 1 0 011.414 0L10 14.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z",clipRule:"evenodd"})})})]}),m.jsxs(Io.Options,{className:"absolute z-10 mt-1 w-full bg-gray-800 border border-gray-700 rounded-lg shadow-lg max-h-60 overflow-auto focus:outline-none",children:[Object.entries(h).map(([x,E])=>{const w=E.filter(b=>!c||b.toLowerCase().includes(c.toLowerCase()));return w.length===0?null:m.jsxs("div",{children:[m.jsx("div",{className:"sticky top-0 px-3 py-1.5 text-xs font-medium text-gray-500 bg-gray-850 border-b border-gray-700",children:x}),w.map(b=>m.jsx(Io.Option,{value:b,className:({active:S})=>`cursor-pointer select-none px-3 py-2 text-sm transition-colors ${S?"bg-blue-600 text-white":"text-gray-100"}`,children:({selected:S})=>m.jsx("span",{className:S?"font-semibold":"font-normal",children:b})},b))]},x)}),v.length===0&&m.jsx("div",{className:"px-3 py-2 text-sm text-gray-500",children:"No objects found"})]})]})})}function pb(){const[n,l]=y.useState([]),[o,s]=y.useState(""),[a,c]=y.useState(!0),[f,p]=y.useState(0),[h,v]=y.useState(50),[x,E]=y.useState(0),w=()=>{c(!0),L0(h,x).then(S=>{l(S.reactions),p(S.total)}).catch(S=>s(S.message)).finally(()=>c(!1))};y.useEffect(()=>{w()},[h,x]);const b=async S=>{if(confirm("Delete this reaction?"))try{await I0(S),w()}catch(C){s(C.message)}};return a?m.jsx($t,{}):o?m.jsxs("div",{className:"text-red-500 text-center p-8",children:["Error: ",o]}):m.jsxs("div",{className:"max-w-7xl mx-auto",children:[m.jsx("h2",{className:"text-2xl font-bold mb-6",children:"Reactions"}),m.jsxs("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg overflow-hidden border border-gray-800",children:[n.length===0?m.jsx(fn,{message:"No reactions found"}):m.jsxs("table",{className:"w-full",children:[m.jsx("thead",{className:"bg-gray-800/80 border-b border-gray-700",children:m.jsxs("tr",{children:[m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"ID"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Projection Def"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Params Hash"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Action"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Target"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Created"}),m.jsx("th",{className:"px-4 py-3"})]})}),m.jsx("tbody",{className:"divide-y divide-gray-800",children:n.map((S,C)=>m.jsxs("tr",{className:`transition-colors ${C%2===0?"bg-gray-900/30":"bg-gray-850/30"} hover:bg-gray-800/60`,children:[m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:S.id}),m.jsx("td",{className:"px-4 py-3",children:m.jsx(lr,{hash:S.projection_def_hash||"unknown"})}),m.jsx("td",{className:"px-4 py-3",children:m.jsx(lr,{hash:S.params_hash||"unknown"})}),m.jsx("td",{className:"px-4 py-3",children:m.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${S.action==="emit_event"?"bg-purple-500/20 text-purple-300 border border-purple-500/30":"bg-blue-500/20 text-blue-300 border border-blue-500/30"}`,children:S.action||"webhook"})}),m.jsx("td",{className:"px-4 py-3 text-sm truncate max-w-xs font-mono",children:S.action==="emit_event"?m.jsxs("div",{children:[m.jsxs("span",{className:"text-purple-400",children:["→ ",S.emit_event_type]}),S.emit_payload_template&&m.jsxs("div",{className:"text-gray-500 text-xs mt-1 truncate",children:["template: ",m.jsx("code",{className:"text-green-400",children:S.emit_payload_template})]})]}):m.jsx("span",{className:"text-blue-400",children:S.webhook_url})}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:ur(S.created_at)}),m.jsx("td",{className:"px-4 py-3",children:m.jsx("button",{onClick:()=>b(S.id),className:"px-3 py-1.5 bg-red-600 hover:bg-red-700 rounded text-sm font-medium transition-colors shadow-lg shadow-red-500/20 hover:shadow-red-500/40",children:"Delete"})})]},C))})]}),m.jsx(Vr,{total:f,limit:h,offset:x,onPageChange:E,onLimitChange:v})]})]})}function mb(){const[n,l]=y.useState([]),[o,s]=y.useState(""),[a,c]=y.useState(!0),[f,p]=y.useState(0),[h,v]=y.useState(50),[x,E]=y.useState(0),[w,b]=y.useState(""),[S,C]=y.useState(""),[j,I]=y.useState(""),[L,P]=y.useState(!1),[M,A]=y.useState(""),[H,q]=y.useState(!1),ee=()=>{c(!0),F0(h,x).then(z=>{l(z.api_keys),p(z.total)}).catch(z=>s(z.message)).finally(()=>c(!1))};y.useEffect(()=>{ee()},[h,x]);const he=async()=>{if(w.trim()){P(!0);try{const z={name:w.trim()};S.trim()&&(z.allowed_events=S.split(",").map(ue=>ue.trim()).filter(Boolean)),j.trim()&&(z.rate_limit=parseInt(j,10));const ae=await D0(z);A(ae.plaintext_key),q(!1),b(""),C(""),I(""),ee()}catch(z){s(z.message)}finally{P(!1)}}},J=async z=>{if(confirm("Delete this API key?"))try{await A0(z),ee()}catch(ae){s(ae.message)}},Q=()=>{navigator.clipboard.writeText(M),q(!0)};return a?m.jsx($t,{}):o?m.jsxs("div",{className:"text-red-500 text-center p-8",children:["Error: ",o]}):m.jsxs("div",{className:"max-w-7xl mx-auto",children:[m.jsx("h2",{className:"text-2xl font-bold mb-6",children:"API Keys"}),M&&m.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50",children:m.jsxs("div",{className:"bg-gray-900 border border-gray-700 rounded-xl p-6 max-w-lg w-full mx-4 shadow-2xl",children:[m.jsx("h3",{className:"text-lg font-bold text-yellow-400 mb-2",children:"Save your API key"}),m.jsx("p",{className:"text-sm text-gray-400 mb-4",children:"This key will only be shown once. Copy it now and store it securely."}),m.jsx("div",{className:"bg-gray-800 rounded-lg p-3 font-mono text-sm text-green-400 break-all mb-4",children:M}),m.jsxs("div",{className:"flex gap-3 justify-end",children:[m.jsx("button",{onClick:Q,className:"px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded-lg text-sm font-medium transition-colors",children:H?"Copied!":"Copy"}),m.jsx("button",{onClick:()=>A(""),className:"px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm font-medium transition-colors",children:"Close"})]})]})}),m.jsx("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg border border-gray-800 p-4 mb-6",children:m.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[m.jsxs("div",{children:[m.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Name"}),m.jsx("input",{type:"text",value:w,onChange:z=>b(z.target.value),placeholder:"my-service",className:"px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),m.jsxs("div",{children:[m.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Allowed Events (comma-separated)"}),m.jsx("input",{type:"text",value:S,onChange:z=>C(z.target.value),placeholder:"order.created, user.signed_up",className:"px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 w-64"})]}),m.jsxs("div",{children:[m.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Rate Limit"}),m.jsx("input",{type:"number",value:j,onChange:z=>I(z.target.value),placeholder:"1000",className:"px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 w-24"})]}),m.jsx("button",{onClick:he,disabled:L||!w.trim(),className:"px-4 py-2 bg-blue-600 hover:bg-blue-700 disabled:opacity-50 rounded-lg text-sm font-medium transition-colors shadow-lg shadow-blue-500/20",children:L?"Creating...":"Create"})]})}),m.jsxs("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg overflow-hidden border border-gray-800",children:[n.length===0?m.jsx(fn,{message:"No API keys found"}):m.jsxs("table",{className:"w-full",children:[m.jsx("thead",{className:"bg-gray-800/80 border-b border-gray-700",children:m.jsxs("tr",{children:[m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"ID"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Name"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Allowed Events"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Rate Limit"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Last Used"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Created"}),m.jsx("th",{className:"px-4 py-3"})]})}),m.jsx("tbody",{className:"divide-y divide-gray-800",children:n.map((z,ae)=>m.jsxs("tr",{className:`transition-colors ${ae%2===0?"bg-gray-900/30":"bg-gray-850/30"} hover:bg-gray-800/60`,children:[m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:z.id}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-200 font-medium",children:z.name}),m.jsx("td",{className:"px-4 py-3",children:m.jsx("div",{className:"flex flex-wrap gap-1",children:z.allowed_events&&z.allowed_events.length>0?z.allowed_events.map((ue,G)=>m.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-blue-500/20 text-blue-300 border border-blue-500/30",children:ue},G)):m.jsx("span",{className:"text-gray-500 text-xs",children:"all"})})}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400 font-mono",children:z.rate_limit??"—"}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:z.last_used_at?ur(z.last_used_at):"—"}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:ur(z.created_at)}),m.jsx("td",{className:"px-4 py-3",children:m.jsx("button",{onClick:()=>J(z.id),className:"px-3 py-1.5 bg-red-600 hover:bg-red-700 rounded text-sm font-medium transition-colors shadow-lg shadow-red-500/20 hover:shadow-red-500/40",children:"Delete"})})]},z.id))})]}),m.jsx(Vr,{total:f,limit:h,offset:x,onPageChange:E,onLimitChange:v})]})]})}function hb({status:n}){const l={success:"bg-green-500/20 text-green-300 border-green-500/30",failed:"bg-red-500/20 text-red-300 border-red-500/30",skipped:"bg-gray-500/20 text-gray-400 border-gray-500/30"};return m.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium border ${l[n]||l.skipped}`,children:n})}function nu(n,l=60){if(n==null)return"—";const o=typeof n=="string"?n:JSON.stringify(n);return o.length>l?o.slice(0,l)+"...":o}function gb(){const[n,l]=y.useState([]),[o,s]=y.useState(""),[a,c]=y.useState(!0),[f,p]=y.useState(0),[h,v]=y.useState(50),[x,E]=y.useState(0),[w,b]=y.useState(""),[S,C]=y.useState(new Set),j=()=>{c(!0);const L=w.trim()?parseInt(w,10):void 0;W0(h,x,L).then(P=>{l(P.reaction_logs),p(P.total)}).catch(P=>s(P.message)).finally(()=>c(!1))};y.useEffect(()=>{j()},[h,x]);const I=L=>{C(P=>{const M=new Set(P);return M.has(L)?M.delete(L):M.add(L),M})};return a?m.jsx($t,{}):o?m.jsxs("div",{className:"text-red-500 text-center p-8",children:["Error: ",o]}):m.jsxs("div",{className:"max-w-7xl mx-auto",children:[m.jsx("h2",{className:"text-2xl font-bold mb-6",children:"Reaction Logs"}),m.jsx("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg border border-gray-800 p-4 mb-6",children:m.jsxs("div",{className:"flex items-end gap-3",children:[m.jsxs("div",{children:[m.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Filter by Reaction ID"}),m.jsx("input",{type:"number",value:w,onChange:L=>b(L.target.value),placeholder:"Reaction ID",className:"px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 w-40"})]}),m.jsx("button",{onClick:()=>{E(0),j()},className:"px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded-lg text-sm font-medium transition-colors",children:"Filter"}),w&&m.jsx("button",{onClick:()=>{b(""),E(0),setTimeout(j,0)},className:"px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm font-medium transition-colors",children:"Clear"})]})}),m.jsxs("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg overflow-hidden border border-gray-800",children:[n.length===0?m.jsx(fn,{message:"No reaction logs found"}):m.jsx("div",{className:"overflow-x-auto",children:m.jsxs("table",{className:"w-full",children:[m.jsx("thead",{className:"bg-gray-800/80 border-b border-gray-700",children:m.jsxs("tr",{children:[m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"ID"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Reaction"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Trigger Event"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Projection"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Old Value"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"New Value"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Action"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Status"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Output"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Duration"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Created"})]})}),m.jsx("tbody",{className:"divide-y divide-gray-800",children:n.map((L,P)=>m.jsxs("tr",{className:`transition-colors ${P%2===0?"bg-gray-900/30":"bg-gray-850/30"} hover:bg-gray-800/60`,children:[m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:L.id}),m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:L.reaction_id}),m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:L.trigger_event_id}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400 max-w-[120px] truncate",children:nu(L.projection_def,30)}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400 font-mono max-w-[120px] truncate",children:nu(L.old_value)}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400 font-mono max-w-[120px] truncate",children:nu(L.new_value)}),m.jsx("td",{className:"px-4 py-3",children:m.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-blue-500/20 text-blue-300 border border-blue-500/30",children:L.action})}),m.jsx("td",{className:"px-4 py-3",children:m.jsx(hb,{status:L.status})}),m.jsx("td",{className:"px-4 py-3 text-sm",children:L.handler_output?m.jsxs("div",{children:[m.jsx("button",{onClick:()=>I(L.id),className:"text-blue-400 hover:text-blue-300 text-xs underline",children:S.has(L.id)?"Hide":"Show"}),S.has(L.id)&&m.jsx("pre",{className:"mt-2 p-2 bg-gray-800 rounded text-xs text-gray-300 max-w-xs overflow-auto whitespace-pre-wrap",children:typeof L.handler_output=="string"?L.handler_output:JSON.stringify(L.handler_output,null,2)})]}):m.jsx("span",{className:"text-gray-600",children:"—"})}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400 font-mono",children:L.duration_ms!=null?`${L.duration_ms}ms`:"—"}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:ur(L.created_at)})]},L.id))})]})}),m.jsx(Vr,{total:f,limit:h,offset:x,onPageChange:E,onLimitChange:v})]})]})}function vb({method:n}){const l={GET:"bg-blue-500/20 text-blue-300 border-blue-500/30",POST:"bg-green-500/20 text-green-300 border-green-500/30",PUT:"bg-yellow-500/20 text-yellow-300 border-yellow-500/30",PATCH:"bg-orange-500/20 text-orange-300 border-orange-500/30",DELETE:"bg-red-500/20 text-red-300 border-red-500/30"};return m.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-bold border ${l[n]||"bg-gray-500/20 text-gray-300 border-gray-500/30"}`,children:n})}function yb({code:n}){let l="bg-gray-500/20 text-gray-300 border-gray-500/30";return n>=200&&n<300?l="bg-green-500/20 text-green-300 border-green-500/30":n>=400&&n<500?l="bg-yellow-500/20 text-yellow-300 border-yellow-500/30":n>=500&&(l="bg-red-500/20 text-red-300 border-red-500/30"),m.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-bold border ${l}`,children:n})}function xb(){const[n,l]=y.useState([]),[o,s]=y.useState(""),[a,c]=y.useState(!0),[f,p]=y.useState(0),[h,v]=y.useState(50),[x,E]=y.useState(0),[w,b]=y.useState(""),S=()=>{c(!0);const C=w.trim()?parseInt(w,10):void 0;H0(h,x,C).then(j=>{l(j.request_logs),p(j.total)}).catch(j=>s(j.message)).finally(()=>c(!1))};return y.useEffect(()=>{S()},[h,x]),a?m.jsx($t,{}):o?m.jsxs("div",{className:"text-red-500 text-center p-8",children:["Error: ",o]}):m.jsxs("div",{className:"max-w-7xl mx-auto",children:[m.jsx("h2",{className:"text-2xl font-bold mb-6",children:"Request Logs"}),m.jsx("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg border border-gray-800 p-4 mb-6",children:m.jsxs("div",{className:"flex items-end gap-3",children:[m.jsxs("div",{children:[m.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Filter by API Key ID"}),m.jsx("input",{type:"number",value:w,onChange:C=>b(C.target.value),placeholder:"API Key ID",className:"px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 w-40"})]}),m.jsx("button",{onClick:()=>{E(0),S()},className:"px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded-lg text-sm font-medium transition-colors",children:"Filter"}),w&&m.jsx("button",{onClick:()=>{b(""),E(0),setTimeout(S,0)},className:"px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm font-medium transition-colors",children:"Clear"})]})}),m.jsxs("div",{className:"bg-gray-900/50 backdrop-blur rounded-lg overflow-hidden border border-gray-800",children:[n.length===0?m.jsx(fn,{message:"No request logs found"}):m.jsx("div",{className:"overflow-x-auto",children:m.jsxs("table",{className:"w-full",children:[m.jsx("thead",{className:"bg-gray-800/80 border-b border-gray-700",children:m.jsxs("tr",{children:[m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"ID"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Method"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Path"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"API Key"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Status"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Error"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Duration"}),m.jsx("th",{className:"px-4 py-3 text-left text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Created"})]})}),m.jsx("tbody",{className:"divide-y divide-gray-800",children:n.map((C,j)=>m.jsxs("tr",{className:`transition-colors ${j%2===0?"bg-gray-900/30":"bg-gray-850/30"} hover:bg-gray-800/60`,children:[m.jsx("td",{className:"px-4 py-3 font-mono text-sm text-gray-300",children:C.id}),m.jsx("td",{className:"px-4 py-3",children:m.jsx(vb,{method:C.method})}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-300 font-mono",children:C.path}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:C.api_key_name||"—"}),m.jsx("td",{className:"px-4 py-3",children:m.jsx(yb,{code:C.status_code})}),m.jsx("td",{className:"px-4 py-3 text-sm text-red-400 max-w-[200px] truncate",children:C.error||"—"}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400 font-mono",children:C.duration_ms!=null?`${C.duration_ms}ms`:"—"}),m.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:ur(C.created_at)})]},C.id))})]})}),m.jsx(Vr,{total:f,limit:h,offset:x,onPageChange:E,onLimitChange:v})]})]})}function wb(){const[n,l]=y.useState("health"),[o,s]=y.useState(!1),[a,c]=y.useState(""),[f,p]=y.useState(!0);y.useEffect(()=>{setTimeout(()=>{T0()||s(!0),p(!1)},100)},[]);const h=()=>{a.trim()&&(P0(a.trim()),s(!1))};return f?m.jsx("div",{className:"flex items-center justify-center h-screen bg-gray-950",children:m.jsx($t,{})}):o?m.jsx("div",{className:"flex items-center justify-center h-screen bg-gray-950 text-gray-100 px-4",children:m.jsxs("div",{className:"bg-gray-900/80 backdrop-blur border border-gray-800 p-8 rounded-xl shadow-2xl max-w-md w-full animate-fadeIn",children:[m.jsxs("div",{className:"text-center mb-6",children:[m.jsx("h2",{className:"text-3xl font-bold mb-2 bg-gradient-to-r from-blue-400 to-purple-500 bg-clip-text text-transparent",children:"OGraph UI"}),m.jsx("p",{className:"text-gray-400 text-sm",children:"Enter your API token to continue"})]}),m.jsx("input",{type:"text",className:"w-full px-4 py-3 bg-gray-800 border border-gray-700 rounded-lg mb-4 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all",placeholder:"API Token",value:a,onChange:v=>c(v.target.value),onKeyDown:v=>v.key==="Enter"&&h(),autoFocus:!0}),m.jsx("button",{onClick:h,className:"w-full px-4 py-3 bg-blue-600 hover:bg-blue-700 rounded-lg font-semibold shadow-lg shadow-blue-500/30 hover:shadow-blue-500/50 transition-all",children:"Continue"})]})}):m.jsx(j0,{page:n,onPageChange:l,children:m.jsxs("div",{className:"animate-fadeIn",children:[n==="health"&&m.jsx(V0,{}),n==="object-defs"&&m.jsx(B0,{}),n==="objects"&&m.jsx(ib,{}),n==="event-defs"&&m.jsx(ab,{}),n==="events"&&m.jsx(ub,{}),n==="projection-defs"&&m.jsx(cb,{}),n==="projections"&&m.jsx(db,{}),n==="reactions"&&m.jsx(pb,{}),n==="api-keys"&&m.jsx(mb,{}),n==="reaction-logs"&&m.jsx(gb,{}),n==="request-logs"&&m.jsx(xb,{})]})})}C0.createRoot(document.getElementById("root")).render(m.jsx(y.StrictMode,{children:m.jsx(wb,{})})); diff --git a/packages/engine/ui/src/components/ApiKeys.tsx b/packages/engine/ui/src/components/ApiKeys.tsx index d0d1ccc..2a9a962 100644 --- a/packages/engine/ui/src/components/ApiKeys.tsx +++ b/packages/engine/ui/src/components/ApiKeys.tsx @@ -164,9 +164,6 @@ export default function ApiKeys() { Name - - Role - Allowed Events @@ -192,11 +189,6 @@ export default function ApiKeys() { > {key.id} {key.name} - - - {key.role || 'default'} - -
{key.allowed_events && key.allowed_events.length > 0 ? (