@owox/web 0.9.0-next-20251003204603 → 0.9.0-next-20251006073458
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -658,7 +658,7 @@ to {
|
|
|
658
658
|
> * {
|
|
659
659
|
pointer-events: auto;
|
|
660
660
|
}
|
|
661
|
-
`,um=16,J$=({reverseOrder:e,position:t="top-center",toastOptions:n,gutter:r,children:s,toasterId:l,containerStyle:c,containerClassName:d})=>{let{toasts:h,handlers:m}=j$(n,l);return p.createElement("div",{"data-rht-toaster":l||"",style:{position:"fixed",zIndex:9999,top:um,left:um,right:um,bottom:um,pointerEvents:"none",...c},className:d,onMouseEnter:m.startPause,onMouseLeave:m.endPause},h.map(g=>{let v=g.position||t,x=m.calculateOffset(g,{reverseOrder:e,gutter:r,defaultPosition:t}),b=W$(v,x);return p.createElement(Q$,{id:g.id,key:g.id,onHeightUpdate:m.updateHeight,className:g.visible?X$:"",style:b},g.type==="custom"?cp(g.message,g):s?s(g):p.createElement(Y$,{toast:g,position:v}))}))},dn=Jt;const hn=e=>{var n;return(n=e.response)==null?void 0:n.data};function O2(e,t="Something went wrong"){var s,l;const n=hn(e);let r=n.message.trim()||t;(l=(s=n.errorDetails)==null?void 0:s.error)!=null&&l.trim()&&(r=`${r}. ${n.errorDetails.error}`),dn.error(r)}class eB{constructor(){Es(this,"isRefreshingToken",!1);Es(this,"refreshTokenPromise",null);Es(this,"accessToken",null)}getAccessToken(){return this.accessToken}setAccessToken(t){this.accessToken=t}isRefreshing(){return this.isRefreshingToken}async refreshToken(t){if(this.isRefreshingToken&&this.refreshTokenPromise)return await this.refreshTokenPromise;this.isRefreshingToken=!0,this.refreshTokenPromise=this.performRefresh(t);try{const n=await this.refreshTokenPromise;return this.setAccessToken(n),n}finally{this.isRefreshingToken=!1,this.refreshTokenPromise=null}}clear(){this.accessToken=null,this.isRefreshingToken=!1,this.refreshTokenPromise=null}async performRefresh(t){try{return await t()}catch(n){throw this.clear(),n}}}const tB={baseURL:"/api",timeout:3e4,headers:{"Content-Type":"application/json",Accept:"application/json"}},za=En.create(tB),x0=new eB;za.interceptors.request.use(e=>{if(e.skipAuthHeader||new nH(e.headers).has("X-OWOX-Authorization"))return e;const n=Vb(),r=(n==null?void 0:n.getAccessToken())??x0.getAccessToken();return r&&(e.headers["X-OWOX-Authorization"]=`Bearer ${r}`),e},e=>Promise.reject(e instanceof Error?e:new Error("Unknown error")));za.interceptors.response.use(e=>e,async e=>{var n,r,s;const t=e.config;if(((n=e.response)==null?void 0:n.status)===401&&!t._retry){t._retry=!0;try{const l=Vb();if(!l)throw new Error("No token provider available");const c=await x0.refreshToken(()=>l.refreshToken());return t.headers["X-OWOX-Authorization"]=`Bearer ${c}`,await za(t)}catch{return x0.clear(),window.dispatchEvent(new CustomEvent("auth:logout",{detail:{reason:"token_refresh_failed"}})),Promise.reject(new Error("Token refresh failed"))}}return((r=e.response)==null?void 0:r.status)===403&&O2(e,"Access forbidden - insufficient permissions"),((s=e.response)==null?void 0:s.status)===400&&O2(e,"Bad request"),Promise.reject(e)});const wA={projects:[],callState:Pr.IDLE,error:null};function nB(e,t){switch(t.type){case"LOADING":return{...e,callState:Pr.LOADING,error:null};case"SUCCESS":return{projects:t.payload,callState:Pr.LOADED,error:null};case"ERROR":return{...e,callState:Pr.ERROR,error:t.payload};case"RESET":return{...wA};default:return e}}function rB({children:e}){const[t,n]=p.useReducer(nB,wA),r=p.useCallback(async()=>{n({type:"LOADING"});try{const d=Vb();if(!d){n({type:"ERROR",payload:hn(new v2("No token provider"))});return}const h=d.getAccessToken();if(!h){n({type:"ERROR",payload:hn(new v2("Unable to obtain access token"))});return}const m=await lH(h);n({type:"SUCCESS",payload:m})}catch(d){n({type:"ERROR",payload:hn(d)})}},[]),s=p.useCallback(()=>{n({type:"RESET"})},[]),l=t.callState===Pr.LOADING,c={...t,loadProjects:r,reset:s,isLoading:l};return o.jsx(lA.Provider,{value:c,children:e})}function aB(){const[e,t]=p.useState(!1);return o.jsx("div",{"data-slot":"sidebar-header","data-sidebar":"header",className:"flex flex-col gap-2",children:o.jsx("ul",{"data-slot":"sidebar-menu","data-sidebar":"menu",className:"flex w-full min-w-0 flex-col gap-1",children:o.jsx("li",{"data-slot":"sidebar-menu-item","data-sidebar":"menu-item",className:"group/menu-item relative",children:o.jsxs(Ar,{open:e,onOpenChange:t,children:[o.jsx(jz,{isOpen:e}),o.jsx(rB,{children:o.jsx(d$,{})})]})})})})}var sB=(e,t,n,r,s,l,c,d)=>{let h=document.documentElement,m=["light","dark"];function g(b){(Array.isArray(e)?e:[e]).forEach(E=>{let C=E==="class",w=C&&l?s.map(R=>l[R]||R):s;C?(h.classList.remove(...w),h.classList.add(l&&l[b]?l[b]:b)):h.setAttribute(E,b)}),v(b)}function v(b){d&&m.includes(b)&&(h.style.colorScheme=b)}function x(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(r)g(r);else try{let b=localStorage.getItem(t)||n,E=c&&b==="system"?x():b;g(E)}catch{}},M2=["light","dark"],RA="(prefers-color-scheme: dark)",oB=typeof window>"u",qb=p.createContext(void 0),iB={setTheme:e=>{},themes:[]},TA=()=>{var e;return(e=p.useContext(qb))!=null?e:iB},lB=e=>p.useContext(qb)?p.createElement(p.Fragment,null,e.children):p.createElement(uB,{...e}),cB=["light","dark"],uB=({forcedTheme:e,disableTransitionOnChange:t=!1,enableSystem:n=!0,enableColorScheme:r=!0,storageKey:s="theme",themes:l=cB,defaultTheme:c=n?"system":"light",attribute:d="data-theme",value:h,children:m,nonce:g,scriptProps:v})=>{let[x,b]=p.useState(()=>fB(s,c)),[E,C]=p.useState(()=>x==="system"?mx():x),w=h?Object.values(h):l,R=p.useCallback(D=>{let N=D;if(!N)return;D==="system"&&n&&(N=mx());let A=h?h[N]:N,k=t?hB(g):null,U=document.documentElement,B=H=>{H==="class"?(U.classList.remove(...w),A&&U.classList.add(A)):H.startsWith("data-")&&(A?U.setAttribute(H,A):U.removeAttribute(H))};if(Array.isArray(d)?d.forEach(B):B(d),r){let H=M2.includes(c)?c:null,Q=M2.includes(N)?N:H;U.style.colorScheme=Q}k==null||k()},[g]),T=p.useCallback(D=>{let N=typeof D=="function"?D(x):D;b(N);try{localStorage.setItem(s,N)}catch{}},[x]),j=p.useCallback(D=>{let N=mx(D);C(N),x==="system"&&n&&!e&&R("system")},[x,e]);p.useEffect(()=>{let D=window.matchMedia(RA);return D.addListener(j),j(D),()=>D.removeListener(j)},[j]),p.useEffect(()=>{let D=N=>{N.key===s&&(N.newValue?b(N.newValue):T(c))};return window.addEventListener("storage",D),()=>window.removeEventListener("storage",D)},[T]),p.useEffect(()=>{R(e??x)},[e,x]);let O=p.useMemo(()=>({theme:x,setTheme:T,forcedTheme:e,resolvedTheme:x==="system"?E:x,themes:n?[...l,"system"]:l,systemTheme:n?E:void 0}),[x,T,e,E,n,l]);return p.createElement(qb.Provider,{value:O},p.createElement(dB,{forcedTheme:e,storageKey:s,attribute:d,enableSystem:n,enableColorScheme:r,defaultTheme:c,value:h,themes:l,nonce:g,scriptProps:v}),m)},dB=p.memo(({forcedTheme:e,storageKey:t,attribute:n,enableSystem:r,enableColorScheme:s,defaultTheme:l,value:c,themes:d,nonce:h,scriptProps:m})=>{let g=JSON.stringify([n,t,l,e,d,c,r,s]).slice(1,-1);return p.createElement("script",{...m,suppressHydrationWarning:!0,nonce:typeof window>"u"?h:"",dangerouslySetInnerHTML:{__html:`(${sB.toString()})(${g})`}})}),fB=(e,t)=>{if(oB)return;let n;try{n=localStorage.getItem(e)||void 0}catch{}return n||t},hB=e=>{let t=document.createElement("style");return e&&t.setAttribute("nonce",e),t.appendChild(document.createTextNode("*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}")),document.head.appendChild(t),()=>{window.getComputedStyle(document.body),setTimeout(()=>{document.head.removeChild(t)},1)}},mx=e=>(e||(e=window.matchMedia(RA)),e.matches?"dark":"light");function mB({theme:e,setTheme:t,signOut:n}){return[{title:`Switch to ${e==="light"?"dark":"light"} mode`,icon:e==="light"?Q8:vL,onClick:()=>{t(e==="light"?"dark":"light")}},{type:"separator"},{title:"Sign out",icon:V8,onClick:n,className:"text-red-600 focus:text-red-600"}]}function pB({avatar:e,initials:t,displayName:n}){return o.jsx("div",{className:"text-muted-foreground flex aspect-square size-8 items-center justify-center rounded-full border bg-white text-sm font-medium dark:bg-white/10",children:e?o.jsx("img",{src:e,alt:n,className:"size-full rounded-full object-cover"}):o.jsx("span",{children:t})})}function gB({isOpen:e,displayName:t,email:n,avatar:r,initials:s}){return o.jsx(Dr,{asChild:!0,children:o.jsxs("button",{type:"button","data-slot":"dropdown-menu-trigger","data-sidebar":"menu-button","data-size":"lg","data-active":e?"true":"false","aria-haspopup":"menu","aria-expanded":e,"data-state":e?"open":"closed",className:"peer/menu-button ring-sidebar-ring active:bg-sidebar-accent active:text-sidebar-accent-foreground data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground flex h-12 w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:rounded-full group-data-[collapsible=icon]:p-0! focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",children:[o.jsx(pB,{avatar:r,initials:s,displayName:t}),o.jsxs("div",{className:"grid flex-1 text-left text-sm leading-tight group-data-[collapsible=icon]:hidden",children:[o.jsx("span",{className:"truncate font-medium",children:t}),n&&o.jsx("span",{className:"text-muted-foreground truncate text-xs",children:n})]}),o.jsx(Ga,{className:`ml-auto size-4 transition-transform duration-200 group-data-[collapsible=icon]:hidden ${e?"rotate-180":""}`})]})})}function vB({items:e}){return o.jsx(Or,{align:"start",side:"top",sideOffset:8,className:"w-56",children:e.map((t,n)=>t.type==="separator"?o.jsx($a,{},`sep-${String(n)}`):o.jsxs(Tt,{onClick:t.onClick,className:`flex items-center gap-2 ${t.className??""}`,children:[o.jsx(t.icon,{className:"size-4"}),t.title]},t.title))})}function yB(e,t){var n,r,s,l;if(e){const c=e.trim().split(" ").filter(Boolean);return c.length>=2?`${((n=c[0])==null?void 0:n[0])??""}${((r=c[1])==null?void 0:r[0])??""}`.toUpperCase():((l=(s=c[0])==null?void 0:s[0])==null?void 0:l.toUpperCase())||""}if(t!=null&&t.includes("@")){const c=t.split("@")[0];return c.length>1?`${c[0]}${c[1]}`.toUpperCase():c[0].toUpperCase()}return"U"}function xB(){const{user:e,signOut:t}=Ml(),{setTheme:n,theme:r}=TA(),[s,l]=p.useState(!1);if(!e)return null;const{fullName:c,email:d,avatar:h}=e,m=c??d??"Unknown User",g=yB(c,d);return o.jsx("div",{"data-slot":"sidebar-menu-item","data-sidebar":"menu-item",className:"group/menu-item relative",children:o.jsxs(Ar,{open:s,onOpenChange:l,children:[o.jsx(gB,{isOpen:s,displayName:m,email:d,avatar:h,initials:g}),o.jsx(vB,{items:mB({theme:r,setTheme:n,signOut:t})})]})})}function bB(){const{user:e,status:t}=Ml();return t===jr.LOADING||t===jr.UNAUTHENTICATED||!(e!=null&&e.projectId)?null:e.projectId}function Ao(){const e=tb(),t=bB(),n=p.useCallback((l,c)=>{if(!t){e("/",{replace:!0});return}const d=Qm(t,l);e(d,c)},[e,t]),r=p.useCallback(l=>t?Qm(t,l):l,[t]);return p.useMemo(()=>({navigate:n,scope:r,projectId:t}),[n,r,t])}function SB(){const{scope:e}=Ao();return o.jsxs(of,{to:e("/data-marts/create"),"data-sidebar":"menu-button","data-size":"md",className:"peer/menu-button ring-sidebar-ring bg-primary hover:bg-primary-hover text-primary-foreground hover:text-primary-foreground flex h-8 w-full items-center gap-2 overflow-hidden rounded-full p-2 text-left text-sm outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-0! focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",children:[o.jsx("div",{className:"flex aspect-square size-8 items-center justify-center",children:o.jsx(ea,{className:"size-4 shrink-0"})}),o.jsx("div",{className:"grid flex-1 text-left text-sm leading-tight",children:o.jsx("span",{className:"truncate font-medium",children:"New Data Mart"})})]})}const CB=[{title:"Data Marts",url:"/data-marts",icon:B6},{title:"Storages",url:"/data-storages",icon:zm},{title:"Destinations",url:"/data-destinations",icon:ob}];function EB(){const{scope:e}=Ao();return o.jsx(UU,{children:CB.map(t=>{const n=t.icon;return o.jsx(FU,{children:o.jsx(of,{to:e(t.url),className:({isActive:r})=>`flex w-full items-center gap-2 rounded-md font-medium transition-colors ${r?"bg-sidebar-active text-sidebar-active-foreground font-medium shadow-sm":""}`,children:({isActive:r})=>o.jsxs(At,{delayDuration:500,children:[o.jsx(Dt,{asChild:!0,children:o.jsxs(VU,{className:`${r?"hover:bg-transparent":""}`,children:[o.jsx(n,{className:"size-4 shrink-0 transition-all"}),o.jsx("span",{children:t.title}),t.badge&&o.jsx("span",{className:"bg-primary/20 text-primary ml-auto rounded-full px-2 py-0.5 text-xs",children:t.badge})]})}),o.jsx(Ot,{side:"right",children:t.title})]})})},t.title)})})}function wB({variant:e="inset",collapsible:t="icon"}){return o.jsxs(DU,{variant:e,collapsible:t,children:[o.jsx(IU,{children:o.jsx(aB,{})}),o.jsxs(PU,{children:[o.jsx(XR,{children:o.jsx(JR,{children:o.jsx(SB,{})})}),o.jsx(XR,{children:o.jsx(JR,{children:o.jsx(EB,{})})})]}),o.jsx(LU,{children:o.jsx(xB,{})}),o.jsx(MU,{})]})}function RB({children:e,...t}){return o.jsx(lB,{attribute:"class",defaultTheme:"system",enableSystem:!0,...t,children:e})}class kl{constructor(t){Es(this,"baseUrl");this.baseUrl=t}async get(t,n,r){const s=this.createUrl(t);return(await za.get(s,{...r,params:n})).data}async post(t,n,r){const s=this.createUrl(t);return(await za.post(s,n,r)).data}async put(t,n,r){const s=this.createUrl(t);return(await za.put(s,n,r)).data}async patch(t,n,r){const s=this.createUrl(t);return(await za.patch(s,n,r)).data}async delete(t,n){const r=this.createUrl(t);return(await za.delete(r,n)).data}createUrl(t){return this.baseUrl?`${this.baseUrl}${t}`:t}}class TB{set(t,n){try{const r=typeof n=="object"?JSON.stringify(n):String(n);localStorage.setItem(t,r)}catch(r){console.error(`Error setting localStorage key "${t}":`,r)}}get(t,n){try{const r=localStorage.getItem(t);if(r===null)return null;switch(n){case"boolean":return r==="true";case"json":{const s=JSON.parse(r);return typeof s=="object"?s:null}default:return r}}catch(r){return console.error(`Error getting localStorage key "${t}":`,r),null}}remove(t){try{localStorage.removeItem(t)}catch(n){console.error(`Error removing localStorage key "${t}":`,n)}}has(t){try{return localStorage.getItem(t)!==null}catch(n){return console.error(`Error checking localStorage key "${t}":`,n),!1}}clear(){try{localStorage.clear()}catch(t){console.error("Error clearing localStorage:",t)}}}const di=new TB;class jB{getTimezones(){return Intl.supportedValuesOf("timeZone")}getTimezonesWithOffset(){const t=this.getTimezones(),n=new Date;return t.map(r=>{const s=this.getTimezoneOffset(r,n),l=this.formatOffset(s),c=this.isDaylightSavingTime(r,n),d=this.getDisplayName(r,l);return{identifier:r,displayName:d,offsetMinutes:s,offsetString:l,isDST:c}})}getTimezoneOffset(t,n=new Date){try{const r=new Intl.DateTimeFormat("en-US",{timeZone:"UTC",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}),s=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}),l=new Date(r.format(n)),c=new Date(s.format(n));return Math.round((c.getTime()-l.getTime())/(1e3*60))}catch(r){return console.warn(`Failed to get offset for timezone ${t}:`,r),0}}formatOffset(t){const n=t>=0?"+":"-",r=Math.abs(t),s=Math.floor(r/60),l=r%60;return`${n}${s.toString().padStart(2,"0")}:${l.toString().padStart(2,"0")}`}isDaylightSavingTime(t,n=new Date){try{const r=new Date(n.getFullYear(),0,1),s=new Date(n.getFullYear(),6,1),l=this.getTimezoneOffset(t,r),c=this.getTimezoneOffset(t,s),d=this.getTimezoneOffset(t,n),h=Math.min(l,c);return d>h}catch(r){return console.warn(`Failed to check DST for timezone ${t}:`,r),!1}}getDisplayName(t,n){return`${t} (${n})`}getBrowserTimezone(){const t=Intl.DateTimeFormat().resolvedOptions().timeZone,n=new Date,r=this.getTimezoneOffset(t,n),s=this.formatOffset(r),l=this.isDaylightSavingTime(t,n),c=this.getDisplayName(t,s);return{identifier:t,displayName:c,offsetMinutes:r,offsetString:s,isDST:l}}getBrowserOffset(){return this.getBrowserTimezone().offsetMinutes}}const _B=new jB;function NB({isLoading:e,className:t}){const[n,r]=p.useState(0),[s,l]=p.useState(!1);return p.useEffect(()=>{let c,d;return e?(l(!0),r(0),c=setInterval(()=>{r(h=>h<90?h+(90-h)/10:h)},200)):(r(100),d=setTimeout(()=>{l(!1)},300)),()=>{clearInterval(c),clearTimeout(d)}},[e]),o.jsx("div",{className:fe("fixed top-0 right-0 left-0 z-50 h-1 transition-opacity duration-300",!s&&"opacity-0",t),children:o.jsx("div",{className:"bg-primary h-full transition-all duration-300 ease-out",style:{width:`${n.toString()}%`}})})}const jA=p.createContext({isLoading:!1});function AB({children:e}){const[t,n]=p.useState(0),r=t>0;return p.useEffect(()=>{const s=za.interceptors.request.use(c=>(c.skipLoadingIndicator||n(d=>d+1),c),c=>(c.config.skipLoadingIndicator||n(d=>Math.max(0,d-1)),Promise.reject(c))),l=za.interceptors.response.use(c=>(c.config.skipLoadingIndicator||n(d=>Math.max(0,d-1)),c),c=>(c.config.skipLoadingIndicator||n(d=>Math.max(0,d-1)),Promise.reject(c)));return()=>{za.interceptors.request.eject(s),za.interceptors.response.eject(l)}},[]),o.jsx(jA.Provider,{value:{isLoading:r},children:e})}function DB(){return p.useContext(jA)}function OB(){return o.jsx(J$,{position:"top-center",toastOptions:{duration:3e3,style:{borderRadius:"32px",boxShadow:"none",padding:"0.4rem 1rem",maxWidth:"800px",fontSize:"0.875rem",borderBottomWidth:"1px",borderBottomStyle:"solid"},success:{style:{background:"#ECFDF5",color:"#166534",borderBottomColor:"#D6DFE6"}},error:{style:{background:"#FEE2E2",color:"#991B1B",borderBottomColor:"#EAD1D1"},duration:6e3},loading:{style:{background:"#E8EDFB",color:"#1D4ED8",borderBottomColor:"#CAD5F6",borderBottomWidth:"1px",borderBottomStyle:"solid"}}}})}function MB({children:e}){const{isLoading:t}=iA(),n=mH(),r=rj(),s=jo();return p.useEffect(()=>{if(t)return;const l=r.projectId,c=n==null?void 0:n.projectId;if(l&&!s.pathname.startsWith("/auth")&&n&&c&&c!==l){const d=new URLSearchParams({projectId:l}).toString();window.location.href=`/auth/sign-in?${d}`}},[t,n,r.projectId,s.pathname]),o.jsx(o.Fragment,{children:e})}const k2="sidebar_state";function kB(){const{state:e,isMobile:t}=vf(),r=t||e==="collapsed",{isLoading:s}=DB();return o.jsxs(o.Fragment,{children:[o.jsx(OB,{}),o.jsx(NB,{isLoading:s}),o.jsxs(pH,{redirectTo:"/auth/sign-in",children:[o.jsx(wB,{variant:"inset",collapsible:"icon"}),o.jsxs(kU,{children:[r&&o.jsx(OU,{}),o.jsx(MB,{children:o.jsx(sj,{})})]})]})]})}function IB(){const[e,t]=p.useState(()=>di.get(k2,"boolean")??!0),n=r=>{t(r),di.set(k2,r)};return o.jsx(RB,{children:o.jsx(AB,{children:o.jsx(AU,{open:e,onOpenChange:n,children:o.jsx(kB,{})})})})}function LB(){return o.jsxs("div",{className:"app-container",children:[o.jsx("h1",{children:"About OWOX"}),o.jsx("p",{children:"OWOX Data Marts — Free, Open-Source Connectors for Data Analysts"})]})}function I2(){return o.jsxs("div",{className:"dm-empty-state-404page",children:[o.jsxs("div",{className:"dm-empty-state-404page-foreground",children:[o.jsx(SL,{className:"dm-empty-state-ico",strokeWidth:1}),o.jsx("h1",{className:"dm-empty-state-title",children:"Lost in the 404th Data Realm"}),o.jsxs("p",{className:"dm-empty-state-subtitle",children:["In this dimension, ",o.jsx("code",{children:"1+1=3"}),", percentages exceed 100%, and dashboards predict"," ",o.jsx("i",{children:"yesterday"}),".",o.jsx("br",{}),"Escape while you can!"]}),o.jsx(we,{variant:"default",asChild:!0,children:o.jsxs(Ni,{to:"/",className:"flex items-center gap-1","aria-label":"Guide Me Home",children:["Guide Me Home",o.jsx(_o,{className:"h-4 w-4"})]})})]}),o.jsx("div",{className:"dm-empty-state-404page-background"})]})}const PB={items:[],loading:!1,error:null};function UB(e,t){switch(t.type){case"SET_ITEMS":return{...e,items:t.payload,loading:!1,error:null};case"SET_LOADING":return{...e,loading:!0,error:null};case"SET_ERROR":return{...e,loading:!1,error:t.payload};default:return e}}const _A=p.createContext(void 0);function FB({children:e}){const[t,n]=p.useReducer(UB,PB);return o.jsx(_A.Provider,{value:{state:t,dispatch:n},children:e})}function zB(){const e=p.useContext(_A);if(e===void 0)throw new Error("useDataMartListContext must be used within a DataMartListProvider");return e}class VB extends kl{constructor(){super("/data-marts")}async getDataMarts(){return this.get("/")}async getDataMartById(t){return this.get(`/${t}`)}async createDataMart(t){return this.post("",t)}async updateDataMart(t,n){return this.patch(`/${t}`,n)}async deleteDataMart(t){return this.delete(`/${t}`)}async updateDataMartDescription(t,n){return this.put(`/${t}/description`,{description:n})}async updateDataMartTitle(t,n){return this.put(`/${t}/title`,{title:n})}async updateDataMartDefinition(t,n){return this.put(`/${t}/definition`,n,{timeout:18e4})}async publishDataMart(t){return this.put(`/${t}/publish`,void 0,{timeout:18e4})}async runDataMart(t,n){return this.post(`/${t}/manual-run`,{payload:n})}async cancelDataMartRun(t,n){await this.post(`/${t}/runs/${n}/cancel`)}async actualizeDataMartSchema(t){return this.post(`/${t}/actualize-schema`,void 0,{timeout:18e4})}async updateDataMartSchema(t,n){return this.put(`/${t}/schema`,n,{timeout:18e4})}async validateSql(t,n,r,s=!0){const l={sql:n},c={...r?{signal:r.signal}:{},skipLoadingIndicator:s,timeout:18e4};return this.post(`/${t}/sql-dry-run`,l,c)}async getDataMartRuns(t,n=5,r=0){return(await this.get(`/${t}/runs`,{limit:n,offset:r})).runs}}const vr=new VB;var lr=(e=>(e.DRAFT="DRAFT",e.PUBLISHED="PUBLISHED",e))(lr||{}),Qe=(e=>(e.SQL="SQL",e.TABLE="TABLE",e.VIEW="VIEW",e.TABLE_PATTERN="TABLE_PATTERN",e.CONNECTOR="CONNECTOR",e))(Qe||{}),Om=(e=>(e.ALREADY_PUBLISHED="ALREADY_PUBLISHED",e.INVALID_STORAGE="INVALID_STORAGE",e.MISSING_DEFINITION_TYPE="MISSING_DEFINITION_TYPE",e.MISSING_DEFINITION="MISSING_DEFINITION",e))(Om||{});const HB={ALREADY_PUBLISHED:"Data mart is already published",INVALID_STORAGE:"Data mart must have a valid storage",MISSING_DEFINITION_TYPE:"Data mart must have an input source configured",MISSING_DEFINITION:"Data mart must have a valid definition"},NA={statuses:{[lr.DRAFT]:{code:lr.DRAFT,displayName:"Draft",description:"Data mart is in draft mode and not yet published"},[lr.PUBLISHED]:{code:lr.PUBLISHED,displayName:"Published",description:"Data mart is published and available for use"}},getInfo(e){return this.statuses[e]},getAllStatuses(){return Object.values(this.statuses)}},AA=e=>e?/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+$/.test(e):!1,DA=e=>e?/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+\.[a-zA-Z0-9_\-*]+$/.test(e):!1,$B=e=>e?AA(e)?"":"Invalid format. Expected: project.dataset.object":"Fully qualified name is required",BB=e=>e?DA(e)?"":"Invalid format. Expected: project.dataset.table_* (with wildcards)":"Table pattern is required",OA=e=>{if(!e)return!1;const t=/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+$/,n=/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+$/;return t.test(e)||n.test(e)},MA=e=>{if(!e)return!1;const t=/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_\-*]+$/,n=/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+\.[a-zA-Z0-9_\-*]+$/;return t.test(e)||n.test(e)},GB=e=>e?OA(e)?"":"Invalid format. Expected: database.object or catalog.database.object":"Fully qualified name is required",qB=e=>e?MA(e)?"":"Invalid format. Expected: database.table_* or catalog.database.table_* (with wildcards)":"Table pattern is required",ZB=[{value:"US",label:"US (multiple regions)",group:"North America"},{value:"northamerica-northeast1",label:"Montréal",group:"North America"},{value:"northamerica-northeast2",label:"Toronto",group:"North America"},{value:"us-central1",label:"Iowa",group:"North America"},{value:"us-east1",label:"South Carolina",group:"North America"},{value:"us-east4",label:"Northern Virginia",group:"North America"},{value:"us-east5",label:"Columbus",group:"North America"},{value:"us-west1",label:"Oregon",group:"North America"},{value:"us-west2",label:"Los Angeles",group:"North America"},{value:"us-west3",label:"Salt Lake City",group:"North America"},{value:"us-west4",label:"Las Vegas",group:"North America"},{value:"EU",label:"EU (multiple regions)",group:"Europe"},{value:"europe-central2",label:"Warsaw",group:"Europe"},{value:"europe-north1",label:"Finland",group:"Europe"},{value:"europe-southwest1",label:"Madrid",group:"Europe"},{value:"europe-west1",label:"Belgium",group:"Europe"},{value:"europe-west2",label:"London",group:"Europe"},{value:"europe-west3",label:"Frankfurt",group:"Europe"},{value:"europe-west4",label:"Netherlands",group:"Europe"},{value:"europe-west6",label:"Zurich",group:"Europe"},{value:"europe-west8",label:"Milan",group:"Europe"},{value:"europe-west9",label:"Paris",group:"Europe"},{value:"europe-west12",label:"Turin",group:"Europe"},{value:"asia-east1",label:"Taiwan",group:"Asia Pacific"},{value:"asia-east2",label:"Hong Kong",group:"Asia Pacific"},{value:"asia-northeast1",label:"Tokyo",group:"Asia Pacific"},{value:"asia-northeast2",label:"Osaka",group:"Asia Pacific"},{value:"asia-northeast3",label:"Seoul",group:"Asia Pacific"},{value:"asia-south1",label:"Mumbai",group:"Asia Pacific"},{value:"asia-south2",label:"Delhi",group:"Asia Pacific"},{value:"asia-southeast1",label:"Singapore",group:"Asia Pacific"},{value:"asia-southeast2",label:"Jakarta",group:"Asia Pacific"},{value:"australia-southeast1",label:"Sydney",group:"Asia Pacific"},{value:"australia-southeast2",label:"Melbourne",group:"Asia Pacific"},{value:"southamerica-east1",label:"São Paulo",group:"Other"},{value:"southamerica-west1",label:"Santiago",group:"Other"},{value:"me-central1",label:"Doha",group:"Other"},{value:"me-central2",label:"Dammam",group:"Other"},{value:"me-west1",label:"Tel Aviv",group:"Other"},{value:"africa-south1",label:"Johannesburg",group:"Other"}];function KB(e){return"projectId"in e}function YB(e){return"outputBucket"in e}var Pe=(e=>(e.GOOGLE_BIGQUERY="GOOGLE_BIGQUERY",e.AWS_ATHENA="AWS_ATHENA",e.SNOWFLAKE="SNOWFLAKE",e.DATABRICKS="DATABRICKS",e.AWS_REDSHIFT="AWS_REDSHIFT",e.AZURE_SYNAPSE="AZURE_SYNAPSE",e))(Pe||{}),po=(e=>(e.ACTIVE="active",e.COMING_SOON="coming_soon",e))(po||{});const QB=({label:e,value:t,truncate:n=!1})=>{const r=typeof t=="string"?t.trim():t,s=r==="";return o.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[o.jsxs("span",{className:"text-muted-foreground text-sm",children:[e,":"]}),n&&r&&!s?o.jsx("span",{className:"truncate text-sm",title:r,children:r.length>30?r.substring(0,30)+"...":r}):o.jsx("span",{className:"text-sm",children:s||r===void 0?o.jsx("span",{className:"text-muted-foreground",children:"—"}):r})]})},WB=({type:e,config:t})=>{const n={[Pe.GOOGLE_BIGQUERY]:[{label:"Project ID",key:"projectId"},{label:"Location",key:"location"}],[Pe.AWS_ATHENA]:[{label:"Region",key:"region"},{label:"Output Bucket",key:"outputBucket"}],[Pe.SNOWFLAKE]:[],[Pe.DATABRICKS]:[],[Pe.AWS_REDSHIFT]:[],[Pe.AZURE_SYNAPSE]:[]},r=t&&(e===Pe.GOOGLE_BIGQUERY&&KB(t)||e===Pe.AWS_ATHENA&&YB(t));return o.jsx("div",{className:"grid gap-2",children:n[e].map(({label:s,key:l})=>{let c;return r&&(c=(e===Pe.GOOGLE_BIGQUERY,t[l])),o.jsx(QB,{label:s,value:c},l)})})},XB=({type:e,config:t})=>o.jsx("div",{className:"space-y-4",children:o.jsxs("div",{className:"space-y-1",children:[o.jsx("h4",{className:"text-sm font-medium",children:"Configuration"}),o.jsx(WB,{type:e,config:t})]})}),JB=lf("inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",secondary:"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",destructive:"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"}},defaultVariants:{variant:"default"}});function Rr({className:e,variant:t,asChild:n=!1,...r}){const s=n?_p:"span";return o.jsx(s,{"data-slot":"badge",className:fe(JB({variant:t}),e),...r})}function kA(e){return e.type===Pe.GOOGLE_BIGQUERY}function IA(e){return e.type===Pe.AWS_ATHENA}const Ii={types:{[Pe.GOOGLE_BIGQUERY]:{type:Pe.GOOGLE_BIGQUERY,displayName:"Google BigQuery",icon:SH,status:po.ACTIVE},[Pe.AWS_ATHENA]:{type:Pe.AWS_ATHENA,displayName:"AWS Athena",icon:CH,status:po.ACTIVE},[Pe.SNOWFLAKE]:{type:Pe.SNOWFLAKE,displayName:"Snowflake",icon:RH,status:po.COMING_SOON},[Pe.DATABRICKS]:{type:Pe.DATABRICKS,displayName:"Databricks",icon:TH,status:po.COMING_SOON},[Pe.AWS_REDSHIFT]:{type:Pe.AWS_REDSHIFT,displayName:"AWS Redshift",icon:jH,status:po.COMING_SOON},[Pe.AZURE_SYNAPSE]:{type:Pe.AZURE_SYNAPSE,displayName:"Azure Synapse",icon:_H,status:po.COMING_SOON}},getInfo(e){return this.types[e]},getAllTypes(){return Object.values(this.types)}};function eG({dataStorage:e,isLoading:t=!1}){if(t)return o.jsx("div",{className:"space-y-4",children:o.jsx("div",{className:"grid gap-4",children:Array(4).fill(0).map((c,d)=>o.jsxs("div",{className:"space-y-1",children:[o.jsx(ir,{className:"h-5 w-24"}),o.jsx(ir,{className:"h-6 w-40"})]},d))})});if(!e)return o.jsx("div",{children:"No storage information available."});const{type:n,config:r,createdAt:s,modifiedAt:l}=e;return o.jsx("div",{className:"space-y-2",children:o.jsxs("div",{className:"grid gap-2",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("div",{children:e.title}),o.jsx(Rr,{variant:"secondary",className:"flex h-7 items-center gap-2",children:(()=>{const{displayName:c,icon:d}=Ii.getInfo(n);return o.jsxs(o.Fragment,{children:[o.jsx(d,{}),c]})})()})]}),o.jsx("div",{className:"bg-muted/10 rounded-md border p-4",children:o.jsx(XB,{type:n,config:r})}),o.jsxs("div",{className:"text-muted-foreground flex gap-6 text-xs",children:[o.jsxs("div",{children:[o.jsx("span",{className:"font-medium",children:"Created:"})," ",new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(s))]}),o.jsxs("div",{children:[o.jsx("span",{className:"font-medium",children:"Modified:"})," ",new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(l))]})]})]})})}function tG(e){const t=e.split(".");return t.length!==2?(console.error("Invalid fully qualified name format:",e),null):{dataset:t[0],table:t[1]}}function nG(e,t,n){const r=encodeURIComponent(e),s=encodeURIComponent(t),l=encodeURIComponent(n);return`https://console.cloud.google.com/bigquery?project=${r}&ws=!1m5!1m4!4m3!1s${r}!2s${s}!3s${l}`}function rG(e){return`https://console.aws.amazon.com/athena/home?region=${encodeURIComponent(e)}#/query-editor`}function aG(e,t){const n=tG(t);if(!n)return null;const{dataset:r,table:s}=n;return kA(e)?nG(e.config.projectId,r,s):IA(e)?rG(e.config.region):null}function sG(e,t){const n=aG(e,t);return n?(window.open(n,"_blank","noopener,noreferrer"),!0):!1}function oG(e){return kA(e)?"Open table in Google BigQuery":IA(e)?"Open region in AWS Athena":"Open data in storage"}const iG=en({accessKeyId:tn().min(1,"Access Key ID is required"),secretAccessKey:tn().min(1,"Secret Access Key is required")}),lG=en({projectId:tn().min(1,"Project ID is required"),location:tn().min(1,"Location is required")}),cG=en({region:tn().min(1,"Region is required"),outputBucket:tn().min(1,"Output Bucket is required")}),LA=en({title:tn().min(1,"Title is required").max(255,"Title must be 255 characters or less")}),uG=LA.extend({type:Vs(Pe.GOOGLE_BIGQUERY),credentials:gA,config:lG}),dG=LA.extend({type:Vs(Pe.AWS_ATHENA),credentials:iG,config:cG}),fG=pA("type",[uG,dG]),hG=(e,t)=>{if(!e)return!1;switch(t){case Pe.GOOGLE_BIGQUERY:return AA(e);case Pe.AWS_ATHENA:return OA(e);default:return!1}},mG=(e,t)=>{if(!e)return!1;switch(t){case Pe.GOOGLE_BIGQUERY:return DA(e);case Pe.AWS_ATHENA:return MA(e);default:return!1}},pG=(e,t)=>{if(!e)return"Fully qualified name is required";switch(t){case Pe.GOOGLE_BIGQUERY:return $B(e);case Pe.AWS_ATHENA:return GB(e);default:return"Unsupported storage type"}},gG=(e,t)=>{if(!e)return"Table pattern is required";switch(t){case Pe.GOOGLE_BIGQUERY:return BB(e);case Pe.AWS_ATHENA:return qB(e);default:return"Unsupported storage type"}},PA=e=>{switch(e){case Pe.GOOGLE_BIGQUERY:return"project.dataset.table";case Pe.AWS_ATHENA:return"database.table or catalog.database.table";default:return""}},vG=e=>{switch(e){case Pe.GOOGLE_BIGQUERY:return"project.dataset.table_*";case Pe.AWS_ATHENA:return"database.table_* or catalog.database.table_*";default:return""}},UA=e=>{switch(e){case Pe.GOOGLE_BIGQUERY:return"Enter the fully qualified name of the table (e.g., project.dataset.table)";case Pe.AWS_ATHENA:return"Enter the fully qualified name of the table (e.g., database.table or catalog.database.table)";default:return""}},yG=e=>{switch(e){case Pe.GOOGLE_BIGQUERY:return'Enter a pattern to match multiple tables (e.g., project.dataset.table_* will match all tables starting with "table_")';case Pe.AWS_ATHENA:return'Enter a pattern to match multiple tables (e.g., database.table_* will match all tables starting with "table_")';default:return""}};var Sn=(e=>(e.SUCCESS="success",e.ERROR="error",e.WARNING="warning",e.INFO="info",e.NEUTRAL="neutral",e))(Sn||{});const xG={solid:"px-2.5 py-0.5 rounded-full",subtle:"px-2.5 py-0.5 rounded-full",outline:"px-2.5 py-0.5 rounded-full border",ghost:""},bG=e=>xG[e],SG={[Sn.SUCCESS]:{icon:Np,colors:{solid:"bg-green-500 text-white",subtle:"bg-green-50 text-green-700 dark:bg-green-950 dark:text-green-400",outline:"border-green-500 text-green-700 dark:text-green-400",ghost:"text-green-500 dark:text-green-400"}},[Sn.ERROR]:{icon:eL,colors:{solid:"bg-red-500 text-white",subtle:"bg-red-50 text-red-700 dark:bg-red-950 dark:text-red-400",outline:"border-red-500 text-red-700 dark:text-red-400",ghost:"text-red-500 dark:text-red-400"}},[Sn.WARNING]:{icon:Dp,colors:{solid:"bg-yellow-500 text-white",subtle:"bg-yellow-50 text-yellow-700 dark:bg-yellow-950 dark:text-yellow-400",outline:"border-yellow-500 text-yellow-700 dark:text-yellow-400",ghost:"text-yellow-500 dark:text-yellow-400"}},[Sn.INFO]:{icon:Xr,colors:{solid:"bg-blue-500 text-white",subtle:"bg-blue-50 text-blue-700 dark:bg-blue-950 dark:text-blue-400",outline:"border-blue-500 text-blue-700 dark:text-blue-400",ghost:"text-blue-500 dark:text-blue-400"}},[Sn.NEUTRAL]:{icon:Xr,colors:{solid:"bg-gray-500 text-white",subtle:"bg-gray-50 text-gray-700 dark:bg-gray-950 dark:text-gray-400",outline:"border-gray-500 text-gray-700 dark:text-gray-400",ghost:"text-muted-foreground"}}};function _f({type:e=Sn.NEUTRAL,variant:t="ghost",showIcon:n=!0,children:r,className:s}){const{icon:l,colors:c}=SG[e],d=h=>{const m="inline-flex items-center gap-1 text-sm",g=bG(h),v=c[h];return fe(m,g,v,s)};return o.jsxs("span",{className:d(t),children:[n&&o.jsx(l,{className:"h-4 w-4","data-testid":"icon"}),r]})}var Lr=(e=>(e.INFO="INFO",e.WARNING="WARNING",e.ERROR="ERROR",e.SYSTEM="SYSTEM",e))(Lr||{}),Cn=(e=>(e.RUNNING="RUNNING",e.SUCCESS="SUCCESS",e.FAILED="FAILED",e.CANCELLED="CANCELLED",e.INTERRUPTED="INTERRUPTED",e))(Cn||{}),es=(e=>(e.STRUCTURED="structured",e.RAW="raw",e.CONFIGURATION="configuration",e))(es||{});const L2=(e,t,n=!1)=>{var c,d;const r=e.split(`
|
|
661
|
+
`,um=16,J$=({reverseOrder:e,position:t="top-center",toastOptions:n,gutter:r,children:s,toasterId:l,containerStyle:c,containerClassName:d})=>{let{toasts:h,handlers:m}=j$(n,l);return p.createElement("div",{"data-rht-toaster":l||"",style:{position:"fixed",zIndex:9999,top:um,left:um,right:um,bottom:um,pointerEvents:"none",...c},className:d,onMouseEnter:m.startPause,onMouseLeave:m.endPause},h.map(g=>{let v=g.position||t,x=m.calculateOffset(g,{reverseOrder:e,gutter:r,defaultPosition:t}),b=W$(v,x);return p.createElement(Q$,{id:g.id,key:g.id,onHeightUpdate:m.updateHeight,className:g.visible?X$:"",style:b},g.type==="custom"?cp(g.message,g):s?s(g):p.createElement(Y$,{toast:g,position:v}))}))},dn=Jt;const hn=e=>{var n;return(n=e.response)==null?void 0:n.data};function O2(e,t="Something went wrong"){var s,l;const n=hn(e);let r=n.message.trim()||t;(l=(s=n.errorDetails)==null?void 0:s.error)!=null&&l.trim()&&(r=`${r}. ${n.errorDetails.error}`),dn.error(r)}class eB{constructor(){Es(this,"isRefreshingToken",!1);Es(this,"refreshTokenPromise",null);Es(this,"accessToken",null)}getAccessToken(){return this.accessToken}setAccessToken(t){this.accessToken=t}isRefreshing(){return this.isRefreshingToken}async refreshToken(t){if(this.isRefreshingToken&&this.refreshTokenPromise)return await this.refreshTokenPromise;this.isRefreshingToken=!0,this.refreshTokenPromise=this.performRefresh(t);try{const n=await this.refreshTokenPromise;return this.setAccessToken(n),n}finally{this.isRefreshingToken=!1,this.refreshTokenPromise=null}}clear(){this.accessToken=null,this.isRefreshingToken=!1,this.refreshTokenPromise=null}async performRefresh(t){try{return await t()}catch(n){throw this.clear(),n}}}const tB={baseURL:"/api",timeout:3e4,headers:{"Content-Type":"application/json",Accept:"application/json"}},za=En.create(tB),x0=new eB;za.interceptors.request.use(e=>{if(e.skipAuthHeader||new nH(e.headers).has("X-OWOX-Authorization"))return e;const n=Vb(),r=(n==null?void 0:n.getAccessToken())??x0.getAccessToken();return r&&(e.headers["X-OWOX-Authorization"]=`Bearer ${r}`),e},e=>Promise.reject(e instanceof Error?e:new Error("Unknown error")));za.interceptors.response.use(e=>e,async e=>{var n,r,s;const t=e.config;if(((n=e.response)==null?void 0:n.status)===401&&!t._retry){t._retry=!0;try{const l=Vb();if(!l)throw new Error("No token provider available");const c=await x0.refreshToken(()=>l.refreshToken());return t.headers["X-OWOX-Authorization"]=`Bearer ${c}`,await za(t)}catch{return x0.clear(),window.dispatchEvent(new CustomEvent("auth:logout",{detail:{reason:"token_refresh_failed"}})),Promise.reject(new Error("Token refresh failed"))}}return((r=e.response)==null?void 0:r.status)===403&&O2(e,"Access forbidden - insufficient permissions"),((s=e.response)==null?void 0:s.status)===400&&O2(e,"Bad request"),Promise.reject(e)});const wA={projects:[],callState:Pr.IDLE,error:null};function nB(e,t){switch(t.type){case"LOADING":return{...e,callState:Pr.LOADING,error:null};case"SUCCESS":return{projects:t.payload,callState:Pr.LOADED,error:null};case"ERROR":return{...e,callState:Pr.ERROR,error:t.payload};case"RESET":return{...wA};default:return e}}function rB({children:e}){const[t,n]=p.useReducer(nB,wA),r=p.useCallback(async()=>{n({type:"LOADING"});try{const d=Vb();if(!d){n({type:"ERROR",payload:hn(new v2("No token provider"))});return}const h=d.getAccessToken();if(!h){n({type:"ERROR",payload:hn(new v2("Unable to obtain access token"))});return}const m=await lH(h);n({type:"SUCCESS",payload:m})}catch(d){n({type:"ERROR",payload:hn(d)})}},[]),s=p.useCallback(()=>{n({type:"RESET"})},[]),l=t.callState===Pr.LOADING,c={...t,loadProjects:r,reset:s,isLoading:l};return o.jsx(lA.Provider,{value:c,children:e})}function aB(){const[e,t]=p.useState(!1);return o.jsx("div",{"data-slot":"sidebar-header","data-sidebar":"header",className:"flex flex-col gap-2",children:o.jsx("ul",{"data-slot":"sidebar-menu","data-sidebar":"menu",className:"flex w-full min-w-0 flex-col gap-1",children:o.jsx("li",{"data-slot":"sidebar-menu-item","data-sidebar":"menu-item",className:"group/menu-item relative",children:o.jsxs(Ar,{open:e,onOpenChange:t,children:[o.jsx(jz,{isOpen:e}),o.jsx(rB,{children:o.jsx(d$,{})})]})})})})}var sB=(e,t,n,r,s,l,c,d)=>{let h=document.documentElement,m=["light","dark"];function g(b){(Array.isArray(e)?e:[e]).forEach(E=>{let C=E==="class",w=C&&l?s.map(R=>l[R]||R):s;C?(h.classList.remove(...w),h.classList.add(l&&l[b]?l[b]:b)):h.setAttribute(E,b)}),v(b)}function v(b){d&&m.includes(b)&&(h.style.colorScheme=b)}function x(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(r)g(r);else try{let b=localStorage.getItem(t)||n,E=c&&b==="system"?x():b;g(E)}catch{}},M2=["light","dark"],RA="(prefers-color-scheme: dark)",oB=typeof window>"u",qb=p.createContext(void 0),iB={setTheme:e=>{},themes:[]},TA=()=>{var e;return(e=p.useContext(qb))!=null?e:iB},lB=e=>p.useContext(qb)?p.createElement(p.Fragment,null,e.children):p.createElement(uB,{...e}),cB=["light","dark"],uB=({forcedTheme:e,disableTransitionOnChange:t=!1,enableSystem:n=!0,enableColorScheme:r=!0,storageKey:s="theme",themes:l=cB,defaultTheme:c=n?"system":"light",attribute:d="data-theme",value:h,children:m,nonce:g,scriptProps:v})=>{let[x,b]=p.useState(()=>fB(s,c)),[E,C]=p.useState(()=>x==="system"?mx():x),w=h?Object.values(h):l,R=p.useCallback(D=>{let N=D;if(!N)return;D==="system"&&n&&(N=mx());let A=h?h[N]:N,k=t?hB(g):null,U=document.documentElement,B=H=>{H==="class"?(U.classList.remove(...w),A&&U.classList.add(A)):H.startsWith("data-")&&(A?U.setAttribute(H,A):U.removeAttribute(H))};if(Array.isArray(d)?d.forEach(B):B(d),r){let H=M2.includes(c)?c:null,Q=M2.includes(N)?N:H;U.style.colorScheme=Q}k==null||k()},[g]),T=p.useCallback(D=>{let N=typeof D=="function"?D(x):D;b(N);try{localStorage.setItem(s,N)}catch{}},[x]),j=p.useCallback(D=>{let N=mx(D);C(N),x==="system"&&n&&!e&&R("system")},[x,e]);p.useEffect(()=>{let D=window.matchMedia(RA);return D.addListener(j),j(D),()=>D.removeListener(j)},[j]),p.useEffect(()=>{let D=N=>{N.key===s&&(N.newValue?b(N.newValue):T(c))};return window.addEventListener("storage",D),()=>window.removeEventListener("storage",D)},[T]),p.useEffect(()=>{R(e??x)},[e,x]);let O=p.useMemo(()=>({theme:x,setTheme:T,forcedTheme:e,resolvedTheme:x==="system"?E:x,themes:n?[...l,"system"]:l,systemTheme:n?E:void 0}),[x,T,e,E,n,l]);return p.createElement(qb.Provider,{value:O},p.createElement(dB,{forcedTheme:e,storageKey:s,attribute:d,enableSystem:n,enableColorScheme:r,defaultTheme:c,value:h,themes:l,nonce:g,scriptProps:v}),m)},dB=p.memo(({forcedTheme:e,storageKey:t,attribute:n,enableSystem:r,enableColorScheme:s,defaultTheme:l,value:c,themes:d,nonce:h,scriptProps:m})=>{let g=JSON.stringify([n,t,l,e,d,c,r,s]).slice(1,-1);return p.createElement("script",{...m,suppressHydrationWarning:!0,nonce:typeof window>"u"?h:"",dangerouslySetInnerHTML:{__html:`(${sB.toString()})(${g})`}})}),fB=(e,t)=>{if(oB)return;let n;try{n=localStorage.getItem(e)||void 0}catch{}return n||t},hB=e=>{let t=document.createElement("style");return e&&t.setAttribute("nonce",e),t.appendChild(document.createTextNode("*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}")),document.head.appendChild(t),()=>{window.getComputedStyle(document.body),setTimeout(()=>{document.head.removeChild(t)},1)}},mx=e=>(e||(e=window.matchMedia(RA)),e.matches?"dark":"light");function mB({theme:e,setTheme:t,signOut:n}){return[{title:`Switch to ${e==="light"?"dark":"light"} mode`,icon:e==="light"?Q8:vL,onClick:()=>{t(e==="light"?"dark":"light")}},{type:"separator"},{title:"Sign out",icon:V8,onClick:n,className:"text-red-600 focus:text-red-600"}]}function pB({avatar:e,initials:t,displayName:n}){return o.jsx("div",{className:"text-muted-foreground flex aspect-square size-8 items-center justify-center rounded-full border bg-white text-sm font-medium dark:bg-white/10",children:e?o.jsx("img",{src:e,alt:n,className:"size-full rounded-full object-cover"}):o.jsx("span",{children:t})})}function gB({isOpen:e,displayName:t,email:n,avatar:r,initials:s}){return o.jsx(Dr,{asChild:!0,children:o.jsxs("button",{type:"button","data-slot":"dropdown-menu-trigger","data-sidebar":"menu-button","data-size":"lg","data-active":e?"true":"false","aria-haspopup":"menu","aria-expanded":e,"data-state":e?"open":"closed",className:"peer/menu-button ring-sidebar-ring active:bg-sidebar-accent active:text-sidebar-accent-foreground data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground flex h-12 w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:rounded-full group-data-[collapsible=icon]:p-0! focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",children:[o.jsx(pB,{avatar:r,initials:s,displayName:t}),o.jsxs("div",{className:"grid flex-1 text-left text-sm leading-tight group-data-[collapsible=icon]:hidden",children:[o.jsx("span",{className:"truncate font-medium",children:t}),n&&o.jsx("span",{className:"text-muted-foreground truncate text-xs",children:n})]}),o.jsx(Ga,{className:`ml-auto size-4 transition-transform duration-200 group-data-[collapsible=icon]:hidden ${e?"rotate-180":""}`})]})})}function vB({items:e}){return o.jsx(Or,{align:"start",side:"top",sideOffset:8,className:"w-56",children:e.map((t,n)=>t.type==="separator"?o.jsx($a,{},`sep-${String(n)}`):o.jsxs(Tt,{onClick:t.onClick,className:`flex items-center gap-2 ${t.className??""}`,children:[o.jsx(t.icon,{className:"size-4"}),t.title]},t.title))})}function yB(e,t){var n,r,s,l;if(e){const c=e.trim().split(" ").filter(Boolean);return c.length>=2?`${((n=c[0])==null?void 0:n[0])??""}${((r=c[1])==null?void 0:r[0])??""}`.toUpperCase():((l=(s=c[0])==null?void 0:s[0])==null?void 0:l.toUpperCase())||""}if(t!=null&&t.includes("@")){const c=t.split("@")[0];return c.length>1?`${c[0]}${c[1]}`.toUpperCase():c[0].toUpperCase()}return"U"}function xB(){const{user:e,signOut:t}=Ml(),{setTheme:n,theme:r}=TA(),[s,l]=p.useState(!1);if(!e)return null;const{fullName:c,email:d,avatar:h}=e,m=c??d??"Unknown User",g=yB(c,d);return o.jsx("div",{"data-slot":"sidebar-menu-item","data-sidebar":"menu-item",className:"group/menu-item relative",children:o.jsxs(Ar,{open:s,onOpenChange:l,children:[o.jsx(gB,{isOpen:s,displayName:m,email:d,avatar:h,initials:g}),o.jsx(vB,{items:mB({theme:r,setTheme:n,signOut:t})})]})})}function bB(){const{user:e,status:t}=Ml();return t===jr.LOADING||t===jr.UNAUTHENTICATED||!(e!=null&&e.projectId)?null:e.projectId}function Ao(){const e=tb(),t=bB(),n=p.useCallback((l,c)=>{if(!t){e("/",{replace:!0});return}const d=Qm(t,l);e(d,c)},[e,t]),r=p.useCallback(l=>t?Qm(t,l):l,[t]);return p.useMemo(()=>({navigate:n,scope:r,projectId:t}),[n,r,t])}function SB(){const{scope:e}=Ao();return o.jsxs(of,{to:e("/data-marts/create"),"data-sidebar":"menu-button","data-size":"md",className:"peer/menu-button ring-sidebar-ring bg-primary hover:bg-primary-hover text-primary-foreground hover:text-primary-foreground flex h-8 w-full items-center gap-2 overflow-hidden rounded-full p-2 text-left text-sm outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-0! focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",children:[o.jsx("div",{className:"flex aspect-square size-8 items-center justify-center",children:o.jsx(ea,{className:"size-4 shrink-0"})}),o.jsx("div",{className:"grid flex-1 text-left text-sm leading-tight",children:o.jsx("span",{className:"truncate font-medium",children:"New Data Mart"})})]})}const CB=[{title:"Data Marts",url:"/data-marts",icon:B6},{title:"Storages",url:"/data-storages",icon:zm},{title:"Destinations",url:"/data-destinations",icon:ob}];function EB(){const{scope:e}=Ao();return o.jsx(UU,{children:CB.map(t=>{const n=t.icon;return o.jsx(FU,{children:o.jsx(of,{to:e(t.url),className:({isActive:r})=>`flex w-full items-center gap-2 rounded-md font-medium transition-colors ${r?"bg-sidebar-active text-sidebar-active-foreground font-medium shadow-sm":""}`,children:({isActive:r})=>o.jsxs(At,{delayDuration:500,children:[o.jsx(Dt,{asChild:!0,children:o.jsxs(VU,{className:`${r?"hover:bg-transparent":""}`,children:[o.jsx(n,{className:"size-4 shrink-0 transition-all"}),o.jsx("span",{children:t.title}),t.badge&&o.jsx("span",{className:"bg-primary/20 text-primary ml-auto rounded-full px-2 py-0.5 text-xs",children:t.badge})]})}),o.jsx(Ot,{side:"right",children:t.title})]})})},t.title)})})}function wB({variant:e="inset",collapsible:t="icon"}){return o.jsxs(DU,{variant:e,collapsible:t,children:[o.jsx(IU,{children:o.jsx(aB,{})}),o.jsxs(PU,{children:[o.jsx(XR,{children:o.jsx(JR,{children:o.jsx(SB,{})})}),o.jsx(XR,{children:o.jsx(JR,{children:o.jsx(EB,{})})})]}),o.jsx(LU,{children:o.jsx(xB,{})}),o.jsx(MU,{})]})}function RB({children:e,...t}){return o.jsx(lB,{attribute:"class",defaultTheme:"system",enableSystem:!0,...t,children:e})}class kl{constructor(t){Es(this,"baseUrl");this.baseUrl=t}async get(t,n,r){const s=this.createUrl(t);return(await za.get(s,{...r,params:n})).data}async post(t,n,r){const s=this.createUrl(t);return(await za.post(s,n,r)).data}async put(t,n,r){const s=this.createUrl(t);return(await za.put(s,n,r)).data}async patch(t,n,r){const s=this.createUrl(t);return(await za.patch(s,n,r)).data}async delete(t,n){const r=this.createUrl(t);return(await za.delete(r,n)).data}createUrl(t){return this.baseUrl?`${this.baseUrl}${t}`:t}}class TB{set(t,n){try{const r=typeof n=="object"?JSON.stringify(n):String(n);localStorage.setItem(t,r)}catch(r){console.error(`Error setting localStorage key "${t}":`,r)}}get(t,n){try{const r=localStorage.getItem(t);if(r===null)return null;switch(n){case"boolean":return r==="true";case"json":{const s=JSON.parse(r);return typeof s=="object"?s:null}default:return r}}catch(r){return console.error(`Error getting localStorage key "${t}":`,r),null}}remove(t){try{localStorage.removeItem(t)}catch(n){console.error(`Error removing localStorage key "${t}":`,n)}}has(t){try{return localStorage.getItem(t)!==null}catch(n){return console.error(`Error checking localStorage key "${t}":`,n),!1}}clear(){try{localStorage.clear()}catch(t){console.error("Error clearing localStorage:",t)}}}const di=new TB;class jB{getTimezones(){return Intl.supportedValuesOf("timeZone")}getTimezonesWithOffset(){const t=this.getTimezones(),n=new Date;return t.map(r=>{const s=this.getTimezoneOffset(r,n),l=this.formatOffset(s),c=this.isDaylightSavingTime(r,n),d=this.getDisplayName(r,l);return{identifier:r,displayName:d,offsetMinutes:s,offsetString:l,isDST:c}})}getTimezoneOffset(t,n=new Date){try{const r=new Intl.DateTimeFormat("en-US",{timeZone:"UTC",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}),s=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}),l=new Date(r.format(n)),c=new Date(s.format(n));return Math.round((c.getTime()-l.getTime())/(1e3*60))}catch(r){return console.warn(`Failed to get offset for timezone ${t}:`,r),0}}formatOffset(t){const n=t>=0?"+":"-",r=Math.abs(t),s=Math.floor(r/60),l=r%60;return`${n}${s.toString().padStart(2,"0")}:${l.toString().padStart(2,"0")}`}isDaylightSavingTime(t,n=new Date){try{const r=new Date(n.getFullYear(),0,1),s=new Date(n.getFullYear(),6,1),l=this.getTimezoneOffset(t,r),c=this.getTimezoneOffset(t,s),d=this.getTimezoneOffset(t,n),h=Math.min(l,c);return d>h}catch(r){return console.warn(`Failed to check DST for timezone ${t}:`,r),!1}}getDisplayName(t,n){return`${t} (${n})`}getBrowserTimezone(){const t=Intl.DateTimeFormat().resolvedOptions().timeZone,n=new Date,r=this.getTimezoneOffset(t,n),s=this.formatOffset(r),l=this.isDaylightSavingTime(t,n),c=this.getDisplayName(t,s);return{identifier:t,displayName:c,offsetMinutes:r,offsetString:s,isDST:l}}getBrowserOffset(){return this.getBrowserTimezone().offsetMinutes}}const _B=new jB;function NB({isLoading:e,className:t}){const[n,r]=p.useState(0),[s,l]=p.useState(!1);return p.useEffect(()=>{let c,d;return e?(l(!0),r(0),c=setInterval(()=>{r(h=>h<90?h+(90-h)/10:h)},200)):(r(100),d=setTimeout(()=>{l(!1)},300)),()=>{clearInterval(c),clearTimeout(d)}},[e]),o.jsx("div",{className:fe("fixed top-0 right-0 left-0 z-50 h-1 transition-opacity duration-300",!s&&"opacity-0",t),children:o.jsx("div",{className:"bg-primary h-full transition-all duration-300 ease-out",style:{width:`${n.toString()}%`}})})}const jA=p.createContext({isLoading:!1});function AB({children:e}){const[t,n]=p.useState(0),r=t>0;return p.useEffect(()=>{const s=za.interceptors.request.use(c=>(c.skipLoadingIndicator||n(d=>d+1),c),c=>(c.config.skipLoadingIndicator||n(d=>Math.max(0,d-1)),Promise.reject(c))),l=za.interceptors.response.use(c=>(c.config.skipLoadingIndicator||n(d=>Math.max(0,d-1)),c),c=>(c.config.skipLoadingIndicator||n(d=>Math.max(0,d-1)),Promise.reject(c)));return()=>{za.interceptors.request.eject(s),za.interceptors.response.eject(l)}},[]),o.jsx(jA.Provider,{value:{isLoading:r},children:e})}function DB(){return p.useContext(jA)}function OB(){return o.jsx(J$,{position:"top-center",toastOptions:{duration:3e3,style:{borderRadius:"32px",boxShadow:"none",padding:"0.4rem 1rem",maxWidth:"800px",fontSize:"0.875rem",borderBottomWidth:"1px",borderBottomStyle:"solid"},success:{style:{background:"#ECFDF5",color:"#166534",borderBottomColor:"#D6DFE6"}},error:{style:{background:"#FEE2E2",color:"#991B1B",borderBottomColor:"#EAD1D1"},duration:6e3},loading:{style:{background:"#E8EDFB",color:"#1D4ED8",borderBottomColor:"#CAD5F6",borderBottomWidth:"1px",borderBottomStyle:"solid"}}}})}function MB({children:e}){const{isLoading:t}=iA(),n=mH(),r=rj(),s=jo();return p.useEffect(()=>{if(t)return;const l=r.projectId,c=n==null?void 0:n.projectId;if(l&&!s.pathname.startsWith("/auth")&&n&&c&&c!==l){const d=new URLSearchParams({projectId:l}).toString();window.location.href=`/auth/sign-in?${d}`}},[t,n,r.projectId,s.pathname]),o.jsx(o.Fragment,{children:e})}const k2="sidebar_state";function kB(){const{state:e,isMobile:t}=vf(),r=t||e==="collapsed",{isLoading:s}=DB();return o.jsxs(o.Fragment,{children:[o.jsx(OB,{}),o.jsx(NB,{isLoading:s}),o.jsxs(pH,{redirectTo:"/auth/sign-in",children:[o.jsx(wB,{variant:"inset",collapsible:"icon"}),o.jsxs(kU,{children:[r&&o.jsx(OU,{}),o.jsx(MB,{children:o.jsx(sj,{})})]})]})]})}function IB(){const[e,t]=p.useState(()=>di.get(k2,"boolean")??!0),n=r=>{t(r),di.set(k2,r)};return o.jsx(RB,{children:o.jsx(AB,{children:o.jsx(AU,{open:e,onOpenChange:n,children:o.jsx(kB,{})})})})}function LB(){return o.jsxs("div",{className:"app-container",children:[o.jsx("h1",{children:"About OWOX"}),o.jsx("p",{children:"OWOX Data Marts — Free, Open-Source Connectors for Data Analysts"})]})}function I2(){return o.jsxs("div",{className:"dm-empty-state-404page",children:[o.jsxs("div",{className:"dm-empty-state-404page-foreground",children:[o.jsx(SL,{className:"dm-empty-state-ico",strokeWidth:1}),o.jsx("h1",{className:"dm-empty-state-title",children:"Lost in the 404th Data Realm"}),o.jsxs("p",{className:"dm-empty-state-subtitle",children:["In this dimension, ",o.jsx("code",{children:"1+1=3"}),", percentages exceed 100%, and dashboards predict"," ",o.jsx("i",{children:"yesterday"}),".",o.jsx("br",{}),"Escape while you can!"]}),o.jsx(we,{variant:"default",asChild:!0,children:o.jsxs(Ni,{to:"/",className:"flex items-center gap-1","aria-label":"Guide Me Home",children:["Guide Me Home",o.jsx(_o,{className:"h-4 w-4"})]})})]}),o.jsx("div",{className:"dm-empty-state-404page-background"})]})}const PB={items:[],loading:!1,error:null};function UB(e,t){switch(t.type){case"SET_ITEMS":return{...e,items:t.payload,loading:!1,error:null};case"SET_LOADING":return{...e,loading:!0,error:null};case"SET_ERROR":return{...e,loading:!1,error:t.payload};default:return e}}const _A=p.createContext(void 0);function FB({children:e}){const[t,n]=p.useReducer(UB,PB);return o.jsx(_A.Provider,{value:{state:t,dispatch:n},children:e})}function zB(){const e=p.useContext(_A);if(e===void 0)throw new Error("useDataMartListContext must be used within a DataMartListProvider");return e}class VB extends kl{constructor(){super("/data-marts")}async getDataMarts(){return this.get("/")}async getDataMartById(t){return this.get(`/${t}`)}async createDataMart(t){return this.post("",t)}async updateDataMart(t,n){return this.patch(`/${t}`,n)}async deleteDataMart(t){return this.delete(`/${t}`)}async updateDataMartDescription(t,n){return this.put(`/${t}/description`,{description:n})}async updateDataMartTitle(t,n){return this.put(`/${t}/title`,{title:n})}async updateDataMartDefinition(t,n){return this.put(`/${t}/definition`,n,{timeout:18e4})}async publishDataMart(t){return this.put(`/${t}/publish`,void 0,{timeout:18e4})}async runDataMart(t,n){return this.post(`/${t}/manual-run`,{payload:n})}async cancelDataMartRun(t,n){await this.post(`/${t}/runs/${n}/cancel`)}async actualizeDataMartSchema(t){return this.post(`/${t}/actualize-schema`,void 0,{timeout:18e4})}async updateDataMartSchema(t,n){return this.put(`/${t}/schema`,n,{timeout:18e4})}async validateSql(t,n,r,s=!0){const l={sql:n},c={...r?{signal:r.signal}:{},skipLoadingIndicator:s,timeout:18e4};return this.post(`/${t}/sql-dry-run`,l,c)}async getDataMartRuns(t,n=5,r=0){return(await this.get(`/${t}/runs`,{limit:n,offset:r})).runs}}const vr=new VB;var lr=(e=>(e.DRAFT="DRAFT",e.PUBLISHED="PUBLISHED",e))(lr||{}),Qe=(e=>(e.SQL="SQL",e.TABLE="TABLE",e.VIEW="VIEW",e.TABLE_PATTERN="TABLE_PATTERN",e.CONNECTOR="CONNECTOR",e))(Qe||{}),Om=(e=>(e.ALREADY_PUBLISHED="ALREADY_PUBLISHED",e.INVALID_STORAGE="INVALID_STORAGE",e.MISSING_DEFINITION_TYPE="MISSING_DEFINITION_TYPE",e.MISSING_DEFINITION="MISSING_DEFINITION",e))(Om||{});const HB={ALREADY_PUBLISHED:"Data mart is already published",INVALID_STORAGE:"Data mart must have a valid storage",MISSING_DEFINITION_TYPE:"Data mart must have an input source configured",MISSING_DEFINITION:"Data mart must have a valid definition"},NA={statuses:{[lr.DRAFT]:{code:lr.DRAFT,displayName:"Draft",description:"Data mart is in draft mode and not yet published"},[lr.PUBLISHED]:{code:lr.PUBLISHED,displayName:"Published",description:"Data mart is published and available for use"}},getInfo(e){return this.statuses[e]},getAllStatuses(){return Object.values(this.statuses)}},AA=e=>e?/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+$/.test(e):!1,DA=e=>e?/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+\.[a-zA-Z0-9_\-*]+$/.test(e):!1,$B=e=>e?AA(e)?"":"Invalid format. Expected: project.dataset.object":"Fully qualified name is required",BB=e=>e?DA(e)?"":"Invalid format. Expected: project.dataset.table_* (with wildcards)":"Table pattern is required",OA=e=>{if(!e)return!1;const t=/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+$/,n=/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+$/;return t.test(e)||n.test(e)},MA=e=>{if(!e)return!1;const t=/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_\-*]+$/,n=/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+\.[a-zA-Z0-9_\-*]+$/;return t.test(e)||n.test(e)},GB=e=>e?OA(e)?"":"Invalid format. Expected: database.object or catalog.database.object":"Fully qualified name is required",qB=e=>e?MA(e)?"":"Invalid format. Expected: database.table_* or catalog.database.table_* (with wildcards)":"Table pattern is required",ZB=[{value:"US",label:"US (multiple regions)",group:"North America"},{value:"northamerica-northeast1",label:"northamerica-northeast1 (Montréal)",group:"North America"},{value:"northamerica-northeast2",label:"northamerica-northeast2 (Toronto)",group:"North America"},{value:"us-central1",label:"us-central1 (Iowa)",group:"North America"},{value:"us-east1",label:"us-east1 (South Carolina)",group:"North America"},{value:"us-east4",label:"us-east4 (Northern Virginia)",group:"North America"},{value:"us-east5",label:"us-east5 (Columbus)",group:"North America"},{value:"us-west1",label:"us-west1 (Oregon)",group:"North America"},{value:"us-west2",label:"us-west2 (Los Angeles)",group:"North America"},{value:"us-west3",label:"us-west3 (Salt Lake City)",group:"North America"},{value:"us-west4",label:"us-west4 (Las Vegas)",group:"North America"},{value:"EU",label:"EU (multiple regions)",group:"Europe"},{value:"europe-central2",label:"europe-central2 (Warsaw)",group:"Europe"},{value:"europe-north1",label:"europe-north1 (Finland)",group:"Europe"},{value:"europe-southwest1",label:"europe-southwest1 (Madrid)",group:"Europe"},{value:"europe-west1",label:"europe-west1 (Belgium)",group:"Europe"},{value:"europe-west2",label:"europe-west2 (London)",group:"Europe"},{value:"europe-west3",label:"europe-west3 (Frankfurt)",group:"Europe"},{value:"europe-west4",label:"europe-west4 (Netherlands)",group:"Europe"},{value:"europe-west6",label:"europe-west6 (Zurich)",group:"Europe"},{value:"europe-west8",label:"europe-west8 (Milan)",group:"Europe"},{value:"europe-west9",label:"europe-west9 (Paris)",group:"Europe"},{value:"europe-west12",label:"europe-west12 (Turin)",group:"Europe"},{value:"asia-east1",label:"asia-east1 (Taiwan)",group:"Asia Pacific"},{value:"asia-east2",label:"asia-east2 (Hong Kong)",group:"Asia Pacific"},{value:"asia-northeast1",label:"asia-northeast1 (Tokyo)",group:"Asia Pacific"},{value:"asia-northeast2",label:"asia-northeast2 (Osaka)",group:"Asia Pacific"},{value:"asia-northeast3",label:"asia-northeast3 (Seoul)",group:"Asia Pacific"},{value:"asia-south1",label:"asia-south1 (Mumbai)",group:"Asia Pacific"},{value:"asia-south2",label:"asia-south2 (Delhi)",group:"Asia Pacific"},{value:"asia-southeast1",label:"asia-southeast1 (Singapore)",group:"Asia Pacific"},{value:"asia-southeast2",label:"asia-southeast2 (Jakarta)",group:"Asia Pacific"},{value:"australia-southeast1",label:"australia-southeast1 (Sydney)",group:"Asia Pacific"},{value:"australia-southeast2",label:"australia-southeast2 (Melbourne)",group:"Asia Pacific"},{value:"southamerica-east1",label:"southamerica-east1 (São Paulo)",group:"Other"},{value:"southamerica-west1",label:"southamerica-west1 (Santiago)",group:"Other"},{value:"me-central1",label:"me-central1 (Doha)",group:"Other"},{value:"me-central2",label:"me-central2 (Dammam)",group:"Other"},{value:"me-west1",label:"me-west1 (Tel Aviv)",group:"Other"},{value:"africa-south1",label:"africa-south1 (Johannesburg)",group:"Other"}];function KB(e){return"projectId"in e}function YB(e){return"outputBucket"in e}var Pe=(e=>(e.GOOGLE_BIGQUERY="GOOGLE_BIGQUERY",e.AWS_ATHENA="AWS_ATHENA",e.SNOWFLAKE="SNOWFLAKE",e.DATABRICKS="DATABRICKS",e.AWS_REDSHIFT="AWS_REDSHIFT",e.AZURE_SYNAPSE="AZURE_SYNAPSE",e))(Pe||{}),po=(e=>(e.ACTIVE="active",e.COMING_SOON="coming_soon",e))(po||{});const QB=({label:e,value:t,truncate:n=!1})=>{const r=typeof t=="string"?t.trim():t,s=r==="";return o.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[o.jsxs("span",{className:"text-muted-foreground text-sm",children:[e,":"]}),n&&r&&!s?o.jsx("span",{className:"truncate text-sm",title:r,children:r.length>30?r.substring(0,30)+"...":r}):o.jsx("span",{className:"text-sm",children:s||r===void 0?o.jsx("span",{className:"text-muted-foreground",children:"—"}):r})]})},WB=({type:e,config:t})=>{const n={[Pe.GOOGLE_BIGQUERY]:[{label:"Project ID",key:"projectId"},{label:"Location",key:"location"}],[Pe.AWS_ATHENA]:[{label:"Region",key:"region"},{label:"Output Bucket",key:"outputBucket"}],[Pe.SNOWFLAKE]:[],[Pe.DATABRICKS]:[],[Pe.AWS_REDSHIFT]:[],[Pe.AZURE_SYNAPSE]:[]},r=t&&(e===Pe.GOOGLE_BIGQUERY&&KB(t)||e===Pe.AWS_ATHENA&&YB(t));return o.jsx("div",{className:"grid gap-2",children:n[e].map(({label:s,key:l})=>{let c;return r&&(c=(e===Pe.GOOGLE_BIGQUERY,t[l])),o.jsx(QB,{label:s,value:c},l)})})},XB=({type:e,config:t})=>o.jsx("div",{className:"space-y-4",children:o.jsxs("div",{className:"space-y-1",children:[o.jsx("h4",{className:"text-sm font-medium",children:"Configuration"}),o.jsx(WB,{type:e,config:t})]})}),JB=lf("inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",secondary:"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",destructive:"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"}},defaultVariants:{variant:"default"}});function Rr({className:e,variant:t,asChild:n=!1,...r}){const s=n?_p:"span";return o.jsx(s,{"data-slot":"badge",className:fe(JB({variant:t}),e),...r})}function kA(e){return e.type===Pe.GOOGLE_BIGQUERY}function IA(e){return e.type===Pe.AWS_ATHENA}const Ii={types:{[Pe.GOOGLE_BIGQUERY]:{type:Pe.GOOGLE_BIGQUERY,displayName:"Google BigQuery",icon:SH,status:po.ACTIVE},[Pe.AWS_ATHENA]:{type:Pe.AWS_ATHENA,displayName:"AWS Athena",icon:CH,status:po.ACTIVE},[Pe.SNOWFLAKE]:{type:Pe.SNOWFLAKE,displayName:"Snowflake",icon:RH,status:po.COMING_SOON},[Pe.DATABRICKS]:{type:Pe.DATABRICKS,displayName:"Databricks",icon:TH,status:po.COMING_SOON},[Pe.AWS_REDSHIFT]:{type:Pe.AWS_REDSHIFT,displayName:"AWS Redshift",icon:jH,status:po.COMING_SOON},[Pe.AZURE_SYNAPSE]:{type:Pe.AZURE_SYNAPSE,displayName:"Azure Synapse",icon:_H,status:po.COMING_SOON}},getInfo(e){return this.types[e]},getAllTypes(){return Object.values(this.types)}};function eG({dataStorage:e,isLoading:t=!1}){if(t)return o.jsx("div",{className:"space-y-4",children:o.jsx("div",{className:"grid gap-4",children:Array(4).fill(0).map((c,d)=>o.jsxs("div",{className:"space-y-1",children:[o.jsx(ir,{className:"h-5 w-24"}),o.jsx(ir,{className:"h-6 w-40"})]},d))})});if(!e)return o.jsx("div",{children:"No storage information available."});const{type:n,config:r,createdAt:s,modifiedAt:l}=e;return o.jsx("div",{className:"space-y-2",children:o.jsxs("div",{className:"grid gap-2",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("div",{children:e.title}),o.jsx(Rr,{variant:"secondary",className:"flex h-7 items-center gap-2",children:(()=>{const{displayName:c,icon:d}=Ii.getInfo(n);return o.jsxs(o.Fragment,{children:[o.jsx(d,{}),c]})})()})]}),o.jsx("div",{className:"bg-muted/10 rounded-md border p-4",children:o.jsx(XB,{type:n,config:r})}),o.jsxs("div",{className:"text-muted-foreground flex gap-6 text-xs",children:[o.jsxs("div",{children:[o.jsx("span",{className:"font-medium",children:"Created:"})," ",new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(s))]}),o.jsxs("div",{children:[o.jsx("span",{className:"font-medium",children:"Modified:"})," ",new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(l))]})]})]})})}function tG(e){const t=e.split(".");return t.length!==2?(console.error("Invalid fully qualified name format:",e),null):{dataset:t[0],table:t[1]}}function nG(e,t,n){const r=encodeURIComponent(e),s=encodeURIComponent(t),l=encodeURIComponent(n);return`https://console.cloud.google.com/bigquery?project=${r}&ws=!1m5!1m4!4m3!1s${r}!2s${s}!3s${l}`}function rG(e){return`https://console.aws.amazon.com/athena/home?region=${encodeURIComponent(e)}#/query-editor`}function aG(e,t){const n=tG(t);if(!n)return null;const{dataset:r,table:s}=n;return kA(e)?nG(e.config.projectId,r,s):IA(e)?rG(e.config.region):null}function sG(e,t){const n=aG(e,t);return n?(window.open(n,"_blank","noopener,noreferrer"),!0):!1}function oG(e){return kA(e)?"Open table in Google BigQuery":IA(e)?"Open region in AWS Athena":"Open data in storage"}const iG=en({accessKeyId:tn().min(1,"Access Key ID is required"),secretAccessKey:tn().min(1,"Secret Access Key is required")}),lG=en({projectId:tn().min(1,"Project ID is required"),location:tn().min(1,"Location is required")}),cG=en({region:tn().min(1,"Region is required"),outputBucket:tn().min(1,"Output Bucket is required")}),LA=en({title:tn().min(1,"Title is required").max(255,"Title must be 255 characters or less")}),uG=LA.extend({type:Vs(Pe.GOOGLE_BIGQUERY),credentials:gA,config:lG}),dG=LA.extend({type:Vs(Pe.AWS_ATHENA),credentials:iG,config:cG}),fG=pA("type",[uG,dG]),hG=(e,t)=>{if(!e)return!1;switch(t){case Pe.GOOGLE_BIGQUERY:return AA(e);case Pe.AWS_ATHENA:return OA(e);default:return!1}},mG=(e,t)=>{if(!e)return!1;switch(t){case Pe.GOOGLE_BIGQUERY:return DA(e);case Pe.AWS_ATHENA:return MA(e);default:return!1}},pG=(e,t)=>{if(!e)return"Fully qualified name is required";switch(t){case Pe.GOOGLE_BIGQUERY:return $B(e);case Pe.AWS_ATHENA:return GB(e);default:return"Unsupported storage type"}},gG=(e,t)=>{if(!e)return"Table pattern is required";switch(t){case Pe.GOOGLE_BIGQUERY:return BB(e);case Pe.AWS_ATHENA:return qB(e);default:return"Unsupported storage type"}},PA=e=>{switch(e){case Pe.GOOGLE_BIGQUERY:return"project.dataset.table";case Pe.AWS_ATHENA:return"database.table or catalog.database.table";default:return""}},vG=e=>{switch(e){case Pe.GOOGLE_BIGQUERY:return"project.dataset.table_*";case Pe.AWS_ATHENA:return"database.table_* or catalog.database.table_*";default:return""}},UA=e=>{switch(e){case Pe.GOOGLE_BIGQUERY:return"Enter the fully qualified name of the table (e.g., project.dataset.table)";case Pe.AWS_ATHENA:return"Enter the fully qualified name of the table (e.g., database.table or catalog.database.table)";default:return""}},yG=e=>{switch(e){case Pe.GOOGLE_BIGQUERY:return'Enter a pattern to match multiple tables (e.g., project.dataset.table_* will match all tables starting with "table_")';case Pe.AWS_ATHENA:return'Enter a pattern to match multiple tables (e.g., database.table_* will match all tables starting with "table_")';default:return""}};var Sn=(e=>(e.SUCCESS="success",e.ERROR="error",e.WARNING="warning",e.INFO="info",e.NEUTRAL="neutral",e))(Sn||{});const xG={solid:"px-2.5 py-0.5 rounded-full",subtle:"px-2.5 py-0.5 rounded-full",outline:"px-2.5 py-0.5 rounded-full border",ghost:""},bG=e=>xG[e],SG={[Sn.SUCCESS]:{icon:Np,colors:{solid:"bg-green-500 text-white",subtle:"bg-green-50 text-green-700 dark:bg-green-950 dark:text-green-400",outline:"border-green-500 text-green-700 dark:text-green-400",ghost:"text-green-500 dark:text-green-400"}},[Sn.ERROR]:{icon:eL,colors:{solid:"bg-red-500 text-white",subtle:"bg-red-50 text-red-700 dark:bg-red-950 dark:text-red-400",outline:"border-red-500 text-red-700 dark:text-red-400",ghost:"text-red-500 dark:text-red-400"}},[Sn.WARNING]:{icon:Dp,colors:{solid:"bg-yellow-500 text-white",subtle:"bg-yellow-50 text-yellow-700 dark:bg-yellow-950 dark:text-yellow-400",outline:"border-yellow-500 text-yellow-700 dark:text-yellow-400",ghost:"text-yellow-500 dark:text-yellow-400"}},[Sn.INFO]:{icon:Xr,colors:{solid:"bg-blue-500 text-white",subtle:"bg-blue-50 text-blue-700 dark:bg-blue-950 dark:text-blue-400",outline:"border-blue-500 text-blue-700 dark:text-blue-400",ghost:"text-blue-500 dark:text-blue-400"}},[Sn.NEUTRAL]:{icon:Xr,colors:{solid:"bg-gray-500 text-white",subtle:"bg-gray-50 text-gray-700 dark:bg-gray-950 dark:text-gray-400",outline:"border-gray-500 text-gray-700 dark:text-gray-400",ghost:"text-muted-foreground"}}};function _f({type:e=Sn.NEUTRAL,variant:t="ghost",showIcon:n=!0,children:r,className:s}){const{icon:l,colors:c}=SG[e],d=h=>{const m="inline-flex items-center gap-1 text-sm",g=bG(h),v=c[h];return fe(m,g,v,s)};return o.jsxs("span",{className:d(t),children:[n&&o.jsx(l,{className:"h-4 w-4","data-testid":"icon"}),r]})}var Lr=(e=>(e.INFO="INFO",e.WARNING="WARNING",e.ERROR="ERROR",e.SYSTEM="SYSTEM",e))(Lr||{}),Cn=(e=>(e.RUNNING="RUNNING",e.SUCCESS="SUCCESS",e.FAILED="FAILED",e.CANCELLED="CANCELLED",e.INTERRUPTED="INTERRUPTED",e))(Cn||{}),es=(e=>(e.STRUCTURED="structured",e.RAW="raw",e.CONFIGURATION="configuration",e))(es||{});const L2=(e,t,n=!1)=>{var c,d;const r=e.split(`
|
|
662
662
|
`).filter(h=>h.trim()!=="");if(r.length>=3){const h=r[0],m=r[1],g=r.slice(2).join(`
|
|
663
663
|
`);if(h.includes("T")&&h.includes("Z")){const v=px(g);return{id:`log-${t.toString()}`,timestamp:h,level:n?Lr.ERROR:Lr.INFO,message:v.message,metadata:{at:((c=v.metadata)==null?void 0:c.at)??h,type:((d=v.metadata)==null?void 0:d.type)??(m!=="unknown"?m:null)}}}}const s=/^\[(.*?)\]\s*\[(.*?)\]\s*(.*)$/.exec(e);if(s){const h=px(s[3]);return{id:`log-${t.toString()}`,timestamp:s[1],level:n?Lr.ERROR:s[2],message:h.message,metadata:h.metadata}}const l=px(e);return{id:`log-${t.toString()}`,timestamp:new Date().toISOString(),level:n?Lr.ERROR:Lr.INFO,message:l.message,metadata:l.metadata}},px=e=>{try{const t=JSON.parse(e);if(typeof t=="object"){const n={},r={...t};"type"in r&&(n.type=r.type,delete r.type),"at"in r&&(n.at=r.at,delete r.at);const s=Object.keys(r);if(s.length===1){const l=s[0],c=r[l];return{message:typeof c=="string"?c:JSON.stringify(c),metadata:Object.keys(n).length>0?n:void 0}}return{message:JSON.stringify(r,null,2),metadata:Object.keys(n).length>0?n:void 0}}}catch{}return{message:e}},b0=e=>{const t=new Date(e),n=String(t.getFullYear()),r=String(t.getMonth()+1).padStart(2,"0"),s=String(t.getDate()).padStart(2,"0"),l=String(t.getHours()).padStart(2,"0"),c=String(t.getMinutes()).padStart(2,"0"),d=String(t.getSeconds()).padStart(2,"0");return`${n}-${r}-${s} ${l}:${c}:${d}`},CG=e=>{var t;return(t=e.metadata)!=null&&t.at?b0(e.metadata.at):b0(e.timestamp)},FA=e=>{var t;return(t=e.metadata)!=null&&t.type?e.metadata.type:e.level},EG=e=>{const t=e.logs.length,n=e.errors.length,r=t+n,s=[`Run #${e.id.slice(-8)}`,`${String(r)} messages`];return n>0&&s.push(`${String(n)} errors`),s.join(" • ")},wG=e=>{const t=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),n=URL.createObjectURL(t),r=document.createElement("a");r.href=n,r.download=`datamart-run-${e.id.slice(0,8)}-logs.json`,r.click(),URL.revokeObjectURL(n)};function RG(e){return o.jsx("div",{className:"flex items-center gap-2",children:(()=>{switch(e){case Cn.SUCCESS:return o.jsx(gj,{className:"h-4 w-4 text-green-500"});case Cn.FAILED:return o.jsx(Ap,{className:"h-4 w-4 text-red-500"});case Cn.RUNNING:return o.jsx(su,{className:"text-primary h-4 w-4 animate-spin"});case Cn.CANCELLED:return o.jsx(z6,{className:"h-4 w-4 text-gray-500"});case Cn.INTERRUPTED:return o.jsx(o8,{className:"h-4 w-4 text-gray-500"});default:return o.jsx(c8,{className:"h-4 w-4 text-gray-500"})}})()})}function TG(e){switch(e){case Lr.INFO:return o.jsx(Xr,{className:"h-3 w-3 text-blue-500"});case Lr.WARNING:return o.jsx(Dp,{className:"h-3 w-3 text-yellow-500"});case Lr.ERROR:return o.jsx(Ap,{className:"h-3 w-3 text-red-500"});case Lr.SYSTEM:return o.jsx(au,{className:"text-muted-foreground h-3 w-3"});default:return o.jsx(Xr,{className:"text-muted-foreground h-3 w-3"})}}function jG(e){switch(e){case Lr.INFO:return"text-blue-600 dark:text-blue-400";case Lr.WARNING:return"text-yellow-600 dark:text-yellow-400";case Lr.ERROR:return"text-red-600 dark:text-red-400";case Lr.SYSTEM:return"text-muted-foreground";default:return"text-muted-foreground"}}function _G({status:e}){switch(e){case Cn.RUNNING:return o.jsx(Rr,{variant:"secondary",className:"text-primary bg-primary/10",children:"Running"});case Cn.SUCCESS:return o.jsx(Rr,{variant:"secondary",className:"bg-green-50 text-green-600 dark:bg-green-950 dark:text-green-400",children:"Success"});case Cn.FAILED:return o.jsx(Rr,{variant:"secondary",className:"bg-red-50 text-red-600 dark:bg-red-950 dark:text-red-400",children:"Failed"});case Cn.CANCELLED:return o.jsx(Rr,{variant:"secondary",className:"bg-gray-50 text-gray-500 dark:bg-gray-950 dark:text-gray-400",children:"Cancelled"});case Cn.INTERRUPTED:return o.jsx(Rr,{variant:"secondary",className:"bg-gray-50 text-gray-500 dark:bg-gray-950 dark:text-gray-400",children:"Interrupted"});default:return o.jsx(Rr,{variant:"secondary",className:"bg-gray-50 text-gray-500 dark:bg-gray-950 dark:text-gray-400",children:"Unknown"})}}function NG({logViewType:e,setLogViewType:t,searchTerm:n,setSearchTerm:r,run:s,cancelDataMartRun:l,dataMartId:c}){const d=g=>{g.stopPropagation()},h=async g=>{if(g.stopPropagation(),c)try{await l(c,s.id),Jt.success("Data mart run cancelled successfully")}catch(v){Jt.error(v instanceof Error?v.message:"Failed to cancel data mart run")}},m=g=>`px-3 py-2 text-sm font-medium transition-colors rounded-none ${g?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground hover:bg-accent"}`;return o.jsxs("div",{className:"bg-background border-border flex items-center justify-between rounded-lg border p-3",children:[o.jsxs("div",{className:"flex items-center gap-4",children:[o.jsxs("div",{className:"bg-background border-border flex items-center rounded-lg border",children:[o.jsx("button",{onClick:g=>{g.stopPropagation(),t(es.STRUCTURED)},className:`${m(e===es.STRUCTURED)} rounded-l-lg`,children:"Structured"}),o.jsx("button",{onClick:g=>{g.stopPropagation(),t(es.RAW)},className:`${m(e===es.RAW)} rounded-none`,children:"Raw"}),o.jsx("button",{onClick:g=>{g.stopPropagation(),t(es.CONFIGURATION)},className:`${m(e===es.CONFIGURATION)} rounded-r-lg`,children:"Configuration"})]}),e!==es.CONFIGURATION&&o.jsxs("div",{className:"relative",children:[o.jsx(_l,{className:"text-muted-foreground absolute top-2.5 left-2 h-4 w-4"}),o.jsx(Zt,{type:"text",placeholder:"Search logs...",value:n,onChange:g=>{r(g.target.value)},onClick:d,className:"border-input bg-background text-foreground placeholder:text-muted-foreground focus:ring-ring rounded-md border py-2 pr-4 pl-8 text-xs focus:border-transparent focus:ring-2 focus:outline-none"})]})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[s.status===Cn.RUNNING&&o.jsxs(we,{variant:"destructive",size:"sm",onClick:g=>void h(g),children:[o.jsx(Bd,{className:"h-4 w-4"}),"Cancel"]}),o.jsxs(we,{variant:"outline",size:"sm",onClick:g=>{g.stopPropagation(),wG(s)},className:"flex items-center gap-2",children:[o.jsx(y8,{className:"h-4 w-4"}),"JSON"]})]})]})}function AG({logs:e}){const t=n=>{n.stopPropagation()};return e.length===0?o.jsx("div",{className:"bg-background border-border rounded-lg border",children:o.jsx("div",{className:"text-muted-foreground p-8 text-center",children:"No logs found"})}):o.jsx("div",{className:"bg-background border-border rounded-lg border",children:o.jsx("div",{className:"max-h-96 overflow-y-auto",children:e.map((n,r)=>o.jsxs("div",{className:`border-border hover:bg-accent/30 flex items-start gap-3 border-b p-3 text-sm text-xs ${r===e.length-1?"border-b-0":""}`,onClick:t,children:[o.jsx("div",{className:"text-muted-foreground flex-shrink-0 font-mono text-xs",children:CG(n)}),o.jsxs("div",{className:"flex min-w-0 flex-shrink-0 items-center gap-2",children:[TG(n.level),o.jsx("span",{className:`text-xs font-medium ${jG(n.level)}`,children:FA(n)})]}),o.jsx("div",{className:`min-w-0 flex-1 text-xs break-words ${n.level===Lr.ERROR?"text-red-700 dark:text-red-300":"text-foreground"}`,children:n.message.includes(`
|
|
664
664
|
`)?o.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap",children:n.message}):o.jsx("span",{children:n.message})})]},n.id))})})}var up=(e=>(e.ERROR="error",e.DEFAULT="default",e))(up||{});function dp({text:e,section:t,variant:n="default",copiedSection:r,onCopy:s,iconOnly:l=!1}){const c=n==="error",d=r===t,h="flex items-center gap-1 px-2 py-1 text-xs rounded transition-colors cursor-pointer",m=c?"text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-950/40":"text-foreground hover:bg-muted";return o.jsx("button",{onClick:g=>{s(e,t),g.stopPropagation()},className:`${h} ${m}`,title:`Copy ${t} to clipboard`,children:l?o.jsx(o.Fragment,{children:d?o.jsx(yr,{className:"h-3 w-3"}):o.jsx($d,{className:"h-3 w-3"})}):d?o.jsxs(o.Fragment,{children:[o.jsx(yr,{className:"h-3 w-3"}),"Copied"]}):o.jsxs(o.Fragment,{children:[o.jsx($d,{className:"h-3 w-3"}),"Copy"]})})}function Zb(){const[e,t]=p.useState(null),n=async(s,l)=>{try{await navigator.clipboard.writeText(s),t(l),setTimeout(()=>{t(null)},2e3)}catch(c){console.error("Failed to copy text: ",c)}};return{copiedSection:e,copyToClipboard:n,handleCopy:(s,l)=>{n(s,l)}}}function DG({logs:e,errors:t}){const{copiedSection:n,handleCopy:r}=Zb(),s=l=>{l.stopPropagation()};return o.jsxs("div",{className:"border-border space-y-4 rounded-lg border p-4",onClick:s,children:[t.length>0&&o.jsxs("div",{children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[o.jsxs("h4",{className:"flex items-center gap-2 text-sm font-medium text-red-600 dark:text-red-400",children:[o.jsx(au,{className:"h-4 w-4 text-red-500"}),"Error Output:"]}),o.jsx(dp,{text:t.join(`
|
|
@@ -700,7 +700,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
700
700
|
monaco.config({ paths: { vs: '...' } })
|
|
701
701
|
|
|
702
702
|
For more please check the link https://github.com/suren-atoyan/monaco-loader#config
|
|
703
|
-
`},lT=DQ(IQ)(_D),LQ={config:MQ},PQ=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return function(s){return n.reduceRight(function(l,c){return c(l)},s)}};function ND(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],ND(e[n],t[n]))}),aT(aT({},e),t)}var UQ={type:"cancelation",msg:"operation is manually canceled"};function jx(e){var t=!1,n=new Promise(function(r,s){e.then(function(l){return t?s(UQ):r(l)}),e.catch(s)});return n.cancel=function(){return t=!0},n}var FQ=NQ.create({config:AQ,isInitialized:!1,resolve:null,reject:null,monaco:null}),AD=uQ(FQ,2),kf=AD[0],bg=AD[1];function zQ(e){var t=LQ.config(e),n=t.monaco,r=cQ(t,["monaco"]);bg(function(s){return{config:ND(s.config,r),monaco:n}})}function VQ(){var e=kf(function(t){var n=t.monaco,r=t.isInitialized,s=t.resolve;return{monaco:n,isInitialized:r,resolve:s}});if(!e.isInitialized){if(bg({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),jx(_x);if(window.monaco&&window.monaco.editor)return DD(window.monaco),e.resolve(window.monaco),jx(_x);PQ(HQ,BQ)(GQ)}return jx(_x)}function HQ(e){return document.body.appendChild(e)}function $Q(e){var t=document.createElement("script");return e&&(t.src=e),t}function BQ(e){var t=kf(function(r){var s=r.config,l=r.reject;return{config:s,reject:l}}),n=$Q("".concat(t.config.paths.vs,"/loader.js"));return n.onload=function(){return e()},n.onerror=t.reject,n}function GQ(){var e=kf(function(n){var r=n.config,s=n.resolve,l=n.reject;return{config:r,resolve:s,reject:l}}),t=window.require;t.config(e.config),t(["vs/editor/editor.main"],function(n){DD(n),e.resolve(n)},function(n){e.reject(n)})}function DD(e){kf().monaco||bg({monaco:e})}function qQ(){return kf(function(e){var t=e.monaco;return t})}var _x=new Promise(function(e,t){return bg({resolve:e,reject:t})}),OD={config:zQ,init:VQ,__getMonacoInstance:qQ},ZQ={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},Nx=ZQ,KQ={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},YQ=KQ;function QQ({children:e}){return _e.createElement("div",{style:YQ.container},e)}var WQ=QQ,XQ=WQ;function JQ({width:e,height:t,isEditorReady:n,loading:r,_ref:s,className:l,wrapperProps:c}){return _e.createElement("section",{style:{...Nx.wrapper,width:e,height:t},...c},!n&&_e.createElement(XQ,null,r),_e.createElement("div",{ref:s,style:{...Nx.fullWidth,...!n&&Nx.hide},className:l}))}var eW=JQ,MD=p.memo(eW);function tW(e){p.useEffect(e,[])}var kD=tW;function nW(e,t,n=!0){let r=p.useRef(!0);p.useEffect(r.current||!n?()=>{r.current=!1}:e,t)}var da=nW;function Ld(){}function Pc(e,t,n,r){return rW(e,r)||aW(e,t,n,r)}function rW(e,t){return e.editor.getModel(ID(e,t))}function aW(e,t,n,r){return e.editor.createModel(t,n,r?ID(e,r):void 0)}function ID(e,t){return e.Uri.parse(t)}function sW({original:e,modified:t,language:n,originalLanguage:r,modifiedLanguage:s,originalModelPath:l,modifiedModelPath:c,keepCurrentOriginalModel:d=!1,keepCurrentModifiedModel:h=!1,theme:m="light",loading:g="Loading...",options:v={},height:x="100%",width:b="100%",className:E,wrapperProps:C={},beforeMount:w=Ld,onMount:R=Ld}){let[T,j]=p.useState(!1),[O,D]=p.useState(!0),N=p.useRef(null),A=p.useRef(null),k=p.useRef(null),U=p.useRef(R),B=p.useRef(w),H=p.useRef(!1);kD(()=>{let W=OD.init();return W.then(I=>(A.current=I)&&D(!1)).catch(I=>(I==null?void 0:I.type)!=="cancelation"&&console.error("Monaco initialization: error:",I)),()=>N.current?G():W.cancel()}),da(()=>{if(N.current&&A.current){let W=N.current.getOriginalEditor(),I=Pc(A.current,e||"",r||n||"text",l||"");I!==W.getModel()&&W.setModel(I)}},[l],T),da(()=>{if(N.current&&A.current){let W=N.current.getModifiedEditor(),I=Pc(A.current,t||"",s||n||"text",c||"");I!==W.getModel()&&W.setModel(I)}},[c],T),da(()=>{let W=N.current.getModifiedEditor();W.getOption(A.current.editor.EditorOption.readOnly)?W.setValue(t||""):t!==W.getValue()&&(W.executeEdits("",[{range:W.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),W.pushUndoStop())},[t],T),da(()=>{var W,I;(I=(W=N.current)==null?void 0:W.getModel())==null||I.original.setValue(e||"")},[e],T),da(()=>{let{original:W,modified:I}=N.current.getModel();A.current.editor.setModelLanguage(W,r||n||"text"),A.current.editor.setModelLanguage(I,s||n||"text")},[n,r,s],T),da(()=>{var W;(W=A.current)==null||W.editor.setTheme(m)},[m],T),da(()=>{var W;(W=N.current)==null||W.updateOptions(v)},[v],T);let Q=p.useCallback(()=>{var Y;if(!A.current)return;B.current(A.current);let W=Pc(A.current,e||"",r||n||"text",l||""),I=Pc(A.current,t||"",s||n||"text",c||"");(Y=N.current)==null||Y.setModel({original:W,modified:I})},[n,t,s,e,r,l,c]),ne=p.useCallback(()=>{var W;!H.current&&k.current&&(N.current=A.current.editor.createDiffEditor(k.current,{automaticLayout:!0,...v}),Q(),(W=A.current)==null||W.editor.setTheme(m),j(!0),H.current=!0)},[v,m,Q]);p.useEffect(()=>{T&&U.current(N.current,A.current)},[T]),p.useEffect(()=>{!O&&!T&&ne()},[O,T,ne]);function G(){var I,Y,q,oe;let W=(I=N.current)==null?void 0:I.getModel();d||((Y=W==null?void 0:W.original)==null||Y.dispose()),h||((q=W==null?void 0:W.modified)==null||q.dispose()),(oe=N.current)==null||oe.dispose()}return _e.createElement(MD,{width:b,height:x,isEditorReady:T,loading:g,_ref:k,className:E,wrapperProps:C})}var oW=sW;p.memo(oW);function iW(e){let t=p.useRef();return p.useEffect(()=>{t.current=e},[e]),t.current}var lW=iW,vm=new Map;function cW({defaultValue:e,defaultLanguage:t,defaultPath:n,value:r,language:s,path:l,theme:c="light",line:d,loading:h="Loading...",options:m={},overrideServices:g={},saveViewState:v=!0,keepCurrentModel:x=!1,width:b="100%",height:E="100%",className:C,wrapperProps:w={},beforeMount:R=Ld,onMount:T=Ld,onChange:j,onValidate:O=Ld}){let[D,N]=p.useState(!1),[A,k]=p.useState(!0),U=p.useRef(null),B=p.useRef(null),H=p.useRef(null),Q=p.useRef(T),ne=p.useRef(R),G=p.useRef(),W=p.useRef(r),I=lW(l),Y=p.useRef(!1),q=p.useRef(!1);kD(()=>{let L=OD.init();return L.then(P=>(U.current=P)&&k(!1)).catch(P=>(P==null?void 0:P.type)!=="cancelation"&&console.error("Monaco initialization: error:",P)),()=>B.current?be():L.cancel()}),da(()=>{var P,Z,re,de;let L=Pc(U.current,e||r||"",t||s||"",l||n||"");L!==((P=B.current)==null?void 0:P.getModel())&&(v&&vm.set(I,(Z=B.current)==null?void 0:Z.saveViewState()),(re=B.current)==null||re.setModel(L),v&&((de=B.current)==null||de.restoreViewState(vm.get(l))))},[l],D),da(()=>{var L;(L=B.current)==null||L.updateOptions(m)},[m],D),da(()=>{!B.current||r===void 0||(B.current.getOption(U.current.editor.EditorOption.readOnly)?B.current.setValue(r):r!==B.current.getValue()&&(q.current=!0,B.current.executeEdits("",[{range:B.current.getModel().getFullModelRange(),text:r,forceMoveMarkers:!0}]),B.current.pushUndoStop(),q.current=!1))},[r],D),da(()=>{var P,Z;let L=(P=B.current)==null?void 0:P.getModel();L&&s&&((Z=U.current)==null||Z.editor.setModelLanguage(L,s))},[s],D),da(()=>{var L;d!==void 0&&((L=B.current)==null||L.revealLine(d))},[d],D),da(()=>{var L;(L=U.current)==null||L.editor.setTheme(c)},[c],D);let oe=p.useCallback(()=>{var L;if(!(!H.current||!U.current)&&!Y.current){ne.current(U.current);let P=l||n,Z=Pc(U.current,r||e||"",t||s||"",P||"");B.current=(L=U.current)==null?void 0:L.editor.create(H.current,{model:Z,automaticLayout:!0,...m},g),v&&B.current.restoreViewState(vm.get(P)),U.current.editor.setTheme(c),d!==void 0&&B.current.revealLine(d),N(!0),Y.current=!0}},[e,t,n,r,s,l,m,g,v,c,d]);p.useEffect(()=>{D&&Q.current(B.current,U.current)},[D]),p.useEffect(()=>{!A&&!D&&oe()},[A,D,oe]),W.current=r,p.useEffect(()=>{var L,P;D&&j&&((L=G.current)==null||L.dispose(),G.current=(P=B.current)==null?void 0:P.onDidChangeModelContent(Z=>{q.current||j(B.current.getValue(),Z)}))},[D,j]),p.useEffect(()=>{if(D){let L=U.current.editor.onDidChangeMarkers(P=>{var re;let Z=(re=B.current.getModel())==null?void 0:re.uri;if(Z&&P.find(de=>de.path===Z.path)){let de=U.current.editor.getModelMarkers({resource:Z});O==null||O(de)}});return()=>{L==null||L.dispose()}}return()=>{}},[D,O]);function be(){var L,P;(L=G.current)==null||L.dispose(),x?v&&vm.set(l,B.current.saveViewState()):(P=B.current.getModel())==null||P.dispose(),B.current.dispose()}return _e.createElement(MD,{width:b,height:E,isEditorReady:D,loading:h,_ref:H,className:C,wrapperProps:w})}var uW=cW,dW=p.memo(uW);function fW({initialValue:e,onChange:t}){const[n,r]=p.useState((e==null?void 0:e.sqlQuery)??""),{theme:s}=TA();p.useEffect(()=>{e!=null&&e.sqlQuery&&e.sqlQuery!==n&&r(e.sqlQuery)},[e,n]);function l(c){c!==void 0&&(r(c),t({sqlQuery:c}))}return o.jsx("div",{className:"shadow-xs",children:o.jsx(dW,{className:"overflow-hidden rounded-md border border-gray-200 dark:border-gray-200/4",height:"30vh",language:"sql",value:n,onChange:l,theme:s==="dark"?"vs-dark":"light",options:{selectOnLineNumbers:!0,hideCursorInOverviewRuler:!0,minimap:{enabled:!1},scrollBeyondLastLine:!1,overviewRulerBorder:!1}})})}function k0({icon:e,title:t,subtitle:n,rightContent:r,onClick:s,className:l}){const c=e;return o.jsxs("div",{className:fe("group flex items-center gap-4 rounded-md border-b border-gray-200 bg-white transition-shadow duration-200 hover:shadow-xs dark:border-0 dark:bg-white/2",s&&"cursor-pointer dark:hover:bg-white/5",l),onClick:s,children:[o.jsxs("div",{className:"flex flex-grow items-start justify-center gap-3 px-6 py-5",children:[e&&o.jsx("div",{className:"flex items-center justify-center",children:o.jsx(c,{className:"h-6 w-6"})}),o.jsxs("div",{className:"flex flex-grow flex-col gap-1",children:[o.jsx("div",{className:"text-md font-medium",children:t}),n&&o.jsx("div",{className:"text-muted-foreground/60 text-sm",children:n})]})]}),o.jsxs("div",{className:"flex items-center justify-center gap-2 p-4",children:[r,s&&o.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full transition-colors duration-200 group-hover:bg-gray-200/50 dark:group-hover:bg-white/4",children:o.jsx(_o,{className:"text-muted-foreground/75 dark:text-muted-foreground/50 h-4 w-4"})})]})]})}var cT=1,hW=.9,mW=.8,pW=.17,Ax=.1,Dx=.999,gW=.9999,vW=.99,yW=/[\\\/_+.#"@\[\(\{&]/,xW=/[\\\/_+.#"@\[\(\{&]/g,bW=/[\s-]/,LD=/[\s-]/g;function I0(e,t,n,r,s,l,c){if(l===t.length)return s===e.length?cT:vW;var d=`${s},${l}`;if(c[d]!==void 0)return c[d];for(var h=r.charAt(l),m=n.indexOf(h,s),g=0,v,x,b,E;m>=0;)v=I0(e,t,n,r,m+1,l+1,c),v>g&&(m===s?v*=cT:yW.test(e.charAt(m-1))?(v*=mW,b=e.slice(s,m-1).match(xW),b&&s>0&&(v*=Math.pow(Dx,b.length))):bW.test(e.charAt(m-1))?(v*=hW,E=e.slice(s,m-1).match(LD),E&&s>0&&(v*=Math.pow(Dx,E.length))):(v*=pW,s>0&&(v*=Math.pow(Dx,m-s))),e.charAt(m)!==t.charAt(l)&&(v*=gW)),(v<Ax&&n.charAt(m-1)===r.charAt(l+1)||r.charAt(l+1)===r.charAt(l)&&n.charAt(m-1)!==r.charAt(l))&&(x=I0(e,t,n,r,m+1,l+2,c),x*Ax>v&&(v=x*Ax)),v>g&&(g=v),m=n.indexOf(h,m+1);return c[d]=g,g}function uT(e){return e.toLowerCase().replace(LD," ")}function SW(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,I0(e,t,uT(e),uT(t),0,0,{})}var Rd='[cmdk-group=""]',Ox='[cmdk-group-items=""]',CW='[cmdk-group-heading=""]',PD='[cmdk-item=""]',dT=`${PD}:not([aria-disabled="true"])`,L0="cmdk-item-select",kc="data-value",EW=(e,t,n)=>SW(e,t,n),UD=p.createContext(void 0),If=()=>p.useContext(UD),FD=p.createContext(void 0),RS=()=>p.useContext(FD),zD=p.createContext(void 0),VD=p.forwardRef((e,t)=>{let n=Ic(()=>{var P,Z;return{search:"",value:(Z=(P=e.value)!=null?P:e.defaultValue)!=null?Z:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=Ic(()=>new Set),s=Ic(()=>new Map),l=Ic(()=>new Map),c=Ic(()=>new Set),d=HD(e),{label:h,children:m,value:g,onValueChange:v,filter:x,shouldFilter:b,loop:E,disablePointerSelection:C=!1,vimBindings:w=!0,...R}=e,T=Mn(),j=Mn(),O=Mn(),D=p.useRef(null),N=kW();Tl(()=>{if(g!==void 0){let P=g.trim();n.current.value=P,A.emit()}},[g]),Tl(()=>{N(6,ne)},[]);let A=p.useMemo(()=>({subscribe:P=>(c.current.add(P),()=>c.current.delete(P)),snapshot:()=>n.current,setState:(P,Z,re)=>{var de,ge,ce,Ae;if(!Object.is(n.current[P],Z)){if(n.current[P]=Z,P==="search")Q(),B(),N(1,H);else if(P==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let Re=document.getElementById(O);Re?Re.focus():(de=document.getElementById(T))==null||de.focus()}if(N(7,()=>{var Re;n.current.selectedItemId=(Re=G())==null?void 0:Re.id,A.emit()}),re||N(5,ne),((ge=d.current)==null?void 0:ge.value)!==void 0){let Re=Z??"";(Ae=(ce=d.current).onValueChange)==null||Ae.call(ce,Re);return}}A.emit()}},emit:()=>{c.current.forEach(P=>P())}}),[]),k=p.useMemo(()=>({value:(P,Z,re)=>{var de;Z!==((de=l.current.get(P))==null?void 0:de.value)&&(l.current.set(P,{value:Z,keywords:re}),n.current.filtered.items.set(P,U(Z,re)),N(2,()=>{B(),A.emit()}))},item:(P,Z)=>(r.current.add(P),Z&&(s.current.has(Z)?s.current.get(Z).add(P):s.current.set(Z,new Set([P]))),N(3,()=>{Q(),B(),n.current.value||H(),A.emit()}),()=>{l.current.delete(P),r.current.delete(P),n.current.filtered.items.delete(P);let re=G();N(4,()=>{Q(),(re==null?void 0:re.getAttribute("id"))===P&&H(),A.emit()})}),group:P=>(s.current.has(P)||s.current.set(P,new Set),()=>{l.current.delete(P),s.current.delete(P)}),filter:()=>d.current.shouldFilter,label:h||e["aria-label"],getDisablePointerSelection:()=>d.current.disablePointerSelection,listId:T,inputId:O,labelId:j,listInnerRef:D}),[]);function U(P,Z){var re,de;let ge=(de=(re=d.current)==null?void 0:re.filter)!=null?de:EW;return P?ge(P,n.current.search,Z):0}function B(){if(!n.current.search||d.current.shouldFilter===!1)return;let P=n.current.filtered.items,Z=[];n.current.filtered.groups.forEach(de=>{let ge=s.current.get(de),ce=0;ge.forEach(Ae=>{let Re=P.get(Ae);ce=Math.max(Re,ce)}),Z.push([de,ce])});let re=D.current;W().sort((de,ge)=>{var ce,Ae;let Re=de.getAttribute("id"),xe=ge.getAttribute("id");return((ce=P.get(xe))!=null?ce:0)-((Ae=P.get(Re))!=null?Ae:0)}).forEach(de=>{let ge=de.closest(Ox);ge?ge.appendChild(de.parentElement===ge?de:de.closest(`${Ox} > *`)):re.appendChild(de.parentElement===re?de:de.closest(`${Ox} > *`))}),Z.sort((de,ge)=>ge[1]-de[1]).forEach(de=>{var ge;let ce=(ge=D.current)==null?void 0:ge.querySelector(`${Rd}[${kc}="${encodeURIComponent(de[0])}"]`);ce==null||ce.parentElement.appendChild(ce)})}function H(){let P=W().find(re=>re.getAttribute("aria-disabled")!=="true"),Z=P==null?void 0:P.getAttribute(kc);A.setState("value",Z||void 0)}function Q(){var P,Z,re,de;if(!n.current.search||d.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let ge=0;for(let ce of r.current){let Ae=(Z=(P=l.current.get(ce))==null?void 0:P.value)!=null?Z:"",Re=(de=(re=l.current.get(ce))==null?void 0:re.keywords)!=null?de:[],xe=U(Ae,Re);n.current.filtered.items.set(ce,xe),xe>0&&ge++}for(let[ce,Ae]of s.current)for(let Re of Ae)if(n.current.filtered.items.get(Re)>0){n.current.filtered.groups.add(ce);break}n.current.filtered.count=ge}function ne(){var P,Z,re;let de=G();de&&(((P=de.parentElement)==null?void 0:P.firstChild)===de&&((re=(Z=de.closest(Rd))==null?void 0:Z.querySelector(CW))==null||re.scrollIntoView({block:"nearest"})),de.scrollIntoView({block:"nearest"}))}function G(){var P;return(P=D.current)==null?void 0:P.querySelector(`${PD}[aria-selected="true"]`)}function W(){var P;return Array.from(((P=D.current)==null?void 0:P.querySelectorAll(dT))||[])}function I(P){let Z=W()[P];Z&&A.setState("value",Z.getAttribute(kc))}function Y(P){var Z;let re=G(),de=W(),ge=de.findIndex(Ae=>Ae===re),ce=de[ge+P];(Z=d.current)!=null&&Z.loop&&(ce=ge+P<0?de[de.length-1]:ge+P===de.length?de[0]:de[ge+P]),ce&&A.setState("value",ce.getAttribute(kc))}function q(P){let Z=G(),re=Z==null?void 0:Z.closest(Rd),de;for(;re&&!de;)re=P>0?OW(re,Rd):MW(re,Rd),de=re==null?void 0:re.querySelector(dT);de?A.setState("value",de.getAttribute(kc)):Y(P)}let oe=()=>I(W().length-1),be=P=>{P.preventDefault(),P.metaKey?oe():P.altKey?q(1):Y(1)},L=P=>{P.preventDefault(),P.metaKey?I(0):P.altKey?q(-1):Y(-1)};return p.createElement(Ye.div,{ref:t,tabIndex:-1,...R,"cmdk-root":"",onKeyDown:P=>{var Z;(Z=R.onKeyDown)==null||Z.call(R,P);let re=P.nativeEvent.isComposing||P.keyCode===229;if(!(P.defaultPrevented||re))switch(P.key){case"n":case"j":{w&&P.ctrlKey&&be(P);break}case"ArrowDown":{be(P);break}case"p":case"k":{w&&P.ctrlKey&&L(P);break}case"ArrowUp":{L(P);break}case"Home":{P.preventDefault(),I(0);break}case"End":{P.preventDefault(),oe();break}case"Enter":{P.preventDefault();let de=G();if(de){let ge=new Event(L0);de.dispatchEvent(ge)}}}}},p.createElement("label",{"cmdk-label":"",htmlFor:k.inputId,id:k.labelId,style:LW},h),Sg(e,P=>p.createElement(FD.Provider,{value:A},p.createElement(UD.Provider,{value:k},P))))}),wW=p.forwardRef((e,t)=>{var n,r;let s=Mn(),l=p.useRef(null),c=p.useContext(zD),d=If(),h=HD(e),m=(r=(n=h.current)==null?void 0:n.forceMount)!=null?r:c==null?void 0:c.forceMount;Tl(()=>{if(!m)return d.item(s,c==null?void 0:c.id)},[m]);let g=$D(s,l,[e.value,e.children,l],e.keywords),v=RS(),x=ji(N=>N.value&&N.value===g.current),b=ji(N=>m||d.filter()===!1?!0:N.search?N.filtered.items.get(s)>0:!0);p.useEffect(()=>{let N=l.current;if(!(!N||e.disabled))return N.addEventListener(L0,E),()=>N.removeEventListener(L0,E)},[b,e.onSelect,e.disabled]);function E(){var N,A;C(),(A=(N=h.current).onSelect)==null||A.call(N,g.current)}function C(){v.setState("value",g.current,!0)}if(!b)return null;let{disabled:w,value:R,onSelect:T,forceMount:j,keywords:O,...D}=e;return p.createElement(Ye.div,{ref:Co(l,t),...D,id:s,"cmdk-item":"",role:"option","aria-disabled":!!w,"aria-selected":!!x,"data-disabled":!!w,"data-selected":!!x,onPointerMove:w||d.getDisablePointerSelection()?void 0:C,onClick:w?void 0:E},e.children)}),RW=p.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:s,...l}=e,c=Mn(),d=p.useRef(null),h=p.useRef(null),m=Mn(),g=If(),v=ji(b=>s||g.filter()===!1?!0:b.search?b.filtered.groups.has(c):!0);Tl(()=>g.group(c),[]),$D(c,d,[e.value,e.heading,h]);let x=p.useMemo(()=>({id:c,forceMount:s}),[s]);return p.createElement(Ye.div,{ref:Co(d,t),...l,"cmdk-group":"",role:"presentation",hidden:v?void 0:!0},n&&p.createElement("div",{ref:h,"cmdk-group-heading":"","aria-hidden":!0,id:m},n),Sg(e,b=>p.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?m:void 0},p.createElement(zD.Provider,{value:x},b))))}),TW=p.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,s=p.useRef(null),l=ji(c=>!c.search);return!n&&!l?null:p.createElement(Ye.div,{ref:Co(s,t),...r,"cmdk-separator":"",role:"separator"})}),jW=p.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,s=e.value!=null,l=RS(),c=ji(m=>m.search),d=ji(m=>m.selectedItemId),h=If();return p.useEffect(()=>{e.value!=null&&l.setState("search",e.value)},[e.value]),p.createElement(Ye.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":h.listId,"aria-labelledby":h.labelId,"aria-activedescendant":d,id:h.inputId,type:"text",value:s?e.value:c,onChange:m=>{s||l.setState("search",m.target.value),n==null||n(m.target.value)}})}),_W=p.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...s}=e,l=p.useRef(null),c=p.useRef(null),d=ji(m=>m.selectedItemId),h=If();return p.useEffect(()=>{if(c.current&&l.current){let m=c.current,g=l.current,v,x=new ResizeObserver(()=>{v=requestAnimationFrame(()=>{let b=m.offsetHeight;g.style.setProperty("--cmdk-list-height",b.toFixed(1)+"px")})});return x.observe(m),()=>{cancelAnimationFrame(v),x.unobserve(m)}}},[]),p.createElement(Ye.div,{ref:Co(l,t),...s,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":d,"aria-label":r,id:h.listId},Sg(e,m=>p.createElement("div",{ref:Co(c,h.listInnerRef),"cmdk-list-sizer":""},m)))}),NW=p.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:s,contentClassName:l,container:c,...d}=e;return p.createElement(Lp,{open:n,onOpenChange:r},p.createElement(Pp,{container:c},p.createElement(Up,{"cmdk-overlay":"",className:s}),p.createElement(Fp,{"aria-label":e.label,"cmdk-dialog":"",className:l},p.createElement(VD,{ref:t,...d}))))}),AW=p.forwardRef((e,t)=>ji(n=>n.filtered.count===0)?p.createElement(Ye.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),DW=p.forwardRef((e,t)=>{let{progress:n,children:r,label:s="Loading...",...l}=e;return p.createElement(Ye.div,{ref:t,...l,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":s},Sg(e,c=>p.createElement("div",{"aria-hidden":!0},c)))}),Eu=Object.assign(VD,{List:_W,Item:wW,Input:jW,Group:RW,Separator:TW,Dialog:NW,Empty:AW,Loading:DW});function OW(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function MW(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function HD(e){let t=p.useRef(e);return Tl(()=>{t.current=e}),t}var Tl=typeof window>"u"?p.useEffect:p.useLayoutEffect;function Ic(e){let t=p.useRef();return t.current===void 0&&(t.current=e()),t}function ji(e){let t=RS(),n=()=>e(t.snapshot());return p.useSyncExternalStore(t.subscribe,n,n)}function $D(e,t,n,r=[]){let s=p.useRef(),l=If();return Tl(()=>{var c;let d=(()=>{var m;for(let g of n){if(typeof g=="string")return g.trim();if(typeof g=="object"&&"current"in g)return g.current?(m=g.current.textContent)==null?void 0:m.trim():s.current}})(),h=r.map(m=>m.trim());l.value(e,d,h),(c=t.current)==null||c.setAttribute(kc,d),s.current=d}),s}var kW=()=>{let[e,t]=p.useState(),n=Ic(()=>new Map);return Tl(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,s)=>{n.current.set(r,s),t({})}};function IW(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function Sg({asChild:e,children:t},n){return e&&p.isValidElement(t)?p.cloneElement(IW(t),{ref:t.ref},n(t.props.children)):n(t)}var LW={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};function BD({className:e,...t}){return o.jsx(Eu,{"data-slot":"command",className:fe("bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",e),...t})}function GD({className:e,...t}){return o.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-9 items-center gap-2 border-b px-3",children:[o.jsx(_l,{className:"size-4 shrink-0 opacity-50"}),o.jsx(Eu.Input,{"data-slot":"command-input",className:fe("placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",e),...t})]})}function PW({className:e,...t}){return o.jsx(Eu.List,{"data-slot":"command-list",className:fe("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",e),...t})}function qD({...e}){return o.jsx(Eu.Empty,{"data-slot":"command-empty",className:"py-6 text-center text-sm",...e})}function ZD({className:e,...t}){return o.jsx(Eu.Group,{"data-slot":"command-group",className:fe("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium",e),...t})}function KD({className:e,...t}){return o.jsx(Eu.Item,{"data-slot":"command-item",className:fe("data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),...t})}var Cg="Popover",[YD]=Fr(Cg,[zs]),Lf=zs(),[UW,Vi]=YD(Cg),QD=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:s,onOpenChange:l,modal:c=!1}=e,d=Lf(t),h=p.useRef(null),[m,g]=p.useState(!1),[v,x]=Jr({prop:r,defaultProp:s??!1,onChange:l,caller:Cg});return o.jsx(du,{...d,children:o.jsx(UW,{scope:t,contentId:Mn(),triggerRef:h,open:v,onOpenChange:x,onOpenToggle:p.useCallback(()=>x(b=>!b),[x]),hasCustomAnchor:m,onCustomAnchorAdd:p.useCallback(()=>g(!0),[]),onCustomAnchorRemove:p.useCallback(()=>g(!1),[]),modal:c,children:n})})};QD.displayName=Cg;var WD="PopoverAnchor",FW=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Vi(WD,n),l=Lf(n),{onCustomAnchorAdd:c,onCustomAnchorRemove:d}=s;return p.useEffect(()=>(c(),()=>d()),[c,d]),o.jsx(fu,{...l,...r,ref:t})});FW.displayName=WD;var XD="PopoverTrigger",JD=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Vi(XD,n),l=Lf(n),c=vt(t,s.triggerRef),d=o.jsx(Ye.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":aO(s.open),...r,ref:c,onClick:je(e.onClick,s.onOpenToggle)});return s.hasCustomAnchor?d:o.jsx(fu,{asChild:!0,...l,children:d})});JD.displayName=XD;var TS="PopoverPortal",[zW,VW]=YD(TS,{forceMount:void 0}),eO=e=>{const{__scopePopover:t,forceMount:n,children:r,container:s}=e,l=Vi(TS,t);return o.jsx(zW,{scope:t,forceMount:n,children:o.jsx(_r,{present:n||l.open,children:o.jsx(Al,{asChild:!0,container:s,children:r})})})};eO.displayName=TS;var nu="PopoverContent",tO=p.forwardRef((e,t)=>{const n=VW(nu,e.__scopePopover),{forceMount:r=n.forceMount,...s}=e,l=Vi(nu,e.__scopePopover);return o.jsx(_r,{present:r||l.open,children:l.modal?o.jsx($W,{...s,ref:t}):o.jsx(BW,{...s,ref:t})})});tO.displayName=nu;var HW=Si("PopoverContent.RemoveScroll"),$W=p.forwardRef((e,t)=>{const n=Vi(nu,e.__scopePopover),r=p.useRef(null),s=vt(t,r),l=p.useRef(!1);return p.useEffect(()=>{const c=r.current;if(c)return kp(c)},[]),o.jsx(ff,{as:HW,allowPinchZoom:!0,children:o.jsx(nO,{...e,ref:s,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:je(e.onCloseAutoFocus,c=>{var d;c.preventDefault(),l.current||(d=n.triggerRef.current)==null||d.focus()}),onPointerDownOutside:je(e.onPointerDownOutside,c=>{const d=c.detail.originalEvent,h=d.button===0&&d.ctrlKey===!0,m=d.button===2||h;l.current=m},{checkForDefaultPrevented:!1}),onFocusOutside:je(e.onFocusOutside,c=>c.preventDefault(),{checkForDefaultPrevented:!1})})})}),BW=p.forwardRef((e,t)=>{const n=Vi(nu,e.__scopePopover),r=p.useRef(!1),s=p.useRef(!1);return o.jsx(nO,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{var c,d;(c=e.onCloseAutoFocus)==null||c.call(e,l),l.defaultPrevented||(r.current||(d=n.triggerRef.current)==null||d.focus(),l.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:l=>{var h,m;(h=e.onInteractOutside)==null||h.call(e,l),l.defaultPrevented||(r.current=!0,l.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const c=l.target;((m=n.triggerRef.current)==null?void 0:m.contains(c))&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&s.current&&l.preventDefault()}})}),nO=p.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:l,disableOutsidePointerEvents:c,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:m,onInteractOutside:g,...v}=e,x=Vi(nu,n),b=Lf(n);return Op(),o.jsx(df,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:l,children:o.jsx(Nl,{asChild:!0,disableOutsidePointerEvents:c,onInteractOutside:g,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:m,onDismiss:()=>x.onOpenChange(!1),children:o.jsx(mf,{"data-state":aO(x.open),role:"dialog",id:x.contentId,...b,...v,ref:t,style:{...v.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),rO="PopoverClose",GW=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Vi(rO,n);return o.jsx(Ye.button,{type:"button",...r,ref:t,onClick:je(e.onClick,()=>s.onOpenChange(!1))})});GW.displayName=rO;var qW="PopoverArrow",ZW=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Lf(n);return o.jsx(pf,{...s,...r,ref:t})});ZW.displayName=qW;function aO(e){return e?"open":"closed"}var KW=QD,YW=JD,QW=eO,WW=tO;function jS({...e}){return o.jsx(KW,{"data-slot":"popover",...e})}function _S({...e}){return o.jsx(YW,{"data-slot":"popover-trigger",...e})}function NS({className:e,align:t="center",sideOffset:n=4,...r}){return o.jsx(QW,{children:o.jsx(WW,{"data-slot":"popover-content",align:t,sideOffset:n,className:fe("bg-popover text-popover-foreground 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 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",e),...r})})}function AS({options:e,value:t,onValueChange:n,placeholder:r="Select an option",emptyMessage:s="No results found.",className:l,disabled:c=!1}){const[d,h]=p.useState(!1),[m,g]=p.useState(""),v=p.useMemo(()=>{const E={};return e.forEach(C=>{const w=C.group??"";Object.prototype.hasOwnProperty.call(E,w)||(E[w]=[]),E[w].push(C)}),E},[e]),x=e.find(E=>E.value===t),b=p.useCallback(E=>{n(E),requestAnimationFrame(()=>{g(""),h(!1)})},[n]);return o.jsxs(jS,{open:d,onOpenChange:h,modal:!0,children:[o.jsx(_S,{asChild:!0,children:o.jsxs(we,{variant:"outline",role:"combobox","aria-expanded":d,className:fe("w-full justify-between",!t&&"text-muted-foreground",l),disabled:c,children:[x?x.label:r,o.jsx(ib,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),o.jsx(NS,{className:"max-h-[300px] overflow-auto p-0",align:"start",sideOffset:5,children:o.jsxs(BD,{children:[o.jsx(GD,{placeholder:`Search ${r.toLowerCase()}...`,value:m,onValueChange:g}),o.jsx(qD,{children:s}),Object.entries(v).map(([E,C])=>{const w=m?C.filter(R=>R.label.toLowerCase().includes(m.toLowerCase())):C;return w.length===0?null:o.jsx(ZD,{heading:E,children:w.map(R=>o.jsxs(KD,{value:R.value,onSelect:()=>{b(R.value)},children:[o.jsx(yr,{className:fe("mr-2 h-4 w-4",t===R.value?"opacity-100":"opacity-0")}),R.label]},R.value))},E||"default")})]})})]})}var Eg="Collapsible",[XW,sO]=Fr(Eg),[JW,DS]=XW(Eg),oO=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:s,disabled:l,onOpenChange:c,...d}=e,[h,m]=Jr({prop:r,defaultProp:s??!1,onChange:c,caller:Eg});return o.jsx(JW,{scope:n,disabled:l,contentId:Mn(),open:h,onOpenToggle:p.useCallback(()=>m(g=>!g),[m]),children:o.jsx(Ye.div,{"data-state":MS(h),"data-disabled":l?"":void 0,...d,ref:t})})});oO.displayName=Eg;var iO="CollapsibleTrigger",lO=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,s=DS(iO,n);return o.jsx(Ye.button,{type:"button","aria-controls":s.contentId,"aria-expanded":s.open||!1,"data-state":MS(s.open),"data-disabled":s.disabled?"":void 0,disabled:s.disabled,...r,ref:t,onClick:je(e.onClick,s.onOpenToggle)})});lO.displayName=iO;var OS="CollapsibleContent",cO=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,s=DS(OS,e.__scopeCollapsible);return o.jsx(_r,{present:n||s.open,children:({present:l})=>o.jsx(eX,{...r,ref:t,present:l})})});cO.displayName=OS;var eX=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:s,...l}=e,c=DS(OS,n),[d,h]=p.useState(r),m=p.useRef(null),g=vt(t,m),v=p.useRef(0),x=v.current,b=p.useRef(0),E=b.current,C=c.open||d,w=p.useRef(C),R=p.useRef(void 0);return p.useEffect(()=>{const T=requestAnimationFrame(()=>w.current=!1);return()=>cancelAnimationFrame(T)},[]),xr(()=>{const T=m.current;if(T){R.current=R.current||{transitionDuration:T.style.transitionDuration,animationName:T.style.animationName},T.style.transitionDuration="0s",T.style.animationName="none";const j=T.getBoundingClientRect();v.current=j.height,b.current=j.width,w.current||(T.style.transitionDuration=R.current.transitionDuration,T.style.animationName=R.current.animationName),h(r)}},[c.open,r]),o.jsx(Ye.div,{"data-state":MS(c.open),"data-disabled":c.disabled?"":void 0,id:c.contentId,hidden:!C,...l,ref:g,style:{"--radix-collapsible-content-height":x?`${x}px`:void 0,"--radix-collapsible-content-width":E?`${E}px`:void 0,...e.style},children:C&&s})});function MS(e){return e?"open":"closed"}var tX=oO,nX=lO,rX=cO,ms="Accordion",aX=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[kS,sX,oX]=Zp(ms),[wg]=Fr(ms,[oX,sO]),IS=sO(),uO=_e.forwardRef((e,t)=>{const{type:n,...r}=e,s=r,l=r;return o.jsx(kS.Provider,{scope:e.__scopeAccordion,children:n==="multiple"?o.jsx(uX,{...l,ref:t}):o.jsx(cX,{...s,ref:t})})});uO.displayName=ms;var[dO,iX]=wg(ms),[fO,lX]=wg(ms,{collapsible:!1}),cX=_e.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},collapsible:l=!1,...c}=e,[d,h]=Jr({prop:n,defaultProp:r??"",onChange:s,caller:ms});return o.jsx(dO,{scope:e.__scopeAccordion,value:_e.useMemo(()=>d?[d]:[],[d]),onItemOpen:h,onItemClose:_e.useCallback(()=>l&&h(""),[l,h]),children:o.jsx(fO,{scope:e.__scopeAccordion,collapsible:l,children:o.jsx(hO,{...c,ref:t})})})}),uX=_e.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},...l}=e,[c,d]=Jr({prop:n,defaultProp:r??[],onChange:s,caller:ms}),h=_e.useCallback(g=>d((v=[])=>[...v,g]),[d]),m=_e.useCallback(g=>d((v=[])=>v.filter(x=>x!==g)),[d]);return o.jsx(dO,{scope:e.__scopeAccordion,value:c,onItemOpen:h,onItemClose:m,children:o.jsx(fO,{scope:e.__scopeAccordion,collapsible:!0,children:o.jsx(hO,{...l,ref:t})})})}),[dX,Rg]=wg(ms),hO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,disabled:r,dir:s,orientation:l="vertical",...c}=e,d=_e.useRef(null),h=vt(d,t),m=sX(n),v=Kp(s)==="ltr",x=je(e.onKeyDown,b=>{var k;if(!aX.includes(b.key))return;const E=b.target,C=m().filter(U=>{var B;return!((B=U.ref.current)!=null&&B.disabled)}),w=C.findIndex(U=>U.ref.current===E),R=C.length;if(w===-1)return;b.preventDefault();let T=w;const j=0,O=R-1,D=()=>{T=w+1,T>O&&(T=j)},N=()=>{T=w-1,T<j&&(T=O)};switch(b.key){case"Home":T=j;break;case"End":T=O;break;case"ArrowRight":l==="horizontal"&&(v?D():N());break;case"ArrowDown":l==="vertical"&&D();break;case"ArrowLeft":l==="horizontal"&&(v?N():D());break;case"ArrowUp":l==="vertical"&&N();break}const A=T%R;(k=C[A].ref.current)==null||k.focus()});return o.jsx(dX,{scope:n,disabled:r,direction:s,orientation:l,children:o.jsx(kS.Slot,{scope:n,children:o.jsx(Ye.div,{...c,"data-orientation":l,ref:h,onKeyDown:r?void 0:x})})})}),xp="AccordionItem",[fX,LS]=wg(xp),mO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,value:r,...s}=e,l=Rg(xp,n),c=iX(xp,n),d=IS(n),h=Mn(),m=r&&c.value.includes(r)||!1,g=l.disabled||e.disabled;return o.jsx(fX,{scope:n,open:m,disabled:g,triggerId:h,children:o.jsx(tX,{"data-orientation":l.orientation,"data-state":bO(m),...d,...s,ref:t,disabled:g,open:m,onOpenChange:v=>{v?c.onItemOpen(r):c.onItemClose(r)}})})});mO.displayName=xp;var pO="AccordionHeader",gO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Rg(ms,n),l=LS(pO,n);return o.jsx(Ye.h3,{"data-orientation":s.orientation,"data-state":bO(l.open),"data-disabled":l.disabled?"":void 0,...r,ref:t})});gO.displayName=pO;var P0="AccordionTrigger",vO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Rg(ms,n),l=LS(P0,n),c=lX(P0,n),d=IS(n);return o.jsx(kS.ItemSlot,{scope:n,children:o.jsx(nX,{"aria-disabled":l.open&&!c.collapsible||void 0,"data-orientation":s.orientation,id:l.triggerId,...d,...r,ref:t})})});vO.displayName=P0;var yO="AccordionContent",xO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Rg(ms,n),l=LS(yO,n),c=IS(n);return o.jsx(rX,{role:"region","aria-labelledby":l.triggerId,"data-orientation":s.orientation,...c,...r,ref:t,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...e.style}})});xO.displayName=yO;function bO(e){return e?"open":"closed"}var hX=uO,mX=mO,pX=gO,gX=vO,vX=xO;const PS={default:{itemClass:"border-b last:border-b-0",triggerClass:"focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",icon:null,chevronClass:"text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200",contentClass:"data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm",contentInnerClass:"pt-0 pb-4",headerClass:"flex"},common:{itemClass:"overflow-hidden",triggerClass:"group focus-visible:ring-primary hover:bg-muted [&[data-state=open]]:bg-muted flex items-center gap-1 rounded-sm px-2 py-1 transition-all outline-none focus-visible:ring-2 [&[data-state=open]]:rounded-br-none [&[data-state=open]]:rounded-bl-none [&[data-state=open]]:font-semibold",icon:o.jsx(xj,{className:"size-4 shrink-0","aria-hidden":"true"}),chevronClass:"size-3.5 shrink-0 transition-transform duration-200 group-data-[state=open]:rotate-180",contentClass:"data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down bg-muted overflow-hidden rounded-sm rounded-tl-none py-0 pr-2 pl-7 text-sm",contentInnerClass:"pt-2 pb-4",headerClass:void 0}},SO=p.createContext("default");function cr({variant:e="default",...t}){return o.jsx(SO.Provider,{value:e,children:o.jsx(hX,{"data-slot":"accordion",...t})})}function US(e){const t=p.useContext(SO);return e??t??"default"}function Gn({className:e,variant:t,...n}){const r=US(t),{itemClass:s}=PS[r];return o.jsx(mX,{"data-slot":"accordion-item",className:fe(s,e),...n})}function qn({className:e,children:t,variant:n,...r}){const s=US(n),{triggerClass:l,icon:c,chevronClass:d,headerClass:h}=PS[s];return o.jsx(pX,{className:h,children:o.jsxs(gX,{"data-slot":"accordion-trigger",className:fe(l,e),...r,children:[c,t,o.jsx(Ga,{className:d,"aria-hidden":"true"})]})})}function Zn({className:e,children:t,variant:n,...r}){const s=US(n),{contentClass:l,contentInnerClass:c}=PS[s];return o.jsx(vX,{"data-slot":"accordion-content",className:fe(l,e),...r,children:o.jsx("div",{className:c,children:t})})}function Bn({href:e,children:t,className:n,...r}){return o.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:fe("text-muted-foreground hover:bg-muted inline-flex items-center px-1 font-medium hover:rounded-md",n),...r,children:[t,o.jsx(cf,{className:"ml-1 inline h-3 w-3","aria-hidden":"true"})]})}function yX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"service-account-details",children:[o.jsx(qn,{children:"How do I get a Service Account JSON key?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"To get the JSON key, you'll need to create or use an existing service account in Google Cloud."}),o.jsx("p",{className:"mb-2",children:"Here's what to do:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Go to"," ",o.jsx(Bn,{className:"underline",href:"https://console.cloud.google.com/iam-admin/serviceaccounts",children:"Google Cloud Console"}),"."]}),o.jsxs("li",{children:["Open ",o.jsx("strong",{children:"IAM & Admin → Service Accounts"}),"."]}),o.jsx("li",{children:"Create a new service account or select an existing one."}),o.jsxs("li",{children:["Assign the ",o.jsx("strong",{children:"bigquery.dataEditor"})," and ",o.jsx("strong",{children:"bigquery.jobUser"})," ","roles to this service account to allow read, write, and create access to your project resources."]}),o.jsxs("li",{children:["Open the Service Accounts page, go to the ",o.jsx("strong",{children:"Keys"})," tab, click"," ",o.jsx("strong",{children:"Add key"}),", and select ",o.jsx("strong",{children:"Create new key"}),"."]}),o.jsxs("li",{children:["Choose ",o.jsx("strong",{children:"JSON"})," format and click ",o.jsx("strong",{children:"Create"}),"."]}),o.jsx("li",{children:"Open the downloaded file, copy its entire content, and paste it into the field above."})]})]})]})})}function xX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"project-id-details",children:[o.jsx(qn,{children:"How do I find my Project ID?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"This is the ID of your Google Cloud project. BigQuery usage costs will be charged to this project."}),o.jsx("p",{className:"mb-2",children:"Here's how to find your billing project ID:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.cloud.google.com/",children:"Google Cloud Console"})," ","and sign in with your Google account."]}),o.jsx("li",{children:'Click the project selector dropdown at the top of the page (it shows the current project name or "Select a project").'}),o.jsxs("li",{children:["Find your project in the list. The ",o.jsx("strong",{children:"Project ID"})," is shown in the ID column."]}),o.jsx("li",{children:"If you don't see your project, use the search box to find it by name or ID."})]})]})]})})}function bX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"gbq-location-details",children:[o.jsx(qn,{children:"How do I find my dataset location?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"BigQuery data is stored in specific regions. To avoid query errors, your SQL queries must process data stored in the same location."}),o.jsx("p",{className:"mb-2",children:"Here's how to check your dataset location:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.cloud.google.com/bigquery",children:"Google Cloud Console BigQuery page"}),"."]}),o.jsx("li",{children:"In the left panel, expand your project and find your datasets."}),o.jsxs("li",{children:["Click each dataset name to open its details. The ",o.jsx("strong",{children:"Data location"})," field shows the region where that dataset is stored (for example,"," ",o.jsx("code",{className:"text-sm font-semibold",children:"US"}),","," ",o.jsx("code",{className:"text-sm font-semibold",children:"EU"}),","," ",o.jsx("code",{className:"text-sm font-semibold",children:"asia-northeast1"}),")."]}),o.jsx("li",{children:"Make sure all your datasets are stored in the same location. If they are in different locations, select the location where most of your data is stored or create separate Storage for each location."}),o.jsx("li",{children:"Put this location value in the field above."})]})]})]})})}const CO=e=>{try{const t=JSON.parse(e),{project_id:n,client_id:r,client_email:s}=t;return!n||!r||!s?null:{url:`https://console.cloud.google.com/iam-admin/serviceaccounts/details/${r}?project=${n}`,email:s}}catch{return null}},SX=({form:e})=>{const[t,n]=p.useState(!1);if(e.watch("type")!==Pe.GOOGLE_BIGQUERY)return null;const r=()=>{n(!0),e.setValue("credentials.serviceAccount","",{shouldDirty:!0})},s=()=>{n(!1),e.resetField("credentials.serviceAccount")},l=e.watch("credentials.serviceAccount"),c=l?CO(l):null;return o.jsxs(o.Fragment,{children:[o.jsxs(Ps,{title:"Connection Settings",children:[o.jsx(Kt,{control:e.control,name:"config.projectId",render:({field:d})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Enter the ID of your Google Cloud project where BigQuery usage will be billed",children:"Project ID"}),o.jsx(Wt,{children:o.jsx(Zt,{...d,placeholder:"Enter a Project Id"})}),o.jsx(tr,{children:o.jsx(xX,{})}),o.jsx(nn,{})]})}),o.jsx(Kt,{control:e.control,name:"config.location",render:({field:d})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Choose the same region where your BigQuery data is stored to ensure queries work correctly",children:"Location"}),o.jsx(Wt,{children:o.jsx(AS,{options:ZB,value:d.value,onValueChange:d.onChange,placeholder:"Select a location",emptyMessage:"No locations found",className:"w-full"})}),o.jsx(tr,{children:o.jsx(bX,{})}),o.jsx(nn,{})]})})]}),o.jsx(Ps,{title:"Authentication",children:o.jsx(Kt,{control:e.control,name:"credentials.serviceAccount",render:({field:d})=>o.jsxs(Yt,{children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(Qt,{tooltip:"Paste a JSON key from a service account that has access to the selected storage provider",children:"Service Account"}),!t&&l&&o.jsx(we,{variant:"ghost",size:"sm",onClick:r,type:"button",children:"Edit"}),t&&o.jsx(we,{variant:"ghost",size:"sm",onClick:s,type:"button",children:"Cancel"})]}),o.jsx(Wt,{children:!t&&c?o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(Bn,{href:c.url,children:c.email})}),o.jsx(Ot,{children:o.jsx("p",{children:"View in Google Cloud Console"})})]}):o.jsx(wi,{...d,className:"min-h-[150px] font-mono",rows:8,placeholder:"Paste your service account JSON here"})}),o.jsx(tr,{children:o.jsx(yX,{})}),o.jsx(nn,{})]})})})]})};function CX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"athena-region-details",children:[o.jsx(qn,{children:"How do I find my Athena region?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"Athena queries run in a specific AWS region. You must select the region where your Athena service and data are located."}),o.jsx("p",{className:"mb-2",children:"Here's how to find your Athena region:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.aws.amazon.com/athena/",children:"the AWS Athena console"}),"."]}),o.jsx("li",{children:"Look at the top right corner of the console. The selected region is shown in the region selector dropdown."}),o.jsx("li",{children:"Make sure to copy and paste the same region here in the form to avoid connection or query errors."})]})]})]})})}function EX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"athena-output-bucket-details",children:[o.jsx(qn,{children:"How do I find a bucket?"}),o.jsxs(Zn,{children:[o.jsxs("p",{className:"mb-2",children:["Athena saves query results in an ",o.jsx("strong",{children:"S3 bucket"}),". You need to specify the bucket used for query output."]}),o.jsx("p",{className:"mb-2",children:"Here's how to find or create an S3 bucket for Athena output:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.aws.amazon.com/s3/",children:"the AWS S3 console"}),"."]}),o.jsx("li",{children:"Look for an existing bucket used for Athena query results, or create a new one."}),o.jsx("li",{children:"If creating a new bucket, make sure it is in the same region as your Athena service."}),o.jsx("li",{children:"Enter the bucket name in this form field."})]})]})]})})}function wX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"athena-access-key-id-details",children:[o.jsx(qn,{children:"How do I get my AWS Access Key ID?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"Before accessing your AWS Access Key ID, make sure you have a user with the necessary permissions to use Athena and Glue in your AWS account."}),o.jsxs("p",{className:"mb-4 text-sm",children:["Learn more about how to create a user in AWS ",o.jsx(Bn,{className:"underline",href:"https://docs.owox.com/docs/storages/supported-storages/aws-athena/?utm_source=owox_data_marts&utm_medium=storage_enity&utm_campaign=tooltip_aws",children:"in documentation"}),"."]}),o.jsx(Ij,{className:"my-4"}),o.jsx("p",{className:"mb-2",children:"The Access Key ID is part of your AWS credentials needed to connect and authenticate."}),o.jsx("p",{className:"mb-2",children:"Here's how to find or create an Access Key ID:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.aws.amazon.com/iam/home#/security_credentials",children:"the AWS IAM Security Credentials page"}),"."]}),o.jsxs("li",{children:["Under ",o.jsx("strong",{children:"Access keys"}),", find your existing keys or create a new access key."]}),o.jsx("li",{children:"When you create a new key, download and securely store the Access Key ID and Secret Access Key."})]})]})]})})}function RX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"athena-secret-access-key-details",children:[o.jsx(qn,{children:"How do I get my AWS Secret Access Key?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"The Secret Access Key is part of your AWS credentials needed to connect and authenticate. It is only shown when you create a new key."}),o.jsx("p",{className:"mb-2",children:"Here's how to get your Secret Access Key:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.aws.amazon.com/iam/home#/security_credentials",children:"the AWS IAM Security Credentials page"}),"."]}),o.jsxs("li",{children:["Under ",o.jsx("strong",{children:"Access keys"}),", create a new access key if you don't have one or lost the secret key."]}),o.jsx("li",{children:"When you create a new key, copy and securely store the Secret Access Key — you won't be able to see it again."})]})]})]})})}const TX=({form:e})=>{const[t,n]=p.useState("");return p.useEffect(()=>{const r=e.getValues("credentials.accessKeyId");if(r){const s="_".repeat(r.length);n(s),e.setValue("credentials.secretAccessKey",s,{shouldDirty:!1})}},[e]),e.watch("type")!==Pe.AWS_ATHENA?null:o.jsxs(o.Fragment,{children:[o.jsxs(Ps,{title:"Connection Settings",children:[o.jsx(Kt,{control:e.control,name:"config.region",render:({field:r})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Enter the AWS region where your Athena service is active",children:"Region"}),o.jsx(Wt,{children:o.jsx(Zt,{...r,placeholder:"Enter a region"})}),o.jsx(tr,{children:o.jsx(CX,{})}),o.jsx(nn,{})]})}),o.jsx(Kt,{control:e.control,name:"config.outputBucket",render:({field:r})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Specify the S3 bucket where Athena query results will be stored",children:"Output Bucket"}),o.jsx(Wt,{children:o.jsx(Zt,{...r,placeholder:"Enter an output bucket"})}),o.jsx(tr,{children:o.jsx(EX,{})}),o.jsx(nn,{})]})})]}),o.jsxs(Ps,{title:"Authentication",children:[o.jsx(Kt,{control:e.control,name:"credentials.accessKeyId",render:({field:r})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Your AWS Access Key ID used for authentication",children:"Access Key ID"}),o.jsx(Wt,{children:o.jsx(Zt,{...r,placeholder:"Enter an access key id"})}),o.jsx(tr,{children:o.jsx(wX,{})}),o.jsx(nn,{})]})}),o.jsx(Kt,{control:e.control,name:"credentials.secretAccessKey",render:({field:r})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Your AWS Secret Access Key used for authentication",children:"Secret Access Key"}),o.jsx(Wt,{children:o.jsx(Zt,{...r,type:"password",placeholder:t||"Enter a secret access key"})}),o.jsx(tr,{children:o.jsx(RX,{})}),o.jsx(nn,{})]})})]})]})};function jX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"bigquery-api-details",children:[o.jsx(qn,{children:"How do I enable the BigQuery API?"}),o.jsxs(Zn,{children:[o.jsxs("p",{className:"mb-2",children:["To run queries and process data in Google BigQuery, you need to enable the"," ",o.jsx(Bn,{className:"underline",href:"https://console.cloud.google.com/apis/library/bigquery.googleapis.com",children:"BigQuery API"})," ","in your Google Cloud project."]}),o.jsx("p",{className:"mb-2",children:"Here's how to do it:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsx("li",{children:"Open the link above and make sure the correct project is selected."}),o.jsxs("li",{children:["If the API isn't enabled yet, click ",o.jsx("strong",{children:"Enable"}),"."]}),o.jsx("li",{children:"If it's already enabled, you'll see the API dashboard — that's fine."})]})]})]})})}function _X(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"athena-api-details",children:[o.jsx(qn,{children:"How do I activate Athena API?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"AWS Athena is a serverless interactive query service. To use it, you need to activate Athena in your AWS account."}),o.jsx("p",{className:"mb-2",children:"Here's how to activate Athena:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.aws.amazon.com/athena/",children:"the AWS Athena console"})," ","and sign in to your AWS account."]}),o.jsx("li",{children:"If you haven't used Athena before, you may need to set up a query result location (an S3 bucket)."}),o.jsx("li",{children:"You can start running queries immediately after setup."})]})]})]})})}function EO(e){return JSON.parse(JSON.stringify(e))}function NX({initialData:e,onSubmit:t,onCancel:n,onDirtyChange:r}){const s=Pi({resolver:zl(fG),defaultValues:e}),{watch:l,control:c,formState:{isDirty:d,isSubmitting:h}}=s,m=l("type");_e.useEffect(()=>{r==null||r(d)},[d,r]);const g=async v=>{const{dirtyFields:x}=s.formState,b=EO(v);return x.credentials||delete b.credentials,t(b)};return o.jsx(Pl,{...s,children:o.jsxs(Ui,{onSubmit:v=>{s.handleSubmit(g)(v)},noValidate:!0,children:[o.jsxs(Ul,{children:[o.jsxs(Ps,{title:"General",children:[o.jsx(Kt,{control:c,name:"title",render:({field:v})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Name the storage to clarify its purpose",children:"Title"}),o.jsx(Wt,{children:o.jsx(Zt,{...v,placeholder:"Storage title"})}),o.jsx(nn,{})]})}),o.jsx(Kt,{control:c,name:"type",render:({field:v})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"The selected source will be used to process data in your Data Marts",children:"Storage Type"}),o.jsx(Wt,{children:o.jsxs(ba,{value:v.value,onValueChange:v.onChange,disabled:!!e,children:[o.jsx(Ca,{className:"w-full",children:o.jsx(Sa,{placeholder:"Select a storage type"})}),o.jsx(Ea,{children:o.jsx(yg,{children:Ii.getAllTypes().map(({type:x,displayName:b,icon:E,status:C})=>o.jsx(Hn,{value:x,disabled:C===po.COMING_SOON,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(E,{size:20}),b]})},x))})})]})}),o.jsxs(tr,{children:[m===Pe.GOOGLE_BIGQUERY&&o.jsx(jX,{}),m===Pe.AWS_ATHENA&&o.jsx(_X,{})]}),o.jsx(nn,{})]})})]}),m===Pe.GOOGLE_BIGQUERY&&o.jsx(SX,{form:s}),m===Pe.AWS_ATHENA&&o.jsx(TX,{form:s})]}),o.jsxs(Fl,{children:[o.jsx(we,{variant:"default",type:"submit",className:"w-full","aria-label":"Save",disabled:!d||h,children:"Save"}),o.jsx(we,{variant:"outline",type:"button",onClick:n,className:"w-full","aria-label":"Cancel",children:"Cancel"})]})]})})}function wO({isOpen:e,onClose:t,dataStorage:n,onSaveSuccess:r}){const{updateDataStorage:s}=xg(),[l,c]=p.useState(!1),[d,h]=p.useState(!1),m=p.useCallback(()=>{d?c(!0):t()},[d,t]),g=p.useCallback(()=>{c(!1),h(!1),t()},[t]),v=p.useCallback(b=>{h(b)},[]),x=async b=>{if(n){const E=await s(n.id,b);E&&(r(E),t())}};return o.jsxs(o.Fragment,{children:[o.jsx(Ai,{open:e,onOpenChange:b=>{b||m()},children:o.jsxs(Di,{children:[o.jsxs(Oi,{children:[o.jsx(Dl,{children:"Configure Storage Provider"}),o.jsx(lu,{children:"Customize settings for your storage provider"})]}),o.jsx(NX,{initialData:n??void 0,onSubmit:x,onCancel:m,onDirtyChange:v})]})}),o.jsx(ya,{open:l,onOpenChange:c,title:"Unsaved Changes",description:"You have unsaved changes. Exit without saving?",confirmLabel:"Yes, leave now",cancelLabel:"No, stay here",onConfirm:g,variant:"destructive"})]})}const AX=({dataStorage:e,onDataStorageChange:t})=>{const[n,r]=p.useState(!1),s=Ii.getInfo(e.type),l=()=>{r(!0)},c=()=>{r(!1)},d=()=>{if(!(()=>{switch(e.type){case Pe.GOOGLE_BIGQUERY:return!!(e.config.projectId&&e.config.location);case Pe.AWS_ATHENA:return!!(e.config.region&&e.config.outputBucket);default:return!1}})())return o.jsxs("div",{className:"flex items-center space-x-2 text-sm",children:[o.jsx(Dp,{className:"h-4 w-4 text-red-500"}),o.jsx("span",{className:"text-red-500",children:"Storage configuration is incomplete"})]});const m=(v,x)=>o.jsxs("span",{children:[o.jsxs("span",{className:"text-muted-foreground/75",children:[v,":"]})," ",o.jsx("span",{className:"text-muted-foreground font-medium",children:x})]}),g=(v,x,b)=>o.jsxs("span",{children:[o.jsxs("span",{className:"text-muted-foreground/75",children:[v,":"]})," ",o.jsx(Bn,{href:b,onClick:E=>{E.stopPropagation()},children:x})]});switch(e.type){case Pe.GOOGLE_BIGQUERY:{const v=e.config.projectId,x=e.config.location,b=`https://console.cloud.google.com/bigquery?project=${v}`;return o.jsxs("div",{className:"flex flex-wrap gap-2",children:[g("Project ID",v,b),o.jsx("span",{className:"text-muted-foreground",children:"•"}),m("Location",x)]})}case Pe.AWS_ATHENA:{const v=e.config.region,x=e.config.outputBucket,b=`https://s3.console.aws.amazon.com/s3/buckets/${x}?region=${v}`;return o.jsxs("div",{className:"flex flex-wrap gap-2",children:[m("Region",v),o.jsx("span",{className:"text-muted-foreground",children:"•"}),g("Bucket",x,b)]})}default:return"Unknown storage type configuration"}};return o.jsxs(o.Fragment,{children:[o.jsx(k0,{title:e.title,icon:s.icon,subtitle:d(),onClick:l}),o.jsx(wS,{children:o.jsx(wO,{isOpen:n,onClose:c,dataStorage:e,onSaveSuccess:h=>{t&&t(h)}})})]})};function DX({initialType:e,onTypeSelect:t}){var c;const[n,r]=p.useState(e??null),s=d=>{r(d),t(d)},l=[{type:Qe.SQL,label:"SQL",description:"SQL query"},{type:Qe.TABLE,label:"Table",description:"Existing table"},{type:Qe.VIEW,label:"View",description:"Existing view"},{type:Qe.TABLE_PATTERN,label:"Pattern",description:"Table pattern"},{type:Qe.CONNECTOR,label:"Connector",description:"Data import from Source to Storage"}];return o.jsxs("div",{className:"dm-card-block",children:[o.jsx(xa,{className:"text-foreground",children:"Definition Type"}),o.jsxs(ba,{value:n??"",onValueChange:d=>{s(d)},children:[o.jsx(Ca,{className:"dm-card-formcontrol w-full","aria-label":"Definition Type",children:o.jsx(Sa,{placeholder:"Select definition type",children:n&&((c=l.find(d=>d.type===n))==null?void 0:c.label)})}),o.jsx(Ea,{children:o.jsx(yg,{children:l.map(d=>o.jsxs(Hn,{value:d.type,children:[d.label,o.jsx("span",{className:"text-muted-foreground/80 ml-2",children:d.description})]},d.type))})})]})]})}const OX=en({definitionType:Vs(Qe.SQL),definition:en({sqlQuery:tn().min(1,"SQL query is required")})}),MX=e=>{const t=e4(e);return en({definitionType:Vs(Qe.TABLE),definition:t})},kX=e=>{const t=e4(e);return en({definitionType:Vs(Qe.VIEW),definition:t})},IX=e=>{const t=Rq(e);return en({definitionType:Vs(Qe.TABLE_PATTERN),definition:t})},LX=en({definitionType:Vs(Qe.CONNECTOR),definition:en({connector:en({source:en({name:tn().min(1,"Connector name is required"),configuration:N2(i$(s$())).min(1,"At least one configuration is required"),node:tn().min(1,"Node is required"),fields:N2(tn()).min(1,"At least one field is required")}),storage:en({fullyQualifiedName:tn().min(1,"fully qualified name is required")})})})}),PX=(e,t)=>{if(!e)return en({definitionType:l$(Bb(Qe)),definition:en({}).optional()});switch(e){case Qe.SQL:return OX;case Qe.TABLE:return MX(t);case Qe.VIEW:return kX(t);case Qe.TABLE_PATTERN:return IX(t);case Qe.CONNECTOR:return LX;default:return en({})}};function UX({control:e}){return o.jsx(Kt,{control:e,name:"definition.sqlQuery",render:({field:t})=>o.jsxs(Yt,{className:"dm-card-block",children:[o.jsx(Qt,{className:"text-foreground",children:"SQL Query"}),o.jsx(Wt,{children:o.jsx(fW,{initialValue:{sqlQuery:t.value},onChange:n=>{t.onChange(n.sqlQuery)}})}),o.jsx(nn,{})]})})}function FX({control:e,storageType:t}){const n=PA(t),r=UA(t);return o.jsx(Kt,{control:e,name:"definition.fullyQualifiedName",render:({field:s})=>o.jsxs(Yt,{className:"dm-card-block",children:[o.jsx(Qt,{children:"Fully Qualified Table Name"}),o.jsx(Wt,{children:o.jsx(Zt,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(tr,{className:"text-muted-foreground/75",children:r}),o.jsx(nn,{})]})})}function zX({control:e,storageType:t}){const n=PA(t),r=UA(t);return o.jsx(Kt,{control:e,name:"definition.fullyQualifiedName",render:({field:s})=>o.jsxs(Yt,{className:"dm-card-block",children:[o.jsx(Qt,{children:"Fully Qualified View Name"}),o.jsx(Wt,{children:o.jsx(Zt,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(tr,{className:"text-muted-foreground/75",children:r}),o.jsx(nn,{})]})})}function VX({control:e,storageType:t}){const n=vG(t),r=yG(t);return o.jsx(Kt,{control:e,name:"definition.pattern",render:({field:s})=>o.jsxs(Yt,{className:"dm-card-block",children:[o.jsx(Qt,{children:"Table Pattern"}),o.jsx(Wt,{children:o.jsx(Zt,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(tr,{className:"text-muted-foreground/75",children:r}),o.jsx(nn,{})]})})}const RO=e=>{switch(e){case Qe.SQL:return{sqlQuery:""};case Qe.TABLE:return{fullyQualifiedName:""};case Qe.VIEW:return{fullyQualifiedName:""};case Qe.TABLE_PATTERN:return{pattern:""};case Qe.CONNECTOR:return{connector:{source:{name:"",configuration:[],node:"",fields:[]},storage:{fullyQualifiedName:""}}};default:return{}}};function km({className:e,...t}){return o.jsx("div",{"data-slot":"card",className:fe("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",e),...t})}function Im({className:e,...t}){return o.jsx("div",{"data-slot":"card-header",className:fe("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",e),...t})}function U0({className:e,...t}){return o.jsx("div",{"data-slot":"card-title",className:fe("leading-none font-semibold",e),...t})}function HX({className:e,...t}){return o.jsx("div",{"data-slot":"card-description",className:fe("text-muted-foreground text-sm",e),...t})}function F0({className:e,...t}){return o.jsx("div",{"data-slot":"card-content",className:fe("px-6",e),...t})}function $X({className:e,...t}){return o.jsx("div",{"data-slot":"card-footer",className:fe("flex items-center px-6 [.border-t]:pt-6",e),...t})}const BX=lf("relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",{variants:{variant:{default:"bg-card text-card-foreground",destructive:"text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90"}},defaultVariants:{variant:"default"}});function FS({className:e,variant:t,...n}){return o.jsx("div",{"data-slot":"alert",role:"alert",className:fe(BX({variant:t}),e),...n})}function TO({className:e,...t}){return o.jsx("div",{"data-slot":"alert-title",className:fe("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",e),...t})}function zS({className:e,...t}){return o.jsx("div",{"data-slot":"alert-description",className:fe("text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",e),...t})}function GX({connectors:e,selectedConnector:t,loading:n,error:r,onConnectorSelect:s,onConnectorDoubleClick:l}){return n?o.jsx("div",{className:"space-y-4",children:o.jsx("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3",children:Array.from({length:6}).map((c,d)=>o.jsxs(km,{children:[o.jsxs(Im,{children:[o.jsx(ir,{className:"h-4 w-3/4"}),o.jsx(ir,{className:"h-3 w-1/2"})]}),o.jsx(F0,{children:o.jsx(ir,{className:"h-10 w-full"})})]},d))})}):r?o.jsxs(FS,{variant:"destructive",children:[o.jsx(au,{className:"h-4 w-4"}),o.jsx(zS,{children:"Failed to load available connectors. Please try again."})]}):o.jsxs("div",{className:"space-y-4",children:[o.jsx("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-2",children:e.map(c=>o.jsx(km,{className:`cursor-pointer transition-all duration-200 hover:shadow-md ${(t==null?void 0:t.name)===c.name?"ring-primary border-primary":"hover:border-muted-foreground/25"}`,onClick:()=>{s(c)},onDoubleClick:()=>{s(c),l==null||l(c)},children:o.jsx(Im,{children:o.jsx("div",{className:"flex items-center justify-between",children:o.jsxs("div",{className:"flex items-center gap-2",children:[c.logoBase64&&o.jsx(Tf,{base64:c.logoBase64,size:16}),o.jsx(U0,{className:"text-base",children:c.displayName})]})})})},c.name))}),e.length===0&&o.jsxs("div",{className:"py-8 text-center",children:[o.jsx(bj,{className:"text-muted-foreground mx-auto mb-4 h-12 w-12"}),o.jsx("h4",{className:"text-muted-foreground text-lg font-medium",children:"No connectors available"}),o.jsx("p",{className:"text-muted-foreground text-sm",children:"Contact your administrator to add connector configurations."})]}),o.jsx("div",{className:"flex flex-col gap-4",children:o.jsxs(km,{className:"bg-muted cursor-pointer transition-all duration-200 hover:shadow-md",children:[o.jsx(Im,{className:"pb-3",children:o.jsx(U0,{className:"text-base",children:"Custom code"})}),o.jsx(F0,{children:o.jsx("p",{className:"text-muted-foreground text-sm",children:"Coming soon..."})})]})})]})}function qX(e,t,n){const{name:r,title:s,requiredType:l,options:c,placeholder:d,default:h}=e,m=s??r,g=r;if(c&&c.length>0){const v=c.map(x=>({value:x,label:x}));return o.jsx(AS,{options:v,value:t[r]||h||"",onValueChange:x=>{n(r,x)},placeholder:d??`Select ${m.toLowerCase()}`,emptyMessage:"No options available",className:"w-full"})}switch(l){case Ts.BOOLEAN:return o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx("input",{type:"checkbox",id:g,name:r,checked:t[r]||h||!1,onChange:v=>{n(r,v.target.checked)},className:"text-primary focus:ring-primary border-border h-4 w-4 rounded"}),o.jsx(xa,{htmlFor:g,className:"cursor-pointer text-sm",children:m})]});case Ts.NUMBER:return o.jsx(Zt,{id:g,name:r,type:"number",value:t[r]||h||"",placeholder:d??`Enter ${m.toLowerCase()}`,onChange:v=>{const x=parseFloat(v.target.value)||0;n(r,x)}});case Ts.ARRAY:return o.jsx(wi,{id:g,name:r,value:Array.isArray(t[r])?t[r].join(`
|
|
703
|
+
`},lT=DQ(IQ)(_D),LQ={config:MQ},PQ=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return function(s){return n.reduceRight(function(l,c){return c(l)},s)}};function ND(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],ND(e[n],t[n]))}),aT(aT({},e),t)}var UQ={type:"cancelation",msg:"operation is manually canceled"};function jx(e){var t=!1,n=new Promise(function(r,s){e.then(function(l){return t?s(UQ):r(l)}),e.catch(s)});return n.cancel=function(){return t=!0},n}var FQ=NQ.create({config:AQ,isInitialized:!1,resolve:null,reject:null,monaco:null}),AD=uQ(FQ,2),kf=AD[0],bg=AD[1];function zQ(e){var t=LQ.config(e),n=t.monaco,r=cQ(t,["monaco"]);bg(function(s){return{config:ND(s.config,r),monaco:n}})}function VQ(){var e=kf(function(t){var n=t.monaco,r=t.isInitialized,s=t.resolve;return{monaco:n,isInitialized:r,resolve:s}});if(!e.isInitialized){if(bg({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),jx(_x);if(window.monaco&&window.monaco.editor)return DD(window.monaco),e.resolve(window.monaco),jx(_x);PQ(HQ,BQ)(GQ)}return jx(_x)}function HQ(e){return document.body.appendChild(e)}function $Q(e){var t=document.createElement("script");return e&&(t.src=e),t}function BQ(e){var t=kf(function(r){var s=r.config,l=r.reject;return{config:s,reject:l}}),n=$Q("".concat(t.config.paths.vs,"/loader.js"));return n.onload=function(){return e()},n.onerror=t.reject,n}function GQ(){var e=kf(function(n){var r=n.config,s=n.resolve,l=n.reject;return{config:r,resolve:s,reject:l}}),t=window.require;t.config(e.config),t(["vs/editor/editor.main"],function(n){DD(n),e.resolve(n)},function(n){e.reject(n)})}function DD(e){kf().monaco||bg({monaco:e})}function qQ(){return kf(function(e){var t=e.monaco;return t})}var _x=new Promise(function(e,t){return bg({resolve:e,reject:t})}),OD={config:zQ,init:VQ,__getMonacoInstance:qQ},ZQ={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},Nx=ZQ,KQ={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},YQ=KQ;function QQ({children:e}){return _e.createElement("div",{style:YQ.container},e)}var WQ=QQ,XQ=WQ;function JQ({width:e,height:t,isEditorReady:n,loading:r,_ref:s,className:l,wrapperProps:c}){return _e.createElement("section",{style:{...Nx.wrapper,width:e,height:t},...c},!n&&_e.createElement(XQ,null,r),_e.createElement("div",{ref:s,style:{...Nx.fullWidth,...!n&&Nx.hide},className:l}))}var eW=JQ,MD=p.memo(eW);function tW(e){p.useEffect(e,[])}var kD=tW;function nW(e,t,n=!0){let r=p.useRef(!0);p.useEffect(r.current||!n?()=>{r.current=!1}:e,t)}var da=nW;function Ld(){}function Pc(e,t,n,r){return rW(e,r)||aW(e,t,n,r)}function rW(e,t){return e.editor.getModel(ID(e,t))}function aW(e,t,n,r){return e.editor.createModel(t,n,r?ID(e,r):void 0)}function ID(e,t){return e.Uri.parse(t)}function sW({original:e,modified:t,language:n,originalLanguage:r,modifiedLanguage:s,originalModelPath:l,modifiedModelPath:c,keepCurrentOriginalModel:d=!1,keepCurrentModifiedModel:h=!1,theme:m="light",loading:g="Loading...",options:v={},height:x="100%",width:b="100%",className:E,wrapperProps:C={},beforeMount:w=Ld,onMount:R=Ld}){let[T,j]=p.useState(!1),[O,D]=p.useState(!0),N=p.useRef(null),A=p.useRef(null),k=p.useRef(null),U=p.useRef(R),B=p.useRef(w),H=p.useRef(!1);kD(()=>{let W=OD.init();return W.then(I=>(A.current=I)&&D(!1)).catch(I=>(I==null?void 0:I.type)!=="cancelation"&&console.error("Monaco initialization: error:",I)),()=>N.current?G():W.cancel()}),da(()=>{if(N.current&&A.current){let W=N.current.getOriginalEditor(),I=Pc(A.current,e||"",r||n||"text",l||"");I!==W.getModel()&&W.setModel(I)}},[l],T),da(()=>{if(N.current&&A.current){let W=N.current.getModifiedEditor(),I=Pc(A.current,t||"",s||n||"text",c||"");I!==W.getModel()&&W.setModel(I)}},[c],T),da(()=>{let W=N.current.getModifiedEditor();W.getOption(A.current.editor.EditorOption.readOnly)?W.setValue(t||""):t!==W.getValue()&&(W.executeEdits("",[{range:W.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),W.pushUndoStop())},[t],T),da(()=>{var W,I;(I=(W=N.current)==null?void 0:W.getModel())==null||I.original.setValue(e||"")},[e],T),da(()=>{let{original:W,modified:I}=N.current.getModel();A.current.editor.setModelLanguage(W,r||n||"text"),A.current.editor.setModelLanguage(I,s||n||"text")},[n,r,s],T),da(()=>{var W;(W=A.current)==null||W.editor.setTheme(m)},[m],T),da(()=>{var W;(W=N.current)==null||W.updateOptions(v)},[v],T);let Q=p.useCallback(()=>{var Y;if(!A.current)return;B.current(A.current);let W=Pc(A.current,e||"",r||n||"text",l||""),I=Pc(A.current,t||"",s||n||"text",c||"");(Y=N.current)==null||Y.setModel({original:W,modified:I})},[n,t,s,e,r,l,c]),ne=p.useCallback(()=>{var W;!H.current&&k.current&&(N.current=A.current.editor.createDiffEditor(k.current,{automaticLayout:!0,...v}),Q(),(W=A.current)==null||W.editor.setTheme(m),j(!0),H.current=!0)},[v,m,Q]);p.useEffect(()=>{T&&U.current(N.current,A.current)},[T]),p.useEffect(()=>{!O&&!T&&ne()},[O,T,ne]);function G(){var I,Y,q,oe;let W=(I=N.current)==null?void 0:I.getModel();d||((Y=W==null?void 0:W.original)==null||Y.dispose()),h||((q=W==null?void 0:W.modified)==null||q.dispose()),(oe=N.current)==null||oe.dispose()}return _e.createElement(MD,{width:b,height:x,isEditorReady:T,loading:g,_ref:k,className:E,wrapperProps:C})}var oW=sW;p.memo(oW);function iW(e){let t=p.useRef();return p.useEffect(()=>{t.current=e},[e]),t.current}var lW=iW,vm=new Map;function cW({defaultValue:e,defaultLanguage:t,defaultPath:n,value:r,language:s,path:l,theme:c="light",line:d,loading:h="Loading...",options:m={},overrideServices:g={},saveViewState:v=!0,keepCurrentModel:x=!1,width:b="100%",height:E="100%",className:C,wrapperProps:w={},beforeMount:R=Ld,onMount:T=Ld,onChange:j,onValidate:O=Ld}){let[D,N]=p.useState(!1),[A,k]=p.useState(!0),U=p.useRef(null),B=p.useRef(null),H=p.useRef(null),Q=p.useRef(T),ne=p.useRef(R),G=p.useRef(),W=p.useRef(r),I=lW(l),Y=p.useRef(!1),q=p.useRef(!1);kD(()=>{let L=OD.init();return L.then(P=>(U.current=P)&&k(!1)).catch(P=>(P==null?void 0:P.type)!=="cancelation"&&console.error("Monaco initialization: error:",P)),()=>B.current?be():L.cancel()}),da(()=>{var P,Z,re,de;let L=Pc(U.current,e||r||"",t||s||"",l||n||"");L!==((P=B.current)==null?void 0:P.getModel())&&(v&&vm.set(I,(Z=B.current)==null?void 0:Z.saveViewState()),(re=B.current)==null||re.setModel(L),v&&((de=B.current)==null||de.restoreViewState(vm.get(l))))},[l],D),da(()=>{var L;(L=B.current)==null||L.updateOptions(m)},[m],D),da(()=>{!B.current||r===void 0||(B.current.getOption(U.current.editor.EditorOption.readOnly)?B.current.setValue(r):r!==B.current.getValue()&&(q.current=!0,B.current.executeEdits("",[{range:B.current.getModel().getFullModelRange(),text:r,forceMoveMarkers:!0}]),B.current.pushUndoStop(),q.current=!1))},[r],D),da(()=>{var P,Z;let L=(P=B.current)==null?void 0:P.getModel();L&&s&&((Z=U.current)==null||Z.editor.setModelLanguage(L,s))},[s],D),da(()=>{var L;d!==void 0&&((L=B.current)==null||L.revealLine(d))},[d],D),da(()=>{var L;(L=U.current)==null||L.editor.setTheme(c)},[c],D);let oe=p.useCallback(()=>{var L;if(!(!H.current||!U.current)&&!Y.current){ne.current(U.current);let P=l||n,Z=Pc(U.current,r||e||"",t||s||"",P||"");B.current=(L=U.current)==null?void 0:L.editor.create(H.current,{model:Z,automaticLayout:!0,...m},g),v&&B.current.restoreViewState(vm.get(P)),U.current.editor.setTheme(c),d!==void 0&&B.current.revealLine(d),N(!0),Y.current=!0}},[e,t,n,r,s,l,m,g,v,c,d]);p.useEffect(()=>{D&&Q.current(B.current,U.current)},[D]),p.useEffect(()=>{!A&&!D&&oe()},[A,D,oe]),W.current=r,p.useEffect(()=>{var L,P;D&&j&&((L=G.current)==null||L.dispose(),G.current=(P=B.current)==null?void 0:P.onDidChangeModelContent(Z=>{q.current||j(B.current.getValue(),Z)}))},[D,j]),p.useEffect(()=>{if(D){let L=U.current.editor.onDidChangeMarkers(P=>{var re;let Z=(re=B.current.getModel())==null?void 0:re.uri;if(Z&&P.find(de=>de.path===Z.path)){let de=U.current.editor.getModelMarkers({resource:Z});O==null||O(de)}});return()=>{L==null||L.dispose()}}return()=>{}},[D,O]);function be(){var L,P;(L=G.current)==null||L.dispose(),x?v&&vm.set(l,B.current.saveViewState()):(P=B.current.getModel())==null||P.dispose(),B.current.dispose()}return _e.createElement(MD,{width:b,height:E,isEditorReady:D,loading:h,_ref:H,className:C,wrapperProps:w})}var uW=cW,dW=p.memo(uW);function fW({initialValue:e,onChange:t}){const[n,r]=p.useState((e==null?void 0:e.sqlQuery)??""),{theme:s}=TA();p.useEffect(()=>{e!=null&&e.sqlQuery&&e.sqlQuery!==n&&r(e.sqlQuery)},[e,n]);function l(c){c!==void 0&&(r(c),t({sqlQuery:c}))}return o.jsx("div",{className:"shadow-xs",children:o.jsx(dW,{className:"overflow-hidden rounded-md border border-gray-200 dark:border-gray-200/4",height:"30vh",language:"sql",value:n,onChange:l,theme:s==="dark"?"vs-dark":"light",options:{selectOnLineNumbers:!0,hideCursorInOverviewRuler:!0,minimap:{enabled:!1},scrollBeyondLastLine:!1,overviewRulerBorder:!1}})})}function k0({icon:e,title:t,subtitle:n,rightContent:r,onClick:s,className:l}){const c=e;return o.jsxs("div",{className:fe("group flex items-center gap-4 rounded-md border-b border-gray-200 bg-white transition-shadow duration-200 hover:shadow-xs dark:border-0 dark:bg-white/2",s&&"cursor-pointer dark:hover:bg-white/5",l),onClick:s,children:[o.jsxs("div",{className:"flex flex-grow items-start justify-center gap-3 px-6 py-5",children:[e&&o.jsx("div",{className:"flex items-center justify-center",children:o.jsx(c,{className:"h-6 w-6"})}),o.jsxs("div",{className:"flex flex-grow flex-col gap-1",children:[o.jsx("div",{className:"text-md font-medium",children:t}),n&&o.jsx("div",{className:"text-muted-foreground/60 text-sm",children:n})]})]}),o.jsxs("div",{className:"flex items-center justify-center gap-2 p-4",children:[r,s&&o.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full transition-colors duration-200 group-hover:bg-gray-200/50 dark:group-hover:bg-white/4",children:o.jsx(_o,{className:"text-muted-foreground/75 dark:text-muted-foreground/50 h-4 w-4"})})]})]})}var cT=1,hW=.9,mW=.8,pW=.17,Ax=.1,Dx=.999,gW=.9999,vW=.99,yW=/[\\\/_+.#"@\[\(\{&]/,xW=/[\\\/_+.#"@\[\(\{&]/g,bW=/[\s-]/,LD=/[\s-]/g;function I0(e,t,n,r,s,l,c){if(l===t.length)return s===e.length?cT:vW;var d=`${s},${l}`;if(c[d]!==void 0)return c[d];for(var h=r.charAt(l),m=n.indexOf(h,s),g=0,v,x,b,E;m>=0;)v=I0(e,t,n,r,m+1,l+1,c),v>g&&(m===s?v*=cT:yW.test(e.charAt(m-1))?(v*=mW,b=e.slice(s,m-1).match(xW),b&&s>0&&(v*=Math.pow(Dx,b.length))):bW.test(e.charAt(m-1))?(v*=hW,E=e.slice(s,m-1).match(LD),E&&s>0&&(v*=Math.pow(Dx,E.length))):(v*=pW,s>0&&(v*=Math.pow(Dx,m-s))),e.charAt(m)!==t.charAt(l)&&(v*=gW)),(v<Ax&&n.charAt(m-1)===r.charAt(l+1)||r.charAt(l+1)===r.charAt(l)&&n.charAt(m-1)!==r.charAt(l))&&(x=I0(e,t,n,r,m+1,l+2,c),x*Ax>v&&(v=x*Ax)),v>g&&(g=v),m=n.indexOf(h,m+1);return c[d]=g,g}function uT(e){return e.toLowerCase().replace(LD," ")}function SW(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,I0(e,t,uT(e),uT(t),0,0,{})}var Rd='[cmdk-group=""]',Ox='[cmdk-group-items=""]',CW='[cmdk-group-heading=""]',PD='[cmdk-item=""]',dT=`${PD}:not([aria-disabled="true"])`,L0="cmdk-item-select",kc="data-value",EW=(e,t,n)=>SW(e,t,n),UD=p.createContext(void 0),If=()=>p.useContext(UD),FD=p.createContext(void 0),RS=()=>p.useContext(FD),zD=p.createContext(void 0),VD=p.forwardRef((e,t)=>{let n=Ic(()=>{var P,Z;return{search:"",value:(Z=(P=e.value)!=null?P:e.defaultValue)!=null?Z:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=Ic(()=>new Set),s=Ic(()=>new Map),l=Ic(()=>new Map),c=Ic(()=>new Set),d=HD(e),{label:h,children:m,value:g,onValueChange:v,filter:x,shouldFilter:b,loop:E,disablePointerSelection:C=!1,vimBindings:w=!0,...R}=e,T=Mn(),j=Mn(),O=Mn(),D=p.useRef(null),N=kW();Tl(()=>{if(g!==void 0){let P=g.trim();n.current.value=P,A.emit()}},[g]),Tl(()=>{N(6,ne)},[]);let A=p.useMemo(()=>({subscribe:P=>(c.current.add(P),()=>c.current.delete(P)),snapshot:()=>n.current,setState:(P,Z,re)=>{var de,ge,ce,Ae;if(!Object.is(n.current[P],Z)){if(n.current[P]=Z,P==="search")Q(),B(),N(1,H);else if(P==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let Re=document.getElementById(O);Re?Re.focus():(de=document.getElementById(T))==null||de.focus()}if(N(7,()=>{var Re;n.current.selectedItemId=(Re=G())==null?void 0:Re.id,A.emit()}),re||N(5,ne),((ge=d.current)==null?void 0:ge.value)!==void 0){let Re=Z??"";(Ae=(ce=d.current).onValueChange)==null||Ae.call(ce,Re);return}}A.emit()}},emit:()=>{c.current.forEach(P=>P())}}),[]),k=p.useMemo(()=>({value:(P,Z,re)=>{var de;Z!==((de=l.current.get(P))==null?void 0:de.value)&&(l.current.set(P,{value:Z,keywords:re}),n.current.filtered.items.set(P,U(Z,re)),N(2,()=>{B(),A.emit()}))},item:(P,Z)=>(r.current.add(P),Z&&(s.current.has(Z)?s.current.get(Z).add(P):s.current.set(Z,new Set([P]))),N(3,()=>{Q(),B(),n.current.value||H(),A.emit()}),()=>{l.current.delete(P),r.current.delete(P),n.current.filtered.items.delete(P);let re=G();N(4,()=>{Q(),(re==null?void 0:re.getAttribute("id"))===P&&H(),A.emit()})}),group:P=>(s.current.has(P)||s.current.set(P,new Set),()=>{l.current.delete(P),s.current.delete(P)}),filter:()=>d.current.shouldFilter,label:h||e["aria-label"],getDisablePointerSelection:()=>d.current.disablePointerSelection,listId:T,inputId:O,labelId:j,listInnerRef:D}),[]);function U(P,Z){var re,de;let ge=(de=(re=d.current)==null?void 0:re.filter)!=null?de:EW;return P?ge(P,n.current.search,Z):0}function B(){if(!n.current.search||d.current.shouldFilter===!1)return;let P=n.current.filtered.items,Z=[];n.current.filtered.groups.forEach(de=>{let ge=s.current.get(de),ce=0;ge.forEach(Ae=>{let Re=P.get(Ae);ce=Math.max(Re,ce)}),Z.push([de,ce])});let re=D.current;W().sort((de,ge)=>{var ce,Ae;let Re=de.getAttribute("id"),xe=ge.getAttribute("id");return((ce=P.get(xe))!=null?ce:0)-((Ae=P.get(Re))!=null?Ae:0)}).forEach(de=>{let ge=de.closest(Ox);ge?ge.appendChild(de.parentElement===ge?de:de.closest(`${Ox} > *`)):re.appendChild(de.parentElement===re?de:de.closest(`${Ox} > *`))}),Z.sort((de,ge)=>ge[1]-de[1]).forEach(de=>{var ge;let ce=(ge=D.current)==null?void 0:ge.querySelector(`${Rd}[${kc}="${encodeURIComponent(de[0])}"]`);ce==null||ce.parentElement.appendChild(ce)})}function H(){let P=W().find(re=>re.getAttribute("aria-disabled")!=="true"),Z=P==null?void 0:P.getAttribute(kc);A.setState("value",Z||void 0)}function Q(){var P,Z,re,de;if(!n.current.search||d.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let ge=0;for(let ce of r.current){let Ae=(Z=(P=l.current.get(ce))==null?void 0:P.value)!=null?Z:"",Re=(de=(re=l.current.get(ce))==null?void 0:re.keywords)!=null?de:[],xe=U(Ae,Re);n.current.filtered.items.set(ce,xe),xe>0&&ge++}for(let[ce,Ae]of s.current)for(let Re of Ae)if(n.current.filtered.items.get(Re)>0){n.current.filtered.groups.add(ce);break}n.current.filtered.count=ge}function ne(){var P,Z,re;let de=G();de&&(((P=de.parentElement)==null?void 0:P.firstChild)===de&&((re=(Z=de.closest(Rd))==null?void 0:Z.querySelector(CW))==null||re.scrollIntoView({block:"nearest"})),de.scrollIntoView({block:"nearest"}))}function G(){var P;return(P=D.current)==null?void 0:P.querySelector(`${PD}[aria-selected="true"]`)}function W(){var P;return Array.from(((P=D.current)==null?void 0:P.querySelectorAll(dT))||[])}function I(P){let Z=W()[P];Z&&A.setState("value",Z.getAttribute(kc))}function Y(P){var Z;let re=G(),de=W(),ge=de.findIndex(Ae=>Ae===re),ce=de[ge+P];(Z=d.current)!=null&&Z.loop&&(ce=ge+P<0?de[de.length-1]:ge+P===de.length?de[0]:de[ge+P]),ce&&A.setState("value",ce.getAttribute(kc))}function q(P){let Z=G(),re=Z==null?void 0:Z.closest(Rd),de;for(;re&&!de;)re=P>0?OW(re,Rd):MW(re,Rd),de=re==null?void 0:re.querySelector(dT);de?A.setState("value",de.getAttribute(kc)):Y(P)}let oe=()=>I(W().length-1),be=P=>{P.preventDefault(),P.metaKey?oe():P.altKey?q(1):Y(1)},L=P=>{P.preventDefault(),P.metaKey?I(0):P.altKey?q(-1):Y(-1)};return p.createElement(Ye.div,{ref:t,tabIndex:-1,...R,"cmdk-root":"",onKeyDown:P=>{var Z;(Z=R.onKeyDown)==null||Z.call(R,P);let re=P.nativeEvent.isComposing||P.keyCode===229;if(!(P.defaultPrevented||re))switch(P.key){case"n":case"j":{w&&P.ctrlKey&&be(P);break}case"ArrowDown":{be(P);break}case"p":case"k":{w&&P.ctrlKey&&L(P);break}case"ArrowUp":{L(P);break}case"Home":{P.preventDefault(),I(0);break}case"End":{P.preventDefault(),oe();break}case"Enter":{P.preventDefault();let de=G();if(de){let ge=new Event(L0);de.dispatchEvent(ge)}}}}},p.createElement("label",{"cmdk-label":"",htmlFor:k.inputId,id:k.labelId,style:LW},h),Sg(e,P=>p.createElement(FD.Provider,{value:A},p.createElement(UD.Provider,{value:k},P))))}),wW=p.forwardRef((e,t)=>{var n,r;let s=Mn(),l=p.useRef(null),c=p.useContext(zD),d=If(),h=HD(e),m=(r=(n=h.current)==null?void 0:n.forceMount)!=null?r:c==null?void 0:c.forceMount;Tl(()=>{if(!m)return d.item(s,c==null?void 0:c.id)},[m]);let g=$D(s,l,[e.value,e.children,l],e.keywords),v=RS(),x=ji(N=>N.value&&N.value===g.current),b=ji(N=>m||d.filter()===!1?!0:N.search?N.filtered.items.get(s)>0:!0);p.useEffect(()=>{let N=l.current;if(!(!N||e.disabled))return N.addEventListener(L0,E),()=>N.removeEventListener(L0,E)},[b,e.onSelect,e.disabled]);function E(){var N,A;C(),(A=(N=h.current).onSelect)==null||A.call(N,g.current)}function C(){v.setState("value",g.current,!0)}if(!b)return null;let{disabled:w,value:R,onSelect:T,forceMount:j,keywords:O,...D}=e;return p.createElement(Ye.div,{ref:Co(l,t),...D,id:s,"cmdk-item":"",role:"option","aria-disabled":!!w,"aria-selected":!!x,"data-disabled":!!w,"data-selected":!!x,onPointerMove:w||d.getDisablePointerSelection()?void 0:C,onClick:w?void 0:E},e.children)}),RW=p.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:s,...l}=e,c=Mn(),d=p.useRef(null),h=p.useRef(null),m=Mn(),g=If(),v=ji(b=>s||g.filter()===!1?!0:b.search?b.filtered.groups.has(c):!0);Tl(()=>g.group(c),[]),$D(c,d,[e.value,e.heading,h]);let x=p.useMemo(()=>({id:c,forceMount:s}),[s]);return p.createElement(Ye.div,{ref:Co(d,t),...l,"cmdk-group":"",role:"presentation",hidden:v?void 0:!0},n&&p.createElement("div",{ref:h,"cmdk-group-heading":"","aria-hidden":!0,id:m},n),Sg(e,b=>p.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?m:void 0},p.createElement(zD.Provider,{value:x},b))))}),TW=p.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,s=p.useRef(null),l=ji(c=>!c.search);return!n&&!l?null:p.createElement(Ye.div,{ref:Co(s,t),...r,"cmdk-separator":"",role:"separator"})}),jW=p.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,s=e.value!=null,l=RS(),c=ji(m=>m.search),d=ji(m=>m.selectedItemId),h=If();return p.useEffect(()=>{e.value!=null&&l.setState("search",e.value)},[e.value]),p.createElement(Ye.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":h.listId,"aria-labelledby":h.labelId,"aria-activedescendant":d,id:h.inputId,type:"text",value:s?e.value:c,onChange:m=>{s||l.setState("search",m.target.value),n==null||n(m.target.value)}})}),_W=p.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...s}=e,l=p.useRef(null),c=p.useRef(null),d=ji(m=>m.selectedItemId),h=If();return p.useEffect(()=>{if(c.current&&l.current){let m=c.current,g=l.current,v,x=new ResizeObserver(()=>{v=requestAnimationFrame(()=>{let b=m.offsetHeight;g.style.setProperty("--cmdk-list-height",b.toFixed(1)+"px")})});return x.observe(m),()=>{cancelAnimationFrame(v),x.unobserve(m)}}},[]),p.createElement(Ye.div,{ref:Co(l,t),...s,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":d,"aria-label":r,id:h.listId},Sg(e,m=>p.createElement("div",{ref:Co(c,h.listInnerRef),"cmdk-list-sizer":""},m)))}),NW=p.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:s,contentClassName:l,container:c,...d}=e;return p.createElement(Lp,{open:n,onOpenChange:r},p.createElement(Pp,{container:c},p.createElement(Up,{"cmdk-overlay":"",className:s}),p.createElement(Fp,{"aria-label":e.label,"cmdk-dialog":"",className:l},p.createElement(VD,{ref:t,...d}))))}),AW=p.forwardRef((e,t)=>ji(n=>n.filtered.count===0)?p.createElement(Ye.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),DW=p.forwardRef((e,t)=>{let{progress:n,children:r,label:s="Loading...",...l}=e;return p.createElement(Ye.div,{ref:t,...l,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":s},Sg(e,c=>p.createElement("div",{"aria-hidden":!0},c)))}),Eu=Object.assign(VD,{List:_W,Item:wW,Input:jW,Group:RW,Separator:TW,Dialog:NW,Empty:AW,Loading:DW});function OW(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function MW(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function HD(e){let t=p.useRef(e);return Tl(()=>{t.current=e}),t}var Tl=typeof window>"u"?p.useEffect:p.useLayoutEffect;function Ic(e){let t=p.useRef();return t.current===void 0&&(t.current=e()),t}function ji(e){let t=RS(),n=()=>e(t.snapshot());return p.useSyncExternalStore(t.subscribe,n,n)}function $D(e,t,n,r=[]){let s=p.useRef(),l=If();return Tl(()=>{var c;let d=(()=>{var m;for(let g of n){if(typeof g=="string")return g.trim();if(typeof g=="object"&&"current"in g)return g.current?(m=g.current.textContent)==null?void 0:m.trim():s.current}})(),h=r.map(m=>m.trim());l.value(e,d,h),(c=t.current)==null||c.setAttribute(kc,d),s.current=d}),s}var kW=()=>{let[e,t]=p.useState(),n=Ic(()=>new Map);return Tl(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,s)=>{n.current.set(r,s),t({})}};function IW(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function Sg({asChild:e,children:t},n){return e&&p.isValidElement(t)?p.cloneElement(IW(t),{ref:t.ref},n(t.props.children)):n(t)}var LW={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};function BD({className:e,...t}){return o.jsx(Eu,{"data-slot":"command",className:fe("bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",e),...t})}function GD({className:e,...t}){return o.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-9 items-center gap-2 border-b px-3",children:[o.jsx(_l,{className:"size-4 shrink-0 opacity-50"}),o.jsx(Eu.Input,{"data-slot":"command-input",className:fe("placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",e),...t})]})}function PW({className:e,...t}){return o.jsx(Eu.List,{"data-slot":"command-list",className:fe("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",e),...t})}function qD({...e}){return o.jsx(Eu.Empty,{"data-slot":"command-empty",className:"py-6 text-center text-sm",...e})}function ZD({className:e,...t}){return o.jsx(Eu.Group,{"data-slot":"command-group",className:fe("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium",e),...t})}function KD({className:e,...t}){return o.jsx(Eu.Item,{"data-slot":"command-item",className:fe("data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),...t})}var Cg="Popover",[YD]=Fr(Cg,[zs]),Lf=zs(),[UW,Vi]=YD(Cg),QD=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:s,onOpenChange:l,modal:c=!1}=e,d=Lf(t),h=p.useRef(null),[m,g]=p.useState(!1),[v,x]=Jr({prop:r,defaultProp:s??!1,onChange:l,caller:Cg});return o.jsx(du,{...d,children:o.jsx(UW,{scope:t,contentId:Mn(),triggerRef:h,open:v,onOpenChange:x,onOpenToggle:p.useCallback(()=>x(b=>!b),[x]),hasCustomAnchor:m,onCustomAnchorAdd:p.useCallback(()=>g(!0),[]),onCustomAnchorRemove:p.useCallback(()=>g(!1),[]),modal:c,children:n})})};QD.displayName=Cg;var WD="PopoverAnchor",FW=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Vi(WD,n),l=Lf(n),{onCustomAnchorAdd:c,onCustomAnchorRemove:d}=s;return p.useEffect(()=>(c(),()=>d()),[c,d]),o.jsx(fu,{...l,...r,ref:t})});FW.displayName=WD;var XD="PopoverTrigger",JD=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Vi(XD,n),l=Lf(n),c=vt(t,s.triggerRef),d=o.jsx(Ye.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":aO(s.open),...r,ref:c,onClick:je(e.onClick,s.onOpenToggle)});return s.hasCustomAnchor?d:o.jsx(fu,{asChild:!0,...l,children:d})});JD.displayName=XD;var TS="PopoverPortal",[zW,VW]=YD(TS,{forceMount:void 0}),eO=e=>{const{__scopePopover:t,forceMount:n,children:r,container:s}=e,l=Vi(TS,t);return o.jsx(zW,{scope:t,forceMount:n,children:o.jsx(_r,{present:n||l.open,children:o.jsx(Al,{asChild:!0,container:s,children:r})})})};eO.displayName=TS;var nu="PopoverContent",tO=p.forwardRef((e,t)=>{const n=VW(nu,e.__scopePopover),{forceMount:r=n.forceMount,...s}=e,l=Vi(nu,e.__scopePopover);return o.jsx(_r,{present:r||l.open,children:l.modal?o.jsx($W,{...s,ref:t}):o.jsx(BW,{...s,ref:t})})});tO.displayName=nu;var HW=Si("PopoverContent.RemoveScroll"),$W=p.forwardRef((e,t)=>{const n=Vi(nu,e.__scopePopover),r=p.useRef(null),s=vt(t,r),l=p.useRef(!1);return p.useEffect(()=>{const c=r.current;if(c)return kp(c)},[]),o.jsx(ff,{as:HW,allowPinchZoom:!0,children:o.jsx(nO,{...e,ref:s,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:je(e.onCloseAutoFocus,c=>{var d;c.preventDefault(),l.current||(d=n.triggerRef.current)==null||d.focus()}),onPointerDownOutside:je(e.onPointerDownOutside,c=>{const d=c.detail.originalEvent,h=d.button===0&&d.ctrlKey===!0,m=d.button===2||h;l.current=m},{checkForDefaultPrevented:!1}),onFocusOutside:je(e.onFocusOutside,c=>c.preventDefault(),{checkForDefaultPrevented:!1})})})}),BW=p.forwardRef((e,t)=>{const n=Vi(nu,e.__scopePopover),r=p.useRef(!1),s=p.useRef(!1);return o.jsx(nO,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{var c,d;(c=e.onCloseAutoFocus)==null||c.call(e,l),l.defaultPrevented||(r.current||(d=n.triggerRef.current)==null||d.focus(),l.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:l=>{var h,m;(h=e.onInteractOutside)==null||h.call(e,l),l.defaultPrevented||(r.current=!0,l.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const c=l.target;((m=n.triggerRef.current)==null?void 0:m.contains(c))&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&s.current&&l.preventDefault()}})}),nO=p.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:l,disableOutsidePointerEvents:c,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:m,onInteractOutside:g,...v}=e,x=Vi(nu,n),b=Lf(n);return Op(),o.jsx(df,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:l,children:o.jsx(Nl,{asChild:!0,disableOutsidePointerEvents:c,onInteractOutside:g,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:m,onDismiss:()=>x.onOpenChange(!1),children:o.jsx(mf,{"data-state":aO(x.open),role:"dialog",id:x.contentId,...b,...v,ref:t,style:{...v.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),rO="PopoverClose",GW=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Vi(rO,n);return o.jsx(Ye.button,{type:"button",...r,ref:t,onClick:je(e.onClick,()=>s.onOpenChange(!1))})});GW.displayName=rO;var qW="PopoverArrow",ZW=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Lf(n);return o.jsx(pf,{...s,...r,ref:t})});ZW.displayName=qW;function aO(e){return e?"open":"closed"}var KW=QD,YW=JD,QW=eO,WW=tO;function jS({...e}){return o.jsx(KW,{"data-slot":"popover",...e})}function _S({...e}){return o.jsx(YW,{"data-slot":"popover-trigger",...e})}function NS({className:e,align:t="center",sideOffset:n=4,...r}){return o.jsx(QW,{children:o.jsx(WW,{"data-slot":"popover-content",align:t,sideOffset:n,className:fe("bg-popover text-popover-foreground 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 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",e),...r})})}function AS({options:e,value:t,onValueChange:n,placeholder:r="Select an option",emptyMessage:s="No results found.",className:l,disabled:c=!1}){const[d,h]=p.useState(!1),[m,g]=p.useState(""),v=p.useMemo(()=>{const E={};return e.forEach(C=>{const w=C.group??"";Object.prototype.hasOwnProperty.call(E,w)||(E[w]=[]),E[w].push(C)}),E},[e]),x=e.find(E=>E.value===t),b=p.useCallback(E=>{n(E),requestAnimationFrame(()=>{g(""),h(!1)})},[n]);return o.jsxs(jS,{open:d,onOpenChange:h,modal:!0,children:[o.jsx(_S,{asChild:!0,children:o.jsxs(we,{variant:"outline",role:"combobox","aria-expanded":d,className:fe("w-full justify-between",!t&&"text-muted-foreground",l),disabled:c,children:[x?x.label:r,o.jsx(ib,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),o.jsx(NS,{className:"max-h-[300px] min-w-[300px] overflow-auto p-0",align:"start",sideOffset:5,children:o.jsxs(BD,{children:[o.jsx(GD,{placeholder:`Search ${r.toLowerCase()}...`,value:m,onValueChange:g}),o.jsx(qD,{children:s}),Object.entries(v).map(([E,C])=>o.jsx(ZD,{heading:E,children:C.map(w=>o.jsxs(KD,{value:w.value,onSelect:()=>{b(w.value)},keywords:[w.label],children:[o.jsx(yr,{className:fe("mr-2 h-4 w-4",t===w.value?"opacity-100":"opacity-0")}),w.label]},w.value))},E||"default"))]})})]})}var Eg="Collapsible",[XW,sO]=Fr(Eg),[JW,DS]=XW(Eg),oO=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:s,disabled:l,onOpenChange:c,...d}=e,[h,m]=Jr({prop:r,defaultProp:s??!1,onChange:c,caller:Eg});return o.jsx(JW,{scope:n,disabled:l,contentId:Mn(),open:h,onOpenToggle:p.useCallback(()=>m(g=>!g),[m]),children:o.jsx(Ye.div,{"data-state":MS(h),"data-disabled":l?"":void 0,...d,ref:t})})});oO.displayName=Eg;var iO="CollapsibleTrigger",lO=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,s=DS(iO,n);return o.jsx(Ye.button,{type:"button","aria-controls":s.contentId,"aria-expanded":s.open||!1,"data-state":MS(s.open),"data-disabled":s.disabled?"":void 0,disabled:s.disabled,...r,ref:t,onClick:je(e.onClick,s.onOpenToggle)})});lO.displayName=iO;var OS="CollapsibleContent",cO=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,s=DS(OS,e.__scopeCollapsible);return o.jsx(_r,{present:n||s.open,children:({present:l})=>o.jsx(eX,{...r,ref:t,present:l})})});cO.displayName=OS;var eX=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:s,...l}=e,c=DS(OS,n),[d,h]=p.useState(r),m=p.useRef(null),g=vt(t,m),v=p.useRef(0),x=v.current,b=p.useRef(0),E=b.current,C=c.open||d,w=p.useRef(C),R=p.useRef(void 0);return p.useEffect(()=>{const T=requestAnimationFrame(()=>w.current=!1);return()=>cancelAnimationFrame(T)},[]),xr(()=>{const T=m.current;if(T){R.current=R.current||{transitionDuration:T.style.transitionDuration,animationName:T.style.animationName},T.style.transitionDuration="0s",T.style.animationName="none";const j=T.getBoundingClientRect();v.current=j.height,b.current=j.width,w.current||(T.style.transitionDuration=R.current.transitionDuration,T.style.animationName=R.current.animationName),h(r)}},[c.open,r]),o.jsx(Ye.div,{"data-state":MS(c.open),"data-disabled":c.disabled?"":void 0,id:c.contentId,hidden:!C,...l,ref:g,style:{"--radix-collapsible-content-height":x?`${x}px`:void 0,"--radix-collapsible-content-width":E?`${E}px`:void 0,...e.style},children:C&&s})});function MS(e){return e?"open":"closed"}var tX=oO,nX=lO,rX=cO,ms="Accordion",aX=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[kS,sX,oX]=Zp(ms),[wg]=Fr(ms,[oX,sO]),IS=sO(),uO=_e.forwardRef((e,t)=>{const{type:n,...r}=e,s=r,l=r;return o.jsx(kS.Provider,{scope:e.__scopeAccordion,children:n==="multiple"?o.jsx(uX,{...l,ref:t}):o.jsx(cX,{...s,ref:t})})});uO.displayName=ms;var[dO,iX]=wg(ms),[fO,lX]=wg(ms,{collapsible:!1}),cX=_e.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},collapsible:l=!1,...c}=e,[d,h]=Jr({prop:n,defaultProp:r??"",onChange:s,caller:ms});return o.jsx(dO,{scope:e.__scopeAccordion,value:_e.useMemo(()=>d?[d]:[],[d]),onItemOpen:h,onItemClose:_e.useCallback(()=>l&&h(""),[l,h]),children:o.jsx(fO,{scope:e.__scopeAccordion,collapsible:l,children:o.jsx(hO,{...c,ref:t})})})}),uX=_e.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},...l}=e,[c,d]=Jr({prop:n,defaultProp:r??[],onChange:s,caller:ms}),h=_e.useCallback(g=>d((v=[])=>[...v,g]),[d]),m=_e.useCallback(g=>d((v=[])=>v.filter(x=>x!==g)),[d]);return o.jsx(dO,{scope:e.__scopeAccordion,value:c,onItemOpen:h,onItemClose:m,children:o.jsx(fO,{scope:e.__scopeAccordion,collapsible:!0,children:o.jsx(hO,{...l,ref:t})})})}),[dX,Rg]=wg(ms),hO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,disabled:r,dir:s,orientation:l="vertical",...c}=e,d=_e.useRef(null),h=vt(d,t),m=sX(n),v=Kp(s)==="ltr",x=je(e.onKeyDown,b=>{var k;if(!aX.includes(b.key))return;const E=b.target,C=m().filter(U=>{var B;return!((B=U.ref.current)!=null&&B.disabled)}),w=C.findIndex(U=>U.ref.current===E),R=C.length;if(w===-1)return;b.preventDefault();let T=w;const j=0,O=R-1,D=()=>{T=w+1,T>O&&(T=j)},N=()=>{T=w-1,T<j&&(T=O)};switch(b.key){case"Home":T=j;break;case"End":T=O;break;case"ArrowRight":l==="horizontal"&&(v?D():N());break;case"ArrowDown":l==="vertical"&&D();break;case"ArrowLeft":l==="horizontal"&&(v?N():D());break;case"ArrowUp":l==="vertical"&&N();break}const A=T%R;(k=C[A].ref.current)==null||k.focus()});return o.jsx(dX,{scope:n,disabled:r,direction:s,orientation:l,children:o.jsx(kS.Slot,{scope:n,children:o.jsx(Ye.div,{...c,"data-orientation":l,ref:h,onKeyDown:r?void 0:x})})})}),xp="AccordionItem",[fX,LS]=wg(xp),mO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,value:r,...s}=e,l=Rg(xp,n),c=iX(xp,n),d=IS(n),h=Mn(),m=r&&c.value.includes(r)||!1,g=l.disabled||e.disabled;return o.jsx(fX,{scope:n,open:m,disabled:g,triggerId:h,children:o.jsx(tX,{"data-orientation":l.orientation,"data-state":bO(m),...d,...s,ref:t,disabled:g,open:m,onOpenChange:v=>{v?c.onItemOpen(r):c.onItemClose(r)}})})});mO.displayName=xp;var pO="AccordionHeader",gO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Rg(ms,n),l=LS(pO,n);return o.jsx(Ye.h3,{"data-orientation":s.orientation,"data-state":bO(l.open),"data-disabled":l.disabled?"":void 0,...r,ref:t})});gO.displayName=pO;var P0="AccordionTrigger",vO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Rg(ms,n),l=LS(P0,n),c=lX(P0,n),d=IS(n);return o.jsx(kS.ItemSlot,{scope:n,children:o.jsx(nX,{"aria-disabled":l.open&&!c.collapsible||void 0,"data-orientation":s.orientation,id:l.triggerId,...d,...r,ref:t})})});vO.displayName=P0;var yO="AccordionContent",xO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Rg(ms,n),l=LS(yO,n),c=IS(n);return o.jsx(rX,{role:"region","aria-labelledby":l.triggerId,"data-orientation":s.orientation,...c,...r,ref:t,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...e.style}})});xO.displayName=yO;function bO(e){return e?"open":"closed"}var hX=uO,mX=mO,pX=gO,gX=vO,vX=xO;const PS={default:{itemClass:"border-b last:border-b-0",triggerClass:"focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",icon:null,chevronClass:"text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200",contentClass:"data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm",contentInnerClass:"pt-0 pb-4",headerClass:"flex"},common:{itemClass:"overflow-hidden",triggerClass:"group focus-visible:ring-primary hover:bg-muted [&[data-state=open]]:bg-muted flex items-center gap-1 rounded-sm px-2 py-1 transition-all outline-none focus-visible:ring-2 [&[data-state=open]]:rounded-br-none [&[data-state=open]]:rounded-bl-none [&[data-state=open]]:font-semibold",icon:o.jsx(xj,{className:"size-4 shrink-0","aria-hidden":"true"}),chevronClass:"size-3.5 shrink-0 transition-transform duration-200 group-data-[state=open]:rotate-180",contentClass:"data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down bg-muted overflow-hidden rounded-sm rounded-tl-none py-0 pr-2 pl-7 text-sm",contentInnerClass:"pt-2 pb-4",headerClass:void 0}},SO=p.createContext("default");function cr({variant:e="default",...t}){return o.jsx(SO.Provider,{value:e,children:o.jsx(hX,{"data-slot":"accordion",...t})})}function US(e){const t=p.useContext(SO);return e??t??"default"}function Gn({className:e,variant:t,...n}){const r=US(t),{itemClass:s}=PS[r];return o.jsx(mX,{"data-slot":"accordion-item",className:fe(s,e),...n})}function qn({className:e,children:t,variant:n,...r}){const s=US(n),{triggerClass:l,icon:c,chevronClass:d,headerClass:h}=PS[s];return o.jsx(pX,{className:h,children:o.jsxs(gX,{"data-slot":"accordion-trigger",className:fe(l,e),...r,children:[c,t,o.jsx(Ga,{className:d,"aria-hidden":"true"})]})})}function Zn({className:e,children:t,variant:n,...r}){const s=US(n),{contentClass:l,contentInnerClass:c}=PS[s];return o.jsx(vX,{"data-slot":"accordion-content",className:fe(l,e),...r,children:o.jsx("div",{className:c,children:t})})}function Bn({href:e,children:t,className:n,...r}){return o.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:fe("text-muted-foreground hover:bg-muted inline-flex items-center px-1 font-medium hover:rounded-md",n),...r,children:[t,o.jsx(cf,{className:"ml-1 inline h-3 w-3","aria-hidden":"true"})]})}function yX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"service-account-details",children:[o.jsx(qn,{children:"How do I get a Service Account JSON key?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"To get the JSON key, you'll need to create or use an existing service account in Google Cloud."}),o.jsx("p",{className:"mb-2",children:"Here's what to do:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Go to"," ",o.jsx(Bn,{className:"underline",href:"https://console.cloud.google.com/iam-admin/serviceaccounts",children:"Google Cloud Console"}),"."]}),o.jsxs("li",{children:["Open ",o.jsx("strong",{children:"IAM & Admin → Service Accounts"}),"."]}),o.jsx("li",{children:"Create a new service account or select an existing one."}),o.jsxs("li",{children:["Assign the ",o.jsx("strong",{children:"bigquery.dataEditor"})," and ",o.jsx("strong",{children:"bigquery.jobUser"})," ","roles to this service account to allow read, write, and create access to your project resources."]}),o.jsxs("li",{children:["Open the Service Accounts page, go to the ",o.jsx("strong",{children:"Keys"})," tab, click"," ",o.jsx("strong",{children:"Add key"}),", and select ",o.jsx("strong",{children:"Create new key"}),"."]}),o.jsxs("li",{children:["Choose ",o.jsx("strong",{children:"JSON"})," format and click ",o.jsx("strong",{children:"Create"}),"."]}),o.jsx("li",{children:"Open the downloaded file, copy its entire content, and paste it into the field above."})]})]})]})})}function xX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"project-id-details",children:[o.jsx(qn,{children:"How do I find my Project ID?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"This is the ID of your Google Cloud project. BigQuery usage costs will be charged to this project."}),o.jsx("p",{className:"mb-2",children:"Here's how to find your billing project ID:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.cloud.google.com/",children:"Google Cloud Console"})," ","and sign in with your Google account."]}),o.jsx("li",{children:'Click the project selector dropdown at the top of the page (it shows the current project name or "Select a project").'}),o.jsxs("li",{children:["Find your project in the list. The ",o.jsx("strong",{children:"Project ID"})," is shown in the ID column."]}),o.jsx("li",{children:"If you don't see your project, use the search box to find it by name or ID."})]})]})]})})}function bX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"gbq-location-details",children:[o.jsx(qn,{children:"How do I find my dataset location?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"BigQuery data is stored in specific regions. To avoid query errors, your SQL queries must process data stored in the same location."}),o.jsx("p",{className:"mb-2",children:"Here's how to check your dataset location:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.cloud.google.com/bigquery",children:"Google Cloud Console BigQuery page"}),"."]}),o.jsx("li",{children:"In the left panel, expand your project and find your datasets."}),o.jsxs("li",{children:["Click each dataset name to open its details. The ",o.jsx("strong",{children:"Data location"})," field shows the region where that dataset is stored (for example,"," ",o.jsx("code",{className:"text-sm font-semibold",children:"US"}),","," ",o.jsx("code",{className:"text-sm font-semibold",children:"EU"}),","," ",o.jsx("code",{className:"text-sm font-semibold",children:"asia-northeast1"}),")."]}),o.jsx("li",{children:"Make sure all your datasets are stored in the same location. If they are in different locations, select the location where most of your data is stored or create separate Storage for each location."}),o.jsx("li",{children:"Put this location value in the field above."})]})]})]})})}const CO=e=>{try{const t=JSON.parse(e),{project_id:n,client_id:r,client_email:s}=t;return!n||!r||!s?null:{url:`https://console.cloud.google.com/iam-admin/serviceaccounts/details/${r}?project=${n}`,email:s}}catch{return null}},SX=({form:e})=>{const[t,n]=p.useState(!1);if(e.watch("type")!==Pe.GOOGLE_BIGQUERY)return null;const r=()=>{n(!0),e.setValue("credentials.serviceAccount","",{shouldDirty:!0})},s=()=>{n(!1),e.resetField("credentials.serviceAccount")},l=e.watch("credentials.serviceAccount"),c=l?CO(l):null;return o.jsxs(o.Fragment,{children:[o.jsxs(Ps,{title:"Connection Settings",children:[o.jsx(Kt,{control:e.control,name:"config.projectId",render:({field:d})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Enter the ID of your Google Cloud project where BigQuery usage will be billed",children:"Project ID"}),o.jsx(Wt,{children:o.jsx(Zt,{...d,placeholder:"Enter a Project Id"})}),o.jsx(tr,{children:o.jsx(xX,{})}),o.jsx(nn,{})]})}),o.jsx(Kt,{control:e.control,name:"config.location",render:({field:d})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Choose the same region where your BigQuery data is stored to ensure queries work correctly",children:"Location"}),o.jsx(Wt,{children:o.jsx(AS,{options:ZB,value:d.value,onValueChange:d.onChange,placeholder:"Select a location",emptyMessage:"No locations found",className:"w-full"})}),o.jsx(tr,{children:o.jsx(bX,{})}),o.jsx(nn,{})]})})]}),o.jsx(Ps,{title:"Authentication",children:o.jsx(Kt,{control:e.control,name:"credentials.serviceAccount",render:({field:d})=>o.jsxs(Yt,{children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(Qt,{tooltip:"Paste a JSON key from a service account that has access to the selected storage provider",children:"Service Account"}),!t&&l&&o.jsx(we,{variant:"ghost",size:"sm",onClick:r,type:"button",children:"Edit"}),t&&o.jsx(we,{variant:"ghost",size:"sm",onClick:s,type:"button",children:"Cancel"})]}),o.jsx(Wt,{children:!t&&c?o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(Bn,{href:c.url,children:c.email})}),o.jsx(Ot,{children:o.jsx("p",{children:"View in Google Cloud Console"})})]}):o.jsx(wi,{...d,className:"min-h-[150px] font-mono",rows:8,placeholder:"Paste your service account JSON here"})}),o.jsx(tr,{children:o.jsx(yX,{})}),o.jsx(nn,{})]})})})]})};function CX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"athena-region-details",children:[o.jsx(qn,{children:"How do I find my Athena region?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"Athena queries run in a specific AWS region. You must select the region where your Athena service and data are located."}),o.jsx("p",{className:"mb-2",children:"Here's how to find your Athena region:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.aws.amazon.com/athena/",children:"the AWS Athena console"}),"."]}),o.jsx("li",{children:"Look at the top right corner of the console. The selected region is shown in the region selector dropdown."}),o.jsx("li",{children:"Make sure to copy and paste the same region here in the form to avoid connection or query errors."})]})]})]})})}function EX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"athena-output-bucket-details",children:[o.jsx(qn,{children:"How do I find a bucket?"}),o.jsxs(Zn,{children:[o.jsxs("p",{className:"mb-2",children:["Athena saves query results in an ",o.jsx("strong",{children:"S3 bucket"}),". You need to specify the bucket used for query output."]}),o.jsx("p",{className:"mb-2",children:"Here's how to find or create an S3 bucket for Athena output:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.aws.amazon.com/s3/",children:"the AWS S3 console"}),"."]}),o.jsx("li",{children:"Look for an existing bucket used for Athena query results, or create a new one."}),o.jsx("li",{children:"If creating a new bucket, make sure it is in the same region as your Athena service."}),o.jsx("li",{children:"Enter the bucket name in this form field."})]})]})]})})}function wX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"athena-access-key-id-details",children:[o.jsx(qn,{children:"How do I get my AWS Access Key ID?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"Before accessing your AWS Access Key ID, make sure you have a user with the necessary permissions to use Athena and Glue in your AWS account."}),o.jsxs("p",{className:"mb-4 text-sm",children:["Learn more about how to create a user in AWS ",o.jsx(Bn,{className:"underline",href:"https://docs.owox.com/docs/storages/supported-storages/aws-athena/?utm_source=owox_data_marts&utm_medium=storage_enity&utm_campaign=tooltip_aws",children:"in documentation"}),"."]}),o.jsx(Ij,{className:"my-4"}),o.jsx("p",{className:"mb-2",children:"The Access Key ID is part of your AWS credentials needed to connect and authenticate."}),o.jsx("p",{className:"mb-2",children:"Here's how to find or create an Access Key ID:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.aws.amazon.com/iam/home#/security_credentials",children:"the AWS IAM Security Credentials page"}),"."]}),o.jsxs("li",{children:["Under ",o.jsx("strong",{children:"Access keys"}),", find your existing keys or create a new access key."]}),o.jsx("li",{children:"When you create a new key, download and securely store the Access Key ID and Secret Access Key."})]})]})]})})}function RX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"athena-secret-access-key-details",children:[o.jsx(qn,{children:"How do I get my AWS Secret Access Key?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"The Secret Access Key is part of your AWS credentials needed to connect and authenticate. It is only shown when you create a new key."}),o.jsx("p",{className:"mb-2",children:"Here's how to get your Secret Access Key:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.aws.amazon.com/iam/home#/security_credentials",children:"the AWS IAM Security Credentials page"}),"."]}),o.jsxs("li",{children:["Under ",o.jsx("strong",{children:"Access keys"}),", create a new access key if you don't have one or lost the secret key."]}),o.jsx("li",{children:"When you create a new key, copy and securely store the Secret Access Key — you won't be able to see it again."})]})]})]})})}const TX=({form:e})=>{const[t,n]=p.useState("");return p.useEffect(()=>{const r=e.getValues("credentials.accessKeyId");if(r){const s="_".repeat(r.length);n(s),e.setValue("credentials.secretAccessKey",s,{shouldDirty:!1})}},[e]),e.watch("type")!==Pe.AWS_ATHENA?null:o.jsxs(o.Fragment,{children:[o.jsxs(Ps,{title:"Connection Settings",children:[o.jsx(Kt,{control:e.control,name:"config.region",render:({field:r})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Enter the AWS region where your Athena service is active",children:"Region"}),o.jsx(Wt,{children:o.jsx(Zt,{...r,placeholder:"Enter a region"})}),o.jsx(tr,{children:o.jsx(CX,{})}),o.jsx(nn,{})]})}),o.jsx(Kt,{control:e.control,name:"config.outputBucket",render:({field:r})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Specify the S3 bucket where Athena query results will be stored",children:"Output Bucket"}),o.jsx(Wt,{children:o.jsx(Zt,{...r,placeholder:"Enter an output bucket"})}),o.jsx(tr,{children:o.jsx(EX,{})}),o.jsx(nn,{})]})})]}),o.jsxs(Ps,{title:"Authentication",children:[o.jsx(Kt,{control:e.control,name:"credentials.accessKeyId",render:({field:r})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Your AWS Access Key ID used for authentication",children:"Access Key ID"}),o.jsx(Wt,{children:o.jsx(Zt,{...r,placeholder:"Enter an access key id"})}),o.jsx(tr,{children:o.jsx(wX,{})}),o.jsx(nn,{})]})}),o.jsx(Kt,{control:e.control,name:"credentials.secretAccessKey",render:({field:r})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Your AWS Secret Access Key used for authentication",children:"Secret Access Key"}),o.jsx(Wt,{children:o.jsx(Zt,{...r,type:"password",placeholder:t||"Enter a secret access key"})}),o.jsx(tr,{children:o.jsx(RX,{})}),o.jsx(nn,{})]})})]})]})};function jX(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"bigquery-api-details",children:[o.jsx(qn,{children:"How do I enable the BigQuery API?"}),o.jsxs(Zn,{children:[o.jsxs("p",{className:"mb-2",children:["To run queries and process data in Google BigQuery, you need to enable the"," ",o.jsx(Bn,{className:"underline",href:"https://console.cloud.google.com/apis/library/bigquery.googleapis.com",children:"BigQuery API"})," ","in your Google Cloud project."]}),o.jsx("p",{className:"mb-2",children:"Here's how to do it:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsx("li",{children:"Open the link above and make sure the correct project is selected."}),o.jsxs("li",{children:["If the API isn't enabled yet, click ",o.jsx("strong",{children:"Enable"}),"."]}),o.jsx("li",{children:"If it's already enabled, you'll see the API dashboard — that's fine."})]})]})]})})}function _X(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"athena-api-details",children:[o.jsx(qn,{children:"How do I activate Athena API?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"AWS Athena is a serverless interactive query service. To use it, you need to activate Athena in your AWS account."}),o.jsx("p",{className:"mb-2",children:"Here's how to activate Athena:"}),o.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[o.jsxs("li",{children:["Open"," ",o.jsx(Bn,{className:"underline",href:"https://console.aws.amazon.com/athena/",children:"the AWS Athena console"})," ","and sign in to your AWS account."]}),o.jsx("li",{children:"If you haven't used Athena before, you may need to set up a query result location (an S3 bucket)."}),o.jsx("li",{children:"You can start running queries immediately after setup."})]})]})]})})}function EO(e){return JSON.parse(JSON.stringify(e))}function NX({initialData:e,onSubmit:t,onCancel:n,onDirtyChange:r}){const s=Pi({resolver:zl(fG),defaultValues:e}),{watch:l,control:c,formState:{isDirty:d,isSubmitting:h}}=s,m=l("type");_e.useEffect(()=>{r==null||r(d)},[d,r]);const g=async v=>{const{dirtyFields:x}=s.formState,b=EO(v);return x.credentials||delete b.credentials,t(b)};return o.jsx(Pl,{...s,children:o.jsxs(Ui,{onSubmit:v=>{s.handleSubmit(g)(v)},noValidate:!0,children:[o.jsxs(Ul,{children:[o.jsxs(Ps,{title:"General",children:[o.jsx(Kt,{control:c,name:"title",render:({field:v})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Name the storage to clarify its purpose",children:"Title"}),o.jsx(Wt,{children:o.jsx(Zt,{...v,placeholder:"Storage title"})}),o.jsx(nn,{})]})}),o.jsx(Kt,{control:c,name:"type",render:({field:v})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"The selected source will be used to process data in your Data Marts",children:"Storage Type"}),o.jsx(Wt,{children:o.jsxs(ba,{value:v.value,onValueChange:v.onChange,disabled:!!e,children:[o.jsx(Ca,{className:"w-full",children:o.jsx(Sa,{placeholder:"Select a storage type"})}),o.jsx(Ea,{children:o.jsx(yg,{children:Ii.getAllTypes().map(({type:x,displayName:b,icon:E,status:C})=>o.jsx(Hn,{value:x,disabled:C===po.COMING_SOON,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(E,{size:20}),b]})},x))})})]})}),o.jsxs(tr,{children:[m===Pe.GOOGLE_BIGQUERY&&o.jsx(jX,{}),m===Pe.AWS_ATHENA&&o.jsx(_X,{})]}),o.jsx(nn,{})]})})]}),m===Pe.GOOGLE_BIGQUERY&&o.jsx(SX,{form:s}),m===Pe.AWS_ATHENA&&o.jsx(TX,{form:s})]}),o.jsxs(Fl,{children:[o.jsx(we,{variant:"default",type:"submit",className:"w-full","aria-label":"Save",disabled:!d||h,children:"Save"}),o.jsx(we,{variant:"outline",type:"button",onClick:n,className:"w-full","aria-label":"Cancel",children:"Cancel"})]})]})})}function wO({isOpen:e,onClose:t,dataStorage:n,onSaveSuccess:r}){const{updateDataStorage:s}=xg(),[l,c]=p.useState(!1),[d,h]=p.useState(!1),m=p.useCallback(()=>{d?c(!0):t()},[d,t]),g=p.useCallback(()=>{c(!1),h(!1),t()},[t]),v=p.useCallback(b=>{h(b)},[]),x=async b=>{if(n){const E=await s(n.id,b);E&&(r(E),t())}};return o.jsxs(o.Fragment,{children:[o.jsx(Ai,{open:e,onOpenChange:b=>{b||m()},children:o.jsxs(Di,{children:[o.jsxs(Oi,{children:[o.jsx(Dl,{children:"Configure Storage Provider"}),o.jsx(lu,{children:"Customize settings for your storage provider"})]}),o.jsx(NX,{initialData:n??void 0,onSubmit:x,onCancel:m,onDirtyChange:v})]})}),o.jsx(ya,{open:l,onOpenChange:c,title:"Unsaved Changes",description:"You have unsaved changes. Exit without saving?",confirmLabel:"Yes, leave now",cancelLabel:"No, stay here",onConfirm:g,variant:"destructive"})]})}const AX=({dataStorage:e,onDataStorageChange:t})=>{const[n,r]=p.useState(!1),s=Ii.getInfo(e.type),l=()=>{r(!0)},c=()=>{r(!1)},d=()=>{if(!(()=>{switch(e.type){case Pe.GOOGLE_BIGQUERY:return!!(e.config.projectId&&e.config.location);case Pe.AWS_ATHENA:return!!(e.config.region&&e.config.outputBucket);default:return!1}})())return o.jsxs("div",{className:"flex items-center space-x-2 text-sm",children:[o.jsx(Dp,{className:"h-4 w-4 text-red-500"}),o.jsx("span",{className:"text-red-500",children:"Storage configuration is incomplete"})]});const m=(v,x)=>o.jsxs("span",{children:[o.jsxs("span",{className:"text-muted-foreground/75",children:[v,":"]})," ",o.jsx("span",{className:"text-muted-foreground font-medium",children:x})]}),g=(v,x,b)=>o.jsxs("span",{children:[o.jsxs("span",{className:"text-muted-foreground/75",children:[v,":"]})," ",o.jsx(Bn,{href:b,onClick:E=>{E.stopPropagation()},children:x})]});switch(e.type){case Pe.GOOGLE_BIGQUERY:{const v=e.config.projectId,x=e.config.location,b=`https://console.cloud.google.com/bigquery?project=${v}`;return o.jsxs("div",{className:"flex flex-wrap gap-2",children:[g("Project ID",v,b),o.jsx("span",{className:"text-muted-foreground",children:"•"}),m("Location",x)]})}case Pe.AWS_ATHENA:{const v=e.config.region,x=e.config.outputBucket,b=`https://s3.console.aws.amazon.com/s3/buckets/${x}?region=${v}`;return o.jsxs("div",{className:"flex flex-wrap gap-2",children:[m("Region",v),o.jsx("span",{className:"text-muted-foreground",children:"•"}),g("Bucket",x,b)]})}default:return"Unknown storage type configuration"}};return o.jsxs(o.Fragment,{children:[o.jsx(k0,{title:e.title,icon:s.icon,subtitle:d(),onClick:l}),o.jsx(wS,{children:o.jsx(wO,{isOpen:n,onClose:c,dataStorage:e,onSaveSuccess:h=>{t&&t(h)}})})]})};function DX({initialType:e,onTypeSelect:t}){var c;const[n,r]=p.useState(e??null),s=d=>{r(d),t(d)},l=[{type:Qe.SQL,label:"SQL",description:"SQL query"},{type:Qe.TABLE,label:"Table",description:"Existing table"},{type:Qe.VIEW,label:"View",description:"Existing view"},{type:Qe.TABLE_PATTERN,label:"Pattern",description:"Table pattern"},{type:Qe.CONNECTOR,label:"Connector",description:"Data import from Source to Storage"}];return o.jsxs("div",{className:"dm-card-block",children:[o.jsx(xa,{className:"text-foreground",children:"Definition Type"}),o.jsxs(ba,{value:n??"",onValueChange:d=>{s(d)},children:[o.jsx(Ca,{className:"dm-card-formcontrol w-full","aria-label":"Definition Type",children:o.jsx(Sa,{placeholder:"Select definition type",children:n&&((c=l.find(d=>d.type===n))==null?void 0:c.label)})}),o.jsx(Ea,{children:o.jsx(yg,{children:l.map(d=>o.jsxs(Hn,{value:d.type,children:[d.label,o.jsx("span",{className:"text-muted-foreground/80 ml-2",children:d.description})]},d.type))})})]})]})}const OX=en({definitionType:Vs(Qe.SQL),definition:en({sqlQuery:tn().min(1,"SQL query is required")})}),MX=e=>{const t=e4(e);return en({definitionType:Vs(Qe.TABLE),definition:t})},kX=e=>{const t=e4(e);return en({definitionType:Vs(Qe.VIEW),definition:t})},IX=e=>{const t=Rq(e);return en({definitionType:Vs(Qe.TABLE_PATTERN),definition:t})},LX=en({definitionType:Vs(Qe.CONNECTOR),definition:en({connector:en({source:en({name:tn().min(1,"Connector name is required"),configuration:N2(i$(s$())).min(1,"At least one configuration is required"),node:tn().min(1,"Node is required"),fields:N2(tn()).min(1,"At least one field is required")}),storage:en({fullyQualifiedName:tn().min(1,"fully qualified name is required")})})})}),PX=(e,t)=>{if(!e)return en({definitionType:l$(Bb(Qe)),definition:en({}).optional()});switch(e){case Qe.SQL:return OX;case Qe.TABLE:return MX(t);case Qe.VIEW:return kX(t);case Qe.TABLE_PATTERN:return IX(t);case Qe.CONNECTOR:return LX;default:return en({})}};function UX({control:e}){return o.jsx(Kt,{control:e,name:"definition.sqlQuery",render:({field:t})=>o.jsxs(Yt,{className:"dm-card-block",children:[o.jsx(Qt,{className:"text-foreground",children:"SQL Query"}),o.jsx(Wt,{children:o.jsx(fW,{initialValue:{sqlQuery:t.value},onChange:n=>{t.onChange(n.sqlQuery)}})}),o.jsx(nn,{})]})})}function FX({control:e,storageType:t}){const n=PA(t),r=UA(t);return o.jsx(Kt,{control:e,name:"definition.fullyQualifiedName",render:({field:s})=>o.jsxs(Yt,{className:"dm-card-block",children:[o.jsx(Qt,{children:"Fully Qualified Table Name"}),o.jsx(Wt,{children:o.jsx(Zt,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(tr,{className:"text-muted-foreground/75",children:r}),o.jsx(nn,{})]})})}function zX({control:e,storageType:t}){const n=PA(t),r=UA(t);return o.jsx(Kt,{control:e,name:"definition.fullyQualifiedName",render:({field:s})=>o.jsxs(Yt,{className:"dm-card-block",children:[o.jsx(Qt,{children:"Fully Qualified View Name"}),o.jsx(Wt,{children:o.jsx(Zt,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(tr,{className:"text-muted-foreground/75",children:r}),o.jsx(nn,{})]})})}function VX({control:e,storageType:t}){const n=vG(t),r=yG(t);return o.jsx(Kt,{control:e,name:"definition.pattern",render:({field:s})=>o.jsxs(Yt,{className:"dm-card-block",children:[o.jsx(Qt,{children:"Table Pattern"}),o.jsx(Wt,{children:o.jsx(Zt,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(tr,{className:"text-muted-foreground/75",children:r}),o.jsx(nn,{})]})})}const RO=e=>{switch(e){case Qe.SQL:return{sqlQuery:""};case Qe.TABLE:return{fullyQualifiedName:""};case Qe.VIEW:return{fullyQualifiedName:""};case Qe.TABLE_PATTERN:return{pattern:""};case Qe.CONNECTOR:return{connector:{source:{name:"",configuration:[],node:"",fields:[]},storage:{fullyQualifiedName:""}}};default:return{}}};function km({className:e,...t}){return o.jsx("div",{"data-slot":"card",className:fe("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",e),...t})}function Im({className:e,...t}){return o.jsx("div",{"data-slot":"card-header",className:fe("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",e),...t})}function U0({className:e,...t}){return o.jsx("div",{"data-slot":"card-title",className:fe("leading-none font-semibold",e),...t})}function HX({className:e,...t}){return o.jsx("div",{"data-slot":"card-description",className:fe("text-muted-foreground text-sm",e),...t})}function F0({className:e,...t}){return o.jsx("div",{"data-slot":"card-content",className:fe("px-6",e),...t})}function $X({className:e,...t}){return o.jsx("div",{"data-slot":"card-footer",className:fe("flex items-center px-6 [.border-t]:pt-6",e),...t})}const BX=lf("relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",{variants:{variant:{default:"bg-card text-card-foreground",destructive:"text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90"}},defaultVariants:{variant:"default"}});function FS({className:e,variant:t,...n}){return o.jsx("div",{"data-slot":"alert",role:"alert",className:fe(BX({variant:t}),e),...n})}function TO({className:e,...t}){return o.jsx("div",{"data-slot":"alert-title",className:fe("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",e),...t})}function zS({className:e,...t}){return o.jsx("div",{"data-slot":"alert-description",className:fe("text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",e),...t})}function GX({connectors:e,selectedConnector:t,loading:n,error:r,onConnectorSelect:s,onConnectorDoubleClick:l}){return n?o.jsx("div",{className:"space-y-4",children:o.jsx("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3",children:Array.from({length:6}).map((c,d)=>o.jsxs(km,{children:[o.jsxs(Im,{children:[o.jsx(ir,{className:"h-4 w-3/4"}),o.jsx(ir,{className:"h-3 w-1/2"})]}),o.jsx(F0,{children:o.jsx(ir,{className:"h-10 w-full"})})]},d))})}):r?o.jsxs(FS,{variant:"destructive",children:[o.jsx(au,{className:"h-4 w-4"}),o.jsx(zS,{children:"Failed to load available connectors. Please try again."})]}):o.jsxs("div",{className:"space-y-4",children:[o.jsx("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-2",children:e.map(c=>o.jsx(km,{className:`cursor-pointer transition-all duration-200 hover:shadow-md ${(t==null?void 0:t.name)===c.name?"ring-primary border-primary":"hover:border-muted-foreground/25"}`,onClick:()=>{s(c)},onDoubleClick:()=>{s(c),l==null||l(c)},children:o.jsx(Im,{children:o.jsx("div",{className:"flex items-center justify-between",children:o.jsxs("div",{className:"flex items-center gap-2",children:[c.logoBase64&&o.jsx(Tf,{base64:c.logoBase64,size:16}),o.jsx(U0,{className:"text-base",children:c.displayName})]})})})},c.name))}),e.length===0&&o.jsxs("div",{className:"py-8 text-center",children:[o.jsx(bj,{className:"text-muted-foreground mx-auto mb-4 h-12 w-12"}),o.jsx("h4",{className:"text-muted-foreground text-lg font-medium",children:"No connectors available"}),o.jsx("p",{className:"text-muted-foreground text-sm",children:"Contact your administrator to add connector configurations."})]}),o.jsx("div",{className:"flex flex-col gap-4",children:o.jsxs(km,{className:"bg-muted cursor-pointer transition-all duration-200 hover:shadow-md",children:[o.jsx(Im,{className:"pb-3",children:o.jsx(U0,{className:"text-base",children:"Custom code"})}),o.jsx(F0,{children:o.jsx("p",{className:"text-muted-foreground text-sm",children:"Coming soon..."})})]})})]})}function qX(e,t,n){const{name:r,title:s,requiredType:l,options:c,placeholder:d,default:h}=e,m=s??r,g=r;if(c&&c.length>0){const v=c.map(x=>({value:x,label:x}));return o.jsx(AS,{options:v,value:t[r]||h||"",onValueChange:x=>{n(r,x)},placeholder:d??`Select ${m.toLowerCase()}`,emptyMessage:"No options available",className:"w-full"})}switch(l){case Ts.BOOLEAN:return o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx("input",{type:"checkbox",id:g,name:r,checked:t[r]||h||!1,onChange:v=>{n(r,v.target.checked)},className:"text-primary focus:ring-primary border-border h-4 w-4 rounded"}),o.jsx(xa,{htmlFor:g,className:"cursor-pointer text-sm",children:m})]});case Ts.NUMBER:return o.jsx(Zt,{id:g,name:r,type:"number",value:t[r]||h||"",placeholder:d??`Enter ${m.toLowerCase()}`,onChange:v=>{const x=parseFloat(v.target.value)||0;n(r,x)}});case Ts.ARRAY:return o.jsx(wi,{id:g,name:r,value:Array.isArray(t[r])?t[r].join(`
|
|
704
704
|
`):Array.isArray(h)?h.join(`
|
|
705
705
|
`):"",placeholder:d??`Enter ${m.toLowerCase()} (one per line)`,rows:4,onChange:v=>{const x=v.target.value.split(`
|
|
706
706
|
`).filter(b=>b.trim());n(r,x)}});case Ts.OBJECT:return o.jsx(wi,{id:g,name:r,value:t[r]&&typeof t[r]=="object"?JSON.stringify(t[r],null,2):typeof h=="object"?JSON.stringify(h,null,2):"",placeholder:d??`Enter ${m.toLowerCase()} as JSON`,rows:6,className:"font-mono",onChange:v=>{try{const x=JSON.parse(v.target.value);n(r,x)}catch{n(r,v.target.value)}}});case Ts.DATE:{const v=x=>{if(!x||typeof x!="string"&&typeof x!="number")return"";const b=typeof x=="string"?x:x.toString();try{const E=new Date(b);return isNaN(E.getTime())?"":E.toISOString().split("T")[0]}catch{return""}};return o.jsx(Zt,{id:g,name:r,type:"date",value:t[r]||v(h)||"",placeholder:d??`Enter ${m.toLowerCase()}`,onChange:x=>{n(r,x.target.value)}})}case Ts.STRING:default:return o.jsx(Zt,{id:g,name:r,type:"text",value:t[r]||h||"",placeholder:d??`Enter ${m.toLowerCase()}`,onChange:v=>{n(r,v.target.value)}})}}function fT({connector:e,connectorSpecification:t,onConfigurationChange:n,onValidationChange:r,initialConfiguration:s,loading:l=!1}){const[c,d]=p.useState({}),h=p.useRef(!1),m=p.useRef(!1);p.useEffect(()=>{if(t){m.current=!0;const b={...s??{}};t.forEach(E=>{b[E.name]===void 0&&E.default!==void 0&&(b[E.name]=E.default)}),d(b),h.current=!0,setTimeout(()=>{m.current=!1},0)}},[t,s]),p.useEffect(()=>{h.current&&s&&Object.keys(s).length>0&&(m.current=!0,d(s),setTimeout(()=>{m.current=!1},0))},[s]),p.useEffect(()=>{h.current&&!m.current&&Object.keys(c).length>0&&(n==null||n(c))},[c,n]);const g=(b,E)=>{d(C=>({...C,[b]:E}))},v=(b,E)=>E.filter(w=>w.required&&w.showInUI!==!1&&w.name!=="Fields").every(w=>{const R=b[w.name];return!(R==null||typeof R=="string"&&R.trim()===""||Array.isArray(R)&&R.length===0)});if(p.useEffect(()=>{if(t&&r){const b=v(c,t);r(b)}},[c,t,r]),l)return o.jsxs("div",{className:"space-y-2",children:[o.jsx("h4",{className:"text-lg font-medium",children:"Configuration"}),o.jsx("p",{className:"text-muted-foreground mb-8 text-sm",children:"Loading connector configuration..."}),o.jsx("div",{className:"flex flex-col gap-4",children:Array.from({length:3}).map((b,E)=>o.jsxs("div",{className:"mb-2 space-y-1",children:[o.jsx(ir,{className:"h-4 w-32"}),o.jsx(ir,{className:"h-10 w-full"}),o.jsx(ir,{className:"h-3 w-48"})]},E))})]});if(!t||t.length===0)return null;const x=[...t].filter(b=>b.showInUI!==!1&&b.name!=="Fields").sort((b,E)=>{const C=w=>{const R=w.default!=null&&w.default!=="";return w.required&&!R?1:w.required&&R?2:!w.required&&!R?3:4};return C(b)-C(E)});return o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.logoBase64&&o.jsx(Tf,{base64:e.logoBase64,size:32}),o.jsxs("h4",{className:"text-lg font-medium",children:[e.displayName," configuration"]})]}),e.docUrl&&o.jsx("a",{href:e.docUrl,target:"_blank",rel:"noopener noreferrer",children:o.jsxs(we,{variant:"link",className:"mb-2 cursor-pointer text-sm",children:["View documentation ",o.jsx(cf,{className:"h-4 w-4"})]})}),o.jsx("div",{className:"flex flex-col gap-4",children:x.map(b=>o.jsxs("div",{className:"mb-2 space-y-1",children:[b.requiredType!==Ts.BOOLEAN&&o.jsxs(xa,{htmlFor:b.name,className:"group flex items-center justify-between gap-2 text-sm font-medium",children:[o.jsxs("span",{children:[b.title??b.name,b.required&&o.jsx("span",{className:"ml-1 text-red-500",children:"*"})]}),b.description&&o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx("button",{type:"button",tabIndex:-1,className:"opacity-60 transition-opacity hover:opacity-100","aria-label":"Help information",children:o.jsx(Xr,{className:"text-muted-foreground/50 hover:text-muted-foreground size-4 shrink-0 transition-colors","aria-hidden":"true"})})}),o.jsx(Ot,{side:"top",align:"center",role:"tooltip",children:b.description})]})]}),qX(b,c,g)]},b.name))})]})}function ZX({connectorFields:e,selectedField:t,connectorName:n,loading:r=!1,onFieldSelect:s}){const l=n?`Select node for ${n}`:"Select node";return r?o.jsxs("div",{className:"space-y-4",children:[o.jsx("h4",{className:"text-lg font-medium",children:l}),o.jsx("div",{className:"flex flex-col gap-4",children:Array.from({length:3}).map((c,d)=>o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx(ir,{className:"h-4 w-4 rounded-full"}),o.jsx(ir,{className:"h-4 w-32"})]},d))})]}):!e||e.length===0?o.jsxs("div",{className:"space-y-4",children:[o.jsx("h4",{className:"text-lg font-medium",children:l}),o.jsx("p",{className:"text-destructive text-sm",children:n?`No nodes found for ${n}`:"No nodes found"}),o.jsx("p",{className:"text-muted-foreground text-muted-foreground text-sm",children:"This connector might not be fully implemented yet or there could be other issues. Please create an issue on GitHub to report this problem."})]}):o.jsxs("div",{className:"space-y-4",children:[o.jsx("h4",{className:"text-lg font-medium",children:l}),o.jsxs("p",{className:"text-muted-foreground text-sm",children:["Can't find the node you need? Open an"," ",o.jsx(Bn,{href:"https://github.com/OWOX/owox-data-marts/issues",children:"issue here"}),"."]}),o.jsx("div",{className:"flex flex-col gap-4",children:e.map(c=>o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx("input",{type:"radio",id:c.name,name:"selectedField",value:c.name,className:"text-primary focus:ring-primary border-border h-4 w-4",onChange:d=>{s(d.target.value)},checked:t===c.name}),o.jsx("label",{htmlFor:c.name,className:"text-muted-foreground cursor-pointer text-sm",children:o.jsx("div",{className:"flex items-center gap-2",children:c.overview??c.name})}),c.name&&o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(Xr,{className:"text-muted-foreground/75 inline-block h-4 w-4 cursor-help"})}),o.jsxs(Ot,{children:[o.jsxs("p",{children:["Table name: ",c.destinationName??c.name]}),c.description&&o.jsx("p",{children:c.description}),c.documentation&&o.jsx("p",{children:c.documentation})]})]})]},c.name))})]})}var Rs=(e=>(e.ASC="asc",e.DESC="desc",e.ORIGINAL="original",e))(Rs||{});function hT({connectorFields:e,selectedField:t,selectedFields:n,onFieldToggle:r,onSelectAllFields:s}){const l=p.useRef(null),c=p.useRef(null),[d,h]=p.useState(""),[m,g]=p.useState(Rs.ORIGINAL),v=e==null?void 0:e.find(A=>A.name===t),x=p.useMemo(()=>(v==null?void 0:v.fields)??[],[v==null?void 0:v.fields]),b=p.useMemo(()=>(v==null?void 0:v.uniqueKeys)??[],[v==null?void 0:v.uniqueKeys]),E=p.useMemo(()=>{const A=new Map;return x.forEach((k,U)=>A.set(k.name,U)),A},[x]),C=p.useMemo(()=>{const A=x.filter(U=>U.name.toLowerCase().includes(d.toLowerCase().trim())),k=(U,B)=>{const H=b.includes(U.name),Q=b.includes(B.name);if(H&&!Q)return-1;if(!H&&Q)return 1;if(m===Rs.ASC)return U.name.localeCompare(B.name);if(m===Rs.DESC)return B.name.localeCompare(U.name);const ne=E.get(U.name)??0,G=E.get(B.name)??0;return ne-G};return[...A].sort(k)},[x,d,b,m,E]),w=x.map(A=>A.name),R=w.filter(A=>!b.includes(A)),T=n.filter(A=>R.includes(A)).length,j=n.filter(A=>w.includes(A)).length,O=R.length>0&&T===R.length,D=T>0&&T<R.length;if(p.useEffect(()=>{l.current&&(l.current.indeterminate=D)},[D]),p.useEffect(()=>{if(b.length>0){const A=b.filter(k=>x.some(U=>U.name===k)&&!n.includes(k));A.length>0&&A.forEach(k=>{r(k,!0)})}},[t,b,x,n,r]),!t||!e||!x.length)return null;const N=A=>{const k=A.target.checked;s?s(R,k):R.forEach(U=>{const B=n.includes(U);k&&!B?r(U,!0):!k&&B&&r(U,!1)})};return o.jsxs("div",{className:"space-y-4",children:[o.jsxs("h4",{className:"text-lg font-medium",children:["Selected field for node: ",t]}),o.jsxs("p",{className:"text-muted-foreground text-sm",children:["Can’t find the field you need? Open an"," ",o.jsx(Bn,{href:"https://github.com/OWOX/owox-data-marts/issues",children:"issue here"}),"."]}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"flex items-center justify-between gap-4",children:[o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx("input",{ref:l,type:"checkbox",id:"master-checkbox",className:"text-primary focus:ring-primary border-border h-4 w-4",checked:O,onChange:N}),o.jsxs("label",{htmlFor:"master-checkbox",className:"cursor-pointer text-sm font-medium",children:["Select all fields (",j,"/",w.length,")"]})]}),o.jsxs("div",{className:"flex items-center gap-2 pr-2",children:[o.jsxs("div",{className:"relative",children:[o.jsx(_l,{className:"text-muted-foreground absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 cursor-text",onClick:()=>{var A;(A=c.current)==null||A.focus()}}),o.jsx("input",{ref:c,type:"text",placeholder:"Search",value:d,onChange:A=>{h(A.target.value)},className:"focus:border-primary h-8 w-48 rounded-none border-0 bg-transparent pl-9 text-sm outline-none focus:border-b"})]}),o.jsxs(Ar,{children:[o.jsx(Dr,{asChild:!0,children:o.jsxs(we,{variant:"ghost",size:"icon","aria-label":"Sort fields",children:[m===Rs.ASC&&o.jsx(bR,{className:"h-4 w-4"}),m===Rs.DESC&&o.jsx(xR,{className:"h-4 w-4"}),m===Rs.ORIGINAL&&o.jsx(SR,{className:"h-4 w-4"})]})}),o.jsxs(Or,{align:"end",children:[o.jsxs(Tt,{onSelect:()=>{g(Rs.ASC)},children:[o.jsx(bR,{className:"text-muted-foreground mr-2 h-4 w-4"}),"A–Z"]}),o.jsxs(Tt,{onSelect:()=>{g(Rs.DESC)},children:[o.jsx(xR,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Z–A"]}),o.jsxs(Tt,{onSelect:()=>{g(Rs.ORIGINAL)},children:[o.jsx(SR,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Original"]})]})]})]})]}),o.jsx("div",{className:"border-border border-t"}),o.jsxs("div",{className:"flex flex-col gap-3",children:[C.map(A=>{const k=b.includes(A.name);return o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx("input",{type:"checkbox",id:`field-${A.name}`,name:"selectedFields",value:A.name,className:"text-primary focus:ring-primary border-border h-4 w-4",onChange:U=>{k||r(A.name,U.target.checked)},checked:n.includes(A.name),disabled:k}),o.jsx("label",{htmlFor:`field-${A.name}`,className:`cursor-pointer text-sm ${k?"text-foreground font-medium":"text-muted-foreground"}`,children:o.jsxs("div",{className:"flex items-center gap-2",children:[A.name,k&&o.jsx(Zx,{className:"text-primary h-3 w-3"})]})}),A.name&&o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(Xr,{className:"text-muted-foreground/75 inline-block h-4 w-4 cursor-help"})}),o.jsxs(Ot,{children:[k&&o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Zx,{className:"text-secondary h-3 w-3"}),o.jsx("p",{className:"font-semibold",children:"Unique key"})]}),o.jsxs("p",{children:["Type: ",A.type]}),A.description&&o.jsx("p",{children:A.description})]})]})]},A.name)}),C.length===0&&d&&o.jsxs("div",{className:"text-muted-foreground py-4 text-center text-sm",children:['No fields match "',d,'"']})]})]})]})}const jO=p.createContext(void 0),_O={triggers:[],selectedTrigger:null,isLoading:!1,error:null};function KX(e,t){switch(t.type){case"FETCH_TRIGGERS_START":case"FETCH_TRIGGER_START":case"CREATE_TRIGGER_START":case"UPDATE_TRIGGER_START":case"DELETE_TRIGGER_START":return{...e,isLoading:!0,error:null};case"FETCH_TRIGGERS_SUCCESS":return{...e,triggers:t.payload,isLoading:!1};case"FETCH_TRIGGER_SUCCESS":return{...e,selectedTrigger:t.payload,isLoading:!1};case"CREATE_TRIGGER_SUCCESS":return{...e,triggers:[...e.triggers,t.payload],isLoading:!1};case"UPDATE_TRIGGER_SUCCESS":return{...e,triggers:e.triggers.map(n=>n.id===t.payload.id?t.payload:n),selectedTrigger:e.selectedTrigger&&e.selectedTrigger.id===t.payload.id?t.payload:e.selectedTrigger,isLoading:!1};case"DELETE_TRIGGER_SUCCESS":return{...e,triggers:e.triggers.filter(n=>n.id!==t.payload),selectedTrigger:e.selectedTrigger&&e.selectedTrigger.id===t.payload?null:e.selectedTrigger,isLoading:!1};case"FETCH_TRIGGERS_ERROR":case"FETCH_TRIGGER_ERROR":case"CREATE_TRIGGER_ERROR":case"UPDATE_TRIGGER_ERROR":case"DELETE_TRIGGER_ERROR":return{...e,isLoading:!1,error:t.payload};case"SELECT_TRIGGER":return{...e,selectedTrigger:t.payload};case"RESET":return _O;default:return e}}class YX extends kl{constructor(){super("/data-marts")}async getScheduledTriggers(t){return this.get(`/${t}/scheduled-triggers`)}async getScheduledTrigger(t,n){return this.get(`/${t}/scheduled-triggers/${n}`)}async createScheduledTrigger(t,n){return this.post(`/${t}/scheduled-triggers`,n)}async updateScheduledTrigger(t,n,r){return this.put(`/${t}/scheduled-triggers/${n}`,r)}async deleteScheduledTrigger(t,n){return this.delete(`/${t}/scheduled-triggers/${n}`)}}const _c=new YX;var pn=(e=>(e.REPORT_RUN="REPORT_RUN",e.CONNECTOR_RUN="CONNECTOR_RUN",e))(pn||{});const Uc={SCHEDULED_REPORT_RUN:"scheduled-report-run-config"};class z0{mapFromDto(t){return{id:t.id,type:t.type,cronExpression:t.cronExpression,timeZone:t.timeZone,isActive:t.isActive,nextRun:t.nextRunTimestamp?new Date(t.nextRunTimestamp):null,lastRun:t.lastRunTimestamp?new Date(t.lastRunTimestamp):null,triggerConfig:t.triggerConfig,createdById:t.createdById,createdAt:new Date(t.createdAt),modifiedAt:new Date(t.modifiedAt)}}async enhanceWithReportData(t){if(t.type!==pn.REPORT_RUN)return t;const n=t.triggerConfig;if(!n.reportId)return t;try{const r=await ho.getReportById(n.reportId),s=cl(r);return{...t,triggerConfig:{...n,report:s}}}catch(r){return console.error(`Failed to fetch report data for trigger ${t.id}:`,r),t}}async enhanceTriggersWithReportData(t){return Promise.all(t.map(n=>this.enhanceWithReportData(n)))}mapToCreateRequest(t){return{type:pn.REPORT_RUN,cronExpression:t.cronExpression,timeZone:t.timeZone,isActive:t.isActive,triggerConfig:t.triggerConfig}}mapToUpdateRequest(t){return{cronExpression:t.cronExpression,timeZone:t.timeZone,isActive:t.isActive}}}class QX{mapFromDto(t){return{id:t.id,type:t.type,cronExpression:t.cronExpression,timeZone:t.timeZone,isActive:t.isActive,nextRun:t.nextRunTimestamp?new Date(t.nextRunTimestamp):null,lastRun:t.lastRunTimestamp?new Date(t.lastRunTimestamp):null,triggerConfig:t.triggerConfig,createdById:t.createdById,createdAt:new Date(t.createdAt),modifiedAt:new Date(t.modifiedAt)}}mapToCreateRequest(t){return{type:pn.CONNECTOR_RUN,cronExpression:t.cronExpression,timeZone:t.timeZone,isActive:t.isActive,triggerConfig:t.triggerConfig}}mapToUpdateRequest(t){return{cronExpression:t.cronExpression,timeZone:t.timeZone,isActive:t.isActive}}}const Mx={getMapper(e){switch(e){case pn.REPORT_RUN:return new z0;case pn.CONNECTOR_RUN:return new QX;default:throw new Error(`Unknown scheduled trigger type: ${String(e)}`)}}},Td={mapFromDto(e){return Mx.getMapper(e.type).mapFromDto(e)},mapFromDtoList(e){return e.map(t=>this.mapFromDto(t))},async mapFromDtoWithReportData(e,t){const n=this.mapFromDto(e);switch(n.type){case pn.REPORT_RUN:return new z0().enhanceWithReportData(n);case pn.CONNECTOR_RUN:{const r=t.definition;return{...n,triggerConfig:{...n.triggerConfig,connector:r}}}default:return n}},async mapFromDtoListWithReportData(e,t){const n=new z0,r=this.mapFromDtoList(e),s=r.filter(c=>c.type===pn.REPORT_RUN),l=await n.enhanceTriggersWithReportData(s);return r.map(c=>{switch(c.type){case pn.REPORT_RUN:return l.find(d=>d.id===c.id)??c;case pn.CONNECTOR_RUN:{const d=t.definition;return{...c,triggerConfig:{...c.triggerConfig,connector:d}}}default:return c}})},mapToCreateRequest(e){return Mx.getMapper(e.type).mapToCreateRequest(e)},mapToUpdateRequest(e){return Mx.getMapper(e.type).mapToUpdateRequest(e)}};function WX({children:e}){const[t,n]=p.useReducer(KX,_O),{dataMart:r}=Li(),{fetchAvailableConnectors:s}=Ll();if(!r)throw new Error("Trigger provider must be used within a data mart context");const l=p.useCallback(async b=>{await s(),n({type:"FETCH_TRIGGERS_START"});try{const E=await _c.getScheduledTriggers(b),C=await Td.mapFromDtoListWithReportData(E,r);n({type:"FETCH_TRIGGERS_SUCCESS",payload:C})}catch(E){n({type:"FETCH_TRIGGERS_ERROR",payload:E instanceof Error?E.message:"Failed to fetch scheduled triggers"})}},[r,s]),c=p.useCallback(async(b,E)=>{n({type:"FETCH_TRIGGERS_START"});try{const w=(await _c.getScheduledTriggers(b)).filter(T=>T.type===E),R=await Td.mapFromDtoListWithReportData(w,r);n({type:"FETCH_TRIGGERS_SUCCESS",payload:R})}catch(C){n({type:"FETCH_TRIGGERS_ERROR",payload:C instanceof Error?C.message:"Failed to fetch scheduled triggers"})}},[r]),d=p.useCallback(async(b,E)=>{n({type:"FETCH_TRIGGER_START"});try{const C=await _c.getScheduledTrigger(b,E),w=await Td.mapFromDtoWithReportData(C,r);n({type:"FETCH_TRIGGER_SUCCESS",payload:w})}catch(C){n({type:"FETCH_TRIGGER_ERROR",payload:C instanceof Error?C.message:"Failed to fetch scheduled trigger"})}},[r]),h=p.useCallback(async(b,E,C,w,R,T)=>{n({type:"CREATE_TRIGGER_START"});try{const j={type:E,cronExpression:C,timeZone:w,isActive:R,triggerConfig:T},O=await _c.createScheduledTrigger(b,j),D=await Td.mapFromDtoWithReportData(O,r);return n({type:"CREATE_TRIGGER_SUCCESS",payload:D}),Jt.success("Trigger created"),D}catch(j){throw n({type:"CREATE_TRIGGER_ERROR",payload:j instanceof Error?j.message:"Failed to create scheduled trigger"}),j}},[r]),m=p.useCallback(async(b,E,C,w,R)=>{n({type:"UPDATE_TRIGGER_START"});try{const T={cronExpression:C,timeZone:w,isActive:R},j=await _c.updateScheduledTrigger(b,E,T),O=await Td.mapFromDtoWithReportData(j,r);n({type:"UPDATE_TRIGGER_SUCCESS",payload:O}),Jt.success("Trigger updated")}catch(T){throw n({type:"UPDATE_TRIGGER_ERROR",payload:T instanceof Error?T.message:"Failed to update scheduled trigger"}),T}},[r]),g=p.useCallback(async(b,E)=>{n({type:"DELETE_TRIGGER_START"});try{await _c.deleteScheduledTrigger(b,E),n({type:"DELETE_TRIGGER_SUCCESS",payload:E}),Jt.success("Trigger deleted")}catch(C){throw n({type:"DELETE_TRIGGER_ERROR",payload:C instanceof Error?C.message:"Failed to delete scheduled trigger"}),C}},[]),v=p.useCallback(b=>{n({type:"SELECT_TRIGGER",payload:b})},[]),x=p.useCallback(()=>{n({type:"RESET"})},[]);return o.jsx(jO.Provider,{value:{...t,getScheduledTriggers:l,getScheduledTriggersByType:c,getScheduledTrigger:d,createScheduledTrigger:h,updateScheduledTrigger:m,deleteScheduledTrigger:g,selectScheduledTrigger:v,reset:x},children:e})}function NO(){const e=p.useContext(jO);if(e===void 0)throw new Error("useScheduledTriggerContext must be used within a ScheduledTriggerProvider");return e}function XX(e){const{getScheduledTriggers:t,getScheduledTriggersByType:n,getScheduledTrigger:r,createScheduledTrigger:s,updateScheduledTrigger:l,deleteScheduledTrigger:c,selectScheduledTrigger:d,reset:h,triggers:m,selectedTrigger:g,isLoading:v,error:x}=NO();return p.useEffect(()=>(e?t(e):h(),()=>{h()}),[e,t,h]),{triggers:m,selectedTrigger:g,isLoading:v,error:x,getScheduledTriggers:b=>t(b),getScheduledTriggersByType:(b,E)=>n(b,E),getScheduledTrigger:(b,E)=>r(b,E),createScheduledTrigger:(b,E,C,w,R,T)=>s(b,E,C,w,R,T),updateScheduledTrigger:(b,E,C,w,R)=>l(b,E,C,w,R),deleteScheduledTrigger:(b,E)=>c(b,E),selectScheduledTrigger:d}}const JX=en({type:Vs(Uc.SCHEDULED_REPORT_RUN),reportId:tn().min(1,"Report ID is required")}),eJ=a$(),tJ=en({type:Bb(pn),cronExpression:tn().min(1,"Cron expression is required"),timeZone:tn().min(1,"Time zone is required"),isActive:r$(),triggerConfig:o$([JX,eJ])});function nJ({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:r}){const s=Pi({resolver:zl(tJ),defaultValues:{type:e?e.type:n??pn.REPORT_RUN,cronExpression:(e==null?void 0:e.cronExpression)??"",timeZone:(e==null?void 0:e.timeZone)??Intl.DateTimeFormat().resolvedOptions().timeZone,isActive:(e==null?void 0:e.isActive)??!0,triggerConfig:e?e.triggerConfig:{type:Uc.SCHEDULED_REPORT_RUN,reportId:t??""}}});p.useEffect(()=>{t&&s.getValues("type")===pn.REPORT_RUN&&s.setValue("triggerConfig",{type:Uc.SCHEDULED_REPORT_RUN,reportId:t})},[t,s]),p.useEffect(()=>{n&&(s.setValue("type",n),n===pn.REPORT_RUN?s.setValue("triggerConfig",{type:Uc.SCHEDULED_REPORT_RUN,reportId:t??""}):s.setValue("triggerConfig",null))},[n,t,s]);const l=d=>{s.setValue("type",d),d===pn.REPORT_RUN?s.setValue("triggerConfig",{type:Uc.SCHEDULED_REPORT_RUN,reportId:t??""}):s.setValue("triggerConfig",null)},c=async d=>{try{await r(d)}catch(h){console.error("Error submitting form:",h)}};return{form:s,handleTypeChange:l,handleSubmit:s.handleSubmit(c),isDirty:s.formState.isDirty}}function rJ({value:e,onChange:t,disabled:n}){const{reports:r,fetchReportsByDataMartId:s}=Il(),{dataMart:l}=Li();p.useEffect(()=>{l&&s(l.id)},[s,l]);const c=r.filter(d=>d.dataDestination.type===It.GOOGLE_SHEETS);return o.jsxs(ba,{value:e,onValueChange:t,disabled:n,children:[o.jsx(Ca,{className:"w-full",children:o.jsx(Sa,{placeholder:"Select a report"})}),o.jsx(Ea,{children:c.map(d=>o.jsx(Hn,{value:d.id,children:d.title},d.id))})]})}var Tg="Switch",[aJ]=Fr(Tg),[sJ,oJ]=aJ(Tg),AO=p.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:s,defaultChecked:l,required:c,disabled:d,value:h="on",onCheckedChange:m,form:g,...v}=e,[x,b]=p.useState(null),E=vt(t,j=>b(j)),C=p.useRef(!1),w=x?g||!!x.closest("form"):!0,[R,T]=Jr({prop:s,defaultProp:l??!1,onChange:m,caller:Tg});return o.jsxs(sJ,{scope:n,checked:R,disabled:d,children:[o.jsx(Ye.button,{type:"button",role:"switch","aria-checked":R,"aria-required":c,"data-state":kO(R),"data-disabled":d?"":void 0,disabled:d,value:h,...v,ref:E,onClick:je(e.onClick,j=>{T(O=>!O),w&&(C.current=j.isPropagationStopped(),C.current||j.stopPropagation())})}),w&&o.jsx(MO,{control:x,bubbles:!C.current,name:r,value:h,checked:R,required:c,disabled:d,form:g,style:{transform:"translateX(-100%)"}})]})});AO.displayName=Tg;var DO="SwitchThumb",OO=p.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,s=oJ(DO,n);return o.jsx(Ye.span,{"data-state":kO(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:t})});OO.displayName=DO;var iJ="SwitchBubbleInput",MO=p.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...s},l)=>{const c=p.useRef(null),d=vt(c,l),h=CS(n),m=Eb(t);return p.useEffect(()=>{const g=c.current;if(!g)return;const v=window.HTMLInputElement.prototype,b=Object.getOwnPropertyDescriptor(v,"checked").set;if(h!==n&&b){const E=new Event("click",{bubbles:r});b.call(g,n),g.dispatchEvent(E)}},[h,n,r]),o.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...s,tabIndex:-1,ref:d,style:{...s.style,...m,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});MO.displayName=iJ;function kO(e){return e?"checked":"unchecked"}var lJ=AO,cJ=OO;function IO({className:e,...t}){return o.jsx(lJ,{"data-slot":"switch",className:fe("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:o.jsx(cJ,{"data-slot":"switch-thumb",className:fe("bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}function uJ(e){const t=e.trim().split(/\s+/);return t.length!==5?null:{minute:t[0],hour:t[1],day:t[2],month:t[3],dayOfWeek:t[4]}}function V0(e,t="UTC"){const n=uJ(e);if(!n)return{type:"daily",time:"09:00",weekdays:[1,2,3,4,5],monthDays:[1],customCron:e,intervalType:"minutes",intervalValue:15,timezone:t};const{minute:r,hour:s,day:l,month:c,dayOfWeek:d}=n;if(r.startsWith("*/")&&s==="*"&&l==="*"&&c==="*"&&d==="*"){const v=Number.parseInt(r.substring(2));if(!isNaN(v))return{type:"interval",time:"09:00",weekdays:[1,2,3,4,5],monthDays:[1],customCron:e,intervalType:"minutes",intervalValue:v,timezone:t}}if(r!=="*"&&s.startsWith("*/")&&l==="*"&&c==="*"&&d==="*"){const v=Number.parseInt(s.substring(2));if(!isNaN(v)&&r==="0")return{type:"interval",time:"09:00",weekdays:[1,2,3,4,5],monthDays:[1],customCron:e,intervalType:"hours",intervalValue:v,timezone:t}}const h=Number.parseInt(r),m=Number.parseInt(s),g=!isNaN(h)&&!isNaN(m)?`${m.toString().padStart(2,"0")}:${h.toString().padStart(2,"0")}`:"09:00";if(!isNaN(h)&&!isNaN(m)&&l==="*"&&c==="*"&&d==="*")return{type:"daily",time:g,weekdays:[1,2,3,4,5],monthDays:[1],customCron:e,intervalType:"minutes",intervalValue:15,timezone:t};if(!isNaN(h)&&!isNaN(m)&&l==="*"&&c==="*"&&d!=="*"){const v=d.split(",").map(x=>Number.parseInt(x.trim())).filter(x=>!isNaN(x)&&x>=0&&x<=6);if(v.length>0)return{type:"weekly",time:g,weekdays:v,monthDays:[1],customCron:e,intervalType:"minutes",intervalValue:15,timezone:t}}if(!isNaN(h)&&!isNaN(m)&&l!=="*"&&c==="*"&&d==="*"){const v=l.split(",").map(x=>Number.parseInt(x.trim())).filter(x=>!isNaN(x)&&x>=1&&x<=31);if(v.length>0)return{type:"monthly",time:g,weekdays:[1,2,3,4,5],monthDays:v,customCron:e,intervalType:"minutes",intervalValue:15,timezone:t}}return{type:"custom",time:"09:00",weekdays:[1,2,3,4,5],monthDays:[1],customCron:e,intervalType:"minutes",intervalValue:15,timezone:t}}function LO({options:e,selected:t,onSelectionChange:n,placeholder:r="Select items...",searchPlaceholder:s="Search...",maxDisplayItems:l=3}){const[c,d]=p.useState(!1),h=v=>{const x=t.includes(v)?t.filter(b=>b!==v):[...t,v].sort((b,E)=>b-E);n(x)},m=(v,x)=>{x.preventDefault(),x.stopPropagation(),n(t.filter(b=>b!==v))},g=()=>{if(t.length===0)return o.jsx("span",{className:"text-muted-foreground text-sm",children:r});const v=t.map(x=>e.find(b=>b.value===x)).filter(Boolean);return v.length<=l?o.jsx("div",{className:"flex flex-wrap gap-1",children:v.map(x=>o.jsxs(Rr,{variant:"secondary",className:"h-5 text-xs",children:[x.label,o.jsx("span",{className:"hover:bg-secondary-foreground/20 ml-1 inline-flex cursor-pointer items-center justify-center rounded-full p-0.5",onClick:b=>m(x.value,b),children:o.jsx(Bd,{className:"h-2 w-2"})})]},x.value))}):o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsxs(Rr,{variant:"secondary",className:"h-5 text-xs",children:[v[0].label,o.jsx("span",{className:"hover:bg-secondary-foreground/20 ml-1 inline-flex cursor-pointer items-center justify-center rounded-full p-0.5",onClick:x=>m(v[0].value,x),children:o.jsx(Bd,{className:"h-2 w-2"})})]}),v.length>1&&o.jsxs(Rr,{variant:"outline",className:"h-5 text-xs",children:["+",v.length-1]})]})};return o.jsxs(jS,{open:c,onOpenChange:d,modal:!0,children:[o.jsx(_S,{asChild:!0,children:o.jsxs(we,{variant:"outline",role:"combobox","aria-expanded":c,className:"h-9 min-h-9 w-full justify-between bg-transparent py-1",children:[o.jsx("div",{className:"flex-1 text-left",children:g()}),o.jsx(ib,{className:"ml-2 h-3 w-3 shrink-0 opacity-50"})]})}),o.jsx(NS,{className:"max-h-[400px] w-full overflow-y-auto p-0",style:{padding:0},children:o.jsxs(BD,{className:"h-full overflow-visible",children:[o.jsx(GD,{placeholder:s,className:"h-8"}),o.jsxs(PW,{className:"h-full max-h-[350px] overflow-y-auto",children:[o.jsx(qD,{children:"No items found."}),o.jsx(ZD,{className:"h-full overflow-visible",children:e.map(v=>o.jsxs(KD,{value:v.value.toString(),onSelect:()=>h(v.value),className:"text-sm",children:[o.jsx(yr,{className:fe("mr-2 h-3 w-3",t.includes(v.value)?"opacity-100":"opacity-0")}),v.label]},v.value))})]})]})})]})}const PO=[{value:1,label:"Monday"},{value:2,label:"Tuesday"},{value:3,label:"Wednesday"},{value:4,label:"Thursday"},{value:5,label:"Friday"},{value:6,label:"Saturday"},{value:0,label:"Sunday"}],ym=()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}};function UO(e,t){if(!t)return"Schedule is disabled";const n=e.time;switch(e.type){case"daily":return`Daily at ${n}`;case"weekly":return`Weekly on ${e.weekdays.map(s=>{var l;return(l=PO.find(c=>c.value===s))==null?void 0:l.label}).join(", ")} at ${n}`;case"monthly":{const s=[...e.monthDays].sort((c,d)=>c-d).map(c=>c===1?"1st":c===2?"2nd":c===3?"3rd":`${String(c)}th`);return`Monthly on the ${s.length===1?s[0]:s.length===2?`${s[0]} and ${s[1]}`:`${s.slice(0,-1).join(", ")}, and ${s[s.length-1]}`} at ${n}`}case"interval":return e.intervalType==="minutes"?`Every ${String(e.intervalValue)} minute${e.intervalValue!==1?"s":""}`:`Every ${String(e.intervalValue)} hour${e.intervalValue!==1?"s":""}`;case"custom":return"Custom schedule";default:return""}}function dJ(e,t,n=!0){const r=V0(e,t);return UO(r,n)}const fJ=Array.from({length:31},(e,t)=>({value:t+1,label:`${String(t+1)}${t===0?"st":t===1?"nd":t===2?"rd":"th"}`})),H0=[5,10,15,30],$0=[1,2,3,4,6,8,12],hJ=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(xa,{children:"Type"}),o.jsxs(ba,{value:e,onValueChange:r=>{t(r)},disabled:n,children:[o.jsx(Ca,{className:"w-full",children:o.jsx(Sa,{})}),o.jsxs(Ea,{children:[o.jsx(Hn,{value:"daily",children:"Daily"}),o.jsx(Hn,{value:"weekly",children:"Weekly"}),o.jsx(Hn,{value:"monthly",children:"Monthly"}),o.jsx(Hn,{value:"interval",children:"Interval"})]})]})]}),mJ=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(xa,{children:"Time"}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx(Zt,{className:"w-24",type:"time",value:e,onChange:r=>{t(r.target.value)},disabled:n})})]}),mT=({value:e,onChange:t,disabled:n,timezones:r})=>o.jsxs("div",{className:"w-full space-y-2",children:[o.jsx(xa,{children:"Timezone"}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx(AS,{options:r,value:e,onValueChange:t,placeholder:"Select timezone",emptyMessage:"No timezones found",disabled:n,className:"w-full"})})]}),pJ=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(xa,{children:"Days of Week"}),o.jsx("div",{className:n?"pointer-events-none":"",children:o.jsx(LO,{options:PO,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:3})})]}),gJ=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(xa,{children:"Days of Month"}),o.jsx("div",{className:n?"pointer-events-none":"",children:o.jsx(LO,{options:fJ,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:4})})]}),vJ=({intervalType:e,intervalValue:t,onTypeChange:n,onValueChange:r,disabled:s})=>o.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[o.jsxs("div",{className:"space-y-2",children:[o.jsx(xa,{children:"Type"}),o.jsxs(ba,{value:e,onValueChange:l=>{n(l)},disabled:s,children:[o.jsx(Ca,{className:"w-full",children:o.jsx(Sa,{})}),o.jsxs(Ea,{children:[o.jsx(Hn,{value:"minutes",children:"Minutes"}),o.jsx(Hn,{value:"hours",children:"Hours"})]})]})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(xa,{children:"Every"}),o.jsxs(ba,{value:t.toString(),onValueChange:l=>{r(Number.parseInt(l)||1)},disabled:s,children:[o.jsx(Ca,{className:"w-full",children:o.jsx(Sa,{})}),o.jsx(Ea,{children:(e==="minutes"?H0:$0).map(l=>o.jsxs(Hn,{value:l.toString(),children:[l," ",e==="minutes"?"min":"hr"]},l))})]})]})]}),yJ=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-1",children:[o.jsx(xa,{className:"text-sm",children:"Cron Expression"}),o.jsx(Zt,{value:e,onChange:r=>{t(r.target.value)},placeholder:"0 9 * * *",className:"h-9 font-mono text-sm",disabled:n}),o.jsx("p",{className:"text-muted-foreground text-xs",children:"Format: minute hour day month day-of-week"})]});function xJ({cron:e="0 9 * * *",timezone:t,enabled:n=!0,onChange:r,className:s,showPreview:l=!0,showSaveButton:c=!1}){const[d,h]=p.useState(n),[m,g]=p.useState(t??ym()),[v,x]=p.useState(!1),b=p.useMemo(()=>_B.getTimezonesWithOffset().map(G=>({value:G.identifier,label:G.displayName,offset:G.offsetString,isDST:G.isDST})),[]),[E,C]=p.useState(()=>V0(e,m)),[w,R]=p.useState(""),[T,j]=p.useState("");p.useEffect(()=>{h(n)},[n]),p.useEffect(()=>{const G=t??ym();g(G)},[t]),p.useEffect(()=>{if(e){const G=V0(e,m);C(G)}},[e,m]);const O=G=>{const[W,I]=G.time.split(":").map(Number);switch(G.type){case"daily":return`${String(I)} ${String(W)} * * *`;case"weekly":return`${String(I)} ${String(W)} * * ${G.weekdays.join(",")}`;case"monthly":return`${String(I)} ${String(W)} ${G.monthDays.join(",")} * *`;case"interval":return G.intervalType==="minutes"?`*/${String(G.intervalValue)} * * * *`:`0 */${String(G.intervalValue)} * * *`;case"custom":return G.customCron;default:return`${String(I)} ${String(W)} * * *`}},D=p.useCallback(G=>{C(W=>{if(W.intervalType===G)return console.log("Type unchanged, skipping update"),W;const Y=(G==="minutes"?H0:$0)[0];return{...W,intervalType:G,intervalValue:Y}})},[]),N=p.useCallback(G=>{C(W=>(W.intervalType==="minutes"?H0:$0).includes(G)?{...W,intervalValue:G}:W)},[]),A=p.useMemo(()=>G=>UO(G,d),[d]);p.useEffect(()=>{const G=O(E);R(G),j(A(E))},[E,d,m,A]);const k=p.useRef(""),U=p.useRef(""),B=p.useRef(!1);p.useEffect(()=>{const G=O(E);r&&(k.current!==G||U.current!==m||B.current!==d)&&(r({cron:G,timezone:m,enabled:d}),k.current=G,U.current=m,B.current=d)},[E,m,d,r]);const H=G=>{h(G)},Q=G=>{g(G),C(W=>({...W,timezone:G}))},ne=["daily","weekly","monthly"].includes(E.type);return o.jsxs("div",{className:s,children:[o.jsx("div",{className:"mb-4 space-y-4 pt-0",children:o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("h3",{className:"text-foreground flex items-center gap-1.5 font-medium",children:"Schedule Settings"}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(xa,{htmlFor:"schedule-enabled",className:"text-sm font-normal",children:d?"Enabled":"Disabled"}),o.jsx(IO,{id:"schedule-enabled",checked:d,onCheckedChange:H})]})]})}),o.jsxs("div",{className:"space-y-4 pt-0",children:[o.jsxs("div",{className:`space-y-4 ${d?"":"opacity-50"}`,children:[o.jsx(hJ,{value:E.type,onChange:G=>{C(W=>({...W,type:G}))},disabled:!d}),E.type!=="custom"&&E.type!=="interval"&&o.jsxs("div",{className:"flex gap-3",children:[o.jsx(mJ,{value:E.time,onChange:G=>{C(W=>({...W,time:G}))},disabled:!d}),ne&&o.jsx(mT,{value:m,onChange:Q,disabled:!d,timezones:b})]}),(E.type==="interval"||E.type==="custom")&&o.jsx(mT,{value:m,onChange:Q,disabled:!d,timezones:b}),E.type==="weekly"&&o.jsx(pJ,{value:E.weekdays,onChange:G=>{C(W=>({...W,weekdays:G}))},disabled:!d}),E.type==="monthly"&&o.jsx(gJ,{value:E.monthDays,onChange:G=>{C(W=>({...W,monthDays:G}))},disabled:!d}),E.type==="interval"&&o.jsx(vJ,{intervalType:E.intervalType,intervalValue:E.intervalValue,onTypeChange:D,onValueChange:N,disabled:!d}),E.type==="custom"&&o.jsx(yJ,{value:E.customCron,onChange:G=>{C(W=>({...W,customCron:G}))},disabled:!d})]}),l&&o.jsxs(o.Fragment,{children:[o.jsx(Ij,{className:"my-3"}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"flex cursor-pointer items-center justify-between",onClick:()=>{x(!v)},children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(cb,{className:"h-4 w-4"}),o.jsx("span",{className:"text-sm font-medium",children:"Preview"})]}),v?o.jsx(ks,{className:"text-muted-foreground h-4 w-4"}):o.jsx(Ga,{className:"text-muted-foreground h-4 w-4"})]}),v&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"grid gap-4",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Status:"}),o.jsx(Rr,{variant:d?"default":"secondary",className:"text-xs",children:d?"Enabled":"Disabled"})]}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Cron:"}),o.jsx(Rr,{variant:"secondary",className:"font-mono text-xs",children:w})]}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Timezone:"}),o.jsx(Rr,{variant:"outline",className:"text-xs",children:m})]}),o.jsxs("div",{className:"flex items-start justify-between gap-2",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Schedule:"}),o.jsx("span",{className:"flex-1 text-right text-xs",children:T})]})]}),d&&ne&&m!==ym()&&o.jsxs(FS,{className:"border-amber-200 bg-amber-50",children:[o.jsx(au,{className:"h-4 w-4"}),o.jsx(TO,{children:"Time Zone"}),o.jsxs(zS,{children:["Schedule runs in ",m," (not your local ",ym()," ","time). Execution time may differ from expected."]})]})]})]})]}),c&&o.jsx(we,{className:"w-full",disabled:!d,children:"Save Schedule"})]})]})}function bJ(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"trigger-type-options-description-details",children:[o.jsx(qn,{children:"How do I choose a type?"}),o.jsxs(Zn,{children:[o.jsxs("p",{className:"mb-2",children:[o.jsx("strong",{children:"Report Run"})," - runs a report to import data from the specified Data Storage into a Destination provider (e.g. Google Sheets document)."]}),o.jsxs("p",{className:"mb-2",children:[o.jsx("strong",{children:"Connector Run"})," - runs a connector (e.g., Facebook Ads) configured in the Data Mart to update raw data in the selected Data Storage."]})]})]})})}function SJ(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"trigger-type-change-description-details",children:[o.jsx(qn,{children:"How do I change the trigger type?"}),o.jsx(Zn,{children:o.jsx("p",{children:"Trigger type cannot be changed after the trigger is created. If you need a different type, delete the existing trigger and create a new one with the desired type."})})]})})}function CJ(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"report-change-description-details",children:[o.jsx(qn,{children:"How do I change a report?"}),o.jsx(Zn,{children:o.jsx("p",{children:"The report cannot be changed after the trigger is created. If you need a different report, delete the existing trigger and create a new one with the desired report."})})]})})}function EJ(){return o.jsx(cr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Gn,{value:"report-select-description-details",children:[o.jsx(qn,{children:"How do I choose the report?"}),o.jsxs(Zn,{children:[o.jsx("p",{className:"mb-2",children:"For a Report Run trigger, select one of the available Destinations (e.g., a Google Sheets report)."}),o.jsxs("p",{children:["You can use an existing one or create a new one on the ",o.jsx("strong",{children:"Destinations"})," tab"," ","of this Data Mart."]})]})]})})}function wJ({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:r,onCancel:s,onDirtyChange:l}){const[c,d]=p.useState(!1),{form:h,handleTypeChange:m,handleSubmit:g,isDirty:v}=nJ({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:async w=>{d(!0);try{await r(w)}finally{d(!1)}}});p.useEffect(()=>{l==null||l(v)},[v,l]);const{control:x,watch:b}=h,C=b("type")===pn.REPORT_RUN;return o.jsx(Pl,{...h,children:o.jsxs(Ui,{onSubmit:w=>void g(w),noValidate:!1,children:[o.jsxs(Ul,{children:[o.jsx(Kt,{control:x,name:"type",render:({field:w})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Choose what you want this trigger to run - a report or a connector",children:"Trigger Type"}),o.jsxs(ba,{onValueChange:R=>{w.onChange(R),m(R)},defaultValue:w.value,disabled:!!n||!!e||!!b("triggerConfig.reportId"),children:[o.jsx(Wt,{children:o.jsx(Ca,{className:"w-full",children:o.jsx(Sa,{placeholder:"Select trigger type"})})}),o.jsxs(Ea,{children:[o.jsx(Hn,{value:pn.REPORT_RUN,children:"Report Run"}),o.jsx(Hn,{value:pn.CONNECTOR_RUN,children:"Connector Run"})]})]}),o.jsx(tr,{children:e?o.jsx(SJ,{}):o.jsx(bJ,{})}),o.jsx(nn,{})]})}),C&&o.jsx(Kt,{control:x,name:"triggerConfig.reportId",render:({field:w})=>o.jsxs(Yt,{children:[o.jsx(Qt,{tooltip:"Select the report that will be run by this trigger",children:"Report"}),o.jsx(Wt,{children:o.jsx($A,{children:o.jsx(rJ,{value:w.value,onChange:w.onChange,disabled:!!t||!!e})})}),o.jsx(tr,{children:e!=null&&e.triggerConfig?o.jsx(CJ,{}):o.jsx(EJ,{})}),o.jsx(nn,{})]})}),o.jsx(xJ,{showPreview:!1,cron:b("cronExpression"),timezone:b("timeZone"),enabled:b("isActive"),onChange:w=>{h.setValue("cronExpression",w.cron,{shouldDirty:!0}),h.setValue("timeZone",w.timezone,{shouldDirty:!0}),h.setValue("isActive",w.enabled,{shouldDirty:!0})},className:"border-border flex flex-col gap-1.5 rounded-md border-b bg-white px-4 py-3 transition-shadow duration-200 hover:shadow-sm dark:border-transparent dark:bg-white/4"})]}),o.jsxs(Fl,{children:[o.jsx(we,{variant:"default",type:"submit",className:"w-full","aria-label":e?"Save changes":"Create trigger",disabled:!v||c,children:c?e?"Saving...":"Creating...":e?"Save changes":"Create trigger"}),s&&o.jsx(we,{variant:"outline",type:"button",onClick:s,className:"w-full","aria-label":"Cancel",children:"Cancel"})]})]})})}function RJ({cronExpression:e,timeZone:t,isEnabled:n=!0}){const r=p.useMemo(()=>dJ(e,t,n),[e,t,n]);return o.jsxs("div",{children:[o.jsx("div",{children:r}),n&&o.jsx("code",{className:"text-muted-foreground mt-1 block text-xs",children:t})]})}function TJ({table:e}){return o.jsx("div",{className:"text-right",children:o.jsxs(Ar,{children:[o.jsx(Dr,{asChild:!0,children:o.jsx(we,{variant:"ghost",className:"dm-card-table-body-row-actionbtn","aria-label":"Toggle columns",children:o.jsx(qa,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsx(Or,{align:"end",children:e.getAllColumns().filter(t=>t.getCanHide()&&t.id!=="actions").map(t=>o.jsx(Tt,{className:"capitalize",children:o.jsxs("label",{className:"flex items-center space-x-2",children:[o.jsx("button",{type:"button",role:"checkbox","aria-checked":t.getIsVisible(),"data-state":t.getIsVisible()?"checked":"unchecked","aria-label":`Toggle column ${t.columnDef.meta.title??t.id}`,className:"peer border-input data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border bg-white shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 dark:bg-white/8",onClick:()=>{t.toggleVisibility(!t.getIsVisible())},children:t.getIsVisible()&&o.jsx("span",{"data-state":"checked","data-slot":"checkbox-indicator",className:"pointer-events-none flex items-center justify-center text-current transition-none",children:o.jsx(yr,{className:"size-3.5 text-white"})})}),o.jsx("span",{children:t.columnDef.meta.title??t.id})]})},t.id))})]})})}function jJ({trigger:e,onEditTrigger:t,onDeleteTrigger:n}){const[r,s]=p.useState(!1),[l,c]=p.useState(!1),d=()=>{c(!1),n(e.id)};return o.jsxs("div",{className:"text-right",onClick:h=>{h.stopPropagation()},children:[o.jsxs(Ar,{open:r,onOpenChange:s,children:[o.jsx(Dr,{asChild:!0,children:o.jsx(we,{variant:"ghost",className:`dm-card-table-body-row-actionbtn opacity-0 transition-opacity ${r?"opacity-100":"group-hover:opacity-100"}`,"aria-label":"Open menu",children:o.jsx(qa,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsxs(Or,{align:"end",children:[o.jsxs(Tt,{onClick:()=>{t(e.id)},children:[o.jsx(uf,{className:"text-foreground h-4 w-4","aria-hidden":"true"}),"Edit trigger"]}),o.jsx($a,{}),o.jsxs(Tt,{onClick:()=>{c(!0)},children:[o.jsx(No,{className:"h-4 w-4 text-red-600","aria-hidden":"true"}),o.jsx("span",{className:"text-red-600",children:"Delete trigger"})]})]})]}),o.jsx(ya,{open:l,onOpenChange:c,title:"Delete Scheduled Trigger",description:"Are you sure you want to delete this scheduled trigger? This action cannot be undone.",confirmLabel:"Delete",cancelLabel:"Cancel",onConfirm:d,variant:"destructive"})]})}function _J(e,t){const n=t.find(r=>r.name===e.source.name);return(n==null?void 0:n.displayName)??e.source.name}function NJ({connector:e}){const{connectors:t}=Ll(),n=_J(e,t);return o.jsx(o.Fragment,{children:n})}function FO({connector:e}){return o.jsx(NJ,{connector:e})}function AJ(e){if(e.length===0)return{lastRunDate:null,lastRunStatus:null,totalRuns:0,firstRunDate:null};const t=e[0],n=e[e.length-1],r=new Date(n.createdAt);return{lastRunDate:new Date(t.createdAt),lastRunStatus:t.status,totalRuns:e.length,firstRunDate:r}}const DJ=e=>{const{connectors:t}=Ll();return p.useMemo(()=>t.find(n=>n.name===e),[t,e])},OJ=_e.memo(function({connector:t,children:n}){const r=DJ(t.source.name),{dataMart:s,runs:l,getDataMartRuns:c}=Li();p.useEffect(()=>{s!=null&&s.id&&c(s.id)},[s==null?void 0:s.id,c]);const d=p.useMemo(()=>r!=null&&r.logoBase64?o.jsx(Tf,{base64:r.logoBase64,size:20}):null,[r==null?void 0:r.logoBase64]),h=p.useCallback(()=>{s!=null&&s.storage&&sG(s.storage,t.storage.fullyQualifiedName)},[s==null?void 0:s.storage,t.storage.fullyQualifiedName]),m=p.useMemo(()=>AJ(l),[l]),g=p.useMemo(()=>!m.lastRunDate||!m.lastRunStatus?null:{statusType:Sq(m.lastRunStatus),statusText:Eq(m.lastRunStatus),date:m.lastRunDate},[m]),v=p.useMemo(()=>(s==null?void 0:s.storage)&&oG(s.storage),[s]),x=p.useMemo(()=>{const b=t.source.fields.length.toString();return`${t.source.node} • ${b} fields`},[t.source.node,t.source.fields.length]);return o.jsxs(Qb,{children:[o.jsx(Wb,{asChild:!0,children:o.jsx("span",{children:n})}),o.jsxs(Xb,{children:[o.jsxs(Jb,{children:[o.jsx(eS,{children:d}),o.jsxs(tS,{children:[o.jsx(nS,{children:o.jsx(FO,{connector:t})}),o.jsx(rS,{children:x})]})]}),o.jsxs(aS,{children:[o.jsxs(fi,{children:[o.jsx(hi,{children:"Last run status:"}),o.jsx(mi,{children:g?o.jsx(_f,{type:g.statusType,variant:"ghost",children:g.statusText}):"Not run yet"})]}),o.jsxs(fi,{children:[o.jsx(hi,{children:"Last run date:"}),o.jsx(mi,{children:g?o.jsx(El,{date:g.date}):"Never run"})]}),o.jsxs(fi,{children:[o.jsx(hi,{children:"Total runs:"}),o.jsxs(mi,{children:[m.totalRuns," runs",m.firstRunDate&&o.jsxs(o.Fragment,{children:[", since"," ",m.firstRunDate.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})]})]})]})]}),o.jsx(sS,{children:o.jsxs(we,{className:"w-full",variant:"default",onClick:h,title:"Open Storage","aria-label":"Open Storage",children:[v,o.jsx(cf,{className:"ml-1 inline h-4 w-4","aria-hidden":"true"})]})})]})]})},(e,t)=>e.connector.source.name===t.connector.source.name&&e.connector.storage.fullyQualifiedName===t.connector.storage.fullyQualifiedName&&e.connector.source.node===t.connector.source.node&&e.connector.source.fields.length===t.connector.source.fields.length);function MJ(e){const t=e.triggerConfig;return o.jsxs("div",{className:"inline gap-1",children:[t.report.title,o.jsx(xq,{report:t.report,children:o.jsx(Xr,{className:"ml-1 inline-block h-4 w-4 align-text-bottom opacity-0 transition-opacity duration-200 group-hover:opacity-100"})})]})}function kJ(e){const t=e.triggerConfig,{connector:n}=t.connector;return o.jsxs("div",{className:"inline gap-1",children:[o.jsx(FO,{connector:n}),o.jsx(OJ,{connector:n,children:o.jsx(Xr,{className:"ml-1 inline-block h-4 w-4 align-text-bottom opacity-0 transition-opacity duration-200 group-hover:opacity-100"})})]})}function IJ({trigger:e}){switch(e.type){case pn.REPORT_RUN:return MJ(e);case pn.CONNECTOR_RUN:return kJ(e);default:return o.jsx("div",{className:"text-muted-foreground text-sm",children:"—"})}}function LJ({onEditTrigger:e,onDeleteTrigger:t}){return[{accessorKey:"type",size:150,header:"Trigger Type",cell:({row:n})=>{const s=n.getValue("type")===pn.REPORT_RUN?"Report Run":"Connector Run";return o.jsx(Rr,{variant:"outline",children:s})},meta:{title:"Trigger Type"}},{accessorKey:"triggerConfig",size:35,header:"Run Target",cell:({row:n})=>o.jsx(IJ,{trigger:n.original}),meta:{title:"Run Target"}},{accessorKey:"cronExpression",size:20,header:"Schedule",cell:({row:n})=>{const r=n.getValue("cronExpression"),s=n.original.timeZone,l=n.getValue("isActive");return o.jsx(RJ,{cronExpression:String(r),timeZone:s,isEnabled:l})},meta:{title:"Schedule"}},{accessorKey:"nextRun",size:15,header:"Next Run",cell:({row:n})=>{const r=n.original.nextRun;return o.jsx("div",{className:"text-muted-foreground text-sm",children:r?o.jsx(El,{date:new Date(r)}):"Not scheduled"})},meta:{title:"Next Run"}},{accessorKey:"lastRun",size:15,header:"Last Run",cell:({row:n})=>{const r=n.original.lastRun;return o.jsx("div",{className:"text-sm",children:r?o.jsx(El,{date:new Date(r)}):o.jsx("span",{className:"text-muted-foreground text-sm",children:"Never run"})})},meta:{title:"Last Run"}},{accessorKey:"isActive",size:15,header:"Trigger Status",cell:({row:n})=>{const r=n.getValue("isActive");return o.jsx(_f,{type:r?Sn.SUCCESS:Sn.NEUTRAL,variant:"ghost",showIcon:!1,children:r?"Enabled":"Disabled"})},meta:{title:"Trigger Status"}},{id:"actions",size:80,header:({table:n})=>o.jsx(TJ,{table:n}),cell:({row:n})=>o.jsx(jJ,{trigger:n.original,onEditTrigger:e,onDeleteTrigger:t}),meta:{title:"Actions"}}]}function PJ({table:e,onPreviousClick:t,onNextClick:n}){return o.jsxs("div",{className:"dm-card-pagination",role:"navigation","aria-label":"Table pagination",children:[o.jsx(we,{variant:"outline",size:"sm",onClick:t,disabled:!e.getCanPreviousPage(),"aria-label":"Go to previous page",children:"Previous"}),o.jsx(we,{variant:"outline",size:"sm",onClick:n,disabled:!e.getCanNextPage(),"aria-label":"Go to next page",children:"Next"})]})}function VS({isOpen:e,onClose:t,dataMartId:n,preSelectedReportId:r,preSelectedType:s}){const{createScheduledTrigger:l,updateScheduledTrigger:c,selectedTrigger:d}=NO(),[h,m]=p.useState(!1),[g,v]=p.useState(!1),x=p.useCallback(()=>{g?m(!0):t()},[g,t]),b=p.useCallback(()=>{m(!1),v(!1),t()},[t]),E=p.useCallback(j=>{v(j)},[]),C=p.useCallback(()=>{v(!1),t()},[t]),w=!!d,R=p.useMemo(()=>d?{type:d.type,cronExpression:d.cronExpression,timeZone:d.timeZone,isActive:d.isActive,triggerConfig:d.type===pn.REPORT_RUN?{type:Uc.SCHEDULED_REPORT_RUN,reportId:d.triggerConfig.reportId}:null}:void 0,[d]),T=async j=>{w?await c(n,d.id,j.cronExpression,j.timeZone,j.isActive):await l(n,j.type,j.cronExpression,j.timeZone,j.isActive,j.triggerConfig),C()};return o.jsxs(o.Fragment,{children:[o.jsx(Ai,{open:e,onOpenChange:j=>{j||x()},children:o.jsxs(Di,{children:[o.jsxs(Oi,{children:[o.jsxs(Dl,{children:[w?"Edit":"Create"," Scheduled Trigger"]}),o.jsx(lu,{children:"Configure automatic runs for your reports or connectors."})]}),o.jsx(wJ,{preSelectedReportId:r,preSelectedType:s,initialData:R,onSubmit:T,onCancel:x,onDirtyChange:E})]})}),o.jsx(ya,{open:h,onOpenChange:m,title:"Unsaved Changes",description:"You have unsaved changes. Exit without saving?",confirmLabel:"Yes, leave now",cancelLabel:"No, stay here",onConfirm:b,variant:"destructive"})]})}function UJ({triggers:e,dataMartId:t,onEditTrigger:n,onDeleteTrigger:r}){const[s,l]=p.useState(!1),c=p.useCallback(()=>{l(!1)},[]),d=p.useCallback(R=>{r(R)},[r]),h=p.useMemo(()=>LJ({onEditTrigger:n,onDeleteTrigger:d}),[n,d]),{sorting:m,setSorting:g,columnVisibility:v,setColumnVisibility:x}=Df({columns:h,storageKeyPrefix:"data-mart-scheduled-triggers",defaultSortingColumn:"type"}),b=gu({data:e,columns:h,getCoreRowModel:pu(),getPaginationRowModel:dg(),onSortingChange:g,getSortedRowModel:Af(),getFilteredRowModel:Nf(),state:{sorting:m,columnVisibility:v},onColumnVisibilityChange:x,enableGlobalFilter:!0,enableColumnResizing:!1}),E=p.useCallback(()=>{b.previousPage()},[b]),C=p.useCallback(()=>{b.nextPage()},[b]);return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"dm-card-table-wrap",children:o.jsxs(vu,{id:"scheduled-triggers-table",className:"dm-card-table",role:"table","aria-label":"Scheduled Triggers",children:[o.jsx(yu,{className:"dm-card-table-header",children:b.getHeaderGroups().map(R=>o.jsx(nr,{className:"dm-card-table-header-row",children:R.headers.map(T=>o.jsx(bu,{className:"[&:has([role=checkbox])]:pl-6 [&>[role=checkbox]]:translate-y-[2px]",scope:"col",style:T.column.id==="type"?{width:150,minWidth:150,maxWidth:150}:T.column.id==="actions"?{width:80,minWidth:80,maxWidth:80}:{width:`${String(T.getSize())}%`},children:T.isPlaceholder?null:typeof T.column.columnDef.header=="function"?T.column.columnDef.header(T.getContext()):T.column.columnDef.header},T.id))},R.id))}),o.jsx(xu,{className:"dm-card-table-body",children:b.getRowModel().rows.length?b.getRowModel().rows.map((R,T)=>o.jsx(nr,{onClick:()=>{n(R.original.id)},className:"dm-card-table-body-row group",role:"row","aria-rowindex":T+1,children:R.getVisibleCells().map((j,O)=>o.jsx(va,{className:`whitespace-normal ${j.column.id==="actions"?"actions-cell":""}`,role:"cell","aria-colindex":O+1,style:j.column.id==="type"?{width:150,minWidth:150,maxWidth:150}:j.column.id==="actions"?{width:80,minWidth:80,maxWidth:80}:{width:`${String(j.column.getSize())}%`},children:typeof j.column.columnDef.cell=="function"?j.column.columnDef.cell(j.getContext()):j.column.columnDef.cell},j.id))},R.id)):o.jsx(nr,{children:o.jsx(va,{colSpan:h.length,className:"dm-card-table-body-row-empty",role:"cell",children:o.jsx("span",{role:"status","aria-live":"polite",children:"No scheduled triggers found."})})})})]})}),o.jsx(PJ,{table:b,onPreviousClick:E,onNextClick:C}),o.jsx(VS,{isOpen:s,onClose:c,dataMartId:t})]})}function FJ({dataMartId:e}){const{triggers:t,deleteScheduledTrigger:n,selectScheduledTrigger:r,selectedTrigger:s}=XX(e),[l,c]=p.useState(!1);p.useEffect(()=>{s&&c(!0)},[s]);const d=g=>{const v=t.find(x=>x.id===g);v&&r(v)},h=()=>{c(!1),r(null)},m=async g=>{try{await n(e,g)}catch(v){console.error("Error deleting trigger:",v)}};return o.jsxs(o.Fragment,{children:[o.jsx(UJ,{triggers:t,dataMartId:e,onEditTrigger:d,onDeleteTrigger:g=>void m(g)}),o.jsx(VS,{isOpen:l,onClose:h,dataMartId:e})]})}function zO(){return o.jsx("div",{className:"dm-card-block !gap-1.5 !py-3",children:o.jsxs("div",{className:"text-foreground flex items-start gap-1.5 text-sm",children:[o.jsx(Cj,{className:"h-5 w-5 shrink-0","aria-hidden":"true"}),o.jsxs("div",{children:[o.jsx("p",{className:"font-medium",children:"Time Triggers"}),o.jsxs("p",{className:"text-muted-foreground",children:["Go to the ",o.jsx("span",{className:"font-medium",children:"Triggers tab"})," to set up automatic runs."]})]})]})})}function zJ({dataStorageType:e,target:t,destinationName:n,connectorName:r,onTargetChange:s}){const l=n.replace(/[^a-zA-Z0-9_]/g,"_"),c=r.replace(/[^a-zA-Z0-9_]/g,"_").toLowerCase(),[d,h]=p.useState(""),[m,g]=p.useState(""),[v,x]=p.useState(null),[b,E]=p.useState(null),C=j=>j.trim()?/^[A-Za-z][A-Za-z0-9_]*$/.test(j)?null:"Use letters, numbers, and underscores; start with a letter":"This field is required",w=p.useCallback((j,O,D,N)=>{s({fullyQualifiedName:`${j}.${O}`,isValid:!!(j&&O&&D===null&&N===null)})},[s]);p.useEffect(()=>{let j="",O="";if(t!=null&&t.fullyQualifiedName){const U=t.fullyQualifiedName.split(".");j=U[0]??"",O=U[1]??""}else j=`${c}_owox`,O=l;const D=C(j),N=C(O);h(j),g(O),x(D),E(N);const A=`${j}.${O}`,k=!!(j&&O&&D===null&&N===null);(!t||t.fullyQualifiedName!==A||t.isValid!==k)&&w(j,O,D,N)},[t,l,c,w]);const R=j=>{h(j);const O=C(j);x(O),w(j,m,O,b)},T=j=>{g(j);const O=C(j);E(O),w(d,j,v,O)};return o.jsxs("div",{className:"space-y-4",children:[o.jsx("h4",{className:"text-lg font-medium",children:"Setup target"}),o.jsxs("div",{className:"flex flex-col gap-4",children:[e===Pe.GOOGLE_BIGQUERY&&o.jsxs("div",{className:"flex flex-col gap-4",children:[o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx("label",{htmlFor:"dataset-name",className:"text-muted-foreground text-sm",children:"Enter dataset name for Google BigQuery where the connector data will be stored. The dataset will be created automatically if it doesn't exist."}),o.jsx(Zt,{type:"text",id:"dataset-name",placeholder:"Enter dataset name",autoComplete:"off",className:"box-border w-full",value:d,"aria-invalid":!!v,"aria-describedby":v?"dataset-name-error":void 0,onChange:j=>{R(j.target.value)},required:!0}),v&&o.jsx("p",{id:"dataset-name-error",className:"text-destructive text-sm",children:v})]}),o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx("label",{htmlFor:"table-name",className:"text-muted-foreground text-sm",children:"Enter table name where the connector data will be stored. The table will be created automatically if it doesn't exist."}),o.jsx(Zt,{type:"text",id:"table-name",placeholder:"Enter table name",autoComplete:"off",className:"box-border w-full",value:m,"aria-invalid":!!b,"aria-describedby":b?"table-name-error":void 0,onChange:j=>{T(j.target.value)},required:!0}),b&&o.jsx("p",{id:"table-name-error",className:"text-destructive text-sm",children:b})]}),o.jsxs("div",{className:"text-muted-foreground mt-2 text-sm",children:["Full path:"," ",o.jsxs("span",{className:"text-foreground/90",children:[d||"[dataset]",".",m||"[table]"]})]})]}),e===Pe.AWS_ATHENA&&o.jsxs("div",{className:"flex flex-col gap-4",children:[o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx("label",{htmlFor:"database-name",className:"text-muted-foreground text-sm",children:"Enter database name for Amazon Athena where the connector data will be stored. The database will be created automatically if it doesn't exist."}),o.jsx(Zt,{type:"text",id:"database-name",placeholder:"Enter database name",autoComplete:"off",className:"box-border w-full",value:d,"aria-invalid":!!v,"aria-describedby":v?"database-name-error":void 0,onChange:j=>{R(j.target.value)},required:!0}),v&&o.jsx("p",{id:"database-name-error",className:"text-destructive text-sm",children:v})]}),o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx("label",{htmlFor:"athena-table-name",className:"text-muted-foreground text-sm",children:"Enter table name where the connector data will be stored. The table will be created automatically if it doesn't exist."}),o.jsx(Zt,{type:"text",id:"athena-table-name",placeholder:"Enter table name",autoComplete:"off",className:"box-border w-full",value:m,"aria-invalid":!!b,"aria-describedby":b?"athena-table-name-error":void 0,onChange:j=>{T(j.target.value)},required:!0}),b&&o.jsx("p",{id:"athena-table-name-error",className:"text-destructive text-sm",children:b})]}),o.jsxs("div",{className:"text-muted-foreground mt-2 text-sm",children:["Full path:"," ",o.jsxs("span",{className:"text-foreground/90",children:[d||"[database]",".",m||"[table]"]})]})]}),o.jsx(zO,{})]})]})}function VJ({currentStep:e,totalSteps:t,canGoNext:n,canGoBack:r,isLoading:s=!1,onNext:l,onBack:c,onFinish:d,nextLabel:h="Next",backLabel:m="Back",finishLabel:g="Finish"}){const v=e===t;return o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("div",{className:"flex-1",children:r&&o.jsxs(we,{variant:"outline",onClick:c,disabled:s,className:"flex items-center gap-2",children:[o.jsx(Q6,{className:"h-4 w-4"}),m]})}),o.jsxs("div",{className:"text-muted-foreground/75 px-4 text-sm",children:["Step ",e," of ",t]}),o.jsx("div",{className:"flex flex-1 justify-end",children:v?o.jsx(we,{onClick:d,disabled:!n||s,className:"flex items-center gap-2",children:g}):o.jsxs(we,{onClick:l,disabled:!n||s,className:"flex items-center gap-2",children:[h,o.jsx(_o,{className:"h-4 w-4"})]})})]})}function HJ({onSubmit:e,dataStorageType:t,configurationOnly:n=!1,existingConnector:r=null,mode:s="full"}){const[l,c]=p.useState(null),[d,h]=p.useState(""),[m,g]=p.useState([]),[v,x]=p.useState(1),[b,E]=p.useState({}),[C,w]=p.useState(!1),[R,T]=p.useState(new Set),[j,O]=p.useState(new Set),{connectors:D,connectorSpecification:N,connectorFields:A,loading:k,loadingSpecification:U,loadingFields:B,error:H,fetchAvailableConnectors:Q,fetchConnectorSpecification:ne,fetchConnectorFields:G}=Ll(),[W,I]=p.useState(null),q=(n?[{id:1,title:"Configuration",description:"Set up connector parameters"}]:s==="fields-only"?[{id:1,title:"Select Fields",description:"Pick specific fields"}]:[{id:1,title:"Select Connector",description:"Choose a data source"},{id:2,title:"Configuration",description:"Set up connector parameters"},{id:3,title:"Select Nodes",description:"Choose data nodes"},{id:4,title:"Select Fields",description:"Pick specific fields"},{id:5,title:"Target Setup",description:"Configure destination"}]).length,oe=p.useCallback(async Te=>{!R.has(Te)&&!U&&(T(ft=>new Set(ft).add(Te)),await ne(Te))},[R,U,ne]),be=p.useCallback(async Te=>{j.has(Te)||(O(ft=>new Set(ft).add(Te)),await G(Te))},[j,G]);p.useEffect(()=>{if(D.length===0&&!k&&Q(),r&&D.length>0&&!l){const{source:Te,storage:ft}=r;h(Te.node),g(Te.fields),E(Te.configuration[0]||{}),I({fullyQualifiedName:ft.fullyQualifiedName,isValid:!0});const lt=D.find(an=>an.name===Te.name);lt&&(c(lt),oe(lt.name),!n&&s!=="fields-only"&&be(lt.name),s==="fields-only"&&be(lt.name))}if(n&&D.length>0&&!l&&!r){const Te=D[0];c(Te),oe(Te.name)}},[s,r,D,n,k,Q,oe,be,l]);const L=Te=>{c(Te),E({}),w(!1),T(ft=>{const lt=new Set(ft);return lt.delete(Te.name),lt}),oe(Te.name),be(Te.name)},P=Te=>{h(Te),g([])},Z=(Te,ft)=>{g(ft?lt=>lt.includes(Te)?lt:[...lt,Te]:lt=>lt.filter(an=>an!==Te))},re=(Te,ft)=>{g(ft?lt=>{const an=Te.filter(wa=>!lt.includes(wa));return[...lt,...an]}:lt=>lt.filter(an=>!Te.includes(an)))},de=Te=>{I(Te)},ge=p.useCallback(Te=>{E(Te)},[]),ce=p.useCallback(Te=>{w(Te)},[]);p.useEffect(()=>{N&&(N.some(ft=>ft.required&&ft.showInUI!==!1&&ft.name!=="Fields")||w(!0))},[N]);const Ae=()=>{v<q&&x(v+1)},Re=()=>{v>1&&x(v-1)},xe=()=>{if(n)return l!==null&&C;if(s==="fields-only")switch(v){case 1:return m.length>0;default:return!1}switch(v){case 1:return l!==null;case 2:return C;case 3:return d!=="";case 4:return m.length>0;case 5:return W!==null&&W.fullyQualifiedName!==""&&W.isValid;default:return!1}},Je=()=>v>1,We=(Te,ft)=>{if(!Te)return ft;const lt=Te.find(an=>an.name===ft);return(lt==null?void 0:lt.destinationName)??ft},zt=()=>{if(n&&v===1)return N&&l?o.jsx(fT,{connector:l,connectorSpecification:N,onConfigurationChange:ge,onValidationChange:ce,initialConfiguration:b,loading:U}):null;if(s==="fields-only")switch(v){case 1:return d&&A?o.jsx(hT,{connectorFields:A,selectedField:d,selectedFields:m,onFieldToggle:Z,onSelectAllFields:re}):null;default:return null}switch(v){case 1:return o.jsx(GX,{connectors:D,selectedConnector:l,loading:k,error:H,onConnectorSelect:L,onConnectorDoubleClick:()=>{x(Te=>Te<q?Te+1:Te)}});case 2:return l&&N?o.jsx(fT,{connector:l,connectorSpecification:N,onConfigurationChange:ge,onValidationChange:ce,initialConfiguration:b,loading:U}):null;case 3:return l&&A?o.jsx(ZX,{connectorFields:A,selectedField:d,connectorName:l.displayName,loading:B,onFieldSelect:P}):null;case 4:return d&&A?o.jsx(hT,{connectorFields:A,selectedField:d,selectedFields:m,onFieldToggle:Z,onSelectAllFields:re}):null;case 5:return d&&A?o.jsx(zJ,{dataStorageType:t,destinationName:We(A,d),connectorName:(l==null?void 0:l.displayName)??"",target:W,onTargetChange:de}):null;default:return null}};return o.jsxs("div",{className:"flex h-full flex-col p-4",children:[o.jsx("div",{className:"mb-6 flex-1 overflow-x-visible overflow-y-auto",children:zt()}),o.jsx("div",{className:"bg-background -mx-4 border-t px-4 pt-4",children:o.jsx(VJ,{currentStep:v,totalSteps:q,canGoNext:xe(),canGoBack:Je(),isLoading:U||B,onNext:Ae,onBack:Re,onFinish:()=>{n&&l?e({source:{name:l.name,configuration:[b],node:(r==null?void 0:r.source.node)??d,fields:(r==null?void 0:r.source.fields)??m},storage:(r==null?void 0:r.storage)??{fullyQualifiedName:(r==null?void 0:r.storage.fullyQualifiedName)??""}}):s==="fields-only"&&r?e({source:{...r.source,fields:m},storage:r.storage}):l&&W&&e({source:{name:l.name,configuration:[b],node:d,fields:m},storage:{fullyQualifiedName:W.fullyQualifiedName}})}})})]})}function VO({isOpen:e,onClose:t,dataStorageType:n,onSubmit:r,configurationOnly:s=!1,existingConnector:l=null,mode:c="full"}){return o.jsx(Ai,{open:e,onOpenChange:t,children:o.jsxs(Di,{className:"flex h-screen min-w-[480px] flex-col",children:[o.jsxs(Oi,{children:[o.jsx(fg,{children:c==="fields-only"?"Edit Fields":l!=null&&l.source.name?"Table filled by connector":"Setup Connector"}),o.jsx(hg,{children:c==="fields-only"?"Select which fields to include in your data mart":"Setup your connector to use in your data mart"})]}),o.jsx("div",{className:"flex-1 overflow-x-visible overflow-y-auto",children:o.jsx(HJ,{onSubmit:d=>{r(d),t()},dataStorageType:n,configurationOnly:s||c==="configuration-only",existingConnector:l,mode:c})})]})})}const HS=({dataStorageType:e,onSubmit:t,children:n,configurationOnly:r=!1,existingConnector:s=null})=>{const[l,c]=p.useState(!1),d=()=>{c(!0)},h=()=>{c(!1)},m=()=>n?o.jsx("div",{onClick:d,style:{cursor:"pointer"},children:n}):null;return o.jsxs(o.Fragment,{children:[m(),l&&o.jsx(tu,{children:o.jsx(VO,{isOpen:l,onClose:h,dataStorageType:e,onSubmit:t,configurationOnly:r,existingConnector:s})})]})};function $J({storageType:e,onSetupConnector:t}){return o.jsx("div",{className:"space-y-4",children:o.jsx(HS,{dataStorageType:e,onSubmit:t,configurationOnly:!1,children:o.jsxs(we,{type:"button",variant:"outline",className:"flex h-24 w-full items-center justify-center gap-2 rounded-md border-0 border-b border-gray-200 bg-white shadow-none hover:bg-white hover:shadow-xs dark:bg-white/2",children:[o.jsx("div",{className:"text-foreground flex h-7 w-7 items-center justify-center rounded-sm bg-gray-200/50 transition-colors duration-200 group-hover:bg-gray-200/75 dark:bg-white/8 dark:group-hover:bg-white/10",children:o.jsx(mL,{className:"h-4 w-4",strokeWidth:2.25})}),o.jsx("span",{children:"Setup Connector"}),o.jsx(_o,{className:"h-6 w-6"})]})})})}const BJ=e=>{switch(e){case Pe.GOOGLE_BIGQUERY:return"Google BigQuery";case Pe.AWS_ATHENA:return"AWS Athena";default:return e}},Lc=e=>typeof e=="object"&&"connector"in e,jd=e=>{if(!Lc(e))return!1;const{source:t,storage:n}=e.connector,r=!!t.name&&!!t.configuration&&t.configuration.length>0&&!!t.node&&!!t.fields&&t.fields.length>0,s=!!n.fullyQualifiedName&&n.fullyQualifiedName.split(".").length===2;return r&&s};function GJ({configIndex:e,connectorDef:t,onRemoveConfiguration:n,onUpdateConfiguration:r,dataMartStatus:s,totalConfigurations:l,dataStorage:c}){const d=Ii.getInfo(c.type),{connectors:h,fetchAvailableConnectors:m}=Ll();p.useEffect(()=>{m()},[m]);const g=C=>{const w=h.find(R=>R.name===C);if(w!=null&&w.logoBase64)return()=>o.jsx(Tf,{base64:w.logoBase64,size:24})},v=()=>{const C=t.connector.source.node||"No node selected";return o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx("span",{className:"text-muted-foreground/75",children:"Node:"})," ",o.jsx("span",{className:"text-muted-foreground font-medium",children:C}),o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(cb,{className:"h-4 w-4"})}),o.jsx(Ot,{children:"Open connector configuration"})]})]})},x=(C,w,R)=>o.jsxs("span",{children:[o.jsxs("span",{className:"text-muted-foreground/75",children:[C,":"]})," ",o.jsx(Bn,{href:R,onClick:T=>{T.stopPropagation()},children:w})]}),b=()=>{switch(c.type){case Pe.GOOGLE_BIGQUERY:{const C=c.config.projectId,w=t.connector.storage.fullyQualifiedName,R=w.split(".")[0],T=w.split(".")[1],j=`https://console.cloud.google.com/bigquery?project=${C}&ws=!1m4!1m3!3m2!1s${C}!2s${R}`,O=`https://console.cloud.google.com/bigquery?project=${C}&ws=!1m4!1m3!3m2!1s${C}!2s${R}!3s${T}`;return o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[x("Dataset",R,j),o.jsx("span",{className:"text-muted-foreground",children:"•"}),x("Table",T,O),o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(Xr,{className:"h-4 w-4"})}),o.jsx(Ot,{children:"The dataset and table are automatically created during the first run of the data mart, if they don't already exist"})]})]})}case Pe.AWS_ATHENA:{const C=c.config.region,w=t.connector.storage.fullyQualifiedName,[R,T]=w.split("."),j=`https://console.aws.amazon.com/athena/home?region=${C}#/query-editor`;return o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[x("Database",R,j),o.jsx("span",{className:"text-muted-foreground",children:"•"}),x("Table",T,j),o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(Xr,{className:"h-4 w-4"})}),o.jsx(Ot,{children:"The database and table are automatically created during the first run of the data mart, if they don't already exist"})]})]})}default:return"Unknown storage type configuration"}},E=()=>!(s===lr.PUBLISHED&&l===1);return o.jsxs("div",{className:"border-border flex w-full items-center rounded-lg border-1 p-1 dark:bg-white/2",children:[o.jsx("div",{className:"flex-grow",children:o.jsxs("div",{className:"grid grid-cols-2 items-center gap-4",children:[o.jsx(HS,{dataStorageType:c.type,onSubmit:r(e),configurationOnly:!0,existingConnector:{source:{...t.connector.source,configuration:[t.connector.source.configuration[e]]},storage:t.connector.storage},children:o.jsx(k0,{icon:g(t.connector.source.name),title:t.connector.source.name||"Connector",subtitle:v(),className:"bg-background hover:bg-muted min-h-[80px] cursor-pointer border-0 transition-colors hover:shadow-none"})}),o.jsx(k0,{title:BJ(c.type),icon:d.icon,subtitle:b(),className:"bg-background min-h-[80px] cursor-default border-0 hover:shadow-none dark:bg-white/2"})]})}),o.jsx("div",{className:"shrink-0 px-4",children:o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(we,{type:"button",variant:"ghost",onClick:()=>{E()&&n(e)},disabled:!E(),children:o.jsx(No,{className:"h-4 w-4"})})}),!E()&&o.jsx(Ot,{children:"Cannot remove the last configuration in published pipeline"})]})})]})}function qJ({storageType:e,onAddConfiguration:t,existingConnector:n}){return o.jsx("div",{children:o.jsx(HS,{dataStorageType:e,onSubmit:r=>{const s=r.source.configuration[0]||{};t(s)},configurationOnly:!0,existingConnector:n,children:o.jsxs(we,{type:"button",variant:"outline",className:"dm-card-table-add-field-btn cursor-pointer",children:[o.jsx(ea,{className:"h-4 w-4"}),o.jsx("span",{children:"Configuration"})]})})})}function ZJ({control:e,storageType:t}){const{dataMart:n,runDataMart:r}=ds(),{setValue:s,getValues:l,trigger:c}=Su(),[d,h]=p.useState(!1),m=()=>{setTimeout(()=>void c("definition"),0)},g=(n==null?void 0:n.status)??lr.DRAFT,v=j=>{const O=j.source,D=j.storage;s("definition",{connector:{source:O,storage:D}},{shouldDirty:!0,shouldTouch:!0}),m()},x=async j=>{if(n){if(n.status.code!==lr.PUBLISHED){dn.error("Manual run is only available for published data marts");return}await r({id:n.id,payload:j})}},b=j=>O=>{const N=l().definition;if(typeof N=="object"&&Lc(N)){const A=[...N.connector.source.configuration];A[j]=O.source.configuration[0]||{};const k={connector:{...N.connector,source:{...N.connector.source,configuration:A}}};s("definition",k,{shouldDirty:!0,shouldTouch:!0}),m()}},E=j=>{const D=l().definition;if(typeof D=="object"&&Lc(D)){const N={connector:{...D.connector,source:{...D.connector.source,fields:j.source.fields}}};s("definition",N,{shouldDirty:!0,shouldTouch:!0}),m()}h(!1)},C=j=>{x({runType:j.runType,data:j.data})},w=j=>{const O=j.connector.source.fields.length;return o.jsxs(we,{type:"button",variant:"outline",onClick:()=>{h(!0)},className:"dm-card-table-add-field-btn cursor-pointer",children:[o.jsx(aL,{className:"h-4 w-4"}),o.jsxs("span",{children:["Edit Fields (",String(O),")"]})]})},R=j=>{const D=l().definition;if(Lc(D)&&D.connector.source.configuration.length<=1){const N=RO(Qe.CONNECTOR);s("definition",N,{shouldDirty:!0,shouldTouch:!0}),m()}if(typeof D=="object"&&Lc(D)&&D.connector.source.configuration.length>1){const N={...D.connector.source,configuration:D.connector.source.configuration.filter((k,U)=>U!==j)},A={connector:{...D.connector,source:N}};s("definition",A,{shouldDirty:!0,shouldTouch:!0}),m()}},T=j=>{const D=l().definition;if(Lc(D)){const N={...D.connector.source,configuration:[...D.connector.source.configuration,j]},A={connector:{...D.connector,source:N}};s("definition",A,{shouldDirty:!0,shouldTouch:!0}),m()}};return o.jsxs(o.Fragment,{children:[o.jsx(Kt,{control:e,name:"definition",render:({field:j})=>o.jsxs(Yt,{children:[o.jsx(Wt,{children:o.jsx("div",{className:"space-y-3",children:!jd(j.value)||g===lr.DRAFT?o.jsx($J,{storageType:t,onSetupConnector:v}):o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(qJ,{storageType:t,onAddConfiguration:T,existingConnector:jd(j.value)?{source:j.value.connector.source,storage:j.value.connector.storage}:void 0}),jd(j.value)&&w(j.value)]}),o.jsx("div",{className:"flex items-center gap-2",children:n&&n.definitionType===Qe.CONNECTOR&&o.jsx(jD,{configuration:n.definition,onManualRun:C,children:o.jsxs(we,{variant:"outline",children:[o.jsx(lb,{className:"h-4 w-4"}),o.jsx("span",{children:"Manual Run..."})]})})})]}),o.jsx("div",{className:"space-y-3",children:jd(j.value)&&(n!=null&&n.storage)?j.value.connector.source.configuration.map((O,D)=>{const N=j.value;return o.jsx(tu,{children:o.jsx(GJ,{configIndex:D,connectorDef:N,dataStorage:n.storage,onRemoveConfiguration:R,onUpdateConfiguration:b,dataMartStatus:typeof g=="object"?g.code:g,totalConfigurations:N.connector.source.configuration.length},D)},D)}):null})]})})}),o.jsx(nn,{})]})}),o.jsx(tu,{children:o.jsx(VO,{isOpen:d,onClose:()=>{h(!1)},onSubmit:E,dataStorageType:t,existingConnector:jd(l().definition)?{source:l().definition.connector.source,storage:l().definition.connector.storage}:void 0,mode:"fields-only"})})]})}function KJ({definitionType:e,storageType:t}){const{control:n}=Su();return o.jsxs("div",{className:"space-y-2",children:[e===Qe.SQL&&o.jsx(UX,{control:n}),e===Qe.TABLE&&o.jsx(FX,{control:n,storageType:t}),e===Qe.VIEW&&o.jsx(zX,{control:n,storageType:t}),e===Qe.TABLE_PATTERN&&o.jsx(VX,{control:n,storageType:t}),e===Qe.CONNECTOR&&o.jsx(ZJ,{control:n,storageType:t})]})}function YJ(e){if(e===0)return"0 Bytes";const t=1024,n=["Bytes","KB","MB","GB","TB"],r=Math.floor(Math.log(e)/Math.log(t));return`${Number.parseFloat((e/Math.pow(t,r)).toFixed(2)).toString()} ${n[r]}`}function QJ(e,t){const[n,r]=p.useState(e);return p.useEffect(()=>{const s=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(s)}},[e,t]),n}const WJ=300;function XJ({sql:e,dataMartId:t,debounceDelay:n=WJ,className:r="",onValidationStateChange:s}){const[l,c]=p.useState({isLoading:!1,isValid:null,error:null,bytes:null}),d=p.useRef(null),h=QJ(e.trim(),n);p.useEffect(()=>{if(!h){const x={isLoading:!1,isValid:null,error:null,bytes:null};c(x),s==null||s(x);return}d.current&&d.current.abort(),d.current=new AbortController;const g=d.current;return(async()=>{const x={isLoading:!0,isValid:null,error:null,bytes:null};c(x),s==null||s(x);try{const b=await vr.validateSql(t,h,g);if(!g.signal.aborted){const E={isLoading:!1,isValid:b.isValid,error:b.error,bytes:b.bytes??null};c(E),s==null||s(E)}}catch(b){if(!g.signal.aborted){const E={isLoading:!1,isValid:!1,error:b instanceof Error?b.message:"Validation error",bytes:null};c(E),s==null||s(E)}}})(),()=>{g.abort()}},[h,t,s]);const m=()=>l.isLoading?o.jsxs("div",{className:"flex h-5 items-center gap-2",children:[o.jsx(su,{className:"h-4 w-4 animate-spin"}),o.jsx("span",{className:"text-sm",children:"Validating..."})]}):l.isValid===null?o.jsxs("div",{className:"flex h-5 items-center gap-2 text-gray-500",children:[o.jsx(zm,{className:"h-4 w-4"}),o.jsx("span",{className:"text-sm",children:"Type a query to get started"})]}):l.isValid?o.jsxs("div",{className:"flex h-5 items-center gap-2",children:[o.jsx(gj,{className:"h-4 w-4 text-green-600"}),o.jsx("span",{className:"text-sm font-medium text-green-600",children:"Valid SQL code"}),l.bytes!==null&&o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"mx-1 text-gray-400",children:"•"}),o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx(zm,{className:"h-3 w-3 text-gray-600"}),o.jsx("span",{className:"text-xs text-gray-600",children:YJ(l.bytes)})]})}),o.jsx(Ot,{children:o.jsx("p",{className:"text-xs",children:"This is an estimated volume and may differ from the actual value"})})]})]})]}):o.jsxs("div",{className:"flex h-9 items-center gap-2",children:[o.jsx(Ap,{className:"h-4 w-4 flex-shrink-0 text-red-600"}),l.error&&o.jsx("span",{className:"text-xs text-red-500",children:l.error})]});return o.jsx("div",{className:`inline-flex h-9 items-center px-3 py-2 ${r}`,children:m()})}function JJ(){const{dataMart:e,updateDataMartDefinition:t}=ds();if(!e)throw new Error("Data mart not found");const{definitionType:n,definition:r,id:s,storage:{type:l}}=e,[c,d]=p.useState(n),[h,m]=p.useState({isValid:null,isLoading:!1,error:null}),g=p.useCallback(()=>{if(!c)return;const H={definitionType:c,definition:RO(c)};return r?{definitionType:c,definition:r}:H},[c,r]),v=p.useCallback(()=>{if(!c)return;const H=PX(c,l);return zl(H)},[c,l]),x=Pi({resolver:v(),defaultValues:g(),mode:"onChange"}),{handleSubmit:b,reset:E,watch:C,formState:{isDirty:w,isValid:R}}=x,T=(H,Q)=>{if(H!==Qe.SQL)return"";const ne=Q;return(ne==null?void 0:ne.sqlQuery)??""},j=C("definition"),O=T(c,j);p.useEffect(()=>{c&&E(g())},[c,E,g]);const D=p.useCallback(H=>{m({isLoading:H.isLoading,isValid:H.isValid,error:H.error})},[]),N=H=>{d(H)},A=async H=>{if(c&&s)try{await t(s,H.definitionType,H.definition),E(H)}catch(Q){console.error("Failed to update data mart definition:",Q)}},k=H=>{if(H.preventDefault(),c===Qe.SQL&&h.isValid===!1){console.error("Cannot submit form with invalid SQL:",h.error);return}b(A)(H)},U=()=>{E(g())},B=()=>c?o.jsxs("form",{onSubmit:k,className:"space-y-4",children:[o.jsx(KJ,{definitionType:c,storageType:l}),o.jsxs("div",{className:"flex items-center gap-4",children:[o.jsx(we,{variant:"default",type:"submit",disabled:!R||!w||c===Qe.SQL&&(h.isValid===!1||h.isLoading),children:"Save"}),o.jsx(we,{type:"button",variant:"ghost",onClick:U,disabled:!w,children:"Discard"}),c===Qe.SQL&&O&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-6 w-px bg-gray-300"}),o.jsx(XJ,{sql:O,dataMartId:s,onValidationStateChange:D})]})]})]}):null;return o.jsx(D4,{...x,children:o.jsxs("div",{className:"space-y-4",children:[!n&&o.jsx(DX,{initialType:c,onTypeSelect:N}),B()]})})}function eee(e){switch(e){case Pe.GOOGLE_BIGQUERY:return{type:"bigquery-data-mart-schema",fields:[]};case Pe.AWS_ATHENA:return{type:"athena-data-mart-schema",fields:[]};default:throw new Error(`Unsupported storage type: ${e}`)}}function HO(e){return e.type==="bigquery-data-mart-schema"}function $O(e){return e.type==="athena-data-mart-schema"}function pT(e){return e!==null&&typeof e=="object"&&"mode"in e}function gT(e){return e!==null&&typeof e=="object"&&"isPrimaryKey"in e}function tee(e){return e==null?"":typeof e=="string"||typeof e=="number"||typeof e=="boolean"?String(e):""}function kx(e){return e==null?e:JSON.parse(JSON.stringify(e))}function nee(e){const t=kx(e),[n,r]=p.useState(t),[s,l]=p.useState(!1);p.useEffect(()=>{const h=kx(e);r(h),l(!1)},[e]);const c=p.useCallback(h=>{n?HO(n)&&h.every(pT)?(r({...n,fields:h}),l(!0)):$O(n)&&h.every(gT)&&(r({...n,fields:h}),l(!0)):h.length>0&&(pT(h[0])?(r({type:"bigquery-data-mart-schema",fields:h}),l(!0)):gT(h[0])&&(r({type:"athena-data-mart-schema",fields:h}),l(!0)))},[n]),d=p.useCallback(()=>{const h=kx(e);r(h),l(!1)},[e]);return{schema:n,isDirty:s,updateSchema:c,resetSchema:d,setIsDirty:l}}function ree(e,t){const n=p.useRef(!1),r=p.useRef(!1),[s,l]=p.useState("idle");return p.useEffect(()=>{e||(n.current||r.current)&&(l(t?"error":"success"),n.current=!1,r.current=!1)},[e,t]),{operationStatus:s,startSaveOperation:()=>{n.current=!0,l("idle")},startActualizeOperation:()=>{r.current=!0,l("idle")},resetOperationStatus:()=>{l("idle")}}}function aee(e){const t=p.useMemo(()=>Array.isArray(e)?Object.fromEntries(e.filter(s=>s.meta&&s.meta.hidden).map(s=>["id"in s&&s.id?s.id:"accessorKey"in s&&typeof s.accessorKey=="string"?s.accessorKey:void 0,!1]).filter(([s])=>s!==void 0)):{},[e]),[n,r]=p.useState({});return p.useEffect(()=>{r(t)},[t]),{columnVisibility:n,setColumnVisibility:r,defaultHiddenColumns:t}}function BO(e,t){const n=e.name?e.name.toLowerCase().includes(t):!1,r=e.alias?e.alias.toLowerCase().includes(t):!1,s=e.description?e.description.toLowerCase().includes(t):!1;if(n||r||s)return!0;const l=e;return l.fields&&l.fields.length>0?l.fields.some(c=>BO(c,t)):!1}function GO(e,t,n=""){const r=[];return e.forEach((s,l)=>{const c=n?`${n}.${String(l)}`:String(l),d=s.name?s.name.toLowerCase().includes(t):!1,h=s.alias?s.alias.toLowerCase().includes(t):!1,m=s.description?s.description.toLowerCase().includes(t):!1;if((d||h||m)&&r.push(c),s.fields&&s.fields.length>0){const g=GO(s.fields,t,c);g.length>0&&(r.includes(c)||r.push(c),r.push(...g))}}),r}function see(e,t,n){const r=e.original;if(!n)return!0;const s=n.toLowerCase();return BO(r,s)}function oee(e){const[t,n]=p.useState(""),r=p.useCallback(l=>{n(l),e.setGlobalFilter(l)},[e]),s=t.toLowerCase();return{value:t,onChange:r,searchValue:s}}var ss=(e=>(e.CONNECTED="CONNECTED",e.CONNECTED_WITH_DEFINITION_MISMATCH="CONNECTED_WITH_DEFINITION_MISMATCH",e.DISCONNECTED="DISCONNECTED",e))(ss||{}),ef=(e=>(e.NULLABLE="NULLABLE",e.REQUIRED="REQUIRED",e.REPEATED="REPEATED",e))(ef||{}),An=(e=>(e.INTEGER="INTEGER",e.FLOAT="FLOAT",e.NUMERIC="NUMERIC",e.BIGNUMERIC="BIGNUMERIC",e.STRING="STRING",e.BYTES="BYTES",e.BOOLEAN="BOOLEAN",e.DATE="DATE",e.TIME="TIME",e.DATETIME="DATETIME",e.TIMESTAMP="TIMESTAMP",e.GEOGRAPHY="GEOGRAPHY",e.JSON="JSON",e.RECORD="RECORD",e.STRUCT="STRUCT",e.RANGE="RANGE",e.INTERVAL="INTERVAL",e))(An||{}),$S=(e=>(e.BOOLEAN="BOOLEAN",e.TINYINT="TINYINT",e.SMALLINT="SMALLINT",e.INTEGER="INTEGER",e.BIGINT="BIGINT",e.REAL="REAL",e.FLOAT="FLOAT",e.DOUBLE="DOUBLE",e.DECIMAL="DECIMAL",e.CHAR="CHAR",e.VARCHAR="VARCHAR",e.STRING="STRING",e.BINARY="BINARY",e.VARBINARY="VARBINARY",e.DATE="DATE",e.TIME="TIME",e.TIMESTAMP="TIMESTAMP",e.TIME_WITH_TIME_ZONE="TIME WITH TIME ZONE",e.TIMESTAMP_WITH_TIME_ZONE="TIMESTAMP WITH TIME ZONE",e.INTERVAL_YEAR_TO_MONTH="INTERVAL YEAR TO MONTH",e.INTERVAL_DAY_TO_SECOND="INTERVAL DAY TO SECOND",e.ARRAY="ARRAY",e.MAP="MAP",e.STRUCT="STRUCT",e.ROW="ROW",e.JSON="JSON",e))($S||{});function iee(e){const[t,n]=p.useState(new Set),[r,s]=p.useState(null),l=p.useRef(""),c=p.useMemo(()=>{const E=C=>C.some(w=>w.type===An.RECORD||w.type===An.STRUCT||w.fields&&E(w.fields));return E(e)},[e]),d=p.useCallback(E=>{n(C=>{const w=new Set(C);return w.has(E)?w.delete(E):w.add(E),w})},[]),h=p.useCallback(()=>{const E=[],C=(w,R="")=>{w.forEach((T,j)=>{const O=R?`${R}.${String(j)}`:String(j);(T.type===An.RECORD||T.type===An.STRUCT)&&T.fields&&T.fields.length>0&&(E.push(O),C(T.fields,O))})};C(e),n(w=>E.every(T=>w.has(T))?new Set:new Set(E))},[e]),m=p.useMemo(()=>{const E=[],C=(w,R="",T=0)=>{w.forEach((j,O)=>{const D=R?`${R}.${String(O)}`:String(O),N=j.type===An.RECORD||j.type===An.STRUCT;E.push({...j,path:D,level:T}),N&&j.fields&&t.has(D)&&C(j.fields,D,T+1)})};return C(e),E},[e,t]),g=p.useCallback(E=>{if(E!==l.current)if(l.current=E,E){r===null&&s(new Set(t));const w=GO(e,E).filter(R=>{const T=R.split(".").map(Number);let j=e,O;for(let D=0;D<T.length;D++){if(O=j[T[D]],!O)return!1;if((O.type===An.RECORD||O.type===An.STRUCT)&&O.fields&&O.fields.length>0)return!0;D<T.length-1&&(j=O.fields??[])}return!1});n(R=>{const T=new Set(R);return w.forEach(j=>{T.add(j)}),T})}else r!==null&&(n(r),s(null))},[e,t,r]),v=p.useCallback(E=>{const C=m[E];return C.type===An.RECORD||C.type===An.STRUCT},[m]),x=p.useMemo(()=>e.map(E=>({...E,fields:void 0})),[e]),b=p.useMemo(()=>{const E=[],C=(w,R="")=>{w.forEach((T,j)=>{const O=R?`${R}.${String(j)}`:String(j);(T.type===An.RECORD||T.type===An.STRUCT)&&T.fields&&T.fields.length>0&&(E.push(O),C(T.fields,O))})};return C(e),E.length===0?!1:E.every(w=>t.has(w))},[e,t]);return{expandedRecords:t,hasRecordFields:c,toggleRecordExpansion:d,toggleAllRecords:h,flattenedFields:m,handleSearchChange:g,isRecordType:v,topLevelFields:x,allExpanded:b}}function lee(e,t,n,r){const s=p.useCallback((h,m)=>{if(n){const g=[...e],v=t[h].path;if(!v)g[h]={...g[h],...m};else{const x=v.split(".").map(Number);let b=g,E;for(let w=0;w<x.length-1;w++)E=b[x[w]],b=E.fields??[];const C=x[x.length-1];b[C]&&(b[C]={...b[C],...m})}n(g)}},[e,t,n]),l=p.useCallback(()=>{if(n){const h={name:"",type:An.STRING,mode:ef.NULLABLE,isPrimaryKey:!1,status:ss.DISCONNECTED};n([...e,h])}},[e,n]),c=p.useCallback(h=>{if(n){const m=[...e],g=t[h].path;if(!g)m.splice(h,1);else{const v=g.split(".").map(Number);let x=m,b;for(let C=0;C<v.length-1;C++)b=x[v[C]],x=b.fields??[];const E=v[v.length-1];x.splice(E,1)}n(m)}},[e,t,n]),d=p.useCallback(h=>{var m,g;if(n&&r){const v=[...e],x=t[h].path,b={name:"",type:An.STRING,mode:ef.NULLABLE,isPrimaryKey:!1,status:ss.DISCONNECTED};if(!x)(m=v[h]).fields??(m.fields=[]),v[h].fields.push(b);else{const E=x.split(".").map(Number);let C=v;for(let w=0;w<E.length;w++){const R=E[w];w===E.length-1?((g=C[R]).fields??(g.fields=[]),C[R].fields.push(b)):C=C[R].fields??[]}}n(v)}},[e,t,n,r]);return{updateField:s,handleAddRow:l,handleDeleteRow:c,handleAddNestedField:d}}function qO(e,t,n){return{handleDragEnd:p.useCallback(s=>{const{active:l,over:c}=s;if(!c||l.id===c.id||!t)return;if(!n){const x=Number(l.id),b=Number(c.id),E=[...e],[C]=E.splice(x,1);E.splice(b,0,C),t(E);return}const d=n.findIndex((x,b)=>(x.path??String(b))===l.id),h=n.findIndex((x,b)=>(x.path??String(b))===c.id);if(d===-1||h===-1)return;const m=n[d].path,g=n[h].path,v=[...e];if(!m&&!g){const[x]=v.splice(d,1);v.splice(h,0,x),t(v);return}if(m&&g){const x=m.split(".").map(Number),b=g.split(".").map(Number);if(x.length===b.length&&x.slice(0,-1).join(".")===b.slice(0,-1).join(".")){let E=v;for(let T=0;T<x.length-1;T++)E=E[x[T]].fields??[];const C=x[x.length-1],w=b[b.length-1],[R]=E.splice(C,1);E.splice(w,0,R),t(v)}}},[e,n,t])}}function cee(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return p.useMemo(()=>r=>{t.forEach(s=>s(r))},t)}const jg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function wu(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function BS(e){return"nodeType"in e}function ta(e){var t,n;return e?wu(e)?e:BS(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function GS(e){const{Document:t}=ta(e);return e instanceof t}function Pf(e){return wu(e)?!1:e instanceof ta(e).HTMLElement}function ZO(e){return e instanceof ta(e).SVGElement}function Ru(e){return e?wu(e)?e.document:BS(e)?GS(e)?e:Pf(e)||ZO(e)?e.ownerDocument:document:document:document}const Us=jg?p.useLayoutEffect:p.useEffect;function qS(e){const t=p.useRef(e);return Us(()=>{t.current=e}),p.useCallback(function(){for(var n=arguments.length,r=new Array(n),s=0;s<n;s++)r[s]=arguments[s];return t.current==null?void 0:t.current(...r)},[])}function uee(){const e=p.useRef(null),t=p.useCallback((r,s)=>{e.current=setInterval(r,s)},[]),n=p.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,n]}function tf(e,t){t===void 0&&(t=[e]);const n=p.useRef(e);return Us(()=>{n.current!==e&&(n.current=e)},t),n}function Uf(e,t){const n=p.useRef();return p.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function bp(e){const t=qS(e),n=p.useRef(null),r=p.useCallback(s=>{s!==n.current&&(t==null||t(s,n.current)),n.current=s},[]);return[n,r]}function B0(e){const t=p.useRef();return p.useEffect(()=>{t.current=e},[e]),t.current}let Ix={};function Ff(e,t){return p.useMemo(()=>{if(t)return t;const n=Ix[e]==null?0:Ix[e]+1;return Ix[e]=n,e+"-"+n},[e,t])}function KO(e){return function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),s=1;s<n;s++)r[s-1]=arguments[s];return r.reduce((l,c)=>{const d=Object.entries(c);for(const[h,m]of d){const g=l[h];g!=null&&(l[h]=g+e*m)}return l},{...t})}}const qc=KO(1),Sp=KO(-1);function dee(e){return"clientX"in e&&"clientY"in e}function ZS(e){if(!e)return!1;const{KeyboardEvent:t}=ta(e.target);return t&&e instanceof t}function fee(e){if(!e)return!1;const{TouchEvent:t}=ta(e.target);return t&&e instanceof t}function G0(e){if(fee(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return dee(e)?{x:e.clientX,y:e.clientY}:null}const nf=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[nf.Translate.toString(e),nf.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),vT="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function hee(e){return e.matches(vT)?e:e.querySelector(vT)}const mee={display:"none"};function pee(e){let{id:t,value:n}=e;return _e.createElement("div",{id:t,style:mee},n)}function gee(e){let{id:t,announcement:n,ariaLiveType:r="assertive"}=e;const s={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return _e.createElement("div",{id:t,style:s,role:"status","aria-live":r,"aria-atomic":!0},n)}function vee(){const[e,t]=p.useState("");return{announce:p.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const YO=p.createContext(null);function yee(e){const t=p.useContext(YO);p.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function xee(){const[e]=p.useState(()=>new Set),t=p.useCallback(r=>(e.add(r),()=>e.delete(r)),[e]);return[p.useCallback(r=>{let{type:s,event:l}=r;e.forEach(c=>{var d;return(d=c[s])==null?void 0:d.call(c,l)})},[e]),t]}const bee={draggable:`
|
package/dist/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" type="image/png" href="/favicon.png" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>OWOX</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-B_KqYXXu.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-wan4gv6z.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
package/package.json
CHANGED