import{i as e,n as t,t as n}from"./jsx-runtime-DG_AJzB_.js";import{t as r}from"./compiler-runtime-DCc3R3Xn.js";import{a as i,o as a}from"./api-base-url-DIb6qukm.js";import{n as o,t as s}from"./createReactComponent-_L2mp4Ui.js";import{t as c}from"./data-source-connection-form-DEf4i7OC.js";import{t as l}from"./auth-client-CVsUOxFj.js";import{z as u}from"./index-BQ5WpFpw.js";import{a as d,n as f,o as p,r as m,t as h}from"./card-CZCl7QNy.js";var g=s(`outline`,`database`,`Database`,[[`path`,{d:`M4 6a8 3 0 1 0 16 0a8 3 0 1 0 -16 0`,key:`svg-0`}],[`path`,{d:`M4 6v6a8 3 0 0 0 16 0v-6`,key:`svg-1`}],[`path`,{d:`M4 12v6a8 3 0 0 0 16 0v-6`,key:`svg-2`}]]),_=r(),v=e(t(),1),y=n(),b=i(`/_authenticated/onboarding/connect-database`);function x(e){if(!(e instanceof Error))return`Failed to finish onboarding`;let t=e.message.trim();return t.length>0?t:`Failed to finish onboarding`}async function S(e){let t=await l.getFullOrganization({query:{organizationId:e}});if(!t.data?.slug)throw Error(`Failed to resolve organization slug`);return t.data.slug}function C(){let e=(0,_.c)(31),t=a(),n=b.useSearch(),r=(0,v.useRef)(null),i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={hasSubmitButton:!1,isDisabled:!0,label:`Create Data Source`},e[0]=i):i=e[0];let[s,l]=(0,v.useState)(i),C=n.orgId,E,D;e[1]!==t||e[2]!==C?(E=()=>{C||(u.error(`Missing organization information`),t({to:`/onboarding/create-org`}))},D=[C,t],e[1]=t,e[2]=C,e[3]=E,e[4]=D):(E=e[3],D=e[4]),(0,v.useEffect)(E,D);let O;e[5]!==t||e[6]!==C?(O=function(e){C&&S(C).then(t=>(u.success(`Data source connected (${e})`),t)).then(async e=>t({params:{org_slug:e},to:`/$org_slug/home`})).catch(T)},e[5]=t,e[6]=C,e[7]=O):O=e[7];let k=O,A;e[8]!==t||e[9]!==C?(A=async function(){if(C)try{await t({params:{org_slug:await S(C)},to:`/$org_slug/home`})}catch(e){let t=e;u.error(x(t))}},e[8]=t,e[9]=C,e[10]=A):A=e[10];let j=A,M;e[11]===Symbol.for(`react.memo_cache_sentinel`)?(M=function(e){return e?[...e.querySelectorAll(`button[type='submit']`)].find(w):null},e[11]=M):M=e[11];let N=M,P;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(P=function(){let e=N(r.current);!e||e.disabled||e.click()},e[12]=P):P=e[12];let F=P,I,L;if(e[13]===Symbol.for(`react.memo_cache_sentinel`)?(I=()=>{let e=r.current;if(!e)return;let t=()=>{let t=N(e);if(!t){l({hasSubmitButton:!1,isDisabled:!0,label:`Create Data Source`});return}l({hasSubmitButton:!0,isDisabled:t.disabled,label:t.textContent?.trim()||`Create Data Source`})};t();let n=new MutationObserver(t);return n.observe(e,{attributeFilter:[`class`,`disabled`,`hidden`,`data-active`,`data-state`],attributes:!0,characterData:!0,childList:!0,subtree:!0}),()=>n.disconnect()},L=[],e[13]=I,e[14]=L):(I=e[13],L=e[14]),(0,v.useEffect)(I,L),!C)return null;let R;e[15]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,y.jsxs)(d,{className:`shrink-0 border-b text-center`,children:[(0,y.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,y.jsx)(g,{size:24,stroke:1.5})}),(0,y.jsx)(p,{className:`text-xl`,children:`Connect a data source`}),(0,y.jsx)(m,{children:`Connect a data source to start querying your workspace data, or skip to explore first`})]}),e[15]=R):R=e[15];let z;e[16]!==k||e[17]!==C?(z=(0,y.jsx)(`div`,{ref:r,className:`min-h-0 flex-1 overflow-y-auto`,children:(0,y.jsx)(c,{organizationId:C,onSuccess:k,className:`px-6 py-4 [&_button[type='submit']]:sr-only`})}),e[16]=k,e[17]=C,e[18]=z):z=e[18];let B;e[19]!==s.hasSubmitButton||e[20]!==s.isDisabled||e[21]!==s.label?(B=s.hasSubmitButton&&(0,y.jsx)(o,{className:`w-full`,disabled:s.isDisabled,onClick:F,children:s.label}),e[19]=s.hasSubmitButton,e[20]=s.isDisabled,e[21]=s.label,e[22]=B):B=e[22];let V;e[23]===j?V=e[24]:(V=(0,y.jsx)(o,{variant:`ghost`,onClick:()=>{j()},className:`mt-2 w-full`,children:`Skip for now`}),e[23]=j,e[24]=V);let H;e[25]!==B||e[26]!==V?(H=(0,y.jsxs)(`div`,{className:`shrink-0 border-t px-6 py-4`,children:[B,V]}),e[25]=B,e[26]=V,e[27]=H):H=e[27];let U;return e[28]!==z||e[29]!==H?(U=(0,y.jsx)(`div`,{className:`flex min-h-screen items-center justify-center p-6`,children:(0,y.jsxs)(h,{className:`flex h-[min(720px,calc(100vh-3rem))] w-full max-w-md flex-col overflow-hidden`,children:[R,(0,y.jsxs)(f,{className:`flex min-h-0 flex-1 flex-col p-0`,children:[z,H]})]})}),e[28]=z,e[29]=H,e[30]=U):U=e[30],U}function w(e){let t=e.closest(`form`);return t?t.offsetParent!==null:e.offsetParent!==null}function T(e){let t=e instanceof Error?e.message:`Failed to link data source`;u.error(t)}var E=C;export{E as component};