index-WAbnQRoa.js 139 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import{j as t,u as ke,a as W,b as V,Q as Gs,c as Ys}from"./query-C_q0vuOo.js";import{a as It,r as l,N as Xs,b as qt,u as ie,L as Te,O as Zs,c as Br,d as me,e as Bt,f as Ve,g as zt,h as ae,i as Js,j as en}from"./react-C4-CelXw.js";import{B as zr,R as Ur,S as ut,A as tn,I as rn,a as sn,b as _e,c as nn,M as an,d as on,C as cn,L as ln,u as A,X as dn,P as Ut,e as Wt,f as ct,T as un,E as Vt,g as Ht,h as mn,K as Wr,i as fn,$ as hn}from"./ui-DcUwFLzq.js";import{o as xn,r as pn,a as gn,b as Re,c as ze,n as mt,s as L,u as Pe,l as Y,e as Vr}from"./forms-BRRx31Es.js";(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))n(a);new MutationObserver(a=>{for(const o of a)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&n(i)}).observe(document,{childList:!0,subtree:!0});function s(a){const o={};return a.integrity&&(o.integrity=a.integrity),a.referrerPolicy&&(o.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?o.credentials="include":a.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function n(a){if(a.ep)return;a.ep=!0;const o=s(a);fetch(a.href,o)}})();var Hr,ir=It;Hr=ir.createRoot,ir.hydrateRoot;function Qr(e){var r,s,n="";if(typeof e=="string"||typeof e=="number")n+=e;else if(typeof e=="object")if(Array.isArray(e)){var a=e.length;for(r=0;r<a;r++)e[r]&&(s=Qr(e[r]))&&(n&&(n+=" "),n+=s)}else for(s in e)e[s]&&(n&&(n+=" "),n+=s);return n}function Kr(){for(var e,r,s=0,n="",a=arguments.length;s<a;s++)(e=arguments[s])&&(r=Qr(e))&&(n&&(n+=" "),n+=r);return n}const Qt="-",vn=e=>{const r=yn(e),{conflictingClassGroups:s,conflictingClassGroupModifiers:n}=e;return{getClassGroupId:i=>{const c=i.split(Qt);return c[0]===""&&c.length!==1&&c.shift(),Gr(c,r)||bn(i)},getConflictingClassGroupIds:(i,c)=>{const d=s[i]||[];return c&&n[i]?[...d,...n[i]]:d}}},Gr=(e,r)=>{if(e.length===0)return r.classGroupId;const s=e[0],n=r.nextPart.get(s),a=n?Gr(e.slice(1),n):void 0;if(a)return a;if(r.validators.length===0)return;const o=e.join(Qt);return r.validators.find(({validator:i})=>i(o))?.classGroupId},cr=/^\[(.+)\]$/,bn=e=>{if(cr.test(e)){const r=cr.exec(e)[1],s=r?.substring(0,r.indexOf(":"));if(s)return"arbitrary.."+s}},yn=e=>{const{theme:r,prefix:s}=e,n={nextPart:new Map,validators:[]};return wn(Object.entries(e.classGroups),s).forEach(([o,i])=>{Pt(i,n,o,r)}),n},Pt=(e,r,s,n)=>{e.forEach(a=>{if(typeof a=="string"){const o=a===""?r:lr(r,a);o.classGroupId=s;return}if(typeof a=="function"){if(jn(a)){Pt(a(n),r,s,n);return}r.validators.push({validator:a,classGroupId:s});return}Object.entries(a).forEach(([o,i])=>{Pt(i,lr(r,o),s,n)})})},lr=(e,r)=>{let s=e;return r.split(Qt).forEach(n=>{s.nextPart.has(n)||s.nextPart.set(n,{nextPart:new Map,validators:[]}),s=s.nextPart.get(n)}),s},jn=e=>e.isThemeGetter,wn=(e,r)=>r?e.map(([s,n])=>{const a=n.map(o=>typeof o=="string"?r+o:typeof o=="object"?Object.fromEntries(Object.entries(o).map(([i,c])=>[r+i,c])):o);return[s,a]}):e,Nn=e=>{if(e<1)return{get:()=>{},set:()=>{}};let r=0,s=new Map,n=new Map;const a=(o,i)=>{s.set(o,i),r++,r>e&&(r=0,n=s,s=new Map)};return{get(o){let i=s.get(o);if(i!==void 0)return i;if((i=n.get(o))!==void 0)return a(o,i),i},set(o,i){s.has(o)?s.set(o,i):a(o,i)}}},Yr="!",Sn=e=>{const{separator:r,experimentalParseClassName:s}=e,n=r.length===1,a=r[0],o=r.length,i=c=>{const d=[];let f=0,u=0,x;for(let v=0;v<c.length;v++){let j=c[v];if(f===0){if(j===a&&(n||c.slice(v,v+o)===r)){d.push(c.slice(u,v)),u=v+o;continue}if(j==="/"){x=v;continue}}j==="["?f++:j==="]"&&f--}const p=d.length===0?c:c.substring(u),h=p.startsWith(Yr),g=h?p.substring(1):p,m=x&&x>u?x-u:void 0;return{modifiers:d,hasImportantModifier:h,baseClassName:g,maybePostfixModifierPosition:m}};return s?c=>s({className:c,parseClassName:i}):i},_n=e=>{if(e.length<=1)return e;const r=[];let s=[];return e.forEach(n=>{n[0]==="["?(r.push(...s.sort(),n),s=[]):s.push(n)}),r.push(...s.sort()),r},Cn=e=>({cache:Nn(e.cacheSize),parseClassName:Sn(e),...vn(e)}),En=/\s+/,kn=(e,r)=>{const{parseClassName:s,getClassGroupId:n,getConflictingClassGroupIds:a}=r,o=[],i=e.trim().split(En);let c="";for(let d=i.length-1;d>=0;d-=1){const f=i[d],{modifiers:u,hasImportantModifier:x,baseClassName:p,maybePostfixModifierPosition:h}=s(f);let g=!!h,m=n(g?p.substring(0,h):p);if(!m){if(!g){c=f+(c.length>0?" "+c:c);continue}if(m=n(p),!m){c=f+(c.length>0?" "+c:c);continue}g=!1}const v=_n(u).join(":"),j=x?v+Yr:v,w=j+m;if(o.includes(w))continue;o.push(w);const y=a(m,g);for(let b=0;b<y.length;++b){const S=y[b];o.push(j+S)}c=f+(c.length>0?" "+c:c)}return c};function Tn(){let e=0,r,s,n="";for(;e<arguments.length;)(r=arguments[e++])&&(s=Xr(r))&&(n&&(n+=" "),n+=s);return n}const Xr=e=>{if(typeof e=="string")return e;let r,s="";for(let n=0;n<e.length;n++)e[n]&&(r=Xr(e[n]))&&(s&&(s+=" "),s+=r);return s};function Rn(e,...r){let s,n,a,o=i;function i(d){const f=r.reduce((u,x)=>x(u),e());return s=Cn(f),n=s.cache.get,a=s.cache.set,o=c,c(d)}function c(d){const f=n(d);if(f)return f;const u=kn(d,s);return a(d,u),u}return function(){return o(Tn.apply(null,arguments))}}const P=e=>{const r=s=>s[e]||[];return r.isThemeGetter=!0,r},Zr=/^\[(?:([a-z-]+):)?(.+)\]$/i,Pn=/^\d+\/\d+$/,An=new Set(["px","full","screen"]),Dn=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,On=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,Mn=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,Ln=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,Fn=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,J=e=>Ne(e)||An.has(e)||Pn.test(e),re=e=>Ae(e,"length",Vn),Ne=e=>!!e&&!Number.isNaN(Number(e)),Nt=e=>Ae(e,"number",Ne),Fe=e=>!!e&&Number.isInteger(Number(e)),$n=e=>e.endsWith("%")&&Ne(e.slice(0,-1)),_=e=>Zr.test(e),se=e=>Dn.test(e),In=new Set(["length","size","percentage"]),qn=e=>Ae(e,In,Jr),Bn=e=>Ae(e,"position",Jr),zn=new Set(["image","url"]),Un=e=>Ae(e,zn,Qn),Wn=e=>Ae(e,"",Hn),$e=()=>!0,Ae=(e,r,s)=>{const n=Zr.exec(e);return n?n[1]?typeof r=="string"?n[1]===r:r.has(n[1]):s(n[2]):!1},Vn=e=>On.test(e)&&!Mn.test(e),Jr=()=>!1,Hn=e=>Ln.test(e),Qn=e=>Fn.test(e),Kn=()=>{const e=P("colors"),r=P("spacing"),s=P("blur"),n=P("brightness"),a=P("borderColor"),o=P("borderRadius"),i=P("borderSpacing"),c=P("borderWidth"),d=P("contrast"),f=P("grayscale"),u=P("hueRotate"),x=P("invert"),p=P("gap"),h=P("gradientColorStops"),g=P("gradientColorStopPositions"),m=P("inset"),v=P("margin"),j=P("opacity"),w=P("padding"),y=P("saturate"),b=P("scale"),S=P("sepia"),D=P("skew"),B=P("space"),te=P("translate"),R=()=>["auto","contain","none"],z=()=>["auto","hidden","clip","visible","scroll"],U=()=>["auto",_,r],E=()=>[_,r],sr=()=>["",J,re],Ke=()=>["auto",Ne,_],nr=()=>["bottom","center","left","left-bottom","left-top","right","right-bottom","right-top","top"],Ge=()=>["solid","dashed","dotted","double","none"],ar=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],wt=()=>["start","end","center","between","around","evenly","stretch"],Le=()=>["","0",_],or=()=>["auto","avoid","all","avoid-page","page","left","right","column"],Z=()=>[Ne,_];return{cacheSize:500,separator:":",theme:{colors:[$e],spacing:[J,re],blur:["none","",se,_],brightness:Z(),borderColor:[e],borderRadius:["none","","full",se,_],borderSpacing:E(),borderWidth:sr(),contrast:Z(),grayscale:Le(),hueRotate:Z(),invert:Le(),gap:E(),gradientColorStops:[e],gradientColorStopPositions:[$n,re],inset:U(),margin:U(),opacity:Z(),padding:E(),saturate:Z(),scale:Z(),sepia:Le(),skew:Z(),space:E(),translate:E()},classGroups:{aspect:[{aspect:["auto","square","video",_]}],container:["container"],columns:[{columns:[se]}],"break-after":[{"break-after":or()}],"break-before":[{"break-before":or()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:[...nr(),_]}],overflow:[{overflow:z()}],"overflow-x":[{"overflow-x":z()}],"overflow-y":[{"overflow-y":z()}],overscroll:[{overscroll:R()}],"overscroll-x":[{"overscroll-x":R()}],"overscroll-y":[{"overscroll-y":R()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:[m]}],"inset-x":[{"inset-x":[m]}],"inset-y":[{"inset-y":[m]}],start:[{start:[m]}],end:[{end:[m]}],top:[{top:[m]}],right:[{right:[m]}],bottom:[{bottom:[m]}],left:[{left:[m]}],visibility:["visible","invisible","collapse"],z:[{z:["auto",Fe,_]}],basis:[{basis:U()}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["wrap","wrap-reverse","nowrap"]}],flex:[{flex:["1","auto","initial","none",_]}],grow:[{grow:Le()}],shrink:[{shrink:Le()}],order:[{order:["first","last","none",Fe,_]}],"grid-cols":[{"grid-cols":[$e]}],"col-start-end":[{col:["auto",{span:["full",Fe,_]},_]}],"col-start":[{"col-start":Ke()}],"col-end":[{"col-end":Ke()}],"grid-rows":[{"grid-rows":[$e]}],"row-start-end":[{row:["auto",{span:[Fe,_]},_]}],"row-start":[{"row-start":Ke()}],"row-end":[{"row-end":Ke()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":["auto","min","max","fr",_]}],"auto-rows":[{"auto-rows":["auto","min","max","fr",_]}],gap:[{gap:[p]}],"gap-x":[{"gap-x":[p]}],"gap-y":[{"gap-y":[p]}],"justify-content":[{justify:["normal",...wt()]}],"justify-items":[{"justify-items":["start","end","center","stretch"]}],"justify-self":[{"justify-self":["auto","start","end","center","stretch"]}],"align-content":[{content:["normal",...wt(),"baseline"]}],"align-items":[{items:["start","end","center","baseline","stretch"]}],"align-self":[{self:["auto","start","end","center","stretch","baseline"]}],"place-content":[{"place-content":[...wt(),"baseline"]}],"place-items":[{"place-items":["start","end","center","baseline","stretch"]}],"place-self":[{"place-self":["auto","start","end","center","stretch"]}],p:[{p:[w]}],px:[{px:[w]}],py:[{py:[w]}],ps:[{ps:[w]}],pe:[{pe:[w]}],pt:[{pt:[w]}],pr:[{pr:[w]}],pb:[{pb:[w]}],pl:[{pl:[w]}],m:[{m:[v]}],mx:[{mx:[v]}],my:[{my:[v]}],ms:[{ms:[v]}],me:[{me:[v]}],mt:[{mt:[v]}],mr:[{mr:[v]}],mb:[{mb:[v]}],ml:[{ml:[v]}],"space-x":[{"space-x":[B]}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":[B]}],"space-y-reverse":["space-y-reverse"],w:[{w:["auto","min","max","fit","svw","lvw","dvw",_,r]}],"min-w":[{"min-w":[_,r,"min","max","fit"]}],"max-w":[{"max-w":[_,r,"none","full","min","max","fit","prose",{screen:[se]},se]}],h:[{h:[_,r,"auto","min","max","fit","svh","lvh","dvh"]}],"min-h":[{"min-h":[_,r,"min","max","fit","svh","lvh","dvh"]}],"max-h":[{"max-h":[_,r,"min","max","fit","svh","lvh","dvh"]}],size:[{size:[_,r,"auto","min","max","fit"]}],"font-size":[{text:["base",se,re]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:["thin","extralight","light","normal","medium","semibold","bold","extrabold","black",Nt]}],"font-family":[{font:[$e]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:["tighter","tight","normal","wide","wider","widest",_]}],"line-clamp":[{"line-clamp":["none",Ne,Nt]}],leading:[{leading:["none","tight","snug","normal","relaxed","loose",J,_]}],"list-image":[{"list-image":["none",_]}],"list-style-type":[{list:["none","disc","decimal",_]}],"list-style-position":[{list:["inside","outside"]}],"placeholder-color":[{placeholder:[e]}],"placeholder-opacity":[{"placeholder-opacity":[j]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"text-color":[{text:[e]}],"text-opacity":[{"text-opacity":[j]}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...Ge(),"wavy"]}],"text-decoration-thickness":[{decoration:["auto","from-font",J,re]}],"underline-offset":[{"underline-offset":["auto",J,_]}],"text-decoration-color":[{decoration:[e]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:E()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",_]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",_]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-opacity":[{"bg-opacity":[j]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:[...nr(),Bn]}],"bg-repeat":[{bg:["no-repeat",{repeat:["","x","y","round","space"]}]}],"bg-size":[{bg:["auto","cover","contain",qn]}],"bg-image":[{bg:["none",{"gradient-to":["t","tr","r","br","b","bl","l","tl"]},Un]}],"bg-color":[{bg:[e]}],"gradient-from-pos":[{from:[g]}],"gradient-via-pos":[{via:[g]}],"gradient-to-pos":[{to:[g]}],"gradient-from":[{from:[h]}],"gradient-via":[{via:[h]}],"gradient-to":[{to:[h]}],rounded:[{rounded:[o]}],"rounded-s":[{"rounded-s":[o]}],"rounded-e":[{"rounded-e":[o]}],"rounded-t":[{"rounded-t":[o]}],"rounded-r":[{"rounded-r":[o]}],"rounded-b":[{"rounded-b":[o]}],"rounded-l":[{"rounded-l":[o]}],"rounded-ss":[{"rounded-ss":[o]}],"rounded-se":[{"rounded-se":[o]}],"rounded-ee":[{"rounded-ee":[o]}],"rounded-es":[{"rounded-es":[o]}],"rounded-tl":[{"rounded-tl":[o]}],"rounded-tr":[{"rounded-tr":[o]}],"rounded-br":[{"rounded-br":[o]}],"rounded-bl":[{"rounded-bl":[o]}],"border-w":[{border:[c]}],"border-w-x":[{"border-x":[c]}],"border-w-y":[{"border-y":[c]}],"border-w-s":[{"border-s":[c]}],"border-w-e":[{"border-e":[c]}],"border-w-t":[{"border-t":[c]}],"border-w-r":[{"border-r":[c]}],"border-w-b":[{"border-b":[c]}],"border-w-l":[{"border-l":[c]}],"border-opacity":[{"border-opacity":[j]}],"border-style":[{border:[...Ge(),"hidden"]}],"divide-x":[{"divide-x":[c]}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":[c]}],"divide-y-reverse":["divide-y-reverse"],"divide-opacity":[{"divide-opacity":[j]}],"divide-style":[{divide:Ge()}],"border-color":[{border:[a]}],"border-color-x":[{"border-x":[a]}],"border-color-y":[{"border-y":[a]}],"border-color-s":[{"border-s":[a]}],"border-color-e":[{"border-e":[a]}],"border-color-t":[{"border-t":[a]}],"border-color-r":[{"border-r":[a]}],"border-color-b":[{"border-b":[a]}],"border-color-l":[{"border-l":[a]}],"divide-color":[{divide:[a]}],"outline-style":[{outline:["",...Ge()]}],"outline-offset":[{"outline-offset":[J,_]}],"outline-w":[{outline:[J,re]}],"outline-color":[{outline:[e]}],"ring-w":[{ring:sr()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:[e]}],"ring-opacity":[{"ring-opacity":[j]}],"ring-offset-w":[{"ring-offset":[J,re]}],"ring-offset-color":[{"ring-offset":[e]}],shadow:[{shadow:["","inner","none",se,Wn]}],"shadow-color":[{shadow:[$e]}],opacity:[{opacity:[j]}],"mix-blend":[{"mix-blend":[...ar(),"plus-lighter","plus-darker"]}],"bg-blend":[{"bg-blend":ar()}],filter:[{filter:["","none"]}],blur:[{blur:[s]}],brightness:[{brightness:[n]}],contrast:[{contrast:[d]}],"drop-shadow":[{"drop-shadow":["","none",se,_]}],grayscale:[{grayscale:[f]}],"hue-rotate":[{"hue-rotate":[u]}],invert:[{invert:[x]}],saturate:[{saturate:[y]}],sepia:[{sepia:[S]}],"backdrop-filter":[{"backdrop-filter":["","none"]}],"backdrop-blur":[{"backdrop-blur":[s]}],"backdrop-brightness":[{"backdrop-brightness":[n]}],"backdrop-contrast":[{"backdrop-contrast":[d]}],"backdrop-grayscale":[{"backdrop-grayscale":[f]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[u]}],"backdrop-invert":[{"backdrop-invert":[x]}],"backdrop-opacity":[{"backdrop-opacity":[j]}],"backdrop-saturate":[{"backdrop-saturate":[y]}],"backdrop-sepia":[{"backdrop-sepia":[S]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":[i]}],"border-spacing-x":[{"border-spacing-x":[i]}],"border-spacing-y":[{"border-spacing-y":[i]}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["none","all","","colors","opacity","shadow","transform",_]}],duration:[{duration:Z()}],ease:[{ease:["linear","in","out","in-out",_]}],delay:[{delay:Z()}],animate:[{animate:["none","spin","ping","pulse","bounce",_]}],transform:[{transform:["","gpu","none"]}],scale:[{scale:[b]}],"scale-x":[{"scale-x":[b]}],"scale-y":[{"scale-y":[b]}],rotate:[{rotate:[Fe,_]}],"translate-x":[{"translate-x":[te]}],"translate-y":[{"translate-y":[te]}],"skew-x":[{"skew-x":[D]}],"skew-y":[{"skew-y":[D]}],"transform-origin":[{origin:["center","top","top-right","right","bottom-right","bottom","bottom-left","left","top-left",_]}],accent:[{accent:["auto",e]}],appearance:[{appearance:["none","auto"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",_]}],"caret-color":[{caret:[e]}],"pointer-events":[{"pointer-events":["none","auto"]}],resize:[{resize:["none","y","x",""]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":E()}],"scroll-mx":[{"scroll-mx":E()}],"scroll-my":[{"scroll-my":E()}],"scroll-ms":[{"scroll-ms":E()}],"scroll-me":[{"scroll-me":E()}],"scroll-mt":[{"scroll-mt":E()}],"scroll-mr":[{"scroll-mr":E()}],"scroll-mb":[{"scroll-mb":E()}],"scroll-ml":[{"scroll-ml":E()}],"scroll-p":[{"scroll-p":E()}],"scroll-px":[{"scroll-px":E()}],"scroll-py":[{"scroll-py":E()}],"scroll-ps":[{"scroll-ps":E()}],"scroll-pe":[{"scroll-pe":E()}],"scroll-pt":[{"scroll-pt":E()}],"scroll-pr":[{"scroll-pr":E()}],"scroll-pb":[{"scroll-pb":E()}],"scroll-pl":[{"scroll-pl":E()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",_]}],fill:[{fill:[e,"none"]}],"stroke-w":[{stroke:[J,re,Nt]}],stroke:[{stroke:[e,"none"]}],sr:["sr-only","not-sr-only"],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-s","border-w-e","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-s","border-color-e","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]}}},Gn=Rn(Kn);function T(...e){return Gn(Kr(e))}let Kt=null,es=null;function At(e){Kt=e.access,e.refresh}function ts(){Kt=null}function dr(){return Kt}function Yn(e){es=e}function Xn(){return es}let Ie=null;async function Zn(){return Ie||(Ie=(async()=>{try{const e=await fetch("/v1/auth/refresh",{method:"POST",credentials:"include"});if(!e.ok)return!1;const r=await e.json();return!r.access_token||!r.refresh_token?!1:(At({access:r.access_token,refresh:r.refresh_token}),!0)}catch{return!1}finally{Ie=null}})(),Ie)}class De extends Error{status;body;constructor(r,s,n){super(n),this.status=r,this.body=s}}async function rs(e,r={}){const s=new Headers(r.headers),n=dr();n&&!s.has("Authorization")&&s.set("Authorization",`Bearer ${n}`);const a=await fetch(e,{...r,headers:s,credentials:"include"});if(a.status!==401||r.skipRefresh)return a;if(!await Zn()){ts();const d=Xn();return d&&typeof window<"u"&&(window.location.href=d),a}const i=new Headers(r.headers),c=dr();return c&&!i.has("Authorization")&&i.set("Authorization",`Bearer ${c}`),fetch(e,{...r,headers:i,credentials:"include"})}async function he(e){const r=await rs(e);if(!r.ok){const s=await ss(r);throw new De(r.status,s,`${r.status} ${r.statusText}`)}return r.json()}async function H(e,r,s){const n=await rs(r,{method:e,headers:s?{"Content-Type":"application/json"}:void 0,body:s?JSON.stringify(s):void 0});if(!n.ok){const a=await ss(n);throw new De(n.status,a,`${e} ${r} → ${n.status}`)}if(n.status!==204)return n.json()}async function ss(e){try{return await e.json()}catch{return null}}const ns=l.createContext(null);function ee(){const e=l.useContext(ns);if(!e)throw new Error("useAuth must be used inside <AuthProvider>");return e}function Jn({children:e}){const[r,s]=l.useState(null),[n,a]=l.useState(!0),[o,i]=l.useState(null),c=l.useCallback(async()=>{try{return await he("/v1/auth/me")}catch(p){if(p instanceof De&&p.status===401)return null;throw p}},[]);l.useEffect(()=>{let p=!1;return(async()=>{try{const h=await fetch("/v1/auth/refresh",{method:"POST",credentials:"include"});if(h.ok){const m=await h.json();m.access_token&&m.refresh_token&&At({access:m.access_token,refresh:m.refresh_token})}const g=await c();p||(s(g),i(null))}catch(h){p||(i(h instanceof Error?h.message:"unknown"),s(null))}finally{p||a(!1)}})(),()=>{p=!0}},[c]);const d=l.useCallback(async(p,h)=>{Yn(window.location.pathname+window.location.search);const g=await fetch("/v1/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({email:p,password:h})});if(!g.ok){const j=(await g.json().catch(()=>null))?.message??`${g.status} ${g.statusText}`;throw new Error(j)}const m=await g.json();At({access:m.access_token,refresh:m.refresh_token}),s(m.user),i(null)},[]),f=l.useCallback(async()=>{try{await fetch("/v1/auth/logout",{method:"POST",credentials:"include"})}catch{}ts(),s(null)},[]),u=l.useCallback(async()=>{const p=await c();s(p)},[c]),x=l.useMemo(()=>({user:r,loading:n,bootError:o,login:d,logout:f,refresh:u}),[r,n,o,d,f,u]);return t.jsx(ns.Provider,{value:x,children:e})}function ft(e){return e==="super_admin"}function as(e){return e==="super_admin"}function ea(e){return e==="super_admin"||e==="tenant_admin"}function os(e){return e==="super_admin"||e==="tenant_admin"}function is(e){return e==="super_admin"}function ta(e){return e==="super_admin"||e==="tenant_admin"||e==="viewer"}const ra=[{to:"/companies",label:"Companies",icon:zr,show:e=>as(e?.role)},{to:"/sources",label:"Sources",icon:Ur,show:e=>os(e?.role)},{to:"/telegram",label:"Telegram",icon:ut,show:e=>is(e?.role)},{to:"/tail",label:"Live tail",icon:tn},{to:"/dlq",label:"DLQ",icon:rn,show:e=>ta(e?.role),badge:"M13c"},{to:"/audit",label:"Audit log",icon:sn,badge:"M13c"}];function sa(){const{user:e}=ee(),r=ra.filter(s=>!s.show||s.show(e));return t.jsxs("aside",{className:"hidden w-56 shrink-0 border-r bg-card md:block",children:[t.jsx("nav",{className:"flex flex-col gap-0.5 p-3",children:r.map(s=>t.jsxs(Xs,{to:s.to,className:({isActive:n})=>T("flex items-center justify-between rounded-md px-3 py-2 text-sm transition-colors",n?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-accent hover:text-accent-foreground"),children:[t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(s.icon,{className:"h-4 w-4","aria-hidden":!0}),s.label]}),s.badge?t.jsx("span",{className:"rounded bg-muted px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wider text-muted-foreground",children:s.badge}):null]},s.to))}),t.jsx("div",{className:"border-t p-3 text-xs text-muted-foreground",children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(_e,{className:"h-3.5 w-3.5"}),t.jsx("span",{children:"M13b W3 · SPA shell"})]})})]})}function ur(e,r){if(typeof e=="function")return e(r);e!=null&&(e.current=r)}function na(...e){return r=>{let s=!1;const n=e.map(a=>{const o=ur(a,r);return!s&&typeof o=="function"&&(s=!0),o});if(s)return()=>{for(let a=0;a<n.length;a++){const o=n[a];typeof o=="function"?o():ur(e[a],null)}}}}function xe(...e){return l.useCallback(na(...e),e)}function Gt(e){const r=l.forwardRef((s,n)=>{let{children:a,...o}=s,i=null,c=!1;const d=[];mr(a)&&typeof Ye=="function"&&(a=Ye(a._payload)),l.Children.forEach(a,p=>{if(da(p)){c=!0;const h=p;let g="child"in h.props?h.props.child:h.props.children;mr(g)&&typeof Ye=="function"&&(g=Ye(g._payload)),i=ia(h,g),d.push(i?.props?.children)}else d.push(p)}),i?i=l.cloneElement(i,void 0,d):!c&&l.Children.count(a)===1&&l.isValidElement(a)&&(i=a);const f=i?la(i):void 0,u=xe(n,f);if(!i){if(a||a===0)throw new Error(c?ha(e):fa(e));return a}const x=ca(o,i.props??{});return i.type!==l.Fragment&&(x.ref=n?u:f),l.cloneElement(i,x)});return r.displayName=`${e}.Slot`,r}var aa=Gt("Slot"),oa=Symbol.for("radix.slottable"),ia=(e,r)=>{if("child"in e.props){const s=e.props.child;return l.isValidElement(s)?l.cloneElement(s,void 0,e.props.children(s.props.children)):null}return l.isValidElement(r)?r:null};function ca(e,r){const s={...r};for(const n in r){const a=e[n],o=r[n];/^on[A-Z]/.test(n)?a&&o?s[n]=(...c)=>{const d=o(...c);return a(...c),d}:a&&(s[n]=a):n==="style"?s[n]={...a,...o}:n==="className"&&(s[n]=[a,o].filter(Boolean).join(" "))}return{...e,...s}}function la(e){let r=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,s=r&&"isReactWarning"in r&&r.isReactWarning;return s?e.ref:(r=Object.getOwnPropertyDescriptor(e,"ref")?.get,s=r&&"isReactWarning"in r&&r.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}function da(e){return l.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===oa}var ua=Symbol.for("react.lazy");function mr(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===ua&&"_payload"in e&&ma(e._payload)}function ma(e){return typeof e=="object"&&e!==null&&"then"in e}var fa=e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,ha=e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,Ye=qt[" use ".trim().toString()];const fr=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,hr=Kr,cs=(e,r)=>s=>{var n;if(r?.variants==null)return hr(e,s?.class,s?.className);const{variants:a,defaultVariants:o}=r,i=Object.keys(a).map(f=>{const u=s?.[f],x=o?.[f];if(u===null)return null;const p=fr(u)||fr(x);return a[f][p]}),c=s&&Object.entries(s).reduce((f,u)=>{let[x,p]=u;return p===void 0||(f[x]=p),f},{}),d=r==null||(n=r.compoundVariants)===null||n===void 0?void 0:n.reduce((f,u)=>{let{class:x,className:p,...h}=u;return Object.entries(h).every(g=>{let[m,v]=g;return Array.isArray(v)?v.includes({...o,...c}[m]):{...o,...c}[m]===v})?[...f,x,p]:f},[]);return hr(e,i,d,s?.class,s?.className)},xa=cs("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),N=l.forwardRef(({className:e,variant:r,size:s,asChild:n=!1,...a},o)=>{const i=n?aa:"button";return t.jsx(i,{ref:o,className:T(xa({variant:r,size:s,className:e})),...a})});N.displayName="Button";const ls="ba.theme";function Dt(){if(typeof window>"u")return"system";const e=window.localStorage.getItem(ls);return e==="light"||e==="dark"||e==="system"?e:"system"}function Ot(e){const r=document.documentElement,s=e==="dark"||e==="system"&&window.matchMedia?.("(prefers-color-scheme: dark)").matches;r.classList.toggle("dark",s),r.style.colorScheme=s?"dark":"light"}function pa(){Ot(Dt()),Dt()==="system"&&window.matchMedia?.("(prefers-color-scheme: dark)").addEventListener("change",()=>{Ot("system")})}function ga(e){window.localStorage.setItem(ls,e),Ot(e)}function va(){const[e,r]=l.useState(Dt),s=l.useCallback(n=>{ga(n),r(n)},[]);return l.useEffect(()=>{if(e!=="system")return;const n=window.matchMedia("(prefers-color-scheme: dark)"),a=()=>r("system");return n.addEventListener("change",a),()=>n.removeEventListener("change",a)},[e]),{theme:e,setTheme:s}}function ba(){const{user:e,logout:r}=ee(),{theme:s,setTheme:n}=va(),a=ie(),[o,i]=l.useState(!1);if(!e)return null;const c=async()=>{await r(),a("/login",{replace:!0})};return t.jsxs("header",{className:"flex h-14 items-center justify-between border-b bg-card px-4",children:[t.jsxs(Te,{to:"/",className:"flex items-center gap-2",children:[t.jsx("span",{className:"inline-block h-6 w-6 rounded bg-primary","aria-hidden":!0}),t.jsx("span",{className:"text-sm font-semibold",children:"broad-announce"})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[ft(e.role)?t.jsx("span",{className:"hidden text-xs text-muted-foreground sm:inline",children:"all companies"}):e.tenant_slug?t.jsx("span",{className:"hidden rounded-md bg-muted px-2 py-1 text-xs sm:inline",children:e.tenant_slug}):null,t.jsxs(N,{variant:"ghost",size:"icon","aria-label":"Toggle theme",onClick:()=>{n(s==="light"?"dark":s==="dark"?"system":"light")},children:[s==="light"&&t.jsx(nn,{className:"h-4 w-4"}),s==="dark"&&t.jsx(an,{className:"h-4 w-4"}),s==="system"&&t.jsx(on,{className:"h-4 w-4"})]}),t.jsxs("div",{className:"relative",children:[t.jsxs(N,{variant:"ghost",size:"sm",onClick:()=>i(d=>!d),"aria-haspopup":"menu","aria-expanded":o,children:[t.jsxs("span",{className:"hidden text-right sm:block",children:[t.jsx("span",{className:"block text-xs font-medium",children:e.email}),t.jsx("span",{className:"block text-[10px] uppercase tracking-wider text-muted-foreground",children:e.role.replace("_"," ")})]}),t.jsx(cn,{className:"h-4 w-4 opacity-60"})]}),o?t.jsx("div",{role:"menu",className:T("absolute right-0 top-full z-50 mt-1 w-48 rounded-md border bg-card p-1 shadow-md"),onMouseLeave:()=>i(!1),children:t.jsxs("button",{type:"button",onClick:c,className:"flex w-full items-center gap-2 rounded px-3 py-2 text-left text-sm hover:bg-accent",children:[t.jsx(ln,{className:"h-4 w-4"}),"Sign out"]})}):null]})]})]})}function ya(){return t.jsxs("div",{className:"flex h-full flex-col",children:[t.jsx(ba,{}),t.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[t.jsx(sa,{}),t.jsx("main",{className:"flex-1 overflow-auto bg-background p-6",children:t.jsx(Zs,{})})]})]})}function ja({children:e}){const{user:r,loading:s}=ee(),n=Br();return s?t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsx("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent"})}):r?t.jsx(t.Fragment,{children:e}):t.jsx(me,{to:"/login",state:{from:n.pathname+n.search},replace:!0})}const k=l.forwardRef(({className:e,type:r,...s},n)=>t.jsx("input",{type:r,className:T("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background","placeholder:text-muted-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...s}));k.displayName="Input";var wa=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],X=wa.reduce((e,r)=>{const s=Gt(`Primitive.${r}`),n=l.forwardRef((a,o)=>{const{asChild:i,...c}=a,d=i?s:r;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),t.jsx(d,{...c,ref:o})});return n.displayName=`Primitive.${r}`,{...e,[r]:n}},{});function Na(e,r){e&&It.flushSync(()=>e.dispatchEvent(r))}var Sa="Label",ds=l.forwardRef((e,r)=>t.jsx(X.label,{...e,ref:r,onMouseDown:s=>{s.target.closest("button, input, select, textarea")||(e.onMouseDown?.(s),!s.defaultPrevented&&s.detail>1&&s.preventDefault())}}));ds.displayName=Sa;var us=ds;const C=l.forwardRef(({className:e,...r},s)=>t.jsx(us,{ref:s,className:T("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",e),...r}));C.displayName=us.displayName;const F=l.forwardRef(({className:e,...r},s)=>t.jsx("div",{ref:s,className:T("rounded-lg border bg-card text-card-foreground shadow-sm",e),...r}));F.displayName="Card";const $=l.forwardRef(({className:e,...r},s)=>t.jsx("div",{ref:s,className:T("flex flex-col space-y-1.5 p-6",e),...r}));$.displayName="CardHeader";const I=l.forwardRef(({className:e,...r},s)=>t.jsx("h3",{ref:s,className:T("text-lg font-semibold leading-none tracking-tight",e),...r}));I.displayName="CardTitle";const G=l.forwardRef(({className:e,...r},s)=>t.jsx("p",{ref:s,className:T("text-sm text-muted-foreground",e),...r}));G.displayName="CardDescription";const q=l.forwardRef(({className:e,...r},s)=>t.jsx("div",{ref:s,className:T("p-6 pt-0",e),...r}));q.displayName="CardContent";const _a=l.forwardRef(({className:e,...r},s)=>t.jsx("div",{ref:s,className:T("flex items-center p-6 pt-0",e),...r}));_a.displayName="CardFooter";function Ca(){const{user:e,login:r,loading:s}=ee(),n=ie(),o=Br().state,[i,c]=l.useState(""),[d,f]=l.useState(""),[u,x]=l.useState(!1),[p,h]=l.useState(null);if(s)return null;if(e){const m=o?.from??"/";return t.jsx(me,{to:m,replace:!0})}const g=async m=>{m.preventDefault(),h(null),x(!0);try{await r(i,d),A.success("Signed in");const v=o?.from??"/";n(v,{replace:!0})}catch(v){const j=v instanceof Error?v.message:"Sign-in failed";h(j),A.error(j)}finally{x(!1)}};return t.jsx("div",{className:"flex h-full items-center justify-center bg-muted/30 p-4",children:t.jsxs(F,{className:"w-full max-w-sm",children:[t.jsxs($,{children:[t.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[t.jsx("span",{className:"inline-block h-6 w-6 rounded bg-primary","aria-hidden":!0}),t.jsx("span",{className:"text-sm font-semibold",children:"broad-announce"})]}),t.jsx(I,{children:"Sign in"}),t.jsx(G,{children:"Operator console for the notification router."})]}),t.jsxs(q,{children:[t.jsxs("form",{onSubmit:g,className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(C,{htmlFor:"email",children:"Email"}),t.jsx(k,{id:"email",type:"email",autoComplete:"email",required:!0,value:i,onChange:m=>c(m.target.value),placeholder:"super@broad-announce.test",disabled:u})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(C,{htmlFor:"password",children:"Password"}),t.jsx(k,{id:"password",type:"password",autoComplete:"current-password",required:!0,value:d,onChange:m=>f(m.target.value),disabled:u})]}),p?t.jsx("p",{role:"alert",className:"text-sm text-destructive",children:p}):null,t.jsx(N,{type:"submit",className:"w-full",disabled:u,children:u?"Signing in…":"Sign in"})]}),t.jsxs("p",{className:"mt-4 text-center text-xs text-muted-foreground",children:["Bootstrap the first super-admin with"," ",t.jsx("code",{className:"rounded bg-muted px-1",children:"scripts/bootstrap-super-admin.sh"}),"."]})]})]})})}function Ea(){const{user:e}=ee();if(!e)return t.jsx(me,{to:"/login",replace:!0});switch(e.role){case"super_admin":return t.jsx(me,{to:"/companies",replace:!0});case"tenant_admin":return t.jsx(me,{to:"/sources",replace:!0});case"viewer":return t.jsx(me,{to:"/dlq",replace:!0});default:return t.jsx(me,{to:"/login",replace:!0})}}function Yt({title:e,description:r,action:s,icon:n,className:a}){return t.jsxs("div",{className:T("flex flex-col items-center justify-center gap-3 rounded-md border border-dashed bg-card p-10 text-center",a),children:[n?t.jsx("div",{className:"text-muted-foreground",children:n}):null,t.jsx("h3",{className:"text-base font-semibold",children:e}),r?t.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:r}):null,s?t.jsx("div",{className:"mt-2",children:s}):null]})}const ht=l.forwardRef(({className:e,...r},s)=>t.jsx("div",{className:"relative w-full overflow-auto",children:t.jsx("table",{ref:s,className:T("w-full caption-bottom text-sm",e),...r})}));ht.displayName="Table";const xt=l.forwardRef(({className:e,...r},s)=>t.jsx("thead",{ref:s,className:T("[&_tr]:border-b bg-muted/40",e),...r}));xt.displayName="TableHeader";const pt=l.forwardRef(({className:e,...r},s)=>t.jsx("tbody",{ref:s,className:T("[&_tr:last-child]:border-0",e),...r}));pt.displayName="TableBody";const fe=l.forwardRef(({className:e,...r},s)=>t.jsx("tr",{ref:s,className:T("border-b transition-colors hover:bg-muted/40 data-[state=selected]:bg-muted",e),...r}));fe.displayName="TableRow";const O=l.forwardRef(({className:e,...r},s)=>t.jsx("th",{ref:s,className:T("h-10 px-3 text-left align-middle text-xs font-medium uppercase tracking-wider text-muted-foreground",e),...r}));O.displayName="TableHead";const M=l.forwardRef(({className:e,...r},s)=>t.jsx("td",{ref:s,className:T("p-3 align-middle",e),...r}));M.displayName="TableCell";const gt={list:e=>["tenants","list",e],detail:e=>["tenants","detail",e]};function ka(e){const r=new URLSearchParams;e.q&&r.set("q",e.q),e.status&&r.set("status",e.status),e.limit&&r.set("limit",String(e.limit)),e.offset&&r.set("offset",String(e.offset));const s=r.toString();return s?`/v1/tenants?${s}`:"/v1/tenants"}function Xt(e){return ke({queryKey:gt.list(e),queryFn:()=>he(ka(e)),staleTime:15e3})}function Ta(e){return ke({queryKey:gt.detail(e),queryFn:()=>he(`/v1/tenants/${e}`),enabled:!!e})}function Ra(){const e=W();return V({mutationFn:r=>H("POST","/v1/tenants",r),onSuccess:()=>{e.invalidateQueries({queryKey:["tenants","list"]})}})}function Pa(e){const r=W();return V({mutationFn:s=>H("PATCH",`/v1/tenants/${e}`,s),onSuccess:s=>{r.setQueryData(gt.detail(e),s),r.invalidateQueries({queryKey:["tenants","list"]})}})}function Aa(e){const r=W();return V({mutationFn:s=>H("POST",`/v1/tenants/${e}/status`,{status:s}),onSuccess:s=>{r.setQueryData(gt.detail(e),s),r.invalidateQueries({queryKey:["tenants","list"]})}})}function st(e){if(e instanceof De){const r=e.body;return r?.message??r?.error??e.message}return e instanceof Error?e.message:"Unknown error"}var Da=function(e,r){for(var s={};e.length;){var n=e[0],a=n.code,o=n.message,i=n.path.join(".");if(!s[i])if("unionErrors"in n){var c=n.unionErrors[0].errors[0];s[i]={message:c.message,type:c.code}}else s[i]={message:o,type:a};if("unionErrors"in n&&n.unionErrors.forEach(function(u){return u.errors.forEach(function(x){return e.push(x)})}),r){var d=s[i].types,f=d&&d[n.code];s[i]=gn(i,r,s,a,f?[].concat(f,n.message):n.message)}e.shift()}return s},Oe=function(e,r,s){return s===void 0&&(s={}),function(n,a,o){try{return Promise.resolve(function(i,c){try{var d=Promise.resolve(e[s.mode==="sync"?"parse":"parseAsync"](n,r)).then(function(f){return o.shouldUseNativeValidation&&xn({},o),{errors:{},values:s.raw?n:f}})}catch(f){return c(f)}return d&&d.then?d.then(void 0,c):d}(0,function(i){if(function(c){return Array.isArray(c?.errors)}(i))return{values:{},errors:pn(Da(i.errors,!o.shouldUseNativeValidation&&o.criteriaMode==="all"),o)};throw i}))}catch(i){return Promise.reject(i)}}};function oe(e,r,{checkForDefaultPrevented:s=!0}={}){return function(a){if(e?.(a),s===!1||!a.defaultPrevented)return r?.(a)}}function Oa(e,r=[]){let s=[];function n(o,i){const c=l.createContext(i);c.displayName=o+"Context";const d=s.length;s=[...s,i];const f=x=>{const{scope:p,children:h,...g}=x,m=p?.[e]?.[d]||c,v=l.useMemo(()=>g,Object.values(g));return t.jsx(m.Provider,{value:v,children:h})};f.displayName=o+"Provider";function u(x,p){const h=p?.[e]?.[d]||c,g=l.useContext(h);if(g)return g;if(i!==void 0)return i;throw new Error(`\`${x}\` must be used within \`${o}\``)}return[f,u]}const a=()=>{const o=s.map(i=>l.createContext(i));return function(c){const d=c?.[e]||o;return l.useMemo(()=>({[`__scope${e}`]:{...c,[e]:d}}),[c,d])}};return a.scopeName=e,[n,Ma(a,...r)]}function Ma(...e){const r=e[0];if(e.length===1)return r;const s=()=>{const n=e.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(o){const i=n.reduce((c,{useScope:d,scopeName:f})=>{const x=d(o)[`__scope${f}`];return{...c,...x}},{});return l.useMemo(()=>({[`__scope${r.scopeName}`]:i}),[i])}};return s.scopeName=r.scopeName,s}var Ue=globalThis?.document?l.useLayoutEffect:()=>{},La=qt[" useId ".trim().toString()]||(()=>{}),Fa=0;function St(e){const[r,s]=l.useState(La());return Ue(()=>{s(n=>n??String(Fa++))},[e]),e||(r?`radix-${r}`:"")}var $a=qt[" useInsertionEffect ".trim().toString()]||Ue;function Ia({prop:e,defaultProp:r,onChange:s=()=>{},caller:n}){const[a,o,i]=qa({defaultProp:r,onChange:s}),c=e!==void 0,d=c?e:a;{const u=l.useRef(e!==void 0);l.useEffect(()=>{const x=u.current;x!==c&&console.warn(`${n} is changing from ${x?"controlled":"uncontrolled"} to ${c?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),u.current=c},[c,n])}const f=l.useCallback(u=>{if(c){const x=Ba(u)?u(e):u;x!==e&&i.current?.(x)}else o(u)},[c,e,o,i]);return[d,f]}function qa({defaultProp:e,onChange:r}){const[s,n]=l.useState(e),a=l.useRef(s),o=l.useRef(r);return $a(()=>{o.current=r},[r]),l.useEffect(()=>{a.current!==s&&(o.current?.(s),a.current=s)},[s,a]),[s,n,o]}function Ba(e){return typeof e=="function"}function We(e){const r=l.useRef(e);return l.useEffect(()=>{r.current=e}),l.useMemo(()=>(...s)=>r.current?.(...s),[])}function za(e,r=globalThis?.document){const s=We(e);l.useEffect(()=>{const n=a=>{a.key==="Escape"&&s(a)};return r.addEventListener("keydown",n,{capture:!0}),()=>r.removeEventListener("keydown",n,{capture:!0})},[s,r])}var Ua="DismissableLayer",Mt="dismissableLayer.update",Wa="dismissableLayer.pointerDownOutside",Va="dismissableLayer.focusOutside",xr,Zt=l.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),ms=l.forwardRef((e,r)=>{const{disableOutsidePointerEvents:s=!1,deferPointerDownOutside:n=!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:c,onDismiss:d,...f}=e,u=l.useContext(Zt),[x,p]=l.useState(null),h=x?.ownerDocument??globalThis?.document,[,g]=l.useState({}),m=xe(r,R=>p(R)),v=Array.from(u.layers),[j]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),w=v.indexOf(j),y=x?v.indexOf(x):-1,b=u.layersWithOutsidePointerEventsDisabled.size>0,S=y>=w,D=l.useRef(!1),B=Ga(R=>{const z=R.target;if(!(z instanceof Node))return;const U=[...u.branches].some(E=>E.contains(z));!S||U||(o?.(R),c?.(R),R.defaultPrevented||d?.())},{ownerDocument:h,deferPointerDownOutside:n,isDeferredPointerDownOutsideRef:D,dismissableSurfaces:u.dismissableSurfaces}),te=Ya(R=>{if(n&&D.current)return;const z=R.target;[...u.branches].some(E=>E.contains(z))||(i?.(R),c?.(R),R.defaultPrevented||d?.())},h);return za(R=>{y===u.layers.size-1&&(a?.(R),!R.defaultPrevented&&d&&(R.preventDefault(),d()))},h),l.useEffect(()=>{if(x)return s&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(xr=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(x)),u.layers.add(x),pr(),()=>{s&&(u.layersWithOutsidePointerEventsDisabled.delete(x),u.layersWithOutsidePointerEventsDisabled.size===0&&(h.body.style.pointerEvents=xr))}},[x,h,s,u]),l.useEffect(()=>()=>{x&&(u.layers.delete(x),u.layersWithOutsidePointerEventsDisabled.delete(x),pr())},[x,u]),l.useEffect(()=>{const R=()=>g({});return document.addEventListener(Mt,R),()=>document.removeEventListener(Mt,R)},[]),t.jsx(X.div,{...f,ref:m,style:{pointerEvents:b?S?"auto":"none":void 0,...e.style},onFocusCapture:oe(e.onFocusCapture,te.onFocusCapture),onBlurCapture:oe(e.onBlurCapture,te.onBlurCapture),onPointerDownCapture:oe(e.onPointerDownCapture,B.onPointerDownCapture)})});ms.displayName=Ua;var Ha="DismissableLayerBranch",Qa=l.forwardRef((e,r)=>{const s=l.useContext(Zt),n=l.useRef(null),a=xe(r,n);return l.useEffect(()=>{const o=n.current;if(o)return s.branches.add(o),()=>{s.branches.delete(o)}},[s.branches]),t.jsx(X.div,{...e,ref:a})});Qa.displayName=Ha;function Ka(){const e=l.useContext(Zt),[r,s]=l.useState(null);return l.useEffect(()=>{if(r)return e.dismissableSurfaces.add(r),()=>{e.dismissableSurfaces.delete(r)}},[r,e.dismissableSurfaces]),s}function Ga(e,r){const{ownerDocument:s=globalThis?.document,deferPointerDownOutside:n=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:o}=r,i=We(e),c=l.useRef(!1),d=l.useRef(!1),f=l.useRef(new Map),u=l.useRef(()=>{});return l.useEffect(()=>{function x(){d.current=!1,a.current=!1,f.current.clear()}function p(){return Array.from(f.current.values()).some(Boolean)}function h(w){if(!d.current)return;const y=w.target;y instanceof Node&&[...o].some(S=>S.contains(y))||f.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{d.current&&u.current()},0)}function g(w){d.current&&f.current.set(w.type,!1)}const m=w=>{if(w.target&&!c.current){let y=function(){s.removeEventListener("click",u.current);const S=p();x(),S||fs(Wa,i,b,{discrete:!0})};const b={originalEvent:w};d.current=!0,a.current=n&&w.button===0,f.current.clear(),!n||w.button!==0?y():(s.removeEventListener("click",u.current),u.current=y,s.addEventListener("click",u.current,{once:!0}))}else s.removeEventListener("click",u.current),x();c.current=!1},v=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of v)s.addEventListener(w,h,!0),s.addEventListener(w,g);const j=window.setTimeout(()=>{s.addEventListener("pointerdown",m)},0);return()=>{window.clearTimeout(j),s.removeEventListener("pointerdown",m),s.removeEventListener("click",u.current);for(const w of v)s.removeEventListener(w,h,!0),s.removeEventListener(w,g)}},[s,i,n,a,o]),{onPointerDownCapture:()=>c.current=!0}}function Ya(e,r=globalThis?.document){const s=We(e),n=l.useRef(!1);return l.useEffect(()=>{const a=o=>{o.target&&!n.current&&fs(Va,s,{originalEvent:o},{discrete:!1})};return r.addEventListener("focusin",a),()=>r.removeEventListener("focusin",a)},[r,s]),{onFocusCapture:()=>n.current=!0,onBlurCapture:()=>n.current=!1}}function pr(){const e=new CustomEvent(Mt);document.dispatchEvent(e)}function fs(e,r,s,{discrete:n}){const a=s.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:s});r&&a.addEventListener(e,r,{once:!0}),n?Na(a,o):a.dispatchEvent(o)}var _t="focusScope.autoFocusOnMount",Ct="focusScope.autoFocusOnUnmount",gr={bubbles:!1,cancelable:!0},Xa="FocusScope",hs=l.forwardRef((e,r)=>{const{loop:s=!1,trapped:n=!1,onMountAutoFocus:a,onUnmountAutoFocus:o,...i}=e,[c,d]=l.useState(null),f=We(a),u=We(o),x=l.useRef(null),p=xe(r,m=>d(m)),h=l.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;l.useEffect(()=>{if(n){let m=function(y){if(h.paused||!c)return;const b=y.target;c.contains(b)?x.current=b:ne(x.current,{select:!0})},v=function(y){if(h.paused||!c)return;const b=y.relatedTarget;b!==null&&(c.contains(b)||ne(x.current,{select:!0}))},j=function(y){if(document.activeElement===document.body)for(const S of y)S.removedNodes.length>0&&ne(c)};document.addEventListener("focusin",m),document.addEventListener("focusout",v);const w=new MutationObserver(j);return c&&w.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",v),w.disconnect()}}},[n,c,h.paused]),l.useEffect(()=>{if(c){br.add(h);const m=document.activeElement;if(!c.contains(m)){const j=new CustomEvent(_t,gr);c.addEventListener(_t,f),c.dispatchEvent(j),j.defaultPrevented||(Za(so(xs(c)),{select:!0}),document.activeElement===m&&ne(c))}return()=>{c.removeEventListener(_t,f),setTimeout(()=>{const j=new CustomEvent(Ct,gr);c.addEventListener(Ct,u),c.dispatchEvent(j),j.defaultPrevented||ne(m??document.body,{select:!0}),c.removeEventListener(Ct,u),br.remove(h)},0)}}},[c,f,u,h]);const g=l.useCallback(m=>{if(!s&&!n||h.paused)return;const v=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,j=document.activeElement;if(v&&j){const w=m.currentTarget,[y,b]=Ja(w);y&&b?!m.shiftKey&&j===b?(m.preventDefault(),s&&ne(y,{select:!0})):m.shiftKey&&j===y&&(m.preventDefault(),s&&ne(b,{select:!0})):j===w&&m.preventDefault()}},[s,n,h.paused]);return t.jsx(X.div,{tabIndex:-1,...i,ref:p,onKeyDown:g})});hs.displayName=Xa;function Za(e,{select:r=!1}={}){const s=document.activeElement;for(const n of e)if(ne(n,{select:r}),document.activeElement!==s)return}function Ja(e){const r=xs(e),s=vr(r,e),n=vr(r.reverse(),e);return[s,n]}function xs(e){const r=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:n=>{const a=n.tagName==="INPUT"&&n.type==="hidden";return n.disabled||n.hidden||a?NodeFilter.FILTER_SKIP:n.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();)r.push(s.currentNode);return r}function vr(e,r){for(const s of e)if(!eo(s,{upTo:r}))return s}function eo(e,{upTo:r}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(r!==void 0&&e===r)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function to(e){return e instanceof HTMLInputElement&&"select"in e}function ne(e,{select:r=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&to(e)&&r&&e.select()}}var br=ro();function ro(){let e=[];return{add(r){const s=e[0];r!==s&&s?.pause(),e=yr(e,r),e.unshift(r)},remove(r){e=yr(e,r),e[0]?.resume()}}}function yr(e,r){const s=[...e],n=s.indexOf(r);return n!==-1&&s.splice(n,1),s}function so(e){return e.filter(r=>r.tagName!=="A")}var no="Portal",ps=l.forwardRef((e,r)=>{const{container:s,...n}=e,[a,o]=l.useState(!1);Ue(()=>o(!0),[]);const i=s||a&&globalThis?.document?.body;return i?It.createPortal(t.jsx(X.div,{...n,ref:r}),i):null});ps.displayName=no;function ao(e,r){return l.useReducer((s,n)=>r[s][n]??s,e)}var vt=e=>{const{present:r,children:s}=e,n=oo(r),a=typeof s=="function"?s({present:n.isPresent}):l.Children.only(s),o=io(n.ref,co(a));return typeof s=="function"||n.isPresent?l.cloneElement(a,{ref:o}):null};vt.displayName="Presence";function oo(e){const[r,s]=l.useState(),n=l.useRef(null),a=l.useRef(e),o=l.useRef("none"),i=e?"mounted":"unmounted",[c,d]=ao(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return l.useEffect(()=>{const f=Xe(n.current);o.current=c==="mounted"?f:"none"},[c]),Ue(()=>{const f=n.current,u=a.current;if(u!==e){const p=o.current,h=Xe(f);e?d("MOUNT"):h==="none"||f?.display==="none"?d("UNMOUNT"):d(u&&p!==h?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,d]),Ue(()=>{if(r){let f;const u=r.ownerDocument.defaultView??window,x=h=>{const m=Xe(n.current).includes(CSS.escape(h.animationName));if(h.target===r&&m&&(d("ANIMATION_END"),!a.current)){const v=r.style.animationFillMode;r.style.animationFillMode="forwards",f=u.setTimeout(()=>{r.style.animationFillMode==="forwards"&&(r.style.animationFillMode=v)})}},p=h=>{h.target===r&&(o.current=Xe(n.current))};return r.addEventListener("animationstart",p),r.addEventListener("animationcancel",x),r.addEventListener("animationend",x),()=>{u.clearTimeout(f),r.removeEventListener("animationstart",p),r.removeEventListener("animationcancel",x),r.removeEventListener("animationend",x)}}else d("ANIMATION_END")},[r,d]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:l.useCallback(f=>{n.current=f?getComputedStyle(f):null,s(f)},[])}}function jr(e,r){if(typeof e=="function")return e(r);e!=null&&(e.current=r)}function io(...e){const r=l.useRef(e);return r.current=e,l.useCallback(s=>{const n=r.current;let a=!1;const o=n.map(i=>{const c=jr(i,s);return!a&&typeof c=="function"&&(a=!0),c});if(a)return()=>{for(let i=0;i<o.length;i++){const c=o[i];typeof c=="function"?c():jr(n[i],null)}}},[])}function Xe(e){return e?.animationName||"none"}function co(e){let r=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,s=r&&"isReactWarning"in r&&r.isReactWarning;return s?e.ref:(r=Object.getOwnPropertyDescriptor(e,"ref")?.get,s=r&&"isReactWarning"in r&&r.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}var Ze=0,be=null;function lo(){l.useEffect(()=>{be||(be={start:wr(),end:wr()});const{start:e,end:r}=be;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==r&&document.body.insertAdjacentElement("beforeend",r),Ze++,()=>{Ze===1&&(be?.start.remove(),be?.end.remove(),be=null),Ze=Math.max(0,Ze-1)}},[])}function wr(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var K=function(){return K=Object.assign||function(r){for(var s,n=1,a=arguments.length;n<a;n++){s=arguments[n];for(var o in s)Object.prototype.hasOwnProperty.call(s,o)&&(r[o]=s[o])}return r},K.apply(this,arguments)};function gs(e,r){var s={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(s[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,n=Object.getOwnPropertySymbols(e);a<n.length;a++)r.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(s[n[a]]=e[n[a]]);return s}function uo(e,r,s){if(s||arguments.length===2)for(var n=0,a=r.length,o;n<a;n++)(o||!(n in r))&&(o||(o=Array.prototype.slice.call(r,0,n)),o[n]=r[n]);return e.concat(o||Array.prototype.slice.call(r))}var nt="right-scroll-bar-position",at="width-before-scroll-bar",mo="with-scroll-bars-hidden",fo="--removed-body-scroll-bar-size";function Et(e,r){return typeof e=="function"?e(r):e&&(e.current=r),e}function ho(e,r){var s=l.useState(function(){return{value:e,callback:r,facade:{get current(){return s.value},set current(n){var a=s.value;a!==n&&(s.value=n,s.callback(n,a))}}}})[0];return s.callback=r,s.facade}var xo=typeof window<"u"?l.useLayoutEffect:l.useEffect,Nr=new WeakMap;function po(e,r){var s=ho(null,function(n){return e.forEach(function(a){return Et(a,n)})});return xo(function(){var n=Nr.get(s);if(n){var a=new Set(n),o=new Set(e),i=s.current;a.forEach(function(c){o.has(c)||Et(c,null)}),o.forEach(function(c){a.has(c)||Et(c,i)})}Nr.set(s,e)},[e]),s}function go(e){return e}function vo(e,r){r===void 0&&(r=go);var s=[],n=!1,a={read:function(){if(n)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return s.length?s[s.length-1]:e},useMedium:function(o){var i=r(o,n);return s.push(i),function(){s=s.filter(function(c){return c!==i})}},assignSyncMedium:function(o){for(n=!0;s.length;){var i=s;s=[],i.forEach(o)}s={push:function(c){return o(c)},filter:function(){return s}}},assignMedium:function(o){n=!0;var i=[];if(s.length){var c=s;s=[],c.forEach(o),i=s}var d=function(){var u=i;i=[],u.forEach(o)},f=function(){return Promise.resolve().then(d)};f(),s={push:function(u){i.push(u),f()},filter:function(u){return i=i.filter(u),s}}}};return a}function bo(e){e===void 0&&(e={});var r=vo(null);return r.options=K({async:!0,ssr:!1},e),r}var vs=function(e){var r=e.sideCar,s=gs(e,["sideCar"]);if(!r)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var n=r.read();if(!n)throw new Error("Sidecar medium not found");return l.createElement(n,K({},s))};vs.isSideCarExport=!0;function yo(e,r){return e.useMedium(r),vs}var bs=bo(),kt=function(){},bt=l.forwardRef(function(e,r){var s=l.useRef(null),n=l.useState({onScrollCapture:kt,onWheelCapture:kt,onTouchMoveCapture:kt}),a=n[0],o=n[1],i=e.forwardProps,c=e.children,d=e.className,f=e.removeScrollBar,u=e.enabled,x=e.shards,p=e.sideCar,h=e.noRelative,g=e.noIsolation,m=e.inert,v=e.allowPinchZoom,j=e.as,w=j===void 0?"div":j,y=e.gapMode,b=gs(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=p,D=po([s,r]),B=K(K({},b),a);return l.createElement(l.Fragment,null,u&&l.createElement(S,{sideCar:bs,removeScrollBar:f,shards:x,noRelative:h,noIsolation:g,inert:m,setCallbacks:o,allowPinchZoom:!!v,lockRef:s,gapMode:y}),i?l.cloneElement(l.Children.only(c),K(K({},B),{ref:D})):l.createElement(w,K({},B,{className:d,ref:D}),c))});bt.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};bt.classNames={fullWidth:at,zeroRight:nt};var jo=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function wo(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var r=jo();return r&&e.setAttribute("nonce",r),e}function No(e,r){e.styleSheet?e.styleSheet.cssText=r:e.appendChild(document.createTextNode(r))}function So(e){var r=document.head||document.getElementsByTagName("head")[0];r.appendChild(e)}var _o=function(){var e=0,r=null;return{add:function(s){e==0&&(r=wo())&&(No(r,s),So(r)),e++},remove:function(){e--,!e&&r&&(r.parentNode&&r.parentNode.removeChild(r),r=null)}}},Co=function(){var e=_o();return function(r,s){l.useEffect(function(){return e.add(r),function(){e.remove()}},[r&&s])}},ys=function(){var e=Co(),r=function(s){var n=s.styles,a=s.dynamic;return e(n,a),null};return r},Eo={left:0,top:0,right:0,gap:0},Tt=function(e){return parseInt(e||"",10)||0},ko=function(e){var r=window.getComputedStyle(document.body),s=r[e==="padding"?"paddingLeft":"marginLeft"],n=r[e==="padding"?"paddingTop":"marginTop"],a=r[e==="padding"?"paddingRight":"marginRight"];return[Tt(s),Tt(n),Tt(a)]},To=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Eo;var r=ko(e),s=document.documentElement.clientWidth,n=window.innerWidth;return{left:r[0],top:r[1],right:r[2],gap:Math.max(0,n-s+r[2]-r[0])}},Ro=ys(),Se="data-scroll-locked",Po=function(e,r,s,n){var a=e.left,o=e.top,i=e.right,c=e.gap;return s===void 0&&(s="margin"),`
  2. .`.concat(mo,` {
  3. overflow: hidden `).concat(n,`;
  4. padding-right: `).concat(c,"px ").concat(n,`;
  5. }
  6. body[`).concat(Se,`] {
  7. overflow: hidden `).concat(n,`;
  8. overscroll-behavior: contain;
  9. `).concat([r&&"position: relative ".concat(n,";"),s==="margin"&&`
  10. padding-left: `.concat(a,`px;
  11. padding-top: `).concat(o,`px;
  12. padding-right: `).concat(i,`px;
  13. margin-left:0;
  14. margin-top:0;
  15. margin-right: `).concat(c,"px ").concat(n,`;
  16. `),s==="padding"&&"padding-right: ".concat(c,"px ").concat(n,";")].filter(Boolean).join(""),`
  17. }
  18. .`).concat(nt,` {
  19. right: `).concat(c,"px ").concat(n,`;
  20. }
  21. .`).concat(at,` {
  22. margin-right: `).concat(c,"px ").concat(n,`;
  23. }
  24. .`).concat(nt," .").concat(nt,` {
  25. right: 0 `).concat(n,`;
  26. }
  27. .`).concat(at," .").concat(at,` {
  28. margin-right: 0 `).concat(n,`;
  29. }
  30. body[`).concat(Se,`] {
  31. `).concat(fo,": ").concat(c,`px;
  32. }
  33. `)},Sr=function(){var e=parseInt(document.body.getAttribute(Se)||"0",10);return isFinite(e)?e:0},Ao=function(){l.useEffect(function(){return document.body.setAttribute(Se,(Sr()+1).toString()),function(){var e=Sr()-1;e<=0?document.body.removeAttribute(Se):document.body.setAttribute(Se,e.toString())}},[])},Do=function(e){var r=e.noRelative,s=e.noImportant,n=e.gapMode,a=n===void 0?"margin":n;Ao();var o=l.useMemo(function(){return To(a)},[a]);return l.createElement(Ro,{styles:Po(o,!r,a,s?"":"!important")})},Lt=!1;if(typeof window<"u")try{var Je=Object.defineProperty({},"passive",{get:function(){return Lt=!0,!0}});window.addEventListener("test",Je,Je),window.removeEventListener("test",Je,Je)}catch{Lt=!1}var ye=Lt?{passive:!1}:!1,Oo=function(e){return e.tagName==="TEXTAREA"},js=function(e,r){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[r]!=="hidden"&&!(s.overflowY===s.overflowX&&!Oo(e)&&s[r]==="visible")},Mo=function(e){return js(e,"overflowY")},Lo=function(e){return js(e,"overflowX")},_r=function(e,r){var s=r.ownerDocument,n=r;do{typeof ShadowRoot<"u"&&n instanceof ShadowRoot&&(n=n.host);var a=ws(e,n);if(a){var o=Ns(e,n),i=o[1],c=o[2];if(i>c)return!0}n=n.parentNode}while(n&&n!==s.body);return!1},Fo=function(e){var r=e.scrollTop,s=e.scrollHeight,n=e.clientHeight;return[r,s,n]},$o=function(e){var r=e.scrollLeft,s=e.scrollWidth,n=e.clientWidth;return[r,s,n]},ws=function(e,r){return e==="v"?Mo(r):Lo(r)},Ns=function(e,r){return e==="v"?Fo(r):$o(r)},Io=function(e,r){return e==="h"&&r==="rtl"?-1:1},qo=function(e,r,s,n,a){var o=Io(e,window.getComputedStyle(r).direction),i=o*n,c=s.target,d=r.contains(c),f=!1,u=i>0,x=0,p=0;do{if(!c)break;var h=Ns(e,c),g=h[0],m=h[1],v=h[2],j=m-v-o*g;(g||j)&&ws(e,c)&&(x+=j,p+=g);var w=c.parentNode;c=w&&w.nodeType===Node.DOCUMENT_FRAGMENT_NODE?w.host:w}while(!d&&c!==document.body||d&&(r.contains(c)||r===c));return(u&&Math.abs(x)<1||!u&&Math.abs(p)<1)&&(f=!0),f},et=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Cr=function(e){return[e.deltaX,e.deltaY]},Er=function(e){return e&&"current"in e?e.current:e},Bo=function(e,r){return e[0]===r[0]&&e[1]===r[1]},zo=function(e){return`
  34. .block-interactivity-`.concat(e,` {pointer-events: none;}
  35. .allow-interactivity-`).concat(e,` {pointer-events: all;}
  36. `)},Uo=0,je=[];function Wo(e){var r=l.useRef([]),s=l.useRef([0,0]),n=l.useRef(),a=l.useState(Uo++)[0],o=l.useState(ys)[0],i=l.useRef(e);l.useEffect(function(){i.current=e},[e]),l.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var m=uo([e.lockRef.current],(e.shards||[]).map(Er),!0).filter(Boolean);return m.forEach(function(v){return v.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),m.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var c=l.useCallback(function(m,v){if("touches"in m&&m.touches.length===2||m.type==="wheel"&&m.ctrlKey)return!i.current.allowPinchZoom;var j=et(m),w=s.current,y="deltaX"in m?m.deltaX:w[0]-j[0],b="deltaY"in m?m.deltaY:w[1]-j[1],S,D=m.target,B=Math.abs(y)>Math.abs(b)?"h":"v";if("touches"in m&&B==="h"&&D.type==="range")return!1;var te=window.getSelection(),R=te&&te.anchorNode,z=R?R===D||R.contains(D):!1;if(z)return!1;var U=_r(B,D);if(!U)return!0;if(U?S=B:(S=B==="v"?"h":"v",U=_r(B,D)),!U)return!1;if(!n.current&&"changedTouches"in m&&(y||b)&&(n.current=S),!S)return!0;var E=n.current||S;return qo(E,v,m,E==="h"?y:b)},[]),d=l.useCallback(function(m){var v=m;if(!(!je.length||je[je.length-1]!==o)){var j="deltaY"in v?Cr(v):et(v),w=r.current.filter(function(S){return S.name===v.type&&(S.target===v.target||v.target===S.shadowParent)&&Bo(S.delta,j)})[0];if(w&&w.should){v.cancelable&&v.preventDefault();return}if(!w){var y=(i.current.shards||[]).map(Er).filter(Boolean).filter(function(S){return S.contains(v.target)}),b=y.length>0?c(v,y[0]):!i.current.noIsolation;b&&v.cancelable&&v.preventDefault()}}},[]),f=l.useCallback(function(m,v,j,w){var y={name:m,delta:v,target:j,should:w,shadowParent:Vo(j)};r.current.push(y),setTimeout(function(){r.current=r.current.filter(function(b){return b!==y})},1)},[]),u=l.useCallback(function(m){s.current=et(m),n.current=void 0},[]),x=l.useCallback(function(m){f(m.type,Cr(m),m.target,c(m,e.lockRef.current))},[]),p=l.useCallback(function(m){f(m.type,et(m),m.target,c(m,e.lockRef.current))},[]);l.useEffect(function(){return je.push(o),e.setCallbacks({onScrollCapture:x,onWheelCapture:x,onTouchMoveCapture:p}),document.addEventListener("wheel",d,ye),document.addEventListener("touchmove",d,ye),document.addEventListener("touchstart",u,ye),function(){je=je.filter(function(m){return m!==o}),document.removeEventListener("wheel",d,ye),document.removeEventListener("touchmove",d,ye),document.removeEventListener("touchstart",u,ye)}},[]);var h=e.removeScrollBar,g=e.inert;return l.createElement(l.Fragment,null,g?l.createElement(o,{styles:zo(a)}):null,h?l.createElement(Do,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Vo(e){for(var r=null;e!==null;)e instanceof ShadowRoot&&(r=e.host,e=e.host),e=e.parentNode;return r}const Ho=yo(bs,Wo);var Ss=l.forwardRef(function(e,r){return l.createElement(bt,K({},e,{ref:r,sideCar:Ho}))});Ss.classNames=bt.classNames;var Qo=function(e){if(typeof document>"u")return null;var r=Array.isArray(e)?e[0]:e;return r.ownerDocument.body},we=new WeakMap,tt=new WeakMap,rt={},Rt=0,_s=function(e){return e&&(e.host||_s(e.parentNode))},Ko=function(e,r){return r.map(function(s){if(e.contains(s))return s;var n=_s(s);return n&&e.contains(n)?n:(console.error("aria-hidden",s,"in not contained inside",e,". Doing nothing"),null)}).filter(function(s){return!!s})},Go=function(e,r,s,n){var a=Ko(r,Array.isArray(e)?e:[e]);rt[s]||(rt[s]=new WeakMap);var o=rt[s],i=[],c=new Set,d=new Set(a),f=function(x){!x||c.has(x)||(c.add(x),f(x.parentNode))};a.forEach(f);var u=function(x){!x||d.has(x)||Array.prototype.forEach.call(x.children,function(p){if(c.has(p))u(p);else try{var h=p.getAttribute(n),g=h!==null&&h!=="false",m=(we.get(p)||0)+1,v=(o.get(p)||0)+1;we.set(p,m),o.set(p,v),i.push(p),m===1&&g&&tt.set(p,!0),v===1&&p.setAttribute(s,"true"),g||p.setAttribute(n,"true")}catch(j){console.error("aria-hidden: cannot operate on ",p,j)}})};return u(r),c.clear(),Rt++,function(){i.forEach(function(x){var p=we.get(x)-1,h=o.get(x)-1;we.set(x,p),o.set(x,h),p||(tt.has(x)||x.removeAttribute(n),tt.delete(x)),h||x.removeAttribute(s)}),Rt--,Rt||(we=new WeakMap,we=new WeakMap,tt=new WeakMap,rt={})}},Yo=function(e,r,s){s===void 0&&(s="data-aria-hidden");var n=Array.from(Array.isArray(e)?e:[e]),a=Qo(e);return a?(n.push.apply(n,Array.from(a.querySelectorAll("[aria-live], script"))),Go(n,a,s,"aria-hidden")):function(){return null}},yt="Dialog",[Cs]=Oa(yt),[Xo,Q]=Cs(yt),Es=e=>{const{__scopeDialog:r,children:s,open:n,defaultOpen:a,onOpenChange:o,modal:i=!0}=e,c=l.useRef(null),d=l.useRef(null),[f,u]=Ia({prop:n,defaultProp:a??!1,onChange:o,caller:yt});return t.jsx(Xo,{scope:r,triggerRef:c,contentRef:d,contentId:St(),titleId:St(),descriptionId:St(),open:f,onOpenChange:u,onOpenToggle:l.useCallback(()=>u(x=>!x),[u]),modal:i,children:s})};Es.displayName=yt;var ks="DialogTrigger",Ts=l.forwardRef((e,r)=>{const{__scopeDialog:s,...n}=e,a=Q(ks,s),o=xe(r,a.triggerRef);return t.jsx(X.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":tr(a.open),...n,ref:o,onClick:oe(e.onClick,a.onOpenToggle)})});Ts.displayName=ks;var Jt="DialogPortal",[Zo,Rs]=Cs(Jt,{forceMount:void 0}),Ps=e=>{const{__scopeDialog:r,forceMount:s,children:n,container:a}=e,o=Q(Jt,r);return t.jsx(Zo,{scope:r,forceMount:s,children:l.Children.map(n,i=>t.jsx(vt,{present:s||o.open,children:t.jsx(ps,{asChild:!0,container:a,children:i})}))})};Ps.displayName=Jt;var lt="DialogOverlay",As=l.forwardRef((e,r)=>{const s=Rs(lt,e.__scopeDialog),{forceMount:n=s.forceMount,...a}=e,o=Q(lt,e.__scopeDialog);return o.modal?t.jsx(vt,{present:n||o.open,children:t.jsx(ei,{...a,ref:r})}):null});As.displayName=lt;var Jo=Gt("DialogOverlay.RemoveScroll"),ei=l.forwardRef((e,r)=>{const{__scopeDialog:s,...n}=e,a=Q(lt,s),o=Ka(),i=xe(r,o);return t.jsx(Ss,{as:Jo,allowPinchZoom:!0,shards:[a.contentRef],children:t.jsx(X.div,{"data-state":tr(a.open),...n,ref:i,style:{pointerEvents:"auto",...n.style}})})}),Ce="DialogContent",Ds=l.forwardRef((e,r)=>{const s=Rs(Ce,e.__scopeDialog),{forceMount:n=s.forceMount,...a}=e,o=Q(Ce,e.__scopeDialog);return t.jsx(vt,{present:n||o.open,children:o.modal?t.jsx(ti,{...a,ref:r}):t.jsx(ri,{...a,ref:r})})});Ds.displayName=Ce;var ti=l.forwardRef((e,r)=>{const s=Q(Ce,e.__scopeDialog),n=l.useRef(null),a=xe(r,s.contentRef,n);return l.useEffect(()=>{const o=n.current;if(o)return Yo(o)},[]),t.jsx(Os,{...e,ref:a,trapFocus:s.open,disableOutsidePointerEvents:s.open,onCloseAutoFocus:oe(e.onCloseAutoFocus,o=>{o.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:oe(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,c=i.button===0&&i.ctrlKey===!0;(i.button===2||c)&&o.preventDefault()}),onFocusOutside:oe(e.onFocusOutside,o=>o.preventDefault())})}),ri=l.forwardRef((e,r)=>{const s=Q(Ce,e.__scopeDialog),n=l.useRef(!1),a=l.useRef(!1);return t.jsx(Os,{...e,ref:r,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{e.onCloseAutoFocus?.(o),o.defaultPrevented||(n.current||s.triggerRef.current?.focus(),o.preventDefault()),n.current=!1,a.current=!1},onInteractOutside:o=>{e.onInteractOutside?.(o),o.defaultPrevented||(n.current=!0,o.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const i=o.target;s.triggerRef.current?.contains(i)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&a.current&&o.preventDefault()}})}),Os=l.forwardRef((e,r)=>{const{__scopeDialog:s,trapFocus:n,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,c=Q(Ce,s);return lo(),t.jsx(t.Fragment,{children:t.jsx(hs,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:a,onUnmountAutoFocus:o,children:t.jsx(ms,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":tr(c.open),...i,ref:r,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})}),Ms="DialogTitle",Ls=l.forwardRef((e,r)=>{const{__scopeDialog:s,...n}=e,a=Q(Ms,s);return t.jsx(X.h2,{id:a.titleId,...n,ref:r})});Ls.displayName=Ms;var Fs="DialogDescription",$s=l.forwardRef((e,r)=>{const{__scopeDialog:s,...n}=e,a=Q(Fs,s);return t.jsx(X.p,{id:a.descriptionId,...n,ref:r})});$s.displayName=Fs;var Is="DialogClose",er=l.forwardRef((e,r)=>{const{__scopeDialog:s,...n}=e,a=Q(Is,s);return t.jsx(X.button,{type:"button",...n,ref:r,onClick:oe(e.onClick,()=>a.onOpenChange(!1))})});er.displayName=Is;function tr(e){return e?"open":"closed"}const pe=Es,jt=Ts,si=Ps,ni=er,qs=l.forwardRef(({className:e,...r},s)=>t.jsx(As,{ref:s,className:T("fixed inset-0 z-50 bg-black/50 backdrop-blur-sm","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...r}));qs.displayName="DialogOverlay";const ce=l.forwardRef(({className:e,children:r,...s},n)=>t.jsxs(si,{children:[t.jsx(qs,{}),t.jsxs(Ds,{ref:n,className:T("fixed left-1/2 top-1/2 z-50 grid w-full max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 border bg-background p-6 shadow-lg sm:rounded-lg","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95","max-h-[90vh] overflow-y-auto",e),...s,children:[r,t.jsxs(er,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none",children:[t.jsx(dn,{className:"h-4 w-4"}),t.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ce.displayName="DialogContent";function ge({className:e,...r}){return t.jsx("div",{className:T("flex flex-col gap-1.5 text-left",e),...r})}function ve({className:e,...r}){return t.jsx("div",{className:T("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end sm:gap-2",e),...r})}const le=l.forwardRef(({className:e,...r},s)=>t.jsx(Ls,{ref:s,className:T("text-lg font-semibold leading-none tracking-tight",e),...r}));le.displayName="DialogTitle";const de=l.forwardRef(({className:e,...r},s)=>t.jsx($s,{ref:s,className:T("text-sm text-muted-foreground",e),...r}));de.displayName="DialogDescription";const ai=/^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/,oi=Re({slug:L().min(2,"Slug must be 2–64 characters").max(64,"Slug must be 2–64 characters").regex(ai,"Lowercase letters, digits, and dashes only"),display_name:L().min(1,"Display name is required"),contact_email:L().email("Enter a valid email"),rate_limit_per_sec:mt({invalid_type_error:"Enter a number"}).int("Whole number only").min(1,"Must be at least 1").max(1e6,"Must be at most 1,000,000"),fcm_shared:ze()});function kr(){const[e,r]=l.useState(!1),s=ie(),n=Ra(),a=Pe({resolver:Oe(oi),defaultValues:{slug:"",display_name:"",contact_email:"",rate_limit_per_sec:1e4,fcm_shared:!0}});l.useEffect(()=>{e&&a.reset()},[e,a]);const o=a.handleSubmit(async i=>{const c={slug:i.slug.trim(),display_name:i.display_name.trim(),contact_email:i.contact_email.trim(),rate_limit_per_sec:i.rate_limit_per_sec,fcm_shared:i.fcm_shared};try{const d=await n.mutateAsync(c);A.success(`Created ${d.display_name}`),r(!1),s(`/companies/${d.id}`)}catch(d){const f=st(d);A.error(f),f.toLowerCase().includes("slug")&&a.setError("slug",{message:f})}});return t.jsxs(pe,{open:e,onOpenChange:r,children:[t.jsx(jt,{asChild:!0,children:t.jsxs(N,{children:[t.jsx(Ut,{className:"h-4 w-4"}),"New company"]})}),t.jsxs(ce,{children:[t.jsxs(ge,{children:[t.jsx(le,{children:"New company"}),t.jsx(de,{children:"The slug becomes part of every event this tenant sends (and shows up in the audit log). Choose carefully — it cannot be changed after creation."})]}),t.jsxs("form",{onSubmit:o,className:"space-y-4",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(C,{htmlFor:"slug",children:"Slug"}),t.jsx(k,{id:"slug",placeholder:"acme-corp",autoComplete:"off",...a.register("slug"),"aria-invalid":!!a.formState.errors.slug}),a.formState.errors.slug?t.jsx("p",{className:"text-xs text-destructive",children:a.formState.errors.slug.message}):t.jsx("p",{className:"text-xs text-muted-foreground",children:"2–64 chars, lowercase + digits + dashes."})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(C,{htmlFor:"rate_limit_per_sec",children:"Rate limit (events/sec)"}),t.jsx(k,{id:"rate_limit_per_sec",type:"number",min:1,max:1e6,...a.register("rate_limit_per_sec",{valueAsNumber:!0}),"aria-invalid":!!a.formState.errors.rate_limit_per_sec}),a.formState.errors.rate_limit_per_sec?t.jsx("p",{className:"text-xs text-destructive",children:a.formState.errors.rate_limit_per_sec.message}):null]})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(C,{htmlFor:"display_name",children:"Display name"}),t.jsx(k,{id:"display_name",placeholder:"Acme Corporation",...a.register("display_name"),"aria-invalid":!!a.formState.errors.display_name}),a.formState.errors.display_name?t.jsx("p",{className:"text-xs text-destructive",children:a.formState.errors.display_name.message}):null]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(C,{htmlFor:"contact_email",children:"Contact email"}),t.jsx(k,{id:"contact_email",type:"email",placeholder:"ops@acme.example",autoComplete:"off",...a.register("contact_email"),"aria-invalid":!!a.formState.errors.contact_email}),a.formState.errors.contact_email?t.jsx("p",{className:"text-xs text-destructive",children:a.formState.errors.contact_email.message}):null]}),t.jsxs("div",{className:"flex items-start gap-2 rounded-md border bg-muted/40 p-3",children:[t.jsx("input",{id:"fcm_shared",type:"checkbox",className:"mt-0.5 h-4 w-4 rounded border-input",...a.register("fcm_shared")}),t.jsxs("div",{className:"space-y-0.5",children:[t.jsx(C,{htmlFor:"fcm_shared",className:"cursor-pointer",children:"Use shared FCM pool"}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Default. Only turn this off for high-volume tenants that need a dedicated sender ID (M13b W3 territory)."})]})]}),t.jsxs(ve,{children:[t.jsx(N,{type:"button",variant:"ghost",onClick:()=>r(!1),disabled:n.isPending,children:"Cancel"}),t.jsx(N,{type:"submit",disabled:n.isPending,children:n.isPending?"Creating…":"Create company"})]})]})]})]})}const ii=cs("inline-flex items-center rounded-md border px-2 py-0.5 text-xs font-medium transition-colors",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground",secondary:"border-transparent bg-secondary text-secondary-foreground",outline:"text-foreground",success:"border-transparent bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-300",warning:"border-transparent bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-300",danger:"border-transparent bg-rose-100 text-rose-800 dark:bg-rose-900/30 dark:text-rose-300",muted:"border-transparent bg-muted text-muted-foreground"}},defaultVariants:{variant:"default"}}),Me=l.forwardRef(({className:e,variant:r,...s},n)=>t.jsx("span",{ref:n,className:T(ii({variant:r}),e),...s}));Me.displayName="Badge";const ci={active:"Active",suspended:"Suspended",archived:"Archived"},li={active:"success",suspended:"warning",archived:"muted"};function di(e){return ci[e]??e}function ui(e){return li[e]??"muted"}function Bs({status:e}){return t.jsx(Me,{variant:ui(e),children:di(e)})}function zs(e){return e>=1e6?`${(e/1e6).toFixed(1)}M/s`:e>=1e3?`${(e/1e3).toFixed(1)}k/s`:`${e}/s`}function qe(e){if(!e)return"—";const r=new Date(e);return Number.isNaN(r.getTime())?e:r.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}const mi=[{value:"",label:"All"},{value:"active",label:"Active"},{value:"suspended",label:"Suspended"},{value:"archived",label:"Archived"}];function fi(){const[e,r]=Bt(),[s,n]=l.useState(e.get("q")??""),a=e.get("status")??"",{user:o}=ee(),i=as(o?.role);l.useEffect(()=>{const h=setTimeout(()=>{const g=new URLSearchParams(e);s.trim()?g.set("q",s.trim()):g.delete("q"),r(g,{replace:!0})},300);return()=>clearTimeout(h)},[s]);const c=l.useMemo(()=>({q:e.get("q")??void 0,status:a||void 0,limit:100}),[e,a]),{data:d,isPending:f,isError:u,error:x,refetch:p}=Xt(c);return t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[t.jsxs("div",{children:[t.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:"Companies"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage the tenants that send events to the router."})]}),i?t.jsx(kr,{}):null]}),t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[t.jsxs("div",{className:"relative flex-1 sm:max-w-sm",children:[t.jsx(Wt,{className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(k,{placeholder:"Search by slug or name",className:"pl-8",value:s,onChange:h=>n(h.target.value),"aria-label":"Search companies"})]}),t.jsx("div",{className:"flex gap-1",children:mi.map(h=>{const g=a===h.value;return t.jsx(N,{variant:g?"secondary":"ghost",size:"sm",onClick:()=>{const m=new URLSearchParams(e);h.value?m.set("status",h.value):m.delete("status"),r(m,{replace:!0})},children:h.label},h.value)})})]}),u?t.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm text-destructive",children:[t.jsx("p",{className:"font-medium",children:"Failed to load companies."}),t.jsx("p",{className:"mt-1 text-xs opacity-80",children:x instanceof Error?x.message:"Unknown error"}),t.jsx(N,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>p(),children:"Retry"})]}):null,f?t.jsx("div",{className:"rounded-md border bg-card p-8 text-center text-sm text-muted-foreground",children:"Loading…"}):d&&d.items.length===0?t.jsx(Yt,{icon:t.jsx(zr,{className:"h-8 w-8"}),title:"No companies yet",description:i?"Create the first company to start routing events.":"You will see your company here once it has been set up.",action:i?t.jsx(kr,{}):null}):d?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"rounded-md border bg-card",children:t.jsxs(ht,{children:[t.jsx(xt,{children:t.jsxs(fe,{children:[t.jsx(O,{children:"Name"}),t.jsx(O,{children:"Slug"}),t.jsx(O,{children:"Status"}),t.jsx(O,{className:"text-right",children:"Rate limit"}),t.jsx(O,{children:"FCM"}),t.jsx(O,{children:"Created"})]})}),t.jsx(pt,{children:d.items.map(h=>t.jsxs(fe,{children:[t.jsx(M,{children:t.jsx(Te,{to:`/companies/${h.id}`,className:"font-medium text-foreground hover:underline",children:h.display_name})}),t.jsx(M,{children:t.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:h.slug})}),t.jsx(M,{children:t.jsx(Bs,{status:h.status})}),t.jsx(M,{className:"text-right tabular-nums",children:zs(h.rate_limit_per_sec)}),t.jsx(M,{className:"text-xs text-muted-foreground",children:h.fcm_shared?"shared":"dedicated"}),t.jsx(M,{className:"text-xs text-muted-foreground",children:qe(h.created_at)})]},h.id))})]})}),t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing ",d.items.length," of ",d.total]})]}):null]})}const hi=Re({display_name:L().min(1,"Display name is required"),contact_email:L().email("Enter a valid email"),rate_limit_per_sec:mt({invalid_type_error:"Enter a number"}).int("Whole number only").min(1).max(1e6),fcm_shared:ze()}),xi={display_name:"",contact_email:"",rate_limit_per_sec:1e4,fcm_shared:!0};function pi(){const{id:e=""}=Ve(),r=ie(),{user:s}=ee(),n=ft(s?.role),a=ea(s?.role),o=Ta(e),i=Pa(e),c=Aa(e),d=Pe({resolver:Oe(hi),defaultValues:xi});if(l.useEffect(()=>{const p=o.data;p&&(d.setValue("display_name",p.display_name),d.setValue("contact_email",p.contact_email),d.setValue("rate_limit_per_sec",p.rate_limit_per_sec),d.setValue("fcm_shared",p.fcm_shared))},[o.data,d]),!a)return t.jsx("div",{className:"rounded-md border bg-card p-6 text-sm text-muted-foreground",children:"You do not have access to this company."});if(o.isError){const p=st(o.error);return t.jsxs("div",{className:"space-y-3",children:[t.jsxs(N,{variant:"ghost",size:"sm",onClick:()=>r("/companies"),children:[t.jsx(ct,{className:"h-4 w-4"}),"Back"]}),t.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm text-destructive",children:p})]})}if(!o.data)return t.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading…"});const f=o.data,u=d.handleSubmit(async p=>{try{await i.mutateAsync({display_name:p.display_name.trim(),contact_email:p.contact_email.trim(),rate_limit_per_sec:p.rate_limit_per_sec,fcm_shared:p.fcm_shared}),A.success("Saved")}catch(h){A.error(st(h))}}),x=async p=>{try{await c.mutateAsync(p),A.success(`Status set to ${p}`)}catch(h){A.error(st(h))}};return t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs(N,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>r("/companies"),children:[t.jsx(ct,{className:"h-4 w-4"}),"Back to companies"]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:f.display_name}),t.jsx(Bs,{status:f.status})]}),t.jsxs("p",{className:"text-sm text-muted-foreground",children:[t.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:f.slug}),t.jsx("span",{className:"mx-2 opacity-50",children:"·"}),"created ",qe(f.created_at)]})]}),t.jsxs("div",{className:"grid gap-6 md:grid-cols-3",children:[t.jsxs(F,{className:"md:col-span-2",children:[t.jsxs($,{children:[t.jsx(I,{children:"Details"}),t.jsx(G,{children:n?"All fields are editable.":"Display name and contact email are editable. Other fields require a super-admin."})]}),t.jsx(q,{children:t.jsxs("form",{onSubmit:u,className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(C,{htmlFor:"display_name",children:"Display name"}),t.jsx(k,{id:"display_name",...d.register("display_name"),"aria-invalid":!!d.formState.errors.display_name}),d.formState.errors.display_name?t.jsx("p",{className:"text-xs text-destructive",children:d.formState.errors.display_name.message}):null]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(C,{htmlFor:"contact_email",children:"Contact email"}),t.jsx(k,{id:"contact_email",type:"email",autoComplete:"off",...d.register("contact_email"),"aria-invalid":!!d.formState.errors.contact_email}),d.formState.errors.contact_email?t.jsx("p",{className:"text-xs text-destructive",children:d.formState.errors.contact_email.message}):null]}),t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(C,{htmlFor:"rate_limit_per_sec",children:"Rate limit"}),t.jsx(k,{id:"rate_limit_per_sec",type:"number",min:1,max:1e6,disabled:!n,...d.register("rate_limit_per_sec",{valueAsNumber:!0}),"aria-invalid":!!d.formState.errors.rate_limit_per_sec}),d.formState.errors.rate_limit_per_sec?t.jsx("p",{className:"text-xs text-destructive",children:d.formState.errors.rate_limit_per_sec.message}):null]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(C,{children:"FCM pool"}),t.jsxs("label",{className:"flex items-center gap-2 rounded-md border bg-muted/40 p-2 text-sm",children:[t.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-input",disabled:!n,...d.register("fcm_shared")}),"Use shared FCM pool"]})]})]}),t.jsx("div",{className:"flex justify-end",children:t.jsx(N,{type:"submit",disabled:i.isPending,children:i.isPending?"Saving…":"Save changes"})})]})})]}),t.jsxs("div",{className:"space-y-4",children:[n?t.jsxs(F,{children:[t.jsxs($,{children:[t.jsx(I,{children:"Status"}),t.jsx(G,{children:"Suspending stops new ingest immediately. Archiving is permanent and is only used to retire a tenant."})]}),t.jsxs(q,{className:"space-y-2",children:[f.status==="active"?t.jsx(N,{variant:"outline",className:"w-full",disabled:c.isPending,onClick:()=>void x("suspended"),children:"Suspend"}):f.status==="suspended"?t.jsx(N,{variant:"default",className:"w-full",disabled:c.isPending,onClick:()=>void x("active"),children:"Activate"}):null,f.status!=="archived"?t.jsx(gi,{onConfirm:()=>void x("archived"),pending:c.isPending}):t.jsx("p",{className:"rounded-md border bg-muted/40 p-3 text-xs text-muted-foreground",children:"Archived. Status changes are not allowed."})]})]}):null,t.jsxs(F,{children:[t.jsx($,{children:t.jsx(I,{className:"text-base",children:"Metadata"})}),t.jsxs(q,{className:"space-y-2 text-sm",children:[t.jsx(ue,{label:"ID",value:t.jsx("code",{className:"text-xs",children:f.id})}),t.jsx(ue,{label:"Slug",value:t.jsx("code",{className:"text-xs",children:f.slug})}),t.jsx(ue,{label:"Rate limit",value:zs(f.rate_limit_per_sec)}),t.jsx(ue,{label:"FCM",value:f.fcm_shared?"shared":"dedicated"}),t.jsx(ue,{label:"Created",value:qe(f.created_at)}),t.jsx(ue,{label:"Updated",value:qe(f.updated_at)}),f.archived_at?t.jsx(ue,{label:"Archived",value:qe(f.archived_at)}):null]})]})]})]})]})}function ue({label:e,value:r}){return t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:e}),t.jsx("span",{className:"text-right",children:r})]})}function gi({onConfirm:e,pending:r}){return t.jsxs(pe,{children:[t.jsx(jt,{asChild:!0,children:t.jsx(N,{variant:"destructive",className:"w-full",disabled:r,children:"Archive…"})}),t.jsxs(ce,{children:[t.jsxs(ge,{children:[t.jsxs(le,{className:"flex items-center gap-2",children:[t.jsx(un,{className:"h-4 w-4 text-destructive"}),"Archive this company?"]}),t.jsxs(de,{children:["Archiving is ",t.jsx("strong",{children:"permanent"}),": the tenant cannot be reactivated, and new events will be rejected. Existing rows (deliveries, audit, DLQ) are kept for compliance but are not surfaced in the UI."]})]}),t.jsxs(ve,{children:[t.jsx(ni,{asChild:!0,children:t.jsx(N,{variant:"ghost",disabled:r,children:"Cancel"})}),t.jsx(N,{variant:"destructive",disabled:r,onClick:e,children:r?"Archiving…":"Archive company"})]})]})]})}function vi(){return t.jsxs(zt,{children:[t.jsx(ae,{index:!0,element:t.jsx(fi,{})}),t.jsx(ae,{path:":id",element:t.jsx(pi,{})})]})}const He={list:(e,r)=>["sources","list",e,r],detail:(e,r)=>["sources","detail",e,r]};function bi(e,r){const s=new URLSearchParams;r.q&&s.set("q",r.q),r.type&&s.set("type",r.type),r.status&&s.set("status",r.status),r.limit&&s.set("limit",String(r.limit)),r.offset&&s.set("offset",String(r.offset));const n=s.toString();return n?`/v1/tenants/${e}/sources?${n}`:`/v1/tenants/${e}/sources`}function yi(e,r){return ke({queryKey:He.list(e,r),queryFn:()=>he(bi(e,r)),enabled:!!e,staleTime:15e3})}function ji(e,r){return ke({queryKey:He.detail(e,r),queryFn:()=>he(`/v1/tenants/${e}/sources/${r}`),enabled:!!e&&!!r})}function wi(e){const r=W();return V({mutationFn:s=>H("POST",`/v1/tenants/${e}/sources`,s),onSuccess:()=>{r.invalidateQueries({queryKey:["sources","list",e]})}})}function Ni(e,r){const s=W();return V({mutationFn:n=>H("PATCH",`/v1/tenants/${e}/sources/${r}`,n),onSuccess:n=>{s.setQueryData(He.detail(e,r),n),s.invalidateQueries({queryKey:["sources","list",e]})}})}function Si(e,r){const s=W();return V({mutationFn:n=>H("POST",`/v1/tenants/${e}/sources/${r}/status`,{status:n}),onSuccess:n=>{s.setQueryData(He.detail(e,r),n),s.invalidateQueries({queryKey:["sources","list",e]})}})}function _i(e,r){const s=W();return V({mutationFn:()=>H("POST",`/v1/tenants/${e}/sources/${r}/rotate-secrets`,{}),onSuccess:n=>{s.setQueryData(He.detail(e,r),n.source),s.invalidateQueries({queryKey:["sources","list",e]})}})}function ot(e){if(e instanceof De){const r=e.body;return r?.message??r?.error??e.message}return e instanceof Error?e.message:"Unknown error"}const Ee=l.forwardRef(({className:e,...r},s)=>t.jsx("textarea",{ref:s,className:T("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background","placeholder:text-muted-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","disabled:cursor-not-allowed disabled:opacity-50",e),...r}));Ee.displayName="Textarea";const dt=l.forwardRef(({className:e,...r},s)=>t.jsx("input",{ref:s,type:"checkbox",className:T("h-4 w-4 shrink-0 rounded-sm border border-input bg-background","cursor-pointer accent-primary","disabled:cursor-not-allowed disabled:opacity-50","focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",e),...r}));dt.displayName="Checkbox";const Ci=/^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/,Ei=Re({id:L().min(2,"Source id must be 2–64 characters").max(64,"Source id must be 2–64 characters").regex(Ci,"Lowercase letters, digits, and dashes only"),name:L().min(1,"Name is required").max(200,"Name must be ≤ 200 characters"),type:Vr(["http","mqtt","ws","grpc"]),rate_limit_per_sec:mt({invalid_type_error:"Enter a number"}).int("Whole number only").min(1,"Must be at least 1").max(1e6,"Must be at most 1,000,000"),description:L().max(500,"Description must be ≤ 500 characters").optional().or(Y("")),mtls_required:ze(),auto_secrets:ze(),hmac_secret:L().optional().or(Y("")),api_key:L().optional().or(Y(""))}),Tr={id:"",name:"",type:"http",rate_limit_per_sec:1e3,description:"",mtls_required:!1,auto_secrets:!0,hmac_secret:"",api_key:""};function Rr({tenantId:e}){const[r,s]=l.useState(!1),[n,a]=l.useState(null),o=wi(e),i=Pe({resolver:Oe(Ei),defaultValues:Tr});l.useEffect(()=>{r&&i.reset(Tr)},[r,i]);const c=i.handleSubmit(async d=>{const f={id:d.id.trim(),name:d.name.trim(),type:d.type,rate_limit_per_sec:d.rate_limit_per_sec,description:d.description??"",mtls_required:d.mtls_required,hmac_secret:d.auto_secrets?void 0:d.hmac_secret||void 0,api_key:d.auto_secrets?void 0:d.api_key||void 0};try{const u=await o.mutateAsync(f);s(!1),u.secrets?a(u):A.success(`Source "${u.source.name}" created.`)}catch(u){A.error(ot(u))}});return t.jsxs(t.Fragment,{children:[t.jsxs(pe,{open:r,onOpenChange:s,children:[t.jsx(jt,{asChild:!0,children:t.jsxs(N,{children:[t.jsx(Ut,{className:"mr-2 h-4 w-4"}),"New source"]})}),t.jsxs(ce,{className:"sm:max-w-lg",children:[t.jsxs(ge,{children:[t.jsx(le,{children:"New source"}),t.jsxs(de,{children:["Create a new ingest endpoint for this company. Secrets are generated and shown ",t.jsx("strong",{children:"only once"}),"; save them before closing the next dialog."]})]}),t.jsxs("form",{onSubmit:c,className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"col-span-1 flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"src-id",children:"ID"}),t.jsx(k,{id:"src-id",placeholder:"primary",...i.register("id")}),i.formState.errors.id?t.jsx("p",{className:"text-xs text-destructive",children:i.formState.errors.id.message}):null]}),t.jsxs("div",{className:"col-span-1 flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"src-type",children:"Type"}),t.jsxs("select",{id:"src-type",className:"h-9 rounded-md border border-input bg-background px-3 text-sm",...i.register("type"),children:[t.jsx("option",{value:"http",children:"HTTP"}),t.jsx("option",{value:"mqtt",children:"MQTT"}),t.jsx("option",{value:"ws",children:"WebSocket"}),t.jsx("option",{value:"grpc",children:"gRPC"})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"src-name",children:"Name"}),t.jsx(k,{id:"src-name",placeholder:"Primary Source",...i.register("name")}),i.formState.errors.name?t.jsx("p",{className:"text-xs text-destructive",children:i.formState.errors.name.message}):null]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"col-span-1 flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"src-rl",children:"Rate limit (/s)"}),t.jsx(k,{id:"src-rl",type:"number",min:1,...i.register("rate_limit_per_sec",{valueAsNumber:!0})}),i.formState.errors.rate_limit_per_sec?t.jsx("p",{className:"text-xs text-destructive",children:i.formState.errors.rate_limit_per_sec.message}):null]}),t.jsxs("div",{className:"col-span-1 flex items-center gap-2 pt-6",children:[t.jsx(dt,{id:"src-mtls",...i.register("mtls_required")}),t.jsx(C,{htmlFor:"src-mtls",className:"cursor-pointer",children:"Require mTLS"})]})]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"src-desc",children:"Description"}),t.jsx(Ee,{id:"src-desc",rows:2,placeholder:"Optional. What does this source do?",...i.register("description")})]}),t.jsxs("div",{className:"rounded-md border bg-muted/30 p-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(dt,{id:"src-auto",...i.register("auto_secrets")}),t.jsx(C,{htmlFor:"src-auto",className:"cursor-pointer",children:"Auto-generate HMAC secret + API key"})]}),i.watch("auto_secrets")?null:t.jsxs("div",{className:"mt-3 grid grid-cols-1 gap-2",children:[t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"src-hmac",className:"text-xs",children:"HMAC secret (32–128 chars)"}),t.jsx(k,{id:"src-hmac",...i.register("hmac_secret")})]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"src-apikey",className:"text-xs",children:"API key (16–128 chars)"}),t.jsx(k,{id:"src-apikey",...i.register("api_key")})]})]})]}),t.jsxs(ve,{children:[t.jsx(N,{type:"button",variant:"ghost",onClick:()=>s(!1),children:"Cancel"}),t.jsx(N,{type:"submit",disabled:o.isPending,children:o.isPending?"Creating…":"Create source"})]})]})]})]}),t.jsx(ki,{state:n,onClose:()=>{n&&A.success(`Source "${n.source.name}" created.`),a(null)}})]})}function ki({state:e,onClose:r}){return t.jsx(pe,{open:!!e,onOpenChange:s=>!s&&r(),children:t.jsxs(ce,{className:"sm:max-w-lg",children:[t.jsxs(ge,{children:[t.jsxs(le,{className:"flex items-center gap-2",children:[t.jsx(_e,{className:"h-5 w-5 text-amber-500"}),"Save these secrets now"]}),t.jsxs(de,{children:["These are the HMAC secret and API key for the source. They are shown ",t.jsx("strong",{children:"once"}),". After you close this dialog, only the hashes are stored; the plaintext is gone from the server."]})]}),e?t.jsx(Ti,{secrets:e.secrets}):null,t.jsx(ve,{children:t.jsx(N,{onClick:r,children:"I have saved these — close"})})]})})}function Ti({secrets:e}){const[r,s]=l.useState(!1),[n,a]=l.useState(!1);return t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx(Pr,{label:"HMAC secret",value:e?.hmac_secret??"",show:r,onToggle:()=>s(o=>!o)}),t.jsx(Pr,{label:"API key",value:e?.api_key??"",show:n,onToggle:()=>a(o=>!o)})]})}function Pr({label:e,value:r,show:s,onToggle:n}){const[a,o]=l.useState(!1);return t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:e}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(N,{type:"button",size:"sm",variant:"ghost",onClick:n,"aria-label":s?"Hide":"Show",children:s?t.jsx(Vt,{className:"h-3 w-3"}):t.jsx(Ht,{className:"h-3 w-3"})}),t.jsxs(N,{type:"button",size:"sm",variant:"ghost",onClick:async()=>{try{await navigator.clipboard.writeText(r),o(!0),setTimeout(()=>o(!1),1500)}catch{}},"aria-label":"Copy",children:[t.jsx(mn,{className:"h-3 w-3"}),t.jsx("span",{className:"ml-1 text-xs",children:a?"Copied":"Copy"})]})]})]}),t.jsx("pre",{className:"overflow-x-auto rounded-md border bg-muted/40 p-2 text-xs leading-relaxed",children:t.jsx("code",{children:s?r:"•".repeat(Math.min(r.length||8,32))})})]})}const Ri={active:"Active",suspended:"Suspended"},Pi={active:"success",suspended:"warning"};function Ai(e){return Ri[e]??e}function Di(e){return Pi[e]??"warning"}function Us({status:e}){return t.jsx(Me,{variant:Di(e),children:Ai(e)})}const Oi={http:"HTTP",mqtt:"MQTT",ws:"WebSocket",grpc:"gRPC"},Mi={http:"Standard HTTP POST ingest with HMAC",mqtt:"MQTT topic subscription",ws:"WebSocket long-lived connection",grpc:"gRPC bidi-streaming ingest (high-volume)"};function Ft(e){return Oi[e]??e}function Li(e){return Mi[e]??""}function Fi({type:e}){return t.jsx(Me,{variant:"muted",children:Ft(e)})}function Ws(e){return e>=1e6?`${(e/1e6).toFixed(1)}M/s`:e>=1e3?`${(e/1e3).toFixed(1)}k/s`:`${e}/s`}function Vs(e){if(!e)return"—";const r=new Date(e);return Number.isNaN(r.getTime())?e:r.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Ar({value:e}){if(e==null)return t.jsx("span",{className:"text-xs text-muted-foreground",children:"\\u2014"});let r;try{r=JSON.stringify(e,null,2)}catch{r=String(e)}return t.jsx("pre",{className:"max-h-48 overflow-auto rounded-md border bg-muted/40 p-3 text-xs leading-relaxed",children:t.jsx("code",{children:r})})}const $i=[{value:"",label:"All types"},{value:"http",label:"HTTP"},{value:"mqtt",label:"MQTT"},{value:"ws",label:"WebSocket"},{value:"grpc",label:"gRPC"}],Ii=[{value:"",label:"All"},{value:"active",label:"Active"},{value:"suspended",label:"Suspended"}];function Dr(){const e=ie(),r=Ve(),{user:s}=ee(),n=os(s?.role),a=ft(s?.role),o=r.id,[i,c]=Bt(),[d,f]=l.useState(i.get("q")??""),u=i.get("type")??"",x=i.get("status")??"",p=Xt({limit:200});l.useEffect(()=>{if(o||!a)return;const b=p.data&&p.data.items[0];b&&e(`/sources/${b.id}`,{replace:!0})},[o,a,p.data,e]),l.useEffect(()=>{const b=setTimeout(()=>{const S=new URLSearchParams(i);d.trim()?S.set("q",d.trim()):S.delete("q"),c(S,{replace:!0})},300);return()=>clearTimeout(b)},[d]);const h=l.useMemo(()=>({q:i.get("q")??void 0,type:u||void 0,status:x||void 0,limit:100}),[i,u,x]),{data:g,isPending:m,isError:v,error:j,refetch:w}=yi(o,h),y=b=>{e(b?`/sources/${b}`:"/sources")};return t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[t.jsxs("div",{children:[t.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:"Sources"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage the ingest endpoints per company. Each source has its own credentials, rate limit, and routing rules."})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[a&&p.data?t.jsxs("select",{className:"h-9 rounded-md border border-input bg-background px-3 text-sm",value:o??"",onChange:b=>y(b.target.value),"aria-label":"Company",children:[t.jsx("option",{value:"",children:"Select a company"}),p.data.items.map(b=>t.jsx("option",{value:b.id,children:b.display_name},b.id))]}):null,n&&o?t.jsx(Rr,{tenantId:o}):null]})]}),o?t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[t.jsxs("div",{className:"relative flex-1 sm:max-w-sm",children:[t.jsx(Wt,{className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(k,{placeholder:"Search by id or name",className:"pl-8",value:d,onChange:b=>f(b.target.value),"aria-label":"Search sources"})]}),t.jsx("div",{className:"flex flex-wrap gap-1",children:$i.map(b=>{const S=u===b.value;return t.jsx(N,{variant:S?"secondary":"ghost",size:"sm",onClick:()=>{const D=new URLSearchParams(i);b.value?D.set("type",b.value):D.delete("type"),c(D,{replace:!0})},children:b.label},b.value)})}),t.jsx("div",{className:"flex gap-1",children:Ii.map(b=>{const S=x===b.value;return t.jsx(N,{variant:S?"secondary":"ghost",size:"sm",onClick:()=>{const D=new URLSearchParams(i);b.value?D.set("status",b.value):D.delete("status"),c(D,{replace:!0})},children:b.label},b.value)})})]}):null,o?v?t.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm text-destructive",children:[t.jsx("p",{className:"font-medium",children:"Failed to load sources."}),t.jsx("p",{className:"mt-1 text-xs opacity-80",children:j instanceof Error?j.message:"Unknown error"}),t.jsx(N,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>w(),children:"Retry"})]}):m?t.jsx("div",{className:"rounded-md border bg-card p-8 text-center text-sm text-muted-foreground",children:"Loading…"}):g&&g.items.length===0?t.jsx(Yt,{icon:t.jsx(Ur,{className:"h-8 w-8"}),title:"No sources yet",description:n?"Create the first source for this company.":"Your operator has not set up any sources for this company yet.",action:n?t.jsx(Rr,{tenantId:o}):null}):g?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"rounded-md border bg-card",children:t.jsxs(ht,{children:[t.jsx(xt,{children:t.jsxs(fe,{children:[t.jsx(O,{children:"Name"}),t.jsx(O,{children:"ID"}),t.jsx(O,{children:"Type"}),t.jsx(O,{children:"Status"}),t.jsx(O,{className:"text-right",children:"Rate limit"}),t.jsx(O,{children:"Secrets"}),t.jsx(O,{children:"Created"})]})}),t.jsx(pt,{children:g.items.map(b=>t.jsxs(fe,{children:[t.jsx(M,{children:t.jsx(Te,{to:`/sources/${o}/${b.id}`,className:"font-medium text-foreground hover:underline",children:b.name})}),t.jsx(M,{children:t.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:b.id})}),t.jsx(M,{children:t.jsx(Fi,{type:b.type})}),t.jsx(M,{children:t.jsx(Us,{status:b.status})}),t.jsx(M,{className:"text-right tabular-nums",children:Ws(b.rate_limit_per_sec)}),t.jsx(M,{className:"text-xs text-muted-foreground",children:qi(b.hmac_set,b.api_key_set)}),t.jsx(M,{className:"text-xs text-muted-foreground",children:Vs(b.created_at)})]},`${b.company_id}:${b.id}`))})]})}),t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing ",g.items.length," of ",g.total]})]}):null:t.jsx("div",{className:"rounded-md border bg-card p-8 text-center text-sm text-muted-foreground",children:a?"Select a company above to see its sources.":"You will see sources here once your company is set up."})]})}function qi(e,r){return e&&r?"HMAC + API":e?"HMAC only":r?"API only":"none"}const Bi=Re({name:L().min(1,"Name is required").max(200,"Name must be ≤ 200 characters"),type:Vr(["http","mqtt","ws","grpc"]),rate_limit_per_sec:mt({invalid_type_error:"Enter a number"}).int("Whole number only").min(1).max(1e6),description:L().max(500).optional().or(Y("")),mtls_required:ze()}),zi={name:"",type:"http",rate_limit_per_sec:1e3,description:"",mtls_required:!1};function Ui(){const e=Ve(),r=ie(),s=e.id??"",n=e.sid??"",a=ji(s,n),o=Ni(s,n),i=Si(s,n),c=_i(s,n),[d,f]=l.useState(null),u=Pe({resolver:Oe(Bi),defaultValues:zi});l.useEffect(()=>{const m=a.data;m&&(u.setValue("name",m.name),u.setValue("type",m.type),u.setValue("rate_limit_per_sec",m.rate_limit_per_sec),u.setValue("description",m.description??""),u.setValue("mtls_required",m.mtls_required))},[a.data,u]);const x=u.handleSubmit(async m=>{try{await o.mutateAsync({name:m.name.trim(),type:m.type,rate_limit_per_sec:m.rate_limit_per_sec,description:m.description??"",mtls_required:m.mtls_required}),A.success("Source updated.")}catch(v){A.error(ot(v))}}),p=async m=>{try{await i.mutateAsync(m),A.success(`Source ${m}.`)}catch(v){A.error(ot(v))}},h=async()=>{try{const m=await c.mutateAsync();f(m)}catch(m){A.error(ot(m))}};if(a.isError)return t.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm text-destructive",children:[t.jsx("p",{className:"font-medium",children:"Failed to load source."}),t.jsx("p",{className:"mt-1 text-xs opacity-80",children:a.error instanceof Error?a.error.message:"Unknown error"})]});if(!a.data)return t.jsx("div",{className:"rounded-md border bg-card p-8 text-center text-sm text-muted-foreground",children:"Loading…"});const g=a.data;return t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx("div",{className:"flex items-center gap-2",children:t.jsxs(N,{variant:"ghost",size:"sm",onClick:()=>r(`/sources/${s}`),children:[t.jsx(ct,{className:"mr-1 h-3 w-3"}),"Sources"]})}),t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:g.name}),t.jsx(Us,{status:g.status})]}),t.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:[t.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:g.id}),t.jsx("span",{className:"mx-2",children:"\\u00b7"}),Ft(g.type)," (",Li(g.type),")"]})]}),t.jsx("div",{className:"flex items-center gap-2",children:g.status==="active"?t.jsx(N,{variant:"outline",size:"sm",onClick:()=>p("suspended"),disabled:i.isPending,children:"Suspend"}):t.jsx(N,{variant:"outline",size:"sm",onClick:()=>p("active"),disabled:i.isPending,children:"Activate"})})]}),t.jsxs(F,{children:[t.jsxs($,{children:[t.jsx(I,{children:"Configuration"}),t.jsx(G,{children:"Edit the source's name, type, rate limit, and mTLS requirement."})]}),t.jsx(q,{children:t.jsxs("form",{onSubmit:x,className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"col-span-2 flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"d-name",children:"Name"}),t.jsx(k,{id:"d-name",...u.register("name")}),u.formState.errors.name?t.jsx("p",{className:"text-xs text-destructive",children:u.formState.errors.name.message}):null]}),t.jsxs("div",{className:"col-span-1 flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"d-type",children:"Type"}),t.jsxs("select",{id:"d-type",className:"h-9 rounded-md border border-input bg-background px-3 text-sm",...u.register("type"),children:[t.jsx("option",{value:"http",children:"HTTP"}),t.jsx("option",{value:"mqtt",children:"MQTT"}),t.jsx("option",{value:"ws",children:"WebSocket"}),t.jsx("option",{value:"grpc",children:"gRPC"})]})]}),t.jsxs("div",{className:"col-span-1 flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"d-rl",children:"Rate limit (/s)"}),t.jsx(k,{id:"d-rl",type:"number",min:1,...u.register("rate_limit_per_sec",{valueAsNumber:!0})})]}),t.jsxs("div",{className:"col-span-2 flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"d-desc",children:"Description"}),t.jsx(Ee,{id:"d-desc",rows:2,...u.register("description")})]}),t.jsxs("div",{className:"col-span-2 flex items-center gap-2 pt-1",children:[t.jsx(dt,{id:"d-mtls",...u.register("mtls_required")}),t.jsx(C,{htmlFor:"d-mtls",className:"cursor-pointer",children:"Require mTLS client cert (M14)"})]}),t.jsx("div",{className:"col-span-2 flex items-center gap-2 pt-2",children:t.jsx(N,{type:"submit",disabled:o.isPending,children:o.isPending?"Saving…":"Save changes"})})]})})]}),t.jsxs(F,{children:[t.jsxs($,{children:[t.jsxs(I,{className:"flex items-center gap-2",children:[t.jsx(Wr,{className:"h-4 w-4"}),"Secrets"]}),t.jsx(G,{children:"The plaintext values are not stored — only their bcrypt hashes. Use rotate to generate new values (returned once)."})]}),t.jsxs(q,{children:[t.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[t.jsx(Or,{label:"HMAC secret",set:g.hmac_set}),t.jsx(Or,{label:"API key",set:g.api_key_set})]}),t.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[t.jsx(N,{variant:"outline",size:"sm",onClick:h,disabled:c.isPending,children:c.isPending?"Rotating…":"Rotate both secrets"}),t.jsx("span",{className:"text-xs text-muted-foreground",children:"Old values are invalidated immediately. The source's clients must be updated to the new values within their cache TTL."})]})]})]}),t.jsxs(F,{children:[t.jsxs($,{children:[t.jsxs(I,{className:"flex items-center gap-2",children:[t.jsx(_e,{className:"h-4 w-4"}),"mTLS / Client cert"]}),t.jsxs(G,{children:["M14 will wire up client cert provisioning, rotation, and revocation for sources with ",t.jsx("code",{children:"mtls_required"})," = true."]})]}),t.jsx(q,{children:t.jsx("div",{className:"text-sm text-muted-foreground",children:t.jsxs("p",{children:[t.jsx("strong",{className:"text-foreground",children:"Currently:"})," ",g.mtls_required?t.jsxs("span",{children:["mTLS is required. Cert lifecycle: ",t.jsx("em",{children:"coming in M14."})]}):t.jsx("span",{children:"Not required. Toggle the flag above when you want to enforce client certs."})]})})})]}),t.jsxs(F,{children:[t.jsxs($,{children:[t.jsxs(I,{className:"flex items-center gap-2",children:[t.jsx(fn,{className:"h-4 w-4"}),"Routing (read-only in W2)"]}),t.jsx(G,{children:"M13c adds the routing-rule editor. W2 only shows the current allowed_targets and match_expr as JSONB."})]}),t.jsxs(q,{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx(C,{children:"Allowed targets"}),t.jsx(Ar,{value:g.allowed_targets})]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx(C,{children:"Match expression"}),t.jsx(Ar,{value:g.match_expr})]})]})]}),t.jsxs(F,{children:[t.jsx($,{children:t.jsx(I,{children:"Metadata"})}),t.jsx(q,{children:t.jsxs("dl",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-sm",children:[t.jsx("dt",{className:"text-muted-foreground",children:"Source ID"}),t.jsx("dd",{children:t.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:g.id})}),t.jsx("dt",{className:"text-muted-foreground",children:"Company"}),t.jsx("dd",{children:t.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:g.company_id})}),t.jsx("dt",{className:"text-muted-foreground",children:"Type"}),t.jsx("dd",{children:Ft(g.type)}),t.jsx("dt",{className:"text-muted-foreground",children:"Rate limit"}),t.jsx("dd",{children:Ws(g.rate_limit_per_sec)}),t.jsx("dt",{className:"text-muted-foreground",children:"Created"}),t.jsx("dd",{children:Vs(g.created_at)})]})})]}),t.jsx(pe,{open:!!d,onOpenChange:m=>!m&&f(null),children:t.jsxs(ce,{className:"sm:max-w-lg",children:[t.jsxs(ge,{children:[t.jsxs(le,{className:"flex items-center gap-2",children:[t.jsx(_e,{className:"h-5 w-5 text-amber-500"}),"New secrets — save them now"]}),t.jsxs(de,{children:["Rotation succeeded. The new HMAC secret and API key are shown",t.jsx("strong",{children:" once"}),". After you close this dialog, only the hashes are stored."]})]}),d?t.jsx(Wi,{secrets:d.secrets}):null,t.jsx(ve,{children:t.jsx(N,{onClick:()=>f(null),children:"I have saved these — close"})})]})})]})}function Or({label:e,set:r}){return t.jsxs("div",{className:"flex items-center justify-between rounded-md border bg-muted/20 p-3",children:[t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"text-xs text-muted-foreground",children:e}),t.jsx("span",{className:"text-sm font-medium",children:r?"Configured":"Not set"})]}),t.jsx("span",{className:r?"inline-flex h-2 w-2 rounded-full bg-emerald-500":"inline-flex h-2 w-2 rounded-full bg-amber-400","aria-label":r?"set":"not set"})]})}function Wi({secrets:e}){const[r,s]=l.useState(!1),[n,a]=l.useState(!1);return t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx(Mr,{label:"New HMAC secret",value:e?.hmac_secret??"",show:r,onToggle:()=>s(o=>!o)}),t.jsx(Mr,{label:"New API key",value:e?.api_key??"",show:n,onToggle:()=>a(o=>!o)})]})}function Mr({label:e,value:r,show:s,onToggle:n}){const[a,o]=l.useState(!1);return t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:e}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(N,{type:"button",size:"sm",variant:"ghost",onClick:n,children:s?"Hide":"Show"}),t.jsx(N,{type:"button",size:"sm",variant:"ghost",onClick:async()=>{try{await navigator.clipboard.writeText(r),o(!0),setTimeout(()=>o(!1),1500)}catch{}},children:a?"Copied":"Copy"})]})]}),t.jsx("pre",{className:"overflow-x-auto rounded-md border bg-muted/40 p-2 text-xs leading-relaxed",children:t.jsx("code",{children:s?r:"•".repeat(Math.min(r.length||8,32))})})]})}function Vi(){return t.jsxs(zt,{children:[t.jsx(ae,{index:!0,element:t.jsx(Dr,{})}),t.jsx(ae,{path:":id",element:t.jsx(Dr,{})}),t.jsx(ae,{path:":id/:sid",element:t.jsx(Ui,{})})]})}const Qe={list:(e,r)=>["telegram-bots","list",e,r],detail:(e,r)=>["telegram-bots","detail",e,r]};function Hi(e,r){const s=new URLSearchParams;r.q&&s.set("q",r.q),r.status&&s.set("status",r.status),r.limit&&s.set("limit",String(r.limit)),r.offset&&s.set("offset",String(r.offset));const n=s.toString();return n?`/v1/tenants/${e}/telegram/bots?${n}`:`/v1/tenants/${e}/telegram/bots`}function Qi(e,r){return ke({queryKey:Qe.list(e,r),queryFn:()=>he(Hi(e,r)),enabled:!!e,staleTime:15e3})}function Ki(e,r){return ke({queryKey:Qe.detail(e,r),queryFn:()=>he(`/v1/tenants/${e}/telegram/bots/${r}`),enabled:!!e&&!!r})}function Gi(e){const r=W();return V({mutationFn:s=>H("POST",`/v1/tenants/${e}/telegram/bots`,s),onSuccess:()=>{r.invalidateQueries({queryKey:["telegram-bots","list",e]})}})}function Yi(e,r){const s=W();return V({mutationFn:n=>H("PATCH",`/v1/tenants/${e}/telegram/bots/${r}`,n),onSuccess:n=>{s.setQueryData(Qe.detail(e,r),n),s.invalidateQueries({queryKey:["telegram-bots","list",e]})}})}function Xi(e,r){const s=W();return V({mutationFn:n=>H("POST",`/v1/tenants/${e}/telegram/bots/${r}/status`,{status:n}),onSuccess:n=>{s.setQueryData(Qe.detail(e,r),n),s.invalidateQueries({queryKey:["telegram-bots","list",e]})}})}function Zi(e,r){const s=W();return V({mutationFn:n=>H("POST",`/v1/tenants/${e}/telegram/bots/${r}/rotate-token`,n),onSuccess:n=>{s.setQueryData(Qe.detail(e,r),n),s.invalidateQueries({queryKey:["telegram-bots","list",e]})}})}function it(e){if(e instanceof De){const r=e.body;return r?.message??r?.error??e.message}return e instanceof Error?e.message:"Unknown error"}const Lr=/^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/,Ji=/^\d+:[A-Za-z0-9_-]{35,}$/,ec=Re({id:L().min(2,"Bot id must be 2–64 characters").max(64,"Bot id must be 2–64 characters").regex(Lr,"Lowercase letters, digits, and dashes only"),name:L().min(1,"Name is required").max(200,"Name must be ≤ 200 characters"),bot_token:L().min(1,"Bot token is required").regex(Ji,"Token must look like 12345678:AbCdEfGh... (35+ chars after the colon)"),welcome_message:L().max(4096,"Welcome message must be ≤ 4096 characters").optional().or(Y("")),default_source_id:L().regex(Lr,"Lowercase letters, digits, and dashes only").optional().or(Y("")),description:L().max(500,"Description must be ≤ 500 characters").optional().or(Y(""))}),Fr={id:"",name:"",bot_token:"",welcome_message:"",default_source_id:"",description:""};function $r({tenantId:e}){const[r,s]=l.useState(!1),[n,a]=l.useState(!1),o=Gi(e),i=Pe({resolver:Oe(ec),defaultValues:Fr});l.useEffect(()=>{r&&i.reset(Fr)},[r,i]);const c=i.handleSubmit(async d=>{try{const f=await o.mutateAsync({id:d.id.trim(),name:d.name.trim(),bot_token:d.bot_token.trim(),welcome_message:d.welcome_message||void 0,default_source_id:d.default_source_id||void 0,description:d.description||void 0});A.success(`Bot "${f.name}" created.`),i.setValue("bot_token",""),a(!1),s(!1)}catch(f){A.error(it(f))}});return t.jsxs(pe,{open:r,onOpenChange:s,children:[t.jsx(jt,{asChild:!0,children:t.jsxs(N,{children:[t.jsx(Ut,{className:"mr-2 h-4 w-4"}),"New bot"]})}),t.jsxs(ce,{className:"sm:max-w-lg",children:[t.jsxs(ge,{children:[t.jsxs(le,{className:"flex items-center gap-2",children:[t.jsx(ut,{className:"h-4 w-4"}),"New Telegram bot"]}),t.jsxs(de,{children:["Paste a bot token from ",t.jsx("strong",{children:"@BotFather"}),". The token is stored encrypted server-side and never shown again after this dialog closes. telegramd will pick it up on its next reload."]})]}),t.jsxs("form",{onSubmit:c,className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"col-span-1 flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"bot-id",children:"ID"}),t.jsx(k,{id:"bot-id",placeholder:"primary",...i.register("id")}),i.formState.errors.id?t.jsx("p",{className:"text-xs text-destructive",children:i.formState.errors.id.message}):null]}),t.jsxs("div",{className:"col-span-1 flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"bot-name",children:"Name"}),t.jsx(k,{id:"bot-name",placeholder:"Acme Ops",...i.register("name")}),i.formState.errors.name?t.jsx("p",{className:"text-xs text-destructive",children:i.formState.errors.name.message}):null]})]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"bot-token",children:"Bot token"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(k,{id:"bot-token",type:n?"text":"password",placeholder:"123456789:AbCdEfGhIjKlMnOpQrStUvWxYz-12345",autoComplete:"off",spellCheck:!1,...i.register("bot_token")}),t.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>a(d=>!d),"aria-label":n?"Hide token":"Show token",children:n?t.jsx(Vt,{className:"h-3 w-3"}):t.jsx(Ht,{className:"h-3 w-3"})})]}),i.formState.errors.bot_token?t.jsx("p",{className:"text-xs text-destructive",children:i.formState.errors.bot_token.message}):t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get this from @BotFather in Telegram. The shape is",t.jsx("code",{className:"ml-1 rounded bg-muted px-1 py-0.5 text-[10px]",children:"<bot_id>:<secret>"}),"."]})]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"bot-default-source",children:"Default source ID (optional)"}),t.jsx(k,{id:"bot-default-source",placeholder:"primary",...i.register("default_source_id")}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"If set, the bot will be the default for alerts coming from this source."}),i.formState.errors.default_source_id?t.jsx("p",{className:"text-xs text-destructive",children:i.formState.errors.default_source_id.message}):null]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"bot-welcome",children:"Welcome message (optional)"}),t.jsx(Ee,{id:"bot-welcome",rows:2,placeholder:"Welcome to Acme alerts! Reply /help to see available commands.",...i.register("welcome_message")}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Sent in response to /start. M13c will wire this into telegramd."}),i.formState.errors.welcome_message?t.jsx("p",{className:"text-xs text-destructive",children:i.formState.errors.welcome_message.message}):null]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"bot-desc",children:"Description (optional)"}),t.jsx(Ee,{id:"bot-desc",rows:2,placeholder:"What does this bot do?",...i.register("description")}),i.formState.errors.description?t.jsx("p",{className:"text-xs text-destructive",children:i.formState.errors.description.message}):null]}),t.jsxs(ve,{children:[t.jsx(N,{type:"button",variant:"ghost",onClick:()=>s(!1),children:"Cancel"}),t.jsx(N,{type:"submit",disabled:o.isPending,children:o.isPending?"Creating…":"Create bot"})]})]})]})]})}const tc={active:"Active",paused:"Paused"},rc={active:"success",paused:"warning"};function sc(e){return tc[e]??e}function nc(e){return rc[e]??"warning"}function $t({status:e}){return t.jsx(Me,{variant:nc(e),children:sc(e)})}function ac(e){return e?"Configured":"Not set"}function oc(e){return e?"success":"warning"}function Hs({set:e}){return t.jsx(Me,{variant:oc(e),children:ac(e)})}function Qs(e){if(!e)return"—";const r=new Date(e);return Number.isNaN(r.getTime())?e:r.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Be(e){if(!e)return"—";const r=new Date(e);return Number.isNaN(r.getTime())?e:r.toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function ic(e,r=60){return e?e.length<=r?e:e.slice(0,r-1)+"…":"—"}const cc=[{value:"",label:"All"},{value:"active",label:"Active"},{value:"paused",label:"Paused"}];function Ir(){const e=ie(),r=Ve(),{user:s}=ee(),n=is(s?.role),a=ft(s?.role),o=r.id,[i,c]=Bt(),[d,f]=l.useState(i.get("q")??""),u=i.get("status")??"",x=Xt({limit:200});l.useEffect(()=>{if(o||!a)return;const y=x.data&&x.data.items[0];y&&e(`/telegram/${y.id}`,{replace:!0})},[o,a,x.data,e]),l.useEffect(()=>{const y=setTimeout(()=>{const b=new URLSearchParams(i);d.trim()?b.set("q",d.trim()):b.delete("q"),c(b,{replace:!0})},300);return()=>clearTimeout(y)},[d]);const p=l.useMemo(()=>({q:i.get("q")??void 0,status:u||void 0,limit:100}),[i,u]),{data:h,isPending:g,isError:m,error:v,refetch:j}=Qi(o,p),w=y=>{e(y?`/telegram/${y}`:"/telegram")};return t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[t.jsxs("div",{children:[t.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:"Telegram bots"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Per-company Telegram bot configuration. Each bot has its own token, welcome message, and default source. The token is write-only — the server never returns it after save."})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[a&&x.data?t.jsxs("select",{className:"h-9 rounded-md border border-input bg-background px-3 text-sm",value:o??"",onChange:y=>w(y.target.value),"aria-label":"Company",children:[t.jsx("option",{value:"",children:"Select a company"}),x.data.items.map(y=>t.jsx("option",{value:y.id,children:y.display_name},y.id))]}):null,n&&o?t.jsx($r,{tenantId:o}):null]})]}),o?t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[t.jsxs("div",{className:"relative flex-1 sm:max-w-sm",children:[t.jsx(Wt,{className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(k,{placeholder:"Search by id or name",className:"pl-8",value:d,onChange:y=>f(y.target.value),"aria-label":"Search bots"})]}),t.jsx("div",{className:"flex gap-1",children:cc.map(y=>{const b=u===y.value;return t.jsx(N,{variant:b?"secondary":"ghost",size:"sm",onClick:()=>{const S=new URLSearchParams(i);y.value?S.set("status",y.value):S.delete("status"),c(S,{replace:!0})},children:y.label},y.value)})})]}):null,o?a?m?t.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm text-destructive",children:[t.jsx("p",{className:"font-medium",children:"Failed to load telegram bots."}),t.jsx("p",{className:"mt-1 text-xs opacity-80",children:v instanceof Error?v.message:"Unknown error"}),t.jsx(N,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>j(),children:"Retry"})]}):g?t.jsx("div",{className:"rounded-md border bg-card p-8 text-center text-sm text-muted-foreground",children:"Loading…"}):h&&h.items.length===0?t.jsx(Yt,{icon:t.jsx(ut,{className:"h-8 w-8"}),title:"No bots yet",description:n?"Create the first telegram bot for this company.":"No telegram bots configured for this company.",action:n?t.jsx($r,{tenantId:o}):null}):h?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"rounded-md border bg-card",children:t.jsxs(ht,{children:[t.jsx(xt,{children:t.jsxs(fe,{children:[t.jsx(O,{children:"Name"}),t.jsx(O,{children:"ID"}),t.jsx(O,{children:"Status"}),t.jsx(O,{children:"Token"}),t.jsx(O,{children:"Default source"}),t.jsx(O,{children:"Welcome"}),t.jsx(O,{children:"Last rotated"}),t.jsx(O,{children:"Created"})]})}),t.jsx(pt,{children:h.items.map(y=>t.jsxs(fe,{children:[t.jsx(M,{children:t.jsx(Te,{to:`/telegram/${o}/${y.id}`,className:"font-medium text-foreground hover:underline",children:y.name})}),t.jsx(M,{children:t.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:y.id})}),t.jsx(M,{children:t.jsx($t,{status:y.status})}),t.jsx(M,{children:t.jsx(Hs,{set:y.bot_token_set})}),t.jsx(M,{className:"text-xs text-muted-foreground",children:y.default_source_id?t.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:y.default_source_id}):"—"}),t.jsx(M,{className:"max-w-[14rem] text-xs text-muted-foreground",children:ic(y.welcome_message,40)}),t.jsx(M,{className:"text-xs text-muted-foreground",children:Be(y.last_rotated_at)}),t.jsx(M,{className:"text-xs text-muted-foreground",children:Qs(y.created_at)})]},`${y.company_id}:${y.id}`))})]})}),t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing ",h.items.length," of ",h.total]})]}):null:t.jsx("div",{className:"rounded-md border bg-card p-8 text-center text-sm text-muted-foreground",children:"Only super admins can manage telegram bots in this version. W3 ships super_admin scope; per-company tenant_admin is a v1.1 follow-up."}):t.jsx("div",{className:"rounded-md border bg-card p-8 text-center text-sm text-muted-foreground",children:a?"Select a company above to see its telegram bots.":"Telegram bots are managed by super admins. Ask your operator to set up a bot for your company."})]})}const lc=/^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/,dc=/^\d+:[A-Za-z0-9_-]{35,}$/,uc=Re({name:L().min(1,"Name is required").max(200,"Name must be ≤ 200 characters"),welcome_message:L().max(4096,"Welcome message must be ≤ 4096 characters").optional().or(Y("")),default_source_id:L().regex(lc,"Lowercase letters, digits, and dashes only").optional().or(Y("")),description:L().max(500,"Description must be ≤ 500 characters").optional().or(Y(""))}),mc={name:"",welcome_message:"",default_source_id:"",description:""};function fc(){const e=Ve(),r=ie(),s=e.id??"",n=e.bid??"",a=Ki(s,n),o=Yi(s,n),i=Xi(s,n),c=Zi(s,n),[d,f]=l.useState(!1),u=Pe({resolver:Oe(uc),defaultValues:mc});l.useEffect(()=>{const g=a.data;g&&(u.setValue("name",g.name),u.setValue("welcome_message",g.welcome_message??""),u.setValue("default_source_id",g.default_source_id??""),u.setValue("description",g.description??""))},[a.data,u]);const x=u.handleSubmit(async g=>{try{await o.mutateAsync({name:g.name.trim(),welcome_message:g.welcome_message||void 0,default_source_id:g.default_source_id||void 0,description:g.description||void 0}),A.success("Bot updated.")}catch(m){A.error(it(m))}}),p=async g=>{try{await i.mutateAsync(g),A.success(`Bot ${g}.`)}catch(m){A.error(it(m))}};if(a.isError)return t.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm text-destructive",children:[t.jsx("p",{className:"font-medium",children:"Failed to load bot."}),t.jsx("p",{className:"mt-1 text-xs opacity-80",children:a.error instanceof Error?a.error.message:"Unknown error"})]});if(!a.data)return t.jsx("div",{className:"rounded-md border bg-card p-8 text-center text-sm text-muted-foreground",children:"Loading…"});const h=a.data;return t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx("div",{className:"flex items-center gap-2",children:t.jsxs(N,{variant:"ghost",size:"sm",onClick:()=>r(`/telegram/${s}`),children:[t.jsx(ct,{className:"mr-1 h-3 w-3"}),"Telegram bots"]})}),t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ut,{className:"h-5 w-5 text-muted-foreground"}),t.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:h.name}),t.jsx($t,{status:h.status})]}),t.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:[t.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:h.id}),t.jsx("span",{className:"mx-2",children:"\\u00b7"}),"company",t.jsx("code",{className:"ml-1 rounded bg-muted px-1.5 py-0.5 text-xs",children:h.company_id})]})]}),t.jsx("div",{className:"flex items-center gap-2",children:h.status==="active"?t.jsx(N,{variant:"outline",size:"sm",onClick:()=>p("paused"),disabled:i.isPending,children:"Pause"}):t.jsx(N,{variant:"outline",size:"sm",onClick:()=>p("active"),disabled:i.isPending,children:"Activate"})})]}),t.jsxs(F,{children:[t.jsxs($,{children:[t.jsx(I,{children:"Configuration"}),t.jsx(G,{children:"Edit the bot's name, welcome message, default source, and description."})]}),t.jsx(q,{children:t.jsxs("form",{onSubmit:x,className:"flex flex-col gap-3",children:[t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"d-name",children:"Name"}),t.jsx(k,{id:"d-name",...u.register("name")}),u.formState.errors.name?t.jsx("p",{className:"text-xs text-destructive",children:u.formState.errors.name.message}):null]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"col-span-1 flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"d-default-source",children:"Default source ID"}),t.jsx(k,{id:"d-default-source",placeholder:"primary",...u.register("default_source_id")}),u.formState.errors.default_source_id?t.jsx("p",{className:"text-xs text-destructive",children:u.formState.errors.default_source_id.message}):null]}),t.jsxs("div",{className:"col-span-1 flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"d-desc",children:"Description"}),t.jsx(k,{id:"d-desc",...u.register("description")}),u.formState.errors.description?t.jsx("p",{className:"text-xs text-destructive",children:u.formState.errors.description.message}):null]})]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx(C,{htmlFor:"d-welcome",children:"Welcome message"}),t.jsx(Ee,{id:"d-welcome",rows:3,...u.register("welcome_message")}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Sent in response to /start. M13c wires this into telegramd."}),u.formState.errors.welcome_message?t.jsx("p",{className:"text-xs text-destructive",children:u.formState.errors.welcome_message.message}):null]}),t.jsx("div",{className:"flex items-center gap-2 pt-1",children:t.jsx(N,{type:"submit",disabled:o.isPending,children:o.isPending?"Saving…":"Save changes"})})]})})]}),t.jsxs(F,{children:[t.jsxs($,{children:[t.jsxs(I,{className:"flex items-center gap-2",children:[t.jsx(Wr,{className:"h-4 w-4"}),"Bot token"]}),t.jsx(G,{children:'The plaintext token is never returned after save. The server stores the hash so it can render "configured"; telegramd reads the plaintext from the same row. Use rotate to swap to a new token (e.g. after revoking the old one in @BotFather).'})]}),t.jsxs(q,{children:[t.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[t.jsx(qr,{label:"Bot token",set:h.bot_token_set}),t.jsx(qr,{label:"Last rotated",text:Be(h.last_rotated_at)})]}),t.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[t.jsx(N,{variant:"outline",size:"sm",onClick:()=>f(!0),disabled:c.isPending,children:c.isPending?"Rotating…":"Rotate token"}),t.jsx("span",{className:"text-xs text-muted-foreground",children:"The new token is set on the row immediately. telegramd picks it up on its next reload (or sooner with a future notify channel)."})]})]})]}),t.jsxs(F,{children:[t.jsx($,{children:t.jsxs(I,{className:"flex items-center gap-2",children:[t.jsx(_e,{className:"h-4 w-4"}),"Security notes"]})}),t.jsx(q,{className:"text-sm text-muted-foreground",children:t.jsxs("ul",{className:"ml-5 list-disc space-y-1",children:[t.jsxs("li",{children:["Bot tokens are write-only. The server never returns the plaintext — only a ",t.jsx("code",{children:"bot_token_set"})," boolean."]}),t.jsx("li",{children:"The plaintext is stored alongside its bcrypt hash so telegramd can use it. The M11 security milestone will replace this with AES-256-GCM encryption and a decryption sidecar."}),t.jsx("li",{children:"Every state change (create, update, status, rotate) writes an audit row visible in the Audit log."})]})})]}),t.jsxs(F,{children:[t.jsx($,{children:t.jsx(I,{children:"Metadata"})}),t.jsx(q,{children:t.jsxs("dl",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-sm",children:[t.jsx("dt",{className:"text-muted-foreground",children:"Bot ID"}),t.jsx("dd",{children:t.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:h.id})}),t.jsx("dt",{className:"text-muted-foreground",children:"Company"}),t.jsx("dd",{children:t.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:h.company_id})}),t.jsx("dt",{className:"text-muted-foreground",children:"Status"}),t.jsxs("dd",{children:[t.jsx($t,{status:h.status})," ",t.jsx(Hs,{set:h.bot_token_set})]}),t.jsx("dt",{className:"text-muted-foreground",children:"Last rotated"}),t.jsx("dd",{children:Be(h.last_rotated_at)}),t.jsx("dt",{className:"text-muted-foreground",children:"Last seen"}),t.jsx("dd",{children:Be(h.last_seen_at)}),t.jsx("dt",{className:"text-muted-foreground",children:"Created"}),t.jsx("dd",{children:Qs(h.created_at)}),t.jsx("dt",{className:"text-muted-foreground",children:"Updated"}),t.jsx("dd",{children:Be(h.updated_at)})]})})]}),t.jsx(hc,{open:d,onOpenChange:f,onSubmit:async g=>{try{await c.mutateAsync({bot_token:g}),A.success("Token rotated."),f(!1)}catch(m){A.error(it(m))}},isPending:c.isPending})]})}function qr({label:e,set:r,text:s}){return t.jsxs("div",{className:"flex items-center justify-between rounded-md border bg-muted/20 p-3",children:[t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"text-xs text-muted-foreground",children:e}),t.jsx("span",{className:"text-sm font-medium",children:s??(r?"Configured":"Not set")})]}),r!==void 0?t.jsx("span",{className:r?"inline-flex h-2 w-2 rounded-full bg-emerald-500":"inline-flex h-2 w-2 rounded-full bg-amber-400","aria-label":r?"set":"not set"}):null]})}function hc({open:e,onOpenChange:r,onSubmit:s,isPending:n}){const[a,o]=l.useState(""),[i,c]=l.useState(!1),[d,f]=l.useState(null);l.useEffect(()=>{e&&(o(""),c(!1),f(null))},[e]);const u=async()=>{const x=a.trim();if(!dc.test(x)){f("Token must look like 12345678:AbCdEfGh... (35+ chars after the colon).");return}f(null),await s(x)};return t.jsx(pe,{open:e,onOpenChange:r,children:t.jsxs(ce,{className:"sm:max-w-lg",children:[t.jsxs(ge,{children:[t.jsxs(le,{className:"flex items-center gap-2",children:[t.jsx(_e,{className:"h-5 w-5 text-amber-500"}),"Rotate bot token"]}),t.jsxs(de,{children:["Paste the new token from ",t.jsx("strong",{children:"@BotFather"}),". The server stores the plaintext (so telegramd can use it) and bcrypt-hashes it for the audit-friendly ",t.jsx("code",{children:"bot_token_hash"})," column. The plaintext is ",t.jsx("strong",{children:"never"})," echoed back."]})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx(C,{htmlFor:"rotate-token",className:"text-xs",children:"New bot token"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(k,{id:"rotate-token",type:i?"text":"password",autoComplete:"off",spellCheck:!1,placeholder:"123456789:AbCdEfGhIjKlMnOpQrStUvWxYz-12345",value:a,onChange:x=>o(x.target.value)}),t.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>c(x=>!x),"aria-label":i?"Hide":"Show",children:i?t.jsx(Vt,{className:"h-3 w-3"}):t.jsx(Ht,{className:"h-3 w-3"})})]}),d?t.jsx("p",{className:"text-xs text-destructive",children:d}):null]}),t.jsxs(ve,{children:[t.jsx(N,{type:"button",variant:"ghost",onClick:()=>r(!1),children:"Cancel"}),t.jsx(N,{type:"button",onClick:u,disabled:n,children:n?"Rotating…":"Rotate token"})]})]})})}function xc(){return t.jsxs(zt,{children:[t.jsx(ae,{index:!0,element:t.jsx(Ir,{})}),t.jsx(ae,{path:":id",element:t.jsx(Ir,{})}),t.jsx(ae,{path:":id/:bid",element:t.jsx(fc,{})})]})}function rr({title:e,description:r,badge:s,children:n,className:a}){return t.jsx("div",{className:T("mx-auto max-w-2xl py-12",a),children:t.jsxs("div",{className:"rounded-lg border bg-card p-8 shadow-sm",children:[t.jsx("div",{className:"mb-4 flex items-center gap-2",children:t.jsx("span",{className:"rounded-md bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground",children:s??"coming soon"})}),t.jsx("h2",{className:"mb-2 text-2xl font-semibold tracking-tight",children:e}),r?t.jsx("p",{className:"mb-6 text-sm text-muted-foreground",children:r}):null,n]})})}function pc(){return t.jsx(rr,{title:"Live tail",badge:"M13c",description:"SSE feed of incoming alerts, filterable by company / severity / source / text. Replaces the per-company dump that lives on /v1/tail today.",children:t.jsxs("ul",{className:"ml-5 list-disc space-y-1 text-sm text-muted-foreground",children:[t.jsx("li",{children:"EventSource('/v1/tail/stream') with auth via short-lived SSE token"}),t.jsx("li",{children:"Filter bar (severity, source, search) + pause-on-scroll-up"}),t.jsx("li",{children:"Click row → modal with full payload + dedupe history"})]})})}function gc(){return t.jsxs(rr,{title:"DLQ",badge:"M13c",description:"React replacement for cmd/admind/ui/dlq.html. Same list/replay/discard flow plus filters and audit hooks.",children:[t.jsxs("p",{className:"mb-4 text-sm text-muted-foreground",children:["Until the React surface ships, the M8 HTML UI is still served at"," ",t.jsx("code",{className:"rounded bg-muted px-1",children:"/dlq"})," by the admind binary."]}),t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Per-channel admin endpoints (",t.jsx("code",{children:"/v1/admin/dlq"})," on deliverd-fcm and deliverd-telegram, JWT-gated) are also available for ops who want to inspect a single channel."]})]})}function vc(){return t.jsx(rr,{title:"Audit log",badge:"M13c",description:"Read-only table of audit_log rows, filterable by actor / action / entity / time.",children:t.jsxs("ul",{className:"ml-5 list-disc space-y-1 text-sm text-muted-foreground",children:[t.jsx("li",{children:"Filter bar: actor (user_id), action, entity_type, time range"}),t.jsx("li",{children:"Row expand: full JSON payload"}),t.jsx("li",{children:"Export to CSV (super-admin only)"})]})})}function bc(){return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"404"}),t.jsx("h1",{className:"mt-2 text-2xl font-semibold tracking-tight",children:"Page not found"}),t.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"The route you followed isn't part of the admin console."}),t.jsx(N,{asChild:!0,className:"mt-6",children:t.jsx(Te,{to:"/",children:"Back to dashboard"})})]})})}function yc(){return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"403"}),t.jsx("h1",{className:"mt-2 text-2xl font-semibold tracking-tight",children:"Forbidden"}),t.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Your role doesn't grant access to this page."}),t.jsx(N,{asChild:!0,className:"mt-6",children:t.jsx(Te,{to:"/",children:"Back to dashboard"})})]})})}const jc=Js([{path:"/login",element:t.jsx(Ca,{})},{path:"/forbidden",element:t.jsx(yc,{})},{element:t.jsx(ja,{children:t.jsx(ya,{})}),children:[{path:"/",element:t.jsx(Ea,{})},{path:"/companies/*",element:t.jsx(vi,{})},{path:"/sources/*",element:t.jsx(Vi,{})},{path:"/telegram/*",element:t.jsx(xc,{})},{path:"/tail",element:t.jsx(pc,{})},{path:"/dlq",element:t.jsx(gc,{})},{path:"/audit",element:t.jsx(vc,{})}]},{path:"*",element:t.jsx(bc,{})}]);pa();const wc=new Gs({defaultOptions:{queries:{staleTime:3e4,retry:1,refetchOnWindowFocus:!0}}}),Ks=document.getElementById("root");if(!Ks)throw new Error("#root element not found in index.html");Hr(Ks).render(t.jsx(l.StrictMode,{children:t.jsx(Ys,{client:wc,children:t.jsxs(Jn,{children:[t.jsx(en,{router:jc}),t.jsx(hn,{position:"top-right",richColors:!0})]})})}));