@maxceem/agw 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agw.mjs +11 -12
- package/dist/release/{0.1.2/console/assets/endpoints-Dnjjwdkn.js → 0.1.3/console/assets/endpoints-CpkgQRHP.js} +1 -1
- package/dist/release/{0.1.2/console/assets/index-D71D9UiI.js → 0.1.3/console/assets/index-CoITs7Dp.js} +2 -2
- package/dist/release/{0.1.2/console/assets/usage-DjvO6eyw.js → 0.1.3/console/assets/usage-DbEmt1ps.js} +1 -1
- package/dist/release/{0.1.2 → 0.1.3}/console/index.html +1 -1
- package/dist/release/{0.1.2 → 0.1.3}/manifest.json +7 -6
- package/dist/release/{0.1.2 → 0.1.3}/worker/index.js +20 -9
- package/dist/release-integrity.json +1 -1
- package/package.json +2 -2
- /package/dist/release/{0.1.2 → 0.1.3}/console/.assetsignore +0 -0
- /package/dist/release/{0.1.2 → 0.1.3}/console/assets/index-CsWBdB28.css +0 -0
- /package/dist/release/{0.1.2 → 0.1.3}/console/favicon.svg +0 -0
- /package/dist/release/{0.1.2 → 0.1.3}/migrations/0000_initial.sql +0 -0
- /package/dist/release/{0.1.2 → 0.1.3}/wrangler.json +0 -0
|
@@ -48,7 +48,7 @@ Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}
|
|
|
48
48
|
`},ad=function(){var e=parseInt(document.body.getAttribute(`data-scroll-locked`)||`0`,10);return isFinite(e)?e:0},od=function(){v.useEffect(function(){return document.body.setAttribute(rd,(ad()+1).toString()),function(){var e=ad()-1;e<=0?document.body.removeAttribute(rd):document.body.setAttribute(rd,e.toString())}},[])},sd=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?`margin`:r;od();var a=v.useMemo(function(){return td(i)},[i]);return v.createElement(nd,{styles:id(a,!t,i,n?``:`!important`)})},cd=!1;if(typeof window<`u`)try{var ld=Object.defineProperty({},"passive",{get:function(){return cd=!0,!0}});window.addEventListener(`test`,ld,ld),window.removeEventListener(`test`,ld,ld)}catch{cd=!1}var ud=cd?{passive:!1}:!1,dd=function(e){return e.tagName===`TEXTAREA`},fd=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!==`hidden`&&!(n.overflowY===n.overflowX&&!dd(e)&&n[t]===`visible`)},pd=function(e){return fd(e,`overflowY`)},md=function(e){return fd(e,`overflowX`)},hd=function(e,t){var n=t.ownerDocument,r=t;do{if(typeof ShadowRoot<`u`&&r instanceof ShadowRoot&&(r=r.host),vd(e,r)){var i=yd(e,r);if(i[1]>i[2])return!0}r=r.parentNode}while(r&&r!==n.body);return!1},gd=function(e){return[e.scrollTop,e.scrollHeight,e.clientHeight]},_d=function(e){return[e.scrollLeft,e.scrollWidth,e.clientWidth]},vd=function(e,t){return e===`v`?pd(t):md(t)},yd=function(e,t){return e===`v`?gd(t):_d(t)},bd=function(e,t){return e===`h`&&t===`rtl`?-1:1},xd=function(e,t,n,r,i){var a=bd(e,window.getComputedStyle(t).direction),o=a*r,s=n.target,c=t.contains(s),l=!1,u=o>0,d=0,f=0;do{if(!s)break;var p=yd(e,s),m=p[0],h=p[1]-p[2]-a*m;(m||h)&&vd(e,s)&&(d+=h,f+=m);var g=s.parentNode;s=g&&g.nodeType===Node.DOCUMENT_FRAGMENT_NODE?g.host:g}while(!c&&s!==document.body||c&&(t.contains(s)||t===s));return(u&&(i&&Math.abs(d)<1||!i&&o>d)||!u&&(i&&Math.abs(f)<1||!i&&-o>f))&&(l=!0),l},Sd=function(e){return`changedTouches`in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Cd=function(e){return[e.deltaX,e.deltaY]},J=function(e){return e&&`current`in e?e.current:e},wd=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Td=function(e){return`
|
|
49
49
|
.block-interactivity-${e} {pointer-events: none;}
|
|
50
50
|
.allow-interactivity-${e} {pointer-events: all;}
|
|
51
|
-
`},Ed=0,Dd=[];function Od(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),i=v.useState(Ed++)[0],a=v.useState(Zu)[0],o=v.useRef(e);v.useEffect(function(){o.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add(`block-interactivity-${i}`);var t=Eu([e.lockRef.current],(e.shards||[]).map(J),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add(`allow-interactivity-${i}`)}),function(){document.body.classList.remove(`block-interactivity-${i}`),t.forEach(function(e){return e.classList.remove(`allow-interactivity-${i}`)})}}},[e.inert,e.lockRef.current,e.shards]);var s=v.useCallback(function(e,t){if(`touches`in e&&e.touches.length===2||e.type===`wheel`&&e.ctrlKey)return!o.current.allowPinchZoom;var i=Sd(e),a=n.current,s=`deltaX`in e?e.deltaX:a[0]-i[0],c=`deltaY`in e?e.deltaY:a[1]-i[1],l,u=e.target,d=Math.abs(s)>Math.abs(c)?`h`:`v`;if(`touches`in e&&d===`h`&&u.type===`range`)return!1;var f=window.getSelection(),p=f&&f.anchorNode;if(p&&(p===u||p.contains(u)))return!1;var m=hd(d,u);if(!m)return!0;if(m?l=d:(l=d===`v`?`h`:`v`,m=hd(d,u)),!m)return!1;if(!r.current&&`changedTouches`in e&&(s||c)&&(r.current=l),!l)return!0;var h=r.current||l;return xd(h,t,e,h===`h`?s:c,!0)},[]),c=v.useCallback(function(e){var n=e;if(!(!Dd.length||Dd[Dd.length-1]!==a)){var r=`deltaY`in n?Cd(n):Sd(n),i=t.current.filter(function(e){return e.name===n.type&&(e.target===n.target||n.target===e.shadowParent)&&wd(e.delta,r)})[0];if(i&&i.should){n.cancelable&&n.preventDefault();return}if(!i){var c=(o.current.shards||[]).map(J).filter(Boolean).filter(function(e){return e.contains(n.target)});(c.length>0?s(n,c[0]):!o.current.noIsolation)&&n.cancelable&&n.preventDefault()}}},[]),l=v.useCallback(function(e,n,r,i){var a={name:e,delta:n,target:r,should:i,shadowParent:kd(r)};t.current.push(a),setTimeout(function(){t.current=t.current.filter(function(e){return e!==a})},1)},[]),u=v.useCallback(function(e){n.current=Sd(e),r.current=void 0},[]),d=v.useCallback(function(t){l(t.type,Cd(t),t.target,s(t,e.lockRef.current))},[]),f=v.useCallback(function(t){l(t.type,Sd(t),t.target,s(t,e.lockRef.current))},[]);v.useEffect(function(){return Dd.push(a),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener(`wheel`,c,ud),document.addEventListener(`touchmove`,c,ud),document.addEventListener(`touchstart`,u,ud),function(){Dd=Dd.filter(function(e){return e!==a}),document.removeEventListener(`wheel`,c,ud),document.removeEventListener(`touchmove`,c,ud),document.removeEventListener(`touchstart`,u,ud)}},[]);var p=e.removeScrollBar,m=e.inert;return v.createElement(v.Fragment,null,m?v.createElement(a,{styles:Td(i)}):null,p?v.createElement(sd,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function kd(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var Ad=Bu(Vu,Od),jd=v.forwardRef(function(e,t){return v.createElement(Uu,wu({},e,{ref:t,sideCar:Ad}))});jd.classNames=Uu.classNames;var Md=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},Nd=new WeakMap,Pd=new WeakMap,Fd={},Id=0,Ld=function(e){return e&&(e.host||Ld(e.parentNode))},Rd=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=Ld(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},zd=function(e,t,n,r){var i=Rd(t,Array.isArray(e)?e:[e]);Fd[n]||(Fd[n]=new WeakMap);var a=Fd[n],o=[],s=new Set,c=new Set(i),l=function(e){!e||s.has(e)||(s.add(e),l(e.parentNode))};i.forEach(l);var u=function(e){!e||c.has(e)||Array.prototype.forEach.call(e.children,function(e){if(s.has(e))u(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(Nd.get(e)||0)+1,l=(a.get(e)||0)+1;Nd.set(e,c),a.set(e,l),o.push(e),c===1&&i&&Pd.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return u(t),s.clear(),Id++,function(){o.forEach(function(e){var t=Nd.get(e)-1,i=a.get(e)-1;Nd.set(e,t),a.set(e,i),t||(Pd.has(e)||e.removeAttribute(r),Pd.delete(e)),i||e.removeAttribute(n)}),Id--,Id||(Nd=new WeakMap,Nd=new WeakMap,Pd=new WeakMap,Fd={})}},Bd=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||Md(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),zd(r,i,n,`aria-hidden`)):function(){return null}},Vd=Object.defineProperty,Hd=(e,t)=>Vd(e,`name`,{value:t,configurable:!0}),Ud=`Dialog`,[Wd,Gd]=Lc(Ud),[Kd,qd]=Wd(Ud),Jd=Hd(e=>{let{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!0}=e,s=v.useRef(null),c=v.useRef(null),[l,u]=ml({prop:r,defaultProp:i??!1,onChange:a,caller:Ud}),[d,f]=v.useState(0),[p,m]=v.useState(0);return(0,I.jsx)(Kd,{scope:t,triggerRef:s,contentRef:c,contentId:Ml(),titleId:Ml(),descriptionId:Ml(),titlePresent:d>0,descriptionPresent:p>0,setTitleCount:f,setDescriptionCount:m,open:l,onOpenChange:u,onOpenToggle:v.useCallback(()=>u(e=>!e),[u]),modal:o,children:n})},`Dialog`),Yd=`DialogTrigger`,Xd=v.forwardRef(Hd(function(e,t){let{__scopeDialog:n,...r}=e,i=qd(Yd,n),a=uc(t,i.triggerRef);return(0,I.jsx)(W.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":_f(i.open),...r,ref:a,onClick:G(e.onClick,i.onOpenToggle)})},`DialogTrigger`)),Zd=`DialogPortal`,[Qd,$d]=Wd(Zd,{forceMount:void 0}),ef=Hd(e=>{let{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=qd(Zd,t);return(0,I.jsx)(Qd,{scope:t,forceMount:n,children:v.Children.map(r,e=>(0,I.jsx)(Sl,{present:n||a.open,children:(0,I.jsx)(gu,{asChild:!0,container:i,children:e})}))})},`DialogPortal`),tf=`DialogOverlay`,nf=v.forwardRef(Hd(function(e,t){let n=$d(tf,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=qd(tf,e.__scopeDialog);return a.modal?(0,I.jsx)(Sl,{present:r||a.open,children:(0,I.jsx)(af,{...i,ref:t})}):null},`DialogOverlay`)),rf=pc(`DialogOverlay.RemoveScroll`),af=v.forwardRef(Hd(function(e,t){let{__scopeDialog:n,...r}=e,i=qd(tf,n),a=uc(t,Kl());return(0,I.jsx)(jd,{as:rf,allowPinchZoom:!0,shards:[i.contentRef],children:(0,I.jsx)(W.div,{"data-state":_f(i.open),...r,ref:a,style:{pointerEvents:`auto`,...r.style}})})},`DialogOverlayImpl`)),of=`DialogContent`,sf=v.forwardRef(Hd(function(e,t){let n=$d(of,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=qd(of,e.__scopeDialog);return(0,I.jsx)(Sl,{present:r||a.open,children:a.modal?(0,I.jsx)(cf,{...i,ref:t}):(0,I.jsx)(lf,{...i,ref:t})})},`DialogContent`)),cf=v.forwardRef(Hd(function(e,t){let n=qd(of,e.__scopeDialog),r=v.useRef(null),i=uc(t,n.contentRef,r);return v.useEffect(()=>{let e=r.current;if(e)return Bd(e)},[]),(0,I.jsx)(uf,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:G(e.onCloseAutoFocus,e=>{e.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:G(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;(t.button===2||n)&&e.preventDefault()}),onFocusOutside:G(e.onFocusOutside,e=>e.preventDefault())})},`DialogContentModal`)),lf=v.forwardRef(Hd(function(e,t){let n=qd(of,e.__scopeDialog),r=v.useRef(!1),i=v.useRef(!1);return(0,I.jsx)(uf,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})},`DialogContentNonModal`)),uf=v.forwardRef(Hd(function(e,t){let{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=e,s=qd(of,n);return Su(),(0,I.jsx)(I.Fragment,{children:(0,I.jsx)(ru,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,I.jsx)(Gl,{role:`dialog`,id:s.contentId,"aria-describedby":s.descriptionPresent?s.descriptionId:void 0,"aria-labelledby":s.titlePresent?s.titleId:void 0,"data-state":_f(s.open),...o,ref:t,deferPointerDownOutside:!0,onDismiss:()=>s.onOpenChange(!1)})})})},`DialogContentImpl`)),df=`DialogTitle`,ff=v.forwardRef(Hd(function(e,t){let{__scopeDialog:n,...r}=e,i=qd(df,n),{setTitleCount:a}=i;return al(()=>(a(e=>e+1),()=>a(e=>e-1)),[a]),(0,I.jsx)(W.h2,{id:i.titleId,...r,ref:t})},`DialogTitle`)),pf=`DialogDescription`,mf=v.forwardRef(Hd(function(e,t){let{__scopeDialog:n,...r}=e,i=qd(pf,n),{setDescriptionCount:a}=i;return al(()=>(a(e=>e+1),()=>a(e=>e-1)),[a]),(0,I.jsx)(W.p,{id:i.descriptionId,...r,ref:t})},`DialogDescription`)),hf=`DialogClose`,gf=v.forwardRef(Hd(function(e,t){let{__scopeDialog:n,...r}=e,i=qd(hf,n);return(0,I.jsx)(W.button,{type:`button`,...r,ref:t,onClick:G(e.onClick,()=>i.onOpenChange(!1))})},`DialogClose`));function _f(e){return e?`open`:`closed`}Hd(_f,`getState`);var vf=Object.defineProperty,yf=(e,t)=>vf(e,`name`,{value:t,configurable:!0});function bf(e){let[t,n]=v.useState(void 0);return al(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=new ResizeObserver(t=>{if(!Array.isArray(t)||!t.length)return;let r=t[0],i,a;if(`borderBoxSize`in r){let e=r.borderBoxSize,t=Array.isArray(e)?e[0]:e;i=t.inlineSize,a=t.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return t.observe(e,{box:`border-box`}),()=>t.unobserve(e)}else n(void 0)},[e]),t}yf(bf,`useSize`);var xf=Object.defineProperty,Sf=(e,t)=>xf(e,`name`,{value:t,configurable:!0}),Cf=`Checkbox`,[wf,Tf]=Lc(Cf),[Ef,Df]=wf(Cf);function Of(e){let{__scopeCheckbox:t,checked:n,children:r,defaultChecked:i,disabled:a,form:o,name:s,onCheckedChange:c,required:l,value:u=`on`,internal_do_not_use_render:d}=e,[f,p]=ml({prop:n,defaultProp:i??!1,onChange:c,caller:Cf}),[m,h]=v.useState(null),[g,_]=v.useState(null),y=v.useRef(!1),[b,x]=v.useReducer(e=>e+1,0),S=!m||!!o||!!m.closest(`form`),C={checked:f,disabled:a,setChecked:p,control:m,setControl:h,name:s,form:o,value:u,hasConsumerStoppedPropagationRef:y,userInteractionCount:b,onUserInteraction:x,required:l,defaultChecked:!Lf(i)&&i,isFormControl:S,bubbleInput:g,setBubbleInput:_};return(0,I.jsx)(Ef,{scope:t,...C,children:If(d)?d(C):r})}Sf(Of,`CheckboxProvider`);var kf=`CheckboxTrigger`,Af=v.forwardRef(Sf(function({__scopeCheckbox:e,onKeyDown:t,onClick:n,...r},i){let{control:a,value:o,disabled:s,checked:c,required:l,setControl:u,setChecked:d,hasConsumerStoppedPropagationRef:f,onUserInteraction:p,isFormControl:m,bubbleInput:h}=Df(kf,e),g=uc(i,u),_=v.useRef(c);return v.useEffect(()=>{let e=a?.form;if(e){let t=Sf(()=>d(_.current),`reset`);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[a,d]),(0,I.jsx)(W.button,{type:`button`,role:`checkbox`,"aria-checked":Lf(c)?`mixed`:c,"aria-required":l,"data-state":Rf(c),"data-disabled":s?``:void 0,disabled:s,value:o,...r,ref:g,onKeyDown:G(t,e=>{e.key===`Enter`&&e.preventDefault()}),onClick:G(n,e=>{p(),d(e=>Lf(e)?!0:!e),h&&m&&(f.current=e.isPropagationStopped(),f.current||e.stopPropagation())})})},`CheckboxTrigger`)),jf=v.forwardRef(Sf(function(e,t){let{__scopeCheckbox:n,name:r,checked:i,defaultChecked:a,required:o,disabled:s,value:c,onCheckedChange:l,form:u,...d}=e;return(0,I.jsx)(Of,{__scopeCheckbox:n,checked:i,defaultChecked:a,disabled:s,required:o,onCheckedChange:l,name:r,form:u,value:c,internal_do_not_use_render:({isFormControl:e})=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Af,{...d,ref:t,__scopeCheckbox:n}),e&&(0,I.jsx)(Ff,{__scopeCheckbox:n})]})})},`Checkbox`)),Mf=`CheckboxIndicator`,Nf=v.forwardRef(Sf(function(e,t){let{__scopeCheckbox:n,forceMount:r,...i}=e,a=Df(Mf,n);return(0,I.jsx)(Sl,{present:r||Lf(a.checked)||a.checked===!0,children:(0,I.jsx)(W.span,{"data-state":Rf(a.checked),"data-disabled":a.disabled?``:void 0,...i,ref:t,style:{pointerEvents:`none`,...e.style}})})},`CheckboxIndicator`)),Pf=`CheckboxBubbleInput`,Ff=v.forwardRef(Sf(function({__scopeCheckbox:e,onClick:t,...n},r){let{control:i,hasConsumerStoppedPropagationRef:a,userInteractionCount:o,checked:s,defaultChecked:c,required:l,disabled:u,name:d,value:f,form:p,bubbleInput:m,setBubbleInput:h}=Df(Pf,e),g=uc(r,h),_=bf(i),y=v.useRef(!1),b=v.useRef(s),x=v.useRef(o);v.useEffect(()=>{let e=m;if(!e)return;let t=window.HTMLInputElement.prototype,n=Object.getOwnPropertyDescriptor(t,`checked`).set,r=o!==x.current;x.current=o;let i=b.current!==s;b.current=s;let c=!(r&&a.current);if(i&&n){y.current=!r;let t=new Event(`click`,{bubbles:c});e.indeterminate=Lf(s),n.call(e,!Lf(s)&&s),e.dispatchEvent(t),y.current=!1}},[m,s,a,o]);let S=v.useRef(!Lf(s)&&s);return(0,I.jsx)(W.input,{type:`checkbox`,"aria-hidden":!0,defaultChecked:c??S.current,required:l,disabled:u,name:d,value:f,form:p,...n,tabIndex:-1,ref:g,onClick:G(t,e=>{y.current&&e.stopPropagation()}),style:{...n.style,..._,position:`absolute`,pointerEvents:`none`,opacity:0,margin:0,transform:`translateX(-100%)`}})},`CheckboxBubbleInput`));function If(e){return typeof e==`function`}Sf(If,`isFunction`);function Lf(e){return e===`indeterminate`}Sf(Lf,`isIndeterminate`);function Rf(e){return Lf(e)?`indeterminate`:e?`checked`:`unchecked`}Sf(Rf,`getState`);var zf=[`top`,`right`,`bottom`,`left`],Bf=Math.min,Vf=Math.max,Hf=Math.round,Uf=Math.floor,Wf=e=>({x:e,y:e}),Gf={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function Kf(e,t,n){return Vf(e,Bf(t,n))}function qf(e,t){return typeof e==`function`?e(t):e}function Jf(e){return e.split(`-`)[0]}function Yf(e){return e.split(`-`)[1]}function Xf(e){return e===`x`?`y`:`x`}function Zf(e){return e===`y`?`height`:`width`}function Qf(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function $f(e){return Xf(Qf(e))}function ep(e,t,n){n===void 0&&(n=!1);let r=Yf(e),i=$f(e),a=Zf(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=lp(o)),[o,lp(o)]}function tp(e){let t=lp(e);return[np(e),t,np(t)]}function np(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var rp=[`left`,`right`],ip=[`right`,`left`],ap=[`top`,`bottom`],op=[`bottom`,`top`];function sp(e,t,n){switch(e){case`top`:case`bottom`:return n?t?ip:rp:t?rp:ip;case`left`:case`right`:return t?ap:op;default:return[]}}function cp(e,t,n,r){let i=Yf(e),a=sp(Jf(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(np)))),a}function lp(e){let t=Jf(e);return Gf[t]+e.slice(t.length)}function up(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function dp(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:up(e)}function fp(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function pp(e,t,n){let{reference:r,floating:i}=e,a=Qf(t),o=$f(t),s=Zf(o),c=Jf(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}let m=Yf(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function mp(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=qf(t,e),p=dp(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=fp(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=fp(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var hp=50,gp=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:mp},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=pp(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<hp&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=pp(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},_p=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=qf(e,t)||{};if(l==null)return{};let d=dp(u),f={x:n,y:r},p=$f(i),m=Zf(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l)),C=S?S[y]:0;(!C||!await(o.isElement==null?void 0:o.isElement(S)))&&(C=s.floating[y]||a.floating[m]);let w=b/2-x/2,T=C/2-h[m]/2-1,E=Bf(d[_],T),ee=Bf(d[v],T),D=C-h[m]-ee,O=C/2-h[m]/2+w,k=Kf(E,O,D),A=!c.arrow&&Yf(i)!=null&&O!==k&&a.reference[m]/2-(O<E?E:ee)-h[m]/2<0,j=A?O<E?O-E:O-D:0;return{[p]:f[p]+j,data:{[p]:k,centerOffset:O-k-j,...A&&{alignmentOffset:j}},reset:A}}}),vp=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=qf(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=Jf(r),_=Qf(o),v=Jf(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[lp(o)]:tp(o)),x=p!==`none`;!d&&x&&b.push(...cp(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=ep(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(!(u===`alignment`&&_!==Qf(t))||T.every(e=>Qf(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=Qf(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}};function yp(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function bp(e){return zf.some(t=>e[t]>=0)}var xp=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=qf(e,t);switch(i){case`referenceHidden`:{let e=yp(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:bp(e)}}}case`escaped`:{let e=yp(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:bp(e)}}}default:return{}}}}},Sp=new Set([`left`,`top`]);async function Cp(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Jf(n),s=Yf(n),c=Qf(n)===`y`,l=Sp.has(o)?-1:1,u=a&&c?-1:1,d=qf(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var wp=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await Cp(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},Tp=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=qf(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=Qf(i),p=Xf(f),m=u[p],h=u[f],g=(e,t)=>Kf(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}},Ep=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=qf(e,t),u={x:n,y:r},d=Qf(i),f=Xf(d),p=u[f],m=u[d],h=qf(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:h.mainAxis??0,crossAxis:h.crossAxis??0};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=Sp.has(Jf(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},Dp=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){let{placement:n,rects:r,platform:i,elements:a}=t,{apply:o=()=>{},...s}=qf(e,t),c=await i.detectOverflow(t,s),l=Jf(n),u=Yf(n),d=Qf(n)===`y`,{width:f,height:p}=r.floating,m,h;l===`top`||l===`bottom`?(m=l,h=u===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?`start`:`end`)?`left`:`right`):(h=l,m=u===`end`?`top`:`bottom`);let g=p-c.top-c.bottom,_=f-c.left-c.right,v=Bf(p-c[m],g),y=Bf(f-c[h],_),b=t.middlewareData.shift,x=!b,S=v,C=y;b!=null&&b.enabled.x&&(C=_),b!=null&&b.enabled.y&&(S=g),x&&!u&&(d?C=f-2*Vf(c.left,c.right):S=p-2*Vf(c.top,c.bottom)),await o({...t,availableWidth:C,availableHeight:S});let w=await i.getDimensions(a.floating);return f!==w.width||p!==w.height?{reset:{rects:!0}}:{}}}};function Op(){return typeof window<`u`}function kp(e){return Mp(e)?(e.nodeName||``).toLowerCase():`#document`}function Ap(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function jp(e){return((Mp(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function Mp(e){return Op()?e instanceof Node||e instanceof Ap(e).Node:!1}function Np(e){return Op()?e instanceof Element||e instanceof Ap(e).Element:!1}function Pp(e){return Op()?e instanceof HTMLElement||e instanceof Ap(e).HTMLElement:!1}function Fp(e){return!Op()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof Ap(e).ShadowRoot}function Ip(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=qp(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function Lp(e){return/^(table|td|th)$/.test(kp(e))}function Rp(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var zp=/transform|translate|scale|rotate|perspective|filter/,Bp=/paint|layout|strict|content/,Vp=e=>!!e&&e!==`none`,Hp;function Up(e){let t=Np(e)?qp(e):e;return Vp(t.transform)||Vp(t.translate)||Vp(t.scale)||Vp(t.rotate)||Vp(t.perspective)||!Gp()&&(Vp(t.backdropFilter)||Vp(t.filter))||zp.test(t.willChange||``)||Bp.test(t.contain||``)}function Wp(e){let t=Yp(e);for(;Pp(t)&&!Kp(t);){if(Up(t))return t;if(Rp(t))return null;t=Yp(t)}return null}function Gp(){return Hp??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),Hp}function Kp(e){return/^(html|body|#document)$/.test(kp(e))}function qp(e){return Ap(e).getComputedStyle(e)}function Jp(e){return Np(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Yp(e){if(kp(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||Fp(e)&&e.host||jp(e);return Fp(t)?t.host:t}function Xp(e){let t=Yp(e);return Kp(t)?(e.ownerDocument||e).body:Pp(t)&&Ip(t)?t:Xp(t)}function Zp(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=Xp(e),i=r===e.ownerDocument?.body,a=Ap(r);if(i){let e=Qp(a);return t.concat(a,a.visualViewport||[],Ip(r)?r:[],e&&n?Zp(e):[])}else return t.concat(r,Zp(r,[],n))}function Qp(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function $p(e){let t=qp(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=Pp(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Hf(n)!==a||Hf(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function em(e){return Np(e)?e:e.contextElement}function tm(e){let t=em(e);if(!Pp(t))return Wf(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=$p(t),o=(a?Hf(n.width):n.width)/r,s=(a?Hf(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var nm=Wf(0);function rm(e){let t=Ap(e);return!Gp()||!t.visualViewport?nm:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function im(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===Ap(e)}function am(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=em(e),o=Wf(1);t&&(r?Np(r)&&(o=tm(r)):o=tm(e));let s=im(a,n,r)?rm(a):Wf(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a&&r){let e=Ap(a),t=Np(r)?Ap(r):r,n=e,i=Qp(n);for(;i&&t!==n;){let e=tm(i),t=i.getBoundingClientRect(),r=qp(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=Ap(i),i=Qp(n)}}return fp({width:u,height:d,x:c,y:l})}function om(e,t){let n=Jp(e).scrollLeft;return t?t.left+n:am(jp(e)).left+n}function sm(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-om(e,n),y:n.top+t.scrollTop}}function cm(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=jp(r),s=t?Rp(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Wf(1),u=Wf(0),d=Pp(r);if((d||!a)&&((kp(r)!==`body`||Ip(o))&&(c=Jp(r)),d)){let e=am(r);l=tm(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?sm(o,c):Wf(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function lm(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function um(e){let t=Jp(e),n=e.ownerDocument.body,r=Vf(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=Vf(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+om(e),o=-t.scrollTop;return qp(n).direction===`rtl`&&(a+=Vf(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var dm=25;function fm(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=Ap(e),a=jp(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!Gp()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(om(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=dm&&(s-=o)}return{width:s,height:c,x:l,y:u}}function pm(e,t){let n=am(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=tm(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function mm(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=fm(e,n,t);else if(t===`document`)r=um(jp(e));else if(Np(t))r=pm(t,n);else{let n=rm(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return fp(r)}function hm(e,t){let n=t.get(e);if(n)return n;let r=Zp(e,[],!1).filter(e=>Np(e)&&kp(e)!==`body`),i=null,a=qp(e).position===`fixed`,o=a?Yp(e):e;for(;Np(o)&&!Kp(o);){let e=qp(o),t=Up(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=Yp(o)}return t.set(e,r),r}function gm(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?Rp(t)?[]:hm(t,this._c):[].concat(n),r],o=mm(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=mm(t,a[e],i);s=Vf(n.top,s),c=Bf(n.right,c),l=Bf(n.bottom,l),u=Vf(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function _m(e){let{width:t,height:n}=$p(e);return{width:t,height:n}}function vm(e,t,n){let r=Pp(t),i=jp(t),a=n===`fixed`,o=am(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=Wf(0);if((r||!a)&&((kp(t)!==`body`||Ip(i))&&(s=Jp(t)),r)){let e=am(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}!r&&i&&(c.x=om(i));let l=i&&!r&&!a?sm(i,s):Wf(0);return{x:o.left+s.scrollLeft-c.x-l.x,y:o.top+s.scrollTop-c.y-l.y,width:o.width,height:o.height}}function ym(e){return qp(e).position===`static`}function bm(e,t){if(!Pp(e)||qp(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return jp(e)===n&&(n=n.ownerDocument.body),n}function xm(e,t){let n=Ap(e);if(Rp(e))return n;if(!Pp(e)){let t=Yp(e);for(;t&&!Kp(t);){if(Np(t)&&!ym(t))return t;t=Yp(t)}return n}let r=bm(e,t);for(;r&&Lp(r)&&ym(r);)r=bm(r,t);return r&&Kp(r)&&ym(r)&&!Up(r)?n:r||Wp(e)||n}var Sm=async function(e){let t=this.getOffsetParent||xm,n=this.getDimensions,r=await n(e.floating);return{reference:vm(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Cm(e){return qp(e).direction===`rtl`}var wm={convertOffsetParentRelativeRectToViewportRelativeRect:cm,getDocumentElement:jp,getClippingRect:gm,getOffsetParent:xm,getElementRects:Sm,getClientRects:lm,getDimensions:_m,getScale:tm,isElement:Np,isRTL:Cm};function Tm(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Em(e,t,n){let r=null,i,a=jp(e);function o(){var e;clearTimeout(i),(e=r)==null||e.disconnect(),r=null}function s(n,c){n===void 0&&(n=!1),c===void 0&&(c=1),o();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(n||t(),!f||!p)return;let m=Uf(d),h=Uf(a.clientWidth-(u+f)),g=Uf(a.clientHeight-(d+p)),_=Uf(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:Vf(0,Bf(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(!Tm(l,e.getBoundingClientRect()))return s();if(n!==c){if(!y)return s();n?s(!1,n):i=setTimeout(()=>{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=Ap(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function Dm(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=em(e),u=i||a?[...l?Zp(l):[],...t?Zp(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?Em(l,n,a):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?am(e):null;c&&g();function g(){let t=am(e);h&&!Tm(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var Om=wp,km=Tp,Am=vp,jm=Dp,Mm=xp,Nm=_p,Pm=Ep,Fm=(e,t,n)=>{let r=new Map,i=n??{},a={...wm,...i.platform,_c:r};return gp(e,t,{...i,platform:a})},Im=typeof document<`u`?v.useLayoutEffect:function(){};function Lm(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Lm(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!Lm(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function Rm(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function zm(e,t){let n=Rm(e);return Math.round(t*n)/n}function Bm(e){let t=v.useRef(e);return Im(()=>{t.current=e}),t}function Vm(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=v.useState(r);Lm(f,r)||p(r);let[m,h]=v.useState(null),[g,_]=v.useState(null),b=v.useCallback(e=>{e!==w.current&&(w.current=e,h(e))},[]),x=v.useCallback(e=>{e!==T.current&&(T.current=e,_(e))},[]),S=a||m,C=o||g,w=v.useRef(null),T=v.useRef(null),E=v.useRef(u),ee=c!=null,D=Bm(c),O=Bm(i),k=Bm(l),A=v.useCallback(()=>{if(!w.current||!T.current)return;let e={placement:t,strategy:n,middleware:f};O.current&&(e.platform=O.current),Fm(w.current,T.current,e).then(e=>{let t={...e,isPositioned:k.current!==!1};j.current&&!Lm(E.current,t)&&(E.current=t,y.flushSync(()=>{d(t)}))})},[f,t,n,O,k]);Im(()=>{l===!1&&E.current.isPositioned&&(E.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let j=v.useRef(!1);Im(()=>(j.current=!0,()=>{j.current=!1}),[]),Im(()=>{if(S&&(w.current=S),C&&(T.current=C),S&&C){if(D.current)return D.current(S,C,A);A()}},[S,C,A,D,ee]);let te=v.useMemo(()=>({reference:w,floating:T,setReference:b,setFloating:x}),[b,x]),ne=v.useMemo(()=>({reference:S,floating:C}),[S,C]),M=v.useMemo(()=>{let e={position:n,left:0,top:0};if(!ne.floating)return e;let t=zm(ne.floating,u.x),r=zm(ne.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...Rm(ne.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,ne.floating,u.x,u.y]);return v.useMemo(()=>({...u,update:A,refs:te,elements:ne,floatingStyles:M}),[u,A,te,ne,M])}var Hm=e=>{function t(e){return{}.hasOwnProperty.call(e,`current`)}return{name:`arrow`,options:e,fn(n){let{element:r,padding:i}=typeof e==`function`?e(n):e;return r&&t(r)?r.current==null?{}:Nm({element:r.current,padding:i}).fn(n):r?Nm({element:r,padding:i}).fn(n):{}}}},Um=(e,t)=>{let n=Om(e);return{name:n.name,fn:n.fn,options:[e,t]}},Wm=(e,t)=>{let n=km(e);return{name:n.name,fn:n.fn,options:[e,t]}},Gm=(e,t)=>({fn:Pm(e).fn,options:[e,t]}),Km=(e,t)=>{let n=Am(e);return{name:n.name,fn:n.fn,options:[e,t]}},qm=(e,t)=>{let n=jm(e);return{name:n.name,fn:n.fn,options:[e,t]}},Jm=(e,t)=>{let n=Mm(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ym=(e,t)=>{let n=Hm(e);return{name:n.name,fn:n.fn,options:[e,t]}},Xm=Object.defineProperty,Zm=v.forwardRef(((e,t)=>Xm(e,`name`,{value:t,configurable:!0}))(function(e,t){let{children:n,width:r=10,height:i=5,...a}=e;return(0,I.jsx)(W.svg,{...a,ref:t,width:r,height:i,viewBox:`0 0 30 10`,preserveAspectRatio:`none`,children:e.asChild?n:(0,I.jsx)(`polygon`,{points:`0,0 30,0 15,10`})})},`Arrow`)),Qm=Object.defineProperty,$m=(e,t)=>Qm(e,`name`,{value:t,configurable:!0}),eh=`Popper`,[th,nh]=Lc(eh),[rh,ih]=th(eh),ah=$m(e=>{let{__scopePopper:t,children:n}=e,[r,i]=v.useState(null),[a,o]=v.useState(void 0);return(0,I.jsx)(rh,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:o,children:n})},`Popper`),oh=`PopperAnchor`,sh=v.forwardRef($m(function(e,t){let{__scopePopper:n,virtualRef:r,...i}=e,a=ih(oh,n),o=v.useRef(null),s=a.onAnchorChange,c=uc(t,v.useCallback(e=>{o.current=e,e&&s(e)},[s])),l=v.useRef(null);v.useEffect(()=>{if(!r)return;let e=l.current;l.current=r.current,e!==l.current&&s(l.current)});let u=a.placementState&&_h(a.placementState),d=u?.[0],f=u?.[1];return r?null:(0,I.jsx)(W.div,{"data-radix-popper-side":d,"data-radix-popper-align":f,...i,ref:c})},`PopperAnchor`)),ch=`PopperContent`,[lh,uh]=th(ch),dh=v.forwardRef($m(function(e,t){let{__scopePopper:n,side:r=`bottom`,sideOffset:i=0,align:a=`center`,alignOffset:o=0,arrowPadding:s=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:d=`partial`,hideWhenDetached:f=!1,updatePositionStrategy:p=`optimized`,onPlaced:m,...h}=e,g=ih(ch,n),[_,y]=v.useState(null),b=uc(t,y),[x,S]=v.useState(null),C=bf(x),w=C?.width??0,T=C?.height??0,E=r+(a===`center`?``:`-`+a),ee=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},D=Array.isArray(l)?l:[l],O=D.length>0,k={padding:ee,boundary:D.filter(hh),altBoundary:O},{refs:A,floatingStyles:j,placement:te,isPositioned:ne,middlewareData:M}=Vm({strategy:`fixed`,placement:E,whileElementsMounted:$m((...e)=>Dm(...e,{animationFrame:p===`always`}),`whileElementsMounted`),elements:{reference:g.anchor},middleware:[Um({mainAxis:i+T,alignmentAxis:o}),c&&Wm({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?Gm():void 0,...k}),c&&Km({...k}),qm({...k,apply:$m(({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)},`apply`)}),x&&Ym({element:x,padding:s}),gh({arrowWidth:w,arrowHeight:T}),f&&Jm({strategy:`referenceHidden`,...k,boundary:O?k.boundary:void 0})]}),N=g.setPlacementState;al(()=>(N(te),()=>{N(void 0)}),[te,N]);let[P,re]=_h(te),ie=K(m);al(()=>{ne&&ie?.()},[ne,ie]);let ae=M.arrow?.x,oe=M.arrow?.y,F=M.arrow?.centerOffset!==0,[se,ce]=v.useState();return al(()=>{_&&ce(window.getComputedStyle(_).zIndex)},[_]),(0,I.jsx)(`div`,{ref:A.setFloating,"data-radix-popper-content-wrapper":``,style:{...j,transform:ne?j.transform:`translate(0, -200%)`,minWidth:`max-content`,zIndex:se,"--radix-popper-transform-origin":[M.transformOrigin?.x,M.transformOrigin?.y].join(` `),...M.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,I.jsx)(lh,{scope:n,placedSide:P,placedAlign:re,onArrowChange:S,arrowX:ae,arrowY:oe,shouldHideArrow:F,children:(0,I.jsx)(W.div,{"data-side":P,"data-align":re,...h,ref:b,style:{...h.style,animation:ne?h.style?.animation:`none`}})})})},`PopperContent`)),fh=`PopperArrow`,ph={top:`bottom`,right:`left`,bottom:`top`,left:`right`},mh=v.forwardRef($m(function(e,t){let{__scopePopper:n,...r}=e,i=uh(fh,n),a=ph[i.placedSide];return(0,I.jsx)(`span`,{ref:i.onArrowChange,style:{position:`absolute`,left:i.arrowX,top:i.arrowY,[a]:0,transformOrigin:{top:``,right:`0 0`,bottom:`center 0`,left:`100% 0`}[i.placedSide],transform:{top:`translateY(100%)`,right:`translateY(50%) rotate(90deg) translateX(-50%)`,bottom:`rotate(180deg)`,left:`translateY(50%) rotate(-90deg) translateX(50%)`}[i.placedSide],visibility:i.shouldHideArrow?`hidden`:void 0},children:(0,I.jsx)(Zm,{...r,ref:t,style:{...r.style,display:`block`}})})},`PopperArrow`));function hh(e){return e!==null}$m(hh,`isNotNull`);var gh=$m(e=>({name:`transformOrigin`,options:e,fn(t){let{placement:n,rects:r,middlewareData:i}=t,a=i.arrow?.centerOffset!==0,o=a?0:e.arrowWidth,s=a?0:e.arrowHeight,[c,l]=_h(n),u={start:`0%`,center:`50%`,end:`100%`}[l],d=(i.arrow?.x??0)+o/2,f=(i.arrow?.y??0)+s/2,p=``,m=``;return c===`bottom`?(p=a?u:`${d}px`,m=`${-s}px`):c===`top`?(p=a?u:`${d}px`,m=`${r.floating.height+s}px`):c===`right`?(p=`${-s}px`,m=a?u:`${f}px`):c===`left`&&(p=`${r.floating.width+s}px`,m=a?u:`${f}px`),{data:{x:p,y:m}}}}),`transformOrigin`);function _h(e){let[t,n=`center`]=e.split(`-`);return[t,n]}$m(_h,`getSideAndAlignFromPlacement`);var vh=ah,yh=sh,bh=dh,xh=mh,Sh=Object.defineProperty,Ch=(e,t)=>Sh(e,`name`,{value:t,configurable:!0}),wh=!1;function Th(){let[e,t]=v.useState(wh);return v.useEffect(()=>{wh||(wh=!0,t(!0))},[]),e}Ch(Th,`useIsHydrated`);var Eh=v.useSyncExternalStore;function Dh(){return()=>{}}Ch(Dh,`subscribe`);function Oh(){return Eh(Dh,()=>!0,()=>!1)}Ch(Oh,`useIsHydratedModern`);var kh=typeof Eh==`function`?Oh:Th,Ah=Object.defineProperty,jh=(e,t)=>Ah(e,`name`,{value:t,configurable:!0}),Mh=`rovingFocusGroup.onEntryFocus`,Nh={bubbles:!1,cancelable:!0},Ph=`RovingFocusGroup`,[Fh,Ih,Lh]=Vc(Ph),[Rh,zh]=Lc(Ph,[Lh]),[Bh,Vh]=Rh(Ph),Hh=v.forwardRef(jh(function(e,t){return(0,I.jsx)(Fh.Provider,{scope:e.__scopeRovingFocusGroup,children:(0,I.jsx)(Fh.Slot,{scope:e.__scopeRovingFocusGroup,children:(0,I.jsx)(Uh,{...e,ref:t})})})},`RovingFocusGroup`)),Uh=v.forwardRef(jh(function(e,t){let{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:c,onEntryFocus:l,preventScrollOnEntryFocus:u=!1,...d}=e,f=v.useRef(null),p=uc(t,f),m=Il(a),[h,g]=ml({prop:o,defaultProp:s??null,onChange:c,caller:Ph}),[_,y]=v.useState(!1),b=K(l),x=Ih(n),S=v.useRef(!1),[C,w]=v.useState(0);return v.useEffect(()=>{let e=f.current;if(e)return e.addEventListener(Mh,b),()=>e.removeEventListener(Mh,b)},[b]),(0,I.jsx)(Bh,{scope:n,orientation:r,dir:m,loop:i,currentTabStopId:h,onItemFocus:v.useCallback(e=>g(e),[g]),onItemShiftTab:v.useCallback(()=>y(!0),[]),onFocusableItemAdd:v.useCallback(()=>w(e=>e+1),[]),onFocusableItemRemove:v.useCallback(()=>w(e=>e-1),[]),children:(0,I.jsx)(W.div,{tabIndex:_||C===0?-1:0,"data-orientation":r,...d,ref:p,style:{outline:`none`,...e.style},onMouseDown:G(e.onMouseDown,()=>{S.current=!0}),onFocus:G(e.onFocus,e=>{let t=!S.current;if(e.target===e.currentTarget&&t&&!_){let t=new CustomEvent(Mh,Nh);if(e.currentTarget.dispatchEvent(t),!t.defaultPrevented){let e=x().filter(e=>e.focusable);Yh([e.find(e=>e.active),e.find(e=>e.id===h),...e].filter(Boolean).map(e=>e.ref.current),u)}}S.current=!1}),onBlur:G(e.onBlur,()=>y(!1))})})},`RovingFocusGroupImpl`)),Wh=`RovingFocusGroupItem`,Gh=v.forwardRef(jh(function(e,t){let{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:a,children:o,...s}=e,c=Ml(),l=a||c,u=Vh(Wh,n),d=u.currentTabStopId===l,f=Ih(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:h}=u,g=kh();return al(()=>{if(!(!g||!r))return p(),()=>m()},[g,r,p,m]),v.useEffect(()=>{if(!(g||!r))return p(),()=>m()},[g,r,p,m]),(0,I.jsx)(Fh.ItemSlot,{scope:n,id:l,focusable:r,active:i,children:(0,I.jsx)(W.span,{tabIndex:d?0:-1,"data-orientation":u.orientation,...s,ref:t,onMouseDown:G(e.onMouseDown,e=>{r?u.onItemFocus(l):e.preventDefault()}),onFocus:G(e.onFocus,()=>u.onItemFocus(l)),onKeyDown:G(e.onKeyDown,e=>{if(e.key===`Tab`&&e.shiftKey){u.onItemShiftTab();return}if(e.target!==e.currentTarget)return;let t=Jh(e,u.orientation,u.dir);if(t!==void 0){if(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return;e.preventDefault();let n=f().filter(e=>e.focusable).map(e=>e.ref.current);if(t===`last`)n.reverse();else if(t===`prev`||t===`next`){t===`prev`&&n.reverse();let r=n.indexOf(e.currentTarget);n=u.loop?Xh(n,r+1):n.slice(r+1)}setTimeout(()=>Yh(n))}}),children:typeof o==`function`?o({isCurrentTabStop:d,hasTabStop:h!=null}):o})})},`RovingFocusGroupItem`)),Kh={ArrowLeft:`prev`,ArrowUp:`prev`,ArrowRight:`next`,ArrowDown:`next`,PageUp:`first`,Home:`first`,PageDown:`last`,End:`last`};function qh(e,t){return t===`rtl`?e===`ArrowLeft`?`ArrowRight`:e===`ArrowRight`?`ArrowLeft`:e:e}jh(qh,`getDirectionAwareKey`);function Jh(e,t,n){let r=qh(e.key,n);if(!(t===`vertical`&&[`ArrowLeft`,`ArrowRight`].includes(r))&&!(t===`horizontal`&&[`ArrowUp`,`ArrowDown`].includes(r)))return Kh[r]}jh(Jh,`getFocusIntent`);function Yh(e,t=!1){let n=document.activeElement;for(let r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}jh(Yh,`focusFirst`);function Xh(e,t){return e.map((n,r)=>e[(t+r)%e.length])}jh(Xh,`wrapArray`);var Zh=Hh,Qh=Gh,$h=Object.defineProperty,eg=(e,t)=>$h(e,`name`,{value:t,configurable:!0}),tg=[`Enter`,` `],ng=[`ArrowDown`,`PageUp`,`Home`],rg=[`ArrowUp`,`PageDown`,`End`],ig=[...ng,...rg];[...tg],[...tg];var ag=`Menu`,[og,sg,cg]=Vc(ag),[lg,ug]=Lc(ag,[cg,nh,zh]),dg=nh(),fg=zh(),[pg,mg]=lg(ag),[hg,gg]=lg(ag),_g=eg(e=>{let{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:a,modal:o=!0}=e,s=dg(t),[c,l]=v.useState(null),u=v.useRef(!1),d=K(a),f=Il(i);return v.useEffect(()=>{let e=eg(()=>{u.current=!0,document.addEventListener(`pointerdown`,t,{capture:!0,once:!0}),document.addEventListener(`pointermove`,t,{capture:!0,once:!0})},`handleKeyDown`),t=eg(()=>u.current=!1,`handlePointer`);return document.addEventListener(`keydown`,e,{capture:!0}),()=>{document.removeEventListener(`keydown`,e,{capture:!0}),document.removeEventListener(`pointerdown`,t,{capture:!0}),document.removeEventListener(`pointermove`,t,{capture:!0})}},[]),v.useEffect(()=>{if(!n)return;let e=eg(()=>d(!1),`handleBlur`);return window.addEventListener(`blur`,e),()=>window.removeEventListener(`blur`,e)},[n,d]),(0,I.jsx)(vh,{...s,children:(0,I.jsx)(pg,{scope:t,open:n,onOpenChange:d,content:c,onContentChange:l,children:(0,I.jsx)(hg,{scope:t,onClose:v.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:f,modal:o,children:r})})})},`Menu`),vg=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,...r}=e,i=dg(n);return(0,I.jsx)(yh,{...i,...r,ref:t})},`MenuAnchor`)),yg=`MenuPortal`,[bg,xg]=lg(yg,{forceMount:void 0}),Sg=eg(e=>{let{__scopeMenu:t,forceMount:n,children:r,container:i}=e,a=mg(yg,t);return(0,I.jsx)(bg,{scope:t,forceMount:n,children:(0,I.jsx)(Sl,{present:n||a.open,children:(0,I.jsx)(gu,{asChild:!0,container:i,children:r})})})},`MenuPortal`),Cg=`MenuContent`,[wg,Tg]=lg(Cg),Eg=v.forwardRef(eg(function(e,t){let n=xg(Cg,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,a=mg(Cg,e.__scopeMenu),o=gg(Cg,e.__scopeMenu);return(0,I.jsx)(og.Provider,{scope:e.__scopeMenu,children:(0,I.jsx)(Sl,{present:r||a.open,children:(0,I.jsx)(og.Slot,{scope:e.__scopeMenu,children:o.modal?(0,I.jsx)(Dg,{...i,ref:t}):(0,I.jsx)(Og,{...i,ref:t})})})})},`MenuContent`)),Dg=v.forwardRef(eg(function(e,t){let n=mg(Cg,e.__scopeMenu),r=v.useRef(null),i=uc(t,r);return v.useEffect(()=>{let e=r.current;if(e)return Bd(e)},[]),(0,I.jsx)(Ag,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:G(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})},`MenuRootContentModal`)),Og=v.forwardRef(eg(function(e,t){let n=mg(Cg,e.__scopeMenu);return(0,I.jsx)(Ag,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})},`MenuRootContentNonModal`)),kg=pc(`MenuContent.ScrollLock`),Ag=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:o,disableOutsidePointerEvents:s,onEntryFocus:c,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,disableOutsideScroll:m,...h}=e,g=mg(Cg,n),_=gg(Cg,n),y=dg(n),b=fg(n),x=sg(n),[S,C]=v.useState(null),w=v.useRef(null),T=uc(t,w,g.onContentChange),E=v.useRef(0),ee=v.useRef(``),D=v.useRef(0),O=v.useRef(null),k=v.useRef(`right`),A=v.useRef(0),j=m?jd:v.Fragment,te=m?{as:kg,allowPinchZoom:!0}:void 0,ne=eg(e=>{let t=ee.current+e,n=x().filter(e=>!e.disabled),r=document.activeElement,i=n.find(e=>e.ref.current===r)?.textValue,a=e_(n.map(e=>e.textValue),t,i),o=n.find(e=>e.textValue===a)?.ref.current;eg((function e(t){ee.current=t,window.clearTimeout(E.current),t!==``&&(E.current=window.setTimeout(()=>e(``),1e3))}),`updateSearch`)(t),o&&setTimeout(()=>o.focus())},`handleTypeaheadSearch`);v.useEffect(()=>()=>window.clearTimeout(E.current),[]),Su();let M=v.useCallback(e=>k.current===O.current?.side&&n_(e,O.current?.area),[]);return(0,I.jsx)(wg,{scope:n,searchRef:ee,onItemEnter:v.useCallback(e=>{M(e)&&e.preventDefault()},[M]),onItemLeave:v.useCallback(e=>{M(e)||(w.current?.focus(),C(null))},[M]),onTriggerLeave:v.useCallback(e=>{M(e)&&e.preventDefault()},[M]),pointerGraceTimerRef:D,onPointerGraceIntentChange:v.useCallback(e=>{O.current=e},[]),children:(0,I.jsx)(j,{...te,children:(0,I.jsx)(ru,{asChild:!0,trapped:i,onMountAutoFocus:G(a,e=>{e.preventDefault(),w.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:(0,I.jsx)(Gl,{asChild:!0,disableOutsidePointerEvents:s,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,children:(0,I.jsx)(Zh,{asChild:!0,...b,dir:_.dir,orientation:`vertical`,loop:r,currentTabStopId:S,onCurrentTabStopIdChange:C,onEntryFocus:G(c,e=>{_.isUsingKeyboardRef.current||e.preventDefault()}),preventScrollOnEntryFocus:!0,children:(0,I.jsx)(bh,{role:`menu`,"aria-orientation":`vertical`,"data-state":Yg(g.open),"data-radix-menu-content":``,dir:_.dir,...y,...h,ref:T,style:{outline:`none`,...h.style},onKeyDown:G(h.onKeyDown,e=>{let t=e.target.closest(`[data-radix-menu-content]`)===e.currentTarget,n=e.ctrlKey||e.altKey||e.metaKey,r=e.key.length===1;t&&(e.key===`Tab`&&e.preventDefault(),!n&&r&&ne(e.key));let i=w.current;if(e.target!==i||!ig.includes(e.key))return;e.preventDefault();let a=x().filter(e=>!e.disabled).map(e=>e.ref.current);rg.includes(e.key)&&a.reverse(),Qg(a)}),onBlur:G(e.onBlur,e=>{e.currentTarget.contains(e.target)||(window.clearTimeout(E.current),ee.current=``)}),onPointerMove:G(e.onPointerMove,r_(e=>{let t=e.target,n=A.current!==e.clientX;if(e.currentTarget.contains(t)&&n){let t=e.clientX>A.current?`right`:`left`;k.current=t,A.current=e.clientX}}))})})})})})})},`MenuContentImpl`)),jg=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,...r}=e;return(0,I.jsx)(W.div,{role:`group`,...r,ref:t})},`MenuGroup`)),Mg=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,...r}=e;return(0,I.jsx)(W.div,{...r,ref:t})},`MenuLabel`)),Ng=`MenuItem`,Pg=`menu.itemSelect`,Fg=v.forwardRef(eg(function(e,t){let{disabled:n=!1,onSelect:r,...i}=e,a=v.useRef(null),o=gg(Ng,e.__scopeMenu),s=Tg(Ng,e.__scopeMenu),c=uc(t,a),l=v.useRef(!1),u=eg(()=>{let e=a.current;if(!n&&e){let t=new CustomEvent(Pg,{bubbles:!0,cancelable:!0});e.addEventListener(Pg,e=>r?.(e),{once:!0}),kc(e,t),t.defaultPrevented?l.current=!1:o.onClose()}},`handleSelect`);return(0,I.jsx)(Ig,{...i,ref:c,disabled:n,onClick:G(e.onClick,u),onPointerDown:t=>{e.onPointerDown?.(t),l.current=!0},onPointerUp:G(e.onPointerUp,e=>{l.current||e.currentTarget?.click()}),onKeyDown:G(e.onKeyDown,e=>{n||e.target!==e.currentTarget||s.searchRef.current!==``&&e.key===` `||tg.includes(e.key)&&(e.currentTarget.click(),e.preventDefault())})})},`MenuItem`)),Ig=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,disabled:r=!1,textValue:i,...a}=e,o=Tg(Ng,n),s=fg(n),c=v.useRef(null),l=uc(t,c),[u,d]=v.useState(!1),[f,p]=v.useState(``);return v.useEffect(()=>{let e=c.current;e&&p((e.textContent??``).trim())},[a.children]),(0,I.jsx)(og.ItemSlot,{scope:n,disabled:r,textValue:i??f,children:(0,I.jsx)(Qh,{asChild:!0,...s,focusable:!r,children:(0,I.jsx)(W.div,{role:`menuitem`,"data-highlighted":u?``:void 0,"aria-disabled":r||void 0,"data-disabled":r?``:void 0,...a,ref:l,onPointerMove:G(e.onPointerMove,r_(e=>{r?o.onItemLeave(e):(o.onItemEnter(e),e.defaultPrevented||e.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:G(e.onPointerLeave,r_(e=>o.onItemLeave(e))),onFocus:G(e.onFocus,()=>d(!0)),onBlur:G(e.onBlur,()=>d(!1))})})})},`MenuItemImpl`)),[Lg,Rg]=lg(`MenuRadioGroup`,{value:void 0,onValueChange:eg(()=>{},`onValueChange`)}),zg=v.forwardRef(eg(function(e,t){let{value:n,onValueChange:r,...i}=e,a=K(r);return(0,I.jsx)(Lg,{scope:e.__scopeMenu,value:n,onValueChange:a,children:(0,I.jsx)(jg,{...i,ref:t})})},`MenuRadioGroup`)),Bg=`MenuRadioItem`,Vg=v.forwardRef(eg(function(e,t){let{value:n,...r}=e,i=Rg(Bg,e.__scopeMenu),a=n===i.value;return(0,I.jsx)(Ug,{scope:e.__scopeMenu,checked:a,children:(0,I.jsx)(Fg,{role:`menuitemradio`,"aria-checked":a,...r,ref:t,"data-state":Zg(a),onSelect:G(r.onSelect,()=>i.onValueChange?.(n),{checkForDefaultPrevented:!1})})})},`MenuRadioItem`)),Hg=`MenuItemIndicator`,[Ug,Wg]=lg(Hg,{checked:!1}),Gg=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,forceMount:r,...i}=e,a=Wg(Hg,n);return(0,I.jsx)(Sl,{present:r||Xg(a.checked)||a.checked===!0,children:(0,I.jsx)(W.span,{...i,ref:t,"data-state":Zg(a.checked)})})},`MenuItemIndicator`)),Kg=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,...r}=e;return(0,I.jsx)(W.div,{role:`separator`,"aria-orientation":`horizontal`,...r,ref:t})},`MenuSeparator`)),[qg,Jg]=lg(`MenuSub`);function Yg(e){return e?`open`:`closed`}eg(Yg,`getOpenState`);function Xg(e){return e===`indeterminate`}eg(Xg,`isIndeterminate`);function Zg(e){return Xg(e)?`indeterminate`:e?`checked`:`unchecked`}eg(Zg,`getCheckedState`);function Qg(e){let t=document.activeElement;for(let n of e)if(n===t||(n.focus(),document.activeElement!==t))return}eg(Qg,`focusFirst`);function $g(e,t){return e.map((n,r)=>e[(t+r)%e.length])}eg($g,`wrapArray`);function e_(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=$g(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}eg(e_,`getNextMatch`);function t_(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}eg(t_,`isPointInPolygon`);function n_(e,t){return t?t_({x:e.clientX,y:e.clientY},t):!1}eg(n_,`isPointerInGraceArea`);function r_(e){return t=>t.pointerType===`mouse`?e(t):void 0}eg(r_,`whenMouse`);var i_=_g,a_=vg,o_=Sg,s_=Eg,c_=Mg,l_=Fg,u_=zg,d_=Vg,f_=Gg,p_=Kg,m_=Object.defineProperty,h_=(e,t)=>m_(e,`name`,{value:t,configurable:!0}),g_=`DropdownMenu`,[__,v_]=Lc(g_,[ug]),y_=ug(),[b_,x_]=__(g_),S_=h_(e=>{let{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:a,onOpenChange:o,modal:s=!0}=e,c=y_(t),l=v.useRef(null),[u,d]=ml({prop:i,defaultProp:a??!1,onChange:o,caller:g_});return(0,I.jsx)(b_,{scope:t,triggerId:Ml(),triggerRef:l,contentId:Ml(),open:u,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(e=>!e),[d]),modal:s,children:(0,I.jsx)(i_,{...c,open:u,onOpenChange:d,dir:r,modal:s,children:n})})},`DropdownMenu`),C_=`DropdownMenuTrigger`,w_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,a=x_(C_,n),o=y_(n),s=uc(t,a.triggerRef);return(0,I.jsx)(a_,{asChild:!0,...o,children:(0,I.jsx)(W.button,{type:`button`,id:a.triggerId,"aria-haspopup":`menu`,"aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":a.open?`open`:`closed`,"data-disabled":r?``:void 0,disabled:r,...i,ref:s,onPointerDown:G(e.onPointerDown,e=>{!r&&e.button===0&&e.ctrlKey===!1&&(a.onOpenToggle(),a.open||e.preventDefault())}),onKeyDown:G(e.onKeyDown,e=>{r||([`Enter`,` `].includes(e.key)&&a.onOpenToggle(),e.key===`ArrowDown`&&a.onOpenChange(!0),[`Enter`,` `,`ArrowDown`].includes(e.key)&&e.preventDefault())})})})},`DropdownMenuTrigger`)),T_=h_(e=>{let{__scopeDropdownMenu:t,...n}=e,r=y_(t);return(0,I.jsx)(o_,{...r,...n})},`DropdownMenuPortal`),E_=`DropdownMenuContent`,D_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=x_(E_,n),a=y_(n),o=v.useRef(!1);return(0,I.jsx)(s_,{id:i.contentId,"aria-labelledby":i.triggerId,...a,...r,ref:t,onCloseAutoFocus:G(e.onCloseAutoFocus,e=>{o.current||i.triggerRef.current?.focus(),o.current=!1,e.preventDefault()}),onInteractOutside:G(e.onInteractOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0,r=t.button===2||n;(!i.modal||r)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-dropdown-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-dropdown-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-dropdown-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-dropdown-menu-trigger-height":`var(--radix-popper-anchor-height)`}})},`DropdownMenuContent`)),O_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=y_(n);return(0,I.jsx)(c_,{...i,...r,ref:t})},`DropdownMenuLabel`)),k_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=y_(n);return(0,I.jsx)(l_,{...i,...r,ref:t})},`DropdownMenuItem`)),A_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=y_(n);return(0,I.jsx)(u_,{...i,...r,ref:t})},`DropdownMenuRadioGroup`)),j_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=y_(n);return(0,I.jsx)(d_,{...i,...r,ref:t})},`DropdownMenuRadioItem`)),M_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=y_(n);return(0,I.jsx)(f_,{...i,...r,ref:t})},`DropdownMenuItemIndicator`)),N_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=y_(n);return(0,I.jsx)(p_,{...i,...r,ref:t})},`DropdownMenuSeparator`)),P_=S_,F_=w_,I_=T_,L_=D_,R_=O_,z_=k_,B_=A_,V_=j_,H_=M_,U_=N_,W_=Object.defineProperty,G_=v.forwardRef(((e,t)=>W_(e,`name`,{value:t,configurable:!0}))(function(e,t){return(0,I.jsx)(W.label,{...e,ref:t,onMouseDown:t=>{t.target.closest(`button, input, select, textarea`)||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}})},`Label`)),K_=Object.defineProperty,q_=(e,t)=>K_(e,`name`,{value:t,configurable:!0});function J_(e){let t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}q_(J_,`usePrevious`);var Y_=Object.defineProperty,X_=(e,t)=>Y_(e,`name`,{value:t,configurable:!0});function Z_(e,[t,n]){return Math.min(n,Math.max(t,e))}X_(Z_,`clamp`);var Q_=Object.defineProperty,$_=(e,t)=>Q_(e,`name`,{value:t,configurable:!0}),ev=[` `,`Enter`,`ArrowUp`,`ArrowDown`],tv=[` `,`Enter`],nv=`Select`,[rv,iv,av]=Vc(nv),[ov,sv]=Lc(nv,[av,nh]),cv=nh(),[lv,uv]=ov(nv),[dv,fv]=ov(nv);function pv(e){let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:a,value:o,defaultValue:s,onValueChange:c,dir:l,name:u,autoComplete:d,disabled:f,required:p,form:m,internal_do_not_use_render:h}=e,g=cv(t),[_,y]=v.useState(null),[b,x]=v.useState(null),[S,C]=v.useState(!1),w=Il(l),[T,E]=ml({prop:r,defaultProp:i??!1,onChange:a,caller:nv}),[ee,D]=ml({prop:o,defaultProp:s,onChange:c,caller:nv}),O=v.useRef(null),k=v.useRef(ee);v.useEffect(()=>{let e=m?_?.ownerDocument.getElementById(m):_?.form;if(e instanceof HTMLFormElement){let t=$_(()=>D(k.current),`reset`);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[m,_,D]);let A=!_||!!m||!!_.closest(`form`),[j,te]=v.useState(new Set),ne=Ml(),M=Array.from(j).map(e=>e.props.value).join(`;`),N=v.useCallback(e=>{te(t=>new Set(t).add(e))},[]),P=v.useCallback(e=>{te(t=>{let n=new Set(t);return n.delete(e),n})},[]),re={required:p,trigger:_,onTriggerChange:y,valueNode:b,onValueNodeChange:x,valueNodeHasChildren:S,onValueNodeHasChildrenChange:C,contentId:ne,value:ee,onValueChange:D,open:T,onOpenChange:E,dir:w,triggerPointerDownPosRef:O,disabled:f,name:u,autoComplete:d,form:m,nativeOptions:j,nativeSelectKey:M,isFormControl:A};return(0,I.jsx)(vh,{...g,children:(0,I.jsx)(lv,{scope:t,...re,children:(0,I.jsx)(rv.Provider,{scope:t,children:(0,I.jsx)(dv,{scope:t,onNativeOptionAdd:N,onNativeOptionRemove:P,children:ty(h)?h(re):n})})})})}$_(pv,`SelectProvider`);var mv=$_(e=>{let{__scopeSelect:t,children:n,...r}=e;return(0,I.jsx)(pv,{__scopeSelect:t,...r,internal_do_not_use_render:({isFormControl:e})=>(0,I.jsxs)(I.Fragment,{children:[n,e?(0,I.jsx)(ey,{__scopeSelect:t}):null]})})},`Select`),hv=`SelectTrigger`,gv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,disabled:r=!1,...i}=e,a=cv(n),o=uv(hv,n),s=o.disabled||r,c=uc(t,o.onTriggerChange),l=iv(n),u=v.useRef(`touch`),[d,f,p]=ry(e=>{let t=l().filter(e=>!e.disabled),n=iy(t,e,t.find(e=>e.value===o.value));n!==void 0&&o.onValueChange(n.value)}),m=$_(e=>{s||(o.onOpenChange(!0),p()),e&&(o.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})},`handleOpen`);return(0,I.jsx)(yh,{asChild:!0,...a,children:(0,I.jsx)(W.button,{type:`button`,role:`combobox`,"aria-controls":o.open?o.contentId:void 0,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":`none`,dir:o.dir,"data-state":o.open?`open`:`closed`,disabled:s,"data-disabled":s?``:void 0,"data-placeholder":ny(o.value)?``:void 0,...i,ref:c,onClick:G(i.onClick,e=>{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:G(i.onPointerDown,e=>{u.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(m(e),e.preventDefault())}),onKeyDown:G(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&ev.includes(e.key)&&(m(),e.preventDefault())})})})},`SelectTrigger`)),_v=`SelectValue`,vv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=uv(_v,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=uc(t,c.onValueNodeChange);al(()=>{l(u)},[l,u]);let f=ny(c.value);return(0,I.jsx)(W.span,{...s,asChild:!f&&s.asChild,ref:d,style:{pointerEvents:`none`},children:(0,I.jsx)(v.Fragment,{children:f?o:a},f?`placeholder`:`value`)})},`SelectValue`)),yv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,children:r,...i}=e;return(0,I.jsx)(W.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})},`SelectIcon`)),[bv,xv]=ov(`SelectPortal`,{forceMount:void 0}),Sv=$_(e=>{let{__scopeSelect:t,forceMount:n,...r}=e;return(0,I.jsx)(bv,{scope:e.__scopeSelect,forceMount:n,children:(0,I.jsx)(gu,{asChild:!0,...r})})},`SelectPortal`),Cv=`SelectContent`,wv=v.forwardRef($_(function(e,t){let n=xv(Cv,e.__scopeSelect),{forceMount:r=n.forceMount,...i}=e,a=uv(Cv,e.__scopeSelect),[o,s]=v.useState();return al(()=>{s(new DocumentFragment)},[]),(0,I.jsx)(Sl,{present:r||a.open,children:({present:e})=>e?(0,I.jsx)(Av,{...i,ref:t}):(0,I.jsx)(Tv,{...i,fragment:o})})},`SelectContent`)),Tv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,children:r,fragment:i}=e;return i?y.createPortal((0,I.jsx)(Dv,{scope:n,children:(0,I.jsx)(rv.Slot,{scope:n,children:(0,I.jsx)(`div`,{ref:t,children:r})})}),i):null},`SelectContentFragment`)),Ev=10,[Dv,Ov]=ov(Cv),kv=pc(`SelectContent.RemoveScroll`),Av=v.forwardRef($_(function(e,t){let{__scopeSelect:n}=e,{position:r=`item-aligned`,onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g,..._}=e,y=uv(Cv,n),[b,x]=v.useState(null),[S,C]=v.useState(null),w=uc(t,x),[T,E]=v.useState(null),[ee,D]=v.useState(null),O=iv(n),[k,A]=v.useState(!1),j=v.useRef(!1);v.useEffect(()=>{if(b)return Bd(b)},[b]),Su();let te=v.useCallback(e=>{let[t,...n]=O().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&S&&(S.scrollTop=0),n===r&&S&&(S.scrollTop=S.scrollHeight),n?.focus(),document.activeElement!==i))return},[O,S]),ne=v.useCallback(()=>te([T,b]),[te,T,b]);v.useEffect(()=>{k&&ne()},[k,ne]);let{onOpenChange:M,triggerPointerDownPosRef:N}=y;v.useEffect(()=>{if(b){let e={x:0,y:0},t=$_(t=>{e={x:Math.abs(Math.round(t.pageX)-(N.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(N.current?.y??0))}},`handlePointerMove`),n=$_(n=>{e.x<=10&&e.y<=10?n.preventDefault():n.composedPath().includes(b)||M(!1),document.removeEventListener(`pointermove`,t),N.current=null},`handlePointerUp`);return N.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[b,M,N]),v.useEffect(()=>{let e=$_(()=>M(!1),`close`);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[M]);let[P,re]=ry(e=>{let t=O().filter(e=>!e.disabled),n=iy(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current?.focus())}),ie=v.useCallback((e,t,n)=>{let r=!j.current&&!n;(y.value!==void 0&&y.value===t||r)&&(E(e),r&&(j.current=!0))},[y.value]),ae=v.useCallback(()=>b?.focus(),[b]),oe=v.useCallback((e,t,n)=>{let r=!j.current&&!n;(y.value!==void 0&&y.value===t||r)&&D(e)},[y.value]),F=r===`popper`?Mv:jv,se=F===Mv?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,I.jsx)(Dv,{scope:n,content:b,viewport:S,onViewportChange:C,itemRefCallback:ie,selectedItem:T,onItemLeave:ae,itemTextRefCallback:oe,focusSelectedItem:ne,selectedItemText:ee,position:r,isPositioned:k,searchRef:P,children:(0,I.jsx)(jd,{as:kv,allowPinchZoom:!0,children:(0,I.jsx)(ru,{asChild:!0,trapped:y.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:G(i,e=>{y.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,I.jsx)(Gl,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>y.onOpenChange(!1),children:(0,I.jsx)(F,{role:`listbox`,id:y.contentId,"data-state":y.open?`open`:`closed`,dir:y.dir,onContextMenu:e=>e.preventDefault(),..._,...se,onPlaced:()=>A(!0),ref:w,style:{display:`flex`,flexDirection:`column`,outline:`none`,..._.style},onKeyDown:G(_.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&re(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=O().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>te(t)),e.preventDefault()}})})})})})})},`SelectContentImpl`)),jv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,onPlaced:r,...i}=e,a=uv(Cv,n),o=Ov(Cv,n),[s,c]=v.useState(null),[l,u]=v.useState(null),d=uc(t,u),f=iv(n),p=v.useRef(!1),m=v.useRef(!0),{viewport:h,selectedItem:g,selectedItemText:_,focusSelectedItem:y}=o,b=v.useCallback(()=>{if(a.trigger&&a.valueNode&&s&&l&&h&&g&&_){let e=a.trigger.getBoundingClientRect(),t=l.getBoundingClientRect(),n=a.valueNode.getBoundingClientRect(),i=_.getBoundingClientRect();if(a.dir!==`rtl`){let r=i.left-t.left,a=n.left-r,o=e.left-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-Ev,d=Z_(a,[Ev,Math.max(Ev,u-l)]);s.style.minWidth=c+`px`,s.style.left=d+`px`}else{let r=t.right-i.right,a=window.innerWidth-n.right-r,o=window.innerWidth-e.right-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-Ev,d=Z_(a,[Ev,Math.max(Ev,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-Ev*2,u=h.scrollHeight,d=window.getComputedStyle(l),m=parseInt(d.borderTopWidth,10),v=parseInt(d.paddingTop,10),y=parseInt(d.borderBottomWidth,10),b=parseInt(d.paddingBottom,10),x=m+v+u+b+y,S=Math.min(g.offsetHeight*5,x),C=window.getComputedStyle(h),w=parseInt(C.paddingTop,10),T=parseInt(C.paddingBottom,10),E=e.top+e.height/2-Ev,ee=c-E,D=g.offsetHeight/2,O=g.offsetTop+D,k=m+v+O,A=x-k;if(k<=E){let e=o.length>0&&g===o[o.length-1].ref.current;s.style.bottom=`0px`;let t=l.clientHeight-h.offsetTop-h.offsetHeight,n=k+Math.max(ee,D+(e?T:0)+t+y);s.style.height=n+`px`}else{let e=o.length>0&&g===o[0].ref.current;s.style.top=`0px`;let t=Math.max(E,m+h.offsetTop+(e?w:0)+D)+A;s.style.height=t+`px`,h.scrollTop=k-E+h.offsetTop}s.style.margin=`${Ev}px 0`,s.style.minHeight=S+`px`,s.style.maxHeight=c+`px`,r?.(),requestAnimationFrame(()=>p.current=!0)}},[f,a.trigger,a.valueNode,s,l,h,g,_,a.dir,r]);al(()=>b(),[b]);let[x,S]=v.useState();return al(()=>{l&&S(window.getComputedStyle(l).zIndex)},[l]),(0,I.jsx)(Nv,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:p,onScrollButtonChange:v.useCallback(e=>{e&&m.current===!0&&(b(),y?.(),m.current=!1)},[b,y]),children:(0,I.jsx)(`div`,{ref:c,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:x},children:(0,I.jsx)(W.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})},`SelectItemAlignedPosition`)),Mv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,align:r=`start`,collisionPadding:i=Ev,...a}=e,o=cv(n);return(0,I.jsx)(bh,{...o,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})},`SelectPopperPosition`)),[Nv,Pv]=ov(Cv,{}),Fv=`SelectViewport`,Iv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,nonce:r,...i}=e,a=Ov(Fv,n),o=Pv(Fv,n),s=uc(t,a.onViewportChange),c=v.useRef(0);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:r}),(0,I.jsx)(rv.Slot,{scope:n,children:(0,I.jsx)(W.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:G(i.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=o;if(r?.current&&n){let e=Math.abs(c.current-t.scrollTop);if(e>0){let r=window.innerHeight-Ev*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}c.current=t.scrollTop})})})]})},`SelectViewport`)),[Lv,Rv]=ov(`SelectGroup`),zv=`SelectItem`,[Bv,Vv]=ov(zv),Hv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=uv(zv,n),c=Ov(zv,n),l=s.value===r,[u,d]=v.useState(a??``),[f,p]=v.useState(!1),m=uc(t,K(e=>c.itemRefCallback?.(e,r,i))),h=Ml(),g=v.useRef(`touch`),_=$_(()=>{i||(s.onValueChange(r),s.onOpenChange(!1))},`handleSelect`);return(0,I.jsx)(Bv,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:v.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,I.jsx)(rv.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,I.jsx)(W.div,{role:`option`,"aria-labelledby":h,"data-highlighted":f?``:void 0,"aria-selected":l&&f,"data-state":l?`checked`:`unchecked`,"aria-disabled":i||void 0,"data-disabled":i?``:void 0,tabIndex:i?void 0:-1,...o,ref:m,onFocus:G(o.onFocus,()=>p(!0)),onBlur:G(o.onBlur,()=>p(!1)),onClick:G(o.onClick,()=>{g.current!==`mouse`&&_()}),onPointerUp:G(o.onPointerUp,()=>{g.current===`mouse`&&_()}),onPointerDown:G(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:G(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:G(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:G(o.onKeyDown,e=>{i||e.target!==e.currentTarget||c.searchRef?.current!==``&&e.key===` `||(tv.includes(e.key)&&_(),e.key===` `&&e.preventDefault())})})})})},`SelectItem`)),Uv=`SelectItemText`,Wv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,className:r,style:i,...a}=e,o=uv(Uv,n),s=Ov(Uv,n),c=Vv(Uv,n),l=fv(Uv,n),[u,d]=v.useState(null),f=K(e=>s.itemTextRefCallback?.(e,c.value,c.disabled)),p=uc(t,d,c.onItemTextChange,f),m=u?.textContent,h=v.useMemo(()=>(0,I.jsx)(`option`,{value:c.value,disabled:c.disabled,children:m},c.value),[c.disabled,c.value,m]),{onNativeOptionAdd:g,onNativeOptionRemove:_}=l;return al(()=>(g(h),()=>_(h)),[g,_,h]),(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(W.span,{id:c.textId,...a,ref:p}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren&&!ny(o.value)?y.createPortal(a.children,o.valueNode):null]})},`SelectItemText`)),Gv=`SelectItemIndicator`,Kv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,...r}=e;return Vv(Gv,n).isSelected?(0,I.jsx)(W.span,{"aria-hidden":!0,...r,ref:t}):null},`SelectItemIndicator`)),qv=`SelectScrollUpButton`,Jv=v.forwardRef($_(function(e,t){let n=Ov(qv,e.__scopeSelect),r=Pv(qv,e.__scopeSelect),[i,a]=v.useState(!1),o=uc(t,r.onScrollButtonChange);return al(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollTop>0;a(e)};$_(e,`handleScroll`);let t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,I.jsx)(Zv,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null},`SelectScrollUpButton`)),Yv=`SelectScrollDownButton`,Xv=v.forwardRef($_(function(e,t){let n=Ov(Yv,e.__scopeSelect),r=Pv(Yv,e.__scopeSelect),[i,a]=v.useState(!1),o=uc(t,r.onScrollButtonChange);return al(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollHeight-t.clientHeight,n=Math.ceil(t.scrollTop)<e;a(n)};$_(e,`handleScroll`);let t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,I.jsx)(Zv,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null},`SelectScrollDownButton`)),Zv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,onAutoScroll:r,...i}=e,a=Ov(`SelectScrollButton`,n),o=v.useRef(null),s=iv(n),c=v.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return v.useEffect(()=>()=>c(),[c]),al(()=>{s().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[s]),(0,I.jsx)(W.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:G(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:G(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:G(i.onPointerLeave,()=>{c()})})},`SelectScrollButtonImpl`)),Qv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,...r}=e;return(0,I.jsx)(W.div,{"aria-hidden":!0,...r,ref:t})},`SelectSeparator`)),$v=`SelectBubbleInput`,ey=v.forwardRef($_(function({__scopeSelect:e,...t},n){let r=uv($v,e),{value:i,onValueChange:a,required:o,disabled:s,name:c,autoComplete:l,form:u}=r,{nativeOptions:d,nativeSelectKey:f}=r,p=v.useRef(null),m=uc(n,p),h=i??``,g=J_(h),_=Array.from(d).some(e=>(e.props.value??``)===``);return v.useEffect(()=>{let e=p.current;if(!e)return;let t=window.HTMLSelectElement.prototype,n=Object.getOwnPropertyDescriptor(t,`value`).set;if(g!==h&&n){let t=new Event(`change`,{bubbles:!0});n.call(e,h),e.dispatchEvent(t)}},[g,h]),(0,I.jsxs)(W.select,{"aria-hidden":!0,required:o,tabIndex:-1,name:c,autoComplete:l,disabled:s,form:u,onChange:e=>a(e.target.value),...t,style:{...Mc,...t.style},ref:m,defaultValue:h,children:[ny(i)&&!_?(0,I.jsx)(`option`,{value:``}):null,Array.from(d)]},f)},`SelectBubbleInput`));function ty(e){return typeof e==`function`}$_(ty,`isFunction`);function ny(e){return e===``||e===void 0}$_(ny,`shouldShowPlaceholder`);function ry(e){let t=K(e),n=v.useRef(``),r=v.useRef(0),i=v.useCallback(e=>{let i=n.current+e;t(i),$_((function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))}),`updateSearch`)(i)},[t]),a=v.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}$_(ry,`useTypeaheadSearch`);function iy(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=ay(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}$_(iy,`findNextItem`);function ay(e,t){return e.map((n,r)=>e[(t+r)%e.length])}$_(ay,`wrapArray`);var oy=Object.defineProperty,sy=(e,t)=>oy(e,`name`,{value:t,configurable:!0}),cy=`Switch`,[ly,uy]=Lc(cy),[dy,fy]=ly(cy);function py(e){let{__scopeSwitch:t,checked:n,children:r,defaultChecked:i,disabled:a,form:o,name:s,onCheckedChange:c,required:l,value:u=`on`,internal_do_not_use_render:d}=e,[f,p]=ml({prop:n,defaultProp:i??!1,onChange:c,caller:cy}),[m,h]=v.useState(null),[g,_]=v.useState(null),y=v.useRef(!1),[b,x]=v.useReducer(e=>e+1,0),S={checked:f,setChecked:p,disabled:a,control:m,setControl:h,name:s,form:o,value:u,hasConsumerStoppedPropagationRef:y,userInteractionCount:b,onUserInteraction:x,required:l,defaultChecked:i,isFormControl:!m||!!o||!!m.closest(`form`),bubbleInput:g,setBubbleInput:_};return(0,I.jsx)(dy,{scope:t,...S,children:xy(d)?d(S):r})}sy(py,`SwitchProvider`);var my=`SwitchTrigger`,hy=v.forwardRef(sy(function({__scopeSwitch:e,onClick:t,...n},r){let{control:i,form:a,value:o,disabled:s,checked:c,required:l,setControl:u,setChecked:d,hasConsumerStoppedPropagationRef:f,onUserInteraction:p,isFormControl:m,bubbleInput:h}=fy(my,e),g=uc(r,u),_=v.useRef(c);return v.useEffect(()=>{let e=a?i?.ownerDocument.getElementById(a):i?.form;if(e instanceof HTMLFormElement){let t=sy(()=>d(_.current),`reset`);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[i,a,d]),(0,I.jsx)(W.button,{type:`button`,role:`switch`,"aria-checked":c,"aria-required":l,"data-state":Sy(c),"data-disabled":s?``:void 0,disabled:s,value:o,...n,ref:g,onClick:G(t,e=>{p(),d(e=>!e),h&&m&&(f.current=e.isPropagationStopped(),f.current||e.stopPropagation())})})},`SwitchTrigger`)),gy=v.forwardRef(sy(function(e,t){let{__scopeSwitch:n,name:r,checked:i,defaultChecked:a,required:o,disabled:s,value:c,onCheckedChange:l,form:u,...d}=e;return(0,I.jsx)(py,{__scopeSwitch:n,checked:i,defaultChecked:a,disabled:s,required:o,onCheckedChange:l,name:r,form:u,value:c,internal_do_not_use_render:({isFormControl:e})=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(hy,{...d,ref:t,__scopeSwitch:n}),e&&(0,I.jsx)(by,{__scopeSwitch:n})]})})},`Switch`)),_y=`SwitchThumb`,vy=v.forwardRef(sy(function(e,t){let{__scopeSwitch:n,...r}=e,i=fy(_y,n);return(0,I.jsx)(W.span,{"data-state":Sy(i.checked),"data-disabled":i.disabled?``:void 0,...r,ref:t})},`SwitchThumb`)),yy=`SwitchBubbleInput`,by=v.forwardRef(sy(function({__scopeSwitch:e,onClick:t,...n},r){let{control:i,hasConsumerStoppedPropagationRef:a,userInteractionCount:o,checked:s,defaultChecked:c,required:l,disabled:u,name:d,value:f,form:p,bubbleInput:m,setBubbleInput:h}=fy(yy,e),g=uc(r,h),_=bf(i),y=v.useRef(!1),b=v.useRef(s),x=v.useRef(o);v.useEffect(()=>{let e=m;if(!e)return;let t=window.HTMLInputElement.prototype,n=Object.getOwnPropertyDescriptor(t,`checked`).set,r=o!==x.current;x.current=o;let i=b.current!==s;b.current=s;let c=!(r&&a.current);if(i&&n){y.current=!r;let t=new Event(`click`,{bubbles:c});n.call(e,s),e.dispatchEvent(t),y.current=!1}},[m,s,a,o]);let S=v.useRef(s);return(0,I.jsx)(W.input,{type:`checkbox`,"aria-hidden":!0,defaultChecked:c??S.current,required:l,disabled:u,name:d,value:f,form:p,...n,tabIndex:-1,ref:g,onClick:G(t,e=>{y.current&&e.stopPropagation()}),style:{...n.style,..._,position:`absolute`,pointerEvents:`none`,opacity:0,margin:0,transform:`translateX(-100%)`}})},`SwitchBubbleInput`));function xy(e){return typeof e==`function`}sy(xy,`isFunction`);function Sy(e){return e?`checked`:`unchecked`}sy(Sy,`getState`);var Cy=Object.defineProperty,wy=(e,t)=>Cy(e,`name`,{value:t,configurable:!0}),Ty=`Tabs`,[Ey,Dy]=Lc(Ty,[zh]),Oy=zh(),[ky,Ay]=Ey(Ty),jy=v.forwardRef(wy(function(e,t){let{__scopeTabs:n,value:r,onValueChange:i,defaultValue:a,orientation:o=`horizontal`,dir:s,activationMode:c=`automatic`,...l}=e,u=Il(s),[d,f]=ml({prop:r,onChange:i,defaultProp:a??``,caller:Ty});return(0,I.jsx)(ky,{scope:n,baseId:Ml(),value:d,onValueChange:f,orientation:o,dir:u,activationMode:c,children:(0,I.jsx)(W.div,{dir:u,"data-orientation":o,...l,ref:t})})},`Tabs`)),My=`TabsList`,Ny=v.forwardRef(wy(function(e,t){let{__scopeTabs:n,loop:r=!0,...i}=e,a=Ay(My,n),o=Oy(n);return(0,I.jsx)(Zh,{asChild:!0,...o,orientation:a.orientation,dir:a.dir,loop:r,children:(0,I.jsx)(W.div,{role:`tablist`,"aria-orientation":a.orientation,...i,ref:t})})},`TabsList`)),Py=`TabsTrigger`,Fy=v.forwardRef(wy(function(e,t){let{__scopeTabs:n,value:r,disabled:i=!1,...a}=e,o=Ay(Py,n),s=Oy(n),c=Iy(o.baseId,r),l=Ly(o.baseId,r),u=r===o.value;return(0,I.jsx)(Qh,{asChild:!0,...s,focusable:!i,active:u,children:(0,I.jsx)(W.button,{type:`button`,role:`tab`,"aria-selected":u,"aria-controls":l,"data-state":u?`active`:`inactive`,"data-disabled":i?``:void 0,disabled:i,id:c,...a,ref:t,onMouseDown:G(e.onMouseDown,e=>{!i&&e.button===0&&e.ctrlKey===!1?o.onValueChange(r):e.preventDefault()}),onKeyDown:G(e.onKeyDown,e=>{i||e.target!==e.currentTarget||[` `,`Enter`].includes(e.key)&&o.onValueChange(r)}),onFocus:G(e.onFocus,()=>{let e=o.activationMode!==`manual`;!u&&!i&&e&&o.onValueChange(r)})})})},`TabsTrigger`));function Iy(e,t){return`${e}-trigger-${t}`}wy(Iy,`makeTriggerId`);function Ly(e,t){return`${e}-content-${t}`}wy(Ly,`makeContentId`);var Ry=jy,zy=Ny,By=Fy,Vy=Object.defineProperty,Hy=(e,t)=>Vy(e,`name`,{value:t,configurable:!0}),[Uy,Wy]=Lc(`Tooltip`,[nh]),Gy=nh(),Ky=`TooltipProvider`,qy=700,Jy=`tooltip.open`,[Yy,Xy]=Uy(Ky),Zy=Hy(e=>{let{__scopeTooltip:t,delayDuration:n=qy,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=v.useRef(!0),s=v.useRef(!1),c=v.useRef(0);return v.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,I.jsx)(Yy,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:v.useCallback(()=>{r<=0||(window.clearTimeout(c.current),o.current=!1)},[r]),onClose:v.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r))},[r]),isPointerInTransitRef:s,onPointerInTransitChange:v.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})},`TooltipProvider`),Qy=`Tooltip`,[$y,eb]=Uy(Qy),tb=Hy(e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=Xy(Qy,e.__scopeTooltip),l=Gy(t),[u,d]=v.useState(null),[f,p]=v.useState(void 0),m=Ml(),h=v.useRef(0),g=o??c.disableHoverableContent,_=s??c.delayDuration,y=v.useRef(!1),[b,x]=ml({prop:r,defaultProp:i??!1,onChange:Hy(e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(Jy))):c.onClose(),a?.(e)},`onChange`),caller:Qy}),S=v.useMemo(()=>b?y.current?`delayed-open`:`instant-open`:`closed`,[b]),C=v.useCallback(()=>{window.clearTimeout(h.current),h.current=0,y.current=!1,x(!0)},[x]),w=v.useCallback(()=>{window.clearTimeout(h.current),h.current=0,x(!1)},[x]),T=v.useCallback(()=>{window.clearTimeout(h.current),h.current=window.setTimeout(()=>{y.current=!0,x(!0),h.current=0},_)},[_,x]);v.useEffect(()=>()=>{h.current&&=(window.clearTimeout(h.current),0)},[]);let E=f??m;return(0,I.jsx)(vh,{...l,children:(0,I.jsx)($y,{scope:t,contentId:E,setContentId:p,open:b,stateAttribute:S,trigger:u,onTriggerChange:d,onTriggerEnter:v.useCallback(()=>{c.isOpenDelayedRef.current?T():C()},[c.isOpenDelayedRef,T,C]),onTriggerLeave:v.useCallback(()=>{g?w():(window.clearTimeout(h.current),h.current=0)},[w,g]),onOpen:C,onClose:w,disableHoverableContent:g,children:n})})},`Tooltip`),nb=`TooltipTrigger`,rb=v.forwardRef(Hy(function(e,t){let{__scopeTooltip:n,...r}=e,i=eb(nb,n),a=Xy(nb,n),o=Gy(n),s=uc(t,v.useRef(null),i.onTriggerChange),c=v.useRef(!1),l=v.useRef(!1),u=v.useCallback(()=>c.current=!1,[]);return v.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,I.jsx)(yh,{asChild:!0,...o,children:(0,I.jsx)(W.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:G(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:G(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:G(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:G(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:G(e.onBlur,i.onClose),onClick:G(e.onClick,i.onClose)})})},`TooltipTrigger`)),ib=`TooltipPortal`,[ab,ob]=Uy(ib,{forceMount:void 0}),sb=Hy(e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=eb(ib,t);return(0,I.jsx)(ab,{scope:t,forceMount:n,children:(0,I.jsx)(Sl,{present:n||a.open,children:(0,I.jsx)(gu,{asChild:!0,container:i,children:r})})})},`TooltipPortal`),cb=`TooltipContent`,lb=v.forwardRef(Hy(function(e,t){let n=ob(cb,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=eb(cb,e.__scopeTooltip);return(0,I.jsx)(Sl,{present:r||o.open,children:o.disableHoverableContent?(0,I.jsx)(fb,{side:i,...a,ref:t}):(0,I.jsx)(ub,{side:i,...a,ref:t})})},`TooltipContent`)),ub=v.forwardRef(Hy(function(e,t){let n=eb(cb,e.__scopeTooltip),r=Xy(cb,e.__scopeTooltip),i=v.useRef(null),a=uc(t,i),[o,s]=v.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=v.useCallback(()=>{s(null),d(!1)},[d]),p=v.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=hb(r,mb(r,n.getBoundingClientRect())),a=gb(t.getBoundingClientRect()),o=vb([...i,...a]);s(o),d(!0)},[d]);return v.useEffect(()=>()=>f(),[f]),v.useEffect(()=>{if(c&&u){let e=Hy(e=>p(e,u),`handleTriggerLeave`),t=Hy(e=>p(e,c),`handleContentLeave`);return c.addEventListener(`pointerleave`,e),u.addEventListener(`pointerleave`,t),()=>{c.removeEventListener(`pointerleave`,e),u.removeEventListener(`pointerleave`,t)}}},[c,u,p,f]),v.useEffect(()=>{if(o){let e=Hy(e=>{let t=e.target,n={x:e.clientX,y:e.clientY},r=c?.contains(t)||u?.contains(t),i=!_b(n,o);r?f():i&&(f(),l())},`handleTrackPointerGrace`);return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,I.jsx)(fb,{...e,ref:a})},`TooltipContentHoverable`)),db=gc(`TooltipContent`),fb=v.forwardRef(Hy(function(e,t){let{__scopeTooltip:n,children:r,"aria-label":i,id:a,onEscapeKeyDown:o,onPointerDownOutside:s,...c}=e,l=eb(cb,n),u=Gy(n),{onClose:d}=l;v.useEffect(()=>(document.addEventListener(Jy,d),()=>document.removeEventListener(Jy,d)),[d]),v.useEffect(()=>{if(l.trigger){let e=Hy(e=>{e.target instanceof Node&&e.target.contains(l.trigger)&&d()},`handleScroll`);return window.addEventListener(`scroll`,e,{capture:!0}),()=>window.removeEventListener(`scroll`,e,{capture:!0})}},[l.trigger,d]);let{setContentId:f}=l;return al(()=>(f(a),()=>{f(void 0)}),[a,f]),(0,I.jsx)(Gl,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:s,onFocusOutside:e=>e.preventDefault(),onDismiss:d,children:(0,I.jsxs)(bh,{"data-state":l.stateAttribute,role:i?void 0:`tooltip`,id:i?void 0:l.contentId,...u,...c,ref:t,style:{...c.style,"--radix-tooltip-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-tooltip-content-available-width":`var(--radix-popper-available-width)`,"--radix-tooltip-content-available-height":`var(--radix-popper-available-height)`,"--radix-tooltip-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-tooltip-trigger-height":`var(--radix-popper-anchor-height)`},children:[(0,I.jsx)(db,{children:r}),i?(0,I.jsx)(Nc,{id:l.contentId,role:`tooltip`,children:i}):null]})})},`TooltipContentImpl`)),pb=v.forwardRef(Hy(function(e,t){let{__scopeTooltip:n,...r}=e,i=Gy(n);return(0,I.jsx)(xh,{...i,...r,ref:t})},`TooltipArrow`));function mb(e,t){let n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),a=Math.abs(t.left-e.x);switch(Math.min(n,r,i,a)){case a:return`left`;case i:return`right`;case n:return`top`;case r:return`bottom`;default:throw Error(`unreachable`)}}Hy(mb,`getExitSideFromRect`);function hb(e,t,n=5){let r=[];switch(t){case`top`:r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case`bottom`:r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case`left`:r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case`right`:r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}Hy(hb,`getPaddedExitPoints`);function gb(e){let{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}Hy(gb,`getPointsFromRect`);function _b(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}Hy(_b,`isPointInPolygon`);function vb(e){let t=e.slice();return t.sort((e,t)=>e.x<t.x?-1:e.x>t.x?1:e.y<t.y?-1:+(e.y>t.y)),yb(t)}Hy(vb,`getHull`);function yb(e){if(e.length<=1)return e.slice();let t=[];for(let n=0;n<e.length;n++){let r=e[n];for(;t.length>=2;){let e=t[t.length-1],n=t[t.length-2];if((e.x-n.x)*(r.y-n.y)>=(e.y-n.y)*(r.x-n.x))t.pop();else break}t.push(r)}t.pop();let n=[];for(let t=e.length-1;t>=0;t--){let r=e[t];for(;n.length>=2;){let e=n[n.length-1],t=n[n.length-2];if((e.x-t.x)*(r.y-t.y)>=(e.y-t.y)*(r.x-t.x))n.pop();else break}n.push(r)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}Hy(yb,`getHullPresorted`);var bb=Zy,xb=tb,Sb=rb,Cb=sb,wb=lb,Tb=pb;function Eb({delayDuration:e=0,...t}){return(0,I.jsx)(bb,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function Db({...e}){return(0,I.jsx)(xb,{"data-slot":`tooltip`,...e})}function Ob({...e}){return(0,I.jsx)(Sb,{"data-slot":`tooltip-trigger`,...e})}function kb({className:e,sideOffset:t=0,children:n,...r}){return(0,I.jsx)(Cb,{children:(0,I.jsxs)(wb,{"data-slot":`tooltip-content`,sideOffset:t,className:H(`z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95`,e),...r,children:[n,(0,I.jsx)(Tb,{className:`z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground`})]})})}var Ab=eo(`inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary-hover`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40`,outline:`border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary-ink underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,xs:`h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5`,lg:`h-10 rounded-md px-6 has-[>svg]:px-4`,icon:`size-9`,"icon-xs":`size-6 rounded-md [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-8`,"icon-lg":`size-10`}},defaultVariants:{variant:`default`,size:`default`}});function Y({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,I.jsx)(r?mc:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:H(Ab({variant:t,size:n,className:e})),...i})}function jb({...e}){return(0,I.jsx)(Jd,{"data-slot":`sheet`,...e})}function Mb({...e}){return(0,I.jsx)(Xd,{"data-slot":`sheet-trigger`,...e})}function Nb({className:e,children:t,side:n=`left`,showCloseButton:r=!0,...i}){return(0,I.jsxs)(ef,{"data-slot":`sheet-portal`,children:[(0,I.jsx)(nf,{"data-slot":`sheet-overlay`,className:`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`}),(0,I.jsxs)(sf,{"data-slot":`sheet-content`,className:H(`fixed inset-y-0 z-50 flex w-3/4 max-w-sm flex-col bg-background shadow-lg outline-none transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-200 data-[state=open]:animate-in data-[state=open]:duration-300`,n===`left`&&`left-0 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left`,n===`right`&&`right-0 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right`,e),...i,children:[t,r&&(0,I.jsxs)(gf,{className:`absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none`,children:[(0,I.jsx)(Ya,{className:`size-4`}),(0,I.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function Pb({className:e,...t}){return(0,I.jsx)(ff,{"data-slot":`sheet-title`,className:H(`text-base leading-none font-semibold`,e),...t})}var Fb=eo(`inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3`,{variants:{variant:{default:`bg-primary text-primary-foreground [a&]:hover:bg-primary-hover`,secondary:`bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90`,destructive:`bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90`,outline:`border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,ghost:`[a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,link:`text-primary-ink underline-offset-4 [a&]:hover:underline`}},defaultVariants:{variant:`default`}});function Ib({className:e,variant:t=`default`,asChild:n=!1,...r}){return(0,I.jsx)(n?mc:`span`,{"data-slot":`badge`,"data-variant":t,className:H(Fb({variant:t}),e),...r})}function Lb({...e}){return(0,I.jsx)(P_,{"data-slot":`dropdown-menu`,...e})}function Rb({...e}){return(0,I.jsx)(F_,{"data-slot":`dropdown-menu-trigger`,...e})}function zb({className:e,sideOffset:t=4,...n}){return(0,I.jsx)(I_,{children:(0,I.jsx)(L_,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:H(`z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,e),...n})})}function Bb({className:e,inset:t,variant:n=`default`,...r}){return(0,I.jsx)(z_,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:H(`relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!`,e),...r})}function Vb({...e}){return(0,I.jsx)(B_,{"data-slot":`dropdown-menu-radio-group`,...e})}function Hb({className:e,children:t,...n}){return(0,I.jsxs)(V_,{"data-slot":`dropdown-menu-radio-item`,className:H(`relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),...n,children:[(0,I.jsx)(`span`,{className:`pointer-events-none absolute left-2 flex size-3.5 items-center justify-center`,children:(0,I.jsx)(H_,{children:(0,I.jsx)(ma,{className:`size-2 fill-current`})})}),t]})}function Ub({className:e,inset:t,...n}){return(0,I.jsx)(R_,{"data-slot":`dropdown-menu-label`,"data-inset":t,className:H(`px-2 py-1.5 text-sm font-medium data-[inset]:pl-8`,e),...n})}function Wb({className:e,...t}){return(0,I.jsx)(U_,{"data-slot":`dropdown-menu-separator`,className:H(`-mx-1 my-1 h-px bg-border`,e),...t})}var Gb={normal:`bg-primary`,warning:`bg-amber-500`,destructive:`bg-destructive`};function Kb({meter:e,className:t}){return e.ratio===null?null:(0,I.jsx)(`div`,{className:H(`h-1.5 w-full overflow-hidden rounded-full bg-muted`,t),role:`progressbar`,"aria-label":`Monthly request allowance used`,"aria-valuemin":0,"aria-valuemax":e.limit??void 0,"aria-valuenow":e.used,"aria-valuetext":e.label,children:(0,I.jsx)(`div`,{className:H(`h-full rounded-full`,Gb[e.tone]),style:{width:`${e.used>0?Math.max(e.ratio*100,2):0}%`}})})}var qb=`M41 0 L82 12 L82 52 C82 71 69.7 90.3 41 100 C12.3 90.3 0 71 0 52 L0 12 Z`,Jb=.82,Yb=.46,Xb=-.06,Zb=.04;function Qb({size:e=22}){let t={width:e*Jb,height:e,transform:`translateY(${e*Zb}px)`},n={fontSize:e*Yb,transform:`translateY(${e*Xb}px)`};return(0,I.jsxs)(`span`,{className:`grid flex-none place-items-center`,style:t,children:[(0,I.jsx)(`svg`,{className:`col-start-1 row-start-1 block size-full fill-(--brand-mark)`,viewBox:`0 0 82 100`,"aria-hidden":`true`,focusable:`false`,children:(0,I.jsx)(`path`,{d:qb})}),(0,I.jsx)(`span`,{className:`col-start-1 row-start-1 font-bold leading-none tracking-[0.01em] text-white`,style:n,children:`AI`})]})}function $b({className:e,onClick:t}){return(0,I.jsxs)(Pn,{to:`/apps`,onClick:t,className:H(`flex items-center gap-1.5 rounded-md text-sm font-semibold tracking-tight`,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`,e),children:[(0,I.jsx)(`span`,{children:`App`}),(0,I.jsx)(Qb,{size:22}),(0,I.jsx)(`span`,{children:`Gateway`})]})}var ex={owner:`Owner`,admin:`Admin`,member:`Member`};function tx(e){return e===`owner`||e===`admin`}var nx=`Your role is read-only. Ask an owner or admin to make this change.`;function rx(e){return e>1}var ix=(0,v.createContext)(null);function ax({session:e,capabilities:t,billing:n,quota:r,children:i}){let a=tx(e.role),o={session:e,capabilities:t,organization:e.organization,memberships:e.memberships,role:e.role,canManage:a,readOnly:!a,billing:n,quota:r};return(0,I.jsx)(ix,{value:o,children:i})}function ox(){let e=(0,v.use)(ix);if(!e)throw Error(`useConsoleSession must be used inside the authenticated console shell`);return e}function sx(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r!=null&&r!==``&&t.set(n,String(r));let n=t.toString();return n?`?${n}`:``}var cx=encodeURIComponent;function X(){return(e,t)=>({method:e,path:t})}var lx={getConsoleCapabilities:X()(`GET`,()=>`/v1/console/capabilities`),getAdminSession:X()(`GET`,()=>`/v1/admin/session`),listOrganizations:X()(`GET`,()=>`/v1/admin/organizations`),selectOrganization:X()(`POST`,()=>`/v1/admin/organizations/select`),listManagementKeys:X()(`GET`,()=>`/v1/admin/keys`),createManagementKey:X()(`POST`,()=>`/v1/admin/keys`),revokeManagementKey:X()(`POST`,e=>`/v1/admin/keys/${cx(e)}/revoke`),listProviders:X()(`GET`,()=>`/v1/admin/providers`),createProvider:X()(`POST`,()=>`/v1/admin/providers`),testProvider:X()(`POST`,()=>`/v1/admin/providers/test`),updateProvider:X()(`PUT`,e=>`/v1/admin/providers/${cx(e)}`),deleteProvider:X()(`DELETE`,e=>`/v1/admin/providers/${cx(e)}`),listProviderGateways:X()(`GET`,()=>`/v1/admin/provider-gateways`),createProviderGateway:X()(`POST`,()=>`/v1/admin/provider-gateways`),testProviderGateway:X()(`POST`,()=>`/v1/admin/provider-gateways/test`),updateProviderGateway:X()(`PATCH`,e=>`/v1/admin/provider-gateways/${cx(e)}`),rotateProviderGateway:X()(`POST`,e=>`/v1/admin/provider-gateways/${cx(e)}/rotate`),deleteProviderGateway:X()(`DELETE`,e=>`/v1/admin/provider-gateways/${cx(e)}`),listApps:X()(`GET`,(e={})=>`/v1/admin/apps${sx(e)}`),createApp:X()(`POST`,()=>`/v1/admin/apps`),getApp:X()(`GET`,e=>`/v1/admin/apps/${cx(e)}`),updateApp:X()(`PUT`,e=>`/v1/admin/apps/${cx(e)}`),deleteApp:X()(`DELETE`,e=>`/v1/admin/apps/${cx(e)}${sx({confirm:e})}`),validateApp:X()(`POST`,e=>`/v1/admin/apps/${cx(e)}/validate`),listAppKeys:X()(`GET`,e=>`/v1/admin/apps/${cx(e)}/keys`),createAppKey:X()(`POST`,e=>`/v1/admin/apps/${cx(e)}/keys`),revokeAppKey:X()(`POST`,(e,t)=>`/v1/admin/apps/${cx(e)}/keys/${cx(t)}/revoke`),listAppUsers:X()(`GET`,(e,t)=>`/v1/admin/apps/${cx(e)}/users${sx(t)}`),setAppUserBlocked:X()(`POST`,(e,t,n)=>`/v1/admin/apps/${cx(e)}/users/${cx(t)}/${n?`block`:`unblock`}`),getAppUsage:X()(`GET`,(e,t={})=>`/v1/admin/apps/${cx(e)}/usage${sx(t)}`),getAppUsageTimeseries:X()(`GET`,(e,t)=>`/v1/admin/apps/${cx(e)}/usage/timeseries${sx(t)}`),getAppUsageBreakdown:X()(`GET`,(e,t)=>`/v1/admin/apps/${cx(e)}/usage/breakdown${sx(t)}`),listAppEvents:X()(`GET`,(e,t)=>`/v1/admin/apps/${cx(e)}/events${sx(t)}`),getAppAuthEventSummary:X()(`GET`,(e,t)=>`/v1/admin/apps/${cx(e)}/auth-events/summary${sx(t)}`),listAppAuthEvents:X()(`GET`,(e,t)=>`/v1/admin/apps/${cx(e)}/auth-events${sx(t)}`),listModelPrices:X()(`GET`,()=>`/v1/admin/prices`),getCliCapabilities:X()(`GET`,()=>`/v1/cli/capabilities`),bootstrapCliAccount:X()(`POST`,()=>`/v1/cli/bootstrap`),createCliOperation:X()(`POST`,()=>`/v1/cli/operations`),pollCliOperation:X()(`GET`,e=>`/v1/cli/operations/${cx(e)}`),getCliAccount:X()(`GET`,()=>`/v1/cli/account`),getCliUsage:X()(`GET`,(e={})=>`/v1/cli/usage${sx(e)}`)},ux=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t,this.name=`ApiError`}},dx=e=>e instanceof ux&&e.status===401,fx=e=>e instanceof ux&&e.status===402;function px(e,t){let n=t??{};return new ux(e,n.error?.code??n.code??`unknown`,n.error?.message??n.message??`Request failed with status ${e}`)}async function mx(e,t={}){let n=new Headers(t.headers);n.set(`x-console-request`,`1`),t.body!==void 0&&n.set(`content-type`,`application/json`);let r=await fetch(e,{...t,headers:n,credentials:`same-origin`}),i=await r.text(),a=null;try{a=i?JSON.parse(i):null}catch{a=null}if(!r.ok)throw px(r.status,a);return a}function hx(e,t,n,r){return mx(e.path(...t),{method:e.method,...n===void 0?{}:{body:JSON.stringify(n)},...r===void 0?{}:{headers:r}})}var gx={get:e=>mx(e),post:(e,t)=>mx(e,{method:`POST`,body:t===void 0?void 0:JSON.stringify(t)}),put:(e,t,n)=>mx(e,{method:`PUT`,body:JSON.stringify(t),headers:n}),patch:(e,t)=>mx(e,{method:`PATCH`,body:JSON.stringify(t)}),delete:e=>mx(e,{method:`DELETE`})},_x={enabled:!1,capture(e,t){},identify(e,t,n){},group(e,t){},reset(){}};function vx(e,t){_x.capture(`provider_added`,{provider:e,route:t?`gateway`:`direct`})}function yx(e){_x.capture(`app_created`,{authentication:e})}function bx(){let{pathname:e}=dt();(0,v.useEffect)(()=>{_x.capture(`$pageview`)},[e])}var xx=`/login`,Sx=`/signup`,Cx=`/apps`,wx=`/checkout`,Tx=new Set([xx,Sx]),Ex=`from`,Dx=`error`;function Ox(e){return e instanceof ux?!(e.status>=400&&e.status<500):!0}function kx(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/\\`)?!1:!Tx.has(new URL(e,`https://console.invalid`).pathname)}function Ax(e){let t=new URLSearchParams(e).get(Ex);return kx(t)?t:Cx}var jx=`plan`,Mx=/^[a-z0-9_-]{1,32}$/u;function Nx(e){let t=new URLSearchParams(e).get(jx);return t!==null&&Mx.test(t)?t:null}function Px(e){return`${wx}?${jx}=${encodeURIComponent(e)}`}function Fx(e,t){return t===null?e:`${e}?${jx}=${encodeURIComponent(t)}`}function Ix(e){let t=Nx(e);return t!==null&&t!==`free`?Px(t):Ax(e)}function Lx(e){return!kx(e)||e===`/apps`?xx:`${xx}?${Ex}=${encodeURIComponent(e)}`}var Rx=`checkout`,zx=`success`;function Bx(e){return new URLSearchParams(e).get(Rx)===zx}function Vx(e,t){let n=new URLSearchParams(t);n.delete(Rx),n.delete(jx);let r=n.toString();return r?`${e}?${r}`:e}var Hx=`${Cx}?${Rx}=${zx}`;function Ux(e){return`${Hx}&${jx}=${encodeURIComponent(e)}`}var Wx={access_denied:{tone:`default`,title:`Google sign-in was cancelled`,description:`You declined the permission request. Try again or use your password.`},registration_disabled:{tone:`destructive`,title:`This gateway does not accept new accounts`,description:`Your Google account is not registered here. Ask an owner or admin to add you, then sign in.`},signup_disabled:{tone:`destructive`,title:`This gateway does not accept new accounts`,description:`Your Google account is not registered here. Ask an owner or admin to add you, then sign in.`}};function Gx(e){let t=new URLSearchParams(e).get(Dx);return t?Wx[t.trim().toLowerCase().replaceAll(/[\s-]+/gu,`_`)]??{tone:`destructive`,title:`Sign-in failed`,description:`The identity provider rejected the sign-in. Try again or use your password.`}:null}var Kx=`/v1/auth`;function qx(e){return gx.post(`${Kx}/sign-in/email`,{...e,rememberMe:!0})}function Jx(e){return gx.post(`${Kx}/sign-up/email`,e)}function Yx(){return gx.post(`${Kx}/sign-out`,{})}function Xx(e){return gx.post(`${Kx}/change-password`,e)}async function Zx(e){let t=kx(e)?e:Cx,n=await gx.post(`${Kx}/sign-in/social`,{provider:`google`,callbackURL:t,errorCallbackURL:Lx(t)});if(!n?.url)throw Error(`Google sign-in is unavailable right now.`);window.location.assign(n.url)}var Qx=e=>e,$x=e=>e,eS={capabilities:[`capabilities`],session:[`session`],organizations:[`organizations`],managementKeys:[`management-keys`],providers:[`providers`],providerGateways:[`provider-gateways`],billingStatus:[`billing`,`status`],billingPlans:[`billing`,`plans`],apps:e=>[`apps`,e],app:e=>[`app`,e],apiKeys:e=>[`api-keys`,e],users:(e,t)=>[`users`,e,t],usage:(e,t)=>[`usage`,e,t],timeseries:(e,t,n)=>[`timeseries`,e,t,n],breakdown:(e,t,n,r)=>[`breakdown`,e,t,n,r],events:(e,t)=>[`events`,e,t],authEventSummary:(e,t)=>[`auth-event-summary`,e,t],authEvents:(e,t)=>[`auth-events`,e,t],prices:[`prices`]};function tS(){return Ti({queryKey:eS.capabilities,queryFn:()=>hx(lx.getConsoleCapabilities,[]),staleTime:1/0,retry:1})}function nS(){return Ti({queryKey:eS.session,queryFn:async()=>(await hx(lx.getAdminSession,[])).session,retry:!1,staleTime:6e4})}function rS(){let e=ui();return Ei({mutationFn:e=>qx(e),onSuccess:()=>e.invalidateQueries()})}function iS(){let e=ui();return Ei({mutationFn:e=>Jx(e),onSuccess:()=>e.invalidateQueries()})}function aS(){let e=ui();return Ei({mutationFn:()=>Yx(),onSettled:()=>{_x.reset(),e.clear()}})}function oS(){return Ei({mutationFn:e=>Xx({...e,revokeOtherSessions:!0})})}function sS(){let e=ui();return Ei({mutationFn:e=>hx(lx.selectOrganization,[],{organizationId:e}),onSuccess:t=>{e.clear(),e.setQueryData(eS.session,t.session)}})}function cS(){return Ti({queryKey:eS.managementKeys,queryFn:()=>hx(lx.listManagementKeys,[])})}function lS(){let e=ui();return Ei({mutationFn:e=>hx(lx.createManagementKey,[],{name:e}),gcTime:0,onSuccess:()=>void e.invalidateQueries({queryKey:eS.managementKeys})})}function uS(){let e=ui();return Ei({mutationFn:e=>hx(lx.revokeManagementKey,[e]),onSuccess:()=>void e.invalidateQueries({queryKey:eS.managementKeys})})}function dS(){return Ti({queryKey:eS.providers,queryFn:()=>hx(lx.listProviders,[])})}function fS(){return Ti({queryKey:eS.providers,queryFn:()=>hx(lx.listProviders,[]),select:e=>e.providers})}function pS(e){e.invalidateQueries({queryKey:eS.providers}),e.invalidateQueries({queryKey:eS.providerGateways})}function mS(){let e=ui();return Ei({mutationFn:e=>hx(lx.createProvider,[],e),gcTime:0,onSuccess:(t,n)=>{vx(n.type,n.providerGatewayId!==void 0),pS(e)}})}function hS(){return Ei({mutationFn:e=>hx(lx.testProvider,[],e),gcTime:0})}function gS(){return Ei({mutationFn:e=>hx(lx.testProviderGateway,[],e),gcTime:0})}function _S(e=!0){return Ti({queryKey:eS.providerGateways,queryFn:()=>hx(lx.listProviderGateways,[]),enabled:e})}function vS(e){let t=ui();return Ei({mutationFn:e,gcTime:0,onSuccess:()=>pS(t)})}function yS(){return vS(e=>hx(lx.createProviderGateway,[],e))}function bS(){return vS(({id:e,name:t})=>hx(lx.updateProviderGateway,[e],{name:t}))}function xS(){return vS(({id:e,token:t})=>hx(lx.rotateProviderGateway,[e],{token:t}))}function SS(){return vS(e=>hx(lx.deleteProviderGateway,[e]))}function CS(){let e=ui();return Ei({mutationFn:({id:e,body:t})=>hx(lx.updateProvider,[e],t),gcTime:0,onSuccess:(t,n)=>{e.invalidateQueries({queryKey:eS.providers}),n.body.status!==void 0&&e.invalidateQueries({queryKey:[`apps`]})}})}function wS(){let e=ui();return Ei({mutationFn:e=>hx(lx.deleteProvider,[e]),onSuccess:()=>pS(e)})}function TS(e){return Ti({queryKey:eS.billingStatus,queryFn:()=>gx.get(`/v1/admin/billing/status`),enabled:e,staleTime:3e4,refetchInterval:e?5*6e4:!1,refetchOnWindowFocus:!0})}function ES(e){return Ti({queryKey:eS.billingPlans,queryFn:()=>gx.get(`/v1/admin/billing/plans`),enabled:e,staleTime:1/0})}function DS(){return Ei({mutationFn:e=>gx.post(`/v1/admin/billing/checkout`,{...e,successUrl:`${window.location.origin}${Ux(e.planKey)}`,cancelUrl:`${window.location.origin}/billing`})})}function OS(){let e=ui();return Ei({mutationFn:e=>gx.post(`/v1/admin/billing/change`,e),onSuccess:()=>void e.invalidateQueries({queryKey:eS.billingStatus})})}function kS(){let e=ui();return Ei({mutationFn:()=>gx.post(`/v1/admin/billing/cancel`),onSuccess:()=>void e.invalidateQueries({queryKey:eS.billingStatus})})}function AS(){let e=ui();return Ei({mutationFn:e=>gx.post(`/v1/admin/billing/resume`,e),onSuccess:()=>void e.invalidateQueries({queryKey:eS.billingStatus})})}function jS(e,t){return Ti({queryKey:eS.apps(e),queryFn:()=>hx(lx.listApps,[{month:e}]),...t===void 0?{}:{refetchInterval:t}})}function MS(e){return Ti({queryKey:eS.app(e),queryFn:async()=>Qx(await hx(lx.getApp,[e]))})}function NS(e){let t=ui();return Ei({mutationFn:async({body:t,revision:n})=>Qx(await hx(lx.updateApp,[e],$x(t),{"If-Match":`"app-${n}"`})),onSuccess:()=>{t.invalidateQueries({queryKey:eS.app(e)}),t.invalidateQueries({queryKey:[`apps`]})}})}function PS(){let e=ui();return Ei({mutationFn:async e=>{let t=await hx(lx.createApp,[],$x(e));return{...Qx(t),api_key:t.api_key}},onSuccess:(t,n)=>{yx(n.config.authentication.type),e.invalidateQueries({queryKey:eS.app(t.app.id)}),e.invalidateQueries({queryKey:[`apps`]})}})}function FS(){let e=ui();return Ei({mutationFn:e=>hx(lx.deleteApp,[e]),onSuccess:()=>e.invalidateQueries({queryKey:[`apps`]})})}function IS(e,t=!0){return Ti({enabled:t,queryKey:eS.apiKeys(e),queryFn:()=>hx(lx.listAppKeys,[e])})}function LS(e){let t=ui();return Ei({mutationFn:t=>hx(lx.createAppKey,[e],{name:t}),onSuccess:()=>void t.invalidateQueries({queryKey:eS.apiKeys(e)})})}function RS(e){let t=ui();return Ei({mutationFn:t=>hx(lx.revokeAppKey,[e,t]),onSuccess:()=>void t.invalidateQueries({queryKey:eS.apiKeys(e)})})}function zS(e,t){return Ti({queryKey:eS.users(e,t),queryFn:()=>hx(lx.listAppUsers,[e,t]),placeholderData:e=>e})}function BS(e){let t=ui();return Ei({mutationFn:({userId:t,blocked:n})=>hx(lx.setAppUserBlocked,[e,t,n]),onSuccess:()=>{t.invalidateQueries({queryKey:[`users`,e]}),t.invalidateQueries({queryKey:[`apps`]})}})}function VS(e,t){return Ti({queryKey:eS.usage(e,t),queryFn:()=>hx(lx.getAppUsage,[e,{month:t}])})}function HS(e,t,n){return Ti({queryKey:eS.timeseries(e,t,n),queryFn:()=>hx(lx.getAppUsageTimeseries,[e,{from:t,to:n}])})}function US(e,t,n,r){return Ti({queryKey:eS.breakdown(e,t,n,r),queryFn:()=>hx(lx.getAppUsageBreakdown,[e,{by:t,from:n,to:r}])})}function WS(e,t){return Ti({queryKey:eS.events(e,t),queryFn:()=>hx(lx.listAppEvents,[e,{...t}]),placeholderData:e=>e})}function GS(e,t){return Ti({queryKey:eS.authEventSummary(e,t),queryFn:()=>hx(lx.getAppAuthEventSummary,[e,{days:t}]),staleTime:3e4})}function KS(e,t){return Ti({queryKey:eS.authEvents(e,t),queryFn:()=>hx(lx.listAppAuthEvents,[e,{...t}]),placeholderData:e=>e})}function qS(){return Ti({queryKey:eS.prices,queryFn:()=>hx(lx.listModelPrices,[]),staleTime:1/0})}function JS(){let{organization:e,memberships:t}=ox(),n=sS();if(!rx(t.length))return null;let r=async t=>{if(t!==e?.id)try{await n.mutateAsync(t)}catch(e){U.error(e instanceof Error?e.message:`Could not switch organization`)}};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Wb,{}),(0,I.jsx)(Ub,{className:`text-xs font-normal text-muted-foreground`,children:`Organizations`}),t.map(t=>{let i=t.organization.id===e?.id;return(0,I.jsxs)(Bb,{disabled:n.isPending,onSelect:()=>void r(t.organization.id),children:[(0,I.jsx)(ra,{className:i?`size-4`:`size-4 opacity-0`}),(0,I.jsx)(`span`,{className:`flex-1 truncate`,children:t.organization.name}),(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ex[t.role]})]},t.organization.id)})]})}function YS({status:e}){return e===`active`?null:(0,I.jsxs)(Ib,{variant:`outline`,className:`gap-1.5 border-muted-foreground/30 text-muted-foreground`,children:[(0,I.jsx)(`span`,{className:`size-1.5 rounded-full bg-muted-foreground`}),`disabled`]})}var XS={ok:`border-emerald-500/40 text-emerald-600 dark:text-emerald-400`,provider_error:`border-destructive/40 text-destructive`,blocked_app_rate:`border-amber-500/40 text-amber-600 dark:text-amber-400`,blocked_app_budget:`border-amber-500/40 text-amber-600 dark:text-amber-400`,blocked_billing:`border-amber-500/40 text-amber-600 dark:text-amber-400`,blocked_user:`border-amber-500/40 text-amber-600 dark:text-amber-400`},ZS={ok:`Served by the provider`,provider_error:`The provider refused or failed the request`,blocked_app_rate:`Refused by this app's own rate limit, which you set`,blocked_app_budget:`Refused by this app's own monthly budget, which you set`,blocked_billing:`Refused: your plan's monthly request allowance was exhausted`,blocked_user:`Refused: this user is blocked`};function QS({status:e}){return(0,I.jsx)(Ib,{variant:`outline`,className:H(`font-mono text-[11px] font-normal`,XS[e]),title:ZS[e],children:e})}var $S={ok:`border-emerald-500/40 text-emerald-600 dark:text-emerald-400`,issuer_claims_missing:`border-amber-500/40 text-amber-600 dark:text-amber-400`,issuer_verification_unavailable:`border-amber-500/40 text-amber-600 dark:text-amber-400`};function eC({outcome:e}){return(0,I.jsx)(Ib,{variant:`outline`,className:H(`font-mono text-[11px] font-normal`,$S[e]??`border-destructive/40 text-destructive`),children:e})}function tC({status:e}){return(0,I.jsx)(Ib,{variant:`outline`,className:H(e===`blocked`?`border-destructive/40 text-destructive`:`border-border text-muted-foreground`),children:e})}var nC=[{value:`light`,label:`Light`,icon:Wa},{value:`dark`,label:`Dark`,icon:Oa},{value:`system`,label:`System`,icon:Da}];function rC(){let{theme:e,resolvedTheme:t,setTheme:n}=Ni(),[r,i]=(0,v.useState)(!1);return(0,v.useEffect)(()=>i(!0),[]),(0,I.jsxs)(Lb,{children:[(0,I.jsx)(Rb,{asChild:!0,children:(0,I.jsx)(Y,{variant:`ghost`,size:`icon`,"aria-label":`Theme`,className:`text-muted-foreground`,children:r?(0,I.jsx)(e===`system`?Da:t===`light`?Wa:Oa,{className:`size-4`}):(0,I.jsx)(`span`,{className:`size-4`})})}),(0,I.jsx)(zb,{align:`end`,className:`w-36`,children:(0,I.jsx)(Vb,{value:e??`system`,onValueChange:n,children:nC.map(e=>(0,I.jsxs)(Hb,{value:e.value,children:[(0,I.jsx)(e.icon,{className:`size-4`}),e.label]},e.value))})})]})}var iC=[{slug:`overview`,label:`Overview`,icon:Qi},{slug:`auth`,label:`Auth policy`,icon:Ba},{slug:`proxy`,label:`Proxy policy`,icon:Ja},{slug:`endpoints`,label:`Endpoints`,icon:Fa},{slug:`limits`,label:`Limits`,icon:ba},{slug:`users`,label:`Users`,icon:qa},{slug:`usage`,label:`Usage`,icon:na},{slug:`auth-events`,label:`Auth & Errors`,icon:za},{slug:`settings`,label:`Settings`,icon:Ra}];iC[0].slug;var aC=new Intl.NumberFormat(`en-US`,{notation:`compact`,maximumFractionDigits:1}),oC=new Intl.NumberFormat(`en-US`),sC=new Intl.NumberFormat(`en-US`,{style:`percent`,minimumFractionDigits:1,maximumFractionDigits:1}),cC=e=>e==null?`—`:oC.format(e),lC=e=>e==null?`—`:e<1e4?oC.format(e):aC.format(e),uC=e=>e==null?`—`:sC.format(e);function dC(e){return e==null?`—`:e===0?`$0.00`:e<.01?`$${e.toFixed(4)}`:fC(e)}function fC(e){return e==null?`—`:e<100?`$${e.toFixed(2)}`:`$${oC.format(Math.round(e))}`}function pC(e){if(!e)return null;let t=e.includes(`T`)?e:`${e.replace(` `,`T`)}Z`,n=new Date(t);return Number.isNaN(n.getTime())?null:n}function mC(e){let t=pC(e);return t?t.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):`—`}function hC(e){let t=pC(e);if(!t)return`never`;let n=Math.round((Date.now()-t.getTime())/1e3),r=[[`second`,60],[`minute`,60],[`hour`,24],[`day`,30],[`month`,12],[`year`,1/0]],i=n;for(let[e,t]of r){if(Math.abs(i)<t)return new Intl.RelativeTimeFormat(void 0,{numeric:`auto`}).format(-Math.round(i),e);i/=t}return t.toLocaleDateString()}var gC=e=>e.input_tokens+e.cached_input_tokens+e.cache_write_tokens,_C=e=>{let t=gC(e);return t===0?null:e.cached_input_tokens/t},vC=e=>gC(e)+e.output_tokens;function yC(){return new Date().toISOString().slice(0,10).slice(0,7)}function bC(){return new Date().toISOString().slice(0,10)}function xC(e){return new Date(Date.now()-e*864e5).toISOString().slice(0,10)}function SC(e){return new Date(`${e}-01T00:00:00Z`).toLocaleDateString(void 0,{month:`long`,year:`numeric`,timeZone:`UTC`})}function CC(e){let t=[],n=new Date;for(let r=0;r<e;r+=1)t.push(new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()-r,1)).toISOString().slice(0,7));return t}function wC(e){return e?.state===`billed`?e.plan:null}function TC(e){return e?.state===`billed`?e.subscription:null}function EC(e){let t=e?.limits,n=typeof t==`object`&&t&&!Array.isArray(t)?t.maxRequestsPerMonth:void 0,r=typeof n==`number`?n:typeof n==`string`&&n.trim().length>0?Number(n):NaN;return Number.isSafeInteger(r)&&r>=0?r:null}function DC(e){let t=EC(e);return t===null?`the ${e.planName} plan`:`the ${e.planName} plan (${cC(t)} requests/month)`}function OC(e){return!e||e.state===`self_hosted`?null:e.state===`unavailable`?{tone:`destructive`,title:`Billing service unavailable`,description:`Gateway traffic may be interrupted. This usually resolves on its own.`,actionable:!1}:e.plan===null?{tone:`destructive`,title:`No active plan`,description:`Gateway traffic is being refused. Choose a plan to start serving it again.`,actionable:!0}:e.subscription?.subscriptionId&&e.plan.isDefault?{tone:`warning`,title:`Your subscription has ended`,description:`You’re on ${DC(e.plan)}. Resubscribe to restore your previous allowance.`,actionable:!0}:e.subscription?.status===`past_due`?{tone:`warning`,title:`Payment past due`,description:`Update your payment method to keep this plan.`,actionable:!0}:null}function kC(e){return!!(e&&!e.claimed&&e.expiresAt)}function AC(e){return!e||!kC(e)?null:{tone:`warning`,title:`Unclaimed free access`,description:`Your free access does not renew until you claim your account. Claim your account for free to keep your apps and usage. Free access ends ${PC(new Date(new Date(e.createdAt).getTime()+30*864e5).toISOString())}.`,actionable:!1}}function jC(e,t){if(!e)return null;let n=PC(e.resetAt),r=kC(t),i=n?`${r?`Ends`:`Resets`} ${n}`:r?`Free access end unavailable`:`Reset time unavailable`;if(e.limit===void 0||e.limit===null)return{used:e.used,limit:null,ratio:null,tone:`normal`,label:`${cC(e.used)} requests this period`,caption:i};let a=e.limit>0?Math.min(e.used/e.limit,1):1;return{used:e.used,limit:e.limit,ratio:a,tone:a>=1?`destructive`:a>=.8?`warning`:`normal`,label:`${cC(e.used)} of ${cC(e.limit)} requests`,caption:i}}function MC(e,t){let n=jC(e,t);return!n||n.ratio===null||n.tone===`normal`?null:n.ratio>=1?{tone:`destructive`,title:kC(t)?`Free request allowance spent`:`Monthly request allowance spent`,description:kC(t)?`This free allowance does not renew until you claim your account. Claim it to move onto a renewing monthly allowance. ${n.caption}.`:`Gateway requests are being refused until the allowance resets. ${n.caption}.`,actionable:!0}:{tone:`warning`,title:kC(t)?`Free request allowance almost spent`:`Monthly request allowance almost spent`,description:`${n.label} used in the current period. ${n.caption}.`,actionable:!0}}function NC(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`})}function PC(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toLocaleString(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,timeZoneName:`short`})}function FC(e){return`${(e.priceAmountCents/100).toLocaleString(void 0,{style:`currency`,currency:e.priceCurrency||`USD`,minimumFractionDigits:e.priceAmountCents%100==0?0:2})}/${e.billingPeriod===`year`?`yr`:`mo`}`}function IC(e,t){return e.prices.find(e=>e.billingPeriod===t)}function LC(e){if(e.endsAt){let t=NC(e.endsAt);if(t)return{label:`Access ends`,value:t}}if(e.status===`on_trial`&&e.trialEndsAt){let t=NC(e.trialEndsAt);if(t)return{label:`Trial ends`,value:t}}if(e.renewsAt){let t=NC(e.renewsAt);if(t)return{label:`Renews`,value:t}}return null}var RC=new Set([`on_trial`,`active`,`paused`,`past_due`]);function zC(e){return!!(e&&e.subscriptionId&&e.source===`lemon_squeezy`&&RC.has(e.status))}function BC(e){return!!(e?.subscriptionId&&e.source===`lemon_squeezy`&&e.status===`cancelled`)}function VC(e){return IC(e,`month`)?.priceAmountCents??0}var HC=`This plan was granted manually. Ask support to change it.`;function UC(e,t,n){let r=wC(n);if(r&&e.planKey===r.planKey)return{intent:`current`,label:`Current plan`,variant:`outline`};let i=t.find(e=>e.planKey===r?.planKey),a=VC(e)>(i?VC(i):0),o=e.prices.length===0,s=a?`default`:`outline`,c=`${a?`Upgrade`:`Downgrade`} to ${e.name}`,l=TC(n);return l&&l.source===`manual`&&RC.has(l.status)?{intent:o?`cancel`:`change`,label:c,variant:s,reason:HC}:o?zC(l)?{intent:`cancel`,label:c,variant:s}:{intent:`cancel`,label:c,variant:s,reason:`There is no paid subscription to leave.`}:{intent:zC(l)?`change`:`checkout`,label:c,variant:s}}var WC=[{to:`/apps`,label:`Apps`,icon:Ca},{to:`/providers`,label:`Providers`,icon:Ma,sections:[{to:`/providers/gateways`,label:`Gateways`,icon:ta}]}];function GC({onNavigate:e}){let{capabilities:t,billing:n,quota:r,canManage:i,organization:a}=ox(),o=dt();if(!t.billing)return null;let s=wC(n),c=jC(r,a);if(!s&&!c)return null;let l=o.pathname===`/billing`,u=c!==null&&c.ratio!==null&&c.ratio>=.8,d=s===null||s.isDefault||u;return(0,I.jsxs)(`div`,{className:H(`rounded-lg px-3 py-2.5 transition-colors`,l?`bg-sidebar-accent text-sidebar-accent-foreground`:`bg-sidebar-accent/40`),children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,I.jsx)(`span`,{className:`truncate text-xs font-medium`,children:s?`${s.planName} plan`:`No plan`}),d?(0,I.jsx)(Pn,{to:`/billing`,onClick:e,"aria-current":l?`page`:void 0,className:H(`shrink-0 rounded-sm text-xs font-medium underline underline-offset-4 transition-colors`,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`,l?`text-sidebar-accent-foreground`:`text-primary-ink hover:text-foreground`),children:i?`Upgrade`:`View plan`}):null]}),c?(0,I.jsxs)(`div`,{className:`mt-1.5 space-y-1`,children:[(0,I.jsx)(`p`,{className:`tabular text-[11px] text-muted-foreground`,children:c.label}),(0,I.jsx)(Kb,{meter:c,className:`h-1`})]}):null]})}function KC(){return(0,I.jsxs)(Db,{children:[(0,I.jsx)(Ob,{asChild:!0,children:(0,I.jsxs)(Ib,{variant:`secondary`,className:`w-full justify-start gap-1.5 py-1`,children:[(0,I.jsx)(ya,{className:`size-3`}),`Read-only`]})}),(0,I.jsx)(kb,{side:`top`,children:nx})]})}function qC(e,t){let n=e?.trim()||t,r=n.split(/[\s@._-]+/).filter(Boolean);return(r.length>1?`${r[0][0]}${r[1][0]}`:n.slice(0,2)).toUpperCase()}function JC({onNavigate:e}){let t=ht(),{session:n,capabilities:r}=ox(),i=aS(),a=async()=>{await i.mutateAsync().catch(()=>void 0),await t(`/login`,{replace:!0})},o=n.user?.email??`Operator`,s=n.user?.name?.trim()||o;return(0,I.jsxs)(Lb,{children:[(0,I.jsxs)(Rb,{className:H(`flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-left transition-colors`,`hover:bg-sidebar-accent hover:text-sidebar-accent-foreground`,`data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground`,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`),children:[(0,I.jsx)(`span`,{"aria-hidden":!0,className:`grid size-8 shrink-0 place-items-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`,children:qC(n.user?.name,o)}),(0,I.jsxs)(`span`,{className:`min-w-0 flex-1 leading-tight`,children:[(0,I.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:s}),(0,I.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:o})]}),(0,I.jsx)(sa,{className:`size-4 shrink-0 text-muted-foreground`})]}),(0,I.jsxs)(zb,{side:`top`,align:`start`,sideOffset:8,className:`w-(--radix-dropdown-menu-trigger-width) min-w-56`,children:[(0,I.jsx)(Bb,{asChild:!0,children:(0,I.jsxs)(Pn,{to:`/settings`,onClick:e,children:[(0,I.jsx)(Ra,{className:`size-4`}),`Settings`]})}),(0,I.jsx)(Bb,{asChild:!0,children:(0,I.jsxs)(Pn,{to:`/keys`,onClick:e,children:[(0,I.jsx)(Sa,{className:`size-4`}),`Management keys`]})}),r.billing?(0,I.jsx)(Bb,{asChild:!0,children:(0,I.jsxs)(Pn,{to:`/billing`,onClick:e,children:[(0,I.jsx)(ga,{className:`size-4`}),`Billing`]})}):null,(0,I.jsx)(JS,{}),(0,I.jsx)(Wb,{}),(0,I.jsxs)(Bb,{disabled:i.isPending,onSelect:()=>void a(),children:[(0,I.jsx)(Ea,{className:`size-4`}),`Sign out`]})]})]})}function YC({to:e,label:t,icon:n,current:r,onNavigate:i,className:a}){return(0,I.jsxs)(Pn,{to:e,onClick:i,"aria-current":r?`page`:void 0,className:H(`flex h-10 items-center gap-2.5 rounded-lg px-3 text-sm font-medium transition-colors`,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`,r?`bg-sidebar-accent text-sidebar-accent-foreground`:`text-muted-foreground hover:bg-sidebar-accent/60 hover:text-sidebar-accent-foreground`,a),children:[n?(0,I.jsx)(n,{className:`size-4 shrink-0`}):null,(0,I.jsx)(`span`,{className:`truncate`,children:t})]})}function XC({onNavigate:e}){let t=dt();return(0,I.jsx)(`nav`,{className:`flex flex-1 flex-col gap-1 p-3`,children:WC.map(n=>{let r=t.pathname.startsWith(n.to),i=r?n.sections:void 0,a=r&&!i?.some(e=>e.to===t.pathname);return(0,I.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,I.jsx)(YC,{to:n.to,label:n.label,icon:n.icon,current:a,onNavigate:e}),i?(0,I.jsx)(`div`,{className:`flex flex-col gap-1`,children:i.map(n=>(0,I.jsx)(YC,{to:n.to,label:n.label,icon:n.icon,current:t.pathname===n.to,onNavigate:e,className:`h-9 pr-3 pl-9.5`},n.to))}):null]},n.to)})})}function ZC({back:e,title:t,badge:n,items:r,onNavigate:i}){let a=dt();return(0,I.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 border-b border-sidebar-border px-3 pb-3`,children:[(0,I.jsxs)(Pn,{to:e.to,onClick:i,className:H(`flex h-8 w-fit items-center gap-1.5 rounded-lg px-2 text-sm text-muted-foreground transition-colors`,`hover:bg-sidebar-accent/60 hover:text-sidebar-accent-foreground`,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`),children:[(0,I.jsx)(Xi,{className:`size-3.5 shrink-0`}),e.label]}),(0,I.jsxs)(`div`,{className:`min-w-0 space-y-1.5 px-2 pt-1 pb-1`,children:[(0,I.jsx)(`h1`,{className:`line-clamp-2 text-lg leading-snug font-semibold tracking-tight break-words`,children:t}),n]})]}),(0,I.jsx)(`nav`,{"aria-label":`${t} sections`,className:`flex flex-1 flex-col gap-1 overflow-y-auto p-3`,children:r.map(e=>(0,I.jsx)(YC,{to:e.to,label:e.label,icon:e.icon,current:a.pathname===e.to||a.pathname.startsWith(`${e.to}/`),onNavigate:i},e.to))})]})}function QC({appId:e,onNavigate:t}){let n=MS(e);return(0,I.jsx)(ZC,{back:{to:`/apps`,label:`Apps`},title:n.data?.app.name??e,badge:n.data?(0,I.jsx)(YS,{status:n.data.app.status}):void 0,items:iC.map(t=>({to:`/apps/${e}/${t.slug}`,label:t.label,icon:t.icon})),onNavigate:t})}function $C({onNavigate:e}){let{readOnly:t}=ox(),n=ft(`/apps/:appId/*`);return(0,I.jsxs)(`div`,{className:`flex h-full flex-col bg-sidebar text-sidebar-foreground`,children:[(0,I.jsxs)(`div`,{className:`flex h-14 items-center justify-between gap-2 px-3`,children:[(0,I.jsx)($b,{className:`px-1`,onClick:e}),(0,I.jsx)(rC,{})]}),n?.params.appId?(0,I.jsx)(QC,{appId:n.params.appId,onNavigate:e}):(0,I.jsx)(XC,{onNavigate:e}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1 border-t border-sidebar-border p-3`,children:[(0,I.jsx)(GC,{onNavigate:e}),t?(0,I.jsx)(`div`,{className:`px-1 pb-1.5`,children:(0,I.jsx)(KC,{})}):null,(0,I.jsx)(JC,{onNavigate:e})]})]})}function ew(){let{capabilities:e,billing:t,quota:n,organization:r}=ox(),i=dt(),a=e.billing?AC(r)??OC(t)??MC(n,r):null;return!a||i.pathname===`/billing`?null:(0,I.jsxs)(Ds,{variant:a.tone===`destructive`?`destructive`:`default`,className:`mb-4`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:a.title}),(0,I.jsxs)(ks,{className:`flex flex-wrap items-center gap-3`,children:[(0,I.jsx)(`span`,{children:a.description}),a.actionable?(0,I.jsx)(Y,{asChild:!0,size:`sm`,variant:`outline`,children:(0,I.jsx)(Pn,{to:`/billing`,children:`View plans`})}):null]})]})}function tw(){let[e,t]=(0,v.useState)(!1);return(0,v.useEffect)(()=>t(!1),[dt().pathname]),(0,I.jsxs)(`header`,{className:`sticky top-0 z-30 flex h-14 items-center gap-2 border-b bg-background/80 px-3 backdrop-blur lg:hidden`,children:[(0,I.jsxs)(jb,{open:e,onOpenChange:t,children:[(0,I.jsx)(Mb,{asChild:!0,children:(0,I.jsx)(Y,{variant:`ghost`,size:`icon`,"aria-label":`Open navigation`,children:(0,I.jsx)(Aa,{className:`size-4`})})}),(0,I.jsxs)(Nb,{side:`left`,className:`w-72 border-sidebar-border p-0`,showCloseButton:!1,children:[(0,I.jsx)(Pb,{className:`sr-only`,children:`Navigation`}),(0,I.jsx)($C,{onNavigate:()=>t(!1)})]})]}),(0,I.jsx)($b,{}),(0,I.jsx)(`div`,{className:`ml-auto`,children:(0,I.jsx)(rC,{})})]})}function nw({children:e}){return(0,I.jsxs)(`div`,{className:`min-h-dvh bg-sidebar`,children:[(0,I.jsx)(`aside`,{className:`fixed inset-y-0 left-0 z-20 hidden w-64 lg:block`,children:(0,I.jsx)($C,{})}),(0,I.jsxs)(`div`,{className:`flex min-h-dvh flex-col lg:pl-64`,children:[(0,I.jsx)(tw,{}),(0,I.jsx)(`main`,{className:`min-w-0 flex-1 bg-background lg:my-2 lg:mr-2 lg:rounded-xl lg:border lg:shadow-sm`,children:(0,I.jsxs)(`div`,{className:`mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8`,children:[(0,I.jsx)(ew,{}),e]})})]})]})}function rw({reason:e,reasonId:t,className:n,children:r}){return(0,I.jsxs)(Db,{children:[(0,I.jsx)(Ob,{asChild:!0,children:(0,I.jsxs)(`span`,{tabIndex:0,className:H(`inline-flex w-fit cursor-not-allowed`,n),children:[r,t?(0,I.jsx)(`span`,{id:t,className:`sr-only`,children:e}):null]})}),(0,I.jsx)(kb,{children:e})]})}function iw({reason:e,wrapperClassName:t,disabled:n,...r}){let{readOnly:i}=ox(),a=(0,v.useId)(),o=e??(i?`Your role is read-only. Ask an owner or admin to make this change.`:void 0);return o?(0,I.jsx)(rw,{reason:o,reasonId:a,className:t,children:(0,I.jsx)(Y,{...r,disabled:!0,"aria-disabled":`true`,"aria-describedby":a})}):(0,I.jsx)(Y,{disabled:n,...r})}function aw({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`skeleton`,className:H(`animate-pulse rounded-md bg-accent`,e),...t})}function ow({className:e,...t}){return(0,I.jsx)(G_,{"data-slot":`label`,className:H(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}function sw({label:e,hint:t,htmlFor:n,className:r,children:i}){return(0,I.jsxs)(`div`,{className:H(`space-y-2`,r),children:[(0,I.jsx)(ow,{htmlFor:n,className:`text-sm`,children:e}),i,t?(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:t}):null]})}function cw({title:e,description:t,action:n}){return(0,I.jsxs)(`div`,{className:H(`flex flex-wrap justify-between gap-x-8 gap-y-3`,t?`items-start`:`items-center`),children:[(0,I.jsxs)(`div`,{className:`min-w-0 flex-1 basis-80 space-y-1`,children:[(0,I.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:e}),t?(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t}):null]}),n?(0,I.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:n}):null]})}function lw({title:e,description:t,action:n}){return(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:e}),t?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t}):null]}),n]})}function uw({children:e}){return(0,I.jsx)(`div`,{className:`rounded-md border border-dashed px-4 py-6 text-center text-sm text-muted-foreground`,children:e})}var dw=`<svg fill="currentColor" fill-rule="evenodd" height="1em" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M13.827 3.52h3.603L24 20h-3.603l-6.57-16.48zm-7.258 0h3.767L16.906 20h-3.674l-1.343-3.461H5.017l-1.344 3.46H0L6.57 3.522zm4.132 9.959L8.453 7.687 6.205 13.48H10.7z"></path></svg>
|
|
51
|
+
`},Ed=0,Dd=[];function Od(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),i=v.useState(Ed++)[0],a=v.useState(Zu)[0],o=v.useRef(e);v.useEffect(function(){o.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add(`block-interactivity-${i}`);var t=Eu([e.lockRef.current],(e.shards||[]).map(J),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add(`allow-interactivity-${i}`)}),function(){document.body.classList.remove(`block-interactivity-${i}`),t.forEach(function(e){return e.classList.remove(`allow-interactivity-${i}`)})}}},[e.inert,e.lockRef.current,e.shards]);var s=v.useCallback(function(e,t){if(`touches`in e&&e.touches.length===2||e.type===`wheel`&&e.ctrlKey)return!o.current.allowPinchZoom;var i=Sd(e),a=n.current,s=`deltaX`in e?e.deltaX:a[0]-i[0],c=`deltaY`in e?e.deltaY:a[1]-i[1],l,u=e.target,d=Math.abs(s)>Math.abs(c)?`h`:`v`;if(`touches`in e&&d===`h`&&u.type===`range`)return!1;var f=window.getSelection(),p=f&&f.anchorNode;if(p&&(p===u||p.contains(u)))return!1;var m=hd(d,u);if(!m)return!0;if(m?l=d:(l=d===`v`?`h`:`v`,m=hd(d,u)),!m)return!1;if(!r.current&&`changedTouches`in e&&(s||c)&&(r.current=l),!l)return!0;var h=r.current||l;return xd(h,t,e,h===`h`?s:c,!0)},[]),c=v.useCallback(function(e){var n=e;if(!(!Dd.length||Dd[Dd.length-1]!==a)){var r=`deltaY`in n?Cd(n):Sd(n),i=t.current.filter(function(e){return e.name===n.type&&(e.target===n.target||n.target===e.shadowParent)&&wd(e.delta,r)})[0];if(i&&i.should){n.cancelable&&n.preventDefault();return}if(!i){var c=(o.current.shards||[]).map(J).filter(Boolean).filter(function(e){return e.contains(n.target)});(c.length>0?s(n,c[0]):!o.current.noIsolation)&&n.cancelable&&n.preventDefault()}}},[]),l=v.useCallback(function(e,n,r,i){var a={name:e,delta:n,target:r,should:i,shadowParent:kd(r)};t.current.push(a),setTimeout(function(){t.current=t.current.filter(function(e){return e!==a})},1)},[]),u=v.useCallback(function(e){n.current=Sd(e),r.current=void 0},[]),d=v.useCallback(function(t){l(t.type,Cd(t),t.target,s(t,e.lockRef.current))},[]),f=v.useCallback(function(t){l(t.type,Sd(t),t.target,s(t,e.lockRef.current))},[]);v.useEffect(function(){return Dd.push(a),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener(`wheel`,c,ud),document.addEventListener(`touchmove`,c,ud),document.addEventListener(`touchstart`,u,ud),function(){Dd=Dd.filter(function(e){return e!==a}),document.removeEventListener(`wheel`,c,ud),document.removeEventListener(`touchmove`,c,ud),document.removeEventListener(`touchstart`,u,ud)}},[]);var p=e.removeScrollBar,m=e.inert;return v.createElement(v.Fragment,null,m?v.createElement(a,{styles:Td(i)}):null,p?v.createElement(sd,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function kd(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var Ad=Bu(Vu,Od),jd=v.forwardRef(function(e,t){return v.createElement(Uu,wu({},e,{ref:t,sideCar:Ad}))});jd.classNames=Uu.classNames;var Md=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},Nd=new WeakMap,Pd=new WeakMap,Fd={},Id=0,Ld=function(e){return e&&(e.host||Ld(e.parentNode))},Rd=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=Ld(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},zd=function(e,t,n,r){var i=Rd(t,Array.isArray(e)?e:[e]);Fd[n]||(Fd[n]=new WeakMap);var a=Fd[n],o=[],s=new Set,c=new Set(i),l=function(e){!e||s.has(e)||(s.add(e),l(e.parentNode))};i.forEach(l);var u=function(e){!e||c.has(e)||Array.prototype.forEach.call(e.children,function(e){if(s.has(e))u(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(Nd.get(e)||0)+1,l=(a.get(e)||0)+1;Nd.set(e,c),a.set(e,l),o.push(e),c===1&&i&&Pd.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return u(t),s.clear(),Id++,function(){o.forEach(function(e){var t=Nd.get(e)-1,i=a.get(e)-1;Nd.set(e,t),a.set(e,i),t||(Pd.has(e)||e.removeAttribute(r),Pd.delete(e)),i||e.removeAttribute(n)}),Id--,Id||(Nd=new WeakMap,Nd=new WeakMap,Pd=new WeakMap,Fd={})}},Bd=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||Md(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),zd(r,i,n,`aria-hidden`)):function(){return null}},Vd=Object.defineProperty,Hd=(e,t)=>Vd(e,`name`,{value:t,configurable:!0}),Ud=`Dialog`,[Wd,Gd]=Lc(Ud),[Kd,qd]=Wd(Ud),Jd=Hd(e=>{let{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!0}=e,s=v.useRef(null),c=v.useRef(null),[l,u]=ml({prop:r,defaultProp:i??!1,onChange:a,caller:Ud}),[d,f]=v.useState(0),[p,m]=v.useState(0);return(0,I.jsx)(Kd,{scope:t,triggerRef:s,contentRef:c,contentId:Ml(),titleId:Ml(),descriptionId:Ml(),titlePresent:d>0,descriptionPresent:p>0,setTitleCount:f,setDescriptionCount:m,open:l,onOpenChange:u,onOpenToggle:v.useCallback(()=>u(e=>!e),[u]),modal:o,children:n})},`Dialog`),Yd=`DialogTrigger`,Xd=v.forwardRef(Hd(function(e,t){let{__scopeDialog:n,...r}=e,i=qd(Yd,n),a=uc(t,i.triggerRef);return(0,I.jsx)(W.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":_f(i.open),...r,ref:a,onClick:G(e.onClick,i.onOpenToggle)})},`DialogTrigger`)),Zd=`DialogPortal`,[Qd,$d]=Wd(Zd,{forceMount:void 0}),ef=Hd(e=>{let{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=qd(Zd,t);return(0,I.jsx)(Qd,{scope:t,forceMount:n,children:v.Children.map(r,e=>(0,I.jsx)(Sl,{present:n||a.open,children:(0,I.jsx)(gu,{asChild:!0,container:i,children:e})}))})},`DialogPortal`),tf=`DialogOverlay`,nf=v.forwardRef(Hd(function(e,t){let n=$d(tf,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=qd(tf,e.__scopeDialog);return a.modal?(0,I.jsx)(Sl,{present:r||a.open,children:(0,I.jsx)(af,{...i,ref:t})}):null},`DialogOverlay`)),rf=pc(`DialogOverlay.RemoveScroll`),af=v.forwardRef(Hd(function(e,t){let{__scopeDialog:n,...r}=e,i=qd(tf,n),a=uc(t,Kl());return(0,I.jsx)(jd,{as:rf,allowPinchZoom:!0,shards:[i.contentRef],children:(0,I.jsx)(W.div,{"data-state":_f(i.open),...r,ref:a,style:{pointerEvents:`auto`,...r.style}})})},`DialogOverlayImpl`)),of=`DialogContent`,sf=v.forwardRef(Hd(function(e,t){let n=$d(of,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=qd(of,e.__scopeDialog);return(0,I.jsx)(Sl,{present:r||a.open,children:a.modal?(0,I.jsx)(cf,{...i,ref:t}):(0,I.jsx)(lf,{...i,ref:t})})},`DialogContent`)),cf=v.forwardRef(Hd(function(e,t){let n=qd(of,e.__scopeDialog),r=v.useRef(null),i=uc(t,n.contentRef,r);return v.useEffect(()=>{let e=r.current;if(e)return Bd(e)},[]),(0,I.jsx)(uf,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:G(e.onCloseAutoFocus,e=>{e.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:G(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;(t.button===2||n)&&e.preventDefault()}),onFocusOutside:G(e.onFocusOutside,e=>e.preventDefault())})},`DialogContentModal`)),lf=v.forwardRef(Hd(function(e,t){let n=qd(of,e.__scopeDialog),r=v.useRef(!1),i=v.useRef(!1);return(0,I.jsx)(uf,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})},`DialogContentNonModal`)),uf=v.forwardRef(Hd(function(e,t){let{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=e,s=qd(of,n);return Su(),(0,I.jsx)(I.Fragment,{children:(0,I.jsx)(ru,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,I.jsx)(Gl,{role:`dialog`,id:s.contentId,"aria-describedby":s.descriptionPresent?s.descriptionId:void 0,"aria-labelledby":s.titlePresent?s.titleId:void 0,"data-state":_f(s.open),...o,ref:t,deferPointerDownOutside:!0,onDismiss:()=>s.onOpenChange(!1)})})})},`DialogContentImpl`)),df=`DialogTitle`,ff=v.forwardRef(Hd(function(e,t){let{__scopeDialog:n,...r}=e,i=qd(df,n),{setTitleCount:a}=i;return al(()=>(a(e=>e+1),()=>a(e=>e-1)),[a]),(0,I.jsx)(W.h2,{id:i.titleId,...r,ref:t})},`DialogTitle`)),pf=`DialogDescription`,mf=v.forwardRef(Hd(function(e,t){let{__scopeDialog:n,...r}=e,i=qd(pf,n),{setDescriptionCount:a}=i;return al(()=>(a(e=>e+1),()=>a(e=>e-1)),[a]),(0,I.jsx)(W.p,{id:i.descriptionId,...r,ref:t})},`DialogDescription`)),hf=`DialogClose`,gf=v.forwardRef(Hd(function(e,t){let{__scopeDialog:n,...r}=e,i=qd(hf,n);return(0,I.jsx)(W.button,{type:`button`,...r,ref:t,onClick:G(e.onClick,()=>i.onOpenChange(!1))})},`DialogClose`));function _f(e){return e?`open`:`closed`}Hd(_f,`getState`);var vf=Object.defineProperty,yf=(e,t)=>vf(e,`name`,{value:t,configurable:!0});function bf(e){let[t,n]=v.useState(void 0);return al(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=new ResizeObserver(t=>{if(!Array.isArray(t)||!t.length)return;let r=t[0],i,a;if(`borderBoxSize`in r){let e=r.borderBoxSize,t=Array.isArray(e)?e[0]:e;i=t.inlineSize,a=t.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return t.observe(e,{box:`border-box`}),()=>t.unobserve(e)}else n(void 0)},[e]),t}yf(bf,`useSize`);var xf=Object.defineProperty,Sf=(e,t)=>xf(e,`name`,{value:t,configurable:!0}),Cf=`Checkbox`,[wf,Tf]=Lc(Cf),[Ef,Df]=wf(Cf);function Of(e){let{__scopeCheckbox:t,checked:n,children:r,defaultChecked:i,disabled:a,form:o,name:s,onCheckedChange:c,required:l,value:u=`on`,internal_do_not_use_render:d}=e,[f,p]=ml({prop:n,defaultProp:i??!1,onChange:c,caller:Cf}),[m,h]=v.useState(null),[g,_]=v.useState(null),y=v.useRef(!1),[b,x]=v.useReducer(e=>e+1,0),S=!m||!!o||!!m.closest(`form`),C={checked:f,disabled:a,setChecked:p,control:m,setControl:h,name:s,form:o,value:u,hasConsumerStoppedPropagationRef:y,userInteractionCount:b,onUserInteraction:x,required:l,defaultChecked:!Lf(i)&&i,isFormControl:S,bubbleInput:g,setBubbleInput:_};return(0,I.jsx)(Ef,{scope:t,...C,children:If(d)?d(C):r})}Sf(Of,`CheckboxProvider`);var kf=`CheckboxTrigger`,Af=v.forwardRef(Sf(function({__scopeCheckbox:e,onKeyDown:t,onClick:n,...r},i){let{control:a,value:o,disabled:s,checked:c,required:l,setControl:u,setChecked:d,hasConsumerStoppedPropagationRef:f,onUserInteraction:p,isFormControl:m,bubbleInput:h}=Df(kf,e),g=uc(i,u),_=v.useRef(c);return v.useEffect(()=>{let e=a?.form;if(e){let t=Sf(()=>d(_.current),`reset`);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[a,d]),(0,I.jsx)(W.button,{type:`button`,role:`checkbox`,"aria-checked":Lf(c)?`mixed`:c,"aria-required":l,"data-state":Rf(c),"data-disabled":s?``:void 0,disabled:s,value:o,...r,ref:g,onKeyDown:G(t,e=>{e.key===`Enter`&&e.preventDefault()}),onClick:G(n,e=>{p(),d(e=>Lf(e)?!0:!e),h&&m&&(f.current=e.isPropagationStopped(),f.current||e.stopPropagation())})})},`CheckboxTrigger`)),jf=v.forwardRef(Sf(function(e,t){let{__scopeCheckbox:n,name:r,checked:i,defaultChecked:a,required:o,disabled:s,value:c,onCheckedChange:l,form:u,...d}=e;return(0,I.jsx)(Of,{__scopeCheckbox:n,checked:i,defaultChecked:a,disabled:s,required:o,onCheckedChange:l,name:r,form:u,value:c,internal_do_not_use_render:({isFormControl:e})=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Af,{...d,ref:t,__scopeCheckbox:n}),e&&(0,I.jsx)(Ff,{__scopeCheckbox:n})]})})},`Checkbox`)),Mf=`CheckboxIndicator`,Nf=v.forwardRef(Sf(function(e,t){let{__scopeCheckbox:n,forceMount:r,...i}=e,a=Df(Mf,n);return(0,I.jsx)(Sl,{present:r||Lf(a.checked)||a.checked===!0,children:(0,I.jsx)(W.span,{"data-state":Rf(a.checked),"data-disabled":a.disabled?``:void 0,...i,ref:t,style:{pointerEvents:`none`,...e.style}})})},`CheckboxIndicator`)),Pf=`CheckboxBubbleInput`,Ff=v.forwardRef(Sf(function({__scopeCheckbox:e,onClick:t,...n},r){let{control:i,hasConsumerStoppedPropagationRef:a,userInteractionCount:o,checked:s,defaultChecked:c,required:l,disabled:u,name:d,value:f,form:p,bubbleInput:m,setBubbleInput:h}=Df(Pf,e),g=uc(r,h),_=bf(i),y=v.useRef(!1),b=v.useRef(s),x=v.useRef(o);v.useEffect(()=>{let e=m;if(!e)return;let t=window.HTMLInputElement.prototype,n=Object.getOwnPropertyDescriptor(t,`checked`).set,r=o!==x.current;x.current=o;let i=b.current!==s;b.current=s;let c=!(r&&a.current);if(i&&n){y.current=!r;let t=new Event(`click`,{bubbles:c});e.indeterminate=Lf(s),n.call(e,!Lf(s)&&s),e.dispatchEvent(t),y.current=!1}},[m,s,a,o]);let S=v.useRef(!Lf(s)&&s);return(0,I.jsx)(W.input,{type:`checkbox`,"aria-hidden":!0,defaultChecked:c??S.current,required:l,disabled:u,name:d,value:f,form:p,...n,tabIndex:-1,ref:g,onClick:G(t,e=>{y.current&&e.stopPropagation()}),style:{...n.style,..._,position:`absolute`,pointerEvents:`none`,opacity:0,margin:0,transform:`translateX(-100%)`}})},`CheckboxBubbleInput`));function If(e){return typeof e==`function`}Sf(If,`isFunction`);function Lf(e){return e===`indeterminate`}Sf(Lf,`isIndeterminate`);function Rf(e){return Lf(e)?`indeterminate`:e?`checked`:`unchecked`}Sf(Rf,`getState`);var zf=[`top`,`right`,`bottom`,`left`],Bf=Math.min,Vf=Math.max,Hf=Math.round,Uf=Math.floor,Wf=e=>({x:e,y:e}),Gf={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function Kf(e,t,n){return Vf(e,Bf(t,n))}function qf(e,t){return typeof e==`function`?e(t):e}function Jf(e){return e.split(`-`)[0]}function Yf(e){return e.split(`-`)[1]}function Xf(e){return e===`x`?`y`:`x`}function Zf(e){return e===`y`?`height`:`width`}function Qf(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function $f(e){return Xf(Qf(e))}function ep(e,t,n){n===void 0&&(n=!1);let r=Yf(e),i=$f(e),a=Zf(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=lp(o)),[o,lp(o)]}function tp(e){let t=lp(e);return[np(e),t,np(t)]}function np(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var rp=[`left`,`right`],ip=[`right`,`left`],ap=[`top`,`bottom`],op=[`bottom`,`top`];function sp(e,t,n){switch(e){case`top`:case`bottom`:return n?t?ip:rp:t?rp:ip;case`left`:case`right`:return t?ap:op;default:return[]}}function cp(e,t,n,r){let i=Yf(e),a=sp(Jf(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(np)))),a}function lp(e){let t=Jf(e);return Gf[t]+e.slice(t.length)}function up(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function dp(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:up(e)}function fp(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function pp(e,t,n){let{reference:r,floating:i}=e,a=Qf(t),o=$f(t),s=Zf(o),c=Jf(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}let m=Yf(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function mp(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=qf(t,e),p=dp(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=fp(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=fp(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var hp=50,gp=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:mp},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=pp(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<hp&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=pp(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},_p=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=qf(e,t)||{};if(l==null)return{};let d=dp(u),f={x:n,y:r},p=$f(i),m=Zf(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l)),C=S?S[y]:0;(!C||!await(o.isElement==null?void 0:o.isElement(S)))&&(C=s.floating[y]||a.floating[m]);let w=b/2-x/2,T=C/2-h[m]/2-1,E=Bf(d[_],T),ee=Bf(d[v],T),D=C-h[m]-ee,O=C/2-h[m]/2+w,k=Kf(E,O,D),A=!c.arrow&&Yf(i)!=null&&O!==k&&a.reference[m]/2-(O<E?E:ee)-h[m]/2<0,j=A?O<E?O-E:O-D:0;return{[p]:f[p]+j,data:{[p]:k,centerOffset:O-k-j,...A&&{alignmentOffset:j}},reset:A}}}),vp=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=qf(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=Jf(r),_=Qf(o),v=Jf(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[lp(o)]:tp(o)),x=p!==`none`;!d&&x&&b.push(...cp(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=ep(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(!(u===`alignment`&&_!==Qf(t))||T.every(e=>Qf(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=Qf(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}};function yp(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function bp(e){return zf.some(t=>e[t]>=0)}var xp=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=qf(e,t);switch(i){case`referenceHidden`:{let e=yp(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:bp(e)}}}case`escaped`:{let e=yp(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:bp(e)}}}default:return{}}}}},Sp=new Set([`left`,`top`]);async function Cp(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Jf(n),s=Yf(n),c=Qf(n)===`y`,l=Sp.has(o)?-1:1,u=a&&c?-1:1,d=qf(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var wp=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await Cp(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},Tp=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=qf(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=Qf(i),p=Xf(f),m=u[p],h=u[f],g=(e,t)=>Kf(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}},Ep=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=qf(e,t),u={x:n,y:r},d=Qf(i),f=Xf(d),p=u[f],m=u[d],h=qf(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:h.mainAxis??0,crossAxis:h.crossAxis??0};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=Sp.has(Jf(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},Dp=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){let{placement:n,rects:r,platform:i,elements:a}=t,{apply:o=()=>{},...s}=qf(e,t),c=await i.detectOverflow(t,s),l=Jf(n),u=Yf(n),d=Qf(n)===`y`,{width:f,height:p}=r.floating,m,h;l===`top`||l===`bottom`?(m=l,h=u===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?`start`:`end`)?`left`:`right`):(h=l,m=u===`end`?`top`:`bottom`);let g=p-c.top-c.bottom,_=f-c.left-c.right,v=Bf(p-c[m],g),y=Bf(f-c[h],_),b=t.middlewareData.shift,x=!b,S=v,C=y;b!=null&&b.enabled.x&&(C=_),b!=null&&b.enabled.y&&(S=g),x&&!u&&(d?C=f-2*Vf(c.left,c.right):S=p-2*Vf(c.top,c.bottom)),await o({...t,availableWidth:C,availableHeight:S});let w=await i.getDimensions(a.floating);return f!==w.width||p!==w.height?{reset:{rects:!0}}:{}}}};function Op(){return typeof window<`u`}function kp(e){return Mp(e)?(e.nodeName||``).toLowerCase():`#document`}function Ap(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function jp(e){return((Mp(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function Mp(e){return Op()?e instanceof Node||e instanceof Ap(e).Node:!1}function Np(e){return Op()?e instanceof Element||e instanceof Ap(e).Element:!1}function Pp(e){return Op()?e instanceof HTMLElement||e instanceof Ap(e).HTMLElement:!1}function Fp(e){return!Op()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof Ap(e).ShadowRoot}function Ip(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=qp(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function Lp(e){return/^(table|td|th)$/.test(kp(e))}function Rp(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var zp=/transform|translate|scale|rotate|perspective|filter/,Bp=/paint|layout|strict|content/,Vp=e=>!!e&&e!==`none`,Hp;function Up(e){let t=Np(e)?qp(e):e;return Vp(t.transform)||Vp(t.translate)||Vp(t.scale)||Vp(t.rotate)||Vp(t.perspective)||!Gp()&&(Vp(t.backdropFilter)||Vp(t.filter))||zp.test(t.willChange||``)||Bp.test(t.contain||``)}function Wp(e){let t=Yp(e);for(;Pp(t)&&!Kp(t);){if(Up(t))return t;if(Rp(t))return null;t=Yp(t)}return null}function Gp(){return Hp??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),Hp}function Kp(e){return/^(html|body|#document)$/.test(kp(e))}function qp(e){return Ap(e).getComputedStyle(e)}function Jp(e){return Np(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Yp(e){if(kp(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||Fp(e)&&e.host||jp(e);return Fp(t)?t.host:t}function Xp(e){let t=Yp(e);return Kp(t)?(e.ownerDocument||e).body:Pp(t)&&Ip(t)?t:Xp(t)}function Zp(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=Xp(e),i=r===e.ownerDocument?.body,a=Ap(r);if(i){let e=Qp(a);return t.concat(a,a.visualViewport||[],Ip(r)?r:[],e&&n?Zp(e):[])}else return t.concat(r,Zp(r,[],n))}function Qp(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function $p(e){let t=qp(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=Pp(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Hf(n)!==a||Hf(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function em(e){return Np(e)?e:e.contextElement}function tm(e){let t=em(e);if(!Pp(t))return Wf(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=$p(t),o=(a?Hf(n.width):n.width)/r,s=(a?Hf(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var nm=Wf(0);function rm(e){let t=Ap(e);return!Gp()||!t.visualViewport?nm:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function im(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===Ap(e)}function am(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=em(e),o=Wf(1);t&&(r?Np(r)&&(o=tm(r)):o=tm(e));let s=im(a,n,r)?rm(a):Wf(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a&&r){let e=Ap(a),t=Np(r)?Ap(r):r,n=e,i=Qp(n);for(;i&&t!==n;){let e=tm(i),t=i.getBoundingClientRect(),r=qp(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=Ap(i),i=Qp(n)}}return fp({width:u,height:d,x:c,y:l})}function om(e,t){let n=Jp(e).scrollLeft;return t?t.left+n:am(jp(e)).left+n}function sm(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-om(e,n),y:n.top+t.scrollTop}}function cm(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=jp(r),s=t?Rp(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Wf(1),u=Wf(0),d=Pp(r);if((d||!a)&&((kp(r)!==`body`||Ip(o))&&(c=Jp(r)),d)){let e=am(r);l=tm(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?sm(o,c):Wf(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function lm(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function um(e){let t=Jp(e),n=e.ownerDocument.body,r=Vf(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=Vf(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+om(e),o=-t.scrollTop;return qp(n).direction===`rtl`&&(a+=Vf(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var dm=25;function fm(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=Ap(e),a=jp(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!Gp()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(om(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=dm&&(s-=o)}return{width:s,height:c,x:l,y:u}}function pm(e,t){let n=am(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=tm(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function mm(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=fm(e,n,t);else if(t===`document`)r=um(jp(e));else if(Np(t))r=pm(t,n);else{let n=rm(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return fp(r)}function hm(e,t){let n=t.get(e);if(n)return n;let r=Zp(e,[],!1).filter(e=>Np(e)&&kp(e)!==`body`),i=null,a=qp(e).position===`fixed`,o=a?Yp(e):e;for(;Np(o)&&!Kp(o);){let e=qp(o),t=Up(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=Yp(o)}return t.set(e,r),r}function gm(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?Rp(t)?[]:hm(t,this._c):[].concat(n),r],o=mm(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=mm(t,a[e],i);s=Vf(n.top,s),c=Bf(n.right,c),l=Bf(n.bottom,l),u=Vf(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function _m(e){let{width:t,height:n}=$p(e);return{width:t,height:n}}function vm(e,t,n){let r=Pp(t),i=jp(t),a=n===`fixed`,o=am(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=Wf(0);if((r||!a)&&((kp(t)!==`body`||Ip(i))&&(s=Jp(t)),r)){let e=am(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}!r&&i&&(c.x=om(i));let l=i&&!r&&!a?sm(i,s):Wf(0);return{x:o.left+s.scrollLeft-c.x-l.x,y:o.top+s.scrollTop-c.y-l.y,width:o.width,height:o.height}}function ym(e){return qp(e).position===`static`}function bm(e,t){if(!Pp(e)||qp(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return jp(e)===n&&(n=n.ownerDocument.body),n}function xm(e,t){let n=Ap(e);if(Rp(e))return n;if(!Pp(e)){let t=Yp(e);for(;t&&!Kp(t);){if(Np(t)&&!ym(t))return t;t=Yp(t)}return n}let r=bm(e,t);for(;r&&Lp(r)&&ym(r);)r=bm(r,t);return r&&Kp(r)&&ym(r)&&!Up(r)?n:r||Wp(e)||n}var Sm=async function(e){let t=this.getOffsetParent||xm,n=this.getDimensions,r=await n(e.floating);return{reference:vm(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Cm(e){return qp(e).direction===`rtl`}var wm={convertOffsetParentRelativeRectToViewportRelativeRect:cm,getDocumentElement:jp,getClippingRect:gm,getOffsetParent:xm,getElementRects:Sm,getClientRects:lm,getDimensions:_m,getScale:tm,isElement:Np,isRTL:Cm};function Tm(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Em(e,t,n){let r=null,i,a=jp(e);function o(){var e;clearTimeout(i),(e=r)==null||e.disconnect(),r=null}function s(n,c){n===void 0&&(n=!1),c===void 0&&(c=1),o();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(n||t(),!f||!p)return;let m=Uf(d),h=Uf(a.clientWidth-(u+f)),g=Uf(a.clientHeight-(d+p)),_=Uf(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:Vf(0,Bf(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(!Tm(l,e.getBoundingClientRect()))return s();if(n!==c){if(!y)return s();n?s(!1,n):i=setTimeout(()=>{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=Ap(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function Dm(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=em(e),u=i||a?[...l?Zp(l):[],...t?Zp(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?Em(l,n,a):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?am(e):null;c&&g();function g(){let t=am(e);h&&!Tm(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var Om=wp,km=Tp,Am=vp,jm=Dp,Mm=xp,Nm=_p,Pm=Ep,Fm=(e,t,n)=>{let r=new Map,i=n??{},a={...wm,...i.platform,_c:r};return gp(e,t,{...i,platform:a})},Im=typeof document<`u`?v.useLayoutEffect:function(){};function Lm(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Lm(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!Lm(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function Rm(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function zm(e,t){let n=Rm(e);return Math.round(t*n)/n}function Bm(e){let t=v.useRef(e);return Im(()=>{t.current=e}),t}function Vm(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=v.useState(r);Lm(f,r)||p(r);let[m,h]=v.useState(null),[g,_]=v.useState(null),b=v.useCallback(e=>{e!==w.current&&(w.current=e,h(e))},[]),x=v.useCallback(e=>{e!==T.current&&(T.current=e,_(e))},[]),S=a||m,C=o||g,w=v.useRef(null),T=v.useRef(null),E=v.useRef(u),ee=c!=null,D=Bm(c),O=Bm(i),k=Bm(l),A=v.useCallback(()=>{if(!w.current||!T.current)return;let e={placement:t,strategy:n,middleware:f};O.current&&(e.platform=O.current),Fm(w.current,T.current,e).then(e=>{let t={...e,isPositioned:k.current!==!1};j.current&&!Lm(E.current,t)&&(E.current=t,y.flushSync(()=>{d(t)}))})},[f,t,n,O,k]);Im(()=>{l===!1&&E.current.isPositioned&&(E.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let j=v.useRef(!1);Im(()=>(j.current=!0,()=>{j.current=!1}),[]),Im(()=>{if(S&&(w.current=S),C&&(T.current=C),S&&C){if(D.current)return D.current(S,C,A);A()}},[S,C,A,D,ee]);let te=v.useMemo(()=>({reference:w,floating:T,setReference:b,setFloating:x}),[b,x]),ne=v.useMemo(()=>({reference:S,floating:C}),[S,C]),M=v.useMemo(()=>{let e={position:n,left:0,top:0};if(!ne.floating)return e;let t=zm(ne.floating,u.x),r=zm(ne.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...Rm(ne.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,ne.floating,u.x,u.y]);return v.useMemo(()=>({...u,update:A,refs:te,elements:ne,floatingStyles:M}),[u,A,te,ne,M])}var Hm=e=>{function t(e){return{}.hasOwnProperty.call(e,`current`)}return{name:`arrow`,options:e,fn(n){let{element:r,padding:i}=typeof e==`function`?e(n):e;return r&&t(r)?r.current==null?{}:Nm({element:r.current,padding:i}).fn(n):r?Nm({element:r,padding:i}).fn(n):{}}}},Um=(e,t)=>{let n=Om(e);return{name:n.name,fn:n.fn,options:[e,t]}},Wm=(e,t)=>{let n=km(e);return{name:n.name,fn:n.fn,options:[e,t]}},Gm=(e,t)=>({fn:Pm(e).fn,options:[e,t]}),Km=(e,t)=>{let n=Am(e);return{name:n.name,fn:n.fn,options:[e,t]}},qm=(e,t)=>{let n=jm(e);return{name:n.name,fn:n.fn,options:[e,t]}},Jm=(e,t)=>{let n=Mm(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ym=(e,t)=>{let n=Hm(e);return{name:n.name,fn:n.fn,options:[e,t]}},Xm=Object.defineProperty,Zm=v.forwardRef(((e,t)=>Xm(e,`name`,{value:t,configurable:!0}))(function(e,t){let{children:n,width:r=10,height:i=5,...a}=e;return(0,I.jsx)(W.svg,{...a,ref:t,width:r,height:i,viewBox:`0 0 30 10`,preserveAspectRatio:`none`,children:e.asChild?n:(0,I.jsx)(`polygon`,{points:`0,0 30,0 15,10`})})},`Arrow`)),Qm=Object.defineProperty,$m=(e,t)=>Qm(e,`name`,{value:t,configurable:!0}),eh=`Popper`,[th,nh]=Lc(eh),[rh,ih]=th(eh),ah=$m(e=>{let{__scopePopper:t,children:n}=e,[r,i]=v.useState(null),[a,o]=v.useState(void 0);return(0,I.jsx)(rh,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:o,children:n})},`Popper`),oh=`PopperAnchor`,sh=v.forwardRef($m(function(e,t){let{__scopePopper:n,virtualRef:r,...i}=e,a=ih(oh,n),o=v.useRef(null),s=a.onAnchorChange,c=uc(t,v.useCallback(e=>{o.current=e,e&&s(e)},[s])),l=v.useRef(null);v.useEffect(()=>{if(!r)return;let e=l.current;l.current=r.current,e!==l.current&&s(l.current)});let u=a.placementState&&_h(a.placementState),d=u?.[0],f=u?.[1];return r?null:(0,I.jsx)(W.div,{"data-radix-popper-side":d,"data-radix-popper-align":f,...i,ref:c})},`PopperAnchor`)),ch=`PopperContent`,[lh,uh]=th(ch),dh=v.forwardRef($m(function(e,t){let{__scopePopper:n,side:r=`bottom`,sideOffset:i=0,align:a=`center`,alignOffset:o=0,arrowPadding:s=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:d=`partial`,hideWhenDetached:f=!1,updatePositionStrategy:p=`optimized`,onPlaced:m,...h}=e,g=ih(ch,n),[_,y]=v.useState(null),b=uc(t,y),[x,S]=v.useState(null),C=bf(x),w=C?.width??0,T=C?.height??0,E=r+(a===`center`?``:`-`+a),ee=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},D=Array.isArray(l)?l:[l],O=D.length>0,k={padding:ee,boundary:D.filter(hh),altBoundary:O},{refs:A,floatingStyles:j,placement:te,isPositioned:ne,middlewareData:M}=Vm({strategy:`fixed`,placement:E,whileElementsMounted:$m((...e)=>Dm(...e,{animationFrame:p===`always`}),`whileElementsMounted`),elements:{reference:g.anchor},middleware:[Um({mainAxis:i+T,alignmentAxis:o}),c&&Wm({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?Gm():void 0,...k}),c&&Km({...k}),qm({...k,apply:$m(({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)},`apply`)}),x&&Ym({element:x,padding:s}),gh({arrowWidth:w,arrowHeight:T}),f&&Jm({strategy:`referenceHidden`,...k,boundary:O?k.boundary:void 0})]}),N=g.setPlacementState;al(()=>(N(te),()=>{N(void 0)}),[te,N]);let[P,re]=_h(te),ie=K(m);al(()=>{ne&&ie?.()},[ne,ie]);let ae=M.arrow?.x,oe=M.arrow?.y,F=M.arrow?.centerOffset!==0,[se,ce]=v.useState();return al(()=>{_&&ce(window.getComputedStyle(_).zIndex)},[_]),(0,I.jsx)(`div`,{ref:A.setFloating,"data-radix-popper-content-wrapper":``,style:{...j,transform:ne?j.transform:`translate(0, -200%)`,minWidth:`max-content`,zIndex:se,"--radix-popper-transform-origin":[M.transformOrigin?.x,M.transformOrigin?.y].join(` `),...M.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,I.jsx)(lh,{scope:n,placedSide:P,placedAlign:re,onArrowChange:S,arrowX:ae,arrowY:oe,shouldHideArrow:F,children:(0,I.jsx)(W.div,{"data-side":P,"data-align":re,...h,ref:b,style:{...h.style,animation:ne?h.style?.animation:`none`}})})})},`PopperContent`)),fh=`PopperArrow`,ph={top:`bottom`,right:`left`,bottom:`top`,left:`right`},mh=v.forwardRef($m(function(e,t){let{__scopePopper:n,...r}=e,i=uh(fh,n),a=ph[i.placedSide];return(0,I.jsx)(`span`,{ref:i.onArrowChange,style:{position:`absolute`,left:i.arrowX,top:i.arrowY,[a]:0,transformOrigin:{top:``,right:`0 0`,bottom:`center 0`,left:`100% 0`}[i.placedSide],transform:{top:`translateY(100%)`,right:`translateY(50%) rotate(90deg) translateX(-50%)`,bottom:`rotate(180deg)`,left:`translateY(50%) rotate(-90deg) translateX(50%)`}[i.placedSide],visibility:i.shouldHideArrow?`hidden`:void 0},children:(0,I.jsx)(Zm,{...r,ref:t,style:{...r.style,display:`block`}})})},`PopperArrow`));function hh(e){return e!==null}$m(hh,`isNotNull`);var gh=$m(e=>({name:`transformOrigin`,options:e,fn(t){let{placement:n,rects:r,middlewareData:i}=t,a=i.arrow?.centerOffset!==0,o=a?0:e.arrowWidth,s=a?0:e.arrowHeight,[c,l]=_h(n),u={start:`0%`,center:`50%`,end:`100%`}[l],d=(i.arrow?.x??0)+o/2,f=(i.arrow?.y??0)+s/2,p=``,m=``;return c===`bottom`?(p=a?u:`${d}px`,m=`${-s}px`):c===`top`?(p=a?u:`${d}px`,m=`${r.floating.height+s}px`):c===`right`?(p=`${-s}px`,m=a?u:`${f}px`):c===`left`&&(p=`${r.floating.width+s}px`,m=a?u:`${f}px`),{data:{x:p,y:m}}}}),`transformOrigin`);function _h(e){let[t,n=`center`]=e.split(`-`);return[t,n]}$m(_h,`getSideAndAlignFromPlacement`);var vh=ah,yh=sh,bh=dh,xh=mh,Sh=Object.defineProperty,Ch=(e,t)=>Sh(e,`name`,{value:t,configurable:!0}),wh=!1;function Th(){let[e,t]=v.useState(wh);return v.useEffect(()=>{wh||(wh=!0,t(!0))},[]),e}Ch(Th,`useIsHydrated`);var Eh=v.useSyncExternalStore;function Dh(){return()=>{}}Ch(Dh,`subscribe`);function Oh(){return Eh(Dh,()=>!0,()=>!1)}Ch(Oh,`useIsHydratedModern`);var kh=typeof Eh==`function`?Oh:Th,Ah=Object.defineProperty,jh=(e,t)=>Ah(e,`name`,{value:t,configurable:!0}),Mh=`rovingFocusGroup.onEntryFocus`,Nh={bubbles:!1,cancelable:!0},Ph=`RovingFocusGroup`,[Fh,Ih,Lh]=Vc(Ph),[Rh,zh]=Lc(Ph,[Lh]),[Bh,Vh]=Rh(Ph),Hh=v.forwardRef(jh(function(e,t){return(0,I.jsx)(Fh.Provider,{scope:e.__scopeRovingFocusGroup,children:(0,I.jsx)(Fh.Slot,{scope:e.__scopeRovingFocusGroup,children:(0,I.jsx)(Uh,{...e,ref:t})})})},`RovingFocusGroup`)),Uh=v.forwardRef(jh(function(e,t){let{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:c,onEntryFocus:l,preventScrollOnEntryFocus:u=!1,...d}=e,f=v.useRef(null),p=uc(t,f),m=Il(a),[h,g]=ml({prop:o,defaultProp:s??null,onChange:c,caller:Ph}),[_,y]=v.useState(!1),b=K(l),x=Ih(n),S=v.useRef(!1),[C,w]=v.useState(0);return v.useEffect(()=>{let e=f.current;if(e)return e.addEventListener(Mh,b),()=>e.removeEventListener(Mh,b)},[b]),(0,I.jsx)(Bh,{scope:n,orientation:r,dir:m,loop:i,currentTabStopId:h,onItemFocus:v.useCallback(e=>g(e),[g]),onItemShiftTab:v.useCallback(()=>y(!0),[]),onFocusableItemAdd:v.useCallback(()=>w(e=>e+1),[]),onFocusableItemRemove:v.useCallback(()=>w(e=>e-1),[]),children:(0,I.jsx)(W.div,{tabIndex:_||C===0?-1:0,"data-orientation":r,...d,ref:p,style:{outline:`none`,...e.style},onMouseDown:G(e.onMouseDown,()=>{S.current=!0}),onFocus:G(e.onFocus,e=>{let t=!S.current;if(e.target===e.currentTarget&&t&&!_){let t=new CustomEvent(Mh,Nh);if(e.currentTarget.dispatchEvent(t),!t.defaultPrevented){let e=x().filter(e=>e.focusable);Yh([e.find(e=>e.active),e.find(e=>e.id===h),...e].filter(Boolean).map(e=>e.ref.current),u)}}S.current=!1}),onBlur:G(e.onBlur,()=>y(!1))})})},`RovingFocusGroupImpl`)),Wh=`RovingFocusGroupItem`,Gh=v.forwardRef(jh(function(e,t){let{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:a,children:o,...s}=e,c=Ml(),l=a||c,u=Vh(Wh,n),d=u.currentTabStopId===l,f=Ih(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:h}=u,g=kh();return al(()=>{if(!(!g||!r))return p(),()=>m()},[g,r,p,m]),v.useEffect(()=>{if(!(g||!r))return p(),()=>m()},[g,r,p,m]),(0,I.jsx)(Fh.ItemSlot,{scope:n,id:l,focusable:r,active:i,children:(0,I.jsx)(W.span,{tabIndex:d?0:-1,"data-orientation":u.orientation,...s,ref:t,onMouseDown:G(e.onMouseDown,e=>{r?u.onItemFocus(l):e.preventDefault()}),onFocus:G(e.onFocus,()=>u.onItemFocus(l)),onKeyDown:G(e.onKeyDown,e=>{if(e.key===`Tab`&&e.shiftKey){u.onItemShiftTab();return}if(e.target!==e.currentTarget)return;let t=Jh(e,u.orientation,u.dir);if(t!==void 0){if(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return;e.preventDefault();let n=f().filter(e=>e.focusable).map(e=>e.ref.current);if(t===`last`)n.reverse();else if(t===`prev`||t===`next`){t===`prev`&&n.reverse();let r=n.indexOf(e.currentTarget);n=u.loop?Xh(n,r+1):n.slice(r+1)}setTimeout(()=>Yh(n))}}),children:typeof o==`function`?o({isCurrentTabStop:d,hasTabStop:h!=null}):o})})},`RovingFocusGroupItem`)),Kh={ArrowLeft:`prev`,ArrowUp:`prev`,ArrowRight:`next`,ArrowDown:`next`,PageUp:`first`,Home:`first`,PageDown:`last`,End:`last`};function qh(e,t){return t===`rtl`?e===`ArrowLeft`?`ArrowRight`:e===`ArrowRight`?`ArrowLeft`:e:e}jh(qh,`getDirectionAwareKey`);function Jh(e,t,n){let r=qh(e.key,n);if(!(t===`vertical`&&[`ArrowLeft`,`ArrowRight`].includes(r))&&!(t===`horizontal`&&[`ArrowUp`,`ArrowDown`].includes(r)))return Kh[r]}jh(Jh,`getFocusIntent`);function Yh(e,t=!1){let n=document.activeElement;for(let r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}jh(Yh,`focusFirst`);function Xh(e,t){return e.map((n,r)=>e[(t+r)%e.length])}jh(Xh,`wrapArray`);var Zh=Hh,Qh=Gh,$h=Object.defineProperty,eg=(e,t)=>$h(e,`name`,{value:t,configurable:!0}),tg=[`Enter`,` `],ng=[`ArrowDown`,`PageUp`,`Home`],rg=[`ArrowUp`,`PageDown`,`End`],ig=[...ng,...rg];[...tg],[...tg];var ag=`Menu`,[og,sg,cg]=Vc(ag),[lg,ug]=Lc(ag,[cg,nh,zh]),dg=nh(),fg=zh(),[pg,mg]=lg(ag),[hg,gg]=lg(ag),_g=eg(e=>{let{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:a,modal:o=!0}=e,s=dg(t),[c,l]=v.useState(null),u=v.useRef(!1),d=K(a),f=Il(i);return v.useEffect(()=>{let e=eg(()=>{u.current=!0,document.addEventListener(`pointerdown`,t,{capture:!0,once:!0}),document.addEventListener(`pointermove`,t,{capture:!0,once:!0})},`handleKeyDown`),t=eg(()=>u.current=!1,`handlePointer`);return document.addEventListener(`keydown`,e,{capture:!0}),()=>{document.removeEventListener(`keydown`,e,{capture:!0}),document.removeEventListener(`pointerdown`,t,{capture:!0}),document.removeEventListener(`pointermove`,t,{capture:!0})}},[]),v.useEffect(()=>{if(!n)return;let e=eg(()=>d(!1),`handleBlur`);return window.addEventListener(`blur`,e),()=>window.removeEventListener(`blur`,e)},[n,d]),(0,I.jsx)(vh,{...s,children:(0,I.jsx)(pg,{scope:t,open:n,onOpenChange:d,content:c,onContentChange:l,children:(0,I.jsx)(hg,{scope:t,onClose:v.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:f,modal:o,children:r})})})},`Menu`),vg=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,...r}=e,i=dg(n);return(0,I.jsx)(yh,{...i,...r,ref:t})},`MenuAnchor`)),yg=`MenuPortal`,[bg,xg]=lg(yg,{forceMount:void 0}),Sg=eg(e=>{let{__scopeMenu:t,forceMount:n,children:r,container:i}=e,a=mg(yg,t);return(0,I.jsx)(bg,{scope:t,forceMount:n,children:(0,I.jsx)(Sl,{present:n||a.open,children:(0,I.jsx)(gu,{asChild:!0,container:i,children:r})})})},`MenuPortal`),Cg=`MenuContent`,[wg,Tg]=lg(Cg),Eg=v.forwardRef(eg(function(e,t){let n=xg(Cg,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,a=mg(Cg,e.__scopeMenu),o=gg(Cg,e.__scopeMenu);return(0,I.jsx)(og.Provider,{scope:e.__scopeMenu,children:(0,I.jsx)(Sl,{present:r||a.open,children:(0,I.jsx)(og.Slot,{scope:e.__scopeMenu,children:o.modal?(0,I.jsx)(Dg,{...i,ref:t}):(0,I.jsx)(Og,{...i,ref:t})})})})},`MenuContent`)),Dg=v.forwardRef(eg(function(e,t){let n=mg(Cg,e.__scopeMenu),r=v.useRef(null),i=uc(t,r);return v.useEffect(()=>{let e=r.current;if(e)return Bd(e)},[]),(0,I.jsx)(Ag,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:G(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})},`MenuRootContentModal`)),Og=v.forwardRef(eg(function(e,t){let n=mg(Cg,e.__scopeMenu);return(0,I.jsx)(Ag,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})},`MenuRootContentNonModal`)),kg=pc(`MenuContent.ScrollLock`),Ag=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:o,disableOutsidePointerEvents:s,onEntryFocus:c,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,disableOutsideScroll:m,...h}=e,g=mg(Cg,n),_=gg(Cg,n),y=dg(n),b=fg(n),x=sg(n),[S,C]=v.useState(null),w=v.useRef(null),T=uc(t,w,g.onContentChange),E=v.useRef(0),ee=v.useRef(``),D=v.useRef(0),O=v.useRef(null),k=v.useRef(`right`),A=v.useRef(0),j=m?jd:v.Fragment,te=m?{as:kg,allowPinchZoom:!0}:void 0,ne=eg(e=>{let t=ee.current+e,n=x().filter(e=>!e.disabled),r=document.activeElement,i=n.find(e=>e.ref.current===r)?.textValue,a=e_(n.map(e=>e.textValue),t,i),o=n.find(e=>e.textValue===a)?.ref.current;eg((function e(t){ee.current=t,window.clearTimeout(E.current),t!==``&&(E.current=window.setTimeout(()=>e(``),1e3))}),`updateSearch`)(t),o&&setTimeout(()=>o.focus())},`handleTypeaheadSearch`);v.useEffect(()=>()=>window.clearTimeout(E.current),[]),Su();let M=v.useCallback(e=>k.current===O.current?.side&&n_(e,O.current?.area),[]);return(0,I.jsx)(wg,{scope:n,searchRef:ee,onItemEnter:v.useCallback(e=>{M(e)&&e.preventDefault()},[M]),onItemLeave:v.useCallback(e=>{M(e)||(w.current?.focus(),C(null))},[M]),onTriggerLeave:v.useCallback(e=>{M(e)&&e.preventDefault()},[M]),pointerGraceTimerRef:D,onPointerGraceIntentChange:v.useCallback(e=>{O.current=e},[]),children:(0,I.jsx)(j,{...te,children:(0,I.jsx)(ru,{asChild:!0,trapped:i,onMountAutoFocus:G(a,e=>{e.preventDefault(),w.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:(0,I.jsx)(Gl,{asChild:!0,disableOutsidePointerEvents:s,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,children:(0,I.jsx)(Zh,{asChild:!0,...b,dir:_.dir,orientation:`vertical`,loop:r,currentTabStopId:S,onCurrentTabStopIdChange:C,onEntryFocus:G(c,e=>{_.isUsingKeyboardRef.current||e.preventDefault()}),preventScrollOnEntryFocus:!0,children:(0,I.jsx)(bh,{role:`menu`,"aria-orientation":`vertical`,"data-state":Yg(g.open),"data-radix-menu-content":``,dir:_.dir,...y,...h,ref:T,style:{outline:`none`,...h.style},onKeyDown:G(h.onKeyDown,e=>{let t=e.target.closest(`[data-radix-menu-content]`)===e.currentTarget,n=e.ctrlKey||e.altKey||e.metaKey,r=e.key.length===1;t&&(e.key===`Tab`&&e.preventDefault(),!n&&r&&ne(e.key));let i=w.current;if(e.target!==i||!ig.includes(e.key))return;e.preventDefault();let a=x().filter(e=>!e.disabled).map(e=>e.ref.current);rg.includes(e.key)&&a.reverse(),Qg(a)}),onBlur:G(e.onBlur,e=>{e.currentTarget.contains(e.target)||(window.clearTimeout(E.current),ee.current=``)}),onPointerMove:G(e.onPointerMove,r_(e=>{let t=e.target,n=A.current!==e.clientX;if(e.currentTarget.contains(t)&&n){let t=e.clientX>A.current?`right`:`left`;k.current=t,A.current=e.clientX}}))})})})})})})},`MenuContentImpl`)),jg=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,...r}=e;return(0,I.jsx)(W.div,{role:`group`,...r,ref:t})},`MenuGroup`)),Mg=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,...r}=e;return(0,I.jsx)(W.div,{...r,ref:t})},`MenuLabel`)),Ng=`MenuItem`,Pg=`menu.itemSelect`,Fg=v.forwardRef(eg(function(e,t){let{disabled:n=!1,onSelect:r,...i}=e,a=v.useRef(null),o=gg(Ng,e.__scopeMenu),s=Tg(Ng,e.__scopeMenu),c=uc(t,a),l=v.useRef(!1),u=eg(()=>{let e=a.current;if(!n&&e){let t=new CustomEvent(Pg,{bubbles:!0,cancelable:!0});e.addEventListener(Pg,e=>r?.(e),{once:!0}),kc(e,t),t.defaultPrevented?l.current=!1:o.onClose()}},`handleSelect`);return(0,I.jsx)(Ig,{...i,ref:c,disabled:n,onClick:G(e.onClick,u),onPointerDown:t=>{e.onPointerDown?.(t),l.current=!0},onPointerUp:G(e.onPointerUp,e=>{l.current||e.currentTarget?.click()}),onKeyDown:G(e.onKeyDown,e=>{n||e.target!==e.currentTarget||s.searchRef.current!==``&&e.key===` `||tg.includes(e.key)&&(e.currentTarget.click(),e.preventDefault())})})},`MenuItem`)),Ig=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,disabled:r=!1,textValue:i,...a}=e,o=Tg(Ng,n),s=fg(n),c=v.useRef(null),l=uc(t,c),[u,d]=v.useState(!1),[f,p]=v.useState(``);return v.useEffect(()=>{let e=c.current;e&&p((e.textContent??``).trim())},[a.children]),(0,I.jsx)(og.ItemSlot,{scope:n,disabled:r,textValue:i??f,children:(0,I.jsx)(Qh,{asChild:!0,...s,focusable:!r,children:(0,I.jsx)(W.div,{role:`menuitem`,"data-highlighted":u?``:void 0,"aria-disabled":r||void 0,"data-disabled":r?``:void 0,...a,ref:l,onPointerMove:G(e.onPointerMove,r_(e=>{r?o.onItemLeave(e):(o.onItemEnter(e),e.defaultPrevented||e.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:G(e.onPointerLeave,r_(e=>o.onItemLeave(e))),onFocus:G(e.onFocus,()=>d(!0)),onBlur:G(e.onBlur,()=>d(!1))})})})},`MenuItemImpl`)),[Lg,Rg]=lg(`MenuRadioGroup`,{value:void 0,onValueChange:eg(()=>{},`onValueChange`)}),zg=v.forwardRef(eg(function(e,t){let{value:n,onValueChange:r,...i}=e,a=K(r);return(0,I.jsx)(Lg,{scope:e.__scopeMenu,value:n,onValueChange:a,children:(0,I.jsx)(jg,{...i,ref:t})})},`MenuRadioGroup`)),Bg=`MenuRadioItem`,Vg=v.forwardRef(eg(function(e,t){let{value:n,...r}=e,i=Rg(Bg,e.__scopeMenu),a=n===i.value;return(0,I.jsx)(Ug,{scope:e.__scopeMenu,checked:a,children:(0,I.jsx)(Fg,{role:`menuitemradio`,"aria-checked":a,...r,ref:t,"data-state":Zg(a),onSelect:G(r.onSelect,()=>i.onValueChange?.(n),{checkForDefaultPrevented:!1})})})},`MenuRadioItem`)),Hg=`MenuItemIndicator`,[Ug,Wg]=lg(Hg,{checked:!1}),Gg=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,forceMount:r,...i}=e,a=Wg(Hg,n);return(0,I.jsx)(Sl,{present:r||Xg(a.checked)||a.checked===!0,children:(0,I.jsx)(W.span,{...i,ref:t,"data-state":Zg(a.checked)})})},`MenuItemIndicator`)),Kg=v.forwardRef(eg(function(e,t){let{__scopeMenu:n,...r}=e;return(0,I.jsx)(W.div,{role:`separator`,"aria-orientation":`horizontal`,...r,ref:t})},`MenuSeparator`)),[qg,Jg]=lg(`MenuSub`);function Yg(e){return e?`open`:`closed`}eg(Yg,`getOpenState`);function Xg(e){return e===`indeterminate`}eg(Xg,`isIndeterminate`);function Zg(e){return Xg(e)?`indeterminate`:e?`checked`:`unchecked`}eg(Zg,`getCheckedState`);function Qg(e){let t=document.activeElement;for(let n of e)if(n===t||(n.focus(),document.activeElement!==t))return}eg(Qg,`focusFirst`);function $g(e,t){return e.map((n,r)=>e[(t+r)%e.length])}eg($g,`wrapArray`);function e_(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=$g(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}eg(e_,`getNextMatch`);function t_(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}eg(t_,`isPointInPolygon`);function n_(e,t){return t?t_({x:e.clientX,y:e.clientY},t):!1}eg(n_,`isPointerInGraceArea`);function r_(e){return t=>t.pointerType===`mouse`?e(t):void 0}eg(r_,`whenMouse`);var i_=_g,a_=vg,o_=Sg,s_=Eg,c_=Mg,l_=Fg,u_=zg,d_=Vg,f_=Gg,p_=Kg,m_=Object.defineProperty,h_=(e,t)=>m_(e,`name`,{value:t,configurable:!0}),g_=`DropdownMenu`,[__,v_]=Lc(g_,[ug]),y_=ug(),[b_,x_]=__(g_),S_=h_(e=>{let{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:a,onOpenChange:o,modal:s=!0}=e,c=y_(t),l=v.useRef(null),[u,d]=ml({prop:i,defaultProp:a??!1,onChange:o,caller:g_});return(0,I.jsx)(b_,{scope:t,triggerId:Ml(),triggerRef:l,contentId:Ml(),open:u,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(e=>!e),[d]),modal:s,children:(0,I.jsx)(i_,{...c,open:u,onOpenChange:d,dir:r,modal:s,children:n})})},`DropdownMenu`),C_=`DropdownMenuTrigger`,w_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,a=x_(C_,n),o=y_(n),s=uc(t,a.triggerRef);return(0,I.jsx)(a_,{asChild:!0,...o,children:(0,I.jsx)(W.button,{type:`button`,id:a.triggerId,"aria-haspopup":`menu`,"aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":a.open?`open`:`closed`,"data-disabled":r?``:void 0,disabled:r,...i,ref:s,onPointerDown:G(e.onPointerDown,e=>{!r&&e.button===0&&e.ctrlKey===!1&&(a.onOpenToggle(),a.open||e.preventDefault())}),onKeyDown:G(e.onKeyDown,e=>{r||([`Enter`,` `].includes(e.key)&&a.onOpenToggle(),e.key===`ArrowDown`&&a.onOpenChange(!0),[`Enter`,` `,`ArrowDown`].includes(e.key)&&e.preventDefault())})})})},`DropdownMenuTrigger`)),T_=h_(e=>{let{__scopeDropdownMenu:t,...n}=e,r=y_(t);return(0,I.jsx)(o_,{...r,...n})},`DropdownMenuPortal`),E_=`DropdownMenuContent`,D_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=x_(E_,n),a=y_(n),o=v.useRef(!1);return(0,I.jsx)(s_,{id:i.contentId,"aria-labelledby":i.triggerId,...a,...r,ref:t,onCloseAutoFocus:G(e.onCloseAutoFocus,e=>{o.current||i.triggerRef.current?.focus(),o.current=!1,e.preventDefault()}),onInteractOutside:G(e.onInteractOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0,r=t.button===2||n;(!i.modal||r)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-dropdown-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-dropdown-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-dropdown-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-dropdown-menu-trigger-height":`var(--radix-popper-anchor-height)`}})},`DropdownMenuContent`)),O_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=y_(n);return(0,I.jsx)(c_,{...i,...r,ref:t})},`DropdownMenuLabel`)),k_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=y_(n);return(0,I.jsx)(l_,{...i,...r,ref:t})},`DropdownMenuItem`)),A_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=y_(n);return(0,I.jsx)(u_,{...i,...r,ref:t})},`DropdownMenuRadioGroup`)),j_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=y_(n);return(0,I.jsx)(d_,{...i,...r,ref:t})},`DropdownMenuRadioItem`)),M_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=y_(n);return(0,I.jsx)(f_,{...i,...r,ref:t})},`DropdownMenuItemIndicator`)),N_=v.forwardRef(h_(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=y_(n);return(0,I.jsx)(p_,{...i,...r,ref:t})},`DropdownMenuSeparator`)),P_=S_,F_=w_,I_=T_,L_=D_,R_=O_,z_=k_,B_=A_,V_=j_,H_=M_,U_=N_,W_=Object.defineProperty,G_=v.forwardRef(((e,t)=>W_(e,`name`,{value:t,configurable:!0}))(function(e,t){return(0,I.jsx)(W.label,{...e,ref:t,onMouseDown:t=>{t.target.closest(`button, input, select, textarea`)||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}})},`Label`)),K_=Object.defineProperty,q_=(e,t)=>K_(e,`name`,{value:t,configurable:!0});function J_(e){let t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}q_(J_,`usePrevious`);var Y_=Object.defineProperty,X_=(e,t)=>Y_(e,`name`,{value:t,configurable:!0});function Z_(e,[t,n]){return Math.min(n,Math.max(t,e))}X_(Z_,`clamp`);var Q_=Object.defineProperty,$_=(e,t)=>Q_(e,`name`,{value:t,configurable:!0}),ev=[` `,`Enter`,`ArrowUp`,`ArrowDown`],tv=[` `,`Enter`],nv=`Select`,[rv,iv,av]=Vc(nv),[ov,sv]=Lc(nv,[av,nh]),cv=nh(),[lv,uv]=ov(nv),[dv,fv]=ov(nv);function pv(e){let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:a,value:o,defaultValue:s,onValueChange:c,dir:l,name:u,autoComplete:d,disabled:f,required:p,form:m,internal_do_not_use_render:h}=e,g=cv(t),[_,y]=v.useState(null),[b,x]=v.useState(null),[S,C]=v.useState(!1),w=Il(l),[T,E]=ml({prop:r,defaultProp:i??!1,onChange:a,caller:nv}),[ee,D]=ml({prop:o,defaultProp:s,onChange:c,caller:nv}),O=v.useRef(null),k=v.useRef(ee);v.useEffect(()=>{let e=m?_?.ownerDocument.getElementById(m):_?.form;if(e instanceof HTMLFormElement){let t=$_(()=>D(k.current),`reset`);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[m,_,D]);let A=!_||!!m||!!_.closest(`form`),[j,te]=v.useState(new Set),ne=Ml(),M=Array.from(j).map(e=>e.props.value).join(`;`),N=v.useCallback(e=>{te(t=>new Set(t).add(e))},[]),P=v.useCallback(e=>{te(t=>{let n=new Set(t);return n.delete(e),n})},[]),re={required:p,trigger:_,onTriggerChange:y,valueNode:b,onValueNodeChange:x,valueNodeHasChildren:S,onValueNodeHasChildrenChange:C,contentId:ne,value:ee,onValueChange:D,open:T,onOpenChange:E,dir:w,triggerPointerDownPosRef:O,disabled:f,name:u,autoComplete:d,form:m,nativeOptions:j,nativeSelectKey:M,isFormControl:A};return(0,I.jsx)(vh,{...g,children:(0,I.jsx)(lv,{scope:t,...re,children:(0,I.jsx)(rv.Provider,{scope:t,children:(0,I.jsx)(dv,{scope:t,onNativeOptionAdd:N,onNativeOptionRemove:P,children:ty(h)?h(re):n})})})})}$_(pv,`SelectProvider`);var mv=$_(e=>{let{__scopeSelect:t,children:n,...r}=e;return(0,I.jsx)(pv,{__scopeSelect:t,...r,internal_do_not_use_render:({isFormControl:e})=>(0,I.jsxs)(I.Fragment,{children:[n,e?(0,I.jsx)(ey,{__scopeSelect:t}):null]})})},`Select`),hv=`SelectTrigger`,gv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,disabled:r=!1,...i}=e,a=cv(n),o=uv(hv,n),s=o.disabled||r,c=uc(t,o.onTriggerChange),l=iv(n),u=v.useRef(`touch`),[d,f,p]=ry(e=>{let t=l().filter(e=>!e.disabled),n=iy(t,e,t.find(e=>e.value===o.value));n!==void 0&&o.onValueChange(n.value)}),m=$_(e=>{s||(o.onOpenChange(!0),p()),e&&(o.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})},`handleOpen`);return(0,I.jsx)(yh,{asChild:!0,...a,children:(0,I.jsx)(W.button,{type:`button`,role:`combobox`,"aria-controls":o.open?o.contentId:void 0,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":`none`,dir:o.dir,"data-state":o.open?`open`:`closed`,disabled:s,"data-disabled":s?``:void 0,"data-placeholder":ny(o.value)?``:void 0,...i,ref:c,onClick:G(i.onClick,e=>{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:G(i.onPointerDown,e=>{u.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(m(e),e.preventDefault())}),onKeyDown:G(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&ev.includes(e.key)&&(m(),e.preventDefault())})})})},`SelectTrigger`)),_v=`SelectValue`,vv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=uv(_v,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=uc(t,c.onValueNodeChange);al(()=>{l(u)},[l,u]);let f=ny(c.value);return(0,I.jsx)(W.span,{...s,asChild:!f&&s.asChild,ref:d,style:{pointerEvents:`none`},children:(0,I.jsx)(v.Fragment,{children:f?o:a},f?`placeholder`:`value`)})},`SelectValue`)),yv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,children:r,...i}=e;return(0,I.jsx)(W.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})},`SelectIcon`)),[bv,xv]=ov(`SelectPortal`,{forceMount:void 0}),Sv=$_(e=>{let{__scopeSelect:t,forceMount:n,...r}=e;return(0,I.jsx)(bv,{scope:e.__scopeSelect,forceMount:n,children:(0,I.jsx)(gu,{asChild:!0,...r})})},`SelectPortal`),Cv=`SelectContent`,wv=v.forwardRef($_(function(e,t){let n=xv(Cv,e.__scopeSelect),{forceMount:r=n.forceMount,...i}=e,a=uv(Cv,e.__scopeSelect),[o,s]=v.useState();return al(()=>{s(new DocumentFragment)},[]),(0,I.jsx)(Sl,{present:r||a.open,children:({present:e})=>e?(0,I.jsx)(Av,{...i,ref:t}):(0,I.jsx)(Tv,{...i,fragment:o})})},`SelectContent`)),Tv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,children:r,fragment:i}=e;return i?y.createPortal((0,I.jsx)(Dv,{scope:n,children:(0,I.jsx)(rv.Slot,{scope:n,children:(0,I.jsx)(`div`,{ref:t,children:r})})}),i):null},`SelectContentFragment`)),Ev=10,[Dv,Ov]=ov(Cv),kv=pc(`SelectContent.RemoveScroll`),Av=v.forwardRef($_(function(e,t){let{__scopeSelect:n}=e,{position:r=`item-aligned`,onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g,..._}=e,y=uv(Cv,n),[b,x]=v.useState(null),[S,C]=v.useState(null),w=uc(t,x),[T,E]=v.useState(null),[ee,D]=v.useState(null),O=iv(n),[k,A]=v.useState(!1),j=v.useRef(!1);v.useEffect(()=>{if(b)return Bd(b)},[b]),Su();let te=v.useCallback(e=>{let[t,...n]=O().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&S&&(S.scrollTop=0),n===r&&S&&(S.scrollTop=S.scrollHeight),n?.focus(),document.activeElement!==i))return},[O,S]),ne=v.useCallback(()=>te([T,b]),[te,T,b]);v.useEffect(()=>{k&&ne()},[k,ne]);let{onOpenChange:M,triggerPointerDownPosRef:N}=y;v.useEffect(()=>{if(b){let e={x:0,y:0},t=$_(t=>{e={x:Math.abs(Math.round(t.pageX)-(N.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(N.current?.y??0))}},`handlePointerMove`),n=$_(n=>{e.x<=10&&e.y<=10?n.preventDefault():n.composedPath().includes(b)||M(!1),document.removeEventListener(`pointermove`,t),N.current=null},`handlePointerUp`);return N.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[b,M,N]),v.useEffect(()=>{let e=$_(()=>M(!1),`close`);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[M]);let[P,re]=ry(e=>{let t=O().filter(e=>!e.disabled),n=iy(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current?.focus())}),ie=v.useCallback((e,t,n)=>{let r=!j.current&&!n;(y.value!==void 0&&y.value===t||r)&&(E(e),r&&(j.current=!0))},[y.value]),ae=v.useCallback(()=>b?.focus(),[b]),oe=v.useCallback((e,t,n)=>{let r=!j.current&&!n;(y.value!==void 0&&y.value===t||r)&&D(e)},[y.value]),F=r===`popper`?Mv:jv,se=F===Mv?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,I.jsx)(Dv,{scope:n,content:b,viewport:S,onViewportChange:C,itemRefCallback:ie,selectedItem:T,onItemLeave:ae,itemTextRefCallback:oe,focusSelectedItem:ne,selectedItemText:ee,position:r,isPositioned:k,searchRef:P,children:(0,I.jsx)(jd,{as:kv,allowPinchZoom:!0,children:(0,I.jsx)(ru,{asChild:!0,trapped:y.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:G(i,e=>{y.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,I.jsx)(Gl,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>y.onOpenChange(!1),children:(0,I.jsx)(F,{role:`listbox`,id:y.contentId,"data-state":y.open?`open`:`closed`,dir:y.dir,onContextMenu:e=>e.preventDefault(),..._,...se,onPlaced:()=>A(!0),ref:w,style:{display:`flex`,flexDirection:`column`,outline:`none`,..._.style},onKeyDown:G(_.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&re(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=O().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>te(t)),e.preventDefault()}})})})})})})},`SelectContentImpl`)),jv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,onPlaced:r,...i}=e,a=uv(Cv,n),o=Ov(Cv,n),[s,c]=v.useState(null),[l,u]=v.useState(null),d=uc(t,u),f=iv(n),p=v.useRef(!1),m=v.useRef(!0),{viewport:h,selectedItem:g,selectedItemText:_,focusSelectedItem:y}=o,b=v.useCallback(()=>{if(a.trigger&&a.valueNode&&s&&l&&h&&g&&_){let e=a.trigger.getBoundingClientRect(),t=l.getBoundingClientRect(),n=a.valueNode.getBoundingClientRect(),i=_.getBoundingClientRect();if(a.dir!==`rtl`){let r=i.left-t.left,a=n.left-r,o=e.left-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-Ev,d=Z_(a,[Ev,Math.max(Ev,u-l)]);s.style.minWidth=c+`px`,s.style.left=d+`px`}else{let r=t.right-i.right,a=window.innerWidth-n.right-r,o=window.innerWidth-e.right-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-Ev,d=Z_(a,[Ev,Math.max(Ev,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-Ev*2,u=h.scrollHeight,d=window.getComputedStyle(l),m=parseInt(d.borderTopWidth,10),v=parseInt(d.paddingTop,10),y=parseInt(d.borderBottomWidth,10),b=parseInt(d.paddingBottom,10),x=m+v+u+b+y,S=Math.min(g.offsetHeight*5,x),C=window.getComputedStyle(h),w=parseInt(C.paddingTop,10),T=parseInt(C.paddingBottom,10),E=e.top+e.height/2-Ev,ee=c-E,D=g.offsetHeight/2,O=g.offsetTop+D,k=m+v+O,A=x-k;if(k<=E){let e=o.length>0&&g===o[o.length-1].ref.current;s.style.bottom=`0px`;let t=l.clientHeight-h.offsetTop-h.offsetHeight,n=k+Math.max(ee,D+(e?T:0)+t+y);s.style.height=n+`px`}else{let e=o.length>0&&g===o[0].ref.current;s.style.top=`0px`;let t=Math.max(E,m+h.offsetTop+(e?w:0)+D)+A;s.style.height=t+`px`,h.scrollTop=k-E+h.offsetTop}s.style.margin=`${Ev}px 0`,s.style.minHeight=S+`px`,s.style.maxHeight=c+`px`,r?.(),requestAnimationFrame(()=>p.current=!0)}},[f,a.trigger,a.valueNode,s,l,h,g,_,a.dir,r]);al(()=>b(),[b]);let[x,S]=v.useState();return al(()=>{l&&S(window.getComputedStyle(l).zIndex)},[l]),(0,I.jsx)(Nv,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:p,onScrollButtonChange:v.useCallback(e=>{e&&m.current===!0&&(b(),y?.(),m.current=!1)},[b,y]),children:(0,I.jsx)(`div`,{ref:c,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:x},children:(0,I.jsx)(W.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})},`SelectItemAlignedPosition`)),Mv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,align:r=`start`,collisionPadding:i=Ev,...a}=e,o=cv(n);return(0,I.jsx)(bh,{...o,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})},`SelectPopperPosition`)),[Nv,Pv]=ov(Cv,{}),Fv=`SelectViewport`,Iv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,nonce:r,...i}=e,a=Ov(Fv,n),o=Pv(Fv,n),s=uc(t,a.onViewportChange),c=v.useRef(0);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:r}),(0,I.jsx)(rv.Slot,{scope:n,children:(0,I.jsx)(W.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:G(i.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=o;if(r?.current&&n){let e=Math.abs(c.current-t.scrollTop);if(e>0){let r=window.innerHeight-Ev*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}c.current=t.scrollTop})})})]})},`SelectViewport`)),[Lv,Rv]=ov(`SelectGroup`),zv=`SelectItem`,[Bv,Vv]=ov(zv),Hv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=uv(zv,n),c=Ov(zv,n),l=s.value===r,[u,d]=v.useState(a??``),[f,p]=v.useState(!1),m=uc(t,K(e=>c.itemRefCallback?.(e,r,i))),h=Ml(),g=v.useRef(`touch`),_=$_(()=>{i||(s.onValueChange(r),s.onOpenChange(!1))},`handleSelect`);return(0,I.jsx)(Bv,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:v.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,I.jsx)(rv.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,I.jsx)(W.div,{role:`option`,"aria-labelledby":h,"data-highlighted":f?``:void 0,"aria-selected":l&&f,"data-state":l?`checked`:`unchecked`,"aria-disabled":i||void 0,"data-disabled":i?``:void 0,tabIndex:i?void 0:-1,...o,ref:m,onFocus:G(o.onFocus,()=>p(!0)),onBlur:G(o.onBlur,()=>p(!1)),onClick:G(o.onClick,()=>{g.current!==`mouse`&&_()}),onPointerUp:G(o.onPointerUp,()=>{g.current===`mouse`&&_()}),onPointerDown:G(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:G(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:G(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:G(o.onKeyDown,e=>{i||e.target!==e.currentTarget||c.searchRef?.current!==``&&e.key===` `||(tv.includes(e.key)&&_(),e.key===` `&&e.preventDefault())})})})})},`SelectItem`)),Uv=`SelectItemText`,Wv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,className:r,style:i,...a}=e,o=uv(Uv,n),s=Ov(Uv,n),c=Vv(Uv,n),l=fv(Uv,n),[u,d]=v.useState(null),f=K(e=>s.itemTextRefCallback?.(e,c.value,c.disabled)),p=uc(t,d,c.onItemTextChange,f),m=u?.textContent,h=v.useMemo(()=>(0,I.jsx)(`option`,{value:c.value,disabled:c.disabled,children:m},c.value),[c.disabled,c.value,m]),{onNativeOptionAdd:g,onNativeOptionRemove:_}=l;return al(()=>(g(h),()=>_(h)),[g,_,h]),(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(W.span,{id:c.textId,...a,ref:p}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren&&!ny(o.value)?y.createPortal(a.children,o.valueNode):null]})},`SelectItemText`)),Gv=`SelectItemIndicator`,Kv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,...r}=e;return Vv(Gv,n).isSelected?(0,I.jsx)(W.span,{"aria-hidden":!0,...r,ref:t}):null},`SelectItemIndicator`)),qv=`SelectScrollUpButton`,Jv=v.forwardRef($_(function(e,t){let n=Ov(qv,e.__scopeSelect),r=Pv(qv,e.__scopeSelect),[i,a]=v.useState(!1),o=uc(t,r.onScrollButtonChange);return al(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollTop>0;a(e)};$_(e,`handleScroll`);let t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,I.jsx)(Zv,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null},`SelectScrollUpButton`)),Yv=`SelectScrollDownButton`,Xv=v.forwardRef($_(function(e,t){let n=Ov(Yv,e.__scopeSelect),r=Pv(Yv,e.__scopeSelect),[i,a]=v.useState(!1),o=uc(t,r.onScrollButtonChange);return al(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollHeight-t.clientHeight,n=Math.ceil(t.scrollTop)<e;a(n)};$_(e,`handleScroll`);let t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,I.jsx)(Zv,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null},`SelectScrollDownButton`)),Zv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,onAutoScroll:r,...i}=e,a=Ov(`SelectScrollButton`,n),o=v.useRef(null),s=iv(n),c=v.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return v.useEffect(()=>()=>c(),[c]),al(()=>{s().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[s]),(0,I.jsx)(W.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:G(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:G(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:G(i.onPointerLeave,()=>{c()})})},`SelectScrollButtonImpl`)),Qv=v.forwardRef($_(function(e,t){let{__scopeSelect:n,...r}=e;return(0,I.jsx)(W.div,{"aria-hidden":!0,...r,ref:t})},`SelectSeparator`)),$v=`SelectBubbleInput`,ey=v.forwardRef($_(function({__scopeSelect:e,...t},n){let r=uv($v,e),{value:i,onValueChange:a,required:o,disabled:s,name:c,autoComplete:l,form:u}=r,{nativeOptions:d,nativeSelectKey:f}=r,p=v.useRef(null),m=uc(n,p),h=i??``,g=J_(h),_=Array.from(d).some(e=>(e.props.value??``)===``);return v.useEffect(()=>{let e=p.current;if(!e)return;let t=window.HTMLSelectElement.prototype,n=Object.getOwnPropertyDescriptor(t,`value`).set;if(g!==h&&n){let t=new Event(`change`,{bubbles:!0});n.call(e,h),e.dispatchEvent(t)}},[g,h]),(0,I.jsxs)(W.select,{"aria-hidden":!0,required:o,tabIndex:-1,name:c,autoComplete:l,disabled:s,form:u,onChange:e=>a(e.target.value),...t,style:{...Mc,...t.style},ref:m,defaultValue:h,children:[ny(i)&&!_?(0,I.jsx)(`option`,{value:``}):null,Array.from(d)]},f)},`SelectBubbleInput`));function ty(e){return typeof e==`function`}$_(ty,`isFunction`);function ny(e){return e===``||e===void 0}$_(ny,`shouldShowPlaceholder`);function ry(e){let t=K(e),n=v.useRef(``),r=v.useRef(0),i=v.useCallback(e=>{let i=n.current+e;t(i),$_((function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))}),`updateSearch`)(i)},[t]),a=v.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}$_(ry,`useTypeaheadSearch`);function iy(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=ay(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}$_(iy,`findNextItem`);function ay(e,t){return e.map((n,r)=>e[(t+r)%e.length])}$_(ay,`wrapArray`);var oy=Object.defineProperty,sy=(e,t)=>oy(e,`name`,{value:t,configurable:!0}),cy=`Switch`,[ly,uy]=Lc(cy),[dy,fy]=ly(cy);function py(e){let{__scopeSwitch:t,checked:n,children:r,defaultChecked:i,disabled:a,form:o,name:s,onCheckedChange:c,required:l,value:u=`on`,internal_do_not_use_render:d}=e,[f,p]=ml({prop:n,defaultProp:i??!1,onChange:c,caller:cy}),[m,h]=v.useState(null),[g,_]=v.useState(null),y=v.useRef(!1),[b,x]=v.useReducer(e=>e+1,0),S={checked:f,setChecked:p,disabled:a,control:m,setControl:h,name:s,form:o,value:u,hasConsumerStoppedPropagationRef:y,userInteractionCount:b,onUserInteraction:x,required:l,defaultChecked:i,isFormControl:!m||!!o||!!m.closest(`form`),bubbleInput:g,setBubbleInput:_};return(0,I.jsx)(dy,{scope:t,...S,children:xy(d)?d(S):r})}sy(py,`SwitchProvider`);var my=`SwitchTrigger`,hy=v.forwardRef(sy(function({__scopeSwitch:e,onClick:t,...n},r){let{control:i,form:a,value:o,disabled:s,checked:c,required:l,setControl:u,setChecked:d,hasConsumerStoppedPropagationRef:f,onUserInteraction:p,isFormControl:m,bubbleInput:h}=fy(my,e),g=uc(r,u),_=v.useRef(c);return v.useEffect(()=>{let e=a?i?.ownerDocument.getElementById(a):i?.form;if(e instanceof HTMLFormElement){let t=sy(()=>d(_.current),`reset`);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[i,a,d]),(0,I.jsx)(W.button,{type:`button`,role:`switch`,"aria-checked":c,"aria-required":l,"data-state":Sy(c),"data-disabled":s?``:void 0,disabled:s,value:o,...n,ref:g,onClick:G(t,e=>{p(),d(e=>!e),h&&m&&(f.current=e.isPropagationStopped(),f.current||e.stopPropagation())})})},`SwitchTrigger`)),gy=v.forwardRef(sy(function(e,t){let{__scopeSwitch:n,name:r,checked:i,defaultChecked:a,required:o,disabled:s,value:c,onCheckedChange:l,form:u,...d}=e;return(0,I.jsx)(py,{__scopeSwitch:n,checked:i,defaultChecked:a,disabled:s,required:o,onCheckedChange:l,name:r,form:u,value:c,internal_do_not_use_render:({isFormControl:e})=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(hy,{...d,ref:t,__scopeSwitch:n}),e&&(0,I.jsx)(by,{__scopeSwitch:n})]})})},`Switch`)),_y=`SwitchThumb`,vy=v.forwardRef(sy(function(e,t){let{__scopeSwitch:n,...r}=e,i=fy(_y,n);return(0,I.jsx)(W.span,{"data-state":Sy(i.checked),"data-disabled":i.disabled?``:void 0,...r,ref:t})},`SwitchThumb`)),yy=`SwitchBubbleInput`,by=v.forwardRef(sy(function({__scopeSwitch:e,onClick:t,...n},r){let{control:i,hasConsumerStoppedPropagationRef:a,userInteractionCount:o,checked:s,defaultChecked:c,required:l,disabled:u,name:d,value:f,form:p,bubbleInput:m,setBubbleInput:h}=fy(yy,e),g=uc(r,h),_=bf(i),y=v.useRef(!1),b=v.useRef(s),x=v.useRef(o);v.useEffect(()=>{let e=m;if(!e)return;let t=window.HTMLInputElement.prototype,n=Object.getOwnPropertyDescriptor(t,`checked`).set,r=o!==x.current;x.current=o;let i=b.current!==s;b.current=s;let c=!(r&&a.current);if(i&&n){y.current=!r;let t=new Event(`click`,{bubbles:c});n.call(e,s),e.dispatchEvent(t),y.current=!1}},[m,s,a,o]);let S=v.useRef(s);return(0,I.jsx)(W.input,{type:`checkbox`,"aria-hidden":!0,defaultChecked:c??S.current,required:l,disabled:u,name:d,value:f,form:p,...n,tabIndex:-1,ref:g,onClick:G(t,e=>{y.current&&e.stopPropagation()}),style:{...n.style,..._,position:`absolute`,pointerEvents:`none`,opacity:0,margin:0,transform:`translateX(-100%)`}})},`SwitchBubbleInput`));function xy(e){return typeof e==`function`}sy(xy,`isFunction`);function Sy(e){return e?`checked`:`unchecked`}sy(Sy,`getState`);var Cy=Object.defineProperty,wy=(e,t)=>Cy(e,`name`,{value:t,configurable:!0}),Ty=`Tabs`,[Ey,Dy]=Lc(Ty,[zh]),Oy=zh(),[ky,Ay]=Ey(Ty),jy=v.forwardRef(wy(function(e,t){let{__scopeTabs:n,value:r,onValueChange:i,defaultValue:a,orientation:o=`horizontal`,dir:s,activationMode:c=`automatic`,...l}=e,u=Il(s),[d,f]=ml({prop:r,onChange:i,defaultProp:a??``,caller:Ty});return(0,I.jsx)(ky,{scope:n,baseId:Ml(),value:d,onValueChange:f,orientation:o,dir:u,activationMode:c,children:(0,I.jsx)(W.div,{dir:u,"data-orientation":o,...l,ref:t})})},`Tabs`)),My=`TabsList`,Ny=v.forwardRef(wy(function(e,t){let{__scopeTabs:n,loop:r=!0,...i}=e,a=Ay(My,n),o=Oy(n);return(0,I.jsx)(Zh,{asChild:!0,...o,orientation:a.orientation,dir:a.dir,loop:r,children:(0,I.jsx)(W.div,{role:`tablist`,"aria-orientation":a.orientation,...i,ref:t})})},`TabsList`)),Py=`TabsTrigger`,Fy=v.forwardRef(wy(function(e,t){let{__scopeTabs:n,value:r,disabled:i=!1,...a}=e,o=Ay(Py,n),s=Oy(n),c=Iy(o.baseId,r),l=Ly(o.baseId,r),u=r===o.value;return(0,I.jsx)(Qh,{asChild:!0,...s,focusable:!i,active:u,children:(0,I.jsx)(W.button,{type:`button`,role:`tab`,"aria-selected":u,"aria-controls":l,"data-state":u?`active`:`inactive`,"data-disabled":i?``:void 0,disabled:i,id:c,...a,ref:t,onMouseDown:G(e.onMouseDown,e=>{!i&&e.button===0&&e.ctrlKey===!1?o.onValueChange(r):e.preventDefault()}),onKeyDown:G(e.onKeyDown,e=>{i||e.target!==e.currentTarget||[` `,`Enter`].includes(e.key)&&o.onValueChange(r)}),onFocus:G(e.onFocus,()=>{let e=o.activationMode!==`manual`;!u&&!i&&e&&o.onValueChange(r)})})})},`TabsTrigger`));function Iy(e,t){return`${e}-trigger-${t}`}wy(Iy,`makeTriggerId`);function Ly(e,t){return`${e}-content-${t}`}wy(Ly,`makeContentId`);var Ry=jy,zy=Ny,By=Fy,Vy=Object.defineProperty,Hy=(e,t)=>Vy(e,`name`,{value:t,configurable:!0}),[Uy,Wy]=Lc(`Tooltip`,[nh]),Gy=nh(),Ky=`TooltipProvider`,qy=700,Jy=`tooltip.open`,[Yy,Xy]=Uy(Ky),Zy=Hy(e=>{let{__scopeTooltip:t,delayDuration:n=qy,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=v.useRef(!0),s=v.useRef(!1),c=v.useRef(0);return v.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,I.jsx)(Yy,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:v.useCallback(()=>{r<=0||(window.clearTimeout(c.current),o.current=!1)},[r]),onClose:v.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r))},[r]),isPointerInTransitRef:s,onPointerInTransitChange:v.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})},`TooltipProvider`),Qy=`Tooltip`,[$y,eb]=Uy(Qy),tb=Hy(e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=Xy(Qy,e.__scopeTooltip),l=Gy(t),[u,d]=v.useState(null),[f,p]=v.useState(void 0),m=Ml(),h=v.useRef(0),g=o??c.disableHoverableContent,_=s??c.delayDuration,y=v.useRef(!1),[b,x]=ml({prop:r,defaultProp:i??!1,onChange:Hy(e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(Jy))):c.onClose(),a?.(e)},`onChange`),caller:Qy}),S=v.useMemo(()=>b?y.current?`delayed-open`:`instant-open`:`closed`,[b]),C=v.useCallback(()=>{window.clearTimeout(h.current),h.current=0,y.current=!1,x(!0)},[x]),w=v.useCallback(()=>{window.clearTimeout(h.current),h.current=0,x(!1)},[x]),T=v.useCallback(()=>{window.clearTimeout(h.current),h.current=window.setTimeout(()=>{y.current=!0,x(!0),h.current=0},_)},[_,x]);v.useEffect(()=>()=>{h.current&&=(window.clearTimeout(h.current),0)},[]);let E=f??m;return(0,I.jsx)(vh,{...l,children:(0,I.jsx)($y,{scope:t,contentId:E,setContentId:p,open:b,stateAttribute:S,trigger:u,onTriggerChange:d,onTriggerEnter:v.useCallback(()=>{c.isOpenDelayedRef.current?T():C()},[c.isOpenDelayedRef,T,C]),onTriggerLeave:v.useCallback(()=>{g?w():(window.clearTimeout(h.current),h.current=0)},[w,g]),onOpen:C,onClose:w,disableHoverableContent:g,children:n})})},`Tooltip`),nb=`TooltipTrigger`,rb=v.forwardRef(Hy(function(e,t){let{__scopeTooltip:n,...r}=e,i=eb(nb,n),a=Xy(nb,n),o=Gy(n),s=uc(t,v.useRef(null),i.onTriggerChange),c=v.useRef(!1),l=v.useRef(!1),u=v.useCallback(()=>c.current=!1,[]);return v.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,I.jsx)(yh,{asChild:!0,...o,children:(0,I.jsx)(W.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:G(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:G(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:G(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:G(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:G(e.onBlur,i.onClose),onClick:G(e.onClick,i.onClose)})})},`TooltipTrigger`)),ib=`TooltipPortal`,[ab,ob]=Uy(ib,{forceMount:void 0}),sb=Hy(e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=eb(ib,t);return(0,I.jsx)(ab,{scope:t,forceMount:n,children:(0,I.jsx)(Sl,{present:n||a.open,children:(0,I.jsx)(gu,{asChild:!0,container:i,children:r})})})},`TooltipPortal`),cb=`TooltipContent`,lb=v.forwardRef(Hy(function(e,t){let n=ob(cb,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=eb(cb,e.__scopeTooltip);return(0,I.jsx)(Sl,{present:r||o.open,children:o.disableHoverableContent?(0,I.jsx)(fb,{side:i,...a,ref:t}):(0,I.jsx)(ub,{side:i,...a,ref:t})})},`TooltipContent`)),ub=v.forwardRef(Hy(function(e,t){let n=eb(cb,e.__scopeTooltip),r=Xy(cb,e.__scopeTooltip),i=v.useRef(null),a=uc(t,i),[o,s]=v.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=v.useCallback(()=>{s(null),d(!1)},[d]),p=v.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=hb(r,mb(r,n.getBoundingClientRect())),a=gb(t.getBoundingClientRect()),o=vb([...i,...a]);s(o),d(!0)},[d]);return v.useEffect(()=>()=>f(),[f]),v.useEffect(()=>{if(c&&u){let e=Hy(e=>p(e,u),`handleTriggerLeave`),t=Hy(e=>p(e,c),`handleContentLeave`);return c.addEventListener(`pointerleave`,e),u.addEventListener(`pointerleave`,t),()=>{c.removeEventListener(`pointerleave`,e),u.removeEventListener(`pointerleave`,t)}}},[c,u,p,f]),v.useEffect(()=>{if(o){let e=Hy(e=>{let t=e.target,n={x:e.clientX,y:e.clientY},r=c?.contains(t)||u?.contains(t),i=!_b(n,o);r?f():i&&(f(),l())},`handleTrackPointerGrace`);return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,I.jsx)(fb,{...e,ref:a})},`TooltipContentHoverable`)),db=gc(`TooltipContent`),fb=v.forwardRef(Hy(function(e,t){let{__scopeTooltip:n,children:r,"aria-label":i,id:a,onEscapeKeyDown:o,onPointerDownOutside:s,...c}=e,l=eb(cb,n),u=Gy(n),{onClose:d}=l;v.useEffect(()=>(document.addEventListener(Jy,d),()=>document.removeEventListener(Jy,d)),[d]),v.useEffect(()=>{if(l.trigger){let e=Hy(e=>{e.target instanceof Node&&e.target.contains(l.trigger)&&d()},`handleScroll`);return window.addEventListener(`scroll`,e,{capture:!0}),()=>window.removeEventListener(`scroll`,e,{capture:!0})}},[l.trigger,d]);let{setContentId:f}=l;return al(()=>(f(a),()=>{f(void 0)}),[a,f]),(0,I.jsx)(Gl,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:s,onFocusOutside:e=>e.preventDefault(),onDismiss:d,children:(0,I.jsxs)(bh,{"data-state":l.stateAttribute,role:i?void 0:`tooltip`,id:i?void 0:l.contentId,...u,...c,ref:t,style:{...c.style,"--radix-tooltip-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-tooltip-content-available-width":`var(--radix-popper-available-width)`,"--radix-tooltip-content-available-height":`var(--radix-popper-available-height)`,"--radix-tooltip-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-tooltip-trigger-height":`var(--radix-popper-anchor-height)`},children:[(0,I.jsx)(db,{children:r}),i?(0,I.jsx)(Nc,{id:l.contentId,role:`tooltip`,children:i}):null]})})},`TooltipContentImpl`)),pb=v.forwardRef(Hy(function(e,t){let{__scopeTooltip:n,...r}=e,i=Gy(n);return(0,I.jsx)(xh,{...i,...r,ref:t})},`TooltipArrow`));function mb(e,t){let n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),a=Math.abs(t.left-e.x);switch(Math.min(n,r,i,a)){case a:return`left`;case i:return`right`;case n:return`top`;case r:return`bottom`;default:throw Error(`unreachable`)}}Hy(mb,`getExitSideFromRect`);function hb(e,t,n=5){let r=[];switch(t){case`top`:r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case`bottom`:r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case`left`:r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case`right`:r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}Hy(hb,`getPaddedExitPoints`);function gb(e){let{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}Hy(gb,`getPointsFromRect`);function _b(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}Hy(_b,`isPointInPolygon`);function vb(e){let t=e.slice();return t.sort((e,t)=>e.x<t.x?-1:e.x>t.x?1:e.y<t.y?-1:+(e.y>t.y)),yb(t)}Hy(vb,`getHull`);function yb(e){if(e.length<=1)return e.slice();let t=[];for(let n=0;n<e.length;n++){let r=e[n];for(;t.length>=2;){let e=t[t.length-1],n=t[t.length-2];if((e.x-n.x)*(r.y-n.y)>=(e.y-n.y)*(r.x-n.x))t.pop();else break}t.push(r)}t.pop();let n=[];for(let t=e.length-1;t>=0;t--){let r=e[t];for(;n.length>=2;){let e=n[n.length-1],t=n[n.length-2];if((e.x-t.x)*(r.y-t.y)>=(e.y-t.y)*(r.x-t.x))n.pop();else break}n.push(r)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}Hy(yb,`getHullPresorted`);var bb=Zy,xb=tb,Sb=rb,Cb=sb,wb=lb,Tb=pb;function Eb({delayDuration:e=0,...t}){return(0,I.jsx)(bb,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function Db({...e}){return(0,I.jsx)(xb,{"data-slot":`tooltip`,...e})}function Ob({...e}){return(0,I.jsx)(Sb,{"data-slot":`tooltip-trigger`,...e})}function kb({className:e,sideOffset:t=0,children:n,...r}){return(0,I.jsx)(Cb,{children:(0,I.jsxs)(wb,{"data-slot":`tooltip-content`,sideOffset:t,className:H(`z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95`,e),...r,children:[n,(0,I.jsx)(Tb,{className:`z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground`})]})})}var Ab=eo(`inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary-hover`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40`,outline:`border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary-ink underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,xs:`h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5`,lg:`h-10 rounded-md px-6 has-[>svg]:px-4`,icon:`size-9`,"icon-xs":`size-6 rounded-md [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-8`,"icon-lg":`size-10`}},defaultVariants:{variant:`default`,size:`default`}});function Y({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,I.jsx)(r?mc:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:H(Ab({variant:t,size:n,className:e})),...i})}function jb({...e}){return(0,I.jsx)(Jd,{"data-slot":`sheet`,...e})}function Mb({...e}){return(0,I.jsx)(Xd,{"data-slot":`sheet-trigger`,...e})}function Nb({className:e,children:t,side:n=`left`,showCloseButton:r=!0,...i}){return(0,I.jsxs)(ef,{"data-slot":`sheet-portal`,children:[(0,I.jsx)(nf,{"data-slot":`sheet-overlay`,className:`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`}),(0,I.jsxs)(sf,{"data-slot":`sheet-content`,className:H(`fixed inset-y-0 z-50 flex w-3/4 max-w-sm flex-col bg-background shadow-lg outline-none transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-200 data-[state=open]:animate-in data-[state=open]:duration-300`,n===`left`&&`left-0 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left`,n===`right`&&`right-0 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right`,e),...i,children:[t,r&&(0,I.jsxs)(gf,{className:`absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none`,children:[(0,I.jsx)(Ya,{className:`size-4`}),(0,I.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function Pb({className:e,...t}){return(0,I.jsx)(ff,{"data-slot":`sheet-title`,className:H(`text-base leading-none font-semibold`,e),...t})}var Fb=eo(`inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3`,{variants:{variant:{default:`bg-primary text-primary-foreground [a&]:hover:bg-primary-hover`,secondary:`bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90`,destructive:`bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90`,outline:`border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,ghost:`[a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,link:`text-primary-ink underline-offset-4 [a&]:hover:underline`}},defaultVariants:{variant:`default`}});function Ib({className:e,variant:t=`default`,asChild:n=!1,...r}){return(0,I.jsx)(n?mc:`span`,{"data-slot":`badge`,"data-variant":t,className:H(Fb({variant:t}),e),...r})}function Lb({...e}){return(0,I.jsx)(P_,{"data-slot":`dropdown-menu`,...e})}function Rb({...e}){return(0,I.jsx)(F_,{"data-slot":`dropdown-menu-trigger`,...e})}function zb({className:e,sideOffset:t=4,...n}){return(0,I.jsx)(I_,{children:(0,I.jsx)(L_,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:H(`z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,e),...n})})}function Bb({className:e,inset:t,variant:n=`default`,...r}){return(0,I.jsx)(z_,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:H(`relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!`,e),...r})}function Vb({...e}){return(0,I.jsx)(B_,{"data-slot":`dropdown-menu-radio-group`,...e})}function Hb({className:e,children:t,...n}){return(0,I.jsxs)(V_,{"data-slot":`dropdown-menu-radio-item`,className:H(`relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),...n,children:[(0,I.jsx)(`span`,{className:`pointer-events-none absolute left-2 flex size-3.5 items-center justify-center`,children:(0,I.jsx)(H_,{children:(0,I.jsx)(ma,{className:`size-2 fill-current`})})}),t]})}function Ub({className:e,inset:t,...n}){return(0,I.jsx)(R_,{"data-slot":`dropdown-menu-label`,"data-inset":t,className:H(`px-2 py-1.5 text-sm font-medium data-[inset]:pl-8`,e),...n})}function Wb({className:e,...t}){return(0,I.jsx)(U_,{"data-slot":`dropdown-menu-separator`,className:H(`-mx-1 my-1 h-px bg-border`,e),...t})}var Gb={normal:`bg-primary`,warning:`bg-amber-500`,destructive:`bg-destructive`};function Kb({meter:e,className:t}){return e.ratio===null?null:(0,I.jsx)(`div`,{className:H(`h-1.5 w-full overflow-hidden rounded-full bg-muted`,t),role:`progressbar`,"aria-label":`Monthly request allowance used`,"aria-valuemin":0,"aria-valuemax":e.limit??void 0,"aria-valuenow":e.used,"aria-valuetext":e.label,children:(0,I.jsx)(`div`,{className:H(`h-full rounded-full`,Gb[e.tone]),style:{width:`${e.used>0?Math.max(e.ratio*100,2):0}%`}})})}var qb=`M41 0 L82 12 L82 52 C82 71 69.7 90.3 41 100 C12.3 90.3 0 71 0 52 L0 12 Z`,Jb=.82,Yb=.46,Xb=-.06,Zb=.04;function Qb({size:e=22}){let t={width:e*Jb,height:e,transform:`translateY(${e*Zb}px)`},n={fontSize:e*Yb,transform:`translateY(${e*Xb}px)`};return(0,I.jsxs)(`span`,{className:`grid flex-none place-items-center`,style:t,children:[(0,I.jsx)(`svg`,{className:`col-start-1 row-start-1 block size-full fill-(--brand-mark)`,viewBox:`0 0 82 100`,"aria-hidden":`true`,focusable:`false`,children:(0,I.jsx)(`path`,{d:qb})}),(0,I.jsx)(`span`,{className:`col-start-1 row-start-1 font-bold leading-none tracking-[0.01em] text-white`,style:n,children:`AI`})]})}function $b({className:e,onClick:t}){return(0,I.jsxs)(Pn,{to:`/apps`,onClick:t,className:H(`flex items-center gap-1.5 rounded-md text-sm font-semibold tracking-tight`,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`,e),children:[(0,I.jsx)(`span`,{children:`App`}),(0,I.jsx)(Qb,{size:22}),(0,I.jsx)(`span`,{children:`Gateway`})]})}var ex={owner:`Owner`,admin:`Admin`,member:`Member`};function tx(e){return e===`owner`||e===`admin`}var nx=`Your role is read-only. Ask an owner or admin to make this change.`;function rx(e){return e>1}var ix=(0,v.createContext)(null);function ax({session:e,capabilities:t,billing:n,quota:r,children:i}){let a=tx(e.role),o={session:e,capabilities:t,organization:e.organization,memberships:e.memberships,role:e.role,canManage:a,readOnly:!a,billing:n,quota:r};return(0,I.jsx)(ix,{value:o,children:i})}function ox(){let e=(0,v.use)(ix);if(!e)throw Error(`useConsoleSession must be used inside the authenticated console shell`);return e}function sx(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r!=null&&r!==``&&t.set(n,String(r));let n=t.toString();return n?`?${n}`:``}var cx=encodeURIComponent;function X(){return(e,t)=>({method:e,path:t})}var lx={getConsoleCapabilities:X()(`GET`,()=>`/v1/console/capabilities`),getAdminSession:X()(`GET`,()=>`/v1/admin/session`),listOrganizations:X()(`GET`,()=>`/v1/admin/organizations`),selectOrganization:X()(`POST`,()=>`/v1/admin/organizations/select`),listManagementKeys:X()(`GET`,()=>`/v1/admin/keys`),createManagementKey:X()(`POST`,()=>`/v1/admin/keys`),revokeManagementKey:X()(`POST`,e=>`/v1/admin/keys/${cx(e)}/revoke`),listProviders:X()(`GET`,()=>`/v1/admin/providers`),createProvider:X()(`POST`,()=>`/v1/admin/providers`),testProvider:X()(`POST`,()=>`/v1/admin/providers/test`),updateProvider:X()(`PUT`,e=>`/v1/admin/providers/${cx(e)}`),deleteProvider:X()(`DELETE`,e=>`/v1/admin/providers/${cx(e)}`),listProviderGateways:X()(`GET`,()=>`/v1/admin/provider-gateways`),createProviderGateway:X()(`POST`,()=>`/v1/admin/provider-gateways`),testProviderGateway:X()(`POST`,()=>`/v1/admin/provider-gateways/test`),updateProviderGateway:X()(`PATCH`,e=>`/v1/admin/provider-gateways/${cx(e)}`),rotateProviderGateway:X()(`POST`,e=>`/v1/admin/provider-gateways/${cx(e)}/rotate`),deleteProviderGateway:X()(`DELETE`,e=>`/v1/admin/provider-gateways/${cx(e)}`),listApps:X()(`GET`,(e={})=>`/v1/admin/apps${sx(e)}`),createApp:X()(`POST`,()=>`/v1/admin/apps`),getApp:X()(`GET`,e=>`/v1/admin/apps/${cx(e)}`),updateApp:X()(`PUT`,e=>`/v1/admin/apps/${cx(e)}`),deleteApp:X()(`DELETE`,e=>`/v1/admin/apps/${cx(e)}${sx({confirm:e})}`),validateApp:X()(`POST`,e=>`/v1/admin/apps/${cx(e)}/validate`),listAppKeys:X()(`GET`,e=>`/v1/admin/apps/${cx(e)}/keys`),createAppKey:X()(`POST`,e=>`/v1/admin/apps/${cx(e)}/keys`),revokeAppKey:X()(`POST`,(e,t)=>`/v1/admin/apps/${cx(e)}/keys/${cx(t)}/revoke`),listAppUsers:X()(`GET`,(e,t)=>`/v1/admin/apps/${cx(e)}/users${sx(t)}`),setAppUserBlocked:X()(`POST`,(e,t,n)=>`/v1/admin/apps/${cx(e)}/users/${cx(t)}/${n?`block`:`unblock`}`),getAppUsage:X()(`GET`,(e,t={})=>`/v1/admin/apps/${cx(e)}/usage${sx(t)}`),getAppUsageTimeseries:X()(`GET`,(e,t)=>`/v1/admin/apps/${cx(e)}/usage/timeseries${sx(t)}`),getAppUsageBreakdown:X()(`GET`,(e,t)=>`/v1/admin/apps/${cx(e)}/usage/breakdown${sx(t)}`),listAppEvents:X()(`GET`,(e,t)=>`/v1/admin/apps/${cx(e)}/events${sx(t)}`),getAppAuthEventSummary:X()(`GET`,(e,t)=>`/v1/admin/apps/${cx(e)}/auth-events/summary${sx(t)}`),listAppAuthEvents:X()(`GET`,(e,t)=>`/v1/admin/apps/${cx(e)}/auth-events${sx(t)}`),listModelPrices:X()(`GET`,()=>`/v1/admin/prices`),getCliCapabilities:X()(`GET`,()=>`/v1/cli/capabilities`),bootstrapCliAccount:X()(`POST`,()=>`/v1/cli/bootstrap`),createCliOperation:X()(`POST`,()=>`/v1/cli/operations`),pollCliOperation:X()(`GET`,e=>`/v1/cli/operations/${cx(e)}`),getCliAccount:X()(`GET`,()=>`/v1/cli/account`),getCliUsage:X()(`GET`,(e={})=>`/v1/cli/usage${sx(e)}`)},ux=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t,this.name=`ApiError`}},dx=e=>e instanceof ux&&e.status===401,fx=e=>e instanceof ux&&e.status===402;function px(e,t){let n=t??{};return new ux(e,n.error?.code??n.code??`unknown`,n.error?.message??n.message??`Request failed with status ${e}`)}async function mx(e,t={}){let n=new Headers(t.headers);n.set(`x-console-request`,`1`),t.body!==void 0&&n.set(`content-type`,`application/json`);let r=await fetch(e,{...t,headers:n,credentials:`same-origin`}),i=await r.text(),a=null;try{a=i?JSON.parse(i):null}catch{a=null}if(!r.ok)throw px(r.status,a);return a}function hx(e,t,n,r){return mx(e.path(...t),{method:e.method,...n===void 0?{}:{body:JSON.stringify(n)},...r===void 0?{}:{headers:r}})}var gx={get:e=>mx(e),post:(e,t)=>mx(e,{method:`POST`,body:t===void 0?void 0:JSON.stringify(t)}),put:(e,t,n)=>mx(e,{method:`PUT`,body:JSON.stringify(t),headers:n}),patch:(e,t)=>mx(e,{method:`PATCH`,body:JSON.stringify(t)}),delete:e=>mx(e,{method:`DELETE`})},_x={enabled:!1,capture(e,t){},identify(e,t,n){},group(e,t){},reset(){}};function vx(e,t){_x.capture(`provider_added`,{provider:e,route:t?`gateway`:`direct`})}function yx(e){_x.capture(`app_created`,{authentication:e})}function bx(){let{pathname:e}=dt();(0,v.useEffect)(()=>{_x.capture(`$pageview`)},[e])}var xx=`/login`,Sx=`/signup`,Cx=`/apps`,wx=`/checkout`,Tx=new Set([xx,Sx]),Ex=`from`,Dx=`error`;function Ox(e){return e instanceof ux?!(e.status>=400&&e.status<500):!0}function kx(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/\\`)?!1:!Tx.has(new URL(e,`https://console.invalid`).pathname)}function Ax(e){let t=new URLSearchParams(e).get(Ex);return kx(t)?t:Cx}var jx=`plan`,Mx=/^[a-z0-9_-]{1,32}$/u;function Nx(e){let t=new URLSearchParams(e).get(jx);return t!==null&&Mx.test(t)?t:null}function Px(e){return`${wx}?${jx}=${encodeURIComponent(e)}`}function Fx(e,t){return t===null?e:`${e}?${jx}=${encodeURIComponent(t)}`}function Ix(e){let t=Nx(e);return t!==null&&t!==`free`?Px(t):Ax(e)}function Lx(e){return!kx(e)||e===`/apps`?xx:`${xx}?${Ex}=${encodeURIComponent(e)}`}var Rx=`checkout`,zx=`success`;function Bx(e){return new URLSearchParams(e).get(Rx)===zx}function Vx(e,t){let n=new URLSearchParams(t);n.delete(Rx),n.delete(jx);let r=n.toString();return r?`${e}?${r}`:e}var Hx=`${Cx}?${Rx}=${zx}`;function Ux(e){return`${Hx}&${jx}=${encodeURIComponent(e)}`}var Wx={access_denied:{tone:`default`,title:`Google sign-in was cancelled`,description:`You declined the permission request. Try again or use your password.`},registration_disabled:{tone:`destructive`,title:`This gateway does not accept new accounts`,description:`Your Google account is not registered here. Ask an owner or admin to add you, then sign in.`},signup_disabled:{tone:`destructive`,title:`This gateway does not accept new accounts`,description:`Your Google account is not registered here. Ask an owner or admin to add you, then sign in.`}};function Gx(e){let t=new URLSearchParams(e).get(Dx);return t?Wx[t.trim().toLowerCase().replaceAll(/[\s-]+/gu,`_`)]??{tone:`destructive`,title:`Sign-in failed`,description:`The identity provider rejected the sign-in. Try again or use your password.`}:null}var Kx=`/v1/auth`;function qx(e){return gx.post(`${Kx}/sign-in/email`,{...e,rememberMe:!0})}function Jx(e){return gx.post(`${Kx}/sign-up/email`,e)}function Yx(){return gx.post(`${Kx}/sign-out`,{})}function Xx(e){return gx.post(`${Kx}/change-password`,e)}async function Zx(e){let t=kx(e)?e:Cx,n=await gx.post(`${Kx}/sign-in/social`,{provider:`google`,callbackURL:t,errorCallbackURL:Lx(t)});if(!n?.url)throw Error(`Google sign-in is unavailable right now.`);window.location.assign(n.url)}var Qx=e=>e,$x=e=>e,eS={capabilities:[`capabilities`],session:[`session`],organizations:[`organizations`],managementKeys:[`management-keys`],providers:[`providers`],providerGateways:[`provider-gateways`],billingStatus:[`billing`,`status`],billingPlans:[`billing`,`plans`],apps:e=>[`apps`,e],app:e=>[`app`,e],apiKeys:e=>[`api-keys`,e],users:(e,t)=>[`users`,e,t],usage:(e,t)=>[`usage`,e,t],timeseries:(e,t,n)=>[`timeseries`,e,t,n],breakdown:(e,t,n,r)=>[`breakdown`,e,t,n,r],events:(e,t)=>[`events`,e,t],authEventSummary:(e,t)=>[`auth-event-summary`,e,t],authEvents:(e,t)=>[`auth-events`,e,t],prices:[`prices`]};function tS(){return Ti({queryKey:eS.capabilities,queryFn:()=>hx(lx.getConsoleCapabilities,[]),staleTime:1/0,retry:1})}function nS(){return Ti({queryKey:eS.session,queryFn:async()=>(await hx(lx.getAdminSession,[])).session,retry:!1,staleTime:6e4})}function rS(){let e=ui();return Ei({mutationFn:e=>qx(e),onSuccess:()=>e.invalidateQueries()})}function iS(){let e=ui();return Ei({mutationFn:e=>Jx(e),onSuccess:()=>e.invalidateQueries()})}function aS(){let e=ui();return Ei({mutationFn:()=>Yx(),onSettled:()=>{_x.reset(),e.clear()}})}function oS(){return Ei({mutationFn:e=>Xx({...e,revokeOtherSessions:!0})})}function sS(){let e=ui();return Ei({mutationFn:e=>hx(lx.selectOrganization,[],{organizationId:e}),onSuccess:t=>{e.clear(),e.setQueryData(eS.session,t.session)}})}function cS(){return Ti({queryKey:eS.managementKeys,queryFn:()=>hx(lx.listManagementKeys,[])})}function lS(){let e=ui();return Ei({mutationFn:e=>hx(lx.createManagementKey,[],{name:e}),gcTime:0,onSuccess:()=>void e.invalidateQueries({queryKey:eS.managementKeys})})}function uS(){let e=ui();return Ei({mutationFn:e=>hx(lx.revokeManagementKey,[e]),onSuccess:()=>void e.invalidateQueries({queryKey:eS.managementKeys})})}function dS(){return Ti({queryKey:eS.providers,queryFn:()=>hx(lx.listProviders,[])})}function fS(){return Ti({queryKey:eS.providers,queryFn:()=>hx(lx.listProviders,[]),select:e=>e.providers})}function pS(e){e.invalidateQueries({queryKey:eS.providers}),e.invalidateQueries({queryKey:eS.providerGateways})}function mS(){let e=ui();return Ei({mutationFn:e=>hx(lx.createProvider,[],e),gcTime:0,onSuccess:(t,n)=>{vx(n.type,n.providerGatewayId!==void 0),pS(e)}})}function hS(){return Ei({mutationFn:e=>hx(lx.testProvider,[],e),gcTime:0})}function gS(){return Ei({mutationFn:e=>hx(lx.testProviderGateway,[],e),gcTime:0})}function _S(e=!0){return Ti({queryKey:eS.providerGateways,queryFn:()=>hx(lx.listProviderGateways,[]),enabled:e})}function vS(e){let t=ui();return Ei({mutationFn:e,gcTime:0,onSuccess:()=>pS(t)})}function yS(){return vS(e=>hx(lx.createProviderGateway,[],e))}function bS(){return vS(({id:e,name:t})=>hx(lx.updateProviderGateway,[e],{name:t}))}function xS(){return vS(({id:e,token:t})=>hx(lx.rotateProviderGateway,[e],{token:t}))}function SS(){return vS(e=>hx(lx.deleteProviderGateway,[e]))}function CS(){let e=ui();return Ei({mutationFn:({id:e,body:t})=>hx(lx.updateProvider,[e],t),gcTime:0,onSuccess:(t,n)=>{e.invalidateQueries({queryKey:eS.providers}),n.body.status!==void 0&&e.invalidateQueries({queryKey:[`apps`]})}})}function wS(){let e=ui();return Ei({mutationFn:e=>hx(lx.deleteProvider,[e]),onSuccess:()=>pS(e)})}function TS(e){return Ti({queryKey:eS.billingStatus,queryFn:()=>gx.get(`/v1/admin/billing/status`),enabled:e,staleTime:3e4,refetchInterval:e?5*6e4:!1,refetchOnWindowFocus:!0})}function ES(e){return Ti({queryKey:eS.billingPlans,queryFn:()=>gx.get(`/v1/admin/billing/plans`),enabled:e,staleTime:1/0})}function DS(){return Ei({mutationFn:e=>gx.post(`/v1/admin/billing/checkout`,{...e,successUrl:`${window.location.origin}${Ux(e.planKey)}`,cancelUrl:`${window.location.origin}/billing`})})}function OS(){let e=ui();return Ei({mutationFn:e=>gx.post(`/v1/admin/billing/change`,e),onSuccess:()=>void e.invalidateQueries({queryKey:eS.billingStatus})})}function kS(){let e=ui();return Ei({mutationFn:()=>gx.post(`/v1/admin/billing/cancel`),onSuccess:()=>void e.invalidateQueries({queryKey:eS.billingStatus})})}function AS(){let e=ui();return Ei({mutationFn:e=>gx.post(`/v1/admin/billing/resume`,e),onSuccess:()=>void e.invalidateQueries({queryKey:eS.billingStatus})})}function jS(e,t){return Ti({queryKey:eS.apps(e),queryFn:()=>hx(lx.listApps,[{month:e}]),...t===void 0?{}:{refetchInterval:t}})}function MS(e){return Ti({queryKey:eS.app(e),queryFn:async()=>Qx(await hx(lx.getApp,[e]))})}function NS(e){let t=ui();return Ei({mutationFn:async({body:t,revision:n})=>Qx(await hx(lx.updateApp,[e],{...$x(t),revision:n})),onSuccess:()=>{t.invalidateQueries({queryKey:eS.app(e)}),t.invalidateQueries({queryKey:[`apps`]})}})}function PS(){let e=ui();return Ei({mutationFn:async e=>{let t=await hx(lx.createApp,[],$x(e));return{...Qx(t),api_key:t.api_key}},onSuccess:(t,n)=>{yx(n.config.authentication.type),e.invalidateQueries({queryKey:eS.app(t.app.id)}),e.invalidateQueries({queryKey:[`apps`]})}})}function FS(){let e=ui();return Ei({mutationFn:e=>hx(lx.deleteApp,[e]),onSuccess:()=>e.invalidateQueries({queryKey:[`apps`]})})}function IS(e,t=!0){return Ti({enabled:t,queryKey:eS.apiKeys(e),queryFn:()=>hx(lx.listAppKeys,[e])})}function LS(e){let t=ui();return Ei({mutationFn:t=>hx(lx.createAppKey,[e],{name:t}),onSuccess:()=>void t.invalidateQueries({queryKey:eS.apiKeys(e)})})}function RS(e){let t=ui();return Ei({mutationFn:t=>hx(lx.revokeAppKey,[e,t]),onSuccess:()=>void t.invalidateQueries({queryKey:eS.apiKeys(e)})})}function zS(e,t){return Ti({queryKey:eS.users(e,t),queryFn:()=>hx(lx.listAppUsers,[e,t]),placeholderData:e=>e})}function BS(e){let t=ui();return Ei({mutationFn:({userId:t,blocked:n})=>hx(lx.setAppUserBlocked,[e,t,n]),onSuccess:()=>{t.invalidateQueries({queryKey:[`users`,e]}),t.invalidateQueries({queryKey:[`apps`]})}})}function VS(e,t){return Ti({queryKey:eS.usage(e,t),queryFn:()=>hx(lx.getAppUsage,[e,{month:t}])})}function HS(e,t,n){return Ti({queryKey:eS.timeseries(e,t,n),queryFn:()=>hx(lx.getAppUsageTimeseries,[e,{from:t,to:n}])})}function US(e,t,n,r){return Ti({queryKey:eS.breakdown(e,t,n,r),queryFn:()=>hx(lx.getAppUsageBreakdown,[e,{by:t,from:n,to:r}])})}function WS(e,t){return Ti({queryKey:eS.events(e,t),queryFn:()=>hx(lx.listAppEvents,[e,{...t}]),placeholderData:e=>e})}function GS(e,t){return Ti({queryKey:eS.authEventSummary(e,t),queryFn:()=>hx(lx.getAppAuthEventSummary,[e,{days:t}]),staleTime:3e4})}function KS(e,t){return Ti({queryKey:eS.authEvents(e,t),queryFn:()=>hx(lx.listAppAuthEvents,[e,{...t}]),placeholderData:e=>e})}function qS(){return Ti({queryKey:eS.prices,queryFn:()=>hx(lx.listModelPrices,[]),staleTime:1/0})}function JS(){let{organization:e,memberships:t}=ox(),n=sS();if(!rx(t.length))return null;let r=async t=>{if(t!==e?.id)try{await n.mutateAsync(t)}catch(e){U.error(e instanceof Error?e.message:`Could not switch organization`)}};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Wb,{}),(0,I.jsx)(Ub,{className:`text-xs font-normal text-muted-foreground`,children:`Organizations`}),t.map(t=>{let i=t.organization.id===e?.id;return(0,I.jsxs)(Bb,{disabled:n.isPending,onSelect:()=>void r(t.organization.id),children:[(0,I.jsx)(ra,{className:i?`size-4`:`size-4 opacity-0`}),(0,I.jsx)(`span`,{className:`flex-1 truncate`,children:t.organization.name}),(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ex[t.role]})]},t.organization.id)})]})}function YS({status:e}){return e===`active`?null:(0,I.jsxs)(Ib,{variant:`outline`,className:`gap-1.5 border-muted-foreground/30 text-muted-foreground`,children:[(0,I.jsx)(`span`,{className:`size-1.5 rounded-full bg-muted-foreground`}),`disabled`]})}var XS={ok:`border-emerald-500/40 text-emerald-600 dark:text-emerald-400`,provider_error:`border-destructive/40 text-destructive`,blocked_app_rate:`border-amber-500/40 text-amber-600 dark:text-amber-400`,blocked_app_budget:`border-amber-500/40 text-amber-600 dark:text-amber-400`,blocked_billing:`border-amber-500/40 text-amber-600 dark:text-amber-400`,blocked_user:`border-amber-500/40 text-amber-600 dark:text-amber-400`},ZS={ok:`Served by the provider`,provider_error:`The provider refused or failed the request`,blocked_app_rate:`Refused by this app's own rate limit, which you set`,blocked_app_budget:`Refused by this app's own monthly budget, which you set`,blocked_billing:`Refused: your plan's monthly request allowance was exhausted`,blocked_user:`Refused: this user is blocked`};function QS({status:e}){return(0,I.jsx)(Ib,{variant:`outline`,className:H(`font-mono text-[11px] font-normal`,XS[e]),title:ZS[e],children:e})}var $S={ok:`border-emerald-500/40 text-emerald-600 dark:text-emerald-400`,issuer_claims_missing:`border-amber-500/40 text-amber-600 dark:text-amber-400`,issuer_verification_unavailable:`border-amber-500/40 text-amber-600 dark:text-amber-400`};function eC({outcome:e}){return(0,I.jsx)(Ib,{variant:`outline`,className:H(`font-mono text-[11px] font-normal`,$S[e]??`border-destructive/40 text-destructive`),children:e})}function tC({status:e}){return(0,I.jsx)(Ib,{variant:`outline`,className:H(e===`blocked`?`border-destructive/40 text-destructive`:`border-border text-muted-foreground`),children:e})}var nC=[{value:`light`,label:`Light`,icon:Wa},{value:`dark`,label:`Dark`,icon:Oa},{value:`system`,label:`System`,icon:Da}];function rC(){let{theme:e,resolvedTheme:t,setTheme:n}=Ni(),[r,i]=(0,v.useState)(!1);return(0,v.useEffect)(()=>i(!0),[]),(0,I.jsxs)(Lb,{children:[(0,I.jsx)(Rb,{asChild:!0,children:(0,I.jsx)(Y,{variant:`ghost`,size:`icon`,"aria-label":`Theme`,className:`text-muted-foreground`,children:r?(0,I.jsx)(e===`system`?Da:t===`light`?Wa:Oa,{className:`size-4`}):(0,I.jsx)(`span`,{className:`size-4`})})}),(0,I.jsx)(zb,{align:`end`,className:`w-36`,children:(0,I.jsx)(Vb,{value:e??`system`,onValueChange:n,children:nC.map(e=>(0,I.jsxs)(Hb,{value:e.value,children:[(0,I.jsx)(e.icon,{className:`size-4`}),e.label]},e.value))})})]})}var iC=[{slug:`overview`,label:`Overview`,icon:Qi},{slug:`auth`,label:`Auth policy`,icon:Ba},{slug:`proxy`,label:`Proxy policy`,icon:Ja},{slug:`endpoints`,label:`Endpoints`,icon:Fa},{slug:`limits`,label:`Limits`,icon:ba},{slug:`users`,label:`Users`,icon:qa},{slug:`usage`,label:`Usage`,icon:na},{slug:`auth-events`,label:`Auth & Errors`,icon:za},{slug:`settings`,label:`Settings`,icon:Ra}];iC[0].slug;var aC=new Intl.NumberFormat(`en-US`,{notation:`compact`,maximumFractionDigits:1}),oC=new Intl.NumberFormat(`en-US`),sC=new Intl.NumberFormat(`en-US`,{style:`percent`,minimumFractionDigits:1,maximumFractionDigits:1}),cC=e=>e==null?`—`:oC.format(e),lC=e=>e==null?`—`:e<1e4?oC.format(e):aC.format(e),uC=e=>e==null?`—`:sC.format(e);function dC(e){return e==null?`—`:e===0?`$0.00`:e<.01?`$${e.toFixed(4)}`:fC(e)}function fC(e){return e==null?`—`:e<100?`$${e.toFixed(2)}`:`$${oC.format(Math.round(e))}`}function pC(e){if(!e)return null;let t=e.includes(`T`)?e:`${e.replace(` `,`T`)}Z`,n=new Date(t);return Number.isNaN(n.getTime())?null:n}function mC(e){let t=pC(e);return t?t.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):`—`}function hC(e){let t=pC(e);if(!t)return`never`;let n=Math.round((Date.now()-t.getTime())/1e3),r=[[`second`,60],[`minute`,60],[`hour`,24],[`day`,30],[`month`,12],[`year`,1/0]],i=n;for(let[e,t]of r){if(Math.abs(i)<t)return new Intl.RelativeTimeFormat(void 0,{numeric:`auto`}).format(-Math.round(i),e);i/=t}return t.toLocaleDateString()}var gC=e=>e.input_tokens+e.cached_input_tokens+e.cache_write_tokens,_C=e=>{let t=gC(e);return t===0?null:e.cached_input_tokens/t},vC=e=>gC(e)+e.output_tokens;function yC(){return new Date().toISOString().slice(0,10).slice(0,7)}function bC(){return new Date().toISOString().slice(0,10)}function xC(e){return new Date(Date.now()-e*864e5).toISOString().slice(0,10)}function SC(e){return new Date(`${e}-01T00:00:00Z`).toLocaleDateString(void 0,{month:`long`,year:`numeric`,timeZone:`UTC`})}function CC(e){let t=[],n=new Date;for(let r=0;r<e;r+=1)t.push(new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()-r,1)).toISOString().slice(0,7));return t}function wC(e){return e?.state===`billed`?e.plan:null}function TC(e){return e?.state===`billed`?e.subscription:null}function EC(e){let t=e?.limits,n=typeof t==`object`&&t&&!Array.isArray(t)?t.maxRequestsPerMonth:void 0,r=typeof n==`number`?n:typeof n==`string`&&n.trim().length>0?Number(n):NaN;return Number.isSafeInteger(r)&&r>=0?r:null}function DC(e){let t=EC(e);return t===null?`the ${e.planName} plan`:`the ${e.planName} plan (${cC(t)} requests/month)`}function OC(e){return!e||e.state===`self_hosted`?null:e.state===`unavailable`?{tone:`destructive`,title:`Billing service unavailable`,description:`Gateway traffic may be interrupted. This usually resolves on its own.`,actionable:!1}:e.plan===null?{tone:`destructive`,title:`No active plan`,description:`Gateway traffic is being refused. Choose a plan to start serving it again.`,actionable:!0}:e.subscription?.subscriptionId&&e.plan.isDefault?{tone:`warning`,title:`Your subscription has ended`,description:`You’re on ${DC(e.plan)}. Resubscribe to restore your previous allowance.`,actionable:!0}:e.subscription?.status===`past_due`?{tone:`warning`,title:`Payment past due`,description:`Update your payment method to keep this plan.`,actionable:!0}:null}function kC(e){return!!(e&&!e.claimed&&e.expiresAt)}function AC(e){return!e||!kC(e)?null:{tone:`warning`,title:`Unclaimed free access`,description:`Your free access does not renew until you claim your account. Claim your account for free to keep your apps and usage. Free access ends ${PC(new Date(new Date(e.createdAt).getTime()+30*864e5).toISOString())}.`,actionable:!1}}function jC(e,t){if(!e)return null;let n=PC(e.resetAt),r=kC(t),i=n?`${r?`Ends`:`Resets`} ${n}`:r?`Free access end unavailable`:`Reset time unavailable`;if(e.limit===void 0||e.limit===null)return{used:e.used,limit:null,ratio:null,tone:`normal`,label:`${cC(e.used)} requests this period`,caption:i};let a=e.limit>0?Math.min(e.used/e.limit,1):1;return{used:e.used,limit:e.limit,ratio:a,tone:a>=1?`destructive`:a>=.8?`warning`:`normal`,label:`${cC(e.used)} of ${cC(e.limit)} requests`,caption:i}}function MC(e,t){let n=jC(e,t);return!n||n.ratio===null||n.tone===`normal`?null:n.ratio>=1?{tone:`destructive`,title:kC(t)?`Free request allowance spent`:`Monthly request allowance spent`,description:kC(t)?`This free allowance does not renew until you claim your account. Claim it to move onto a renewing monthly allowance. ${n.caption}.`:`Gateway requests are being refused until the allowance resets. ${n.caption}.`,actionable:!0}:{tone:`warning`,title:kC(t)?`Free request allowance almost spent`:`Monthly request allowance almost spent`,description:`${n.label} used in the current period. ${n.caption}.`,actionable:!0}}function NC(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`})}function PC(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toLocaleString(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,timeZoneName:`short`})}function FC(e){return`${(e.priceAmountCents/100).toLocaleString(void 0,{style:`currency`,currency:e.priceCurrency||`USD`,minimumFractionDigits:e.priceAmountCents%100==0?0:2})}/${e.billingPeriod===`year`?`yr`:`mo`}`}function IC(e,t){return e.prices.find(e=>e.billingPeriod===t)}function LC(e){if(e.endsAt){let t=NC(e.endsAt);if(t)return{label:`Access ends`,value:t}}if(e.status===`on_trial`&&e.trialEndsAt){let t=NC(e.trialEndsAt);if(t)return{label:`Trial ends`,value:t}}if(e.renewsAt){let t=NC(e.renewsAt);if(t)return{label:`Renews`,value:t}}return null}var RC=new Set([`on_trial`,`active`,`paused`,`past_due`]);function zC(e){return!!(e&&e.subscriptionId&&e.source===`lemon_squeezy`&&RC.has(e.status))}function BC(e){return!!(e?.subscriptionId&&e.source===`lemon_squeezy`&&e.status===`cancelled`)}function VC(e){return IC(e,`month`)?.priceAmountCents??0}var HC=`This plan was granted manually. Ask support to change it.`;function UC(e,t,n){let r=wC(n);if(r&&e.planKey===r.planKey)return{intent:`current`,label:`Current plan`,variant:`outline`};let i=t.find(e=>e.planKey===r?.planKey),a=VC(e)>(i?VC(i):0),o=e.prices.length===0,s=a?`default`:`outline`,c=`${a?`Upgrade`:`Downgrade`} to ${e.name}`,l=TC(n);return l&&l.source===`manual`&&RC.has(l.status)?{intent:o?`cancel`:`change`,label:c,variant:s,reason:HC}:o?zC(l)?{intent:`cancel`,label:c,variant:s}:{intent:`cancel`,label:c,variant:s,reason:`There is no paid subscription to leave.`}:{intent:zC(l)?`change`:`checkout`,label:c,variant:s}}var WC=[{to:`/apps`,label:`Apps`,icon:Ca},{to:`/providers`,label:`Providers`,icon:Ma,sections:[{to:`/providers/gateways`,label:`Gateways`,icon:ta}]}];function GC({onNavigate:e}){let{capabilities:t,billing:n,quota:r,canManage:i,organization:a}=ox(),o=dt();if(!t.billing)return null;let s=wC(n),c=jC(r,a);if(!s&&!c)return null;let l=o.pathname===`/billing`,u=c!==null&&c.ratio!==null&&c.ratio>=.8,d=s===null||s.isDefault||u;return(0,I.jsxs)(`div`,{className:H(`rounded-lg px-3 py-2.5 transition-colors`,l?`bg-sidebar-accent text-sidebar-accent-foreground`:`bg-sidebar-accent/40`),children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,I.jsx)(`span`,{className:`truncate text-xs font-medium`,children:s?`${s.planName} plan`:`No plan`}),d?(0,I.jsx)(Pn,{to:`/billing`,onClick:e,"aria-current":l?`page`:void 0,className:H(`shrink-0 rounded-sm text-xs font-medium underline underline-offset-4 transition-colors`,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`,l?`text-sidebar-accent-foreground`:`text-primary-ink hover:text-foreground`),children:i?`Upgrade`:`View plan`}):null]}),c?(0,I.jsxs)(`div`,{className:`mt-1.5 space-y-1`,children:[(0,I.jsx)(`p`,{className:`tabular text-[11px] text-muted-foreground`,children:c.label}),(0,I.jsx)(Kb,{meter:c,className:`h-1`})]}):null]})}function KC(){return(0,I.jsxs)(Db,{children:[(0,I.jsx)(Ob,{asChild:!0,children:(0,I.jsxs)(Ib,{variant:`secondary`,className:`w-full justify-start gap-1.5 py-1`,children:[(0,I.jsx)(ya,{className:`size-3`}),`Read-only`]})}),(0,I.jsx)(kb,{side:`top`,children:nx})]})}function qC(e,t){let n=e?.trim()||t,r=n.split(/[\s@._-]+/).filter(Boolean);return(r.length>1?`${r[0][0]}${r[1][0]}`:n.slice(0,2)).toUpperCase()}function JC({onNavigate:e}){let t=ht(),{session:n,capabilities:r}=ox(),i=aS(),a=async()=>{await i.mutateAsync().catch(()=>void 0),await t(`/login`,{replace:!0})},o=n.user?.email??`Operator`,s=n.user?.name?.trim()||o;return(0,I.jsxs)(Lb,{children:[(0,I.jsxs)(Rb,{className:H(`flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-left transition-colors`,`hover:bg-sidebar-accent hover:text-sidebar-accent-foreground`,`data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground`,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`),children:[(0,I.jsx)(`span`,{"aria-hidden":!0,className:`grid size-8 shrink-0 place-items-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`,children:qC(n.user?.name,o)}),(0,I.jsxs)(`span`,{className:`min-w-0 flex-1 leading-tight`,children:[(0,I.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:s}),(0,I.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:o})]}),(0,I.jsx)(sa,{className:`size-4 shrink-0 text-muted-foreground`})]}),(0,I.jsxs)(zb,{side:`top`,align:`start`,sideOffset:8,className:`w-(--radix-dropdown-menu-trigger-width) min-w-56`,children:[(0,I.jsx)(Bb,{asChild:!0,children:(0,I.jsxs)(Pn,{to:`/settings`,onClick:e,children:[(0,I.jsx)(Ra,{className:`size-4`}),`Settings`]})}),(0,I.jsx)(Bb,{asChild:!0,children:(0,I.jsxs)(Pn,{to:`/keys`,onClick:e,children:[(0,I.jsx)(Sa,{className:`size-4`}),`Management keys`]})}),r.billing?(0,I.jsx)(Bb,{asChild:!0,children:(0,I.jsxs)(Pn,{to:`/billing`,onClick:e,children:[(0,I.jsx)(ga,{className:`size-4`}),`Billing`]})}):null,(0,I.jsx)(JS,{}),(0,I.jsx)(Wb,{}),(0,I.jsxs)(Bb,{disabled:i.isPending,onSelect:()=>void a(),children:[(0,I.jsx)(Ea,{className:`size-4`}),`Sign out`]})]})]})}function YC({to:e,label:t,icon:n,current:r,onNavigate:i,className:a}){return(0,I.jsxs)(Pn,{to:e,onClick:i,"aria-current":r?`page`:void 0,className:H(`flex h-10 items-center gap-2.5 rounded-lg px-3 text-sm font-medium transition-colors`,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`,r?`bg-sidebar-accent text-sidebar-accent-foreground`:`text-muted-foreground hover:bg-sidebar-accent/60 hover:text-sidebar-accent-foreground`,a),children:[n?(0,I.jsx)(n,{className:`size-4 shrink-0`}):null,(0,I.jsx)(`span`,{className:`truncate`,children:t})]})}function XC({onNavigate:e}){let t=dt();return(0,I.jsx)(`nav`,{className:`flex flex-1 flex-col gap-1 p-3`,children:WC.map(n=>{let r=t.pathname.startsWith(n.to),i=r?n.sections:void 0,a=r&&!i?.some(e=>e.to===t.pathname);return(0,I.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,I.jsx)(YC,{to:n.to,label:n.label,icon:n.icon,current:a,onNavigate:e}),i?(0,I.jsx)(`div`,{className:`flex flex-col gap-1`,children:i.map(n=>(0,I.jsx)(YC,{to:n.to,label:n.label,icon:n.icon,current:t.pathname===n.to,onNavigate:e,className:`h-9 pr-3 pl-9.5`},n.to))}):null]},n.to)})})}function ZC({back:e,title:t,badge:n,items:r,onNavigate:i}){let a=dt();return(0,I.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 border-b border-sidebar-border px-3 pb-3`,children:[(0,I.jsxs)(Pn,{to:e.to,onClick:i,className:H(`flex h-8 w-fit items-center gap-1.5 rounded-lg px-2 text-sm text-muted-foreground transition-colors`,`hover:bg-sidebar-accent/60 hover:text-sidebar-accent-foreground`,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`),children:[(0,I.jsx)(Xi,{className:`size-3.5 shrink-0`}),e.label]}),(0,I.jsxs)(`div`,{className:`min-w-0 space-y-1.5 px-2 pt-1 pb-1`,children:[(0,I.jsx)(`h1`,{className:`line-clamp-2 text-lg leading-snug font-semibold tracking-tight break-words`,children:t}),n]})]}),(0,I.jsx)(`nav`,{"aria-label":`${t} sections`,className:`flex flex-1 flex-col gap-1 overflow-y-auto p-3`,children:r.map(e=>(0,I.jsx)(YC,{to:e.to,label:e.label,icon:e.icon,current:a.pathname===e.to||a.pathname.startsWith(`${e.to}/`),onNavigate:i},e.to))})]})}function QC({appId:e,onNavigate:t}){let n=MS(e);return(0,I.jsx)(ZC,{back:{to:`/apps`,label:`Apps`},title:n.data?.app.name??e,badge:n.data?(0,I.jsx)(YS,{status:n.data.app.status}):void 0,items:iC.map(t=>({to:`/apps/${e}/${t.slug}`,label:t.label,icon:t.icon})),onNavigate:t})}function $C({onNavigate:e}){let{readOnly:t}=ox(),n=ft(`/apps/:appId/*`);return(0,I.jsxs)(`div`,{className:`flex h-full flex-col bg-sidebar text-sidebar-foreground`,children:[(0,I.jsxs)(`div`,{className:`flex h-14 items-center justify-between gap-2 px-3`,children:[(0,I.jsx)($b,{className:`px-1`,onClick:e}),(0,I.jsx)(rC,{})]}),n?.params.appId?(0,I.jsx)(QC,{appId:n.params.appId,onNavigate:e}):(0,I.jsx)(XC,{onNavigate:e}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1 border-t border-sidebar-border p-3`,children:[(0,I.jsx)(GC,{onNavigate:e}),t?(0,I.jsx)(`div`,{className:`px-1 pb-1.5`,children:(0,I.jsx)(KC,{})}):null,(0,I.jsx)(JC,{onNavigate:e})]})]})}function ew(){let{capabilities:e,billing:t,quota:n,organization:r}=ox(),i=dt(),a=e.billing?AC(r)??OC(t)??MC(n,r):null;return!a||i.pathname===`/billing`?null:(0,I.jsxs)(Ds,{variant:a.tone===`destructive`?`destructive`:`default`,className:`mb-4`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:a.title}),(0,I.jsxs)(ks,{className:`flex flex-wrap items-center gap-3`,children:[(0,I.jsx)(`span`,{children:a.description}),a.actionable?(0,I.jsx)(Y,{asChild:!0,size:`sm`,variant:`outline`,children:(0,I.jsx)(Pn,{to:`/billing`,children:`View plans`})}):null]})]})}function tw(){let[e,t]=(0,v.useState)(!1);return(0,v.useEffect)(()=>t(!1),[dt().pathname]),(0,I.jsxs)(`header`,{className:`sticky top-0 z-30 flex h-14 items-center gap-2 border-b bg-background/80 px-3 backdrop-blur lg:hidden`,children:[(0,I.jsxs)(jb,{open:e,onOpenChange:t,children:[(0,I.jsx)(Mb,{asChild:!0,children:(0,I.jsx)(Y,{variant:`ghost`,size:`icon`,"aria-label":`Open navigation`,children:(0,I.jsx)(Aa,{className:`size-4`})})}),(0,I.jsxs)(Nb,{side:`left`,className:`w-72 border-sidebar-border p-0`,showCloseButton:!1,children:[(0,I.jsx)(Pb,{className:`sr-only`,children:`Navigation`}),(0,I.jsx)($C,{onNavigate:()=>t(!1)})]})]}),(0,I.jsx)($b,{}),(0,I.jsx)(`div`,{className:`ml-auto`,children:(0,I.jsx)(rC,{})})]})}function nw({children:e}){return(0,I.jsxs)(`div`,{className:`min-h-dvh bg-sidebar`,children:[(0,I.jsx)(`aside`,{className:`fixed inset-y-0 left-0 z-20 hidden w-64 lg:block`,children:(0,I.jsx)($C,{})}),(0,I.jsxs)(`div`,{className:`flex min-h-dvh flex-col lg:pl-64`,children:[(0,I.jsx)(tw,{}),(0,I.jsx)(`main`,{className:`min-w-0 flex-1 bg-background lg:my-2 lg:mr-2 lg:rounded-xl lg:border lg:shadow-sm`,children:(0,I.jsxs)(`div`,{className:`mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8`,children:[(0,I.jsx)(ew,{}),e]})})]})]})}function rw({reason:e,reasonId:t,className:n,children:r}){return(0,I.jsxs)(Db,{children:[(0,I.jsx)(Ob,{asChild:!0,children:(0,I.jsxs)(`span`,{tabIndex:0,className:H(`inline-flex w-fit cursor-not-allowed`,n),children:[r,t?(0,I.jsx)(`span`,{id:t,className:`sr-only`,children:e}):null]})}),(0,I.jsx)(kb,{children:e})]})}function iw({reason:e,wrapperClassName:t,disabled:n,...r}){let{readOnly:i}=ox(),a=(0,v.useId)(),o=e??(i?`Your role is read-only. Ask an owner or admin to make this change.`:void 0);return o?(0,I.jsx)(rw,{reason:o,reasonId:a,className:t,children:(0,I.jsx)(Y,{...r,disabled:!0,"aria-disabled":`true`,"aria-describedby":a})}):(0,I.jsx)(Y,{disabled:n,...r})}function aw({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`skeleton`,className:H(`animate-pulse rounded-md bg-accent`,e),...t})}function ow({className:e,...t}){return(0,I.jsx)(G_,{"data-slot":`label`,className:H(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}function sw({label:e,hint:t,htmlFor:n,className:r,children:i}){return(0,I.jsxs)(`div`,{className:H(`space-y-2`,r),children:[(0,I.jsx)(ow,{htmlFor:n,className:`text-sm`,children:e}),i,t?(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:t}):null]})}function cw({title:e,description:t,action:n}){return(0,I.jsxs)(`div`,{className:H(`flex flex-wrap justify-between gap-x-8 gap-y-3`,t?`items-start`:`items-center`),children:[(0,I.jsxs)(`div`,{className:`min-w-0 flex-1 basis-80 space-y-1`,children:[(0,I.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:e}),t?(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t}):null]}),n?(0,I.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:n}):null]})}function lw({title:e,description:t,action:n}){return(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:e}),t?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t}):null]}),n]})}function uw({children:e}){return(0,I.jsx)(`div`,{className:`rounded-md border border-dashed px-4 py-6 text-center text-sm text-muted-foreground`,children:e})}var dw=`<svg fill="currentColor" fill-rule="evenodd" height="1em" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M13.827 3.52h3.603L24 20h-3.603l-6.57-16.48zm-7.258 0h3.767L16.906 20h-3.674l-1.343-3.461H5.017l-1.344 3.46H0L6.57 3.522zm4.132 9.959L8.453 7.687 6.205 13.48H10.7z"></path></svg>
|
|
52
52
|
`,fw=`<svg fill="currentColor" height="1em" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.546 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.676-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701"></path></svg>
|
|
53
53
|
`,pw=`<svg fill="#EB5424" height="1em" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M21.98 7.448L19.62 0H4.347L2.02 7.448c-1.352 4.312.03 9.206 3.815 12.015L12.007 24l6.157-4.552c3.755-2.81 5.182-7.688 3.815-12.015l-6.16 4.58 2.343 7.45-6.157-4.597-6.158 4.58 2.358-7.433-6.188-4.55 7.63-.045L12.008 0l2.356 7.404 7.615.044z"></path></svg>
|
|
54
54
|
`,mw=`<svg fill="currentColor" fill-rule="evenodd" height="1em" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M2.316 4.8h14.682v4.8H7.31a.302.302 0 00-.308.3v4.2c0 .171.14.3.308.3h9.688v4.8h-4.686a.302.302 0 00-.308.3v4.2c0 .171.141.3.308.3h4.378a.297.297 0 00.308-.3v-4.5h4.694a.302.302 0 00.308-.3v-4.2c0-.171-.14-.3-.308-.3h-4.694V9.6h4.694A.302.302 0 0022 9.3V5.1c0-.171-.14-.3-.308-.3h-4.694V.3c0-.171-.14-.3-.308-.3H2.316A.31.31 0 002 .3v4.2c0 .171.14.3.316.3z"></path></svg>
|
|
@@ -72,7 +72,7 @@ Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}
|
|
|
72
72
|
`,Mw=`<svg height="1em" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M23.197 4.503A6 6 0 0015 2.307a5.973 5.973 0 00-2.995 4.933l5.996.008v.515h-5.996c.039.937.298 1.87.8 2.74a6 6 0 1010.39-6z" fill="#EF2CC1"></path><path d="M.805 4.5A6 6 0 003 12.697a5.972 5.972 0 005.77.127L5.779 7.627l.446-.257 2.997 5.192A6 6 0 10.804 4.5z" fill="#CAAEF5"></path><path d="M12 23.894a6 6 0 005.999-6c0-2.13-1.1-3.996-2.775-5.06l-3.005 5.189-.444-.258 2.997-5.192A6 6 0 1012 23.894z" fill="#FC4C02"></path></svg>
|
|
73
73
|
`,Nw=`<svg fill="currentColor" fill-rule="evenodd" height="1em" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M12 0l12 20.785H0L12 0z"></path></svg>
|
|
74
74
|
`,Pw=`<svg fill="currentColor" fill-rule="evenodd" height="1em" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M6.469 8.776L16.512 23h-4.464L2.005 8.776H6.47zm-.004 7.9l2.233 3.164L6.467 23H2l4.465-6.324zM22 2.582V23h-3.659V7.764L22 2.582zM22 1l-9.952 14.095-2.233-3.163L17.533 1H22z"></path></svg>
|
|
75
|
-
`,Fw=[`openai`,`anthropic`,`xai`,`gemini`,`perplexity`,`deepseek`,`groq`,`mistral`,`together`,`fireworks`,`cerebras`,`moonshot`,`huggingface`,`baseten`,`bytedance`,`openrouter`],Iw=[`responses`,`chat_completions`,`anthropic_messages`,`gemini_native`,`audio_transcription`,`other`],Lw={responses:`v1/responses`,chat_completions:`v1/chat/completions`,anthropic_messages:`v1/messages`,gemini_native:`v1beta/models/{model}:generateContent`,audio_transcription:`v1/audio/transcriptions`},Rw=[`responses`,`transcription`],zw={responses:`responses`,transcription:`audio_transcription`},Bw=[`responses`,`chat_completions`,`gemini_native`,`anthropic`,`none`],Vw={apiStyles:Iw,endpointStyles:[]},Hw={openai:{apiStyles:Iw,endpointStyles:[`responses`,`transcription`]},xai:{apiStyles:Iw,endpointStyles:[`responses`,`transcription`]},openrouter:{apiStyles:[`chat_completions`],endpointStyles:[]}};function Uw(e){return Hw[e]??Vw}var Ww=Fw.filter(e=>Uw(e).endpointStyles.length>0);function Gw(e){return Ww.filter(t=>Uw(t).endpointStyles.includes(e))}var Kw={openai:{slug:`openai`,stripPathPrefix:`v1/`},anthropic:{slug:`anthropic`},xai:{slug:`grok`},gemini:{slug:`google-ai-studio`},perplexity:{slug:`perplexity-ai`}},qw=[`responses`,`chat_completions`,`anthropic_messages`],Jw=[`responses`];function Yw(e){return{modelPrefix:e,apiStyles:qw,endpointStyles:Jw}}var Xw={cf_aig:Kw,vercel:{openai:Yw(`openai/`),anthropic:Yw(`anthropic/`),gemini:Yw(`google/`),xai:Yw(`spacexai/`),perplexity:Yw(`perplexity/`),deepseek:Yw(`deepseek/`),moonshot:Yw(`moonshotai/`)}},Zw=[`openrouter`];function Qw(e){return Zw.includes(e)}var $w=Fw,eT={openai:`OpenAI`,anthropic:`Anthropic`,xai:`xAI`,gemini:`Gemini`,perplexity:`Perplexity`,deepseek:`DeepSeek`,groq:`Groq`,mistral:`Mistral`,together:`Together AI`,fireworks:`Fireworks AI`,cerebras:`Cerebras`,moonshot:`Moonshot AI`,huggingface:`Hugging Face`,baseten:`Baseten`,bytedance:`ByteDance Ark`,openrouter:`OpenRouter`},tT={cf_aig:`Cloudflare AI Gateway`,vercel:`Vercel AI Gateway`},nT=[{value:`cf_aig`,label:tT.cf_aig,defaultName:`Our CF gateway`,tokenDocsUrl:`https://developers.cloudflare.com/ai-gateway/configuration/authentication/`,needsCloudflareIds:!0,credentialNote:`Requests use the provider keys stored in your Cloudflare AI Gateway's own key store.`},{value:`vercel`,label:tT.vercel,defaultName:`Our Vercel gateway`,tokenDocsUrl:`https://vercel.com/docs/ai-gateway/authentication-and-byok/api-keys`,needsCloudflareIds:!1,credentialNote:`Your provider credential stored in Vercel is preferred. Vercel may fall back to system credentials.`}],rT=Bw,iT=`x-end-user-id`;function aT(e,t){let n=Object.keys(t?.[e.type]??{}),r=Object.keys(e.pricing??{});return[...n,...r.filter(e=>!n.includes(e))]}var oT=Gw;function sT(e,t,n){let r=oT(e);return t.filter(t=>r.includes(t.type)&&(n?.(t,e)??!0))}var cT=/^[a-z0-9-]{1,64}$/,lT=e=>e.end_user?.source===`issuer`?e.end_user.issuer:void 0;function uT(){return{provider:`firebase`,jwks_url:``,issuer:``,audience:``,user_id_claim:`sub`,required_claims:[],max_token_lifetime_seconds:86400}}function dT(e,t){if(e.type===`apple_app_attest`)return{...e,end_user:{source:`issuer`,issuer:t??lT(e)??uT()}};if(!t){let{end_user:t,...n}=e;return n}return{...e,end_user:{source:`issuer`,issuer:t}}}var fT=e=>typeof e==`string`?{path:e}:e;function pT(e){return!e.fixed_model&&(!e.clamp||e.clamp===void 0)?e.path:{path:e.path,...e.fixed_model?{fixed_model:e.fixed_model}:{},...e.clamp?{clamp:e.clamp}:{}}}function mT(){return{allowed_paths:[],allowed_models:[]}}function hT(e=`openai`){return{api_style:`responses`,provider:e,model:``}}function gT(e,t=`endpoint`){if(e[t]===void 0)return t;for(let n=2;n<1e3;n+=1){let r=`${t}-${n}`;if(e[r]===void 0)return r}return`${t}-${Date.now()}`}function _T(e,t,n){return Object.fromEntries(Object.entries(e).map(([e,r])=>[e===t?n:e,r]))}function vT(e,t,n){return cT.test(e)?e!==n&&t[e]!==void 0?`Another endpoint already uses this slug`:null:`Use 1-64 characters from a-z, 0-9, and -`}function yT(e){return e.providers.mode}function bT(e){if(yT(e)===`all`)return[];let t=e.providers.selected??{};return Object.keys(t).filter(e=>t[e]!==void 0)}function xT(e){return $w.includes(e)}function ST(e){return Object.hasOwn(tT,e)}function CT(e,t){if(yT(e)===`all`)return[...$w];let n=new Map(t.map(e=>[e.slug,e.type])),r=new Set(bT(e).flatMap(e=>{let t=n.get(e);return t?[t]:xT(e)?[e]:[]}));return $w.filter(e=>r.has(e))}var wT=`size-full text-current`;function TT(e){return e.trim().replace(`<svg`,`<svg class="${wT}"`)}function ET(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,TT(t)]))}var DT=ET({openai:Dw,anthropic:dw,xai:Pw,gemini:Sw,perplexity:kw,deepseek:yw,groq:Cw,mistral:Tw,together:Mw,fireworks:xw,cerebras:gw,moonshot:Ew,huggingface:ww,baseten:mw,bytedance:hw,openrouter:Ow}),OT=ET({cf_aig:_w,vercel:Nw}),kT=ET({firebase:bw,supabase:jw,auth0:pw,clerk:vw,apple:fw,revenuecat:Aw});function AT(e){return Object.hasOwn(kT,e)}function jT({svg:e,className:t}){return(0,I.jsx)(`span`,{"aria-hidden":!0,className:H(`inline-flex size-[1.15em] shrink-0`,t),dangerouslySetInnerHTML:{__html:e}})}function MT({type:e,className:t}){return(0,I.jsx)(jT,{svg:DT[e],className:t})}function NT({type:e,className:t}){return(0,I.jsx)(jT,{svg:OT[e],className:t})}function PT({type:e,className:t}){return(0,I.jsx)(jT,{svg:kT[e],className:t})}function FT({type:e,className:t}){return(0,I.jsxs)(`span`,{className:H(`inline-flex items-center gap-1.5`,t),children:[(0,I.jsx)(MT,{type:e}),eT[e]]})}function IT({type:e,className:t}){return(0,I.jsxs)(`span`,{className:H(`inline-flex items-center gap-1.5`,t),children:[(0,I.jsx)(NT,{type:e}),tT[e]]})}function LT(e,t){if(yT(e)===`all`)return[];let n=t.filter(e=>e.status===`active`),r=new Set(n.map(e=>e.type));return CT(e,n).filter(e=>!r.has(e))}function RT({proxy:e}){let t=dS();if(!t.data)return null;let n=LT(e,t.data.providers);return n.length===0?null:(0,I.jsxs)(Ds,{children:[(0,I.jsx)(ca,{}),(0,I.jsxs)(Os,{children:[`No credential for`,` `,n.map((e,t)=>(0,I.jsxs)(v.Fragment,{children:[t>0?`, `:null,(0,I.jsx)(FT,{type:e,className:`align-middle`})]},e))]}),(0,I.jsxs)(ks,{children:[`This app allows`,` `,n.length===1?`a provider`:`providers`,` you have not configured, so those requests fail with `,(0,I.jsx)(`code`,{className:`font-mono text-xs`,children:`provider_not_configured`}),`.`,` `,(0,I.jsx)(Pn,{to:`/providers`,className:`text-primary-ink underline underline-offset-4`,children:`Add a provider key`}),`.`]})]})}function zT({...e}){return(0,I.jsx)(mv,{"data-slot":`select`,...e})}function BT({...e}){return(0,I.jsx)(vv,{"data-slot":`select-value`,...e})}function VT({className:e,size:t=`default`,children:n,...r}){return(0,I.jsxs)(gv,{"data-slot":`select-trigger`,"data-size":t,className:H(`flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground`,e),...r,children:[n,(0,I.jsx)(yv,{asChild:!0,children:(0,I.jsx)(ia,{className:`size-4 opacity-50`})})]})}function HT({className:e,children:t,position:n=`item-aligned`,align:r=`center`,...i}){return(0,I.jsx)(Sv,{children:(0,I.jsxs)(wv,{"data-slot":`select-content`,className:H(`relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,align:r,...i,children:[(0,I.jsx)(GT,{}),(0,I.jsx)(Iv,{className:H(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1`),children:t}),(0,I.jsx)(KT,{})]})})}function UT({className:e,children:t,...n}){return(0,I.jsxs)(Hv,{"data-slot":`select-item`,className:H(`relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2`,e),...n,children:[(0,I.jsx)(`span`,{"data-slot":`select-item-indicator`,className:`absolute right-2 flex size-3.5 items-center justify-center`,children:(0,I.jsx)(Kv,{children:(0,I.jsx)(ra,{className:`size-4`})})}),(0,I.jsx)(Wv,{children:t})]})}function WT({className:e,...t}){return(0,I.jsx)(Qv,{"data-slot":`select-separator`,className:H(`pointer-events-none -mx-1 my-1 h-px bg-border`,e),...t})}function GT({className:e,...t}){return(0,I.jsx)(Jv,{"data-slot":`select-scroll-up-button`,className:H(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(oa,{className:`size-4`})})}function KT({className:e,...t}){return(0,I.jsx)(Xv,{"data-slot":`select-scroll-down-button`,className:H(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(ia,{className:`size-4`})})}function qT({value:e,onChange:t,months:n=12}){let r=CC(n);return(0,I.jsxs)(zT,{value:e,onValueChange:t,children:[(0,I.jsx)(VT,{className:`w-[180px]`,size:`sm`,"aria-label":`Month`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:r.map(e=>(0,I.jsx)(UT,{value:e,children:SC(e)},e))})]})}var JT=[{value:`7`,label:`Last 7 days`},{value:`30`,label:`Last 30 days`},{value:`90`,label:`Last 90 days`}];function YT({value:e,onChange:t}){return(0,I.jsxs)(zT,{value:e,onValueChange:t,children:[(0,I.jsx)(VT,{className:`w-[150px]`,size:`sm`,"aria-label":`Date range`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:JT.map(e=>(0,I.jsx)(UT,{value:e.value,children:e.label},e.value))})]})}function XT(e){return{name:e.name,config:e.config,status:e.status}}var ZT=e=>e;function QT(e){let t=MS(e),n=NS(e),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),d=(0,v.useRef)(null),f=t.data?.app;(0,v.useEffect)(()=>{if(!f||l===e&&r!==null&&a!==null&&JSON.stringify(r)!==a)return;let t=XT(f);d.current=lT(t.config.authentication)??null,i(t),o(JSON.stringify(t)),c(f.revision),u(e)},[e,f]);let p=l===e?r:null,m=l===e?a:null,h=p!==null&&m!==null&&JSON.stringify(p)!==m,g=(0,v.useCallback)(e=>{i(t=>t&&{...t,...e})},[]),_=(0,v.useCallback)(e=>{i(t=>t&&{...t,config:{...t.config,...e}})},[]);return{query:t,draft:p,dirty:h,update:g,updateConfig:_,updateAuthentication:(0,v.useCallback)(e=>{_({authentication:e})},[_]),updateIssuer:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let n=t.config.authentication,r=lT(n)??(n.type===`apple_app_attest`?uT():void 0);return r?{...t,config:{...t.config,authentication:dT(n,{...r,...e})}}:t})},[]),setEndUserSource:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let n=t.config.authentication,r=lT(n);r&&(d.current=r);let i=e===`issuer`?dT(n,r??d.current??uT()):e===`app_install`?n.type===`apple_app_attest`?{...n,end_user:{source:`app_install`}}:n:e===`header`?n.type===`api_key`?{...n,end_user:{source:`header`,header:n.end_user?.source===`header`?n.end_user.header:iT}}:n:dT(n,void 0),a=i.type!==`api_key`||i.end_user!==void 0||t.config.limits===void 0?t.config:{...t.config,limits:{...t.config.limits,per_user:{requests:{per_minute:null,per_day:null},spending:{monthly_usd:null}}}};return{...t,config:{...a,authentication:i}}})},[]),updateEndUserHeader:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let n=t.config.authentication;return n.type!==`api_key`||n.end_user?.source!==`header`?t:{...t,config:{...t.config,authentication:{...n,end_user:{source:`header`,header:e}}}}})},[]),updateProxy:(0,v.useCallback)(e=>{i(t=>t&&{...t,config:{...t.config,routing:{...t.config.routing,...e}}})},[]),updateLimits:(0,v.useCallback)(e=>_({limits:e}),[_]),updateEndpoints:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let{endpoints:n,...r}=t.config;return{...t,config:Object.keys(e).length===0?r:{...r,endpoints:e}}})},[]),reset:(0,v.useCallback)(()=>{if(!m)return;let e=JSON.parse(m);d.current=lT(e.config.authentication)??null,i(e)},[m]),save:(0,v.useCallback)(async()=>{if(!p||s===null)return!1;try{let e=await n.mutateAsync({body:ZT(p),revision:s});return c(e.app.revision),o(JSON.stringify(p)),U.success(`Configuration saved`,{description:`The gateway picks it up within the 60 second config cache TTL.`}),!0}catch(e){return U.error(`Save rejected`,{description:e instanceof Error?e.message:`Unknown error`}),!1}},[p,s,n]),saving:n.isPending}}function $T(e){let t=e=>Array.isArray(e)?e.length>0&&e.every(Boolean):!!e;return(e.jwks_url??``).startsWith(`https://`)&&t(e.issuer)&&t(e.audience)}function eE(e){return e.path.trim()?e.equals===void 0?Array.isArray(e.contains)?e.contains.length>0&&e.contains.every(e=>e.trim().length>0):!!e.contains?.trim():String(e.equals).length>0:!1}function tE(e){let t=e.config.authentication;if(!e.name.trim())return`Give the app a name.`;if(t.type===`apple_app_attest`){let{team_id:e,bundle_id:n}=t.app_attest;if(!e.trim()||!n.trim())return`Enter the Apple Team ID and Bundle ID.`}if(t.type===`api_key`&&t.end_user?.source===`header`&&!t.end_user.header.trim())return`Enter the header name.`;let n=lT(t);if(n){if(!$T(n))return`Finish the identity provider details.`;if(!(n.required_claims??[]).every(eE))return`Finish the subscription check.`}return null}function nE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card`,className:H(`flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm`,e),...t})}function rE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-header`,className:H(`@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6`,e),...t})}function iE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-title`,className:H(`leading-none font-semibold`,e),...t})}function aE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-description`,className:H(`text-sm text-muted-foreground`,e),...t})}function oE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-content`,className:H(`px-6`,e),...t})}function sE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,I.jsx)(`table`,{"data-slot":`table`,className:H(`w-full caption-bottom text-sm [--table-inset:1.5rem]`,`[&_tr>*:first-child]:pl-(--table-inset) [&_tr>*:last-child]:pr-(--table-inset)`,e),...t})})}function cE({className:e,...t}){return(0,I.jsx)(`thead`,{"data-slot":`table-header`,className:H(`[&_tr]:border-b`,e),...t})}function lE({className:e,...t}){return(0,I.jsx)(`tbody`,{"data-slot":`table-body`,className:H(`[&_tr:last-child]:border-0`,e),...t})}function uE({className:e,...t}){return(0,I.jsx)(`tr`,{"data-slot":`table-row`,className:H(`border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted`,e),...t})}function Z({className:e,...t}){return(0,I.jsx)(`th`,{"data-slot":`table-head`,className:H(`h-11 px-3 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function Q({className:e,...t}){return(0,I.jsx)(`td`,{"data-slot":`table-cell`,className:H(`px-3 py-2.5 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function dE({label:e,value:t,detail:n}){return(0,I.jsx)(nE,{className:`gap-0 py-4`,children:(0,I.jsxs)(oE,{className:`px-4`,children:[(0,I.jsx)(`p`,{className:`text-xs font-medium tracking-wide text-muted-foreground uppercase`,children:e}),(0,I.jsx)(`p`,{className:`tabular mt-1.5 text-2xl leading-none font-semibold`,children:t}),n?(0,I.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:n}):null]})})}function fE(e){return e==null?`—`:e<1e3?`${Math.round(e)} ms`:e<6e4?`${(e/1e3).toFixed(1)} s`:e<36e5?`${Math.round(e/6e4)} min`:`${(e/36e5).toFixed(1)} h`}function pE(e){let t=new Map,n=(e,n,r,i,a)=>{let o=t.get(e)??{outcome:n,reason:r,days:new Map};o.days.set(i,(o.days.get(i)??0)+a),t.set(e,o)};for(let t of e?.daily??[])t.outcome!==`ok`&&n(`auth:${t.outcome}:${t.reason??``}`,t.outcome,t.reason,t.date,t.count);for(let t of e?.usage_failures??[])n(`proxy:${t.status}`,t.status,`proxied request`,t.date,t.count);return[...t.values()].map(e=>({outcome:e.outcome,reason:e.reason,total:[...e.days.values()].reduce((e,t)=>e+t,0),days:[...e.days.entries()].map(([e,t])=>({date:e,count:t})).sort((e,t)=>e.date<t.date?-1:+(e.date>t.date))})).sort((e,t)=>t.total-e.total||(e.outcome<t.outcome?-1:+(e.outcome>t.outcome)))}var mE=[`issuer_claims_missing`,`issuer_token_rejected`,`issuer_verification_unavailable`,`attest_failed`,`auth_required`,`ok`];function hE({appId:e}){let[t,n]=(0,v.useState)(`30`),[r,i]=(0,v.useState)(`all`),[a,o]=(0,v.useState)([]),s=GS(e,Number(t)),c=KS(e,{limit:25,outcome:r===`all`?void 0:r,before_id:a.at(-1)}),l=(0,v.useMemo)(()=>pE(s.data),[s.data]),u=s.data?.claim_delay,d=s.data?.pending_users??0;return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,I.jsx)(dE,{label:`Exchange success`,value:uC(s.data?.token_exchange.success_rate),detail:`${cC(s.data?.token_exchange.total??0)} attempts`}),(0,I.jsx)(dE,{label:`Claim delay p50`,value:fE(u?.p50_ms),detail:`${cC(u?.count??0)} measured`}),(0,I.jsx)(dE,{label:`Claim delay p95`,value:fE(u?.p95_ms),detail:`avg ${fE(u?.avg_ms)}`}),(0,I.jsx)(dE,{label:`Pending activations`,value:cC(d),detail:d>0?`waiting on a claim now`:`none waiting`})]}),(0,I.jsxs)(nE,{className:`py-0`,children:[(0,I.jsx)(rE,{className:`pt-6`,children:(0,I.jsx)(lw,{title:`Failures by cause`,description:`Refused authentication attempts and non-ok proxied requests, busiest first.`,action:(0,I.jsx)(YT,{value:t,onChange:n})})}),(0,I.jsx)(oE,{className:`px-0 pb-0`,children:s.isPending?(0,I.jsx)(`div`,{className:`px-6 pb-6`,children:(0,I.jsx)(aw,{className:`h-24 w-full`})}):l.length===0?(0,I.jsx)(`div`,{className:`px-6 pb-6`,children:(0,I.jsx)(uw,{children:`No failed requests in this range.`})}):(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`Outcome`}),(0,I.jsx)(Z,{children:`Reason`}),(0,I.jsx)(Z,{className:`text-right`,children:`Count`}),(0,I.jsx)(Z,{className:`text-right`,children:`Days affected`}),(0,I.jsx)(Z,{children:`Last seen`})]})}),(0,I.jsx)(lE,{children:l.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{children:(0,I.jsx)(eC,{outcome:e.outcome})}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.reason??`—`}),(0,I.jsx)(Q,{className:`tabular text-right`,children:cC(e.total)}),(0,I.jsx)(Q,{className:`tabular text-right`,children:cC(e.days.length)}),(0,I.jsx)(Q,{className:`text-xs whitespace-nowrap text-muted-foreground`,children:e.days.at(-1)?.date??`—`})]},`${e.outcome}-${e.reason??``}`))})]})})]}),(0,I.jsxs)(nE,{className:`py-0`,children:[(0,I.jsx)(rE,{className:`pt-6`,children:(0,I.jsx)(lw,{title:`Recent attempts`,description:`Every token exchange and key registration, newest first.`,action:(0,I.jsxs)(zT,{value:r,onValueChange:e=>{i(e),o([])},children:[(0,I.jsx)(VT,{className:`w-[210px]`,size:`sm`,"aria-label":`Outcome`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`all`,children:`All outcomes`}),mE.map(e=>(0,I.jsx)(UT,{value:e,children:e},e))]})]})})}),(0,I.jsxs)(oE,{className:`px-0 pb-0`,children:[(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`When`}),(0,I.jsx)(Z,{children:`User`}),(0,I.jsx)(Z,{children:`Call`}),(0,I.jsx)(Z,{children:`Outcome`}),(0,I.jsx)(Z,{children:`Reason`}),(0,I.jsx)(Z,{children:`App version`}),(0,I.jsx)(Z,{className:`text-right`,children:`Latency`}),(0,I.jsx)(Z,{className:`text-right`,children:`Claim delay`})]})}),(0,I.jsx)(lE,{children:c.isPending?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:8,children:(0,I.jsx)(aw,{className:`h-8 w-full`})})}):c.data?.events.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:8,className:`py-8 text-center text-sm text-muted-foreground`,children:`No attempts.`})}):c.data?.events.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{className:`text-xs whitespace-nowrap text-muted-foreground`,children:mC(e.created_at)}),(0,I.jsx)(Q,{className:`font-mono text-xs`,children:e.user_id??(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:`unknown`})}),(0,I.jsxs)(Q,{className:`font-mono text-xs text-muted-foreground`,children:[e.event,e.auth_method?(0,I.jsx)(`span`,{className:`block`,children:e.auth_method}):null]}),(0,I.jsx)(Q,{children:(0,I.jsx)(eC,{outcome:e.outcome})}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.reason??`—`}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.app_version??`—`}),(0,I.jsx)(Q,{className:`tabular text-right text-xs`,children:e.latency_ms===null?`—`:`${cC(e.latency_ms)} ms`}),(0,I.jsx)(Q,{className:`tabular text-right text-xs`,children:e.claim_delay_ms===null?`—`:(0,I.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,title:`This exchange ended a wait for an entitlement claim to propagate.`,children:fE(e.claim_delay_ms)})})]},e.id))})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t px-6 py-3`,children:[(0,I.jsx)(Y,{variant:`outline`,size:`sm`,disabled:a.length===0,onClick:()=>o(e=>e.slice(0,-1)),children:`Newer`}),(0,I.jsx)(Y,{variant:`outline`,size:`sm`,disabled:!c.data?.next_before_id,onClick:()=>o(e=>[...e,c.data.next_before_id]),children:`Older`})]})]})]})]})}function $({className:e,type:t,...n}){return(0,I.jsx)(`input`,{type:t,"data-slot":`input`,className:H(`h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30`,`focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,`aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40`,e),...n})}function gE({className:e,...t}){return(0,I.jsx)(jf,{"data-slot":`checkbox`,className:H(`peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary`,e),...t,children:(0,I.jsx)(Nf,{"data-slot":`checkbox-indicator`,className:`grid place-content-center text-current transition-none`,children:(0,I.jsx)(ra,{className:`size-3.5`})})})}var _E=[{value:`production`,label:`Production`,hint:`Builds signed for TestFlight and the App Store.`},{value:`development`,label:`Development`,hint:`Builds run from Xcode, which attest in Apple's development environment.`}];function vE({value:e,onChange:t,compact:n=!1,disabled:r=!1}){let i=e??[`production`],a=i.includes(`development`),o=(e,n)=>{let r=_E.map(e=>e.value).filter(t=>t===e?n:i.includes(t));r.length!==0&&t(r)};return(0,I.jsx)(sw,{label:`iOS app environment`,hint:n?void 0:`Which of Apple's two environments this app accepts attestations from. Removing one also stops the keys it already registered.`,children:(0,I.jsxs)(`div`,{className:`space-y-2`,children:[_E.map(e=>{let t=i.includes(e.value);return(0,I.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,I.jsx)(gE,{id:`env-${e.value}`,checked:t,disabled:r||t&&i.length===1,onCheckedChange:t=>o(e.value,t===!0)}),(0,I.jsxs)(`div`,{className:`-mt-0.5`,children:[(0,I.jsx)(ow,{htmlFor:`env-${e.value}`,className:`text-sm font-normal`,children:e.label}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]})]},e.value)}),a&&!n?(0,I.jsxs)(`p`,{className:`flex items-start gap-2 rounded-md bg-amber-500/[0.08] p-2.5 text-xs leading-relaxed text-amber-700 dark:text-amber-400`,children:[(0,I.jsx)(Ka,{className:`mt-0.5 size-3.5 shrink-0`}),(0,I.jsx)(`span`,{children:`Any device carrying your team's provisioning profile can attest against this app. Keep this on a development bundle id rather than the one you ship.`})]}):null]})})}function yE({label:e,choices:t,value:n,disabled:r=!1,describedBy:i,onChange:a}){return(0,I.jsx)(`div`,{role:`radiogroup`,"aria-label":e,"aria-describedby":i,className:`space-y-1`,children:t.map(e=>{let t=e.value===n;return(0,I.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":t,disabled:r,onClick:()=>a(e.value),className:H(`flex w-full items-start gap-3.5 rounded-lg px-3 py-3 text-left transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,r?`cursor-not-allowed opacity-60`:`hover:bg-muted/50`),children:[(0,I.jsx)(`span`,{"aria-hidden":`true`,className:H(`mt-0.5 flex size-4.5 shrink-0 items-center justify-center rounded-full border transition-colors`,t?`border-primary`:`border-muted-foreground/50`),children:t?(0,I.jsx)(`span`,{className:`size-2.5 rounded-full bg-primary`}):null}),(0,I.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`span`,{className:`block text-sm font-medium`,children:e.label}),(0,I.jsx)(`span`,{className:`mt-0.5 block text-sm text-muted-foreground`,children:e.description})]})]},e.value)})})}function bE({href:e,children:t}){return(0,I.jsxs)(`a`,{href:e,target:`_blank`,rel:`noreferrer noopener`,className:`inline-flex items-center gap-0.5 underline decoration-border underline-offset-4 transition-colors hover:text-foreground hover:decoration-foreground`,children:[t,(0,I.jsx)(va,{className:`size-3`})]})}function xE({label:e,presets:t,selected:n,values:r,onSelect:i,onValueChange:a,idPrefix:o,compact:s=!1,disabled:c=!1}){let l=!s&&`warning`in n?n.warning:void 0,u=!s&&`note`in n?n.note:void 0,d=`docs`in n?n.docs:void 0,f=n.vendor??n.label;return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`${o}-preset`,children:e}),(0,I.jsxs)(zT,{value:n.id,disabled:c,onValueChange:e=>{let n=t.find(t=>t.id===e);n&&i(n)},children:[(0,I.jsx)(VT,{id:`${o}-preset`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:t.map(e=>(0,I.jsx)(UT,{value:e.id,children:(0,I.jsx)(SE,{preset:e})},e.id))})]}),n.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n.description}):null]}),n.inputs.map(e=>(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`${o}-${e.key}`,children:e.label}),(0,I.jsx)($,{id:`${o}-${e.key}`,value:r[e.key]??``,placeholder:e.placeholder,className:`font-mono text-xs`,disabled:c,onChange:t=>a(e.key,t.target.value)}),e.hint||e.docs?(0,I.jsxs)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:[e.hint,e.docs?(0,I.jsxs)(I.Fragment,{children:[e.hint?` `:null,(0,I.jsx)(bE,{href:e.docs.href,children:e.docs.label})]}):null]}):null]},e.key)),l?(0,I.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-amber-500/40 bg-amber-500/10 p-3 text-xs leading-relaxed text-amber-700 dark:text-amber-400`,children:[(0,I.jsx)(Ka,{className:`mt-0.5 size-3.5 shrink-0`}),(0,I.jsx)(`span`,{children:l})]}):null,u?(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:u}):null,d?(0,I.jsxs)(`a`,{href:d,target:`_blank`,rel:`noreferrer noopener`,className:`inline-flex items-center gap-1 text-xs text-muted-foreground underline underline-offset-4 hover:text-foreground`,children:[f,` documentation`,(0,I.jsx)(va,{className:`size-3`})]}):null]})}function SE({preset:e,className:t}){return(0,I.jsxs)(`span`,{className:H(`inline-flex items-center gap-1.5`,t),children:[AT(e.id)?(0,I.jsx)(PT,{type:e.id}):null,e.id===`custom`?(0,I.jsx)(ea,{"aria-hidden":!0,className:`size-[1.15em] shrink-0 text-current`,strokeWidth:1.8}):null,e.label]})}var CE=e=>e.replace(/^https?:\/\//u,``).replace(/\/+$/u,``);function wE(e,t){return Object.fromEntries(e.inputs.map(e=>[e.key,(t[e.key]??``).trim()]))}var TE=(e,t)=>e.build(wE(e,t)),EE=(e,t)=>e.build(wE(e,t)),DE=[{id:`firebase`,label:`Firebase Authentication`,vendor:`Firebase`,description:`Google-signed ID tokens. Scoped to your project by the aud and iss claims.`,inputs:[{key:`project_id`,label:`Firebase project id`,placeholder:`my-app-1a2b3`,hint:`Found in Project settings. Not the project number.`}],warning:`Firebase signs every project's tokens with one shared key set, so the JWKS URL alone identifies nobody. The issuer and audience below are what scope this app to your project — without them the gateway would accept a token from any Firebase project in the world.`,docs:`https://firebase.google.com/docs/auth/admin/verify-id-tokens`,build:({project_id:e})=>({jwks_url:`https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com`,issuer:`https://securetoken.google.com/${e}`,audience:e,user_id_claim:`sub`,required_claims:[]}),read:({audience:e})=>({project_id:e})},{id:`supabase`,label:`Supabase Auth`,vendor:`Supabase`,description:`Per-project JWKS. Requires asymmetric signing keys.`,inputs:[{key:`project_ref`,label:`Project ref`,placeholder:`abcdefghijklmnop`,hint:`The subdomain of your project URL: https://<ref>.supabase.co`}],warning:`Only projects migrated to asymmetric JWT signing keys can be verified. A legacy HS256 project publishes no public keys, so its JWKS endpoint returns an empty set and every token is rejected.`,docs:`https://supabase.com/docs/guides/auth/signing-keys`,build:({project_ref:e})=>{let t=CE(e).replace(/\.supabase\.co$/u,``);return{jwks_url:`https://${t}.supabase.co/auth/v1/.well-known/jwks.json`,issuer:`https://${t}.supabase.co/auth/v1`,audience:`authenticated`,user_id_claim:`sub`,required_claims:[]}},read:({issuer:e})=>({project_ref:CE(e).replace(/\.supabase\.co\/auth\/v1$/u,``)})},{id:`auth0`,label:`Auth0`,vendor:`Auth0`,description:`Per-tenant JWKS, with the API identifier as the audience.`,inputs:[{key:`domain`,label:`Tenant domain`,placeholder:`my-tenant.us.auth0.com`,hint:`Your Auth0 domain or custom domain, without https://`},{key:`audience`,label:`API identifier`,placeholder:`https://api.my-app.com`,hint:`The Identifier of the API you registered in Auth0. It is not a URL that has to resolve.`}],warning:`Auth0 puts a trailing slash in the iss claim. The preset writes it for you; do not remove it or every token is rejected.`,docs:`https://auth0.com/docs/secure/tokens/access-tokens/validate-access-tokens`,build:({domain:e,audience:t})=>{let n=CE(e);return{jwks_url:`https://${n}/.well-known/jwks.json`,issuer:`https://${n}/`,audience:t,user_id_claim:`sub`,required_claims:[]}},read:({issuer:e,audience:t})=>({domain:CE(e),audience:t})},{id:`clerk`,label:`Clerk`,vendor:`Clerk`,description:`Session tokens verified against your Frontend API JWKS.`,inputs:[{key:`frontend_api`,label:`Frontend API host`,placeholder:`clean-mayfly-62.clerk.accounts.dev`,hint:`Your Clerk Frontend API URL or custom domain, without https://`},{key:`audience`,label:`Audience`,placeholder:`my-app`,hint:`The aud your Clerk JWT template sets. Clerk's default session token has none — add one in the template, because the gateway requires it.`}],warning:`Clerk's own guidance also checks the azp claim against your permitted origins. This gateway serves native apps, where there is no origin to bind to, so the preset omits it — add an azp requirement manually if your tokens carry one.`,docs:`https://clerk.com/docs/guides/sessions/manual-jwt-verification`,build:({frontend_api:e,audience:t})=>{let n=CE(e);return{jwks_url:`https://${n}/.well-known/jwks.json`,issuer:`https://${n}`,audience:t,user_id_claim:`sub`,required_claims:[]}},read:({issuer:e,audience:t})=>({frontend_api:CE(e),audience:t})},{id:`custom`,label:`Custom issuer`,description:`Any issuer publishing a JWKS document over HTTPS.`,inputs:[{key:`jwks_url`,label:`JWKS URL`,placeholder:`https://issuer.example.com/.well-known/jwks.json`,hint:`If this issuer signs tokens for more than one service, add a claim requirement under Subscription check too.`},{key:`issuer`,label:`Issuer (iss)`,placeholder:`https://issuer.example.com`,hint:`Exactly the iss claim your tokens carry, trailing slash included.`},{key:`audience`,label:`Audience (aud)`,placeholder:`https://api.my-app.com`,hint:`Exactly one aud value your tokens carry.`}],build:({jwks_url:e,issuer:t,audience:n})=>({jwks_url:e,issuer:t,audience:n,user_id_claim:`sub`,required_claims:[]}),read:e=>({...e})}],OE=DE.find(e=>e.id===`custom`),kE=e=>DE.find(t=>t.id===e)??OE;function AE(e){let t=e=>Array.isArray(e)?e[0]??``:e??``;return{jwks_url:e.jwks_url??``,issuer:t(e.issuer),audience:t(e.audience)}}function jE(e){let t=AE(e);if(e.provider){let n=kE(e.provider);return{preset:n,values:n.read(t)}}let n={preset:OE,values:{...t}},r=e=>Array.isArray(e)&&e.length>1;if(r(e.issuer)||r(e.audience))return n;for(let e of DE){if(e===OE)continue;let n=e.read(t);if(!LE(e,n))continue;let r=TE(e,n);if(r.jwks_url===t.jwks_url&&r.issuer===t.issuer&&r.audience===t.audience)return{preset:e,values:n}}return n}var ME=`revenueCatEntitlements`;function NE(e){let t=e.split(`,`).map(e=>e.trim());return{path:ME,contains:t.length>1?t:e}}function PE(e){if(e.length===0)return``;let[t,...n]=e;return!t||n.length>0||t.contains===void 0?null:Array.isArray(t.contains)?t.contains.join(`, `):t.contains}var FE=`Which claim says the user has paid`,IE=[{id:`none`,label:`No entitlement check`,description:`Any user the issuer signs a token for may call the gateway.`,inputs:[],build:()=>[]},{id:`revenuecat`,label:`RevenueCat entitlement`,vendor:`RevenueCat`,inputs:[{key:`entitlement`,label:`Entitlement identifier`,placeholder:`pro`,hint:`In RevenueCat, under Product catalog → Entitlements: the identifier, not the display name. Several, comma separated, admit a user carrying any one of them.`,docs:{href:`https://www.revenuecat.com/docs/getting-started/entitlements`,label:`RevenueCat documentation`}}],build:({entitlement:e})=>e?[NE(e)]:[]},{id:`custom`,label:`Custom claim`,description:`Any single claim requirement. More can be added under Subscription check.`,inputs:[{key:`path`,label:`Claim path`,placeholder:`scope`},{key:`value`,label:`Required value`,placeholder:`ai.invoke`}],build:({path:e,value:t})=>e&&t?[{path:e,contains:t}]:[]}],LE=(e,t)=>e.inputs.every(e=>(t[e.key]??``).trim().length>0);function RE({issuer:e,disabled:t=!1,onChange:n}){let{preset:r,values:i}=jE(e),a=(t,r)=>{let i=TE(t,r);n({provider:t.id,jwks_url:i.jwks_url,issuer:i.issuer,audience:i.audience,user_id_claim:e.user_id_claim??i.user_id_claim})};return(0,I.jsx)(xE,{idPrefix:`issuer`,label:`Identity provider`,presets:DE,selected:r,values:i,compact:!0,disabled:t,onSelect:e=>a(e,{}),onValueChange:(e,t)=>a(r,{...i,[e]:t})})}function zE({claims:e,disabled:t=!1,onChange:n}){let r=(t,r)=>n(e.map((e,n)=>n===t?{...e,...r}:e));return(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Claims the sign-in token must carry. Dot paths; contains matches arrays and space-delimited scopes, equals compares exactly.`}),(0,I.jsxs)(Y,{variant:`outline`,size:`sm`,disabled:t,onClick:()=>n([...e,{path:``,contains:``}]),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add claim`]})]}),e.length===0?(0,I.jsx)(uw,{children:`No claim requirements.`}):e.map((i,a)=>{let o=i.equals===void 0?`contains`:`equals`;return(0,I.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-[180px] flex-1`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Path`}),(0,I.jsx)($,{value:i.path,placeholder:`claims.entitlements`,className:`font-mono text-xs`,disabled:t,onChange:e=>r(a,{path:e.target.value})})]}),(0,I.jsxs)(`div`,{className:`w-[140px]`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Match`}),(0,I.jsxs)(zT,{value:o,disabled:t,onValueChange:t=>n(e.map((e,n)=>n===a?t===`equals`?{path:e.path,equals:Array.isArray(e.contains)?e.contains[0]??``:e.contains??``}:{path:e.path,contains:String(e.equals??``)}:e)),children:[(0,I.jsx)(VT,{className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`contains`,children:`contains`}),(0,I.jsx)(UT,{value:`equals`,children:`equals`})]})]})]}),(0,I.jsxs)(`div`,{className:`min-w-[180px] flex-1`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Value`}),(0,I.jsx)($,{value:o===`contains`&&Array.isArray(i.contains)?i.contains.join(`, `):String(i.equals??i.contains??``),placeholder:o===`contains`?`pro, pro_test`:`pro`,className:`font-mono text-xs`,disabled:t,onChange:e=>{if(o===`equals`){r(a,{equals:e.target.value});return}let t=e.target.value.split(`,`).map(e=>e.trim());r(a,{contains:t.length>1?t:e.target.value})}})]}),(0,I.jsx)(Y,{variant:`ghost`,size:`icon`,"aria-label":`Remove claim`,disabled:t,onClick:()=>n(e.filter((e,t)=>t!==a)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},a)})]})}var BE=IE.filter(e=>e.id!==`none`),VE=NE(``);function HE({issuer:e,disabled:t=!1,onChange:n}){let r=e.required_claims??[],i=PE(r),a=(e.entitlement??(r[0]?.path===`revenueCatEntitlements`?`revenuecat`:`custom`))===`revenuecat`&&i!==null?`revenuecat`:`custom`,o=BE.find(e=>e.id===a)??BE[0],s=e=>{e!==a&&n({entitlement:e,required_claims:e===`revenuecat`?[NE(i??``)]:r})};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`entitlement-check`,children:FE}),(0,I.jsxs)(zT,{value:a,disabled:t,onValueChange:e=>s(e),children:[(0,I.jsx)(VT,{id:`entitlement-check`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:BE.map(e=>(0,I.jsx)(UT,{value:e.id,children:(0,I.jsx)(SE,{preset:e})},e.id))})]}),o.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o.description}):null]}),a===`revenuecat`?(0,I.jsx)(UE,{input:o.inputs[0],entitlement:i??``,disabled:t,onChange:e=>n({required_claims:[NE(e)]})}):(0,I.jsx)(zE,{claims:r,disabled:t,onChange:e=>n({required_claims:e})})]})}function UE({input:e,entitlement:t,disabled:n,onChange:r}){return(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`entitlement-value`,children:e.label}),(0,I.jsx)($,{id:`entitlement-value`,value:t,placeholder:e.placeholder,className:`max-w-[320px] font-mono text-xs`,disabled:n,onChange:e=>r(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:[e.hint,e.docs?(0,I.jsxs)(I.Fragment,{children:[` `,(0,I.jsx)(bE,{href:e.docs.href,children:e.docs.label})]}):null]})]})}var WE=[{value:`issuer`,label:`Signed-in users only`,description:`Users sign in through your identity provider, and the gateway verifies it.`},{value:`app_install`,label:`Unauthenticated users`,description:`Anyone with your app can call. Each installation counts as one user.`}],GE=[{value:`issuer`,label:`Signed-in users only`,description:`Your backend forwards each user's sign-in token, and the gateway verifies it.`},{value:`header`,label:`Your backend sends the user id`,description:`In the ${iT} header on every request.`},{value:`none`,label:`No user identity`,description:`Requests are not linked to any user.`}];function KE({...e}){return(0,I.jsx)(Jd,{"data-slot":`dialog`,...e})}function qE({...e}){return(0,I.jsx)(Xd,{"data-slot":`dialog-trigger`,...e})}function JE({...e}){return(0,I.jsx)(ef,{"data-slot":`dialog-portal`,...e})}function YE({className:e,...t}){return(0,I.jsx)(nf,{"data-slot":`dialog-overlay`,className:H(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function XE({className:e,children:t,showCloseButton:n=!0,dismissOnOutsideInteraction:r=!1,onInteractOutside:i,...a}){return(0,I.jsxs)(JE,{"data-slot":`dialog-portal`,children:[(0,I.jsx)(YE,{}),(0,I.jsxs)(sf,{"data-slot":`dialog-content`,className:H(`fixed top-[50%] left-[50%] z-50 flex max-h-[calc(100dvh-4rem)] w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] flex-col overflow-hidden rounded-lg border bg-background shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg`,n&&`[&_[data-slot=dialog-header]]:pr-14`,e),onInteractOutside:e=>{i?.(e),r||e.preventDefault()},...a,children:[t,n&&(0,I.jsxs)(gf,{"data-slot":`dialog-close`,className:`absolute top-5 right-4 inline-flex size-8 items-center justify-center rounded-md text-muted-foreground opacity-70 ring-offset-background transition-[opacity,background-color,color] hover:bg-muted hover:text-foreground hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,I.jsx)(Ya,{}),(0,I.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function ZE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`dialog-header`,className:H(`flex shrink-0 flex-col gap-2 border-b p-6 text-center sm:text-left`,e),...t})}function QE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`dialog-body`,className:H(`min-h-0 flex-1 overflow-y-auto px-6 py-5`,e),...t})}function $E({className:e,showCloseButton:t=!1,children:n,...r}){return(0,I.jsxs)(`div`,{"data-slot":`dialog-footer`,className:H(`flex shrink-0 flex-col-reverse gap-2 border-t px-6 py-4 sm:flex-row sm:justify-end`,e),...r,children:[n,t&&(0,I.jsx)(gf,{asChild:!0,children:(0,I.jsx)(Y,{variant:`outline`,children:`Close`})})]})}function eD({className:e,...t}){return(0,I.jsx)(ff,{"data-slot":`dialog-title`,className:H(`text-lg leading-6 font-semibold`,e),...t})}function tD({className:e,...t}){return(0,I.jsx)(mf,{"data-slot":`dialog-description`,className:H(`text-sm text-muted-foreground`,e),...t})}function nD({open:e,onOpenChange:t,title:n,description:r,submitLabel:i,pending:a,disabled:o,onSubmit:s,secondaryAction:c,className:l,children:u}){let{readOnly:d}=ox(),f=d||o||a;return(0,I.jsx)(KE,{open:e,onOpenChange:t,children:(0,I.jsx)(XE,{className:l??`sm:max-w-md`,...r?{}:{"aria-describedby":void 0},children:(0,I.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,autoComplete:`off`,onSubmit:e=>{e.preventDefault(),!f&&s()},children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{className:`text-balance`,children:n})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[r?(0,I.jsx)(tD,{className:`text-pretty`,children:r}):null,u]}),(0,I.jsxs)($E,{children:[c,(0,I.jsx)(Y,{type:`button`,variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,I.jsxs)(iw,{type:`submit`,disabled:o||a,children:[a?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,i]})]})]})})})}function rD({open:e,title:t,description:n,label:r,secret:i,acknowledgeLabel:a=`I’ve saved this key`,footnote:o,onAcknowledge:s}){let[c,l]=(0,v.useState)(!1),u=async()=>{try{await navigator.clipboard.writeText(i),l(!0),U.success(`Copied to clipboard`)}catch{U.error(`Could not copy. Select the value and copy it manually.`)}},d=()=>{l(!1),s()};return(0,I.jsx)(KE,{open:e,onOpenChange:e=>{e||d()},children:(0,I.jsxs)(XE,{showCloseButton:!1,className:`sm:max-w-lg`,onEscapeKeyDown:e=>e.preventDefault(),children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{className:`text-balance`,children:t})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{className:`text-pretty`,children:n}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`revealed-secret`,children:r}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)($,{id:`revealed-secret`,value:i,readOnly:!0,className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,I.jsxs)(Y,{type:`button`,variant:`outline`,className:`min-w-24`,onClick:()=>void u(),children:[c?(0,I.jsx)(ra,{className:`size-4`}):(0,I.jsx)(ha,{className:`size-4`}),c?`Copied`:`Copy`]})]}),o?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}):null]})]}),(0,I.jsx)($E,{children:(0,I.jsx)(Y,{onClick:d,children:a})})]})})}function iD({appId:e,exchanged:t=!1,title:n=`Server API keys`,description:r}){let i=IS(e),a=LS(e),o=RS(e),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(null),p=async()=>{if(l.trim())try{let e=await a.mutateAsync(l.trim());c(!1),u(``),f(e)}catch(e){U.error(e instanceof Error?e.message:`Could not create the API key`)}},m=async e=>{try{await o.mutateAsync(e),U.success(`API key revoked`)}catch(e){U.error(e instanceof Error?e.message:`Could not revoke the API key`)}};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:n,description:r,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>{u(``),c(!0)},children:[(0,I.jsx)(Na,{className:`size-4`}),`New key`]})})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[t?null:(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Your backend sends one of these keys as an Authorization bearer credential. Revoking takes effect within a minute.`}),(0,I.jsx)(`div`,{className:`overflow-hidden rounded-md border`,children:(0,I.jsxs)(sE,{className:`[--table-inset:1rem]`,children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Prefix`}),(0,I.jsx)(Z,{children:`Last used`}),(0,I.jsx)(Z,{children:`Status`}),(0,I.jsx)(Z,{className:`w-24`})]})}),(0,I.jsx)(lE,{children:i.data?.keys.length?i.data.keys.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{children:e.name}),(0,I.jsxs)(Q,{className:`font-mono text-xs`,children:[e.key_prefix,`…`]}),(0,I.jsx)(Q,{className:`text-xs text-muted-foreground`,children:hC(e.last_used_at)}),(0,I.jsx)(Q,{children:(0,I.jsx)(Ib,{variant:e.status===`active`?`secondary`:`outline`,children:e.status})}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsxs)(iw,{variant:`ghost`,size:`sm`,className:`text-destructive`,disabled:e.status===`revoked`||o.isPending,onClick:()=>void m(e.id),children:[(0,I.jsx)(Va,{className:`size-3.5`}),`Revoke`]})})]},e.id)):(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,className:`py-8 text-center text-sm text-muted-foreground`,children:`No API keys yet.`})})})]})})]})]}),(0,I.jsx)(nD,{open:s,onOpenChange:c,title:`Create an API key`,submitLabel:`Create key`,pending:a.isPending,disabled:!l.trim(),onSubmit:()=>void p(),children:(0,I.jsx)(sw,{label:`Key name`,htmlFor:`api-key-name`,hint:`Name it so you can tell keys apart in the list.`,children:(0,I.jsx)($,{id:`api-key-name`,value:l,placeholder:`Production Worker`,maxLength:100,autoFocus:!0,autoComplete:`off`,onChange:e=>u(e.target.value)})})}),(0,I.jsx)(rD,{open:d!==null,title:`Copy your new key now`,description:(0,I.jsxs)(I.Fragment,{children:[`This is the only time the plaintext for`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:d?.name}),` is available — you will not see it again. The gateway stores only a hash.`]}),label:`API key`,secret:d?.key??``,onAcknowledge:()=>{f(null),a.reset()}})]})}var aD=`identity`,oD=[{slug:`identity`,label:`Application identity`},{slug:`users`,label:`User authentication`},{slug:`subscription`,label:`Subscription check`}],sD={secure:{icon:la,className:`text-emerald-600 dark:text-emerald-400`},weak:{icon:za,className:`text-amber-600 dark:text-amber-400`},incomplete:{icon:ca,className:`text-destructive`},off:{icon:ua,className:`text-muted-foreground/60`}},cD=[{value:`paid`,label:`Paid users only`,description:`The sign-in token must carry a claim that says the user has paid.`},{value:`any`,label:`Any signed-in user`,description:`Signing in is enough. Nothing about payment is checked.`}],lD=e=>(e.required_claims??[]).length>0||e.entitlement!==void 0?`paid`:`any`;function uD(e,t){let n=e.config.authentication,r=lT(n);return{identity:n.type===`apple_app_attest`?!n.app_attest.team_id.trim()||!n.app_attest.bundle_id.trim()?{tone:`incomplete`,text:`Team or bundle id missing`}:{tone:`secure`,text:`Verified with App Attest`}:t===!1?{tone:`incomplete`,text:`No active API key`}:{tone:`secure`,text:`Verified with API keys`},users:(()=>{switch(n.end_user?.source??`none`){case`issuer`:return r&&$T(r)?{tone:`secure`,text:`Signed-in users only`}:{tone:`incomplete`,text:`Identity provider not finished`};case`header`:return n.type===`api_key`&&n.end_user?.source===`header`&&!n.end_user.header.trim()?{tone:`incomplete`,text:`Header name missing`}:{tone:`weak`,text:`Your backend names the user`};case`app_install`:return{tone:`weak`,text:`Unauthenticated users allowed`};default:return{tone:`weak`,text:`No user identity`}}})(),subscription:r?lD(r)===`paid`?(r.required_claims??[]).every(eE)&&(r.required_claims??[]).length>0?{tone:`secure`,text:`Paid users only`}:{tone:`incomplete`,text:`Paid check not finished`}:{tone:`weak`,text:`Any signed-in user`}:{tone:`off`,text:`Needs signed-in users`}}}function dD({appId:e,level:t,state:n}){let r=n.draft,i=r.config.authentication,{readOnly:a}=ox(),o=IS(e,i.type===`api_key`),s=uD(r,o.data?o.data.keys.some(e=>e.status===`active`):void 0),c=oD.some(e=>e.slug===t)&&s[t].tone!==`off`?t:aD;return(0,I.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[16rem_minmax(0,1fr)]`,children:[(0,I.jsx)(`nav`,{"aria-label":`Auth policy levels`,className:`flex flex-col gap-1 lg:sticky lg:top-6 lg:self-start`,children:oD.map(t=>(0,I.jsx)(fD,{to:`/apps/${e}/auth/${t.slug}`,label:t.label,status:s[t.slug],current:t.slug===c},t.slug))}),(0,I.jsx)(`div`,{className:`min-w-0 space-y-4`,children:c===`identity`?i.type===`apple_app_attest`?(0,I.jsx)(pD,{authentication:i,readOnly:a,state:n}):(0,I.jsx)(iD,{appId:e,exchanged:lT(i)!==void 0,title:`Application identity`,description:`A server application. Your backend proves itself with one of these API keys.`}):c===`users`?(0,I.jsx)(mD,{authentication:i,readOnly:a,state:n}):(0,I.jsx)(hD,{issuer:lT(i)??uT(),readOnly:a,state:n})})]})}function fD({to:e,label:t,status:n,current:r}){let{icon:i,className:a}=sD[n.tone],o=(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(i,{className:H(`mt-0.5 size-4 shrink-0`,a),"aria-hidden":`true`}),(0,I.jsxs)(`span`,{className:`min-w-0`,children:[(0,I.jsx)(`span`,{className:`block text-sm font-medium`,children:t}),(0,I.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:n.text})]})]}),s=`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition-colors`;return n.tone===`off`?(0,I.jsx)(`div`,{"aria-disabled":`true`,className:H(s,`opacity-60`),children:o}):(0,I.jsx)(Pn,{to:e,"aria-current":r?`page`:void 0,className:H(s,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`,r?`bg-muted`:`hover:bg-muted/60`),children:o})}function pD({authentication:e,readOnly:t,state:n}){let r=e.app_attest,i=t=>n.updateAuthentication({...e,app_attest:{...r,...t}});return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Application identity`,description:`An iOS application. Only builds signed with this team and bundle id can call AI providers through this gateway.`})}),(0,I.jsxs)(oE,{className:`space-y-6`,children:[(0,I.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-team-id`,children:`Apple Team ID`}),(0,I.jsx)($,{id:`apple-team-id`,value:r.team_id,placeholder:`ABCDE12345`,className:`font-mono text-xs`,disabled:t,onChange:e=>i({team_id:e.target.value})}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In your Apple Developer account under`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/account#MembershipDetailsCard`,children:`Membership details`}),`.`]})]}),(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-bundle-id`,children:`Bundle ID`}),(0,I.jsx)($,{id:`apple-bundle-id`,value:r.bundle_id,placeholder:`com.example.app`,className:`font-mono text-xs`,disabled:t,onChange:e=>i({bundle_id:e.target.value})}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In Xcode, on your target's`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/documentation/xcode/configuring-the-build-settings-of-a-target#Set-the-bundle-ID`,children:`Signing & Capabilities`}),` `,`tab.`]})]})]}),(0,I.jsx)(vE,{value:r.environments,compact:!0,disabled:t,onChange:t=>n.updateAuthentication({...e,app_attest:{team_id:r.team_id,bundle_id:r.bundle_id,...t.length===1&&t[0]===`production`?{}:{environments:t}}})})]})]})}function mD({authentication:e,readOnly:t,state:n}){let r=(0,v.useId)(),i=e.end_user?.source??`none`,a=lT(e),o=e.type===`api_key`?GE:WE;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`User authentication`,description:`Choose whether only users signed in to your app can call AI through this gateway.`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[t?(0,I.jsx)(rw,{reason:nx,reasonId:r,className:`w-full`,children:(0,I.jsx)(yE,{label:`User authentication`,choices:o,value:i,disabled:!0,describedBy:r,onChange:()=>{}})}):(0,I.jsx)(yE,{label:`User authentication`,choices:o,value:i,onChange:e=>n.setEndUserSource(e===`none`?void 0:e)}),e.type===`api_key`&&e.end_user?.source===`header`?(0,I.jsx)(sw,{label:`Header name`,htmlFor:`end-user-header`,hint:`Lowercased, and removed before the request reaches the provider. Defaults to ${iT}.`,children:(0,I.jsx)($,{id:`end-user-header`,value:e.end_user.header,placeholder:iT,className:`max-w-[320px] font-mono text-xs`,disabled:t,onChange:e=>n.updateEndUserHeader(e.target.value)})}):null]})]}),i===`issuer`?(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Identity provider`,description:`Where your users sign in. The gateway verifies their sign-in tokens against it.`})}),(0,I.jsx)(oE,{children:(0,I.jsx)(RE,{issuer:a??uT(),disabled:t,onChange:n.updateIssuer})})]}):null]})}function hD({issuer:e,readOnly:t,state:n}){let r=(0,v.useId)(),i=lD(e);return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Subscription check`,description:`Check that the user has paid for the app before they can call AI providers through this gateway.`})}),(0,I.jsxs)(oE,{className:`space-y-6`,children:[t?(0,I.jsx)(rw,{reason:nx,reasonId:r,className:`w-full`,children:(0,I.jsx)(yE,{label:`Subscription check`,choices:cD,value:i,disabled:!0,describedBy:r,onChange:()=>{}})}):(0,I.jsx)(yE,{label:`Subscription check`,choices:cD,value:i,onChange:e=>{e!==i&&n.updateIssuer(e===`any`?{entitlement:void 0,required_claims:[]}:{entitlement:`revenuecat`,required_claims:[VE]})}}),i===`paid`?(0,I.jsx)(`div`,{className:`border-t pt-6`,children:(0,I.jsx)(HE,{issuer:e,disabled:t,onChange:n.updateIssuer})}):null]})]})}var gD={requests:{per_minute:null,per_day:null},spending:{monthly_usd:null}},_D={per_user:gD,per_app:gD},vD=e=>e===``?null:Number(e);function yD({state:e}){let t=e.draft,n=t.config.limits??_D,r=t.config.authentication.type!==`api_key`||t.config.authentication.end_user!==void 0,i=(t,r)=>e.updateLimits({...n,[t]:{...n[t],...r}});return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`p`,{className:`text-sm leading-relaxed text-muted-foreground`,children:[`Limits you set on `,(0,I.jsx)(`strong`,{className:`font-medium text-foreground`,children:`your app's end users`}),`. They are unrelated to your own`,` `,(0,I.jsx)(Pn,{to:`/billing`,className:`text-primary-ink underline underline-offset-4`,children:`plan allowance`}),`, which meters all your apps together: a request refused here never spends it. Edits take up to a minute to apply everywhere.`]}),(0,I.jsxs)(`div`,{className:r?`grid gap-4 lg:grid-cols-2`:`grid gap-4`,children:[r?(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Per-user limits`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Applied independently to every authenticated user. Rate limits return`,` `,(0,I.jsx)(`code`,{className:`font-mono`,children:`app_rate_limited`}),`; exhausting the monthly spend returns `,(0,I.jsx)(`code`,{className:`font-mono`,children:`app_budget_exhausted`}),`.`]}),(0,I.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,I.jsx)(sw,{label:`Requests per minute`,htmlFor:`rpm`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`rpm`,type:`number`,min:1,value:n.per_user.requests.per_minute??``,placeholder:`Unlimited`,onChange:e=>i(`per_user`,{requests:{...n.per_user.requests,per_minute:vD(e.target.value)}})})}),(0,I.jsx)(sw,{label:`Requests per day`,htmlFor:`rpd`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`rpd`,type:`number`,min:1,value:n.per_user.requests.per_day??``,placeholder:`Unlimited`,onChange:e=>i(`per_user`,{requests:{...n.per_user.requests,per_day:vD(e.target.value)}})})})]}),(0,I.jsx)(`div`,{className:`border-t pt-4`,children:(0,I.jsx)(sw,{label:`Monthly spending budget (USD)`,htmlFor:`budget`,hint:n.per_user.spending.monthly_usd===null?`Unlimited`:`${dC(n.per_user.spending.monthly_usd)} per user per month. Settled from completed requests, so it stops the request after the one that crosses it.`,children:(0,I.jsx)($,{id:`budget`,type:`number`,min:0,step:`0.01`,value:n.per_user.spending.monthly_usd??``,placeholder:`Unlimited`,onChange:e=>i(`per_user`,{spending:{monthly_usd:vD(e.target.value)}})})})})]})]}):(0,I.jsx)(nE,{children:(0,I.jsx)(oE,{className:`pt-6`,children:(0,I.jsx)(uw,{children:`This application identifies no end users, so there is nobody for a per-user limit to apply to. Choose a user authentication method on the Auth policy tab to set them, or use the application limits below.`})})}),(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Application limits`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Shared across all users and credentials for this application. Leave a field empty to keep that application-wide limit unrestricted.`}),(0,I.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,I.jsx)(sw,{label:`Requests per minute`,htmlFor:`app-rpm`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`app-rpm`,type:`number`,min:1,value:n.per_app.requests.per_minute??``,placeholder:`Unlimited`,onChange:e=>i(`per_app`,{requests:{...n.per_app.requests,per_minute:vD(e.target.value)}})})}),(0,I.jsx)(sw,{label:`Requests per day`,htmlFor:`app-rpd`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`app-rpd`,type:`number`,min:1,value:n.per_app.requests.per_day??``,placeholder:`Unlimited`,onChange:e=>i(`per_app`,{requests:{...n.per_app.requests,per_day:vD(e.target.value)}})})})]}),(0,I.jsx)(`div`,{className:`border-t pt-4`,children:(0,I.jsx)(sw,{label:`Monthly spending budget (USD)`,htmlFor:`app-budget`,hint:n.per_app.spending.monthly_usd===null?`Unlimited`:`${dC(n.per_app.spending.monthly_usd)} per application per month. Settled from completed requests, so it stops the request after the one that crosses it.`,children:(0,I.jsx)($,{id:`app-budget`,type:`number`,min:0,step:`0.01`,value:n.per_app.spending.monthly_usd??``,placeholder:`Unlimited`,onChange:e=>i(`per_app`,{spending:{monthly_usd:vD(e.target.value)}})})})})]})]})]})]})}function bD(e){return e?.apiBaseUrl??window.location.origin}function xD({appId:e,month:t,state:n}){let{capabilities:r}=ox(),i=VS(e,t),a=zS(e,{month:t,limit:1}),o=n.draft.config.authentication,s=(i.data?.input_tokens??0)+(i.data?.cached_input_tokens??0)+(i.data?.cache_write_tokens??0)+(i.data?.output_tokens??0),c=lT(o);return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[o.type===`api_key`?(0,I.jsx)(SD,{appId:e}):null,(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,I.jsx)(dE,{label:`Spend`,value:i.isPending?(0,I.jsx)(aw,{className:`h-6 w-20`}):dC(i.data?.cost_usd??0),detail:`month to date`}),(0,I.jsx)(dE,{label:`Users`,value:a.isPending?(0,I.jsx)(aw,{className:`h-6 w-12`}):cC(a.data?.total??0),detail:`all time`}),(0,I.jsx)(dE,{label:`Requests`,value:i.isPending?(0,I.jsx)(aw,{className:`h-6 w-16`}):cC(i.data?.requests??0),detail:`month to date`}),(0,I.jsx)(dE,{label:`Tokens`,value:i.isPending?(0,I.jsx)(aw,{className:`h-6 w-16`}):lC(s),detail:`all buckets`})]}),(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Client base URL`})}),(0,I.jsxs)(oE,{children:[(0,I.jsxs)(`code`,{className:`block rounded-md bg-muted px-3 py-2 font-mono text-xs break-all`,children:[bD(r),`/v1/apps/`,e,`/proxy/{provider}/{provider_path}`]}),(0,I.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:c?(0,I.jsxs)(I.Fragment,{children:[`Auth exchange lives at`,` `,(0,I.jsxs)(`span`,{className:`font-mono`,children:[`/v1/apps/`,e,`/auth/token`]}),`.`]}):(0,I.jsxs)(I.Fragment,{children:[`Clients send their API key as the`,` `,(0,I.jsx)(`span`,{className:`font-mono`,children:`Authorization`}),` bearer credential; this app has no token exchange.`]})})]})]})]})}function SD({appId:e}){let t=IS(e);return!t.data||t.data.keys.some(e=>e.status===`active`)?null:(0,I.jsxs)(Ds,{children:[(0,I.jsx)(Sa,{}),(0,I.jsx)(Os,{children:`This app has no active API key`}),(0,I.jsxs)(ks,{children:[`Nothing can call it until one is created.`,` `,(0,I.jsx)(Pn,{to:`/apps/${e}/auth/identity`,className:`text-primary-ink underline underline-offset-4`,children:`Create an API key`})]})]})}function CD({className:e,size:t=`default`,...n}){return(0,I.jsx)(gy,{"data-slot":`switch`,"data-size":t,className:H(`peer group/switch inline-flex shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-[1.15rem] data-[size=default]:w-8 data-[size=sm]:h-3.5 data-[size=sm]:w-6 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input dark:data-[state=unchecked]:bg-input/80`,e),...n,children:(0,I.jsx)(vy,{"data-slot":`switch-thumb`,className:H(`pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0 dark:data-[state=checked]:bg-primary-foreground dark:data-[state=unchecked]:bg-foreground`)})})}function wD({values:e,onChange:t,placeholder:n,suggestions:r=[],warn:i,warnTitle:a}){let[o,s]=(0,v.useState)(``),c=`suggestions-${Math.abs(TD(r.join(`,`)+n))}`,l=n=>{let r=n.trim();if(!r||e.includes(r))return s(``);t([...e,r]),s(``)};return(0,I.jsxs)(`div`,{className:`space-y-2`,children:[e.length>0?(0,I.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(n=>{let r=i?.(n)??!1;return(0,I.jsxs)(`span`,{title:r?a:void 0,className:H(`inline-flex items-center gap-1 rounded-md border py-1 pr-1 pl-2 font-mono text-xs`,r?`border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-400`:`bg-muted/50`),children:[n,(0,I.jsx)(`button`,{type:`button`,"aria-label":`Remove ${n}`,className:`rounded p-0.5 text-muted-foreground transition-colors hover:bg-background hover:text-foreground`,onClick:()=>t(e.filter(e=>e!==n)),children:(0,I.jsx)(Ya,{className:`size-3`})})]},n)})}):null,(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)($,{value:o,list:r.length>0?c:void 0,placeholder:n,className:`h-8 font-mono text-xs`,onChange:e=>s(e.target.value),onKeyDown:n=>{(n.key===`Enter`||n.key===`,`)&&(n.preventDefault(),l(o)),n.key===`Backspace`&&o===``&&e.length>0&&t(e.slice(0,-1))}}),r.length>0?(0,I.jsx)(`datalist`,{id:c,children:r.map(e=>(0,I.jsx)(`option`,{value:e},e))}):null,(0,I.jsxs)(Y,{type:`button`,variant:`outline`,size:`sm`,className:`h-8`,onClick:()=>l(o),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add`]})]})]})}function TD(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+e.charCodeAt(n)|0;return t}var ED={responses:`Responses`,chat_completions:`Chat Completions`,anthropic_messages:`Anthropic Messages`,gemini_native:`Gemini generateContent`,audio_transcription:`Transcription`};function DD(e){return Object.hasOwn(ED,e)}var OD={gemini:[`gemini_native`],openai:[`audio_transcription`],xai:[`audio_transcription`]};function kD(e){return{style:e,label:ED[e],path:Lw[e]}}function AD(e,t){let n=Xw[e]?.[t];if(!n)return null;let r=OD[t]??[],i=n.apiStyles?.filter(DD);return{narrowed:i!==void 0,available:(i??[]).map(kD),unavailable:i?r.filter(e=>!i.includes(e)).map(kD):[],modelIds:n.modelPrefix?`${eT[t]} model IDs with no "${n.modelPrefix}" prefix — the gateway adds it upstream`:`${eT[t]} model IDs, unchanged`}}function jD(e,t,n){if(e===null)return!0;let r=AD(e,t);if(!r)return!1;if(!r.narrowed)return!0;let i=zw[n];return r.available.some(e=>e.style===i)}var MD={openai:`Forwarded with the leading v1/ stripped, matching Cloudflare's provider-native URL.`,anthropic:`Forwarded with the v1/ prefix retained.`,xai:`Routed to Cloudflare's grok slug; the tenant path stays /proxy/xai/...`,gemini:`Use the OpenAI-compatible path v1beta/openai/chat/completions.`,perplexity:`Routed to Cloudflare's perplexity-ai slug; use chat/completions for Sonar models.`,deepseek:`Direct only. DeepSeek's base URL has no v1/, so the path is chat/completions.`,groq:`Direct only. Groq namespaces its OpenAI API: use openai/v1/chat/completions.`,mistral:`Direct only. Use v1/chat/completions.`,together:`Direct only. Use v1/chat/completions; models are namespaced, e.g. openai/gpt-oss-120b.`,fireworks:`Direct only. Use inference/v1/chat/completions. Models are account-scoped (accounts/…/models/…), so price them under custom model pricing.`,cerebras:`Direct only. Use v1/chat/completions.`,moonshot:`Direct only. Use v1/chat/completions on the international api.moonshot.ai host.`,huggingface:`Direct only. Use v1/chat/completions on the Inference Providers router. Pin the upstream in the model ID (author/model:provider) — otherwise the router picks one and the price varies with it.`,baseten:`Direct only. Use v1/chat/completions on the Model APIs host.`,bytedance:`Direct only. BytePlus ModelArk's version segment is already in the base URL: the path is chat/completions. Models must be activated in your ModelArk console first.`,openrouter:`Direct only, chat completions only. Models are OpenRouter slugs, e.g. google/gemini-3.6-flash, and need no local price: cost is reported by OpenRouter per request.`};function ND(e,t){if(e.providerGatewayId===null)return null;let n=t.find(t=>t.id===e.providerGatewayId),r=n?AD(n.type,e.type):null;if(!r?.narrowed)return null;let i=r.available.map(e=>`${e.label} at ${e.path}`).join(`, `),a=r.unavailable.length>0?` Not available on this route: ${r.unavailable.map(e=>e.label).join(`, `)}.`:``;return`Routed through ${n.name}: ${i}.${a} Models: ${r.modelIds}.`}function PD({state:e}){return(0,I.jsx)(Ib,{variant:`outline`,className:`border-muted-foreground/30 text-[11px] font-normal text-muted-foreground`,children:e})}function FD({row:e,config:t,onChange:n}){let r=(t?.allowed_paths??[]).map(fT),i=e.knownModels,a=e=>n({...mT(),...t,allowed_paths:e.map(pT)});return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.title,e.badge?(0,I.jsx)(PD,{state:e.badge}):null]}),description:e.description,action:(0,I.jsx)(CD,{"aria-label":`Enable ${e.slug}`,checked:t!==void 0,onCheckedChange:e=>n(e?mT():void 0)})})}),t?(0,I.jsxs)(oE,{className:`space-y-5`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(ow,{className:`text-sm`,children:`Allowed paths`}),(0,I.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:()=>a([...r,{path:``}]),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add path`]})]}),r.length===0?(0,I.jsx)(uw,{children:`Every path is allowed. Add one or more paths to restrict this provider.`}):(0,I.jsx)(`div`,{className:`space-y-2`,children:r.map((e,t)=>(0,I.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-[200px] flex-[2]`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Path`}),(0,I.jsx)($,{value:e.path,placeholder:`v1/responses`,className:`font-mono text-xs`,onChange:e=>a(r.map((n,r)=>r===t?{...n,path:e.target.value}:n))})]}),(0,I.jsxs)(`div`,{className:`min-w-[150px] flex-1`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Fixed model`}),(0,I.jsx)($,{value:e.fixed_model??``,placeholder:`none`,className:`font-mono text-xs`,onChange:e=>a(r.map((n,r)=>r===t?{...n,fixed_model:e.target.value||void 0}:n))})]}),(0,I.jsxs)(`div`,{className:`w-[170px]`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Output cap style`}),(0,I.jsxs)(zT,{value:e.clamp??`auto`,onValueChange:e=>a(r.map((n,r)=>r===t?{...n,clamp:e===`auto`?void 0:e}:n)),children:[(0,I.jsx)(VT,{className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`auto`,children:`auto (by body)`}),rT.map(e=>(0,I.jsx)(UT,{value:e,children:e},e))]})]})]}),(0,I.jsx)(Y,{variant:`ghost`,size:`icon`,"aria-label":`Remove path`,onClick:()=>a(r.filter((e,n)=>n!==t)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},t))}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Leave this list empty to allow every path. A fixed model applies to transcription-style routes with no model in the body; it is never injected upstream. Leave the output cap style on auto unless the route needs an exception.`})]}),(0,I.jsx)(sw,{label:`Allowed models`,hint:`Leave empty to allow every model with configured pricing. A non-empty list restricts this provider; rewrites are resolved before pricing is checked.`,children:(0,I.jsx)(wD,{values:t.allowed_models??[],suggestions:i,placeholder:`gpt-5.6-terra`,onChange:e=>n({...t,allowed_models:e})})}),(0,I.jsx)(sw,{label:`Max output tokens`,hint:`Empty = unrestricted. If set, requests above this are rejected; requests without an output-limit parameter get this value injected. Transcription routes ignore this cap.`,children:(0,I.jsx)($,{type:`number`,min:1,className:`max-w-[200px]`,value:t.max_output_tokens??``,placeholder:`8192`,onChange:e=>n({...t,max_output_tokens:e.target.value?Number(e.target.value):void 0})})})]}):null]})}function ID(e,t,n,r){let i=e.map(e=>({slug:e.slug,title:e.name,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`span`,{className:`font-mono`,children:[`/proxy/`,e.slug,`/…`]}),` ·`,` `,(0,I.jsx)(FT,{type:e.type,className:`align-middle`}),` —`,` `,ND(e,t)??MD[e.type]]}),knownModels:aT(e,r),...e.status===`disabled`?{badge:`disabled`}:{}})),a=n.filter(t=>!e.some(e=>e.slug===t)).map(e=>({slug:e,title:e,description:`No instance answers for this slug. Recreate it on the Providers page, or turn this off.`,knownModels:[],badge:`deleted`}));return[...i,...a]}var LD=e=>e.filter(([e,t])=>e!==``&&t!==``),RD=e=>Object.fromEntries(LD(e));function zD({rewrites:e,onChange:t}){let[n,r]=(0,v.useState)(()=>Object.entries(e)),i=JSON.stringify(e),[a,o]=(0,v.useState)(i);i!==a&&(o(i),i!==JSON.stringify(RD(n))&&r(Object.entries(e)));let s=e=>{r(e),t(RD(e))},c=(e,t)=>s(n.map((n,r)=>r===e?t:n)),l=LD(n).length<n.length;return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Model rewrites`,description:`Server-side remap applied after the allowlist check, so a target need not be client-allowlisted. Usage records the rewritten model.`,action:(0,I.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:()=>s([...n,[``,``]]),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add rewrite`]})})}),(0,I.jsxs)(oE,{className:`space-y-2`,children:[n.length===0?(0,I.jsx)(uw,{children:`No rewrites. Clients get exactly the model they ask for.`}):n.map(([e,t],r)=>(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)($,{value:e,"aria-label":`Rewrite ${r+1} source model`,placeholder:`gpt-5.6-terra`,className:`flex-1 font-mono text-xs`,onChange:e=>c(r,[e.target.value,t])}),(0,I.jsx)(Zi,{className:`size-4 shrink-0 text-muted-foreground`}),(0,I.jsx)($,{value:t,"aria-label":`Rewrite ${r+1} target model`,placeholder:`gpt-5.7`,className:`flex-1 font-mono text-xs`,onChange:t=>c(r,[e,t.target.value])}),(0,I.jsx)(Y,{variant:`ghost`,size:`icon`,"aria-label":`Remove rewrite ${r+1}`,onClick:()=>s(n.filter((e,t)=>t!==r)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},r)),l?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`A rewrite is saved once both sides are filled in. A row left half-finished is dropped.`}):null]})]})}function BD({state:e}){let t=e.draft.config.routing,n=yT(t),r=bT(t),i=fS().data??[],a=_S().data?.gateways??[],o=qS().data?.prices,s=ID(i,a,r,o);return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(nE,{className:n===`all`?`border-emerald-500/30`:void 0,children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Provider access`,description:`Choose whether this application can use every provider supported by the gateway or only providers you select.`,action:(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(ow,{htmlFor:`configure-providers`,className:`text-xs text-muted-foreground`,children:`Configure individually`}),(0,I.jsx)(CD,{id:`configure-providers`,"aria-label":`Configure providers individually`,checked:n===`selected`,onCheckedChange:t=>{e.updateProxy(t?{providers:{mode:`selected`,selected:(()=>{let e=i.find(e=>e.status===`active`)??i[0];return e?{[e.slug]:mT()}:{}})()}}:{providers:{mode:`all`}})}})]})})}),(0,I.jsx)(oE,{children:n===`all`?(0,I.jsx)(`div`,{className:`rounded-xl border border-emerald-500/25 bg-emerald-500/[0.06] p-4`,children:(0,I.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,I.jsx)(`span`,{className:`mt-0.5 flex size-9 shrink-0 items-center justify-center rounded-lg bg-emerald-500/12 text-emerald-600 dark:text-emerald-400`,children:(0,I.jsx)(la,{className:`size-5`})}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`p`,{className:`text-sm font-semibold`,children:`Every configured instance is allowed`}),(0,I.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`New provider instances, paths, and models are available automatically. Turn on individual configuration only when this application needs restrictions.`}),(0,I.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:i.length===0?(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No provider instances yet.`}):i.map(e=>(0,I.jsx)(Ib,{variant:`secondary`,className:H(`bg-background/75 font-mono text-[11px] font-normal`,e.status===`disabled`&&`text-muted-foreground line-through decoration-muted-foreground/50`),title:e.status===`disabled`?`${e.slug} is disabled and serves no traffic`:void 0,children:e.slug},e.slug))})]})]})}):(0,I.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-muted/45 p-4 ring-1 ring-border/70`,children:[(0,I.jsx)(`span`,{className:`mt-0.5 flex size-9 shrink-0 items-center justify-center rounded-lg bg-background text-muted-foreground shadow-sm ring-1 ring-border`,children:(0,I.jsx)(Ha,{className:`size-4`})}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`p`,{className:`text-sm font-medium`,children:[r.length,` of `,i.length,` provider instances enabled`]}),(0,I.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`Use the switches below. An enabled instance allows every path and model until you add a restriction, and clients reach it at its own slug.`})]})]})})]}),n===`selected`&&s.length===0?(0,I.jsx)(nE,{children:(0,I.jsx)(oE,{children:(0,I.jsx)(uw,{children:`No provider instances to choose from. Add one on the Providers page, then come back to restrict this app to it.`})})}):null,n===`selected`?s.map(n=>(0,I.jsx)(FD,{row:n,config:t.providers.selected?.[n.slug],onChange:r=>e.updateProxy({providers:{mode:`selected`,selected:{...t.providers.selected,[n.slug]:r}}})},n.slug)):null,(0,I.jsx)(zD,{rewrites:t.model_rewrites??{},onChange:t=>e.updateProxy({model_rewrites:t})})]})}function VD({open:e,onOpenChange:t,title:n,description:r,confirmLabel:i=`Confirm`,confirmWord:a,destructive:o,pending:s,onConfirm:c}){let[l,u]=(0,v.useState)(``);return(0,I.jsx)(KE,{open:e,onOpenChange:e=>{e||u(``),t(e)},children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:n})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{asChild:!0,children:(0,I.jsx)(`div`,{className:`space-y-2 text-sm text-muted-foreground`,children:r})}),a?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsxs)(ow,{htmlFor:`confirm-word`,className:`text-xs`,children:[`Type `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:a}),` to continue`]}),(0,I.jsx)($,{id:`confirm-word`,value:l,autoComplete:`off`,className:`font-mono`,onChange:e=>u(e.target.value)})]}):null]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(Y,{variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,I.jsx)(Y,{variant:o?`destructive`:`default`,disabled:!(!a||l===a)||s,onClick:c,children:i})]})]})})}function HD({appId:e,state:t}){let n=t.draft,r=ht(),i=FS(),{readOnly:a}=ox(),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(!1),u=async()=>{try{await navigator.clipboard.writeText(e),l(!0),U.success(`Application id copied`)}catch{U.error(`Could not copy the application id`)}},d=async()=>{try{let t=await i.mutateAsync(e);U.success(`Deleted ${n.name}`,{description:`${t.removed_users} users removed. Usage history was kept.`}),r(`/apps`)}catch(e){U.error(e instanceof Error?e.message:`Could not delete the app`)}};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(nE,{children:(0,I.jsxs)(oE,{className:`space-y-5`,children:[(0,I.jsx)(sw,{label:`Name`,htmlFor:`app-name`,children:(0,I.jsx)($,{id:`app-name`,value:n.name,maxLength:100,disabled:a,className:`max-w-md`,onChange:e=>t.update({name:e.target.value})})}),(0,I.jsx)(sw,{label:`Application id`,htmlFor:`app-id`,hint:`Fixed when the app was created. It is part of every URL your clients call.`,children:(0,I.jsxs)(`div`,{className:`flex max-w-md gap-2`,children:[(0,I.jsx)($,{id:`app-id`,value:e,readOnly:!0,className:`font-mono text-xs`}),(0,I.jsxs)(Y,{type:`button`,variant:`outline`,className:`min-w-24`,onClick:()=>void u(),children:[c?(0,I.jsx)(ra,{className:`size-4`}):(0,I.jsx)(ha,{className:`size-4`}),c?`Copied`:`Copy`]})]})})]})}),(0,I.jsx)(nE,{children:(0,I.jsx)(oE,{children:(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:`App enabled`}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Turned off, this app refuses every request. Nothing is deleted, and turning it back on restores it as it was.`})]}),(0,I.jsx)(CD,{"aria-label":`App enabled`,checked:n.status===`active`,disabled:a,onCheckedChange:e=>t.update({status:e?`active`:`disabled`})})]})})}),(0,I.jsx)(nE,{className:`border-destructive/40`,children:(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Delete this app`,description:`Clients of this app stop working immediately. Registered users and App Attest keys are removed. Usage history is kept for accounting.`,action:(0,I.jsx)(iw,{variant:`destructive`,size:`sm`,disabled:i.isPending,onClick:()=>s(!0),children:`Delete app`})})})}),(0,I.jsx)(VD,{open:o,onOpenChange:s,title:`Delete ${n.name}?`,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`p`,{children:`Clients of this app stop working immediately. Registered users and App Attest keys are removed; usage history is kept for accounting.`}),(0,I.jsx)(`p`,{children:`This cannot be undone.`})]}),confirmWord:e,confirmLabel:`Delete app`,destructive:!0,pending:i.isPending,onConfirm:()=>void d()})]})}var UD=25;function WD({appId:e}){let[t,n]=(0,v.useState)(yC()),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(`all`),[s,c]=(0,v.useState)(0),[l,u]=(0,v.useState)(null),d=zS(e,{month:t,query:r||void 0,status:a===`all`?void 0:a,limit:UD,offset:s*UD}),f=BS(e),p=async()=>{if(!l)return;let e=l.status===`active`;try{await f.mutateAsync({userId:l.id,blocked:e}),U.success(e?`Blocked ${l.id}`:`Unblocked ${l.id}`,{description:e?`Their Durable Object was updated, so it applies even to a live gateway token.`:void 0}),u(null)}catch(e){U.error(e instanceof Error?e.message:`Could not update the user`)}},m=d.data?.total??0,h=Math.max(1,Math.ceil(m/UD));return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,I.jsxs)(`div`,{className:`relative min-w-[220px] flex-1`,children:[(0,I.jsx)(Ia,{className:`absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,I.jsx)($,{value:r,placeholder:`Search user id`,className:`h-9 pl-8 font-mono text-xs`,onChange:e=>{i(e.target.value),c(0)}})]}),(0,I.jsxs)(zT,{value:a,onValueChange:e=>{o(e),c(0)},children:[(0,I.jsx)(VT,{className:`w-[140px]`,size:`sm`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`all`,children:`All users`}),(0,I.jsx)(UT,{value:`active`,children:`Active`}),(0,I.jsx)(UT,{value:`blocked`,children:`Blocked`})]})]}),(0,I.jsx)(qT,{value:t,onChange:n})]}),(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`User`}),(0,I.jsx)(Z,{children:`Attestation`}),(0,I.jsx)(Z,{children:`Last seen`}),(0,I.jsx)(Z,{className:`text-right`,children:`Requests`}),(0,I.jsx)(Z,{className:`text-right`,children:`Tokens`}),(0,I.jsx)(Z,{className:`text-right`,children:`Cost`}),(0,I.jsx)(Z,{className:`w-24`})]})}),(0,I.jsx)(lE,{children:d.isPending?[0,1,2].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:7,children:(0,I.jsx)(aw,{className:`h-8 w-full`})})},e)):d.data?.users.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:7,className:`py-10 text-center text-sm text-muted-foreground`,children:`No users yet. A row appears once a client completes its first token exchange.`})}):d.data?.users.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{children:(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`font-mono text-xs`,children:e.id}),e.status===`blocked`?(0,I.jsx)(tC,{status:`blocked`}):null]})}),(0,I.jsx)(Q,{children:e.attest_registered?(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,I.jsx)(Ib,{variant:`secondary`,className:`text-[11px] font-normal`,children:`registered`}),(0,I.jsxs)(`span`,{className:`tabular text-[11px] text-muted-foreground`,children:[`counter `,e.attest_counter]})]}):(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.is_virtual?`server attributed`:`issuer token`})}),(0,I.jsx)(Q,{className:`text-xs text-muted-foreground`,children:hC(e.last_seen_at)}),(0,I.jsx)(Q,{className:`tabular text-right`,children:cC(e.usage.requests)}),(0,I.jsx)(Q,{className:`tabular text-right`,children:lC(vC(e.usage))}),(0,I.jsx)(Q,{className:`tabular text-right`,children:dC(e.usage.cost_usd)}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsx)(iw,{variant:`ghost`,size:`sm`,disabled:e.is_virtual,onClick:()=>u(e),className:e.status===`active`?`text-destructive`:void 0,children:e.status===`active`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)($i,{className:`size-3.5`}),`Block`]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(la,{className:`size-3.5`}),`Unblock`]})})})]},e.id))})]})}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-muted-foreground`,children:[(0,I.jsxs)(`span`,{children:[cC(m),` users · page `,s+1,` of `,h]}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(Y,{variant:`outline`,size:`sm`,disabled:s===0,onClick:()=>c(e=>e-1),children:`Previous`}),(0,I.jsx)(Y,{variant:`outline`,size:`sm`,disabled:s+1>=h,onClick:()=>c(e=>e+1),children:`Next`})]})]}),(0,I.jsx)(VD,{open:l!==null,onOpenChange:e=>!e&&u(null),title:l?.status===`active`?`Block ${l?.id}?`:`Unblock ${l?.id}?`,description:l?.status===`active`?(0,I.jsx)(`p`,{children:`Their requests are refused immediately, even with an unexpired gateway token, because the block is written to their Durable Object as well as D1.`}):(0,I.jsx)(`p`,{children:`Their requests resume as soon as the Durable Object is updated.`}),confirmLabel:l?.status===`active`?`Block user`:`Unblock user`,destructive:l?.status===`active`,pending:f.isPending,onConfirm:()=>void p()})]})}var GD=(0,v.lazy)(()=>w(()=>import(`./usage-DjvO6eyw.js`).then(e=>({default:e.UsageTab})),[])),KD=(0,v.lazy)(()=>w(()=>import(`./endpoints-Dnjjwdkn.js`).then(e=>({default:e.EndpointsTab})),[]));function qD(){let{appId:e=``,tab:t=`overview`,section:n}=_t(),r=QT(e),[i,a]=(0,v.useState)(yC()),o=iC.find(e=>e.slug===t),{query:s,draft:c,dirty:l}=r,u=c?tE(c):null;return s.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load this app`}),(0,I.jsxs)(ks,{children:[s.error instanceof Error?s.error.message:`Unknown error`,(0,I.jsx)(Pn,{to:`/apps`,className:`underline underline-offset-4`,children:`Back to apps`})]})]}):(0,I.jsxs)(`div`,{className:`space-y-6 pb-24`,children:[(0,I.jsx)(cw,{title:o?.label??`Overview`,action:t===`overview`?(0,I.jsx)(qT,{value:i,onChange:a}):void 0}),s.data?.config_error?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`The stored configuration is invalid`}),(0,I.jsxs)(ks,{children:[s.data.config_error,`. The gateway rejects requests for this app until it is fixed.`]})]}):null,c?(0,I.jsx)(RT,{proxy:c.config.routing}):null,s.isPending||!c?(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(aw,{className:`h-32 w-full`}),(0,I.jsx)(aw,{className:`h-64 w-full`})]}):t===`overview`?(0,I.jsx)(xD,{appId:e,month:i,state:r}):t===`auth`?(0,I.jsx)(dD,{appId:e,level:n,state:r}):t===`proxy`?(0,I.jsx)(BD,{state:r}):t===`limits`?(0,I.jsx)(yD,{state:r}):t===`users`?(0,I.jsx)(WD,{appId:e}):t===`auth-events`?(0,I.jsx)(hE,{appId:e}):t===`settings`?(0,I.jsx)(HD,{appId:e,state:r}):(0,I.jsx)(v.Suspense,{fallback:(0,I.jsx)(aw,{className:`h-64 w-full`}),children:t===`usage`?(0,I.jsx)(GD,{appId:e}):(0,I.jsx)(KD,{appId:e,state:r})}),l?(0,I.jsx)(`div`,{className:`fixed inset-x-0 bottom-0 z-40 border-t bg-background/95 backdrop-blur`,children:(0,I.jsxs)(`div`,{className:`mx-auto flex max-w-7xl items-center gap-3 px-4 py-3 sm:px-6`,children:[(0,I.jsxs)(`span`,{className:`text-sm`,children:[(0,I.jsx)(`span`,{className:`mr-2 inline-block size-2 rounded-full bg-amber-500 align-middle`}),`Unsaved changes to `,(0,I.jsx)(`span`,{className:`font-medium`,children:c?.name??e})]}),(0,I.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,I.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:r.reset,disabled:r.saving,children:`Discard`}),(0,I.jsxs)(iw,{size:`sm`,reason:u??void 0,onClick:()=>void r.save(),disabled:r.saving,children:[r.saving?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Save changes`]})]})]})}):null]})}var JD=[{id:`ios`,label:`iOS application`,description:`Calls AI providers straight from the app.`,icon:Ua},{id:`server`,label:`Server`,description:`A backend you run, using a private API key.`,icon:La}],YD={basics:{id:`basics`,label:`Basics`},app_identity:{id:`app_identity`,label:`Application identity`,subtitle:`Application identity`,text:`Set your app's identity so that only this app can call AI providers through this gateway.`},users:{id:`users`,label:`User authentication`,subtitle:`User authentication`,text:`Choose whether only users signed in to your app can call AI through this gateway.`},identity_provider:{id:`identity_provider`,label:`Identity provider`,subtitle:`Identity provider`,text:`Where your users sign in. The gateway verifies their sign-in tokens against it.`},subscription:{id:`subscription`,label:`Subscription check`,subtitle:`Subscription check`,text:`Check that the user has paid for the app before they can call AI providers through this gateway.`}},XD=IE.find(e=>e.id===`none`);function ZD({trigger:e}={}){let{capabilities:t}=ox(),[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(0),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(void 0),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)(DE[0]),[x,S]=(0,v.useState)({}),[C,w]=(0,v.useState)(XD),[T,E]=(0,v.useState)({}),[ee,D]=(0,v.useState)(null),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(!1),[te,ne]=(0,v.useState)(!1),M=ht(),N=PS(),P=(0,v.useMemo)(()=>{let e=[YD.basics];return c===`ios`&&e.push(YD.app_identity),e.push(YD.users),g===`issuer`&&e.push(YD.identity_provider,YD.subscription),e},[c,g]),re=P[Math.min(i,P.length-1)],ie=i>=P.length-1,ae=(0,v.useMemo)(()=>TE(y,x),[y,x]),oe=LE(y,x)&&ae.jwks_url.startsWith(`https://`)&&ae.issuer.length>0&&ae.audience.length>0,F=(()=>{switch(re.id){case`basics`:return o.trim().length>0&&c!==null;case`app_identity`:return u.trim().length>0&&f.trim().length>0;case`users`:return g!==null;case`identity_provider`:return oe;case`subscription`:return LE(C,T)}})(),se=()=>{a(0),s(``),l(null),d(``),p(``),h(void 0),_(null),b(DE[0]),S({}),w(XD),E({})},ce=e=>{e&&se(),r(e)},le=e=>{e!==c&&(l(e),_(null))},ue=()=>{let e=g===`issuer`?{source:`issuer`,issuer:{provider:y.id,jwks_url:ae.jwks_url,issuer:ae.issuer,audience:ae.audience,user_id_claim:ae.user_id_claim,required_claims:EE(C,T),max_token_lifetime_seconds:86400,...C.id===`none`?{}:{entitlement:C.id}}}:null;return c===`ios`?{type:`apple_app_attest`,app_attest:{team_id:u.trim(),bundle_id:f.trim(),...m?.includes(`development`)?{environments:m}:{}},end_user:e??{source:`app_install`}}:e?{type:`api_key`,end_user:e}:g===`header`?{type:`api_key`,end_user:{source:`header`,header:iT}}:{type:`api_key`}},de=async()=>{if(c)try{let e=await N.mutateAsync({name:o.trim(),config:{authentication:ue(),routing:{providers:{mode:`all`},model_rewrites:{}},...c===`server`?{}:{limits:{per_user:{requests:{per_minute:10,per_day:300},spending:{monthly_usd:null}},per_app:{requests:{per_minute:null,per_day:null},spending:{monthly_usd:null}}}}},status:`active`});if(r(!1),c===`server`){if(!e.api_key)throw Error(`The app was created without its initial API key`);k(e.app.id),D(e.api_key),ne(!1),j(!0);return}U.success(`Created ${e.app.id}`),M(`/apps/${e.app.id}/proxy`)}catch(e){U.error(e instanceof Error?e.message:`Could not create the app`)}},fe=()=>{_(c===`ios`?`app_install`:`none`),a(P.findIndex(e=>e.id===`users`))},pe=()=>{if(ie){de();return}a(e=>e+1)},me=async()=>{if(ee)try{await navigator.clipboard.writeText(ee.key),ne(!0),U.success(`API key copied`)}catch{U.error(`Could not copy the API key`)}},he=()=>{j(!1),U.success(`Created ${O}`),M(`/apps/${O}/proxy`)};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(KE,{open:n,onOpenChange:ce,children:[(0,I.jsx)(qE,{asChild:!0,children:e??(0,I.jsxs)(iw,{size:`sm`,children:[(0,I.jsx)(Na,{className:`size-4`}),`New app`]})}),(0,I.jsxs)(XE,{className:`sm:max-w-2xl`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:`Create a new application`})}),(0,I.jsxs)(QE,{className:`space-y-6`,children:[re.subtitle?(0,I.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,I.jsx)(`h3`,{className:`text-base font-semibold`,children:re.subtitle}),re.text?(0,I.jsx)(`p`,{className:`text-sm text-pretty text-muted-foreground`,children:re.text}):null]}):null,re.id===`basics`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`app-name`,children:`Application name`}),(0,I.jsx)($,{id:`app-name`,value:o,placeholder:`Calorie Tracker`,maxLength:100,autoFocus:!0,onChange:e=>s(e.target.value)})]}),(0,I.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,I.jsx)(`legend`,{className:`text-sm font-medium`,children:`Application type`}),(0,I.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2`,role:`radiogroup`,children:JD.map(e=>{let t=e.icon,n=c===e.id;return(0,I.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,className:H(`group min-h-32 rounded-xl bg-background p-5 text-left shadow-sm ring-1 ring-border transition-[box-shadow,background-color] hover:bg-muted/40 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,n&&`bg-primary/[0.04] shadow-md ring-2 ring-primary`),onClick:()=>le(e.id),children:[(0,I.jsx)(`span`,{className:H(`mb-3 flex size-10 items-center justify-center rounded-lg bg-muted text-muted-foreground transition-[background-color,color]`,n&&`bg-primary text-primary-foreground`),children:(0,I.jsx)(t,{className:`size-5`})}),(0,I.jsx)(`span`,{className:`block text-sm font-semibold`,children:e.label}),(0,I.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-muted-foreground`,children:e.description})]},e.id)})})]})]}):null,re.id===`app_identity`?(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-team-id`,children:`Apple Team ID`}),(0,I.jsx)($,{id:`apple-team-id`,value:u,placeholder:`ABCDE12345`,className:`font-mono text-xs`,autoFocus:!0,onChange:e=>d(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In your Apple Developer account under`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/account#MembershipDetailsCard`,children:`Membership details`}),`.`]})]}),(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-bundle-id`,children:`Bundle ID`}),(0,I.jsx)($,{id:`apple-bundle-id`,value:f,placeholder:`com.example.calorietracker`,className:`font-mono text-xs`,onChange:e=>p(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In Xcode, on your target's`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/documentation/xcode/configuring-the-build-settings-of-a-target#Set-the-bundle-ID`,children:`Signing & Capabilities`}),` `,`tab.`]})]})]}),(0,I.jsx)(vE,{value:m,onChange:h,compact:!0})]}):null,re.id===`users`?(0,I.jsx)(yE,{label:`User authentication`,choices:c===`ios`?WE:GE,value:g,onChange:_}):null,re.id===`identity_provider`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(xE,{idPrefix:`issuer`,label:`Identity provider`,presets:DE,selected:y,values:x,compact:!0,onSelect:e=>{b(e),S({})},onValueChange:(e,t)=>S(n=>({...n,[e]:t}))}),(0,I.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Don't have these details yet?`,` `,(0,I.jsx)(`button`,{type:`button`,className:`font-medium text-primary-ink underline decoration-primary-ink/40 underline-offset-4 transition-colors hover:decoration-primary-ink`,onClick:fe,children:c===`ios`?`Allow unauthenticated users for now`:`Continue without user identity for now`}),` `,`and set this up later.`]})]}):null,re.id===`subscription`?(0,I.jsx)(xE,{idPrefix:`entitlement`,label:FE,presets:IE,selected:C,values:T,compact:!0,onSelect:e=>{w(e),E({})},onValueChange:(e,t)=>E(n=>({...n,[e]:t}))}):null]}),(0,I.jsxs)($E,{className:`items-center sm:justify-between`,children:[i>0?(0,I.jsxs)(Y,{variant:`ghost`,onClick:()=>a(e=>e-1),disabled:N.isPending,children:[(0,I.jsx)(Xi,{className:`size-4`}),`Back`]}):(0,I.jsx)(Y,{variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,I.jsx)(QD,{steps:P,current:i,onSelect:a}),(0,I.jsxs)(Y,{disabled:!F||N.isPending,onClick:pe,children:[N.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,ie?`Create app`:`Next`]})]})]})]}),(0,I.jsx)(KE,{open:A,onOpenChange:e=>{e||he()},children:(0,I.jsxs)(XE,{showCloseButton:!1,className:`sm:max-w-lg`,onEscapeKeyDown:e=>e.preventDefault(),children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{className:`text-balance`,children:`Your application is ready`})}),(0,I.jsxs)(QE,{className:`space-y-5`,children:[(0,I.jsxs)(tD,{className:`text-pretty`,children:[`This is the API key for`,` `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:O}),`. It is shown only once, so copy it now.`]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`created-api-key`,children:`API key`}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)($,{id:`created-api-key`,value:ee?.key??``,readOnly:!0,className:`font-mono text-xs`}),(0,I.jsxs)(Y,{type:`button`,variant:`outline`,className:`min-w-24`,onClick:()=>void me(),children:[te?(0,I.jsx)(ra,{className:`size-4`}):(0,I.jsx)(ha,{className:`size-4`}),te?`Copied`:`Copy`]})]})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:`Base URL`}),(0,I.jsxs)(`code`,{className:`block rounded-md bg-muted px-3 py-2 font-mono text-xs break-all text-muted-foreground`,children:[bD(t),`/v1/apps/`,(0,I.jsx)(`span`,{className:`text-foreground`,children:O}),`/proxy/{provider}/{provider_path}`]})]})]}),(0,I.jsx)($E,{children:(0,I.jsx)(Y,{onClick:he,children:`I’ve saved this key`})})]})})]})}function QD({steps:e,current:t,onSelect:n}){return(0,I.jsx)(`ol`,{className:`flex items-center gap-2`,"aria-label":`Steps`,children:e.map((e,r)=>{let i=r<t,a=r===t,o=(0,I.jsx)(`span`,{className:H(`block size-2 rounded-full transition-colors`,a?`bg-primary`:i?`bg-primary/40`:`bg-border`)});return(0,I.jsx)(`li`,{"aria-current":a?`step`:void 0,children:i?(0,I.jsx)(`button`,{type:`button`,"aria-label":`Back to ${e.label}`,className:`flex size-5 items-center justify-center rounded-full hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>n(r),children:o}):(0,I.jsx)(`span`,{className:`flex size-5 items-center justify-center`,"aria-label":`${e.label}${a?`, current step`:``}`,children:o})},e.id)})})}function $D({label:e,children:t}){return(0,I.jsxs)(Lb,{children:[(0,I.jsx)(Rb,{asChild:!0,children:(0,I.jsx)(Y,{variant:`ghost`,size:`icon-sm`,"aria-label":`Actions for ${e}`,children:(0,I.jsx)(_a,{})})}),(0,I.jsx)(zb,{align:`end`,className:`min-w-44`,children:t})]})}function eO({reason:e,destructive:t,onSelect:n,children:r}){let{readOnly:i}=ox(),a=(0,v.useId)(),o=e??(i?`Your role is read-only. Ask an owner or admin to make this change.`:void 0),s=t?`destructive`:`default`;return o?(0,I.jsx)(rw,{reason:o,reasonId:a,className:`w-full`,children:(0,I.jsx)(Bb,{variant:s,disabled:!0,"aria-describedby":a,className:`w-full`,children:r})}):(0,I.jsx)(Bb,{variant:s,onSelect:n,children:r})}var tO={"data-1p-ignore":`true`,"data-lpignore":`true`},nO={autoComplete:`off`,...tO},rO={type:`password`,autoComplete:`new-password`,spellCheck:!1,...tO};function iO(e){return Object.entries(e??{}).map(([e,t])=>({model:e,input:String(t.input),output:String(t.output)}))}function aO(e){let t={};for(let n of e){let e=n.model.trim(),r=n.input.trim(),i=n.output.trim();if(!e&&!r&&!i)continue;if(!e)return{error:`Every pricing row needs a model name`};if(!r||!i)return{error:`Enter both prices for ${e} — use 0 only if it is genuinely free`};let a=Number(r),o=Number(i);if(!Number.isFinite(a)||a<0||!Number.isFinite(o)||o<0)return{error:`Prices for ${e} must be numbers of 0 or more`};if(Object.hasOwn(t,e))return{error:`${e} is priced twice — remove the duplicate row`};t[e]={input:a,output:o}}return{pricing:t}}function oO(e,t){return e instanceof Error?e.message:t}var sO=e=>`gateway-${e}`,cO=`/providers/gateways`;function lO(e){if(e.referencedCount!==0)return e.providerCount===0?`Disabled provider instances still reference this gateway; delete them to release it`:e.referencedCount>e.providerCount?`Delete the active and disabled provider instances routed through this gateway first`:`Delete every active provider instance routed through this gateway first`}function uO({label:e,value:t}){return(0,I.jsxs)(`div`,{children:[e,`: `,(0,I.jsx)(`span`,{className:`font-mono text-xs`,children:t})]})}function dO({row:e,gateways:t}){if(e.providerGatewayId===null)return(0,I.jsxs)(`div`,{className:`space-y-0.5`,children:[e.secretHint===null?(0,I.jsx)(`div`,{children:`API key`}):(0,I.jsx)(uO,{label:`API key`,value:`…${e.secretHint}`}),e.baseUrl===null?null:(0,I.jsx)(uO,{label:`Base URL`,value:e.baseUrl})]});let n=t.find(t=>t.id===e.providerGatewayId);return n?(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[`Gateway:`,(0,I.jsx)(NT,{type:n.type}),(0,I.jsx)(Pn,{className:`text-primary-ink underline underline-offset-4`,to:`${cO}#${sO(n.id)}`,children:n.name})]}):(0,I.jsx)(I.Fragment,{children:`Gateway`})}function fO({gateway:e}){return(0,I.jsxs)(`div`,{className:`space-y-0.5`,children:[e.type===`cf_aig`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(uO,{label:`Account ID`,value:e.config.accountId}),(0,I.jsx)(uO,{label:`Gateway ID`,value:e.config.gatewayId})]}):null,(0,I.jsx)(uO,{label:`API key`,value:`…${e.secretHint}`})]})}var pO=[{slug:`providers`,path:`/providers`,Component:vO},{slug:`gateways`,path:cO,Component:OO}],mO=pO[0];function hO(){return(0,I.jsx)(Ib,{variant:`outline`,className:`border-muted-foreground/30 text-muted-foreground`,children:`disabled`})}function gO({slug:e,names:t}){return t.length===0?null:(0,I.jsxs)(`p`,{children:[(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:t.join(`, `)}),` `,t.length===1?`names`:`name`,` `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:e}),` in its configuration.`]})}function _O(){let{section:e}=_t(),t=e===void 0?mO:pO.find(t=>t.slug===e);return t?(0,I.jsx)(t.Component,{}):(0,I.jsx)(Vt,{to:mO.path,replace:!0})}function vO(){let{readOnly:e}=ox(),t=dS(),n=_S(),r=wS(),i=CS(),a=jS(yC()),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(null),g=t.data?.providers??[],_=n.data?.gateways??[],y=e=>(a.data?.apps??[]).filter(t=>t.referenced_providers.includes(e)).map(e=>e.name),b=async()=>{if(f)try{await r.mutateAsync(f.id),U.success(`Deleted ${f.name}`),p(null)}catch(e){U.error(oO(e,`Could not delete the provider`))}},x=async()=>{if(m)try{await i.mutateAsync({id:m.id,body:{status:`disabled`}}),U.success(`Disabled ${m.name}`),h(null)}catch(e){U.error(oO(e,`Could not disable the provider`))}},S=async e=>{try{await i.mutateAsync({id:e.id,body:{status:`active`}}),U.success(`Enabled ${e.name}`)}catch(e){U.error(oO(e,`Could not enable the provider`))}};return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Providers`,description:`Set up the AI providers your apps use.`,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>s(!0),children:[(0,I.jsx)(Na,{className:`size-4`}),`Add provider`]})}),t.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load providers`}),(0,I.jsx)(ks,{children:oO(t.error,`Unknown error`)})]}):null,(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Provider`}),(0,I.jsx)(Z,{children:`Slug`}),(0,I.jsx)(Z,{children:`Auth`}),(0,I.jsx)(Z,{className:`text-right`,children:`Actions`})]})}),(0,I.jsx)(lE,{children:t.isPending?[0,1,2].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,children:(0,I.jsx)(aw,{className:`h-5 w-full`})})},e)):g.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,className:`py-10 text-center text-sm text-muted-foreground`,children:`No providers yet. Add a key per provider, or route one through a gateway.`})}):g.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{className:`font-medium`,children:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.name,e.status===`disabled`?(0,I.jsx)(hO,{}):null]})}),(0,I.jsx)(Q,{children:(0,I.jsxs)(Ib,{variant:`secondary`,children:[(0,I.jsx)(MT,{type:e.type}),eT[e.type]]})}),(0,I.jsx)(Q,{className:`font-mono text-xs`,children:e.slug}),(0,I.jsx)(Q,{className:`text-sm text-muted-foreground`,children:(0,I.jsx)(dO,{row:e,gateways:_})}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsxs)($D,{label:e.name,children:[(0,I.jsxs)(Bb,{onSelect:()=>l(e),children:[(0,I.jsx)(da,{}),`Pricing`]}),(0,I.jsxs)(eO,{reason:e.providerGatewayId===null?void 0:`This instance authenticates with the gateway token — update the gateway's token instead`,onSelect:()=>d(e),children:[(0,I.jsx)(Pa,{}),`Update key`]}),(0,I.jsx)(Wb,{}),e.status===`disabled`?(0,I.jsxs)(eO,{onSelect:()=>void S(e),children:[(0,I.jsx)(fa,{}),`Enable provider`]}):(0,I.jsxs)(eO,{onSelect:()=>h(e),children:[(0,I.jsx)(pa,{}),`Disable provider`]}),(0,I.jsxs)(eO,{destructive:!0,onSelect:()=>p(e),children:[(0,I.jsx)(Ga,{}),`Delete provider`]})]})})]},e.id))})]})}),(0,I.jsx)(EO,{open:o,onOpenChange:s,providers:g,gateways:_}),(0,I.jsx)(MO,{provider:u,onClose:()=>d(null)},u?.id),(0,I.jsx)(NO,{provider:c,onClose:()=>l(null),readOnly:e}),(0,I.jsx)(VD,{open:f!==null,onOpenChange:e=>{e||p(null)},title:`Delete provider`,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`p`,{children:[`Apps using`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:f?eT[f.type]:``}),` `,`start failing within a minute, and any custom pricing on this provider is deleted with it.`]}),f?(0,I.jsx)(gO,{slug:f.slug,names:y(f.slug)}):null,(0,I.jsx)(`p`,{children:`This cannot be undone. Update the key instead if you only want to replace it, or disable the provider to pause it and keep the key.`})]}),confirmLabel:`Delete provider`,destructive:!0,pending:r.isPending,onConfirm:()=>void b()}),(0,I.jsx)(VD,{open:m!==null,onOpenChange:e=>{e||h(null)},title:`Disable provider`,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`p`,{children:[`Requests to`,` `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:m?.slug??``}),` start failing within a minute.`]}),m?(0,I.jsx)(gO,{slug:m.slug,names:y(m.slug)}):null]}),confirmLabel:`Disable provider`,pending:i.isPending,onConfirm:()=>void x()})]})}var yO=`__new__`,bO={works:{icon:la,className:`bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`},unconfirmed:{icon:xa,className:`bg-muted text-muted-foreground`},failed:{icon:ca,className:`bg-destructive/10 text-destructive`}};function xO(e){return e.reason===`unexpected_status`&&e.status!==void 0&&e.status<500&&e.status!==429}function SO(e,t,n){let r=eT[t],i=n?`The gateway`:r;switch(e.reason){case`no_probe`:return`There is no test call for ${r}, so nothing was checked. Add it if you know it is right.`;case`unreachable`:return`${i} did not answer in time, so nothing is proven either way.`;case`unexpected_status`:return xO(e)?n?`The gateway answered with HTTP ${e.status}. Check that it holds a stored key for ${r}.`:`${r} answered with HTTP ${e.status}, so this key could not be used.`:`${i} answered with HTTP ${e.status}, so nothing is proven either way.`;default:return`Nothing is proven either way. Add it if you know it is right.`}}function CO(e,t,n){if(e.validated)return{status:`works`,message:`Works. The provider accepted this credential.`};let r=SO(e,t,n);return xO(e)?{status:`failed`,message:r}:{status:`unconfirmed`,message:r}}function wO(e){if(e.validated)return{status:`works`,message:`Works. The gateway accepted this token.`};if(e.reason===`rejected`)return{status:`failed`,message:`The gateway refused this token (HTTP ${e.status}). Check the token itself, that authentication is turned on, and that the gateway holds a key for OpenAI.`};if(e.reason===`unreachable`)return{status:`unconfirmed`,message:`The gateway did not answer in time, so nothing is proven either way.`};let t=e.reason===`unexpected_status`?`The gateway answered with HTTP ${e.status}. Check the account and gateway IDs.`:`Nothing is proven either way. Add it if you know it is right.`;return{status:xO(e)?`failed`:`unconfirmed`,message:t}}function TO({outcome:e}){let{icon:t,className:n}=bO[e.status];return(0,I.jsxs)(`p`,{"aria-live":`polite`,className:H(`flex items-start gap-2 rounded-md px-3 py-2 text-xs`,n),children:[(0,I.jsx)(t,{className:`mt-px size-3.5 shrink-0`}),e.message]})}function EO({open:e,onOpenChange:t,providers:n,gateways:r}){let i=mS(),a=hS(),[o,s]=(0,v.useState)(`openai`),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(`key`),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(``),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(null),[ee,D]=(0,v.useState)(null),O=(0,v.useRef)(null),k=(0,v.useRef)(!1);(0,v.useEffect)(()=>{!k.current||!O.current||(k.current=!1,O.current.focus())});let A=r.filter(e=>e.status===`active`),j=T&&!A.some(e=>e.id===T.id)?[...A,T]:A,te=e=>n.some(t=>t.slug===e),ne=x||te(o),M=e=>{s(e),S(!1),D(null),te(e)?k.current=!0:b(``)},N=u===`key`?!!f:!!g,P=!!c.trim()&&N&&(!ne||!!y.trim()),re=()=>{s(`openai`),l(``),d(`key`),p(``),h(``),_(``),b(``),S(!1),E(null),D(null),i.reset(),a.reset()},ie=()=>{re(),t(!1)},ae=u===`key`&&m.trim()?{baseUrl:m.trim()}:{},oe=async()=>{if(N){D(null);try{let e=await a.mutateAsync({type:o,...u===`key`?{secret:f,...ae}:{providerGatewayId:g}});D(CO(e,o,u===`gateway`))}catch(e){D({status:`failed`,message:oO(e,`The credential could not be checked`)})}finally{a.reset()}}},F=async()=>{if(P)try{await i.mutateAsync({type:o,name:c.trim(),...y.trim()?{slug:y.trim()}:{},...u===`key`?{secret:f,...ae}:{providerGatewayId:g}}),ie(),U.success(`Added ${eT[o]}`)}catch(e){p(``),e instanceof ux&&e.code===`slug_taken`&&(S(!0),k.current=!0),U.error(oO(e,`Could not store the credential`))}};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(nD,{open:e,onOpenChange:e=>e?t(!0):ie(),title:`Add a provider`,submitLabel:`Add provider`,pending:i.isPending,disabled:!P,onSubmit:()=>void F(),secondaryAction:(0,I.jsxs)(Y,{type:`button`,variant:`secondary`,className:`sm:mr-auto`,disabled:!N||a.isPending,onClick:()=>void oe(),children:[a.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Test provider`]}),children:(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(sw,{label:`Name`,htmlFor:`provider-name`,hint:`How this provider is named in the list.`,children:(0,I.jsx)($,{id:`provider-name`,...nO,value:c,placeholder:`Prod OpenAI`,autoFocus:!0,onChange:e=>l(e.target.value)})}),(0,I.jsx)(sw,{label:`Provider`,htmlFor:`provider-type`,children:(0,I.jsxs)(zT,{value:o,onValueChange:e=>M(e),children:[(0,I.jsx)(VT,{id:`provider-type`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:$w.map(e=>(0,I.jsx)(UT,{value:e,children:(0,I.jsx)(FT,{type:e})},e))})]})}),(0,I.jsx)(sw,{label:`Authentication`,htmlFor:`provider-authentication`,hint:`Call the provider directly, or route through a gateway.`,children:(0,I.jsxs)(zT,{value:u,onValueChange:e=>{d(e),e===`gateway`&&h(``),D(null)},children:[(0,I.jsx)(VT,{id:`provider-authentication`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsxs)(UT,{value:`key`,children:[(0,I.jsx)(Sa,{}),`API key`]}),(0,I.jsxs)(UT,{value:`gateway`,children:[(0,I.jsx)(ta,{}),`Use gateway`]})]})]})}),u===`key`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(sw,{label:`API key`,htmlFor:`provider-secret`,children:(0,I.jsx)($,{id:`provider-secret`,...rO,value:f,placeholder:`sk-…`,onChange:e=>{p(e.target.value),D(null)}})}),(0,I.jsx)(sw,{label:`Base URL (optional)`,htmlFor:`provider-base-url`,hint:`Point this instance at an OpenAI-compatible endpoint you control — Azure OpenAI, vLLM, a proxy. HTTPS, port 443, no path-only tweaks beyond the base. Leave empty to use the provider's own API.`,children:(0,I.jsx)($,{id:`provider-base-url`,...nO,className:`font-mono`,value:m,placeholder:`https://my-vllm.example.com/v1/`,onChange:e=>{h(e.target.value),D(null)}})})]}):(0,I.jsx)(sw,{label:`Gateway`,htmlFor:`provider-gateway`,hint:`The provider's own key lives in that gateway; this row carries no secret.`,children:(0,I.jsxs)(zT,{value:g,onValueChange:e=>{if(e){if(e===yO){w(!0);return}_(e),D(null)}},children:[(0,I.jsx)(VT,{id:`provider-gateway`,className:`w-full`,children:(0,I.jsx)(BT,{placeholder:j.length?`Choose a gateway`:`No gateways yet`})}),(0,I.jsxs)(HT,{children:[j.map(e=>(0,I.jsx)(UT,{value:e.id,children:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,I.jsx)(NT,{type:e.type}),e.name]})},e.id)),j.length?(0,I.jsx)(WT,{}):null,(0,I.jsxs)(UT,{value:yO,className:`font-medium text-primary-ink focus:text-primary-ink`,children:[(0,I.jsx)(Na,{className:`size-4 text-primary-ink`}),`New gateway…`]})]})]})}),ne?(0,I.jsx)(sw,{label:`Slug`,htmlFor:`provider-slug`,hint:(0,I.jsxs)(I.Fragment,{children:[`Another instance already uses `,(0,I.jsx)(`code`,{className:`font-mono`,children:o}),`, so this one needs its own `,(0,I.jsx)(`code`,{className:`font-mono`,children:`/proxy/<slug>/…`}),` `,`segment.`]}),children:(0,I.jsx)($,{id:`provider-slug`,ref:O,...nO,className:`font-mono`,value:y,placeholder:`${o}-dev`,onChange:e=>b(e.target.value)})}):null,ee?(0,I.jsx)(TO,{outcome:ee}):null]})}),(0,I.jsx)(kO,{open:C,onOpenChange:w,onCreated:e=>{E(e),_(e.id)}})]})}function DO({label:e=`Add provider`}){let[t,n]=(0,v.useState)(!1),r=dS(),i=_S(t);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(iw,{size:`sm`,onClick:()=>n(!0),children:e}),(0,I.jsx)(EO,{open:t,onOpenChange:n,providers:r.data?.providers??[],gateways:i.data?.gateways??[]})]})}function OO(){let e=_S(),[t,n]=(0,v.useState)(!1),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),l=SS(),u=e.data?.gateways??[],d=e.isError?e.error:null,{hash:f}=dt();(0,v.useEffect)(()=>{f&&document.getElementById(f.slice(1))?.scrollIntoView({behavior:`smooth`,block:`center`})},[f,e.data]);let p=async()=>{if(s)try{await l.mutateAsync(s.id),U.success(`Deleted ${s.name}`),c(null)}catch(e){U.error(oO(e,`Could not delete the gateway`))}};return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Gateways`,description:`Set up the gateways you use to reach AI providers.`,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>n(!0),children:[(0,I.jsx)(Na,{className:`size-4`}),`Add gateway`]})}),d?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load gateways`}),(0,I.jsx)(ks,{children:oO(d,`Unknown error`)})]}):null,(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Type`}),(0,I.jsx)(Z,{children:`Auth`}),(0,I.jsx)(Z,{className:`text-right`,children:`Actions`})]})}),(0,I.jsx)(lE,{children:e.isPending?[0,1].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:4,children:(0,I.jsx)(aw,{className:`h-5 w-full`})})},e)):u.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:4,className:`py-10 text-center text-sm text-muted-foreground`,children:`No gateways yet. Add one to route providers through it.`})}):u.map(e=>(0,I.jsxs)(uE,{id:sO(e.id),children:[(0,I.jsx)(Q,{className:`font-medium`,children:e.name}),(0,I.jsx)(Q,{children:(0,I.jsxs)(Ib,{variant:`secondary`,children:[(0,I.jsx)(NT,{type:e.type}),tT[e.type]]})}),(0,I.jsx)(Q,{className:`text-sm text-muted-foreground`,children:(0,I.jsx)(fO,{gateway:e})}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsxs)($D,{label:e.name,children:[(0,I.jsxs)(eO,{onSelect:()=>o(e),children:[(0,I.jsx)(Pa,{}),`Update token`]}),(0,I.jsxs)(eO,{onSelect:()=>i(e),children:[(0,I.jsx)(ja,{}),`Rename`]}),(0,I.jsx)(Wb,{}),(0,I.jsxs)(eO,{destructive:!0,reason:lO(e),onSelect:()=>c(e),children:[(0,I.jsx)(Ga,{}),`Delete gateway`]})]})})]},e.id))})]})}),(0,I.jsx)(kO,{open:t,onOpenChange:n}),(0,I.jsx)(AO,{gateway:r,onClose:()=>i(null)}),(0,I.jsx)(jO,{gateway:a,onClose:()=>o(null)}),(0,I.jsx)(VD,{open:s!==null,onOpenChange:e=>{e||c(null)},title:`Delete gateway`,description:(0,I.jsxs)(`p`,{children:[`The stored token for`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:s?.name}),` is destroyed. Nothing routes through it, so no traffic changes.`]}),confirmLabel:`Delete gateway`,destructive:!0,pending:l.isPending,onConfirm:()=>void p()})]})}function kO({open:e,onOpenChange:t,onCreated:n}){let r=yS(),i=gS(),[a,o]=(0,v.useState)(nT[0].value),s=nT.find(e=>e.value===a)??nT[0],[c,l]=(0,v.useState)(s.defaultName),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(null),y=!!(m&&(!s.needsCloudflareIds||u.trim()&&f.trim())),b=!!c.trim()&&y,x=()=>{o(nT[0].value),l(nT[0].defaultName),d(``),p(``),h(``),_(null),r.reset(),i.reset()},S=async()=>{if(y){_(null);try{let e=await i.mutateAsync(s.value===`cf_aig`?{type:`cf_aig`,accountId:u.trim(),gatewayId:f.trim(),token:m}:{type:`vercel`,token:m});_(wO(e))}catch(e){_({status:`failed`,message:oO(e,`The connection could not be checked`)})}finally{i.reset()}}},C=e=>{let t=nT.find(t=>t.value===e);t&&(o(e),l(t.defaultName),d(``),p(``),h(``),_(null))},w=()=>{x(),t(!1)},T=async()=>{if(b)try{let e=await r.mutateAsync(s.value===`cf_aig`?{type:`cf_aig`,name:c.trim(),accountId:u.trim(),gatewayId:f.trim(),token:m}:{type:`vercel`,name:c.trim(),token:m});x(),U.success(`Added ${e.gateway.name}`),n?.(e.gateway),t(!1)}catch(e){h(``),U.error(oO(e,`Could not add the gateway`))}};return(0,I.jsx)(nD,{open:e,onOpenChange:e=>e?t(!0):w(),title:`Add gateway`,submitLabel:`Add gateway`,pending:r.isPending,disabled:!b,onSubmit:()=>void T(),secondaryAction:(0,I.jsxs)(Y,{type:`button`,variant:`secondary`,className:`sm:mr-auto`,disabled:!y||i.isPending,onClick:()=>void S(),children:[i.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Test gateway`]}),children:(0,I.jsxs)(`div`,{className:`space-y-4`,children:[nT.length>1?(0,I.jsx)(sw,{label:`Gateway type`,htmlFor:`gateway-type`,children:(0,I.jsxs)(zT,{value:a,onValueChange:e=>C(e),children:[(0,I.jsx)(VT,{id:`gateway-type`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:nT.map(e=>(0,I.jsx)(UT,{value:e.value,children:(0,I.jsx)(IT,{type:e.value})},e.value))})]})}):null,(0,I.jsx)(sw,{label:`Name`,htmlFor:`gateway-name`,children:(0,I.jsx)($,{id:`gateway-name`,...nO,value:c,onChange:e=>l(e.target.value)})}),s.needsCloudflareIds?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(sw,{label:`Cloudflare Account ID`,htmlFor:`gateway-account`,children:(0,I.jsx)($,{id:`gateway-account`,...nO,value:u,onChange:e=>{d(e.target.value),_(null)}})}),(0,I.jsx)(sw,{label:`Cloudflare Gateway ID`,htmlFor:`gateway-gateway`,children:(0,I.jsx)($,{id:`gateway-gateway`,...nO,value:f,onChange:e=>{p(e.target.value),_(null)}})})]}):null,(0,I.jsx)(sw,{label:`Gateway token`,htmlFor:`gateway-token`,hint:(0,I.jsx)(`a`,{className:`underline underline-offset-4`,href:s.tokenDocsUrl,target:`_blank`,rel:`noreferrer`,children:`How to create the token`}),children:(0,I.jsx)($,{id:`gateway-token`,...rO,value:m,onChange:e=>{h(e.target.value),_(null)}})}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:s.credentialNote}),g?(0,I.jsx)(TO,{outcome:g}):null]})})}function AO({gateway:e,onClose:t}){let n=bS(),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(null);e&&a!==e.id&&(o(e.id),i(e.name));let s=()=>{o(null),t()},c=async()=>{if(!(!e||!r.trim()))try{await n.mutateAsync({id:e.id,name:r.trim()}),U.success(`Renamed to ${r.trim()}`),s()}catch(e){U.error(oO(e,`Could not rename the gateway`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>e?void 0:s(),children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:`Rename gateway`})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{children:`Only the display name changes. Nothing about the connection or the providers routed through it moves.`}),(0,I.jsx)(sw,{label:`Name`,htmlFor:`gateway-rename`,children:(0,I.jsx)($,{id:`gateway-rename`,...nO,value:r,onChange:e=>i(e.target.value)})})]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(Y,{variant:`outline`,onClick:s,children:`Cancel`}),(0,I.jsxs)(Y,{disabled:!r.trim()||n.isPending,onClick:()=>void c(),children:[n.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Save name`]})]})]})})}function jO({gateway:e,onClose:t}){let n=xS(),r=gS(),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(null),c=()=>{a(``),s(null),n.reset(),r.reset(),t()},l=async()=>{if(!(!e||!i)){s(null);try{let t=await r.mutateAsync(e.type===`cf_aig`?{type:`cf_aig`,accountId:e.config.accountId,gatewayId:e.config.gatewayId,token:i}:{type:`vercel`,token:i});s(wO(t))}catch(e){s({status:`failed`,message:oO(e,`The connection could not be checked`)})}finally{r.reset()}}},u=async()=>{if(!(!e||!i))try{await n.mutateAsync({id:e.id,token:i}),a(``),s(null),n.reset(),U.success(`Updated the token for ${e.name}`),t()}catch(e){a(``),U.error(oO(e,`Could not update the gateway token`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>e?void 0:c(),children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsxs)(eD,{children:[`Update the token for `,e?.name]})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsxs)(tD,{children:[`One token authenticates every provider routed through this gateway, so all`,` `,e?.providerCount??0,` of them pick the new one up within a minute.`]}),(0,I.jsx)(sw,{label:`New gateway token`,htmlFor:`gateway-rotate-token`,children:(0,I.jsx)($,{id:`gateway-rotate-token`,...rO,value:i,onChange:e=>{a(e.target.value),s(null)}})}),o?(0,I.jsx)(TO,{outcome:o}):null]}),(0,I.jsxs)($E,{children:[(0,I.jsxs)(Y,{type:`button`,variant:`secondary`,className:`sm:mr-auto`,disabled:!i||r.isPending,onClick:()=>void l(),children:[r.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Test token`]}),(0,I.jsx)(Y,{variant:`outline`,onClick:c,children:`Cancel`}),(0,I.jsxs)(Y,{disabled:!i||n.isPending,onClick:()=>void u(),children:[n.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Update token`]})]})]})})}function MO({provider:e,onClose:t}){let n=CS(),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(e?.baseUrl??``),s=()=>{i(``),n.reset(),t()},c=a.trim(),l=e&&c!==(e.baseUrl??``)?{baseUrl:c===``?null:c}:{},u=async()=>{if(!(!e||!r))try{await n.mutateAsync({id:e.id,body:{secret:r,...l}}),i(``),n.reset(),U.success(`Updated the key for ${e.name}`),t()}catch(e){i(``),U.error(oO(e,`Could not update the credential`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>e?void 0:s(),children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsxs)(eD,{children:[`Update the key for `,e?.name]})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{children:`The new credential replaces the old one in place. Custom pricing is kept, and requests pick it up within a minute.`}),(0,I.jsx)(sw,{label:`New API key`,htmlFor:`rotate-secret`,children:(0,I.jsx)($,{id:`rotate-secret`,...rO,value:r,onChange:e=>i(e.target.value)})}),(0,I.jsx)(sw,{label:`Base URL`,htmlFor:`rotate-base-url`,hint:`Changing the origin needs the key above, because the stored key is never sent to a new origin. Leave empty to use the provider's own API.`,children:(0,I.jsx)($,{id:`rotate-base-url`,...nO,className:`font-mono`,value:a,placeholder:`https://my-vllm.example.com/v1/`,onChange:e=>o(e.target.value)})})]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(Y,{variant:`outline`,onClick:s,children:`Cancel`}),(0,I.jsxs)(Y,{disabled:!r||n.isPending,onClick:()=>void u(),children:[n.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Update key`]})]})]})})}function NO({provider:e,onClose:t,readOnly:n}){let r=CS(),[i,a]=(0,v.useState)([]),[o,s]=(0,v.useState)(null);e&&o!==e.id&&(s(e.id),a(iO(e.pricing)));let c=(e,t)=>{a(n=>n.map((n,r)=>r===e?{...n,...t}:n))},l=async()=>{if(!e)return;let n=aO(i);if(`error`in n){U.error(n.error);return}try{await r.mutateAsync({id:e.id,body:{pricing:Object.keys(n.pricing).length?n.pricing:null}}),U.success(`Updated pricing for ${e.name}`),t()}catch(e){U.error(oO(e,`Could not save the pricing`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>{e||(s(null),t())},children:(0,I.jsxs)(XE,{className:`sm:max-w-2xl`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:`Custom model pricing`})}),(0,I.jsxs)(QE,{className:`space-y-3`,children:[(0,I.jsxs)(tD,{children:[`For models the built-in catalog does not cover, or prices it in a way you disagree with.`,e&&Qw(e.type)?` ${eT[e.type]??e.type} reports the cost of
|
|
75
|
+
`,Fw=[`openai`,`anthropic`,`xai`,`gemini`,`perplexity`,`deepseek`,`groq`,`mistral`,`together`,`fireworks`,`cerebras`,`moonshot`,`huggingface`,`baseten`,`bytedance`,`openrouter`],Iw=[`responses`,`chat_completions`,`anthropic_messages`,`gemini_native`,`audio_transcription`,`other`],Lw={responses:`v1/responses`,chat_completions:`v1/chat/completions`,anthropic_messages:`v1/messages`,gemini_native:`v1beta/models/{model}:generateContent`,audio_transcription:`v1/audio/transcriptions`},Rw=[`responses`,`transcription`],zw={responses:`responses`,transcription:`audio_transcription`},Bw=[`responses`,`chat_completions`,`gemini_native`,`anthropic`,`none`],Vw={apiStyles:Iw,endpointStyles:[]},Hw={openai:{apiStyles:Iw,endpointStyles:[`responses`,`transcription`]},xai:{apiStyles:Iw,endpointStyles:[`responses`,`transcription`]},openrouter:{apiStyles:[`chat_completions`],endpointStyles:[]}};function Uw(e){return Hw[e]??Vw}var Ww=Fw.filter(e=>Uw(e).endpointStyles.length>0);function Gw(e){return Ww.filter(t=>Uw(t).endpointStyles.includes(e))}var Kw={openai:{slug:`openai`,stripPathPrefix:`v1/`},anthropic:{slug:`anthropic`},xai:{slug:`grok`},gemini:{slug:`google-ai-studio`},perplexity:{slug:`perplexity-ai`}},qw=[`responses`,`chat_completions`,`anthropic_messages`],Jw=[`responses`];function Yw(e){return{modelPrefix:e,apiStyles:qw,endpointStyles:Jw}}var Xw={cf_aig:Kw,vercel:{openai:Yw(`openai/`),anthropic:Yw(`anthropic/`),gemini:Yw(`google/`),xai:Yw(`spacexai/`),perplexity:Yw(`perplexity/`),deepseek:Yw(`deepseek/`),moonshot:Yw(`moonshotai/`)}},Zw=[`openrouter`];function Qw(e){return Zw.includes(e)}var $w=Fw,eT={openai:`OpenAI`,anthropic:`Anthropic`,xai:`xAI`,gemini:`Gemini`,perplexity:`Perplexity`,deepseek:`DeepSeek`,groq:`Groq`,mistral:`Mistral`,together:`Together AI`,fireworks:`Fireworks AI`,cerebras:`Cerebras`,moonshot:`Moonshot AI`,huggingface:`Hugging Face`,baseten:`Baseten`,bytedance:`ByteDance Ark`,openrouter:`OpenRouter`},tT={cf_aig:`Cloudflare AI Gateway`,vercel:`Vercel AI Gateway`},nT=[{value:`cf_aig`,label:tT.cf_aig,defaultName:`Our CF gateway`,tokenDocsUrl:`https://developers.cloudflare.com/ai-gateway/configuration/authentication/`,needsCloudflareIds:!0,credentialNote:`Requests use the provider keys stored in your Cloudflare AI Gateway's own key store.`},{value:`vercel`,label:tT.vercel,defaultName:`Our Vercel gateway`,tokenDocsUrl:`https://vercel.com/docs/ai-gateway/authentication-and-byok/api-keys`,needsCloudflareIds:!1,credentialNote:`Your provider credential stored in Vercel is preferred. Vercel may fall back to system credentials.`}],rT=Bw,iT=`x-end-user-id`;function aT(e,t){let n=Object.keys(t?.[e.type]??{}),r=Object.keys(e.pricing??{});return[...n,...r.filter(e=>!n.includes(e))]}var oT=Gw;function sT(e,t,n){let r=oT(e);return t.filter(t=>r.includes(t.type)&&(n?.(t,e)??!0))}var cT=/^[a-z0-9-]{1,64}$/,lT=e=>e.end_user?.source===`issuer`?e.end_user.issuer:void 0;function uT(){return{provider:`firebase`,jwks_url:``,issuer:``,audience:``,user_id_claim:`sub`,required_claims:[],max_token_lifetime_seconds:86400}}function dT(e,t){if(e.type===`apple_app_attest`)return{...e,end_user:{source:`issuer`,issuer:t??lT(e)??uT()}};if(!t){let{end_user:t,...n}=e;return n}return{...e,end_user:{source:`issuer`,issuer:t}}}var fT=e=>typeof e==`string`?{path:e}:e;function pT(e){return!e.fixed_model&&(!e.clamp||e.clamp===void 0)?e.path:{path:e.path,...e.fixed_model?{fixed_model:e.fixed_model}:{},...e.clamp?{clamp:e.clamp}:{}}}function mT(){return{allowed_paths:[],allowed_models:[]}}function hT(e=`openai`){return{api_style:`responses`,provider:e,model:``}}function gT(e,t=`endpoint`){if(e[t]===void 0)return t;for(let n=2;n<1e3;n+=1){let r=`${t}-${n}`;if(e[r]===void 0)return r}return`${t}-${Date.now()}`}function _T(e,t,n){return Object.fromEntries(Object.entries(e).map(([e,r])=>[e===t?n:e,r]))}function vT(e,t,n){return cT.test(e)?e!==n&&t[e]!==void 0?`Another endpoint already uses this slug`:null:`Use 1-64 characters from a-z, 0-9, and -`}function yT(e){return e.providers.mode}function bT(e){if(yT(e)===`all`)return[];let t=e.providers.selected??{};return Object.keys(t).filter(e=>t[e]!==void 0)}function xT(e){return $w.includes(e)}function ST(e){return Object.hasOwn(tT,e)}function CT(e,t){if(yT(e)===`all`)return[...$w];let n=new Map(t.map(e=>[e.slug,e.type])),r=new Set(bT(e).flatMap(e=>{let t=n.get(e);return t?[t]:xT(e)?[e]:[]}));return $w.filter(e=>r.has(e))}var wT=`size-full text-current`;function TT(e){return e.trim().replace(`<svg`,`<svg class="${wT}"`)}function ET(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,TT(t)]))}var DT=ET({openai:Dw,anthropic:dw,xai:Pw,gemini:Sw,perplexity:kw,deepseek:yw,groq:Cw,mistral:Tw,together:Mw,fireworks:xw,cerebras:gw,moonshot:Ew,huggingface:ww,baseten:mw,bytedance:hw,openrouter:Ow}),OT=ET({cf_aig:_w,vercel:Nw}),kT=ET({firebase:bw,supabase:jw,auth0:pw,clerk:vw,apple:fw,revenuecat:Aw});function AT(e){return Object.hasOwn(kT,e)}function jT({svg:e,className:t}){return(0,I.jsx)(`span`,{"aria-hidden":!0,className:H(`inline-flex size-[1.15em] shrink-0`,t),dangerouslySetInnerHTML:{__html:e}})}function MT({type:e,className:t}){return(0,I.jsx)(jT,{svg:DT[e],className:t})}function NT({type:e,className:t}){return(0,I.jsx)(jT,{svg:OT[e],className:t})}function PT({type:e,className:t}){return(0,I.jsx)(jT,{svg:kT[e],className:t})}function FT({type:e,className:t}){return(0,I.jsxs)(`span`,{className:H(`inline-flex items-center gap-1.5`,t),children:[(0,I.jsx)(MT,{type:e}),eT[e]]})}function IT({type:e,className:t}){return(0,I.jsxs)(`span`,{className:H(`inline-flex items-center gap-1.5`,t),children:[(0,I.jsx)(NT,{type:e}),tT[e]]})}function LT(e,t){if(yT(e)===`all`)return[];let n=t.filter(e=>e.status===`active`),r=new Set(n.map(e=>e.type));return CT(e,n).filter(e=>!r.has(e))}function RT({proxy:e}){let t=dS();if(!t.data)return null;let n=LT(e,t.data.providers);return n.length===0?null:(0,I.jsxs)(Ds,{children:[(0,I.jsx)(ca,{}),(0,I.jsxs)(Os,{children:[`No credential for`,` `,n.map((e,t)=>(0,I.jsxs)(v.Fragment,{children:[t>0?`, `:null,(0,I.jsx)(FT,{type:e,className:`align-middle`})]},e))]}),(0,I.jsxs)(ks,{children:[`This app allows`,` `,n.length===1?`a provider`:`providers`,` you have not configured, so those requests fail with `,(0,I.jsx)(`code`,{className:`font-mono text-xs`,children:`provider_not_configured`}),`.`,` `,(0,I.jsx)(Pn,{to:`/providers`,className:`text-primary-ink underline underline-offset-4`,children:`Add a provider key`}),`.`]})]})}function zT({...e}){return(0,I.jsx)(mv,{"data-slot":`select`,...e})}function BT({...e}){return(0,I.jsx)(vv,{"data-slot":`select-value`,...e})}function VT({className:e,size:t=`default`,children:n,...r}){return(0,I.jsxs)(gv,{"data-slot":`select-trigger`,"data-size":t,className:H(`flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground`,e),...r,children:[n,(0,I.jsx)(yv,{asChild:!0,children:(0,I.jsx)(ia,{className:`size-4 opacity-50`})})]})}function HT({className:e,children:t,position:n=`item-aligned`,align:r=`center`,...i}){return(0,I.jsx)(Sv,{children:(0,I.jsxs)(wv,{"data-slot":`select-content`,className:H(`relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,align:r,...i,children:[(0,I.jsx)(GT,{}),(0,I.jsx)(Iv,{className:H(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1`),children:t}),(0,I.jsx)(KT,{})]})})}function UT({className:e,children:t,...n}){return(0,I.jsxs)(Hv,{"data-slot":`select-item`,className:H(`relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2`,e),...n,children:[(0,I.jsx)(`span`,{"data-slot":`select-item-indicator`,className:`absolute right-2 flex size-3.5 items-center justify-center`,children:(0,I.jsx)(Kv,{children:(0,I.jsx)(ra,{className:`size-4`})})}),(0,I.jsx)(Wv,{children:t})]})}function WT({className:e,...t}){return(0,I.jsx)(Qv,{"data-slot":`select-separator`,className:H(`pointer-events-none -mx-1 my-1 h-px bg-border`,e),...t})}function GT({className:e,...t}){return(0,I.jsx)(Jv,{"data-slot":`select-scroll-up-button`,className:H(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(oa,{className:`size-4`})})}function KT({className:e,...t}){return(0,I.jsx)(Xv,{"data-slot":`select-scroll-down-button`,className:H(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(ia,{className:`size-4`})})}function qT({value:e,onChange:t,months:n=12}){let r=CC(n);return(0,I.jsxs)(zT,{value:e,onValueChange:t,children:[(0,I.jsx)(VT,{className:`w-[180px]`,size:`sm`,"aria-label":`Month`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:r.map(e=>(0,I.jsx)(UT,{value:e,children:SC(e)},e))})]})}var JT=[{value:`7`,label:`Last 7 days`},{value:`30`,label:`Last 30 days`},{value:`90`,label:`Last 90 days`}];function YT({value:e,onChange:t}){return(0,I.jsxs)(zT,{value:e,onValueChange:t,children:[(0,I.jsx)(VT,{className:`w-[150px]`,size:`sm`,"aria-label":`Date range`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:JT.map(e=>(0,I.jsx)(UT,{value:e.value,children:e.label},e.value))})]})}function XT(e){return{name:e.name,config:e.config,status:e.status}}var ZT=e=>e;function QT(e){let t=MS(e),n=NS(e),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),d=(0,v.useRef)(null),f=t.data?.app;(0,v.useEffect)(()=>{if(!f||l===e&&r!==null&&a!==null&&JSON.stringify(r)!==a)return;let t=XT(f);d.current=lT(t.config.authentication)??null,i(t),o(JSON.stringify(t)),c(f.revision),u(e)},[e,f]);let p=l===e?r:null,m=l===e?a:null,h=p!==null&&m!==null&&JSON.stringify(p)!==m,g=(0,v.useCallback)(e=>{i(t=>t&&{...t,...e})},[]),_=(0,v.useCallback)(e=>{i(t=>t&&{...t,config:{...t.config,...e}})},[]);return{query:t,draft:p,dirty:h,update:g,updateConfig:_,updateAuthentication:(0,v.useCallback)(e=>{_({authentication:e})},[_]),updateIssuer:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let n=t.config.authentication,r=lT(n)??(n.type===`apple_app_attest`?uT():void 0);return r?{...t,config:{...t.config,authentication:dT(n,{...r,...e})}}:t})},[]),setEndUserSource:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let n=t.config.authentication,r=lT(n);r&&(d.current=r);let i=e===`issuer`?dT(n,r??d.current??uT()):e===`app_install`?n.type===`apple_app_attest`?{...n,end_user:{source:`app_install`}}:n:e===`header`?n.type===`api_key`?{...n,end_user:{source:`header`,header:n.end_user?.source===`header`?n.end_user.header:iT}}:n:dT(n,void 0),a=i.type!==`api_key`||i.end_user!==void 0||t.config.limits===void 0?t.config:{...t.config,limits:{...t.config.limits,per_user:{requests:{per_minute:null,per_day:null},spending:{monthly_usd:null}}}};return{...t,config:{...a,authentication:i}}})},[]),updateEndUserHeader:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let n=t.config.authentication;return n.type!==`api_key`||n.end_user?.source!==`header`?t:{...t,config:{...t.config,authentication:{...n,end_user:{source:`header`,header:e}}}}})},[]),updateProxy:(0,v.useCallback)(e=>{i(t=>t&&{...t,config:{...t.config,routing:{...t.config.routing,...e}}})},[]),updateLimits:(0,v.useCallback)(e=>_({limits:e}),[_]),updateEndpoints:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let{endpoints:n,...r}=t.config;return{...t,config:Object.keys(e).length===0?r:{...r,endpoints:e}}})},[]),reset:(0,v.useCallback)(()=>{if(!m)return;let e=JSON.parse(m);d.current=lT(e.config.authentication)??null,i(e)},[m]),save:(0,v.useCallback)(async()=>{if(!p||s===null)return!1;try{let e=await n.mutateAsync({body:ZT(p),revision:s});return c(e.app.revision),o(JSON.stringify(p)),U.success(`Configuration saved`,{description:`The gateway picks it up within the 60 second config cache TTL.`}),!0}catch(e){return U.error(`Save rejected`,{description:e instanceof Error?e.message:`Unknown error`}),!1}},[p,s,n]),saving:n.isPending}}function $T(e){let t=e=>Array.isArray(e)?e.length>0&&e.every(Boolean):!!e;return(e.jwks_url??``).startsWith(`https://`)&&t(e.issuer)&&t(e.audience)}function eE(e){return e.path.trim()?e.equals===void 0?Array.isArray(e.contains)?e.contains.length>0&&e.contains.every(e=>e.trim().length>0):!!e.contains?.trim():String(e.equals).length>0:!1}function tE(e){let t=e.config.authentication;if(!e.name.trim())return`Give the app a name.`;if(t.type===`apple_app_attest`){let{team_id:e,bundle_id:n}=t.app_attest;if(!e.trim()||!n.trim())return`Enter the Apple Team ID and Bundle ID.`}if(t.type===`api_key`&&t.end_user?.source===`header`&&!t.end_user.header.trim())return`Enter the header name.`;let n=lT(t);if(n){if(!$T(n))return`Finish the identity provider details.`;if(!(n.required_claims??[]).every(eE))return`Finish the subscription check.`}return null}function nE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card`,className:H(`flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm`,e),...t})}function rE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-header`,className:H(`@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6`,e),...t})}function iE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-title`,className:H(`leading-none font-semibold`,e),...t})}function aE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-description`,className:H(`text-sm text-muted-foreground`,e),...t})}function oE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-content`,className:H(`px-6`,e),...t})}function sE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,I.jsx)(`table`,{"data-slot":`table`,className:H(`w-full caption-bottom text-sm [--table-inset:1.5rem]`,`[&_tr>*:first-child]:pl-(--table-inset) [&_tr>*:last-child]:pr-(--table-inset)`,e),...t})})}function cE({className:e,...t}){return(0,I.jsx)(`thead`,{"data-slot":`table-header`,className:H(`[&_tr]:border-b`,e),...t})}function lE({className:e,...t}){return(0,I.jsx)(`tbody`,{"data-slot":`table-body`,className:H(`[&_tr:last-child]:border-0`,e),...t})}function uE({className:e,...t}){return(0,I.jsx)(`tr`,{"data-slot":`table-row`,className:H(`border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted`,e),...t})}function Z({className:e,...t}){return(0,I.jsx)(`th`,{"data-slot":`table-head`,className:H(`h-11 px-3 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function Q({className:e,...t}){return(0,I.jsx)(`td`,{"data-slot":`table-cell`,className:H(`px-3 py-2.5 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function dE({label:e,value:t,detail:n}){return(0,I.jsx)(nE,{className:`gap-0 py-4`,children:(0,I.jsxs)(oE,{className:`px-4`,children:[(0,I.jsx)(`p`,{className:`text-xs font-medium tracking-wide text-muted-foreground uppercase`,children:e}),(0,I.jsx)(`p`,{className:`tabular mt-1.5 text-2xl leading-none font-semibold`,children:t}),n?(0,I.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:n}):null]})})}function fE(e){return e==null?`—`:e<1e3?`${Math.round(e)} ms`:e<6e4?`${(e/1e3).toFixed(1)} s`:e<36e5?`${Math.round(e/6e4)} min`:`${(e/36e5).toFixed(1)} h`}function pE(e){let t=new Map,n=(e,n,r,i,a)=>{let o=t.get(e)??{outcome:n,reason:r,days:new Map};o.days.set(i,(o.days.get(i)??0)+a),t.set(e,o)};for(let t of e?.daily??[])t.outcome!==`ok`&&n(`auth:${t.outcome}:${t.reason??``}`,t.outcome,t.reason,t.date,t.count);for(let t of e?.usage_failures??[])n(`proxy:${t.status}`,t.status,`proxied request`,t.date,t.count);return[...t.values()].map(e=>({outcome:e.outcome,reason:e.reason,total:[...e.days.values()].reduce((e,t)=>e+t,0),days:[...e.days.entries()].map(([e,t])=>({date:e,count:t})).sort((e,t)=>e.date<t.date?-1:+(e.date>t.date))})).sort((e,t)=>t.total-e.total||(e.outcome<t.outcome?-1:+(e.outcome>t.outcome)))}var mE=[`issuer_claims_missing`,`issuer_token_rejected`,`issuer_verification_unavailable`,`attest_failed`,`auth_required`,`ok`];function hE({appId:e}){let[t,n]=(0,v.useState)(`30`),[r,i]=(0,v.useState)(`all`),[a,o]=(0,v.useState)([]),s=GS(e,Number(t)),c=KS(e,{limit:25,outcome:r===`all`?void 0:r,before_id:a.at(-1)}),l=(0,v.useMemo)(()=>pE(s.data),[s.data]),u=s.data?.claim_delay,d=s.data?.pending_users??0;return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,I.jsx)(dE,{label:`Exchange success`,value:uC(s.data?.token_exchange.success_rate),detail:`${cC(s.data?.token_exchange.total??0)} attempts`}),(0,I.jsx)(dE,{label:`Claim delay p50`,value:fE(u?.p50_ms),detail:`${cC(u?.count??0)} measured`}),(0,I.jsx)(dE,{label:`Claim delay p95`,value:fE(u?.p95_ms),detail:`avg ${fE(u?.avg_ms)}`}),(0,I.jsx)(dE,{label:`Pending activations`,value:cC(d),detail:d>0?`waiting on a claim now`:`none waiting`})]}),(0,I.jsxs)(nE,{className:`py-0`,children:[(0,I.jsx)(rE,{className:`pt-6`,children:(0,I.jsx)(lw,{title:`Failures by cause`,description:`Refused authentication attempts and non-ok proxied requests, busiest first.`,action:(0,I.jsx)(YT,{value:t,onChange:n})})}),(0,I.jsx)(oE,{className:`px-0 pb-0`,children:s.isPending?(0,I.jsx)(`div`,{className:`px-6 pb-6`,children:(0,I.jsx)(aw,{className:`h-24 w-full`})}):l.length===0?(0,I.jsx)(`div`,{className:`px-6 pb-6`,children:(0,I.jsx)(uw,{children:`No failed requests in this range.`})}):(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`Outcome`}),(0,I.jsx)(Z,{children:`Reason`}),(0,I.jsx)(Z,{className:`text-right`,children:`Count`}),(0,I.jsx)(Z,{className:`text-right`,children:`Days affected`}),(0,I.jsx)(Z,{children:`Last seen`})]})}),(0,I.jsx)(lE,{children:l.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{children:(0,I.jsx)(eC,{outcome:e.outcome})}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.reason??`—`}),(0,I.jsx)(Q,{className:`tabular text-right`,children:cC(e.total)}),(0,I.jsx)(Q,{className:`tabular text-right`,children:cC(e.days.length)}),(0,I.jsx)(Q,{className:`text-xs whitespace-nowrap text-muted-foreground`,children:e.days.at(-1)?.date??`—`})]},`${e.outcome}-${e.reason??``}`))})]})})]}),(0,I.jsxs)(nE,{className:`py-0`,children:[(0,I.jsx)(rE,{className:`pt-6`,children:(0,I.jsx)(lw,{title:`Recent attempts`,description:`Every token exchange and key registration, newest first.`,action:(0,I.jsxs)(zT,{value:r,onValueChange:e=>{i(e),o([])},children:[(0,I.jsx)(VT,{className:`w-[210px]`,size:`sm`,"aria-label":`Outcome`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`all`,children:`All outcomes`}),mE.map(e=>(0,I.jsx)(UT,{value:e,children:e},e))]})]})})}),(0,I.jsxs)(oE,{className:`px-0 pb-0`,children:[(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`When`}),(0,I.jsx)(Z,{children:`User`}),(0,I.jsx)(Z,{children:`Call`}),(0,I.jsx)(Z,{children:`Outcome`}),(0,I.jsx)(Z,{children:`Reason`}),(0,I.jsx)(Z,{children:`App version`}),(0,I.jsx)(Z,{className:`text-right`,children:`Latency`}),(0,I.jsx)(Z,{className:`text-right`,children:`Claim delay`})]})}),(0,I.jsx)(lE,{children:c.isPending?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:8,children:(0,I.jsx)(aw,{className:`h-8 w-full`})})}):c.data?.events.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:8,className:`py-8 text-center text-sm text-muted-foreground`,children:`No attempts.`})}):c.data?.events.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{className:`text-xs whitespace-nowrap text-muted-foreground`,children:mC(e.created_at)}),(0,I.jsx)(Q,{className:`font-mono text-xs`,children:e.user_id??(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:`unknown`})}),(0,I.jsxs)(Q,{className:`font-mono text-xs text-muted-foreground`,children:[e.event,e.auth_method?(0,I.jsx)(`span`,{className:`block`,children:e.auth_method}):null]}),(0,I.jsx)(Q,{children:(0,I.jsx)(eC,{outcome:e.outcome})}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.reason??`—`}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.app_version??`—`}),(0,I.jsx)(Q,{className:`tabular text-right text-xs`,children:e.latency_ms===null?`—`:`${cC(e.latency_ms)} ms`}),(0,I.jsx)(Q,{className:`tabular text-right text-xs`,children:e.claim_delay_ms===null?`—`:(0,I.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,title:`This exchange ended a wait for an entitlement claim to propagate.`,children:fE(e.claim_delay_ms)})})]},e.id))})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t px-6 py-3`,children:[(0,I.jsx)(Y,{variant:`outline`,size:`sm`,disabled:a.length===0,onClick:()=>o(e=>e.slice(0,-1)),children:`Newer`}),(0,I.jsx)(Y,{variant:`outline`,size:`sm`,disabled:!c.data?.next_before_id,onClick:()=>o(e=>[...e,c.data.next_before_id]),children:`Older`})]})]})]})]})}function $({className:e,type:t,...n}){return(0,I.jsx)(`input`,{type:t,"data-slot":`input`,className:H(`h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30`,`focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,`aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40`,e),...n})}function gE({className:e,...t}){return(0,I.jsx)(jf,{"data-slot":`checkbox`,className:H(`peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary`,e),...t,children:(0,I.jsx)(Nf,{"data-slot":`checkbox-indicator`,className:`grid place-content-center text-current transition-none`,children:(0,I.jsx)(ra,{className:`size-3.5`})})})}var _E=[{value:`production`,label:`Production`,hint:`Builds signed for TestFlight and the App Store.`},{value:`development`,label:`Development`,hint:`Builds run from Xcode, which attest in Apple's development environment.`}];function vE({value:e,onChange:t,compact:n=!1,disabled:r=!1}){let i=e??[`production`],a=i.includes(`development`),o=(e,n)=>{let r=_E.map(e=>e.value).filter(t=>t===e?n:i.includes(t));r.length!==0&&t(r)};return(0,I.jsx)(sw,{label:`iOS app environment`,hint:n?void 0:`Which of Apple's two environments this app accepts attestations from. Removing one also stops the keys it already registered.`,children:(0,I.jsxs)(`div`,{className:`space-y-2`,children:[_E.map(e=>{let t=i.includes(e.value);return(0,I.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,I.jsx)(gE,{id:`env-${e.value}`,checked:t,disabled:r||t&&i.length===1,onCheckedChange:t=>o(e.value,t===!0)}),(0,I.jsxs)(`div`,{className:`-mt-0.5`,children:[(0,I.jsx)(ow,{htmlFor:`env-${e.value}`,className:`text-sm font-normal`,children:e.label}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]})]},e.value)}),a&&!n?(0,I.jsxs)(`p`,{className:`flex items-start gap-2 rounded-md bg-amber-500/[0.08] p-2.5 text-xs leading-relaxed text-amber-700 dark:text-amber-400`,children:[(0,I.jsx)(Ka,{className:`mt-0.5 size-3.5 shrink-0`}),(0,I.jsx)(`span`,{children:`Any device carrying your team's provisioning profile can attest against this app. Keep this on a development bundle id rather than the one you ship.`})]}):null]})})}function yE({label:e,choices:t,value:n,disabled:r=!1,describedBy:i,onChange:a}){return(0,I.jsx)(`div`,{role:`radiogroup`,"aria-label":e,"aria-describedby":i,className:`space-y-1`,children:t.map(e=>{let t=e.value===n;return(0,I.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":t,disabled:r,onClick:()=>a(e.value),className:H(`flex w-full items-start gap-3.5 rounded-lg px-3 py-3 text-left transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,r?`cursor-not-allowed opacity-60`:`hover:bg-muted/50`),children:[(0,I.jsx)(`span`,{"aria-hidden":`true`,className:H(`mt-0.5 flex size-4.5 shrink-0 items-center justify-center rounded-full border transition-colors`,t?`border-primary`:`border-muted-foreground/50`),children:t?(0,I.jsx)(`span`,{className:`size-2.5 rounded-full bg-primary`}):null}),(0,I.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`span`,{className:`block text-sm font-medium`,children:e.label}),(0,I.jsx)(`span`,{className:`mt-0.5 block text-sm text-muted-foreground`,children:e.description})]})]},e.value)})})}function bE({href:e,children:t}){return(0,I.jsxs)(`a`,{href:e,target:`_blank`,rel:`noreferrer noopener`,className:`inline-flex items-center gap-0.5 underline decoration-border underline-offset-4 transition-colors hover:text-foreground hover:decoration-foreground`,children:[t,(0,I.jsx)(va,{className:`size-3`})]})}function xE({label:e,presets:t,selected:n,values:r,onSelect:i,onValueChange:a,idPrefix:o,compact:s=!1,disabled:c=!1}){let l=!s&&`warning`in n?n.warning:void 0,u=!s&&`note`in n?n.note:void 0,d=`docs`in n?n.docs:void 0,f=n.vendor??n.label;return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`${o}-preset`,children:e}),(0,I.jsxs)(zT,{value:n.id,disabled:c,onValueChange:e=>{let n=t.find(t=>t.id===e);n&&i(n)},children:[(0,I.jsx)(VT,{id:`${o}-preset`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:t.map(e=>(0,I.jsx)(UT,{value:e.id,children:(0,I.jsx)(SE,{preset:e})},e.id))})]}),n.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n.description}):null]}),n.inputs.map(e=>(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`${o}-${e.key}`,children:e.label}),(0,I.jsx)($,{id:`${o}-${e.key}`,value:r[e.key]??``,placeholder:e.placeholder,className:`font-mono text-xs`,disabled:c,onChange:t=>a(e.key,t.target.value)}),e.hint||e.docs?(0,I.jsxs)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:[e.hint,e.docs?(0,I.jsxs)(I.Fragment,{children:[e.hint?` `:null,(0,I.jsx)(bE,{href:e.docs.href,children:e.docs.label})]}):null]}):null]},e.key)),l?(0,I.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-amber-500/40 bg-amber-500/10 p-3 text-xs leading-relaxed text-amber-700 dark:text-amber-400`,children:[(0,I.jsx)(Ka,{className:`mt-0.5 size-3.5 shrink-0`}),(0,I.jsx)(`span`,{children:l})]}):null,u?(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:u}):null,d?(0,I.jsxs)(`a`,{href:d,target:`_blank`,rel:`noreferrer noopener`,className:`inline-flex items-center gap-1 text-xs text-muted-foreground underline underline-offset-4 hover:text-foreground`,children:[f,` documentation`,(0,I.jsx)(va,{className:`size-3`})]}):null]})}function SE({preset:e,className:t}){return(0,I.jsxs)(`span`,{className:H(`inline-flex items-center gap-1.5`,t),children:[AT(e.id)?(0,I.jsx)(PT,{type:e.id}):null,e.id===`custom`?(0,I.jsx)(ea,{"aria-hidden":!0,className:`size-[1.15em] shrink-0 text-current`,strokeWidth:1.8}):null,e.label]})}var CE=e=>e.replace(/^https?:\/\//u,``).replace(/\/+$/u,``);function wE(e,t){return Object.fromEntries(e.inputs.map(e=>[e.key,(t[e.key]??``).trim()]))}var TE=(e,t)=>e.build(wE(e,t)),EE=(e,t)=>e.build(wE(e,t)),DE=[{id:`firebase`,label:`Firebase Authentication`,vendor:`Firebase`,description:`Google-signed ID tokens. Scoped to your project by the aud and iss claims.`,inputs:[{key:`project_id`,label:`Firebase project id`,placeholder:`my-app-1a2b3`,hint:`Found in Project settings. Not the project number.`}],warning:`Firebase signs every project's tokens with one shared key set, so the JWKS URL alone identifies nobody. The issuer and audience below are what scope this app to your project — without them the gateway would accept a token from any Firebase project in the world.`,docs:`https://firebase.google.com/docs/auth/admin/verify-id-tokens`,build:({project_id:e})=>({jwks_url:`https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com`,issuer:`https://securetoken.google.com/${e}`,audience:e,user_id_claim:`sub`,required_claims:[]}),read:({audience:e})=>({project_id:e})},{id:`supabase`,label:`Supabase Auth`,vendor:`Supabase`,description:`Per-project JWKS. Requires asymmetric signing keys.`,inputs:[{key:`project_ref`,label:`Project ref`,placeholder:`abcdefghijklmnop`,hint:`The subdomain of your project URL: https://<ref>.supabase.co`}],warning:`Only projects migrated to asymmetric JWT signing keys can be verified. A legacy HS256 project publishes no public keys, so its JWKS endpoint returns an empty set and every token is rejected.`,docs:`https://supabase.com/docs/guides/auth/signing-keys`,build:({project_ref:e})=>{let t=CE(e).replace(/\.supabase\.co$/u,``);return{jwks_url:`https://${t}.supabase.co/auth/v1/.well-known/jwks.json`,issuer:`https://${t}.supabase.co/auth/v1`,audience:`authenticated`,user_id_claim:`sub`,required_claims:[]}},read:({issuer:e})=>({project_ref:CE(e).replace(/\.supabase\.co\/auth\/v1$/u,``)})},{id:`auth0`,label:`Auth0`,vendor:`Auth0`,description:`Per-tenant JWKS, with the API identifier as the audience.`,inputs:[{key:`domain`,label:`Tenant domain`,placeholder:`my-tenant.us.auth0.com`,hint:`Your Auth0 domain or custom domain, without https://`},{key:`audience`,label:`API identifier`,placeholder:`https://api.my-app.com`,hint:`The Identifier of the API you registered in Auth0. It is not a URL that has to resolve.`}],warning:`Auth0 puts a trailing slash in the iss claim. The preset writes it for you; do not remove it or every token is rejected.`,docs:`https://auth0.com/docs/secure/tokens/access-tokens/validate-access-tokens`,build:({domain:e,audience:t})=>{let n=CE(e);return{jwks_url:`https://${n}/.well-known/jwks.json`,issuer:`https://${n}/`,audience:t,user_id_claim:`sub`,required_claims:[]}},read:({issuer:e,audience:t})=>({domain:CE(e),audience:t})},{id:`clerk`,label:`Clerk`,vendor:`Clerk`,description:`Session tokens verified against your Frontend API JWKS.`,inputs:[{key:`frontend_api`,label:`Frontend API host`,placeholder:`clean-mayfly-62.clerk.accounts.dev`,hint:`Your Clerk Frontend API URL or custom domain, without https://`},{key:`audience`,label:`Audience`,placeholder:`my-app`,hint:`The aud your Clerk JWT template sets. Clerk's default session token has none — add one in the template, because the gateway requires it.`}],warning:`Clerk's own guidance also checks the azp claim against your permitted origins. This gateway serves native apps, where there is no origin to bind to, so the preset omits it — add an azp requirement manually if your tokens carry one.`,docs:`https://clerk.com/docs/guides/sessions/manual-jwt-verification`,build:({frontend_api:e,audience:t})=>{let n=CE(e);return{jwks_url:`https://${n}/.well-known/jwks.json`,issuer:`https://${n}`,audience:t,user_id_claim:`sub`,required_claims:[]}},read:({issuer:e,audience:t})=>({frontend_api:CE(e),audience:t})},{id:`custom`,label:`Custom issuer`,description:`Any issuer publishing a JWKS document over HTTPS.`,inputs:[{key:`jwks_url`,label:`JWKS URL`,placeholder:`https://issuer.example.com/.well-known/jwks.json`,hint:`If this issuer signs tokens for more than one service, add a claim requirement under Subscription check too.`},{key:`issuer`,label:`Issuer (iss)`,placeholder:`https://issuer.example.com`,hint:`Exactly the iss claim your tokens carry, trailing slash included.`},{key:`audience`,label:`Audience (aud)`,placeholder:`https://api.my-app.com`,hint:`Exactly one aud value your tokens carry.`}],build:({jwks_url:e,issuer:t,audience:n})=>({jwks_url:e,issuer:t,audience:n,user_id_claim:`sub`,required_claims:[]}),read:e=>({...e})}],OE=DE.find(e=>e.id===`custom`),kE=e=>DE.find(t=>t.id===e)??OE;function AE(e){let t=e=>Array.isArray(e)?e[0]??``:e??``;return{jwks_url:e.jwks_url??``,issuer:t(e.issuer),audience:t(e.audience)}}function jE(e){let t=AE(e);if(e.provider){let n=kE(e.provider);return{preset:n,values:n.read(t)}}let n={preset:OE,values:{...t}},r=e=>Array.isArray(e)&&e.length>1;if(r(e.issuer)||r(e.audience))return n;for(let e of DE){if(e===OE)continue;let n=e.read(t);if(!LE(e,n))continue;let r=TE(e,n);if(r.jwks_url===t.jwks_url&&r.issuer===t.issuer&&r.audience===t.audience)return{preset:e,values:n}}return n}var ME=`revenueCatEntitlements`;function NE(e){let t=e.split(`,`).map(e=>e.trim());return{path:ME,contains:t.length>1?t:e}}function PE(e){if(e.length===0)return``;let[t,...n]=e;return!t||n.length>0||t.contains===void 0?null:Array.isArray(t.contains)?t.contains.join(`, `):t.contains}var FE=`Which claim says the user has paid`,IE=[{id:`none`,label:`No entitlement check`,description:`Any user the issuer signs a token for may call the gateway.`,inputs:[],build:()=>[]},{id:`revenuecat`,label:`RevenueCat entitlement`,vendor:`RevenueCat`,inputs:[{key:`entitlement`,label:`Entitlement identifier`,placeholder:`pro`,hint:`In RevenueCat, under Product catalog → Entitlements: the identifier, not the display name. Several, comma separated, admit a user carrying any one of them.`,docs:{href:`https://www.revenuecat.com/docs/getting-started/entitlements`,label:`RevenueCat documentation`}}],build:({entitlement:e})=>e?[NE(e)]:[]},{id:`custom`,label:`Custom claim`,description:`Any single claim requirement. More can be added under Subscription check.`,inputs:[{key:`path`,label:`Claim path`,placeholder:`scope`},{key:`value`,label:`Required value`,placeholder:`ai.invoke`}],build:({path:e,value:t})=>e&&t?[{path:e,contains:t}]:[]}],LE=(e,t)=>e.inputs.every(e=>(t[e.key]??``).trim().length>0);function RE({issuer:e,disabled:t=!1,onChange:n}){let{preset:r,values:i}=jE(e),a=(t,r)=>{let i=TE(t,r);n({provider:t.id,jwks_url:i.jwks_url,issuer:i.issuer,audience:i.audience,user_id_claim:e.user_id_claim??i.user_id_claim})};return(0,I.jsx)(xE,{idPrefix:`issuer`,label:`Identity provider`,presets:DE,selected:r,values:i,compact:!0,disabled:t,onSelect:e=>a(e,{}),onValueChange:(e,t)=>a(r,{...i,[e]:t})})}function zE({claims:e,disabled:t=!1,onChange:n}){let r=(t,r)=>n(e.map((e,n)=>n===t?{...e,...r}:e));return(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Claims the sign-in token must carry. Dot paths; contains matches arrays and space-delimited scopes, equals compares exactly.`}),(0,I.jsxs)(Y,{variant:`outline`,size:`sm`,disabled:t,onClick:()=>n([...e,{path:``,contains:``}]),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add claim`]})]}),e.length===0?(0,I.jsx)(uw,{children:`No claim requirements.`}):e.map((i,a)=>{let o=i.equals===void 0?`contains`:`equals`;return(0,I.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-[180px] flex-1`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Path`}),(0,I.jsx)($,{value:i.path,placeholder:`claims.entitlements`,className:`font-mono text-xs`,disabled:t,onChange:e=>r(a,{path:e.target.value})})]}),(0,I.jsxs)(`div`,{className:`w-[140px]`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Match`}),(0,I.jsxs)(zT,{value:o,disabled:t,onValueChange:t=>n(e.map((e,n)=>n===a?t===`equals`?{path:e.path,equals:Array.isArray(e.contains)?e.contains[0]??``:e.contains??``}:{path:e.path,contains:String(e.equals??``)}:e)),children:[(0,I.jsx)(VT,{className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`contains`,children:`contains`}),(0,I.jsx)(UT,{value:`equals`,children:`equals`})]})]})]}),(0,I.jsxs)(`div`,{className:`min-w-[180px] flex-1`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Value`}),(0,I.jsx)($,{value:o===`contains`&&Array.isArray(i.contains)?i.contains.join(`, `):String(i.equals??i.contains??``),placeholder:o===`contains`?`pro, pro_test`:`pro`,className:`font-mono text-xs`,disabled:t,onChange:e=>{if(o===`equals`){r(a,{equals:e.target.value});return}let t=e.target.value.split(`,`).map(e=>e.trim());r(a,{contains:t.length>1?t:e.target.value})}})]}),(0,I.jsx)(Y,{variant:`ghost`,size:`icon`,"aria-label":`Remove claim`,disabled:t,onClick:()=>n(e.filter((e,t)=>t!==a)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},a)})]})}var BE=IE.filter(e=>e.id!==`none`),VE=NE(``);function HE({issuer:e,disabled:t=!1,onChange:n}){let r=e.required_claims??[],i=PE(r),a=(e.entitlement??(r[0]?.path===`revenueCatEntitlements`?`revenuecat`:`custom`))===`revenuecat`&&i!==null?`revenuecat`:`custom`,o=BE.find(e=>e.id===a)??BE[0],s=e=>{e!==a&&n({entitlement:e,required_claims:e===`revenuecat`?[NE(i??``)]:r})};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`entitlement-check`,children:FE}),(0,I.jsxs)(zT,{value:a,disabled:t,onValueChange:e=>s(e),children:[(0,I.jsx)(VT,{id:`entitlement-check`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:BE.map(e=>(0,I.jsx)(UT,{value:e.id,children:(0,I.jsx)(SE,{preset:e})},e.id))})]}),o.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o.description}):null]}),a===`revenuecat`?(0,I.jsx)(UE,{input:o.inputs[0],entitlement:i??``,disabled:t,onChange:e=>n({required_claims:[NE(e)]})}):(0,I.jsx)(zE,{claims:r,disabled:t,onChange:e=>n({required_claims:e})})]})}function UE({input:e,entitlement:t,disabled:n,onChange:r}){return(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`entitlement-value`,children:e.label}),(0,I.jsx)($,{id:`entitlement-value`,value:t,placeholder:e.placeholder,className:`max-w-[320px] font-mono text-xs`,disabled:n,onChange:e=>r(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:[e.hint,e.docs?(0,I.jsxs)(I.Fragment,{children:[` `,(0,I.jsx)(bE,{href:e.docs.href,children:e.docs.label})]}):null]})]})}var WE=[{value:`issuer`,label:`Signed-in users only`,description:`Users sign in through your identity provider, and the gateway verifies it.`},{value:`app_install`,label:`Unauthenticated users`,description:`Anyone with your app can call. Each installation counts as one user.`}],GE=[{value:`issuer`,label:`Signed-in users only`,description:`Your backend forwards each user's sign-in token, and the gateway verifies it.`},{value:`header`,label:`Your backend sends the user id`,description:`In the ${iT} header on every request.`},{value:`none`,label:`No user identity`,description:`Requests are not linked to any user.`}];function KE({...e}){return(0,I.jsx)(Jd,{"data-slot":`dialog`,...e})}function qE({...e}){return(0,I.jsx)(Xd,{"data-slot":`dialog-trigger`,...e})}function JE({...e}){return(0,I.jsx)(ef,{"data-slot":`dialog-portal`,...e})}function YE({className:e,...t}){return(0,I.jsx)(nf,{"data-slot":`dialog-overlay`,className:H(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function XE({className:e,children:t,showCloseButton:n=!0,dismissOnOutsideInteraction:r=!1,onInteractOutside:i,...a}){return(0,I.jsxs)(JE,{"data-slot":`dialog-portal`,children:[(0,I.jsx)(YE,{}),(0,I.jsxs)(sf,{"data-slot":`dialog-content`,className:H(`fixed top-[50%] left-[50%] z-50 flex max-h-[calc(100dvh-4rem)] w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] flex-col overflow-hidden rounded-lg border bg-background shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg`,n&&`[&_[data-slot=dialog-header]]:pr-14`,e),onInteractOutside:e=>{i?.(e),r||e.preventDefault()},...a,children:[t,n&&(0,I.jsxs)(gf,{"data-slot":`dialog-close`,className:`absolute top-5 right-4 inline-flex size-8 items-center justify-center rounded-md text-muted-foreground opacity-70 ring-offset-background transition-[opacity,background-color,color] hover:bg-muted hover:text-foreground hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,I.jsx)(Ya,{}),(0,I.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function ZE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`dialog-header`,className:H(`flex shrink-0 flex-col gap-2 border-b p-6 text-center sm:text-left`,e),...t})}function QE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`dialog-body`,className:H(`min-h-0 flex-1 overflow-y-auto px-6 py-5`,e),...t})}function $E({className:e,showCloseButton:t=!1,children:n,...r}){return(0,I.jsxs)(`div`,{"data-slot":`dialog-footer`,className:H(`flex shrink-0 flex-col-reverse gap-2 border-t px-6 py-4 sm:flex-row sm:justify-end`,e),...r,children:[n,t&&(0,I.jsx)(gf,{asChild:!0,children:(0,I.jsx)(Y,{variant:`outline`,children:`Close`})})]})}function eD({className:e,...t}){return(0,I.jsx)(ff,{"data-slot":`dialog-title`,className:H(`text-lg leading-6 font-semibold`,e),...t})}function tD({className:e,...t}){return(0,I.jsx)(mf,{"data-slot":`dialog-description`,className:H(`text-sm text-muted-foreground`,e),...t})}function nD({open:e,onOpenChange:t,title:n,description:r,submitLabel:i,pending:a,disabled:o,onSubmit:s,secondaryAction:c,className:l,children:u}){let{readOnly:d}=ox(),f=d||o||a;return(0,I.jsx)(KE,{open:e,onOpenChange:t,children:(0,I.jsx)(XE,{className:l??`sm:max-w-md`,...r?{}:{"aria-describedby":void 0},children:(0,I.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,autoComplete:`off`,onSubmit:e=>{e.preventDefault(),!f&&s()},children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{className:`text-balance`,children:n})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[r?(0,I.jsx)(tD,{className:`text-pretty`,children:r}):null,u]}),(0,I.jsxs)($E,{children:[c,(0,I.jsx)(Y,{type:`button`,variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,I.jsxs)(iw,{type:`submit`,disabled:o||a,children:[a?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,i]})]})]})})})}function rD({open:e,title:t,description:n,label:r,secret:i,acknowledgeLabel:a=`I’ve saved this key`,footnote:o,onAcknowledge:s}){let[c,l]=(0,v.useState)(!1),u=async()=>{try{await navigator.clipboard.writeText(i),l(!0),U.success(`Copied to clipboard`)}catch{U.error(`Could not copy. Select the value and copy it manually.`)}},d=()=>{l(!1),s()};return(0,I.jsx)(KE,{open:e,onOpenChange:e=>{e||d()},children:(0,I.jsxs)(XE,{showCloseButton:!1,className:`sm:max-w-lg`,onEscapeKeyDown:e=>e.preventDefault(),children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{className:`text-balance`,children:t})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{className:`text-pretty`,children:n}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`revealed-secret`,children:r}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)($,{id:`revealed-secret`,value:i,readOnly:!0,className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,I.jsxs)(Y,{type:`button`,variant:`outline`,className:`min-w-24`,onClick:()=>void u(),children:[c?(0,I.jsx)(ra,{className:`size-4`}):(0,I.jsx)(ha,{className:`size-4`}),c?`Copied`:`Copy`]})]}),o?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}):null]})]}),(0,I.jsx)($E,{children:(0,I.jsx)(Y,{onClick:d,children:a})})]})})}function iD({appId:e,exchanged:t=!1,title:n=`Server API keys`,description:r}){let i=IS(e),a=LS(e),o=RS(e),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(null),p=async()=>{if(l.trim())try{let e=await a.mutateAsync(l.trim());c(!1),u(``),f(e)}catch(e){U.error(e instanceof Error?e.message:`Could not create the API key`)}},m=async e=>{try{await o.mutateAsync(e),U.success(`API key revoked`)}catch(e){U.error(e instanceof Error?e.message:`Could not revoke the API key`)}};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:n,description:r,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>{u(``),c(!0)},children:[(0,I.jsx)(Na,{className:`size-4`}),`New key`]})})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[t?null:(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Your backend sends one of these keys as an Authorization bearer credential. Revoking takes effect within a minute.`}),(0,I.jsx)(`div`,{className:`overflow-hidden rounded-md border`,children:(0,I.jsxs)(sE,{className:`[--table-inset:1rem]`,children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Prefix`}),(0,I.jsx)(Z,{children:`Last used`}),(0,I.jsx)(Z,{children:`Status`}),(0,I.jsx)(Z,{className:`w-24`})]})}),(0,I.jsx)(lE,{children:i.data?.keys.length?i.data.keys.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{children:e.name}),(0,I.jsxs)(Q,{className:`font-mono text-xs`,children:[e.key_prefix,`…`]}),(0,I.jsx)(Q,{className:`text-xs text-muted-foreground`,children:hC(e.last_used_at)}),(0,I.jsx)(Q,{children:(0,I.jsx)(Ib,{variant:e.status===`active`?`secondary`:`outline`,children:e.status})}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsxs)(iw,{variant:`ghost`,size:`sm`,className:`text-destructive`,disabled:e.status===`revoked`||o.isPending,onClick:()=>void m(e.id),children:[(0,I.jsx)(Va,{className:`size-3.5`}),`Revoke`]})})]},e.id)):(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,className:`py-8 text-center text-sm text-muted-foreground`,children:`No API keys yet.`})})})]})})]})]}),(0,I.jsx)(nD,{open:s,onOpenChange:c,title:`Create an API key`,submitLabel:`Create key`,pending:a.isPending,disabled:!l.trim(),onSubmit:()=>void p(),children:(0,I.jsx)(sw,{label:`Key name`,htmlFor:`api-key-name`,hint:`Name it so you can tell keys apart in the list.`,children:(0,I.jsx)($,{id:`api-key-name`,value:l,placeholder:`Production Worker`,maxLength:100,autoFocus:!0,autoComplete:`off`,onChange:e=>u(e.target.value)})})}),(0,I.jsx)(rD,{open:d!==null,title:`Copy your new key now`,description:(0,I.jsxs)(I.Fragment,{children:[`This is the only time the plaintext for`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:d?.name}),` is available — you will not see it again. The gateway stores only a hash.`]}),label:`API key`,secret:d?.key??``,onAcknowledge:()=>{f(null),a.reset()}})]})}var aD=`identity`,oD=[{slug:`identity`,label:`Application identity`},{slug:`users`,label:`User authentication`},{slug:`subscription`,label:`Subscription check`}],sD={secure:{icon:la,className:`text-emerald-600 dark:text-emerald-400`},weak:{icon:za,className:`text-amber-600 dark:text-amber-400`},incomplete:{icon:ca,className:`text-destructive`},off:{icon:ua,className:`text-muted-foreground/60`}},cD=[{value:`paid`,label:`Paid users only`,description:`The sign-in token must carry a claim that says the user has paid.`},{value:`any`,label:`Any signed-in user`,description:`Signing in is enough. Nothing about payment is checked.`}],lD=e=>(e.required_claims??[]).length>0||e.entitlement!==void 0?`paid`:`any`;function uD(e,t){let n=e.config.authentication,r=lT(n);return{identity:n.type===`apple_app_attest`?!n.app_attest.team_id.trim()||!n.app_attest.bundle_id.trim()?{tone:`incomplete`,text:`Team or bundle id missing`}:{tone:`secure`,text:`Verified with App Attest`}:t===!1?{tone:`incomplete`,text:`No active API key`}:{tone:`secure`,text:`Verified with API keys`},users:(()=>{switch(n.end_user?.source??`none`){case`issuer`:return r&&$T(r)?{tone:`secure`,text:`Signed-in users only`}:{tone:`incomplete`,text:`Identity provider not finished`};case`header`:return n.type===`api_key`&&n.end_user?.source===`header`&&!n.end_user.header.trim()?{tone:`incomplete`,text:`Header name missing`}:{tone:`weak`,text:`Your backend names the user`};case`app_install`:return{tone:`weak`,text:`Unauthenticated users allowed`};default:return{tone:`weak`,text:`No user identity`}}})(),subscription:r?lD(r)===`paid`?(r.required_claims??[]).every(eE)&&(r.required_claims??[]).length>0?{tone:`secure`,text:`Paid users only`}:{tone:`incomplete`,text:`Paid check not finished`}:{tone:`weak`,text:`Any signed-in user`}:{tone:`off`,text:`Needs signed-in users`}}}function dD({appId:e,level:t,state:n}){let r=n.draft,i=r.config.authentication,{readOnly:a}=ox(),o=IS(e,i.type===`api_key`),s=uD(r,o.data?o.data.keys.some(e=>e.status===`active`):void 0),c=oD.some(e=>e.slug===t)&&s[t].tone!==`off`?t:aD;return(0,I.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[16rem_minmax(0,1fr)]`,children:[(0,I.jsx)(`nav`,{"aria-label":`Auth policy levels`,className:`flex flex-col gap-1 lg:sticky lg:top-6 lg:self-start`,children:oD.map(t=>(0,I.jsx)(fD,{to:`/apps/${e}/auth/${t.slug}`,label:t.label,status:s[t.slug],current:t.slug===c},t.slug))}),(0,I.jsx)(`div`,{className:`min-w-0 space-y-4`,children:c===`identity`?i.type===`apple_app_attest`?(0,I.jsx)(pD,{authentication:i,readOnly:a,state:n}):(0,I.jsx)(iD,{appId:e,exchanged:lT(i)!==void 0,title:`Application identity`,description:`A server application. Your backend proves itself with one of these API keys.`}):c===`users`?(0,I.jsx)(mD,{authentication:i,readOnly:a,state:n}):(0,I.jsx)(hD,{issuer:lT(i)??uT(),readOnly:a,state:n})})]})}function fD({to:e,label:t,status:n,current:r}){let{icon:i,className:a}=sD[n.tone],o=(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(i,{className:H(`mt-0.5 size-4 shrink-0`,a),"aria-hidden":`true`}),(0,I.jsxs)(`span`,{className:`min-w-0`,children:[(0,I.jsx)(`span`,{className:`block text-sm font-medium`,children:t}),(0,I.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:n.text})]})]}),s=`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition-colors`;return n.tone===`off`?(0,I.jsx)(`div`,{"aria-disabled":`true`,className:H(s,`opacity-60`),children:o}):(0,I.jsx)(Pn,{to:e,"aria-current":r?`page`:void 0,className:H(s,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`,r?`bg-muted`:`hover:bg-muted/60`),children:o})}function pD({authentication:e,readOnly:t,state:n}){let r=e.app_attest,i=t=>n.updateAuthentication({...e,app_attest:{...r,...t}});return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Application identity`,description:`An iOS application. Only builds signed with this team and bundle id can call AI providers through this gateway.`})}),(0,I.jsxs)(oE,{className:`space-y-6`,children:[(0,I.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-team-id`,children:`Apple Team ID`}),(0,I.jsx)($,{id:`apple-team-id`,value:r.team_id,placeholder:`ABCDE12345`,className:`font-mono text-xs`,disabled:t,onChange:e=>i({team_id:e.target.value})}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In your Apple Developer account under`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/account#MembershipDetailsCard`,children:`Membership details`}),`.`]})]}),(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-bundle-id`,children:`Bundle ID`}),(0,I.jsx)($,{id:`apple-bundle-id`,value:r.bundle_id,placeholder:`com.example.app`,className:`font-mono text-xs`,disabled:t,onChange:e=>i({bundle_id:e.target.value})}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In Xcode, on your target's`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/documentation/xcode/configuring-the-build-settings-of-a-target#Set-the-bundle-ID`,children:`Signing & Capabilities`}),` `,`tab.`]})]})]}),(0,I.jsx)(vE,{value:r.environments,compact:!0,disabled:t,onChange:t=>n.updateAuthentication({...e,app_attest:{team_id:r.team_id,bundle_id:r.bundle_id,...t.length===1&&t[0]===`production`?{}:{environments:t}}})})]})]})}function mD({authentication:e,readOnly:t,state:n}){let r=(0,v.useId)(),i=e.end_user?.source??`none`,a=lT(e),o=e.type===`api_key`?GE:WE;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`User authentication`,description:`Choose whether only users signed in to your app can call AI through this gateway.`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[t?(0,I.jsx)(rw,{reason:nx,reasonId:r,className:`w-full`,children:(0,I.jsx)(yE,{label:`User authentication`,choices:o,value:i,disabled:!0,describedBy:r,onChange:()=>{}})}):(0,I.jsx)(yE,{label:`User authentication`,choices:o,value:i,onChange:e=>n.setEndUserSource(e===`none`?void 0:e)}),e.type===`api_key`&&e.end_user?.source===`header`?(0,I.jsx)(sw,{label:`Header name`,htmlFor:`end-user-header`,hint:`Lowercased, and removed before the request reaches the provider. Defaults to ${iT}.`,children:(0,I.jsx)($,{id:`end-user-header`,value:e.end_user.header,placeholder:iT,className:`max-w-[320px] font-mono text-xs`,disabled:t,onChange:e=>n.updateEndUserHeader(e.target.value)})}):null]})]}),i===`issuer`?(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Identity provider`,description:`Where your users sign in. The gateway verifies their sign-in tokens against it.`})}),(0,I.jsx)(oE,{children:(0,I.jsx)(RE,{issuer:a??uT(),disabled:t,onChange:n.updateIssuer})})]}):null]})}function hD({issuer:e,readOnly:t,state:n}){let r=(0,v.useId)(),i=lD(e);return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Subscription check`,description:`Check that the user has paid for the app before they can call AI providers through this gateway.`})}),(0,I.jsxs)(oE,{className:`space-y-6`,children:[t?(0,I.jsx)(rw,{reason:nx,reasonId:r,className:`w-full`,children:(0,I.jsx)(yE,{label:`Subscription check`,choices:cD,value:i,disabled:!0,describedBy:r,onChange:()=>{}})}):(0,I.jsx)(yE,{label:`Subscription check`,choices:cD,value:i,onChange:e=>{e!==i&&n.updateIssuer(e===`any`?{entitlement:void 0,required_claims:[]}:{entitlement:`revenuecat`,required_claims:[VE]})}}),i===`paid`?(0,I.jsx)(`div`,{className:`border-t pt-6`,children:(0,I.jsx)(HE,{issuer:e,disabled:t,onChange:n.updateIssuer})}):null]})]})}var gD={requests:{per_minute:null,per_day:null},spending:{monthly_usd:null}},_D={per_user:gD,per_app:gD},vD=e=>e===``?null:Number(e);function yD({state:e}){let t=e.draft,n=t.config.limits??_D,r=t.config.authentication.type!==`api_key`||t.config.authentication.end_user!==void 0,i=(t,r)=>e.updateLimits({...n,[t]:{...n[t],...r}});return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`p`,{className:`text-sm leading-relaxed text-muted-foreground`,children:[`Limits you set on `,(0,I.jsx)(`strong`,{className:`font-medium text-foreground`,children:`your app's end users`}),`. They are unrelated to your own`,` `,(0,I.jsx)(Pn,{to:`/billing`,className:`text-primary-ink underline underline-offset-4`,children:`plan allowance`}),`, which meters all your apps together: a request refused here never spends it. Edits take up to a minute to apply everywhere.`]}),(0,I.jsxs)(`div`,{className:r?`grid gap-4 lg:grid-cols-2`:`grid gap-4`,children:[r?(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Per-user limits`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Applied independently to every authenticated user. Rate limits return`,` `,(0,I.jsx)(`code`,{className:`font-mono`,children:`app_rate_limited`}),`; exhausting the monthly spend returns `,(0,I.jsx)(`code`,{className:`font-mono`,children:`app_budget_exhausted`}),`.`]}),(0,I.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,I.jsx)(sw,{label:`Requests per minute`,htmlFor:`rpm`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`rpm`,type:`number`,min:1,value:n.per_user.requests.per_minute??``,placeholder:`Unlimited`,onChange:e=>i(`per_user`,{requests:{...n.per_user.requests,per_minute:vD(e.target.value)}})})}),(0,I.jsx)(sw,{label:`Requests per day`,htmlFor:`rpd`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`rpd`,type:`number`,min:1,value:n.per_user.requests.per_day??``,placeholder:`Unlimited`,onChange:e=>i(`per_user`,{requests:{...n.per_user.requests,per_day:vD(e.target.value)}})})})]}),(0,I.jsx)(`div`,{className:`border-t pt-4`,children:(0,I.jsx)(sw,{label:`Monthly spending budget (USD)`,htmlFor:`budget`,hint:n.per_user.spending.monthly_usd===null?`Unlimited`:`${dC(n.per_user.spending.monthly_usd)} per user per month. Settled from completed requests, so it stops the request after the one that crosses it.`,children:(0,I.jsx)($,{id:`budget`,type:`number`,min:0,step:`0.01`,value:n.per_user.spending.monthly_usd??``,placeholder:`Unlimited`,onChange:e=>i(`per_user`,{spending:{monthly_usd:vD(e.target.value)}})})})})]})]}):(0,I.jsx)(nE,{children:(0,I.jsx)(oE,{className:`pt-6`,children:(0,I.jsx)(uw,{children:`This application identifies no end users, so there is nobody for a per-user limit to apply to. Choose a user authentication method on the Auth policy tab to set them, or use the application limits below.`})})}),(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Application limits`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Shared across all users and credentials for this application. Leave a field empty to keep that application-wide limit unrestricted.`}),(0,I.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,I.jsx)(sw,{label:`Requests per minute`,htmlFor:`app-rpm`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`app-rpm`,type:`number`,min:1,value:n.per_app.requests.per_minute??``,placeholder:`Unlimited`,onChange:e=>i(`per_app`,{requests:{...n.per_app.requests,per_minute:vD(e.target.value)}})})}),(0,I.jsx)(sw,{label:`Requests per day`,htmlFor:`app-rpd`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`app-rpd`,type:`number`,min:1,value:n.per_app.requests.per_day??``,placeholder:`Unlimited`,onChange:e=>i(`per_app`,{requests:{...n.per_app.requests,per_day:vD(e.target.value)}})})})]}),(0,I.jsx)(`div`,{className:`border-t pt-4`,children:(0,I.jsx)(sw,{label:`Monthly spending budget (USD)`,htmlFor:`app-budget`,hint:n.per_app.spending.monthly_usd===null?`Unlimited`:`${dC(n.per_app.spending.monthly_usd)} per application per month. Settled from completed requests, so it stops the request after the one that crosses it.`,children:(0,I.jsx)($,{id:`app-budget`,type:`number`,min:0,step:`0.01`,value:n.per_app.spending.monthly_usd??``,placeholder:`Unlimited`,onChange:e=>i(`per_app`,{spending:{monthly_usd:vD(e.target.value)}})})})})]})]})]})]})}function bD(e){return e?.apiBaseUrl??window.location.origin}function xD({appId:e,month:t,state:n}){let{capabilities:r}=ox(),i=VS(e,t),a=zS(e,{month:t,limit:1}),o=n.draft.config.authentication,s=(i.data?.input_tokens??0)+(i.data?.cached_input_tokens??0)+(i.data?.cache_write_tokens??0)+(i.data?.output_tokens??0),c=lT(o);return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[o.type===`api_key`?(0,I.jsx)(SD,{appId:e}):null,(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,I.jsx)(dE,{label:`Spend`,value:i.isPending?(0,I.jsx)(aw,{className:`h-6 w-20`}):dC(i.data?.cost_usd??0),detail:`month to date`}),(0,I.jsx)(dE,{label:`Users`,value:a.isPending?(0,I.jsx)(aw,{className:`h-6 w-12`}):cC(a.data?.total??0),detail:`all time`}),(0,I.jsx)(dE,{label:`Requests`,value:i.isPending?(0,I.jsx)(aw,{className:`h-6 w-16`}):cC(i.data?.requests??0),detail:`month to date`}),(0,I.jsx)(dE,{label:`Tokens`,value:i.isPending?(0,I.jsx)(aw,{className:`h-6 w-16`}):lC(s),detail:`all buckets`})]}),(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Client base URL`})}),(0,I.jsxs)(oE,{children:[(0,I.jsxs)(`code`,{className:`block rounded-md bg-muted px-3 py-2 font-mono text-xs break-all`,children:[bD(r),`/v1/apps/`,e,`/proxy/{provider}/{provider_path}`]}),(0,I.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:c?(0,I.jsxs)(I.Fragment,{children:[`Auth exchange lives at`,` `,(0,I.jsxs)(`span`,{className:`font-mono`,children:[`/v1/apps/`,e,`/auth/token`]}),`.`]}):(0,I.jsxs)(I.Fragment,{children:[`Clients send their API key as the`,` `,(0,I.jsx)(`span`,{className:`font-mono`,children:`Authorization`}),` bearer credential; this app has no token exchange.`]})})]})]})]})}function SD({appId:e}){let t=IS(e);return!t.data||t.data.keys.some(e=>e.status===`active`)?null:(0,I.jsxs)(Ds,{children:[(0,I.jsx)(Sa,{}),(0,I.jsx)(Os,{children:`This app has no active API key`}),(0,I.jsxs)(ks,{children:[`Nothing can call it until one is created.`,` `,(0,I.jsx)(Pn,{to:`/apps/${e}/auth/identity`,className:`text-primary-ink underline underline-offset-4`,children:`Create an API key`})]})]})}function CD({className:e,size:t=`default`,...n}){return(0,I.jsx)(gy,{"data-slot":`switch`,"data-size":t,className:H(`peer group/switch inline-flex shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-[1.15rem] data-[size=default]:w-8 data-[size=sm]:h-3.5 data-[size=sm]:w-6 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input dark:data-[state=unchecked]:bg-input/80`,e),...n,children:(0,I.jsx)(vy,{"data-slot":`switch-thumb`,className:H(`pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0 dark:data-[state=checked]:bg-primary-foreground dark:data-[state=unchecked]:bg-foreground`)})})}function wD({values:e,onChange:t,placeholder:n,suggestions:r=[],warn:i,warnTitle:a}){let[o,s]=(0,v.useState)(``),c=`suggestions-${Math.abs(TD(r.join(`,`)+n))}`,l=n=>{let r=n.trim();if(!r||e.includes(r))return s(``);t([...e,r]),s(``)};return(0,I.jsxs)(`div`,{className:`space-y-2`,children:[e.length>0?(0,I.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(n=>{let r=i?.(n)??!1;return(0,I.jsxs)(`span`,{title:r?a:void 0,className:H(`inline-flex items-center gap-1 rounded-md border py-1 pr-1 pl-2 font-mono text-xs`,r?`border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-400`:`bg-muted/50`),children:[n,(0,I.jsx)(`button`,{type:`button`,"aria-label":`Remove ${n}`,className:`rounded p-0.5 text-muted-foreground transition-colors hover:bg-background hover:text-foreground`,onClick:()=>t(e.filter(e=>e!==n)),children:(0,I.jsx)(Ya,{className:`size-3`})})]},n)})}):null,(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)($,{value:o,list:r.length>0?c:void 0,placeholder:n,className:`h-8 font-mono text-xs`,onChange:e=>s(e.target.value),onKeyDown:n=>{(n.key===`Enter`||n.key===`,`)&&(n.preventDefault(),l(o)),n.key===`Backspace`&&o===``&&e.length>0&&t(e.slice(0,-1))}}),r.length>0?(0,I.jsx)(`datalist`,{id:c,children:r.map(e=>(0,I.jsx)(`option`,{value:e},e))}):null,(0,I.jsxs)(Y,{type:`button`,variant:`outline`,size:`sm`,className:`h-8`,onClick:()=>l(o),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add`]})]})]})}function TD(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+e.charCodeAt(n)|0;return t}var ED={responses:`Responses`,chat_completions:`Chat Completions`,anthropic_messages:`Anthropic Messages`,gemini_native:`Gemini generateContent`,audio_transcription:`Transcription`};function DD(e){return Object.hasOwn(ED,e)}var OD={gemini:[`gemini_native`],openai:[`audio_transcription`],xai:[`audio_transcription`]};function kD(e){return{style:e,label:ED[e],path:Lw[e]}}function AD(e,t){let n=Xw[e]?.[t];if(!n)return null;let r=OD[t]??[],i=n.apiStyles?.filter(DD);return{narrowed:i!==void 0,available:(i??[]).map(kD),unavailable:i?r.filter(e=>!i.includes(e)).map(kD):[],modelIds:n.modelPrefix?`${eT[t]} model IDs with no "${n.modelPrefix}" prefix — the gateway adds it upstream`:`${eT[t]} model IDs, unchanged`}}function jD(e,t,n){if(e===null)return!0;let r=AD(e,t);if(!r)return!1;if(!r.narrowed)return!0;let i=zw[n];return r.available.some(e=>e.style===i)}var MD={openai:`Forwarded with the leading v1/ stripped, matching Cloudflare's provider-native URL.`,anthropic:`Forwarded with the v1/ prefix retained.`,xai:`Routed to Cloudflare's grok slug; the tenant path stays /proxy/xai/...`,gemini:`Use the OpenAI-compatible path v1beta/openai/chat/completions.`,perplexity:`Routed to Cloudflare's perplexity-ai slug; use chat/completions for Sonar models.`,deepseek:`Direct only. DeepSeek's base URL has no v1/, so the path is chat/completions.`,groq:`Direct only. Groq namespaces its OpenAI API: use openai/v1/chat/completions.`,mistral:`Direct only. Use v1/chat/completions.`,together:`Direct only. Use v1/chat/completions; models are namespaced, e.g. openai/gpt-oss-120b.`,fireworks:`Direct only. Use inference/v1/chat/completions. Models are account-scoped (accounts/…/models/…), so price them under custom model pricing.`,cerebras:`Direct only. Use v1/chat/completions.`,moonshot:`Direct only. Use v1/chat/completions on the international api.moonshot.ai host.`,huggingface:`Direct only. Use v1/chat/completions on the Inference Providers router. Pin the upstream in the model ID (author/model:provider) — otherwise the router picks one and the price varies with it.`,baseten:`Direct only. Use v1/chat/completions on the Model APIs host.`,bytedance:`Direct only. BytePlus ModelArk's version segment is already in the base URL: the path is chat/completions. Models must be activated in your ModelArk console first.`,openrouter:`Direct only, chat completions only. Models are OpenRouter slugs, e.g. google/gemini-3.6-flash, and need no local price: cost is reported by OpenRouter per request.`};function ND(e,t){if(e.providerGatewayId===null)return null;let n=t.find(t=>t.id===e.providerGatewayId),r=n?AD(n.type,e.type):null;if(!r?.narrowed)return null;let i=r.available.map(e=>`${e.label} at ${e.path}`).join(`, `),a=r.unavailable.length>0?` Not available on this route: ${r.unavailable.map(e=>e.label).join(`, `)}.`:``;return`Routed through ${n.name}: ${i}.${a} Models: ${r.modelIds}.`}function PD({state:e}){return(0,I.jsx)(Ib,{variant:`outline`,className:`border-muted-foreground/30 text-[11px] font-normal text-muted-foreground`,children:e})}function FD({row:e,config:t,onChange:n}){let r=(t?.allowed_paths??[]).map(fT),i=e.knownModels,a=e=>n({...mT(),...t,allowed_paths:e.map(pT)});return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.title,e.badge?(0,I.jsx)(PD,{state:e.badge}):null]}),description:e.description,action:(0,I.jsx)(CD,{"aria-label":`Enable ${e.slug}`,checked:t!==void 0,onCheckedChange:e=>n(e?mT():void 0)})})}),t?(0,I.jsxs)(oE,{className:`space-y-5`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(ow,{className:`text-sm`,children:`Allowed paths`}),(0,I.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:()=>a([...r,{path:``}]),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add path`]})]}),r.length===0?(0,I.jsx)(uw,{children:`Every path is allowed. Add one or more paths to restrict this provider.`}):(0,I.jsx)(`div`,{className:`space-y-2`,children:r.map((e,t)=>(0,I.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-[200px] flex-[2]`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Path`}),(0,I.jsx)($,{value:e.path,placeholder:`v1/responses`,className:`font-mono text-xs`,onChange:e=>a(r.map((n,r)=>r===t?{...n,path:e.target.value}:n))})]}),(0,I.jsxs)(`div`,{className:`min-w-[150px] flex-1`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Fixed model`}),(0,I.jsx)($,{value:e.fixed_model??``,placeholder:`none`,className:`font-mono text-xs`,onChange:e=>a(r.map((n,r)=>r===t?{...n,fixed_model:e.target.value||void 0}:n))})]}),(0,I.jsxs)(`div`,{className:`w-[170px]`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Output cap style`}),(0,I.jsxs)(zT,{value:e.clamp??`auto`,onValueChange:e=>a(r.map((n,r)=>r===t?{...n,clamp:e===`auto`?void 0:e}:n)),children:[(0,I.jsx)(VT,{className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`auto`,children:`auto (by body)`}),rT.map(e=>(0,I.jsx)(UT,{value:e,children:e},e))]})]})]}),(0,I.jsx)(Y,{variant:`ghost`,size:`icon`,"aria-label":`Remove path`,onClick:()=>a(r.filter((e,n)=>n!==t)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},t))}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Leave this list empty to allow every path. A fixed model applies to transcription-style routes with no model in the body; it is never injected upstream. Leave the output cap style on auto unless the route needs an exception.`})]}),(0,I.jsx)(sw,{label:`Allowed models`,hint:`Leave empty to allow every model with configured pricing. A non-empty list restricts this provider; rewrites are resolved before pricing is checked.`,children:(0,I.jsx)(wD,{values:t.allowed_models??[],suggestions:i,placeholder:`gpt-5.6-terra`,onChange:e=>n({...t,allowed_models:e})})}),(0,I.jsx)(sw,{label:`Max output tokens`,hint:`Empty = unrestricted. If set, requests above this are rejected; requests without an output-limit parameter get this value injected. Transcription routes ignore this cap.`,children:(0,I.jsx)($,{type:`number`,min:1,className:`max-w-[200px]`,value:t.max_output_tokens??``,placeholder:`8192`,onChange:e=>n({...t,max_output_tokens:e.target.value?Number(e.target.value):void 0})})})]}):null]})}function ID(e,t,n,r){let i=e.map(e=>({slug:e.slug,title:e.name,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`span`,{className:`font-mono`,children:[`/proxy/`,e.slug,`/…`]}),` ·`,` `,(0,I.jsx)(FT,{type:e.type,className:`align-middle`}),` —`,` `,ND(e,t)??MD[e.type]]}),knownModels:aT(e,r),...e.status===`disabled`?{badge:`disabled`}:{}})),a=n.filter(t=>!e.some(e=>e.slug===t)).map(e=>({slug:e,title:e,description:`No instance answers for this slug. Recreate it on the Providers page, or turn this off.`,knownModels:[],badge:`deleted`}));return[...i,...a]}var LD=e=>e.filter(([e,t])=>e!==``&&t!==``),RD=e=>Object.fromEntries(LD(e));function zD({rewrites:e,onChange:t}){let[n,r]=(0,v.useState)(()=>Object.entries(e)),i=JSON.stringify(e),[a,o]=(0,v.useState)(i);i!==a&&(o(i),i!==JSON.stringify(RD(n))&&r(Object.entries(e)));let s=e=>{r(e),t(RD(e))},c=(e,t)=>s(n.map((n,r)=>r===e?t:n)),l=LD(n).length<n.length;return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Model rewrites`,description:`Server-side remap applied after the allowlist check, so a target need not be client-allowlisted. Usage records the rewritten model.`,action:(0,I.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:()=>s([...n,[``,``]]),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add rewrite`]})})}),(0,I.jsxs)(oE,{className:`space-y-2`,children:[n.length===0?(0,I.jsx)(uw,{children:`No rewrites. Clients get exactly the model they ask for.`}):n.map(([e,t],r)=>(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)($,{value:e,"aria-label":`Rewrite ${r+1} source model`,placeholder:`gpt-5.6-terra`,className:`flex-1 font-mono text-xs`,onChange:e=>c(r,[e.target.value,t])}),(0,I.jsx)(Zi,{className:`size-4 shrink-0 text-muted-foreground`}),(0,I.jsx)($,{value:t,"aria-label":`Rewrite ${r+1} target model`,placeholder:`gpt-5.7`,className:`flex-1 font-mono text-xs`,onChange:t=>c(r,[e,t.target.value])}),(0,I.jsx)(Y,{variant:`ghost`,size:`icon`,"aria-label":`Remove rewrite ${r+1}`,onClick:()=>s(n.filter((e,t)=>t!==r)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},r)),l?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`A rewrite is saved once both sides are filled in. A row left half-finished is dropped.`}):null]})]})}function BD({state:e}){let t=e.draft.config.routing,n=yT(t),r=bT(t),i=fS().data??[],a=_S().data?.gateways??[],o=qS().data?.prices,s=ID(i,a,r,o);return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(nE,{className:n===`all`?`border-emerald-500/30`:void 0,children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Provider access`,description:`Choose whether this application can use every provider supported by the gateway or only providers you select.`,action:(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(ow,{htmlFor:`configure-providers`,className:`text-xs text-muted-foreground`,children:`Configure individually`}),(0,I.jsx)(CD,{id:`configure-providers`,"aria-label":`Configure providers individually`,checked:n===`selected`,onCheckedChange:t=>{e.updateProxy(t?{providers:{mode:`selected`,selected:(()=>{let e=i.find(e=>e.status===`active`)??i[0];return e?{[e.slug]:mT()}:{}})()}}:{providers:{mode:`all`}})}})]})})}),(0,I.jsx)(oE,{children:n===`all`?(0,I.jsx)(`div`,{className:`rounded-xl border border-emerald-500/25 bg-emerald-500/[0.06] p-4`,children:(0,I.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,I.jsx)(`span`,{className:`mt-0.5 flex size-9 shrink-0 items-center justify-center rounded-lg bg-emerald-500/12 text-emerald-600 dark:text-emerald-400`,children:(0,I.jsx)(la,{className:`size-5`})}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`p`,{className:`text-sm font-semibold`,children:`Every configured instance is allowed`}),(0,I.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`New provider instances, paths, and models are available automatically. Turn on individual configuration only when this application needs restrictions.`}),(0,I.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:i.length===0?(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No provider instances yet.`}):i.map(e=>(0,I.jsx)(Ib,{variant:`secondary`,className:H(`bg-background/75 font-mono text-[11px] font-normal`,e.status===`disabled`&&`text-muted-foreground line-through decoration-muted-foreground/50`),title:e.status===`disabled`?`${e.slug} is disabled and serves no traffic`:void 0,children:e.slug},e.slug))})]})]})}):(0,I.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-muted/45 p-4 ring-1 ring-border/70`,children:[(0,I.jsx)(`span`,{className:`mt-0.5 flex size-9 shrink-0 items-center justify-center rounded-lg bg-background text-muted-foreground shadow-sm ring-1 ring-border`,children:(0,I.jsx)(Ha,{className:`size-4`})}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`p`,{className:`text-sm font-medium`,children:[r.length,` of `,i.length,` provider instances enabled`]}),(0,I.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`Use the switches below. An enabled instance allows every path and model until you add a restriction, and clients reach it at its own slug.`})]})]})})]}),n===`selected`&&s.length===0?(0,I.jsx)(nE,{children:(0,I.jsx)(oE,{children:(0,I.jsx)(uw,{children:`No provider instances to choose from. Add one on the Providers page, then come back to restrict this app to it.`})})}):null,n===`selected`?s.map(n=>(0,I.jsx)(FD,{row:n,config:t.providers.selected?.[n.slug],onChange:r=>e.updateProxy({providers:{mode:`selected`,selected:{...t.providers.selected,[n.slug]:r}}})},n.slug)):null,(0,I.jsx)(zD,{rewrites:t.model_rewrites??{},onChange:t=>e.updateProxy({model_rewrites:t})})]})}function VD({open:e,onOpenChange:t,title:n,description:r,confirmLabel:i=`Confirm`,confirmWord:a,destructive:o,pending:s,onConfirm:c}){let[l,u]=(0,v.useState)(``);return(0,I.jsx)(KE,{open:e,onOpenChange:e=>{e||u(``),t(e)},children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:n})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{asChild:!0,children:(0,I.jsx)(`div`,{className:`space-y-2 text-sm text-muted-foreground`,children:r})}),a?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsxs)(ow,{htmlFor:`confirm-word`,className:`text-xs`,children:[`Type `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:a}),` to continue`]}),(0,I.jsx)($,{id:`confirm-word`,value:l,autoComplete:`off`,className:`font-mono`,onChange:e=>u(e.target.value)})]}):null]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(Y,{variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,I.jsx)(Y,{variant:o?`destructive`:`default`,disabled:!(!a||l===a)||s,onClick:c,children:i})]})]})})}function HD({appId:e,state:t}){let n=t.draft,r=ht(),i=FS(),{readOnly:a}=ox(),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(!1),u=async()=>{try{await navigator.clipboard.writeText(e),l(!0),U.success(`Application id copied`)}catch{U.error(`Could not copy the application id`)}},d=async()=>{try{let t=await i.mutateAsync(e);U.success(`Deleted ${n.name}`,{description:`${t.removed_users} users removed. Usage history was kept.`}),r(`/apps`)}catch(e){U.error(e instanceof Error?e.message:`Could not delete the app`)}};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(nE,{children:(0,I.jsxs)(oE,{className:`space-y-5`,children:[(0,I.jsx)(sw,{label:`Name`,htmlFor:`app-name`,children:(0,I.jsx)($,{id:`app-name`,value:n.name,maxLength:100,disabled:a,className:`max-w-md`,onChange:e=>t.update({name:e.target.value})})}),(0,I.jsx)(sw,{label:`Application id`,htmlFor:`app-id`,hint:`Fixed when the app was created. It is part of every URL your clients call.`,children:(0,I.jsxs)(`div`,{className:`flex max-w-md gap-2`,children:[(0,I.jsx)($,{id:`app-id`,value:e,readOnly:!0,className:`font-mono text-xs`}),(0,I.jsxs)(Y,{type:`button`,variant:`outline`,className:`min-w-24`,onClick:()=>void u(),children:[c?(0,I.jsx)(ra,{className:`size-4`}):(0,I.jsx)(ha,{className:`size-4`}),c?`Copied`:`Copy`]})]})})]})}),(0,I.jsx)(nE,{children:(0,I.jsx)(oE,{children:(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:`App enabled`}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Turned off, this app refuses every request. Nothing is deleted, and turning it back on restores it as it was.`})]}),(0,I.jsx)(CD,{"aria-label":`App enabled`,checked:n.status===`active`,disabled:a,onCheckedChange:e=>t.update({status:e?`active`:`disabled`})})]})})}),(0,I.jsx)(nE,{className:`border-destructive/40`,children:(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Delete this app`,description:`Clients of this app stop working immediately. Registered users and App Attest keys are removed. Usage history is kept for accounting.`,action:(0,I.jsx)(iw,{variant:`destructive`,size:`sm`,disabled:i.isPending,onClick:()=>s(!0),children:`Delete app`})})})}),(0,I.jsx)(VD,{open:o,onOpenChange:s,title:`Delete ${n.name}?`,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`p`,{children:`Clients of this app stop working immediately. Registered users and App Attest keys are removed; usage history is kept for accounting.`}),(0,I.jsx)(`p`,{children:`This cannot be undone.`})]}),confirmWord:e,confirmLabel:`Delete app`,destructive:!0,pending:i.isPending,onConfirm:()=>void d()})]})}var UD=25;function WD({appId:e}){let[t,n]=(0,v.useState)(yC()),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(`all`),[s,c]=(0,v.useState)(0),[l,u]=(0,v.useState)(null),d=zS(e,{month:t,query:r||void 0,status:a===`all`?void 0:a,limit:UD,offset:s*UD}),f=BS(e),p=async()=>{if(!l)return;let e=l.status===`active`;try{await f.mutateAsync({userId:l.id,blocked:e}),U.success(e?`Blocked ${l.id}`:`Unblocked ${l.id}`,{description:e?`Their Durable Object was updated, so it applies even to a live gateway token.`:void 0}),u(null)}catch(e){U.error(e instanceof Error?e.message:`Could not update the user`)}},m=d.data?.total??0,h=Math.max(1,Math.ceil(m/UD));return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,I.jsxs)(`div`,{className:`relative min-w-[220px] flex-1`,children:[(0,I.jsx)(Ia,{className:`absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,I.jsx)($,{value:r,placeholder:`Search user id`,className:`h-9 pl-8 font-mono text-xs`,onChange:e=>{i(e.target.value),c(0)}})]}),(0,I.jsxs)(zT,{value:a,onValueChange:e=>{o(e),c(0)},children:[(0,I.jsx)(VT,{className:`w-[140px]`,size:`sm`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`all`,children:`All users`}),(0,I.jsx)(UT,{value:`active`,children:`Active`}),(0,I.jsx)(UT,{value:`blocked`,children:`Blocked`})]})]}),(0,I.jsx)(qT,{value:t,onChange:n})]}),(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`User`}),(0,I.jsx)(Z,{children:`Attestation`}),(0,I.jsx)(Z,{children:`Last seen`}),(0,I.jsx)(Z,{className:`text-right`,children:`Requests`}),(0,I.jsx)(Z,{className:`text-right`,children:`Tokens`}),(0,I.jsx)(Z,{className:`text-right`,children:`Cost`}),(0,I.jsx)(Z,{className:`w-24`})]})}),(0,I.jsx)(lE,{children:d.isPending?[0,1,2].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:7,children:(0,I.jsx)(aw,{className:`h-8 w-full`})})},e)):d.data?.users.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:7,className:`py-10 text-center text-sm text-muted-foreground`,children:`No users yet. A row appears once a client completes its first token exchange.`})}):d.data?.users.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{children:(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`font-mono text-xs`,children:e.id}),e.status===`blocked`?(0,I.jsx)(tC,{status:`blocked`}):null]})}),(0,I.jsx)(Q,{children:e.attest_registered?(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,I.jsx)(Ib,{variant:`secondary`,className:`text-[11px] font-normal`,children:`registered`}),(0,I.jsxs)(`span`,{className:`tabular text-[11px] text-muted-foreground`,children:[`counter `,e.attest_counter]})]}):(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.is_virtual?`server attributed`:`issuer token`})}),(0,I.jsx)(Q,{className:`text-xs text-muted-foreground`,children:hC(e.last_seen_at)}),(0,I.jsx)(Q,{className:`tabular text-right`,children:cC(e.usage.requests)}),(0,I.jsx)(Q,{className:`tabular text-right`,children:lC(vC(e.usage))}),(0,I.jsx)(Q,{className:`tabular text-right`,children:dC(e.usage.cost_usd)}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsx)(iw,{variant:`ghost`,size:`sm`,disabled:e.is_virtual,onClick:()=>u(e),className:e.status===`active`?`text-destructive`:void 0,children:e.status===`active`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)($i,{className:`size-3.5`}),`Block`]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(la,{className:`size-3.5`}),`Unblock`]})})})]},e.id))})]})}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-muted-foreground`,children:[(0,I.jsxs)(`span`,{children:[cC(m),` users · page `,s+1,` of `,h]}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(Y,{variant:`outline`,size:`sm`,disabled:s===0,onClick:()=>c(e=>e-1),children:`Previous`}),(0,I.jsx)(Y,{variant:`outline`,size:`sm`,disabled:s+1>=h,onClick:()=>c(e=>e+1),children:`Next`})]})]}),(0,I.jsx)(VD,{open:l!==null,onOpenChange:e=>!e&&u(null),title:l?.status===`active`?`Block ${l?.id}?`:`Unblock ${l?.id}?`,description:l?.status===`active`?(0,I.jsx)(`p`,{children:`Their requests are refused immediately, even with an unexpired gateway token, because the block is written to their Durable Object as well as D1.`}):(0,I.jsx)(`p`,{children:`Their requests resume as soon as the Durable Object is updated.`}),confirmLabel:l?.status===`active`?`Block user`:`Unblock user`,destructive:l?.status===`active`,pending:f.isPending,onConfirm:()=>void p()})]})}var GD=(0,v.lazy)(()=>w(()=>import(`./usage-DbEmt1ps.js`).then(e=>({default:e.UsageTab})),[])),KD=(0,v.lazy)(()=>w(()=>import(`./endpoints-CpkgQRHP.js`).then(e=>({default:e.EndpointsTab})),[]));function qD(){let{appId:e=``,tab:t=`overview`,section:n}=_t(),r=QT(e),[i,a]=(0,v.useState)(yC()),o=iC.find(e=>e.slug===t),{query:s,draft:c,dirty:l}=r,u=c?tE(c):null;return s.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load this app`}),(0,I.jsxs)(ks,{children:[s.error instanceof Error?s.error.message:`Unknown error`,(0,I.jsx)(Pn,{to:`/apps`,className:`underline underline-offset-4`,children:`Back to apps`})]})]}):(0,I.jsxs)(`div`,{className:`space-y-6 pb-24`,children:[(0,I.jsx)(cw,{title:o?.label??`Overview`,action:t===`overview`?(0,I.jsx)(qT,{value:i,onChange:a}):void 0}),s.data?.config_error?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`The stored configuration is invalid`}),(0,I.jsxs)(ks,{children:[s.data.config_error,`. The gateway rejects requests for this app until it is fixed.`]})]}):null,c?(0,I.jsx)(RT,{proxy:c.config.routing}):null,s.isPending||!c?(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(aw,{className:`h-32 w-full`}),(0,I.jsx)(aw,{className:`h-64 w-full`})]}):t===`overview`?(0,I.jsx)(xD,{appId:e,month:i,state:r}):t===`auth`?(0,I.jsx)(dD,{appId:e,level:n,state:r}):t===`proxy`?(0,I.jsx)(BD,{state:r}):t===`limits`?(0,I.jsx)(yD,{state:r}):t===`users`?(0,I.jsx)(WD,{appId:e}):t===`auth-events`?(0,I.jsx)(hE,{appId:e}):t===`settings`?(0,I.jsx)(HD,{appId:e,state:r}):(0,I.jsx)(v.Suspense,{fallback:(0,I.jsx)(aw,{className:`h-64 w-full`}),children:t===`usage`?(0,I.jsx)(GD,{appId:e}):(0,I.jsx)(KD,{appId:e,state:r})}),l?(0,I.jsx)(`div`,{className:`fixed inset-x-0 bottom-0 z-40 border-t bg-background/95 backdrop-blur`,children:(0,I.jsxs)(`div`,{className:`mx-auto flex max-w-7xl items-center gap-3 px-4 py-3 sm:px-6`,children:[(0,I.jsxs)(`span`,{className:`text-sm`,children:[(0,I.jsx)(`span`,{className:`mr-2 inline-block size-2 rounded-full bg-amber-500 align-middle`}),`Unsaved changes to `,(0,I.jsx)(`span`,{className:`font-medium`,children:c?.name??e})]}),(0,I.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,I.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:r.reset,disabled:r.saving,children:`Discard`}),(0,I.jsxs)(iw,{size:`sm`,reason:u??void 0,onClick:()=>void r.save(),disabled:r.saving,children:[r.saving?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Save changes`]})]})]})}):null]})}var JD=[{id:`ios`,label:`iOS application`,description:`Calls AI providers straight from the app.`,icon:Ua},{id:`server`,label:`Server`,description:`A backend you run, using a private API key.`,icon:La}],YD={basics:{id:`basics`,label:`Basics`},app_identity:{id:`app_identity`,label:`Application identity`,subtitle:`Application identity`,text:`Set your app's identity so that only this app can call AI providers through this gateway.`},users:{id:`users`,label:`User authentication`,subtitle:`User authentication`,text:`Choose whether only users signed in to your app can call AI through this gateway.`},identity_provider:{id:`identity_provider`,label:`Identity provider`,subtitle:`Identity provider`,text:`Where your users sign in. The gateway verifies their sign-in tokens against it.`},subscription:{id:`subscription`,label:`Subscription check`,subtitle:`Subscription check`,text:`Check that the user has paid for the app before they can call AI providers through this gateway.`}},XD=IE.find(e=>e.id===`none`);function ZD({trigger:e}={}){let{capabilities:t}=ox(),[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(0),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(void 0),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)(DE[0]),[x,S]=(0,v.useState)({}),[C,w]=(0,v.useState)(XD),[T,E]=(0,v.useState)({}),[ee,D]=(0,v.useState)(null),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(!1),[te,ne]=(0,v.useState)(!1),M=ht(),N=PS(),P=(0,v.useMemo)(()=>{let e=[YD.basics];return c===`ios`&&e.push(YD.app_identity),e.push(YD.users),g===`issuer`&&e.push(YD.identity_provider,YD.subscription),e},[c,g]),re=P[Math.min(i,P.length-1)],ie=i>=P.length-1,ae=(0,v.useMemo)(()=>TE(y,x),[y,x]),oe=LE(y,x)&&ae.jwks_url.startsWith(`https://`)&&ae.issuer.length>0&&ae.audience.length>0,F=(()=>{switch(re.id){case`basics`:return o.trim().length>0&&c!==null;case`app_identity`:return u.trim().length>0&&f.trim().length>0;case`users`:return g!==null;case`identity_provider`:return oe;case`subscription`:return LE(C,T)}})(),se=()=>{a(0),s(``),l(null),d(``),p(``),h(void 0),_(null),b(DE[0]),S({}),w(XD),E({})},ce=e=>{e&&se(),r(e)},le=e=>{e!==c&&(l(e),_(null))},ue=()=>{let e=g===`issuer`?{source:`issuer`,issuer:{provider:y.id,jwks_url:ae.jwks_url,issuer:ae.issuer,audience:ae.audience,user_id_claim:ae.user_id_claim,required_claims:EE(C,T),max_token_lifetime_seconds:86400,...C.id===`none`?{}:{entitlement:C.id}}}:null;return c===`ios`?{type:`apple_app_attest`,app_attest:{team_id:u.trim(),bundle_id:f.trim(),...m?.includes(`development`)?{environments:m}:{}},end_user:e??{source:`app_install`}}:e?{type:`api_key`,end_user:e}:g===`header`?{type:`api_key`,end_user:{source:`header`,header:iT}}:{type:`api_key`}},de=async()=>{if(c)try{let e=await N.mutateAsync({name:o.trim(),config:{authentication:ue(),routing:{providers:{mode:`all`},model_rewrites:{}},...c===`server`?{}:{limits:{per_user:{requests:{per_minute:10,per_day:300},spending:{monthly_usd:null}},per_app:{requests:{per_minute:null,per_day:null},spending:{monthly_usd:null}}}}},status:`active`});if(r(!1),c===`server`){if(!e.api_key)throw Error(`The app was created without its initial API key`);k(e.app.id),D(e.api_key),ne(!1),j(!0);return}U.success(`Created ${e.app.id}`),M(`/apps/${e.app.id}/proxy`)}catch(e){U.error(e instanceof Error?e.message:`Could not create the app`)}},fe=()=>{_(c===`ios`?`app_install`:`none`),a(P.findIndex(e=>e.id===`users`))},pe=()=>{if(ie){de();return}a(e=>e+1)},me=async()=>{if(ee)try{await navigator.clipboard.writeText(ee.key),ne(!0),U.success(`API key copied`)}catch{U.error(`Could not copy the API key`)}},he=()=>{j(!1),U.success(`Created ${O}`),M(`/apps/${O}/proxy`)};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(KE,{open:n,onOpenChange:ce,children:[(0,I.jsx)(qE,{asChild:!0,children:e??(0,I.jsxs)(iw,{size:`sm`,children:[(0,I.jsx)(Na,{className:`size-4`}),`New app`]})}),(0,I.jsxs)(XE,{className:`sm:max-w-2xl`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:`Create a new application`})}),(0,I.jsxs)(QE,{className:`space-y-6`,children:[re.subtitle?(0,I.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,I.jsx)(`h3`,{className:`text-base font-semibold`,children:re.subtitle}),re.text?(0,I.jsx)(`p`,{className:`text-sm text-pretty text-muted-foreground`,children:re.text}):null]}):null,re.id===`basics`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`app-name`,children:`Application name`}),(0,I.jsx)($,{id:`app-name`,value:o,placeholder:`Calorie Tracker`,maxLength:100,autoFocus:!0,onChange:e=>s(e.target.value)})]}),(0,I.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,I.jsx)(`legend`,{className:`text-sm font-medium`,children:`Application type`}),(0,I.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2`,role:`radiogroup`,children:JD.map(e=>{let t=e.icon,n=c===e.id;return(0,I.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,className:H(`group min-h-32 rounded-xl bg-background p-5 text-left shadow-sm ring-1 ring-border transition-[box-shadow,background-color] hover:bg-muted/40 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,n&&`bg-primary/[0.04] shadow-md ring-2 ring-primary`),onClick:()=>le(e.id),children:[(0,I.jsx)(`span`,{className:H(`mb-3 flex size-10 items-center justify-center rounded-lg bg-muted text-muted-foreground transition-[background-color,color]`,n&&`bg-primary text-primary-foreground`),children:(0,I.jsx)(t,{className:`size-5`})}),(0,I.jsx)(`span`,{className:`block text-sm font-semibold`,children:e.label}),(0,I.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-muted-foreground`,children:e.description})]},e.id)})})]})]}):null,re.id===`app_identity`?(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-team-id`,children:`Apple Team ID`}),(0,I.jsx)($,{id:`apple-team-id`,value:u,placeholder:`ABCDE12345`,className:`font-mono text-xs`,autoFocus:!0,onChange:e=>d(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In your Apple Developer account under`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/account#MembershipDetailsCard`,children:`Membership details`}),`.`]})]}),(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-bundle-id`,children:`Bundle ID`}),(0,I.jsx)($,{id:`apple-bundle-id`,value:f,placeholder:`com.example.calorietracker`,className:`font-mono text-xs`,onChange:e=>p(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In Xcode, on your target's`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/documentation/xcode/configuring-the-build-settings-of-a-target#Set-the-bundle-ID`,children:`Signing & Capabilities`}),` `,`tab.`]})]})]}),(0,I.jsx)(vE,{value:m,onChange:h,compact:!0})]}):null,re.id===`users`?(0,I.jsx)(yE,{label:`User authentication`,choices:c===`ios`?WE:GE,value:g,onChange:_}):null,re.id===`identity_provider`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(xE,{idPrefix:`issuer`,label:`Identity provider`,presets:DE,selected:y,values:x,compact:!0,onSelect:e=>{b(e),S({})},onValueChange:(e,t)=>S(n=>({...n,[e]:t}))}),(0,I.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Don't have these details yet?`,` `,(0,I.jsx)(`button`,{type:`button`,className:`font-medium text-primary-ink underline decoration-primary-ink/40 underline-offset-4 transition-colors hover:decoration-primary-ink`,onClick:fe,children:c===`ios`?`Allow unauthenticated users for now`:`Continue without user identity for now`}),` `,`and set this up later.`]})]}):null,re.id===`subscription`?(0,I.jsx)(xE,{idPrefix:`entitlement`,label:FE,presets:IE,selected:C,values:T,compact:!0,onSelect:e=>{w(e),E({})},onValueChange:(e,t)=>E(n=>({...n,[e]:t}))}):null]}),(0,I.jsxs)($E,{className:`items-center sm:justify-between`,children:[i>0?(0,I.jsxs)(Y,{variant:`ghost`,onClick:()=>a(e=>e-1),disabled:N.isPending,children:[(0,I.jsx)(Xi,{className:`size-4`}),`Back`]}):(0,I.jsx)(Y,{variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,I.jsx)(QD,{steps:P,current:i,onSelect:a}),(0,I.jsxs)(Y,{disabled:!F||N.isPending,onClick:pe,children:[N.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,ie?`Create app`:`Next`]})]})]})]}),(0,I.jsx)(KE,{open:A,onOpenChange:e=>{e||he()},children:(0,I.jsxs)(XE,{showCloseButton:!1,className:`sm:max-w-lg`,onEscapeKeyDown:e=>e.preventDefault(),children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{className:`text-balance`,children:`Your application is ready`})}),(0,I.jsxs)(QE,{className:`space-y-5`,children:[(0,I.jsxs)(tD,{className:`text-pretty`,children:[`This is the API key for`,` `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:O}),`. It is shown only once, so copy it now.`]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`created-api-key`,children:`API key`}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)($,{id:`created-api-key`,value:ee?.key??``,readOnly:!0,className:`font-mono text-xs`}),(0,I.jsxs)(Y,{type:`button`,variant:`outline`,className:`min-w-24`,onClick:()=>void me(),children:[te?(0,I.jsx)(ra,{className:`size-4`}):(0,I.jsx)(ha,{className:`size-4`}),te?`Copied`:`Copy`]})]})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:`Base URL`}),(0,I.jsxs)(`code`,{className:`block rounded-md bg-muted px-3 py-2 font-mono text-xs break-all text-muted-foreground`,children:[bD(t),`/v1/apps/`,(0,I.jsx)(`span`,{className:`text-foreground`,children:O}),`/proxy/{provider}/{provider_path}`]})]})]}),(0,I.jsx)($E,{children:(0,I.jsx)(Y,{onClick:he,children:`I’ve saved this key`})})]})})]})}function QD({steps:e,current:t,onSelect:n}){return(0,I.jsx)(`ol`,{className:`flex items-center gap-2`,"aria-label":`Steps`,children:e.map((e,r)=>{let i=r<t,a=r===t,o=(0,I.jsx)(`span`,{className:H(`block size-2 rounded-full transition-colors`,a?`bg-primary`:i?`bg-primary/40`:`bg-border`)});return(0,I.jsx)(`li`,{"aria-current":a?`step`:void 0,children:i?(0,I.jsx)(`button`,{type:`button`,"aria-label":`Back to ${e.label}`,className:`flex size-5 items-center justify-center rounded-full hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>n(r),children:o}):(0,I.jsx)(`span`,{className:`flex size-5 items-center justify-center`,"aria-label":`${e.label}${a?`, current step`:``}`,children:o})},e.id)})})}function $D({label:e,children:t}){return(0,I.jsxs)(Lb,{children:[(0,I.jsx)(Rb,{asChild:!0,children:(0,I.jsx)(Y,{variant:`ghost`,size:`icon-sm`,"aria-label":`Actions for ${e}`,children:(0,I.jsx)(_a,{})})}),(0,I.jsx)(zb,{align:`end`,className:`min-w-44`,children:t})]})}function eO({reason:e,destructive:t,onSelect:n,children:r}){let{readOnly:i}=ox(),a=(0,v.useId)(),o=e??(i?`Your role is read-only. Ask an owner or admin to make this change.`:void 0),s=t?`destructive`:`default`;return o?(0,I.jsx)(rw,{reason:o,reasonId:a,className:`w-full`,children:(0,I.jsx)(Bb,{variant:s,disabled:!0,"aria-describedby":a,className:`w-full`,children:r})}):(0,I.jsx)(Bb,{variant:s,onSelect:n,children:r})}var tO={"data-1p-ignore":`true`,"data-lpignore":`true`},nO={autoComplete:`off`,...tO},rO={type:`password`,autoComplete:`new-password`,spellCheck:!1,...tO};function iO(e){return Object.entries(e??{}).map(([e,t])=>({model:e,input:String(t.input),output:String(t.output)}))}function aO(e){let t={};for(let n of e){let e=n.model.trim(),r=n.input.trim(),i=n.output.trim();if(!e&&!r&&!i)continue;if(!e)return{error:`Every pricing row needs a model name`};if(!r||!i)return{error:`Enter both prices for ${e} — use 0 only if it is genuinely free`};let a=Number(r),o=Number(i);if(!Number.isFinite(a)||a<0||!Number.isFinite(o)||o<0)return{error:`Prices for ${e} must be numbers of 0 or more`};if(Object.hasOwn(t,e))return{error:`${e} is priced twice — remove the duplicate row`};t[e]={input:a,output:o}}return{pricing:t}}function oO(e,t){return e instanceof Error?e.message:t}var sO=e=>`gateway-${e}`,cO=`/providers/gateways`;function lO(e){if(e.referencedCount!==0)return e.providerCount===0?`Disabled provider instances still reference this gateway; delete them to release it`:e.referencedCount>e.providerCount?`Delete the active and disabled provider instances routed through this gateway first`:`Delete every active provider instance routed through this gateway first`}function uO({label:e,value:t}){return(0,I.jsxs)(`div`,{children:[e,`: `,(0,I.jsx)(`span`,{className:`font-mono text-xs`,children:t})]})}function dO({row:e,gateways:t}){if(e.providerGatewayId===null)return(0,I.jsxs)(`div`,{className:`space-y-0.5`,children:[e.secretHint===null?(0,I.jsx)(`div`,{children:`API key`}):(0,I.jsx)(uO,{label:`API key`,value:`…${e.secretHint}`}),e.baseUrl===null?null:(0,I.jsx)(uO,{label:`Base URL`,value:e.baseUrl})]});let n=t.find(t=>t.id===e.providerGatewayId);return n?(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[`Gateway:`,(0,I.jsx)(NT,{type:n.type}),(0,I.jsx)(Pn,{className:`text-primary-ink underline underline-offset-4`,to:`${cO}#${sO(n.id)}`,children:n.name})]}):(0,I.jsx)(I.Fragment,{children:`Gateway`})}function fO({gateway:e}){return(0,I.jsxs)(`div`,{className:`space-y-0.5`,children:[e.type===`cf_aig`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(uO,{label:`Account ID`,value:e.config.accountId}),(0,I.jsx)(uO,{label:`Gateway ID`,value:e.config.gatewayId})]}):null,(0,I.jsx)(uO,{label:`API key`,value:`…${e.secretHint}`})]})}var pO=[{slug:`providers`,path:`/providers`,Component:vO},{slug:`gateways`,path:cO,Component:OO}],mO=pO[0];function hO(){return(0,I.jsx)(Ib,{variant:`outline`,className:`border-muted-foreground/30 text-muted-foreground`,children:`disabled`})}function gO({slug:e,names:t}){return t.length===0?null:(0,I.jsxs)(`p`,{children:[(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:t.join(`, `)}),` `,t.length===1?`names`:`name`,` `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:e}),` in its configuration.`]})}function _O(){let{section:e}=_t(),t=e===void 0?mO:pO.find(t=>t.slug===e);return t?(0,I.jsx)(t.Component,{}):(0,I.jsx)(Vt,{to:mO.path,replace:!0})}function vO(){let{readOnly:e}=ox(),t=dS(),n=_S(),r=wS(),i=CS(),a=jS(yC()),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(null),g=t.data?.providers??[],_=n.data?.gateways??[],y=e=>(a.data?.apps??[]).filter(t=>t.referenced_providers.includes(e)).map(e=>e.name),b=async()=>{if(f)try{await r.mutateAsync(f.id),U.success(`Deleted ${f.name}`),p(null)}catch(e){U.error(oO(e,`Could not delete the provider`))}},x=async()=>{if(m)try{await i.mutateAsync({id:m.id,body:{status:`disabled`}}),U.success(`Disabled ${m.name}`),h(null)}catch(e){U.error(oO(e,`Could not disable the provider`))}},S=async e=>{try{await i.mutateAsync({id:e.id,body:{status:`active`}}),U.success(`Enabled ${e.name}`)}catch(e){U.error(oO(e,`Could not enable the provider`))}};return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Providers`,description:`Set up the AI providers your apps use.`,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>s(!0),children:[(0,I.jsx)(Na,{className:`size-4`}),`Add provider`]})}),t.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load providers`}),(0,I.jsx)(ks,{children:oO(t.error,`Unknown error`)})]}):null,(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Provider`}),(0,I.jsx)(Z,{children:`Slug`}),(0,I.jsx)(Z,{children:`Auth`}),(0,I.jsx)(Z,{className:`text-right`,children:`Actions`})]})}),(0,I.jsx)(lE,{children:t.isPending?[0,1,2].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,children:(0,I.jsx)(aw,{className:`h-5 w-full`})})},e)):g.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,className:`py-10 text-center text-sm text-muted-foreground`,children:`No providers yet. Add a key per provider, or route one through a gateway.`})}):g.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{className:`font-medium`,children:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.name,e.status===`disabled`?(0,I.jsx)(hO,{}):null]})}),(0,I.jsx)(Q,{children:(0,I.jsxs)(Ib,{variant:`secondary`,children:[(0,I.jsx)(MT,{type:e.type}),eT[e.type]]})}),(0,I.jsx)(Q,{className:`font-mono text-xs`,children:e.slug}),(0,I.jsx)(Q,{className:`text-sm text-muted-foreground`,children:(0,I.jsx)(dO,{row:e,gateways:_})}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsxs)($D,{label:e.name,children:[(0,I.jsxs)(Bb,{onSelect:()=>l(e),children:[(0,I.jsx)(da,{}),`Pricing`]}),(0,I.jsxs)(eO,{reason:e.providerGatewayId===null?void 0:`This instance authenticates with the gateway token — update the gateway's token instead`,onSelect:()=>d(e),children:[(0,I.jsx)(Pa,{}),`Update key`]}),(0,I.jsx)(Wb,{}),e.status===`disabled`?(0,I.jsxs)(eO,{onSelect:()=>void S(e),children:[(0,I.jsx)(fa,{}),`Enable provider`]}):(0,I.jsxs)(eO,{onSelect:()=>h(e),children:[(0,I.jsx)(pa,{}),`Disable provider`]}),(0,I.jsxs)(eO,{destructive:!0,onSelect:()=>p(e),children:[(0,I.jsx)(Ga,{}),`Delete provider`]})]})})]},e.id))})]})}),(0,I.jsx)(EO,{open:o,onOpenChange:s,providers:g,gateways:_}),(0,I.jsx)(MO,{provider:u,onClose:()=>d(null)},u?.id),(0,I.jsx)(NO,{provider:c,onClose:()=>l(null),readOnly:e}),(0,I.jsx)(VD,{open:f!==null,onOpenChange:e=>{e||p(null)},title:`Delete provider`,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`p`,{children:[`Apps using`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:f?eT[f.type]:``}),` `,`start failing within a minute, and any custom pricing on this provider is deleted with it.`]}),f?(0,I.jsx)(gO,{slug:f.slug,names:y(f.slug)}):null,(0,I.jsx)(`p`,{children:`This cannot be undone. Update the key instead if you only want to replace it, or disable the provider to pause it and keep the key.`})]}),confirmLabel:`Delete provider`,destructive:!0,pending:r.isPending,onConfirm:()=>void b()}),(0,I.jsx)(VD,{open:m!==null,onOpenChange:e=>{e||h(null)},title:`Disable provider`,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`p`,{children:[`Requests to`,` `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:m?.slug??``}),` start failing within a minute.`]}),m?(0,I.jsx)(gO,{slug:m.slug,names:y(m.slug)}):null]}),confirmLabel:`Disable provider`,pending:i.isPending,onConfirm:()=>void x()})]})}var yO=`__new__`,bO={works:{icon:la,className:`bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`},unconfirmed:{icon:xa,className:`bg-muted text-muted-foreground`},failed:{icon:ca,className:`bg-destructive/10 text-destructive`}};function xO(e){return e.reason===`unexpected_status`&&e.status!==void 0&&e.status<500&&e.status!==429}function SO(e,t,n){let r=eT[t],i=n?`The gateway`:r;switch(e.reason){case`no_probe`:return`There is no test call for ${r}, so nothing was checked. Add it if you know it is right.`;case`unreachable`:return`${i} did not answer in time, so nothing is proven either way.`;case`unexpected_status`:return xO(e)?n?`The gateway answered with HTTP ${e.status}. Check that it holds a stored key for ${r}.`:`${r} answered with HTTP ${e.status}, so this key could not be used.`:`${i} answered with HTTP ${e.status}, so nothing is proven either way.`;default:return`Nothing is proven either way. Add it if you know it is right.`}}function CO(e,t,n){if(e.validated)return{status:`works`,message:`Works. The provider accepted this credential.`};let r=SO(e,t,n);return xO(e)?{status:`failed`,message:r}:{status:`unconfirmed`,message:r}}function wO(e){if(e.validated)return{status:`works`,message:`Works. The gateway accepted this token.`};if(e.reason===`rejected`)return{status:`failed`,message:`The gateway refused this token (HTTP ${e.status}). Check the token itself, that authentication is turned on, and that the gateway holds a key for OpenAI.`};if(e.reason===`unreachable`)return{status:`unconfirmed`,message:`The gateway did not answer in time, so nothing is proven either way.`};let t=e.reason===`unexpected_status`?`The gateway answered with HTTP ${e.status}. Check the account and gateway IDs.`:`Nothing is proven either way. Add it if you know it is right.`;return{status:xO(e)?`failed`:`unconfirmed`,message:t}}function TO({outcome:e}){let{icon:t,className:n}=bO[e.status];return(0,I.jsxs)(`p`,{"aria-live":`polite`,className:H(`flex items-start gap-2 rounded-md px-3 py-2 text-xs`,n),children:[(0,I.jsx)(t,{className:`mt-px size-3.5 shrink-0`}),e.message]})}function EO({open:e,onOpenChange:t,providers:n,gateways:r}){let i=mS(),a=hS(),[o,s]=(0,v.useState)(`openai`),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(`key`),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(``),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(null),[ee,D]=(0,v.useState)(null),O=(0,v.useRef)(null),k=(0,v.useRef)(!1);(0,v.useEffect)(()=>{!k.current||!O.current||(k.current=!1,O.current.focus())});let A=r.filter(e=>e.status===`active`),j=T&&!A.some(e=>e.id===T.id)?[...A,T]:A,te=e=>n.some(t=>t.slug===e),ne=x||te(o),M=e=>{s(e),S(!1),D(null),te(e)?k.current=!0:b(``)},N=u===`key`?!!f:!!g,P=!!c.trim()&&N&&(!ne||!!y.trim()),re=()=>{s(`openai`),l(``),d(`key`),p(``),h(``),_(``),b(``),S(!1),E(null),D(null),i.reset(),a.reset()},ie=()=>{re(),t(!1)},ae=u===`key`&&m.trim()?{baseUrl:m.trim()}:{},oe=async()=>{if(N){D(null);try{let e=await a.mutateAsync({type:o,...u===`key`?{secret:f,...ae}:{providerGatewayId:g}});D(CO(e,o,u===`gateway`))}catch(e){D({status:`failed`,message:oO(e,`The credential could not be checked`)})}finally{a.reset()}}},F=async()=>{if(P)try{await i.mutateAsync({type:o,name:c.trim(),...y.trim()?{slug:y.trim()}:{},...u===`key`?{secret:f,...ae}:{providerGatewayId:g}}),ie(),U.success(`Added ${eT[o]}`)}catch(e){p(``),e instanceof ux&&e.code===`slug_taken`&&(S(!0),k.current=!0),U.error(oO(e,`Could not store the credential`))}};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(nD,{open:e,onOpenChange:e=>e?t(!0):ie(),title:`Add a provider`,submitLabel:`Add provider`,pending:i.isPending,disabled:!P,onSubmit:()=>void F(),secondaryAction:(0,I.jsxs)(Y,{type:`button`,variant:`secondary`,className:`sm:mr-auto`,disabled:!N||a.isPending,onClick:()=>void oe(),children:[a.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Test provider`]}),children:(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(sw,{label:`Name`,htmlFor:`provider-name`,hint:`How this provider is named in the list.`,children:(0,I.jsx)($,{id:`provider-name`,...nO,value:c,placeholder:`Prod OpenAI`,autoFocus:!0,onChange:e=>l(e.target.value)})}),(0,I.jsx)(sw,{label:`Provider`,htmlFor:`provider-type`,children:(0,I.jsxs)(zT,{value:o,onValueChange:e=>M(e),children:[(0,I.jsx)(VT,{id:`provider-type`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:$w.map(e=>(0,I.jsx)(UT,{value:e,children:(0,I.jsx)(FT,{type:e})},e))})]})}),(0,I.jsx)(sw,{label:`Authentication`,htmlFor:`provider-authentication`,hint:`Call the provider directly, or route through a gateway.`,children:(0,I.jsxs)(zT,{value:u,onValueChange:e=>{d(e),e===`gateway`&&h(``),D(null)},children:[(0,I.jsx)(VT,{id:`provider-authentication`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsxs)(UT,{value:`key`,children:[(0,I.jsx)(Sa,{}),`API key`]}),(0,I.jsxs)(UT,{value:`gateway`,children:[(0,I.jsx)(ta,{}),`Use gateway`]})]})]})}),u===`key`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(sw,{label:`API key`,htmlFor:`provider-secret`,children:(0,I.jsx)($,{id:`provider-secret`,...rO,value:f,placeholder:`sk-…`,onChange:e=>{p(e.target.value),D(null)}})}),(0,I.jsx)(sw,{label:`Base URL (optional)`,htmlFor:`provider-base-url`,hint:`Point this instance at an OpenAI-compatible endpoint you control — Azure OpenAI, vLLM, a proxy. HTTPS, port 443, no path-only tweaks beyond the base. Leave empty to use the provider's own API.`,children:(0,I.jsx)($,{id:`provider-base-url`,...nO,className:`font-mono`,value:m,placeholder:`https://my-vllm.example.com/v1/`,onChange:e=>{h(e.target.value),D(null)}})})]}):(0,I.jsx)(sw,{label:`Gateway`,htmlFor:`provider-gateway`,hint:`The provider's own key lives in that gateway; this row carries no secret.`,children:(0,I.jsxs)(zT,{value:g,onValueChange:e=>{if(e){if(e===yO){w(!0);return}_(e),D(null)}},children:[(0,I.jsx)(VT,{id:`provider-gateway`,className:`w-full`,children:(0,I.jsx)(BT,{placeholder:j.length?`Choose a gateway`:`No gateways yet`})}),(0,I.jsxs)(HT,{children:[j.map(e=>(0,I.jsx)(UT,{value:e.id,children:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,I.jsx)(NT,{type:e.type}),e.name]})},e.id)),j.length?(0,I.jsx)(WT,{}):null,(0,I.jsxs)(UT,{value:yO,className:`font-medium text-primary-ink focus:text-primary-ink`,children:[(0,I.jsx)(Na,{className:`size-4 text-primary-ink`}),`New gateway…`]})]})]})}),ne?(0,I.jsx)(sw,{label:`Slug`,htmlFor:`provider-slug`,hint:(0,I.jsxs)(I.Fragment,{children:[`Another instance already uses `,(0,I.jsx)(`code`,{className:`font-mono`,children:o}),`, so this one needs its own `,(0,I.jsx)(`code`,{className:`font-mono`,children:`/proxy/<slug>/…`}),` `,`segment.`]}),children:(0,I.jsx)($,{id:`provider-slug`,ref:O,...nO,className:`font-mono`,value:y,placeholder:`${o}-dev`,onChange:e=>b(e.target.value)})}):null,ee?(0,I.jsx)(TO,{outcome:ee}):null]})}),(0,I.jsx)(kO,{open:C,onOpenChange:w,onCreated:e=>{E(e),_(e.id)}})]})}function DO({label:e=`Add provider`}){let[t,n]=(0,v.useState)(!1),r=dS(),i=_S(t);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(iw,{size:`sm`,onClick:()=>n(!0),children:e}),(0,I.jsx)(EO,{open:t,onOpenChange:n,providers:r.data?.providers??[],gateways:i.data?.gateways??[]})]})}function OO(){let e=_S(),[t,n]=(0,v.useState)(!1),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),l=SS(),u=e.data?.gateways??[],d=e.isError?e.error:null,{hash:f}=dt();(0,v.useEffect)(()=>{f&&document.getElementById(f.slice(1))?.scrollIntoView({behavior:`smooth`,block:`center`})},[f,e.data]);let p=async()=>{if(s)try{await l.mutateAsync(s.id),U.success(`Deleted ${s.name}`),c(null)}catch(e){U.error(oO(e,`Could not delete the gateway`))}};return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Gateways`,description:`Set up the gateways you use to reach AI providers.`,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>n(!0),children:[(0,I.jsx)(Na,{className:`size-4`}),`Add gateway`]})}),d?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load gateways`}),(0,I.jsx)(ks,{children:oO(d,`Unknown error`)})]}):null,(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Type`}),(0,I.jsx)(Z,{children:`Auth`}),(0,I.jsx)(Z,{className:`text-right`,children:`Actions`})]})}),(0,I.jsx)(lE,{children:e.isPending?[0,1].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:4,children:(0,I.jsx)(aw,{className:`h-5 w-full`})})},e)):u.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:4,className:`py-10 text-center text-sm text-muted-foreground`,children:`No gateways yet. Add one to route providers through it.`})}):u.map(e=>(0,I.jsxs)(uE,{id:sO(e.id),children:[(0,I.jsx)(Q,{className:`font-medium`,children:e.name}),(0,I.jsx)(Q,{children:(0,I.jsxs)(Ib,{variant:`secondary`,children:[(0,I.jsx)(NT,{type:e.type}),tT[e.type]]})}),(0,I.jsx)(Q,{className:`text-sm text-muted-foreground`,children:(0,I.jsx)(fO,{gateway:e})}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsxs)($D,{label:e.name,children:[(0,I.jsxs)(eO,{onSelect:()=>o(e),children:[(0,I.jsx)(Pa,{}),`Update token`]}),(0,I.jsxs)(eO,{onSelect:()=>i(e),children:[(0,I.jsx)(ja,{}),`Rename`]}),(0,I.jsx)(Wb,{}),(0,I.jsxs)(eO,{destructive:!0,reason:lO(e),onSelect:()=>c(e),children:[(0,I.jsx)(Ga,{}),`Delete gateway`]})]})})]},e.id))})]})}),(0,I.jsx)(kO,{open:t,onOpenChange:n}),(0,I.jsx)(AO,{gateway:r,onClose:()=>i(null)}),(0,I.jsx)(jO,{gateway:a,onClose:()=>o(null)}),(0,I.jsx)(VD,{open:s!==null,onOpenChange:e=>{e||c(null)},title:`Delete gateway`,description:(0,I.jsxs)(`p`,{children:[`The stored token for`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:s?.name}),` is destroyed. Nothing routes through it, so no traffic changes.`]}),confirmLabel:`Delete gateway`,destructive:!0,pending:l.isPending,onConfirm:()=>void p()})]})}function kO({open:e,onOpenChange:t,onCreated:n}){let r=yS(),i=gS(),[a,o]=(0,v.useState)(nT[0].value),s=nT.find(e=>e.value===a)??nT[0],[c,l]=(0,v.useState)(s.defaultName),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(null),y=!!(m&&(!s.needsCloudflareIds||u.trim()&&f.trim())),b=!!c.trim()&&y,x=()=>{o(nT[0].value),l(nT[0].defaultName),d(``),p(``),h(``),_(null),r.reset(),i.reset()},S=async()=>{if(y){_(null);try{let e=await i.mutateAsync(s.value===`cf_aig`?{type:`cf_aig`,accountId:u.trim(),gatewayId:f.trim(),token:m}:{type:`vercel`,token:m});_(wO(e))}catch(e){_({status:`failed`,message:oO(e,`The connection could not be checked`)})}finally{i.reset()}}},C=e=>{let t=nT.find(t=>t.value===e);t&&(o(e),l(t.defaultName),d(``),p(``),h(``),_(null))},w=()=>{x(),t(!1)},T=async()=>{if(b)try{let e=await r.mutateAsync(s.value===`cf_aig`?{type:`cf_aig`,name:c.trim(),accountId:u.trim(),gatewayId:f.trim(),token:m}:{type:`vercel`,name:c.trim(),token:m});x(),U.success(`Added ${e.gateway.name}`),n?.(e.gateway),t(!1)}catch(e){h(``),U.error(oO(e,`Could not add the gateway`))}};return(0,I.jsx)(nD,{open:e,onOpenChange:e=>e?t(!0):w(),title:`Add gateway`,submitLabel:`Add gateway`,pending:r.isPending,disabled:!b,onSubmit:()=>void T(),secondaryAction:(0,I.jsxs)(Y,{type:`button`,variant:`secondary`,className:`sm:mr-auto`,disabled:!y||i.isPending,onClick:()=>void S(),children:[i.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Test gateway`]}),children:(0,I.jsxs)(`div`,{className:`space-y-4`,children:[nT.length>1?(0,I.jsx)(sw,{label:`Gateway type`,htmlFor:`gateway-type`,children:(0,I.jsxs)(zT,{value:a,onValueChange:e=>C(e),children:[(0,I.jsx)(VT,{id:`gateway-type`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:nT.map(e=>(0,I.jsx)(UT,{value:e.value,children:(0,I.jsx)(IT,{type:e.value})},e.value))})]})}):null,(0,I.jsx)(sw,{label:`Name`,htmlFor:`gateway-name`,children:(0,I.jsx)($,{id:`gateway-name`,...nO,value:c,onChange:e=>l(e.target.value)})}),s.needsCloudflareIds?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(sw,{label:`Cloudflare Account ID`,htmlFor:`gateway-account`,children:(0,I.jsx)($,{id:`gateway-account`,...nO,value:u,onChange:e=>{d(e.target.value),_(null)}})}),(0,I.jsx)(sw,{label:`Cloudflare Gateway ID`,htmlFor:`gateway-gateway`,children:(0,I.jsx)($,{id:`gateway-gateway`,...nO,value:f,onChange:e=>{p(e.target.value),_(null)}})})]}):null,(0,I.jsx)(sw,{label:`Gateway token`,htmlFor:`gateway-token`,hint:(0,I.jsx)(`a`,{className:`underline underline-offset-4`,href:s.tokenDocsUrl,target:`_blank`,rel:`noreferrer`,children:`How to create the token`}),children:(0,I.jsx)($,{id:`gateway-token`,...rO,value:m,onChange:e=>{h(e.target.value),_(null)}})}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:s.credentialNote}),g?(0,I.jsx)(TO,{outcome:g}):null]})})}function AO({gateway:e,onClose:t}){let n=bS(),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(null);e&&a!==e.id&&(o(e.id),i(e.name));let s=()=>{o(null),t()},c=async()=>{if(!(!e||!r.trim()))try{await n.mutateAsync({id:e.id,name:r.trim()}),U.success(`Renamed to ${r.trim()}`),s()}catch(e){U.error(oO(e,`Could not rename the gateway`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>e?void 0:s(),children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:`Rename gateway`})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{children:`Only the display name changes. Nothing about the connection or the providers routed through it moves.`}),(0,I.jsx)(sw,{label:`Name`,htmlFor:`gateway-rename`,children:(0,I.jsx)($,{id:`gateway-rename`,...nO,value:r,onChange:e=>i(e.target.value)})})]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(Y,{variant:`outline`,onClick:s,children:`Cancel`}),(0,I.jsxs)(Y,{disabled:!r.trim()||n.isPending,onClick:()=>void c(),children:[n.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Save name`]})]})]})})}function jO({gateway:e,onClose:t}){let n=xS(),r=gS(),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(null),c=()=>{a(``),s(null),n.reset(),r.reset(),t()},l=async()=>{if(!(!e||!i)){s(null);try{let t=await r.mutateAsync(e.type===`cf_aig`?{type:`cf_aig`,accountId:e.config.accountId,gatewayId:e.config.gatewayId,token:i}:{type:`vercel`,token:i});s(wO(t))}catch(e){s({status:`failed`,message:oO(e,`The connection could not be checked`)})}finally{r.reset()}}},u=async()=>{if(!(!e||!i))try{await n.mutateAsync({id:e.id,token:i}),a(``),s(null),n.reset(),U.success(`Updated the token for ${e.name}`),t()}catch(e){a(``),U.error(oO(e,`Could not update the gateway token`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>e?void 0:c(),children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsxs)(eD,{children:[`Update the token for `,e?.name]})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsxs)(tD,{children:[`One token authenticates every provider routed through this gateway, so all`,` `,e?.providerCount??0,` of them pick the new one up within a minute.`]}),(0,I.jsx)(sw,{label:`New gateway token`,htmlFor:`gateway-rotate-token`,children:(0,I.jsx)($,{id:`gateway-rotate-token`,...rO,value:i,onChange:e=>{a(e.target.value),s(null)}})}),o?(0,I.jsx)(TO,{outcome:o}):null]}),(0,I.jsxs)($E,{children:[(0,I.jsxs)(Y,{type:`button`,variant:`secondary`,className:`sm:mr-auto`,disabled:!i||r.isPending,onClick:()=>void l(),children:[r.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Test token`]}),(0,I.jsx)(Y,{variant:`outline`,onClick:c,children:`Cancel`}),(0,I.jsxs)(Y,{disabled:!i||n.isPending,onClick:()=>void u(),children:[n.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Update token`]})]})]})})}function MO({provider:e,onClose:t}){let n=CS(),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(e?.baseUrl??``),s=()=>{i(``),n.reset(),t()},c=a.trim(),l=e&&c!==(e.baseUrl??``)?{baseUrl:c===``?null:c}:{},u=async()=>{if(!(!e||!r))try{await n.mutateAsync({id:e.id,body:{secret:r,...l}}),i(``),n.reset(),U.success(`Updated the key for ${e.name}`),t()}catch(e){i(``),U.error(oO(e,`Could not update the credential`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>e?void 0:s(),children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsxs)(eD,{children:[`Update the key for `,e?.name]})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{children:`The new credential replaces the old one in place. Custom pricing is kept, and requests pick it up within a minute.`}),(0,I.jsx)(sw,{label:`New API key`,htmlFor:`rotate-secret`,children:(0,I.jsx)($,{id:`rotate-secret`,...rO,value:r,onChange:e=>i(e.target.value)})}),(0,I.jsx)(sw,{label:`Base URL`,htmlFor:`rotate-base-url`,hint:`Changing the origin needs the key above, because the stored key is never sent to a new origin. Leave empty to use the provider's own API.`,children:(0,I.jsx)($,{id:`rotate-base-url`,...nO,className:`font-mono`,value:a,placeholder:`https://my-vllm.example.com/v1/`,onChange:e=>o(e.target.value)})})]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(Y,{variant:`outline`,onClick:s,children:`Cancel`}),(0,I.jsxs)(Y,{disabled:!r||n.isPending,onClick:()=>void u(),children:[n.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Update key`]})]})]})})}function NO({provider:e,onClose:t,readOnly:n}){let r=CS(),[i,a]=(0,v.useState)([]),[o,s]=(0,v.useState)(null);e&&o!==e.id&&(s(e.id),a(iO(e.pricing)));let c=(e,t)=>{a(n=>n.map((n,r)=>r===e?{...n,...t}:n))},l=async()=>{if(!e)return;let n=aO(i);if(`error`in n){U.error(n.error);return}try{await r.mutateAsync({id:e.id,body:{pricing:Object.keys(n.pricing).length?n.pricing:null}}),U.success(`Updated pricing for ${e.name}`),t()}catch(e){U.error(oO(e,`Could not save the pricing`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>{e||(s(null),t())},children:(0,I.jsxs)(XE,{className:`sm:max-w-2xl`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:`Custom model pricing`})}),(0,I.jsxs)(QE,{className:`space-y-3`,children:[(0,I.jsxs)(tD,{children:[`For models the built-in catalog does not cover, or prices it in a way you disagree with.`,e&&Qw(e.type)?` ${eT[e.type]??e.type} reports the cost of
|
|
76
76
|
every request, so its models proxy with no price here; a price entered here is
|
|
77
77
|
only used if a response ever comes back without one.`:` Requests for unpriced models are rejected until a price is set here.`,` `,`Enter $0 for a model that is genuinely free.`]}),i.length===0?(0,I.jsx)(uw,{children:`No custom prices for this provider.`}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{"aria-hidden":!0,className:`grid grid-cols-[2fr_1fr_1fr_auto] gap-2 text-xs text-muted-foreground`,children:[(0,I.jsx)(`span`,{children:`Model`}),(0,I.jsx)(`span`,{children:`Input $/1M`}),(0,I.jsx)(`span`,{children:`Output $/1M`}),(0,I.jsx)(`span`,{className:`w-9`})]}),i.map((e,t)=>(0,I.jsxs)(`div`,{className:`grid grid-cols-[2fr_1fr_1fr_auto] items-center gap-2`,children:[(0,I.jsx)($,{"aria-label":`Model ${t+1}`,value:e.model,placeholder:`gpt-brand-new`,disabled:n,onChange:e=>c(t,{model:e.target.value})}),(0,I.jsx)($,{"aria-label":`Input price ${t+1}`,inputMode:`decimal`,value:e.input,placeholder:`1.25`,disabled:n,onChange:e=>c(t,{input:e.target.value})}),(0,I.jsx)($,{"aria-label":`Output price ${t+1}`,inputMode:`decimal`,value:e.output,placeholder:`10`,disabled:n,onChange:e=>c(t,{output:e.target.value})}),(0,I.jsx)(Y,{variant:`ghost`,size:`icon`,"aria-label":`Remove pricing row ${t+1}`,disabled:n,onClick:()=>a(e=>e.filter((e,n)=>n!==t)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},t))]}),(0,I.jsxs)(Y,{variant:`outline`,size:`sm`,disabled:n,onClick:()=>a(e=>[...e,{model:``,input:``,output:``}]),children:[(0,I.jsx)(Na,{className:`size-4`}),`Add model`]})]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(Y,{variant:`outline`,onClick:t,children:`Cancel`}),(0,I.jsxs)(iw,{disabled:r.isPending,onClick:()=>void l(),children:[r.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Save pricing`]})]})]})})}var PO=4e3;function FO(){let e=dt(),t=ht(),n=ui(),r=(0,v.useRef)(!1),i=(0,v.useRef)(void 0),a=Bx(e.search);(0,v.useEffect)(()=>()=>clearTimeout(i.current),[]),(0,v.useEffect)(()=>{if(!a||r.current)return;r.current=!0,U.success(`Payment complete`,{description:`Your new plan is being activated.`}),_x.capture(`subscription_started`,{plan:Nx(e.search)??`unknown`});let o=()=>void n.invalidateQueries({queryKey:eS.billingStatus});o(),i.current=setTimeout(o,PO),t(Vx(e.pathname,e.search),{replace:!0})},[a,n,t,e.pathname,e.search])}function IO(e,t,n){let r=e.resolved?.routing;if(!r)return null;for(let e of t){if(e.status!==`active`)continue;let t=r.providers?.[e.slug];if(r.providerMode===`selected`&&!t)continue;let i=t?.allowed_models?.length?t.allowed_models:[...Object.keys(e.pricing??{}),...Object.entries(n[e.type]??{}).filter(([,e])=>e.output!==void 0).map(([e])=>e)],a=e.type===`openai`?`v1/responses`:e.type===`anthropic`?`v1/messages`:e.type===`gemini`?`v1beta/models/${i[0]}:generateContent`:!e.providerGatewayId&&e.type===`groq`?`openai/v1/chat/completions`:!e.providerGatewayId&&e.type===`fireworks`?`inference/v1/chat/completions`:!e.providerGatewayId&&[`deepseek`,`bytedance`].includes(e.type)?`chat/completions`:`v1/chat/completions`,o=t?.allowed_paths?.length?t.allowed_paths:[a];for(let t of o){let n=typeof t==`string`?t:t.path;if(n.includes(`*`))continue;let r=typeof t!=`string`&&t.fixed_model?t.fixed_model:i[0];if(!r)continue;let a=[{role:`user`,content:`Say hello.`}],o=n.endsWith(`responses`)?{model:r,input:`Say hello.`}:n.endsWith(`chat/completions`)?{model:r,messages:a}:n.endsWith(`messages`)?{model:r,max_tokens:128,messages:a}:n.endsWith(`:generateContent`)?{contents:[{parts:[{text:`Say hello.`}]}]}:null;if(o)return{provider:e.slug,path:n,body:o,anthropic:n.endsWith(`messages`)}}}return null}var LO=`https://docs.appaigateway.com/quickstart/`,RO=15e3;function zO({index:e,title:t,description:n,done:r,completedLabel:i,action:a,status:o}){return(0,I.jsxs)(`li`,{className:`grid grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-x-3 gap-y-2 sm:gap-x-4`,children:[(0,I.jsx)(`span`,{"aria-hidden":!0,className:`grid size-6 shrink-0 place-items-center rounded-full bg-muted text-xs font-semibold tabular`,children:e}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-0.5`,children:[(0,I.jsxs)(`p`,{className:H(`text-sm font-medium`,r&&`text-muted-foreground`),children:[t,r?(0,I.jsx)(`span`,{className:`sr-only`,children:` — done`}):null]}),(0,I.jsx)(`p`,{className:`text-sm text-pretty text-muted-foreground`,children:n})]}),(0,I.jsx)(`div`,{className:`shrink-0 sm:pt-0.5`,children:r?(0,I.jsx)(`span`,{className:`flex size-8 items-center justify-center text-primary`,role:`img`,"aria-label":i,children:(0,I.jsx)(ra,{className:`size-5`,"aria-hidden":!0})}):a}),o?(0,I.jsx)(`div`,{className:`col-span-2 col-start-2 min-w-0`,children:o}):null]})}function BO(){return(0,I.jsxs)(`p`,{className:`flex items-center gap-2 pt-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Waiting for your first request`,children:[(0,I.jsxs)(`span`,{className:`relative flex size-2`,"aria-hidden":!0,children:[(0,I.jsx)(`span`,{className:`absolute inline-flex size-full animate-ping rounded-full bg-primary opacity-60`}),(0,I.jsx)(`span`,{className:`relative inline-flex size-2 rounded-full bg-primary`})]}),`Waiting…`]})}function VO({app:e}){let t=MS(e.id),n=dS(),r=qS(),i=e.authentication_type===`apple_app_attest`;if(t.isPending||n.isPending||r.isPending)return(0,I.jsx)(aw,{className:`mt-4 h-32`});let a=t.data&&n.data&&r.data?IO(t.data,n.data.providers,r.data.prices):null;if(!a)return(0,I.jsx)(`p`,{className:`mt-3 text-sm text-muted-foreground`,children:`No text request example is available for this app’s current provider and model settings.`});let{provider:o,path:s,body:c,anthropic:l}=a,u=e=>`'${e.replaceAll(`'`,`'\\''`)}'`,d=window.location.origin;return(0,I.jsx)(`div`,{className:`mt-4 min-w-0 overflow-hidden rounded-lg border bg-muted/40`,children:(0,I.jsx)(`pre`,{className:`overflow-x-auto p-4 text-xs leading-relaxed`,children:(0,I.jsx)(`code`,{children:i?`import Foundation
|
|
78
78
|
import AppAIGateway
|