@owox/web 0.11.0-next-20251029154828 → 0.11.0-next-20251030104310
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.
|
@@ -720,10 +720,10 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
720
720
|
monaco.config({ paths: { vs: '...' } })
|
|
721
721
|
|
|
722
722
|
For more please check the link https://github.com/suren-atoyan/monaco-loader#config
|
|
723
|
-
`},LT=XQ(nX)(dD),rX={config:eX},aX=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 fD(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],fD(e[n],t[n]))}),MT(MT({},e),t)}var sX={type:"cancelation",msg:"operation is manually canceled"};function Vx(e){var t=!1,n=new Promise(function(r,s){e.then(function(l){return t?s(sX):r(l)}),e.catch(s)});return n.cancel=function(){return t=!0},n}var oX=["monaco"],iX=WQ.create({config:QQ,isInitialized:!1,resolve:null,reject:null,monaco:null}),hD=OQ(iX,2),Zf=hD[0],Dg=hD[1];function lX(e){var t=rX.config(e),n=t.monaco,r=AQ(t,oX);Dg(function(s){return{config:fD(s.config,r),monaco:n}})}function cX(){var e=Zf(function(t){var n=t.monaco,r=t.isInitialized,s=t.resolve;return{monaco:n,isInitialized:r,resolve:s}});if(!e.isInitialized){if(Dg({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),Vx(Hx);if(window.monaco&&window.monaco.editor)return mD(window.monaco),e.resolve(window.monaco),Vx(Hx);aX(uX,fX)(hX)}return Vx(Hx)}function uX(e){return document.body.appendChild(e)}function dX(e){var t=document.createElement("script");return e&&(t.src=e),t}function fX(e){var t=Zf(function(r){var s=r.config,l=r.reject;return{config:s,reject:l}}),n=dX("".concat(t.config.paths.vs,"/loader.js"));return n.onload=function(){return e()},n.onerror=t.reject,n}function hX(){var e=Zf(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){var r=n.m;mD(r),e.resolve(r)},function(n){e.reject(n)})}function mD(e){Zf().monaco||Dg({monaco:e})}function mX(){return Zf(function(e){var t=e.monaco;return t})}var Hx=new Promise(function(e,t){return Dg({resolve:e,reject:t})}),pD={config:lX,init:cX,__getMonacoInstance:mX},pX={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},$x=pX,gX={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},vX=gX;function yX({children:e}){return je.createElement("div",{style:vX.container},e)}var xX=yX,bX=xX;function SX({width:e,height:t,isEditorReady:n,loading:r,_ref:s,className:l,wrapperProps:c}){return je.createElement("section",{style:{...$x.wrapper,width:e,height:t},...c},!n&&je.createElement(bX,null,r),je.createElement("div",{ref:s,style:{...$x.fullWidth,...!n&&$x.hide},className:l}))}var CX=SX,gD=p.memo(CX);function wX(e){p.useEffect(e,[])}var vD=wX;function EX(e,t,n=!0){let r=p.useRef(!0);p.useEffect(r.current||!n?()=>{r.current=!1}:e,t)}var da=EX;function Zd(){}function Zc(e,t,n,r){return RX(e,r)||TX(e,t,n,r)}function RX(e,t){return e.editor.getModel(yD(e,t))}function TX(e,t,n,r){return e.editor.createModel(t,n,r?yD(e,r):void 0)}function yD(e,t){return e.Uri.parse(t)}function jX({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:w,wrapperProps:C={},beforeMount:E=Zd,onMount:R=Zd}){let[T,j]=p.useState(!1),[O,D]=p.useState(!0),_=p.useRef(null),A=p.useRef(null),M=p.useRef(null),U=p.useRef(R),B=p.useRef(E),G=p.useRef(!1);vD(()=>{let $=pD.init();return $.then(I=>(A.current=I)&&D(!1)).catch(I=>(I==null?void 0:I.type)!=="cancelation"&&console.error("Monaco initialization: error:",I)),()=>_.current?H():$.cancel()}),da(()=>{if(_.current&&A.current){let $=_.current.getOriginalEditor(),I=Zc(A.current,e||"",r||n||"text",l||"");I!==$.getModel()&&$.setModel(I)}},[l],T),da(()=>{if(_.current&&A.current){let $=_.current.getModifiedEditor(),I=Zc(A.current,t||"",s||n||"text",c||"");I!==$.getModel()&&$.setModel(I)}},[c],T),da(()=>{let $=_.current.getModifiedEditor();$.getOption(A.current.editor.EditorOption.readOnly)?$.setValue(t||""):t!==$.getValue()&&($.executeEdits("",[{range:$.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),$.pushUndoStop())},[t],T),da(()=>{var $,I;(I=($=_.current)==null?void 0:$.getModel())==null||I.original.setValue(e||"")},[e],T),da(()=>{let{original:$,modified:I}=_.current.getModel();A.current.editor.setModelLanguage($,r||n||"text"),A.current.editor.setModelLanguage(I,s||n||"text")},[n,r,s],T),da(()=>{var $;($=A.current)==null||$.editor.setTheme(m)},[m],T),da(()=>{var $;($=_.current)==null||$.updateOptions(v)},[v],T);let K=p.useCallback(()=>{var Y;if(!A.current)return;B.current(A.current);let $=Zc(A.current,e||"",r||n||"text",l||""),I=Zc(A.current,t||"",s||n||"text",c||"");(Y=_.current)==null||Y.setModel({original:$,modified:I})},[n,t,s,e,r,l,c]),re=p.useCallback(()=>{var $;!G.current&&M.current&&(_.current=A.current.editor.createDiffEditor(M.current,{automaticLayout:!0,...v}),K(),($=A.current)==null||$.editor.setTheme(m),j(!0),G.current=!0)},[v,m,K]);p.useEffect(()=>{T&&U.current(_.current,A.current)},[T]),p.useEffect(()=>{!O&&!T&&re()},[O,T,re]);function H(){var I,Y,Z,ie;let $=(I=_.current)==null?void 0:I.getModel();d||((Y=$==null?void 0:$.original)==null||Y.dispose()),h||((Z=$==null?void 0:$.modified)==null||Z.dispose()),(ie=_.current)==null||ie.dispose()}return je.createElement(gD,{width:b,height:x,isEditorReady:T,loading:g,_ref:M,className:w,wrapperProps:C})}var _X=jX;p.memo(_X);function NX(e){let t=p.useRef();return p.useEffect(()=>{t.current=e},[e]),t.current}var AX=NX,Dm=new Map;function DX({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:w="100%",className:C,wrapperProps:E={},beforeMount:R=Zd,onMount:T=Zd,onChange:j,onValidate:O=Zd}){let[D,_]=p.useState(!1),[A,M]=p.useState(!0),U=p.useRef(null),B=p.useRef(null),G=p.useRef(null),K=p.useRef(T),re=p.useRef(R),H=p.useRef(),$=p.useRef(r),I=AX(l),Y=p.useRef(!1),Z=p.useRef(!1);vD(()=>{let L=pD.init();return L.then(P=>(U.current=P)&&M(!1)).catch(P=>(P==null?void 0:P.type)!=="cancelation"&&console.error("Monaco initialization: error:",P)),()=>B.current?be():L.cancel()}),da(()=>{var P,W,ae,fe;let L=Zc(U.current,e||r||"",t||s||"",l||n||"");L!==((P=B.current)==null?void 0:P.getModel())&&(v&&Dm.set(I,(W=B.current)==null?void 0:W.saveViewState()),(ae=B.current)==null||ae.setModel(L),v&&((fe=B.current)==null||fe.restoreViewState(Dm.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()&&(Z.current=!0,B.current.executeEdits("",[{range:B.current.getModel().getFullModelRange(),text:r,forceMoveMarkers:!0}]),B.current.pushUndoStop(),Z.current=!1))},[r],D),da(()=>{var P,W;let L=(P=B.current)==null?void 0:P.getModel();L&&s&&((W=U.current)==null||W.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 ie=p.useCallback(()=>{var L;if(!(!G.current||!U.current)&&!Y.current){re.current(U.current);let P=l||n,W=Zc(U.current,r||e||"",t||s||"",P||"");B.current=(L=U.current)==null?void 0:L.editor.create(G.current,{model:W,automaticLayout:!0,...m},g),v&&B.current.restoreViewState(Dm.get(P)),U.current.editor.setTheme(c),d!==void 0&&B.current.revealLine(d),_(!0),Y.current=!0}},[e,t,n,r,s,l,m,g,v,c,d]);p.useEffect(()=>{D&&K.current(B.current,U.current)},[D]),p.useEffect(()=>{!A&&!D&&ie()},[A,D,ie]),$.current=r,p.useEffect(()=>{var L,P;D&&j&&((L=H.current)==null||L.dispose(),H.current=(P=B.current)==null?void 0:P.onDidChangeModelContent(W=>{Z.current||j(B.current.getValue(),W)}))},[D,j]),p.useEffect(()=>{if(D){let L=U.current.editor.onDidChangeMarkers(P=>{var ae;let W=(ae=B.current.getModel())==null?void 0:ae.uri;if(W&&P.find(fe=>fe.path===W.path)){let fe=U.current.editor.getModelMarkers({resource:W});O==null||O(fe)}});return()=>{L==null||L.dispose()}}return()=>{}},[D,O]);function be(){var L,P;(L=H.current)==null||L.dispose(),x?v&&Dm.set(l,B.current.saveViewState()):(P=B.current.getModel())==null||P.dispose(),B.current.dispose()}return je.createElement(gD,{width:b,height:w,isEditorReady:D,loading:h,_ref:G,className:C,wrapperProps:E})}var OX=DX,MX=p.memo(OX);function kX({initialValue:e,onChange:t}){const[n,r]=p.useState((e==null?void 0:e.sqlQuery)??""),{resolvedTheme:s}=s4();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(MX,{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:J("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(Ra,{className:"text-muted-foreground/75 dark:text-muted-foreground/50 h-4 w-4"})})]})]})}var PT=1,IX=.9,LX=.8,PX=.17,Bx=.1,Gx=.999,UX=.9999,FX=.99,zX=/[\\\/_+.#"@\[\(\{&]/,VX=/[\\\/_+.#"@\[\(\{&]/g,HX=/[\s-]/,xD=/[\s-]/g;function Y0(e,t,n,r,s,l,c){if(l===t.length)return s===e.length?PT:FX;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,w;m>=0;)v=Y0(e,t,n,r,m+1,l+1,c),v>g&&(m===s?v*=PT:zX.test(e.charAt(m-1))?(v*=LX,b=e.slice(s,m-1).match(VX),b&&s>0&&(v*=Math.pow(Gx,b.length))):HX.test(e.charAt(m-1))?(v*=IX,w=e.slice(s,m-1).match(xD),w&&s>0&&(v*=Math.pow(Gx,w.length))):(v*=PX,s>0&&(v*=Math.pow(Gx,m-s))),e.charAt(m)!==t.charAt(l)&&(v*=UX)),(v<Bx&&n.charAt(m-1)===r.charAt(l+1)||r.charAt(l+1)===r.charAt(l)&&n.charAt(m-1)!==r.charAt(l))&&(x=Y0(e,t,n,r,m+1,l+2,c),x*Bx>v&&(v=x*Bx)),v>g&&(g=v),m=n.indexOf(h,m+1);return c[d]=g,g}function UT(e){return e.toLowerCase().replace(xD," ")}function $X(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,Y0(e,t,UT(e),UT(t),0,0,{})}var Id='[cmdk-group=""]',qx='[cmdk-group-items=""]',BX='[cmdk-group-heading=""]',bD='[cmdk-item=""]',FT=`${bD}:not([aria-disabled="true"])`,W0="cmdk-item-select",Bc="data-value",GX=(e,t,n)=>$X(e,t,n),SD=p.createContext(void 0),Kf=()=>p.useContext(SD),CD=p.createContext(void 0),Z1=()=>p.useContext(CD),wD=p.createContext(void 0),ED=p.forwardRef((e,t)=>{let n=Gc(()=>{var P,W;return{search:"",value:(W=(P=e.value)!=null?P:e.defaultValue)!=null?W:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=Gc(()=>new Set),s=Gc(()=>new Map),l=Gc(()=>new Map),c=Gc(()=>new Set),d=RD(e),{label:h,children:m,value:g,onValueChange:v,filter:x,shouldFilter:b,loop:w,disablePointerSelection:C=!1,vimBindings:E=!0,...R}=e,T=Nn(),j=Nn(),O=Nn(),D=p.useRef(null),_=nJ();Pl(()=>{if(g!==void 0){let P=g.trim();n.current.value=P,A.emit()}},[g]),Pl(()=>{_(6,re)},[]);let A=p.useMemo(()=>({subscribe:P=>(c.current.add(P),()=>c.current.delete(P)),snapshot:()=>n.current,setState:(P,W,ae)=>{var fe,ge,ue,Ne;if(!Object.is(n.current[P],W)){if(n.current[P]=W,P==="search")K(),B(),_(1,G);else if(P==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let Re=document.getElementById(O);Re?Re.focus():(fe=document.getElementById(T))==null||fe.focus()}if(_(7,()=>{var Re;n.current.selectedItemId=(Re=H())==null?void 0:Re.id,A.emit()}),ae||_(5,re),((ge=d.current)==null?void 0:ge.value)!==void 0){let Re=W??"";(Ne=(ue=d.current).onValueChange)==null||Ne.call(ue,Re);return}}A.emit()}},emit:()=>{c.current.forEach(P=>P())}}),[]),M=p.useMemo(()=>({value:(P,W,ae)=>{var fe;W!==((fe=l.current.get(P))==null?void 0:fe.value)&&(l.current.set(P,{value:W,keywords:ae}),n.current.filtered.items.set(P,U(W,ae)),_(2,()=>{B(),A.emit()}))},item:(P,W)=>(r.current.add(P),W&&(s.current.has(W)?s.current.get(W).add(P):s.current.set(W,new Set([P]))),_(3,()=>{K(),B(),n.current.value||G(),A.emit()}),()=>{l.current.delete(P),r.current.delete(P),n.current.filtered.items.delete(P);let ae=H();_(4,()=>{K(),(ae==null?void 0:ae.getAttribute("id"))===P&&G(),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,W){var ae,fe;let ge=(fe=(ae=d.current)==null?void 0:ae.filter)!=null?fe:GX;return P?ge(P,n.current.search,W):0}function B(){if(!n.current.search||d.current.shouldFilter===!1)return;let P=n.current.filtered.items,W=[];n.current.filtered.groups.forEach(fe=>{let ge=s.current.get(fe),ue=0;ge.forEach(Ne=>{let Re=P.get(Ne);ue=Math.max(Re,ue)}),W.push([fe,ue])});let ae=D.current;$().sort((fe,ge)=>{var ue,Ne;let Re=fe.getAttribute("id"),xe=ge.getAttribute("id");return((ue=P.get(xe))!=null?ue:0)-((Ne=P.get(Re))!=null?Ne:0)}).forEach(fe=>{let ge=fe.closest(qx);ge?ge.appendChild(fe.parentElement===ge?fe:fe.closest(`${qx} > *`)):ae.appendChild(fe.parentElement===ae?fe:fe.closest(`${qx} > *`))}),W.sort((fe,ge)=>ge[1]-fe[1]).forEach(fe=>{var ge;let ue=(ge=D.current)==null?void 0:ge.querySelector(`${Id}[${Bc}="${encodeURIComponent(fe[0])}"]`);ue==null||ue.parentElement.appendChild(ue)})}function G(){let P=$().find(ae=>ae.getAttribute("aria-disabled")!=="true"),W=P==null?void 0:P.getAttribute(Bc);A.setState("value",W||void 0)}function K(){var P,W,ae,fe;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 ue of r.current){let Ne=(W=(P=l.current.get(ue))==null?void 0:P.value)!=null?W:"",Re=(fe=(ae=l.current.get(ue))==null?void 0:ae.keywords)!=null?fe:[],xe=U(Ne,Re);n.current.filtered.items.set(ue,xe),xe>0&&ge++}for(let[ue,Ne]of s.current)for(let Re of Ne)if(n.current.filtered.items.get(Re)>0){n.current.filtered.groups.add(ue);break}n.current.filtered.count=ge}function re(){var P,W,ae;let fe=H();fe&&(((P=fe.parentElement)==null?void 0:P.firstChild)===fe&&((ae=(W=fe.closest(Id))==null?void 0:W.querySelector(BX))==null||ae.scrollIntoView({block:"nearest"})),fe.scrollIntoView({block:"nearest"}))}function H(){var P;return(P=D.current)==null?void 0:P.querySelector(`${bD}[aria-selected="true"]`)}function $(){var P;return Array.from(((P=D.current)==null?void 0:P.querySelectorAll(FT))||[])}function I(P){let W=$()[P];W&&A.setState("value",W.getAttribute(Bc))}function Y(P){var W;let ae=H(),fe=$(),ge=fe.findIndex(Ne=>Ne===ae),ue=fe[ge+P];(W=d.current)!=null&&W.loop&&(ue=ge+P<0?fe[fe.length-1]:ge+P===fe.length?fe[0]:fe[ge+P]),ue&&A.setState("value",ue.getAttribute(Bc))}function Z(P){let W=H(),ae=W==null?void 0:W.closest(Id),fe;for(;ae&&!fe;)ae=P>0?eJ(ae,Id):tJ(ae,Id),fe=ae==null?void 0:ae.querySelector(FT);fe?A.setState("value",fe.getAttribute(Bc)):Y(P)}let ie=()=>I($().length-1),be=P=>{P.preventDefault(),P.metaKey?ie():P.altKey?Z(1):Y(1)},L=P=>{P.preventDefault(),P.metaKey?I(0):P.altKey?Z(-1):Y(-1)};return p.createElement(Ke.div,{ref:t,tabIndex:-1,...R,"cmdk-root":"",onKeyDown:P=>{var W;(W=R.onKeyDown)==null||W.call(R,P);let ae=P.nativeEvent.isComposing||P.keyCode===229;if(!(P.defaultPrevented||ae))switch(P.key){case"n":case"j":{E&&P.ctrlKey&&be(P);break}case"ArrowDown":{be(P);break}case"p":case"k":{E&&P.ctrlKey&&L(P);break}case"ArrowUp":{L(P);break}case"Home":{P.preventDefault(),I(0);break}case"End":{P.preventDefault(),ie();break}case"Enter":{P.preventDefault();let fe=H();if(fe){let ge=new Event(W0);fe.dispatchEvent(ge)}}}}},p.createElement("label",{"cmdk-label":"",htmlFor:M.inputId,id:M.labelId,style:aJ},h),Og(e,P=>p.createElement(CD.Provider,{value:A},p.createElement(SD.Provider,{value:M},P))))}),qX=p.forwardRef((e,t)=>{var n,r;let s=Nn(),l=p.useRef(null),c=p.useContext(wD),d=Kf(),h=RD(e),m=(r=(n=h.current)==null?void 0:n.forceMount)!=null?r:c==null?void 0:c.forceMount;Pl(()=>{if(!m)return d.item(s,c==null?void 0:c.id)},[m]);let g=TD(s,l,[e.value,e.children,l],e.keywords),v=Z1(),x=Ai(_=>_.value&&_.value===g.current),b=Ai(_=>m||d.filter()===!1?!0:_.search?_.filtered.items.get(s)>0:!0);p.useEffect(()=>{let _=l.current;if(!(!_||e.disabled))return _.addEventListener(W0,w),()=>_.removeEventListener(W0,w)},[b,e.onSelect,e.disabled]);function w(){var _,A;C(),(A=(_=h.current).onSelect)==null||A.call(_,g.current)}function C(){v.setState("value",g.current,!0)}if(!b)return null;let{disabled:E,value:R,onSelect:T,forceMount:j,keywords:O,...D}=e;return p.createElement(Ke.div,{ref:No(l,t),...D,id:s,"cmdk-item":"",role:"option","aria-disabled":!!E,"aria-selected":!!x,"data-disabled":!!E,"data-selected":!!x,onPointerMove:E||d.getDisablePointerSelection()?void 0:C,onClick:E?void 0:w},e.children)}),ZX=p.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:s,...l}=e,c=Nn(),d=p.useRef(null),h=p.useRef(null),m=Nn(),g=Kf(),v=Ai(b=>s||g.filter()===!1?!0:b.search?b.filtered.groups.has(c):!0);Pl(()=>g.group(c),[]),TD(c,d,[e.value,e.heading,h]);let x=p.useMemo(()=>({id:c,forceMount:s}),[s]);return p.createElement(Ke.div,{ref:No(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),Og(e,b=>p.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?m:void 0},p.createElement(wD.Provider,{value:x},b))))}),KX=p.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,s=p.useRef(null),l=Ai(c=>!c.search);return!n&&!l?null:p.createElement(Ke.div,{ref:No(s,t),...r,"cmdk-separator":"",role:"separator"})}),YX=p.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,s=e.value!=null,l=Z1(),c=Ai(m=>m.search),d=Ai(m=>m.selectedItemId),h=Kf();return p.useEffect(()=>{e.value!=null&&l.setState("search",e.value)},[e.value]),p.createElement(Ke.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)}})}),WX=p.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...s}=e,l=p.useRef(null),c=p.useRef(null),d=Ai(m=>m.selectedItemId),h=Kf();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(Ke.div,{ref:No(l,t),...s,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":d,"aria-label":r,id:h.listId},Og(e,m=>p.createElement("div",{ref:No(c,h.listInnerRef),"cmdk-list-sizer":""},m)))}),QX=p.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:s,contentClassName:l,container:c,...d}=e;return p.createElement(Yp,{open:n,onOpenChange:r},p.createElement(Wp,{container:c},p.createElement(Qp,{"cmdk-overlay":"",className:s}),p.createElement(Xp,{"aria-label":e.label,"cmdk-dialog":"",className:l},p.createElement(ED,{ref:t,...d}))))}),XX=p.forwardRef((e,t)=>Ai(n=>n.filtered.count===0)?p.createElement(Ke.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),JX=p.forwardRef((e,t)=>{let{progress:n,children:r,label:s="Loading...",...l}=e;return p.createElement(Ke.div,{ref:t,...l,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":s},Og(e,c=>p.createElement("div",{"aria-hidden":!0},c)))}),Mu=Object.assign(ED,{List:WX,Item:qX,Input:YX,Group:ZX,Separator:KX,Dialog:QX,Empty:XX,Loading:JX});function eJ(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function tJ(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function RD(e){let t=p.useRef(e);return Pl(()=>{t.current=e}),t}var Pl=typeof window>"u"?p.useEffect:p.useLayoutEffect;function Gc(e){let t=p.useRef();return t.current===void 0&&(t.current=e()),t}function Ai(e){let t=Z1(),n=()=>e(t.snapshot());return p.useSyncExternalStore(t.subscribe,n,n)}function TD(e,t,n,r=[]){let s=p.useRef(),l=Kf();return Pl(()=>{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(Bc,d),s.current=d}),s}var nJ=()=>{let[e,t]=p.useState(),n=Gc(()=>new Map);return Pl(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,s)=>{n.current.set(r,s),t({})}};function rJ(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function Og({asChild:e,children:t},n){return e&&p.isValidElement(t)?p.cloneElement(rJ(t),{ref:t.ref},n(t.props.children)):n(t)}var aJ={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};function jD({className:e,...t}){return o.jsx(Mu,{"data-slot":"command",className:J("bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",e),...t})}function _D({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(Fl,{className:"size-4 shrink-0 opacity-50"}),o.jsx(Mu.Input,{"data-slot":"command-input",className:J("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 sJ({className:e,...t}){return o.jsx(Mu.List,{"data-slot":"command-list",className:J("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",e),...t})}function ND({...e}){return o.jsx(Mu.Empty,{"data-slot":"command-empty",className:"py-6 text-center text-sm",...e})}function AD({className:e,...t}){return o.jsx(Mu.Group,{"data-slot":"command-group",className:J("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 DD({className:e,...t}){return o.jsx(Mu.Item,{"data-slot":"command-item",className:J("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 Mg="Popover",[OD]=kr(Mg,[Gs]),Yf=Gs(),[oJ,Zi]=OD(Mg),MD=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:s,onOpenChange:l,modal:c=!1}=e,d=Yf(t),h=p.useRef(null),[m,g]=p.useState(!1),[v,x]=zr({prop:r,defaultProp:s??!1,onChange:l,caller:Mg});return o.jsx(Su,{...d,children:o.jsx(oJ,{scope:t,contentId:Nn(),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})})};MD.displayName=Mg;var kD="PopoverAnchor",iJ=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Zi(kD,n),l=Yf(n),{onCustomAnchorAdd:c,onCustomAnchorRemove:d}=s;return p.useEffect(()=>(c(),()=>d()),[c,d]),o.jsx(Cu,{...l,...r,ref:t})});iJ.displayName=kD;var ID="PopoverTrigger",LD=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Zi(ID,n),l=Yf(n),c=vt(t,s.triggerRef),d=o.jsx(Ke.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":VD(s.open),...r,ref:c,onClick:Te(e.onClick,s.onOpenToggle)});return s.hasCustomAnchor?d:o.jsx(Cu,{asChild:!0,...l,children:d})});LD.displayName=ID;var K1="PopoverPortal",[lJ,cJ]=OD(K1,{forceMount:void 0}),PD=e=>{const{__scopePopover:t,forceMount:n,children:r,container:s}=e,l=Zi(K1,t);return o.jsx(lJ,{scope:t,forceMount:n,children:o.jsx(Sr,{present:n||l.open,children:o.jsx(Vl,{asChild:!0,container:s,children:r})})})};PD.displayName=K1;var mu="PopoverContent",UD=p.forwardRef((e,t)=>{const n=cJ(mu,e.__scopePopover),{forceMount:r=n.forceMount,...s}=e,l=Zi(mu,e.__scopePopover);return o.jsx(Sr,{present:r||l.open,children:l.modal?o.jsx(dJ,{...s,ref:t}):o.jsx(fJ,{...s,ref:t})})});UD.displayName=mu;var uJ=Ri("PopoverContent.RemoveScroll"),dJ=p.forwardRef((e,t)=>{const n=Zi(mu,e.__scopePopover),r=p.useRef(null),s=vt(t,r),l=p.useRef(!1);return p.useEffect(()=>{const c=r.current;if(c)return Zp(c)},[]),o.jsx(Ef,{as:uJ,allowPinchZoom:!0,children:o.jsx(FD,{...e,ref:s,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Te(e.onCloseAutoFocus,c=>{var d;c.preventDefault(),l.current||(d=n.triggerRef.current)==null||d.focus()}),onPointerDownOutside:Te(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:Te(e.onFocusOutside,c=>c.preventDefault(),{checkForDefaultPrevented:!1})})})}),fJ=p.forwardRef((e,t)=>{const n=Zi(mu,e.__scopePopover),r=p.useRef(!1),s=p.useRef(!1);return o.jsx(FD,{...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()}})}),FD=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=Zi(mu,n),b=Yf(n);return Gp(),o.jsx(wf,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:l,children:o.jsx(zl,{asChild:!0,disableOutsidePointerEvents:c,onInteractOutside:g,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:m,onDismiss:()=>x.onOpenChange(!1),children:o.jsx(Tf,{"data-state":VD(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)"}})})})}),zD="PopoverClose",hJ=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Zi(zD,n);return o.jsx(Ke.button,{type:"button",...r,ref:t,onClick:Te(e.onClick,()=>s.onOpenChange(!1))})});hJ.displayName=zD;var mJ="PopoverArrow",pJ=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Yf(n);return o.jsx(jf,{...s,...r,ref:t})});pJ.displayName=mJ;function VD(e){return e?"open":"closed"}var gJ=MD,vJ=LD,yJ=PD,xJ=UD;function Y1({...e}){return o.jsx(gJ,{"data-slot":"popover",...e})}function W1({...e}){return o.jsx(vJ,{"data-slot":"popover-trigger",...e})}function Q1({className:e,align:t="center",sideOffset:n=4,...r}){return o.jsx(yJ,{children:o.jsx(xJ,{"data-slot":"popover-content",align:t,sideOffset:n,className:J("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 X1({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 w={};return e.forEach(C=>{const E=C.group??"";Object.prototype.hasOwnProperty.call(w,E)||(w[E]=[]),w[E].push(C)}),w},[e]),x=e.find(w=>w.value===t),b=p.useCallback(w=>{n(w),requestAnimationFrame(()=>{g(""),h(!1)})},[n]);return o.jsxs(Y1,{open:d,onOpenChange:h,modal:!0,children:[o.jsx(W1,{asChild:!0,children:o.jsxs(Ce,{variant:"outline",role:"combobox","aria-expanded":d,className:J("w-full justify-between",!t&&"text-muted-foreground",l),disabled:c,children:[x?x.label:r,o.jsx(Sb,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),o.jsx(Q1,{className:"max-h-[300px] min-w-[300px] overflow-auto p-0",align:"start",sideOffset:5,children:o.jsxs(jD,{children:[o.jsx(_D,{placeholder:`Search ${r.toLowerCase()}...`,value:m,onValueChange:g}),o.jsx(ND,{children:s}),Object.entries(v).map(([w,C])=>o.jsx(AD,{heading:w,children:C.map(E=>o.jsxs(DD,{value:E.value,onSelect:()=>{b(E.value)},keywords:[E.label],children:[o.jsx(dr,{className:J("mr-2 h-4 w-4",t===E.value?"opacity-100":"opacity-0")}),E.label]},E.value))},w||"default"))]})})]})}var kg="Collapsible",[bJ,HD]=kr(kg),[SJ,J1]=bJ(kg),$D=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:s,disabled:l,onOpenChange:c,...d}=e,[h,m]=zr({prop:r,defaultProp:s??!1,onChange:c,caller:kg});return o.jsx(SJ,{scope:n,disabled:l,contentId:Nn(),open:h,onOpenToggle:p.useCallback(()=>m(g=>!g),[m]),children:o.jsx(Ke.div,{"data-state":rS(h),"data-disabled":l?"":void 0,...d,ref:t})})});$D.displayName=kg;var BD="CollapsibleTrigger",eS=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,s=J1(BD,n);return o.jsx(Ke.button,{type:"button","aria-controls":s.contentId,"aria-expanded":s.open||!1,"data-state":rS(s.open),"data-disabled":s.disabled?"":void 0,disabled:s.disabled,...r,ref:t,onClick:Te(e.onClick,s.onOpenToggle)})});eS.displayName=BD;var tS="CollapsibleContent",nS=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,s=J1(tS,e.__scopeCollapsible);return o.jsx(Sr,{present:n||s.open,children:({present:l})=>o.jsx(CJ,{...r,ref:t,present:l})})});nS.displayName=tS;var CJ=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:s,...l}=e,c=J1(tS,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),w=b.current,C=c.open||d,E=p.useRef(C),R=p.useRef(void 0);return p.useEffect(()=>{const T=requestAnimationFrame(()=>E.current=!1);return()=>cancelAnimationFrame(T)},[]),br(()=>{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,E.current||(T.style.transitionDuration=R.current.transitionDuration,T.style.animationName=R.current.animationName),h(r)}},[c.open,r]),o.jsx(Ke.div,{"data-state":rS(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":w?`${w}px`:void 0,...e.style},children:C&&s})});function rS(e){return e?"open":"closed"}var GD=$D,wJ=eS,EJ=nS,xs="Accordion",RJ=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[aS,TJ,jJ]=og(xs),[Ig]=kr(xs,[jJ,HD]),sS=HD(),qD=je.forwardRef((e,t)=>{const{type:n,...r}=e,s=r,l=r;return o.jsx(aS.Provider,{scope:e.__scopeAccordion,children:n==="multiple"?o.jsx(DJ,{...l,ref:t}):o.jsx(AJ,{...s,ref:t})})});qD.displayName=xs;var[ZD,_J]=Ig(xs),[KD,NJ]=Ig(xs,{collapsible:!1}),AJ=je.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},collapsible:l=!1,...c}=e,[d,h]=zr({prop:n,defaultProp:r??"",onChange:s,caller:xs});return o.jsx(ZD,{scope:e.__scopeAccordion,value:je.useMemo(()=>d?[d]:[],[d]),onItemOpen:h,onItemClose:je.useCallback(()=>l&&h(""),[l,h]),children:o.jsx(KD,{scope:e.__scopeAccordion,collapsible:l,children:o.jsx(YD,{...c,ref:t})})})}),DJ=je.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},...l}=e,[c,d]=zr({prop:n,defaultProp:r??[],onChange:s,caller:xs}),h=je.useCallback(g=>d((v=[])=>[...v,g]),[d]),m=je.useCallback(g=>d((v=[])=>v.filter(x=>x!==g)),[d]);return o.jsx(ZD,{scope:e.__scopeAccordion,value:c,onItemOpen:h,onItemClose:m,children:o.jsx(KD,{scope:e.__scopeAccordion,collapsible:!0,children:o.jsx(YD,{...l,ref:t})})})}),[OJ,Lg]=Ig(xs),YD=je.forwardRef((e,t)=>{const{__scopeAccordion:n,disabled:r,dir:s,orientation:l="vertical",...c}=e,d=je.useRef(null),h=vt(d,t),m=TJ(n),v=Af(s)==="ltr",x=Te(e.onKeyDown,b=>{var M;if(!RJ.includes(b.key))return;const w=b.target,C=m().filter(U=>{var B;return!((B=U.ref.current)!=null&&B.disabled)}),E=C.findIndex(U=>U.ref.current===w),R=C.length;if(E===-1)return;b.preventDefault();let T=E;const j=0,O=R-1,D=()=>{T=E+1,T>O&&(T=j)},_=()=>{T=E-1,T<j&&(T=O)};switch(b.key){case"Home":T=j;break;case"End":T=O;break;case"ArrowRight":l==="horizontal"&&(v?D():_());break;case"ArrowDown":l==="vertical"&&D();break;case"ArrowLeft":l==="horizontal"&&(v?_():D());break;case"ArrowUp":l==="vertical"&&_();break}const A=T%R;(M=C[A].ref.current)==null||M.focus()});return o.jsx(OJ,{scope:n,disabled:r,direction:s,orientation:l,children:o.jsx(aS.Slot,{scope:n,children:o.jsx(Ke.div,{...c,"data-orientation":l,ref:h,onKeyDown:r?void 0:x})})})}),Op="AccordionItem",[MJ,oS]=Ig(Op),WD=je.forwardRef((e,t)=>{const{__scopeAccordion:n,value:r,...s}=e,l=Lg(Op,n),c=_J(Op,n),d=sS(n),h=Nn(),m=r&&c.value.includes(r)||!1,g=l.disabled||e.disabled;return o.jsx(MJ,{scope:n,open:m,disabled:g,triggerId:h,children:o.jsx(GD,{"data-orientation":l.orientation,"data-state":nO(m),...d,...s,ref:t,disabled:g,open:m,onOpenChange:v=>{v?c.onItemOpen(r):c.onItemClose(r)}})})});WD.displayName=Op;var QD="AccordionHeader",XD=je.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Lg(xs,n),l=oS(QD,n);return o.jsx(Ke.h3,{"data-orientation":s.orientation,"data-state":nO(l.open),"data-disabled":l.disabled?"":void 0,...r,ref:t})});XD.displayName=QD;var Q0="AccordionTrigger",JD=je.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Lg(xs,n),l=oS(Q0,n),c=NJ(Q0,n),d=sS(n);return o.jsx(aS.ItemSlot,{scope:n,children:o.jsx(wJ,{"aria-disabled":l.open&&!c.collapsible||void 0,"data-orientation":s.orientation,id:l.triggerId,...d,...r,ref:t})})});JD.displayName=Q0;var eO="AccordionContent",tO=je.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Lg(xs,n),l=oS(eO,n),c=sS(n);return o.jsx(EJ,{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}})});tO.displayName=eO;function nO(e){return e?"open":"closed"}var kJ=qD,IJ=WD,LJ=XD,PJ=JD,UJ=tO;const iS={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(W9,{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}},rO=p.createContext("default");function hr({variant:e="default",...t}){return o.jsx(rO.Provider,{value:e,children:o.jsx(kJ,{"data-slot":"accordion",...t})})}function lS(e){const t=p.useContext(rO);return e??t??"default"}function Kn({className:e,variant:t,...n}){const r=lS(t),{itemClass:s}=iS[r];return o.jsx(IJ,{"data-slot":"accordion-item",className:J(s,e),...n})}function Yn({className:e,children:t,variant:n,...r}){const s=lS(n),{triggerClass:l,icon:c,chevronClass:d,headerClass:h}=iS[s];return o.jsx(LJ,{className:h,children:o.jsxs(PJ,{"data-slot":"accordion-trigger",className:J(l,e),...r,children:[c,t,o.jsx(Za,{className:d,"aria-hidden":"true"})]})})}function Wn({className:e,children:t,variant:n,...r}){const s=lS(n),{contentClass:l,contentInnerClass:c}=iS[s];return o.jsx(UJ,{"data-slot":"accordion-content",className:J(l,e),...r,children:o.jsx("div",{className:c,children:t})})}function fr({href:e,children:t,className:n,...r}){return o.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:J("text-muted-foreground hover:bg-muted inline-flex items-center px-1 font-medium hover:rounded-md",n),...r,children:[t,o.jsx(Tl,{className:"ml-1 inline h-3 w-3","aria-hidden":"true"})]})}function FJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"service-account-details",children:[o.jsx(Yn,{children:"How do I get a Service Account JSON key?"}),o.jsxs(Wn,{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(fr,{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 zJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"project-id-details",children:[o.jsx(Yn,{children:"How do I find my Project ID?"}),o.jsxs(Wn,{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(fr,{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 VJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"gbq-location-details",children:[o.jsx(Yn,{children:"How do I find my dataset location?"}),o.jsxs(Wn,{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(fr,{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 aO=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}},HJ=({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?aO(l):null;return o.jsxs(o.Fragment,{children:[o.jsxs(Vs,{title:"Connection Settings",children:[o.jsx(Qt,{control:e.control,name:"config.projectId",render:({field:d})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Enter the ID of your Google Cloud project where BigQuery usage will be billed",children:"Project ID"}),o.jsx(en,{children:o.jsx($t,{...d,placeholder:"Enter a Project Id"})}),o.jsx(ar,{children:o.jsx(zJ,{})}),o.jsx(ln,{})]})}),o.jsx(Qt,{control:e.control,name:"config.location",render:({field:d})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Choose the same region where your BigQuery data is stored to ensure queries work correctly",children:"Location"}),o.jsx(en,{children:o.jsx(X1,{options:aq,value:d.value,onValueChange:d.onChange,placeholder:"Select a location",emptyMessage:"No locations found",className:"w-full"})}),o.jsx(ar,{children:o.jsx(VJ,{})}),o.jsx(ln,{})]})})]}),o.jsx(Vs,{title:"Authentication",children:o.jsx(Qt,{control:e.control,name:"credentials.serviceAccount",render:({field:d})=>o.jsxs(Xt,{children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(Jt,{tooltip:"Paste a JSON key from a service account that has access to the selected storage provider",children:"Service Account"}),!t&&l&&o.jsx(Ce,{variant:"ghost",size:"sm",onClick:r,type:"button",children:"Edit"}),t&&o.jsx(Ce,{variant:"ghost",size:"sm",onClick:s,type:"button",children:"Cancel"})]}),o.jsx(en,{children:!t&&c?o.jsxs(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsx(fr,{href:c.url,children:c.email})}),o.jsx(_t,{children:o.jsx("p",{children:"View in Google Cloud Console"})})]}):o.jsx(Fi,{...d,className:"min-h-[150px] font-mono",rows:8,placeholder:"Paste your service account JSON here"})}),o.jsx(ar,{children:o.jsx(FJ,{})}),o.jsx(ln,{})]})})})]})};function $J(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"athena-region-details",children:[o.jsx(Yn,{children:"How do I find my Athena region?"}),o.jsxs(Wn,{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(fr,{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 BJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"athena-output-bucket-details",children:[o.jsx(Yn,{children:"How do I find a bucket?"}),o.jsxs(Wn,{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(fr,{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 GJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"athena-access-key-id-details",children:[o.jsx(Yn,{children:"How do I get my AWS Access Key ID?"}),o.jsxs(Wn,{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(fr,{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(d_,{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(fr,{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 qJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"athena-secret-access-key-details",children:[o.jsx(Yn,{children:"How do I get my AWS Secret Access Key?"}),o.jsxs(Wn,{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(fr,{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 ZJ=({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(Vs,{title:"Connection Settings",children:[o.jsx(Qt,{control:e.control,name:"config.region",render:({field:r})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Enter the AWS region where your Athena service is active",children:"Region"}),o.jsx(en,{children:o.jsx($t,{...r,placeholder:"Enter a region"})}),o.jsx(ar,{children:o.jsx($J,{})}),o.jsx(ln,{})]})}),o.jsx(Qt,{control:e.control,name:"config.outputBucket",render:({field:r})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Specify the S3 bucket where Athena query results will be stored",children:"Output Bucket"}),o.jsx(en,{children:o.jsx($t,{...r,placeholder:"Enter an output bucket"})}),o.jsx(ar,{children:o.jsx(BJ,{})}),o.jsx(ln,{})]})})]}),o.jsxs(Vs,{title:"Authentication",children:[o.jsx(Qt,{control:e.control,name:"credentials.accessKeyId",render:({field:r})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Your AWS Access Key ID used for authentication",children:"Access Key ID"}),o.jsx(en,{children:o.jsx($t,{...r,placeholder:"Enter an access key id"})}),o.jsx(ar,{children:o.jsx(GJ,{})}),o.jsx(ln,{})]})}),o.jsx(Qt,{control:e.control,name:"credentials.secretAccessKey",render:({field:r})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Your AWS Secret Access Key used for authentication",children:"Secret Access Key"}),o.jsx(en,{children:o.jsx($t,{...r,type:"password",placeholder:t||"Enter a secret access key"})}),o.jsx(ar,{children:o.jsx(qJ,{})}),o.jsx(ln,{})]})})]})]})};function KJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"bigquery-api-details",children:[o.jsx(Yn,{children:"How do I enable the BigQuery API?"}),o.jsxs(Wn,{children:[o.jsxs("p",{className:"mb-2",children:["To run queries and process data in Google BigQuery, you need to enable the"," ",o.jsx(fr,{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 YJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"athena-api-details",children:[o.jsx(Yn,{children:"How do I activate Athena API?"}),o.jsxs(Wn,{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(fr,{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 sO(e){return JSON.parse(JSON.stringify(e))}function WJ({initialData:e,onSubmit:t,onCancel:n,onDirtyChange:r}){const s=$i({resolver:Wl(wq),defaultValues:e}),{watch:l,control:c,formState:{isDirty:d,isSubmitting:h}}=s,m=l("type");je.useEffect(()=>{r==null||r(d)},[d,r]);const g=async v=>{const{dirtyFields:x}=s.formState,b=sO(v);return x.credentials||delete b.credentials,t(b)};return o.jsx(Zl,{...s,children:o.jsxs(Bi,{onSubmit:v=>{s.handleSubmit(g)(v)},noValidate:!0,children:[o.jsxs(Kl,{children:[o.jsxs(Vs,{title:"General",children:[o.jsx(Qt,{control:c,name:"title",render:({field:v})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Name the storage to clarify its purpose",children:"Title"}),o.jsx(en,{children:o.jsx($t,{...v,placeholder:"Storage title"})}),o.jsx(ln,{})]})}),o.jsx(Qt,{control:c,name:"type",render:({field:v})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"The selected source will be used to process data in your Data Marts",children:"Storage Type"}),o.jsx(en,{children:o.jsxs(Sa,{value:v.value,onValueChange:v.onChange,disabled:!!e,children:[o.jsx(wa,{className:"w-full",children:o.jsx(Ca,{placeholder:"Select a storage type"})}),o.jsx(Ea,{children:o.jsx(Ng,{children:Vi.getAllTypes().map(({type:x,displayName:b,icon:w,status:C})=>o.jsx(qn,{value:x,disabled:C===bo.COMING_SOON,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(w,{size:20}),b]})},x))})})]})}),o.jsxs(ar,{children:[m===Pe.GOOGLE_BIGQUERY&&o.jsx(KJ,{}),m===Pe.AWS_ATHENA&&o.jsx(YJ,{})]}),o.jsx(ln,{})]})})]}),m===Pe.GOOGLE_BIGQUERY&&o.jsx(HJ,{form:s}),m===Pe.AWS_ATHENA&&o.jsx(ZJ,{form:s})]}),o.jsxs(Yl,{children:[o.jsx(Ce,{variant:"default",type:"submit",className:"w-full","aria-label":"Save",disabled:!d||h,children:"Save"}),o.jsx(Ce,{variant:"outline",type:"button",onClick:n,className:"w-full","aria-label":"Cancel",children:"Cancel"})]})]})})}function oO({isOpen:e,onClose:t,dataStorage:n,onSaveSuccess:r}){const{updateDataStorage:s}=Ag(),[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(w=>{h(w)},[]),x=async w=>{if(n){const C=await s(n.id,w);C&&(r(C),t())}},b=p.useRef(!1);return p.useEffect(()=>{const w=n?"Edit":"Create";e&&!b.current?(Fe({event:"data_storage_config_open",category:"DataStorage",action:w,label:n==null?void 0:n.type}),b.current=!0):!e&&b.current&&(Fe({event:"data_storage_config_close",category:"DataStorage",action:w,label:n==null?void 0:n.type}),b.current=!1)},[e,n]),o.jsxs(o.Fragment,{children:[o.jsx(Mi,{open:e,onOpenChange:w=>{w||m()},children:o.jsxs(ki,{children:[o.jsxs(Ii,{children:[o.jsx(Li,{children:"Configure Storage Provider"}),o.jsx(Hl,{children:"Customize settings for your storage provider"})]}),o.jsx(WJ,{initialData:n??void 0,onSubmit:x,onCancel:m,onDirtyChange:v})]})}),o.jsx(xa,{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 QJ=({dataStorage:e,onDataStorageChange:t})=>{const[n,r]=p.useState(!1),s=Vi.getInfo(e.type),l=()=>{r(!0)},c=()=>{r(!1)},d=()=>{if(!p4(e))return o.jsxs("div",{className:"flex items-center space-x-2 text-sm",children:[o.jsx(Bp,{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(fr,{href:b,onClick:w=>{w.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(G1,{children:o.jsx(oO,{isOpen:n,onClose:c,dataStorage:e,onSaveSuccess:h=>{t&&t(h)}})})]})};function XJ({initialType:e,onTypeSelect:t}){var c;const[n,r]=p.useState(e??null);p.useEffect(()=>{e!==void 0&&e!==n&&r(e)},[e,n]);const 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(ba,{className:"text-foreground",children:"Definition Type"}),o.jsxs(Sa,{value:n??"",onValueChange:d=>{s(d)},children:[o.jsx(wa,{className:"dm-card-formcontrol w-full","aria-label":"Definition Type",children:o.jsx(Ca,{placeholder:"Select definition type",children:n&&((c=l.find(d=>d.type===n))==null?void 0:c.label)})}),o.jsx(Ea,{children:o.jsx(Ng,{children:l.map(d=>o.jsxs(qn,{value:d.type,children:[d.label,o.jsx("span",{className:"text-muted-foreground/80 ml-2",children:d.description})]},d.type))})})]})]})}const JJ=sn({definitionType:qs(qe.SQL),definition:sn({sqlQuery:on().min(1,"SQL query is required")})}),eee=e=>{const t=I4(e);return sn({definitionType:qs(qe.TABLE),definition:t})},tee=e=>{const t=I4(e);return sn({definitionType:qs(qe.VIEW),definition:t})},nee=e=>{const t=LZ(e);return sn({definitionType:qs(qe.TABLE_PATTERN),definition:t})},ree=sn({definitionType:qs(qe.CONNECTOR),definition:sn({connector:sn({source:sn({name:on().min(1,"Connector name is required"),configuration:tT(vB(pB())).min(1,"At least one configuration is required"),node:on().min(1,"Node is required"),fields:tT(on()).min(1,"At least one field is required")}),storage:sn({fullyQualifiedName:on().min(1,"fully qualified name is required")})})})}),aee=(e,t)=>{if(!e)return sn({definitionType:yB(c1(qe)),definition:sn({}).optional()});switch(e){case qe.SQL:return JJ;case qe.TABLE:return eee(t);case qe.VIEW:return tee(t);case qe.TABLE_PATTERN:return nee(t);case qe.CONNECTOR:return ree;default:return sn({})}};function see({control:e}){return o.jsx(Qt,{control:e,name:"definition.sqlQuery",render:({field:t})=>o.jsxs(Xt,{className:"dm-card-block",children:[o.jsx(Jt,{className:"text-foreground",children:"SQL Query"}),o.jsx(en,{children:o.jsx(kX,{initialValue:{sqlQuery:t.value},onChange:n=>{t.onChange(n.sqlQuery)}})}),o.jsx(ln,{})]})})}function oee({control:e,storageType:t}){const n=v4(t),r=y4(t);return o.jsx(Qt,{control:e,name:"definition.fullyQualifiedName",render:({field:s})=>o.jsxs(Xt,{className:"dm-card-block",children:[o.jsx(Jt,{children:"Fully Qualified Table Name"}),o.jsx(en,{children:o.jsx($t,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(ar,{className:"text-muted-foreground/75",children:r}),o.jsx(ln,{})]})})}function iee({control:e,storageType:t}){const n=v4(t),r=y4(t);return o.jsx(Qt,{control:e,name:"definition.fullyQualifiedName",render:({field:s})=>o.jsxs(Xt,{className:"dm-card-block",children:[o.jsx(Jt,{children:"Fully Qualified View Name"}),o.jsx(en,{children:o.jsx($t,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(ar,{className:"text-muted-foreground/75",children:r}),o.jsx(ln,{})]})})}function lee({control:e,storageType:t}){const n=_q(t),r=Nq(t);return o.jsx(Qt,{control:e,name:"definition.pattern",render:({field:s})=>o.jsxs(Xt,{className:"dm-card-block",children:[o.jsx(Jt,{children:"Table Pattern"}),o.jsx(en,{children:o.jsx($t,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(ar,{className:"text-muted-foreground/75",children:r}),o.jsx(ln,{})]})})}const X0=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{}}},cee=bf("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 cS({className:e,variant:t,...n}){return o.jsx("div",{"data-slot":"alert",role:"alert",className:J(cee({variant:t}),e),...n})}function iO({className:e,...t}){return o.jsx("div",{"data-slot":"alert-title",className:J("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",e),...t})}function uS({className:e,...t}){return o.jsx("div",{"data-slot":"alert-description",className:J("text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",e),...t})}var Pg="Tabs",[uee]=kr(Pg,[ig]),lO=ig(),[dee,dS]=uee(Pg),cO=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,onValueChange:s,defaultValue:l,orientation:c="horizontal",dir:d,activationMode:h="automatic",...m}=e,g=Af(d),[v,x]=zr({prop:r,onChange:s,defaultProp:l??"",caller:Pg});return o.jsx(dee,{scope:n,baseId:Nn(),value:v,onValueChange:x,orientation:c,dir:g,activationMode:h,children:o.jsx(Ke.div,{dir:g,"data-orientation":c,...m,ref:t})})});cO.displayName=Pg;var uO="TabsList",dO=p.forwardRef((e,t)=>{const{__scopeTabs:n,loop:r=!0,...s}=e,l=dS(uO,n),c=lO(n);return o.jsx(EN,{asChild:!0,...c,orientation:l.orientation,dir:l.dir,loop:r,children:o.jsx(Ke.div,{role:"tablist","aria-orientation":l.orientation,...s,ref:t})})});dO.displayName=uO;var fO="TabsTrigger",hO=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,disabled:s=!1,...l}=e,c=dS(fO,n),d=lO(n),h=gO(c.baseId,r),m=vO(c.baseId,r),g=r===c.value;return o.jsx(RN,{asChild:!0,...d,focusable:!s,active:g,children:o.jsx(Ke.button,{type:"button",role:"tab","aria-selected":g,"aria-controls":m,"data-state":g?"active":"inactive","data-disabled":s?"":void 0,disabled:s,id:h,...l,ref:t,onMouseDown:Te(e.onMouseDown,v=>{!s&&v.button===0&&v.ctrlKey===!1?c.onValueChange(r):v.preventDefault()}),onKeyDown:Te(e.onKeyDown,v=>{[" ","Enter"].includes(v.key)&&c.onValueChange(r)}),onFocus:Te(e.onFocus,()=>{const v=c.activationMode!=="manual";!g&&!s&&v&&c.onValueChange(r)})})})});hO.displayName=fO;var mO="TabsContent",pO=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,forceMount:s,children:l,...c}=e,d=dS(mO,n),h=gO(d.baseId,r),m=vO(d.baseId,r),g=r===d.value,v=p.useRef(g);return p.useEffect(()=>{const x=requestAnimationFrame(()=>v.current=!1);return()=>cancelAnimationFrame(x)},[]),o.jsx(Sr,{present:s||g,children:({present:x})=>o.jsx(Ke.div,{"data-state":g?"active":"inactive","data-orientation":d.orientation,role:"tabpanel","aria-labelledby":h,hidden:!x,id:m,tabIndex:0,...c,ref:t,style:{...e.style,animationDuration:v.current?"0s":void 0},children:x&&l})})});pO.displayName=mO;function gO(e,t){return`${e}-trigger-${t}`}function vO(e,t){return`${e}-content-${t}`}var fee=cO,hee=dO,mee=hO,pee=pO;function gee({className:e,...t}){return o.jsx(fee,{"data-slot":"tabs",className:J("flex flex-col gap-2",e),...t})}function vee({className:e,...t}){return o.jsx(hee,{"data-slot":"tabs-list",className:J("bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",e),...t})}function yee({className:e,...t}){return o.jsx(mee,{"data-slot":"tabs-trigger",className:J("data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),...t})}function xee({className:e,...t}){return o.jsx(pee,{"data-slot":"tabs-content",className:J("flex-1 outline-none",e),...t})}const bee=GD,See=eS,Cee=nS;function wee({children:e,className:t="",...n}){return o.jsx("div",{className:J("flex flex-1 flex-col overflow-hidden",t),...n,children:e})}function Eee({children:e,className:t="",...n}){return o.jsx("div",{className:J("bg-muted dark:bg-sidebar flex-1 overflow-y-auto p-4",t),...n,children:o.jsx("div",{className:"flex min-h-full flex-col gap-4",children:e})})}function Ree({children:e,className:t="",variant:n="horizontal",...r}){const s=n==="vertical"?"flex flex-col gap-1.5 pt-4":"flex items-center justify-between border-t px-4 py-3";return o.jsx("div",{className:J(s,t),...r,children:e})}function $d({children:e,className:t="",...n}){return o.jsx("div",{"data-slot":"wizard-step-item",className:J("group border-border flex flex-col gap-2 rounded-md border-b bg-white px-4 py-3 transition-shadow duration-200 hover:shadow-sm dark:border-transparent dark:bg-white/4",t),...n,children:e})}function Tee({label:e,children:t,className:n="",options:r,value:s,onValueChange:l,required:c=!1,tooltip:d,...h}){return o.jsx("div",{"data-slot":"wizard-step-item-one-of",className:J("group border-border flex flex-col gap-2 rounded-md border-b bg-white px-4 py-3 transition-shadow duration-200 hover:shadow-sm dark:border-transparent dark:bg-white/4",n),...h,children:o.jsxs(gee,{value:s,onValueChange:l,children:[o.jsxs("div",{className:"flex items-center",children:[o.jsx(wo,{required:c,tooltip:d,className:"w-full",children:e}),o.jsx(vee,{children:r.map(m=>o.jsx(yee,{value:m.value,children:m.label},m.value))})]}),t]})})}function jee({title:e,children:t,defaultOpen:n=!1,className:r=""}){const[s,l]=p.useState(n);return o.jsxs(bee,{open:s,onOpenChange:l,"data-slot":"wizard-collapsible",className:J("group flex flex-col gap-2 py-3",r),children:[o.jsx(See,{asChild:!0,children:o.jsxs("button",{type:"button",className:J("flex cursor-pointer items-center gap-1"),children:[o.jsx("span",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:e}),o.jsx(Ra,{className:J("text-foreground/75 h-3.5 w-3.5 transition-transform duration-200",s&&"rotate-90")})]})}),o.jsx(Cee,{className:"data-[state=open]:animate-collapsible-down data-[state=closed]:animate-collapsible-up overflow-hidden",children:o.jsx("div",{className:"flex flex-col gap-2 pt-2",children:t})})]})}function wo({children:e,required:t=!1,tooltip:n,tooltipProps:r,className:s="",...l}){return o.jsxs(ba,{"data-slot":"wizard-step-label",className:J("text-foreground flex items-center justify-between gap-2 text-sm font-medium",s),...l,children:[t?o.jsxs(Tt,{...r,children:[o.jsx(jt,{asChild:!0,children:o.jsxs("span",{className:"flex items-center gap-1",children:[e,o.jsx("span",{className:"ml-1 text-red-500",children:"*"})]})}),o.jsx(_t,{side:"top",align:"center",role:"tooltip",children:"Required"})]}):o.jsx("span",{children:e}),n&&o.jsxs(Tt,{...r,children:[o.jsx(jt,{asChild:!0,children:o.jsx("button",{type:"button",tabIndex:-1,className:"pointer-events-none opacity-0 transition group-hover:pointer-events-auto group-hover:opacity-100","aria-label":"Help information",children:o.jsx(Fr,{className:"text-muted-foreground/50 hover:text-muted-foreground size-4 shrink-0 transition-colors","aria-hidden":"true"})})}),o.jsx(_t,{side:"top",align:"center",role:"tooltip",children:n})]})]})}function wl({title:e,children:t,className:n="",...r}){return o.jsxs("section",{"data-slot":"wizard-step-section",className:J("mb-8",n),...r,children:[e&&o.jsx("h3",{className:"text-muted-foreground/75 mb-2 text-xs font-semibold tracking-wide uppercase",children:e}),o.jsx("div",{className:"flex flex-col gap-2",children:t})]})}function Di({icon:e,title:t,subtitle:n,docUrl:r,variant:s="default",className:l,...c}){return s==="compact"?o.jsxs("div",{"data-slot":"wizard-step-hero",className:J("border-border mb-6 flex items-center justify-between gap-4 border-b pb-4",l),...c,children:[o.jsxs("div",{className:"flex items-center gap-2",children:[e&&o.jsx("div",{children:e}),o.jsx("h2",{className:"text-md font-medium",children:t})]}),r!=null&&o.jsx(Ce,{variant:"outline",asChild:!0,children:o.jsxs(Ba,{to:r,target:"_blank",rel:"noopener noreferrer",children:["Documentation",o.jsx(Tl,{className:"h-4 w-4"})]})})]}):o.jsxs("div",{"data-slot":"wizard-step-hero",className:J("mb-6 flex flex-col items-center justify-center text-center",l),...c,children:[e&&o.jsx("div",{className:"mt-6 mb-3",children:e}),o.jsx("h2",{className:"text-xl font-medium",children:t}),n&&o.jsx("p",{className:"text-muted-foreground mt-2 text-sm",children:n}),r!=null&&o.jsx(Ce,{variant:"outline",className:"mt-3 mb-6",asChild:!0,children:o.jsxs(Ba,{to:r,target:"_blank",rel:"noopener noreferrer",children:["Documentation",o.jsx(Tl,{className:"h-4 w-4"})]})})]})}function Ro({children:e,className:t="",...n}){return o.jsx("div",{"data-slot":"wizard-step",className:J("space-y-4",t),...n,children:e})}function _ee({children:e,className:t="",...n}){return o.jsx("div",{className:J("grid grid-cols-1 gap-4 md:grid-cols-2",t),...n,children:e})}function Nee({icon:e,title:t,selected:n=!1,disabled:r=!1,onClick:s,onDoubleClick:l,className:c="",...d}){return o.jsxs("div",{className:J("border-border flex items-center gap-4 rounded-md border-b bg-white px-4 py-3 transition-shadow duration-200 select-none hover:shadow-sm dark:border-transparent dark:bg-white/4",r?"cursor-not-allowed opacity-50 hover:shadow-none":"cursor-pointer hover:shadow-sm dark:hover:bg-white/8",n&&!r?"ring-primary border-transparent ring-2 dark:bg-white/8":"",c),onClick:s,onDoubleClick:l,...d,children:[e&&o.jsx("span",{className:"shrink-0",children:e}),r?o.jsxs(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsx("span",{className:"cursor-not-allowed text-sm font-medium opacity-70",children:t})}),o.jsx(_t,{side:"top",align:"center",children:"Coming soon"})]}):o.jsx("span",{className:"text-sm font-medium",children:t})]})}function yO({type:e,id:t,name:n,value:r,label:s,checked:l,selected:c=!1,disabled:d=!1,tooltip:h,rightIcon:m,onChange:g,className:v="",...x}){const b=C=>{g&&g(e==="checkbox"?C.target.checked:C.target.value)},w=p.useRef(null);return o.jsxs("div",{"data-slot":"wizard-step-card-item",onClick:C=>{if(d)return;const E=C.target;E.tagName==="INPUT"||E.tagName==="LABEL"||E.closest("label")||w.current&&w.current.click()},className:J("group border-border flex items-center gap-2 rounded-md border-b bg-white px-4 py-3 transition-shadow duration-200 select-none hover:shadow-sm dark:border-transparent dark:bg-white/4",d?"cursor-not-allowed":"cursor-pointer hover:shadow-sm dark:hover:bg-white/8",c?"ring-primary border-transparent ring-2 dark:bg-white/8":"",v),children:[o.jsx("input",{ref:w,id:t,type:e,name:n,value:r,checked:l,disabled:d,onChange:b,className:J("text-primary focus:ring-primary border-border cursor-pointer",e==="radio"||e==="checkbox"?"h-4 w-4":"h-8 w-full rounded-md border px-2"),...x}),s&&o.jsx(wo,{htmlFor:t,className:J("cursor-pointer",d&&"cursor-not-allowed"),children:s}),(h||m)&&o.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[h&&o.jsxs(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsx(Fr,{className:"text-muted-foreground/75 pointer-events-none h-4 w-4 opacity-0 group-hover:pointer-events-auto group-hover:opacity-100","data-tooltip-trigger":!0})}),o.jsx(_t,{side:"top",align:"center",children:h})]}),m&&o.jsx("div",{className:"flex items-center",children:m})]})]})}function fS({variant:e="grid",items:t,className:n=""}){const r=t??(e==="grid"?12:6),s=e==="grid"?"grid grid-cols-1 gap-4 md:grid-cols-2":"flex flex-col gap-4";return o.jsx("div",{"data-slot":"wizard-step-loading",className:J(s,n),children:Array.from({length:r}).map((l,c)=>o.jsx(as,{className:"border-border h-12 rounded-md border-b bg-white dark:bg-white/4"},c))})}function Aee({connectors:e,selectedConnector:t,loading:n,error:r,onConnectorSelect:s,onConnectorDoubleClick:l}){return n?o.jsx(fS,{variant:"grid"}):r?o.jsxs(cS,{variant:"destructive",children:[o.jsx(Sf,{className:"h-4 w-4"}),o.jsx(uS,{children:"Failed to load available connectors. Please try again."})]}):o.jsxs(Ro,{children:[o.jsx(wl,{title:"Choose Connector",children:o.jsx(_ee,{children:e.map(c=>o.jsx(Nee,{icon:c.logoBase64?o.jsx(Ff,{base64:c.logoBase64,size:20}):null,title:c.displayName,selected:(t==null?void 0:t.name)===c.name,onClick:()=>{s(c)},onDoubleClick:()=>{s(c),l==null||l(c)}},c.name))})}),e.length===0&&o.jsx(Di,{icon:o.jsx(nf,{size:56,strokeWidth:1}),title:"No connectors available",subtitle:"Ask your administrator to configure connectors."})]})}function Dee({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(o.Fragment,{children:[o.jsx("div",{className:"flex-1",children:r&&o.jsxs(Ce,{variant:"outline",onClick:c,disabled:s,children:[o.jsx(JI,{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(Ce,{variant:"default",onClick:d,disabled:!n||s,children:g}):o.jsxs(Ce,{variant:"default",onClick:l,disabled:!n||s,children:[h,o.jsx(Ra,{className:"h-4 w-4"})]})})]})}function El({connector:e,size:t=24,variant:n="compact"}){return o.jsx(Di,{icon:o.jsx(Ff,{base64:e.logoBase64,size:t}),title:e.displayName,docUrl:e.docUrl,variant:n})}function nu({label:e}){return o.jsx("div",{className:"border-border text-muted-foreground mt-3 flex items-center justify-center gap-2 border-t pt-3 text-sm",children:o.jsx(Ce,{variant:"outline",asChild:!0,children:o.jsxs(Ba,{to:"https://github.com/OWOX/owox-data-marts/issues",target:"_blank",rel:"noopener noreferrer",children:[e," Open issue here",o.jsx(Tl,{className:"h-4 w-4"})]})})})}const J0="**********";function Oee({specification:e,configuration:t,onValueChange:n}){const{name:r,title:s}=e,l=s??r,c=r;return o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx($t,{type:"checkbox",id:c,name:r,checked:t[r]||!1,onChange:d=>{n(r,d.target.checked)},className:"text-primary focus:ring-primary border-border h-4 w-4 rounded"}),o.jsx(ba,{htmlFor:c,className:"cursor-pointer text-sm",children:o.jsx(wo,{htmlFor:c,required:e.required,tooltip:e.description,children:l})})]})}function Mee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s,default:l}=e,c=e.title??e.name;return o.jsx($t,{id:r,name:r,type:"number",value:t[r]||l||"",placeholder:s??`Enter ${c.toLowerCase()}`,onChange:d=>{const h=parseFloat(d.target.value)||0;n(r,h)}})}function kee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s,default:l}=e,c=e.title??e.name;return o.jsx(Fi,{id:r,name:r,value:Array.isArray(t[r])?t[r].join(`
|
|
723
|
+
`},LT=XQ(nX)(dD),rX={config:eX},aX=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 fD(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],fD(e[n],t[n]))}),MT(MT({},e),t)}var sX={type:"cancelation",msg:"operation is manually canceled"};function Vx(e){var t=!1,n=new Promise(function(r,s){e.then(function(l){return t?s(sX):r(l)}),e.catch(s)});return n.cancel=function(){return t=!0},n}var oX=["monaco"],iX=WQ.create({config:QQ,isInitialized:!1,resolve:null,reject:null,monaco:null}),hD=OQ(iX,2),Zf=hD[0],Dg=hD[1];function lX(e){var t=rX.config(e),n=t.monaco,r=AQ(t,oX);Dg(function(s){return{config:fD(s.config,r),monaco:n}})}function cX(){var e=Zf(function(t){var n=t.monaco,r=t.isInitialized,s=t.resolve;return{monaco:n,isInitialized:r,resolve:s}});if(!e.isInitialized){if(Dg({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),Vx(Hx);if(window.monaco&&window.monaco.editor)return mD(window.monaco),e.resolve(window.monaco),Vx(Hx);aX(uX,fX)(hX)}return Vx(Hx)}function uX(e){return document.body.appendChild(e)}function dX(e){var t=document.createElement("script");return e&&(t.src=e),t}function fX(e){var t=Zf(function(r){var s=r.config,l=r.reject;return{config:s,reject:l}}),n=dX("".concat(t.config.paths.vs,"/loader.js"));return n.onload=function(){return e()},n.onerror=t.reject,n}function hX(){var e=Zf(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){var r=n.m;mD(r),e.resolve(r)},function(n){e.reject(n)})}function mD(e){Zf().monaco||Dg({monaco:e})}function mX(){return Zf(function(e){var t=e.monaco;return t})}var Hx=new Promise(function(e,t){return Dg({resolve:e,reject:t})}),pD={config:lX,init:cX,__getMonacoInstance:mX},pX={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},$x=pX,gX={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},vX=gX;function yX({children:e}){return je.createElement("div",{style:vX.container},e)}var xX=yX,bX=xX;function SX({width:e,height:t,isEditorReady:n,loading:r,_ref:s,className:l,wrapperProps:c}){return je.createElement("section",{style:{...$x.wrapper,width:e,height:t},...c},!n&&je.createElement(bX,null,r),je.createElement("div",{ref:s,style:{...$x.fullWidth,...!n&&$x.hide},className:l}))}var CX=SX,gD=p.memo(CX);function wX(e){p.useEffect(e,[])}var vD=wX;function EX(e,t,n=!0){let r=p.useRef(!0);p.useEffect(r.current||!n?()=>{r.current=!1}:e,t)}var da=EX;function Zd(){}function Zc(e,t,n,r){return RX(e,r)||TX(e,t,n,r)}function RX(e,t){return e.editor.getModel(yD(e,t))}function TX(e,t,n,r){return e.editor.createModel(t,n,r?yD(e,r):void 0)}function yD(e,t){return e.Uri.parse(t)}function jX({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:w,wrapperProps:C={},beforeMount:E=Zd,onMount:R=Zd}){let[T,j]=p.useState(!1),[O,D]=p.useState(!0),_=p.useRef(null),A=p.useRef(null),M=p.useRef(null),U=p.useRef(R),B=p.useRef(E),G=p.useRef(!1);vD(()=>{let $=pD.init();return $.then(I=>(A.current=I)&&D(!1)).catch(I=>(I==null?void 0:I.type)!=="cancelation"&&console.error("Monaco initialization: error:",I)),()=>_.current?H():$.cancel()}),da(()=>{if(_.current&&A.current){let $=_.current.getOriginalEditor(),I=Zc(A.current,e||"",r||n||"text",l||"");I!==$.getModel()&&$.setModel(I)}},[l],T),da(()=>{if(_.current&&A.current){let $=_.current.getModifiedEditor(),I=Zc(A.current,t||"",s||n||"text",c||"");I!==$.getModel()&&$.setModel(I)}},[c],T),da(()=>{let $=_.current.getModifiedEditor();$.getOption(A.current.editor.EditorOption.readOnly)?$.setValue(t||""):t!==$.getValue()&&($.executeEdits("",[{range:$.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),$.pushUndoStop())},[t],T),da(()=>{var $,I;(I=($=_.current)==null?void 0:$.getModel())==null||I.original.setValue(e||"")},[e],T),da(()=>{let{original:$,modified:I}=_.current.getModel();A.current.editor.setModelLanguage($,r||n||"text"),A.current.editor.setModelLanguage(I,s||n||"text")},[n,r,s],T),da(()=>{var $;($=A.current)==null||$.editor.setTheme(m)},[m],T),da(()=>{var $;($=_.current)==null||$.updateOptions(v)},[v],T);let K=p.useCallback(()=>{var Y;if(!A.current)return;B.current(A.current);let $=Zc(A.current,e||"",r||n||"text",l||""),I=Zc(A.current,t||"",s||n||"text",c||"");(Y=_.current)==null||Y.setModel({original:$,modified:I})},[n,t,s,e,r,l,c]),re=p.useCallback(()=>{var $;!G.current&&M.current&&(_.current=A.current.editor.createDiffEditor(M.current,{automaticLayout:!0,...v}),K(),($=A.current)==null||$.editor.setTheme(m),j(!0),G.current=!0)},[v,m,K]);p.useEffect(()=>{T&&U.current(_.current,A.current)},[T]),p.useEffect(()=>{!O&&!T&&re()},[O,T,re]);function H(){var I,Y,Z,ie;let $=(I=_.current)==null?void 0:I.getModel();d||((Y=$==null?void 0:$.original)==null||Y.dispose()),h||((Z=$==null?void 0:$.modified)==null||Z.dispose()),(ie=_.current)==null||ie.dispose()}return je.createElement(gD,{width:b,height:x,isEditorReady:T,loading:g,_ref:M,className:w,wrapperProps:C})}var _X=jX;p.memo(_X);function NX(e){let t=p.useRef();return p.useEffect(()=>{t.current=e},[e]),t.current}var AX=NX,Dm=new Map;function DX({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:w="100%",className:C,wrapperProps:E={},beforeMount:R=Zd,onMount:T=Zd,onChange:j,onValidate:O=Zd}){let[D,_]=p.useState(!1),[A,M]=p.useState(!0),U=p.useRef(null),B=p.useRef(null),G=p.useRef(null),K=p.useRef(T),re=p.useRef(R),H=p.useRef(),$=p.useRef(r),I=AX(l),Y=p.useRef(!1),Z=p.useRef(!1);vD(()=>{let L=pD.init();return L.then(P=>(U.current=P)&&M(!1)).catch(P=>(P==null?void 0:P.type)!=="cancelation"&&console.error("Monaco initialization: error:",P)),()=>B.current?be():L.cancel()}),da(()=>{var P,W,ae,fe;let L=Zc(U.current,e||r||"",t||s||"",l||n||"");L!==((P=B.current)==null?void 0:P.getModel())&&(v&&Dm.set(I,(W=B.current)==null?void 0:W.saveViewState()),(ae=B.current)==null||ae.setModel(L),v&&((fe=B.current)==null||fe.restoreViewState(Dm.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()&&(Z.current=!0,B.current.executeEdits("",[{range:B.current.getModel().getFullModelRange(),text:r,forceMoveMarkers:!0}]),B.current.pushUndoStop(),Z.current=!1))},[r],D),da(()=>{var P,W;let L=(P=B.current)==null?void 0:P.getModel();L&&s&&((W=U.current)==null||W.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 ie=p.useCallback(()=>{var L;if(!(!G.current||!U.current)&&!Y.current){re.current(U.current);let P=l||n,W=Zc(U.current,r||e||"",t||s||"",P||"");B.current=(L=U.current)==null?void 0:L.editor.create(G.current,{model:W,automaticLayout:!0,...m},g),v&&B.current.restoreViewState(Dm.get(P)),U.current.editor.setTheme(c),d!==void 0&&B.current.revealLine(d),_(!0),Y.current=!0}},[e,t,n,r,s,l,m,g,v,c,d]);p.useEffect(()=>{D&&K.current(B.current,U.current)},[D]),p.useEffect(()=>{!A&&!D&&ie()},[A,D,ie]),$.current=r,p.useEffect(()=>{var L,P;D&&j&&((L=H.current)==null||L.dispose(),H.current=(P=B.current)==null?void 0:P.onDidChangeModelContent(W=>{Z.current||j(B.current.getValue(),W)}))},[D,j]),p.useEffect(()=>{if(D){let L=U.current.editor.onDidChangeMarkers(P=>{var ae;let W=(ae=B.current.getModel())==null?void 0:ae.uri;if(W&&P.find(fe=>fe.path===W.path)){let fe=U.current.editor.getModelMarkers({resource:W});O==null||O(fe)}});return()=>{L==null||L.dispose()}}return()=>{}},[D,O]);function be(){var L,P;(L=H.current)==null||L.dispose(),x?v&&Dm.set(l,B.current.saveViewState()):(P=B.current.getModel())==null||P.dispose(),B.current.dispose()}return je.createElement(gD,{width:b,height:w,isEditorReady:D,loading:h,_ref:G,className:C,wrapperProps:E})}var OX=DX,MX=p.memo(OX);function kX({initialValue:e,onChange:t}){const[n,r]=p.useState((e==null?void 0:e.sqlQuery)??""),{resolvedTheme:s}=s4();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(MX,{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:J("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(Ra,{className:"text-muted-foreground/75 dark:text-muted-foreground/50 h-4 w-4"})})]})]})}var PT=1,IX=.9,LX=.8,PX=.17,Bx=.1,Gx=.999,UX=.9999,FX=.99,zX=/[\\\/_+.#"@\[\(\{&]/,VX=/[\\\/_+.#"@\[\(\{&]/g,HX=/[\s-]/,xD=/[\s-]/g;function Y0(e,t,n,r,s,l,c){if(l===t.length)return s===e.length?PT:FX;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,w;m>=0;)v=Y0(e,t,n,r,m+1,l+1,c),v>g&&(m===s?v*=PT:zX.test(e.charAt(m-1))?(v*=LX,b=e.slice(s,m-1).match(VX),b&&s>0&&(v*=Math.pow(Gx,b.length))):HX.test(e.charAt(m-1))?(v*=IX,w=e.slice(s,m-1).match(xD),w&&s>0&&(v*=Math.pow(Gx,w.length))):(v*=PX,s>0&&(v*=Math.pow(Gx,m-s))),e.charAt(m)!==t.charAt(l)&&(v*=UX)),(v<Bx&&n.charAt(m-1)===r.charAt(l+1)||r.charAt(l+1)===r.charAt(l)&&n.charAt(m-1)!==r.charAt(l))&&(x=Y0(e,t,n,r,m+1,l+2,c),x*Bx>v&&(v=x*Bx)),v>g&&(g=v),m=n.indexOf(h,m+1);return c[d]=g,g}function UT(e){return e.toLowerCase().replace(xD," ")}function $X(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,Y0(e,t,UT(e),UT(t),0,0,{})}var Id='[cmdk-group=""]',qx='[cmdk-group-items=""]',BX='[cmdk-group-heading=""]',bD='[cmdk-item=""]',FT=`${bD}:not([aria-disabled="true"])`,W0="cmdk-item-select",Bc="data-value",GX=(e,t,n)=>$X(e,t,n),SD=p.createContext(void 0),Kf=()=>p.useContext(SD),CD=p.createContext(void 0),Z1=()=>p.useContext(CD),wD=p.createContext(void 0),ED=p.forwardRef((e,t)=>{let n=Gc(()=>{var P,W;return{search:"",value:(W=(P=e.value)!=null?P:e.defaultValue)!=null?W:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=Gc(()=>new Set),s=Gc(()=>new Map),l=Gc(()=>new Map),c=Gc(()=>new Set),d=RD(e),{label:h,children:m,value:g,onValueChange:v,filter:x,shouldFilter:b,loop:w,disablePointerSelection:C=!1,vimBindings:E=!0,...R}=e,T=Nn(),j=Nn(),O=Nn(),D=p.useRef(null),_=nJ();Pl(()=>{if(g!==void 0){let P=g.trim();n.current.value=P,A.emit()}},[g]),Pl(()=>{_(6,re)},[]);let A=p.useMemo(()=>({subscribe:P=>(c.current.add(P),()=>c.current.delete(P)),snapshot:()=>n.current,setState:(P,W,ae)=>{var fe,ge,ue,Ne;if(!Object.is(n.current[P],W)){if(n.current[P]=W,P==="search")K(),B(),_(1,G);else if(P==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let Re=document.getElementById(O);Re?Re.focus():(fe=document.getElementById(T))==null||fe.focus()}if(_(7,()=>{var Re;n.current.selectedItemId=(Re=H())==null?void 0:Re.id,A.emit()}),ae||_(5,re),((ge=d.current)==null?void 0:ge.value)!==void 0){let Re=W??"";(Ne=(ue=d.current).onValueChange)==null||Ne.call(ue,Re);return}}A.emit()}},emit:()=>{c.current.forEach(P=>P())}}),[]),M=p.useMemo(()=>({value:(P,W,ae)=>{var fe;W!==((fe=l.current.get(P))==null?void 0:fe.value)&&(l.current.set(P,{value:W,keywords:ae}),n.current.filtered.items.set(P,U(W,ae)),_(2,()=>{B(),A.emit()}))},item:(P,W)=>(r.current.add(P),W&&(s.current.has(W)?s.current.get(W).add(P):s.current.set(W,new Set([P]))),_(3,()=>{K(),B(),n.current.value||G(),A.emit()}),()=>{l.current.delete(P),r.current.delete(P),n.current.filtered.items.delete(P);let ae=H();_(4,()=>{K(),(ae==null?void 0:ae.getAttribute("id"))===P&&G(),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,W){var ae,fe;let ge=(fe=(ae=d.current)==null?void 0:ae.filter)!=null?fe:GX;return P?ge(P,n.current.search,W):0}function B(){if(!n.current.search||d.current.shouldFilter===!1)return;let P=n.current.filtered.items,W=[];n.current.filtered.groups.forEach(fe=>{let ge=s.current.get(fe),ue=0;ge.forEach(Ne=>{let Re=P.get(Ne);ue=Math.max(Re,ue)}),W.push([fe,ue])});let ae=D.current;$().sort((fe,ge)=>{var ue,Ne;let Re=fe.getAttribute("id"),xe=ge.getAttribute("id");return((ue=P.get(xe))!=null?ue:0)-((Ne=P.get(Re))!=null?Ne:0)}).forEach(fe=>{let ge=fe.closest(qx);ge?ge.appendChild(fe.parentElement===ge?fe:fe.closest(`${qx} > *`)):ae.appendChild(fe.parentElement===ae?fe:fe.closest(`${qx} > *`))}),W.sort((fe,ge)=>ge[1]-fe[1]).forEach(fe=>{var ge;let ue=(ge=D.current)==null?void 0:ge.querySelector(`${Id}[${Bc}="${encodeURIComponent(fe[0])}"]`);ue==null||ue.parentElement.appendChild(ue)})}function G(){let P=$().find(ae=>ae.getAttribute("aria-disabled")!=="true"),W=P==null?void 0:P.getAttribute(Bc);A.setState("value",W||void 0)}function K(){var P,W,ae,fe;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 ue of r.current){let Ne=(W=(P=l.current.get(ue))==null?void 0:P.value)!=null?W:"",Re=(fe=(ae=l.current.get(ue))==null?void 0:ae.keywords)!=null?fe:[],xe=U(Ne,Re);n.current.filtered.items.set(ue,xe),xe>0&&ge++}for(let[ue,Ne]of s.current)for(let Re of Ne)if(n.current.filtered.items.get(Re)>0){n.current.filtered.groups.add(ue);break}n.current.filtered.count=ge}function re(){var P,W,ae;let fe=H();fe&&(((P=fe.parentElement)==null?void 0:P.firstChild)===fe&&((ae=(W=fe.closest(Id))==null?void 0:W.querySelector(BX))==null||ae.scrollIntoView({block:"nearest"})),fe.scrollIntoView({block:"nearest"}))}function H(){var P;return(P=D.current)==null?void 0:P.querySelector(`${bD}[aria-selected="true"]`)}function $(){var P;return Array.from(((P=D.current)==null?void 0:P.querySelectorAll(FT))||[])}function I(P){let W=$()[P];W&&A.setState("value",W.getAttribute(Bc))}function Y(P){var W;let ae=H(),fe=$(),ge=fe.findIndex(Ne=>Ne===ae),ue=fe[ge+P];(W=d.current)!=null&&W.loop&&(ue=ge+P<0?fe[fe.length-1]:ge+P===fe.length?fe[0]:fe[ge+P]),ue&&A.setState("value",ue.getAttribute(Bc))}function Z(P){let W=H(),ae=W==null?void 0:W.closest(Id),fe;for(;ae&&!fe;)ae=P>0?eJ(ae,Id):tJ(ae,Id),fe=ae==null?void 0:ae.querySelector(FT);fe?A.setState("value",fe.getAttribute(Bc)):Y(P)}let ie=()=>I($().length-1),be=P=>{P.preventDefault(),P.metaKey?ie():P.altKey?Z(1):Y(1)},L=P=>{P.preventDefault(),P.metaKey?I(0):P.altKey?Z(-1):Y(-1)};return p.createElement(Ke.div,{ref:t,tabIndex:-1,...R,"cmdk-root":"",onKeyDown:P=>{var W;(W=R.onKeyDown)==null||W.call(R,P);let ae=P.nativeEvent.isComposing||P.keyCode===229;if(!(P.defaultPrevented||ae))switch(P.key){case"n":case"j":{E&&P.ctrlKey&&be(P);break}case"ArrowDown":{be(P);break}case"p":case"k":{E&&P.ctrlKey&&L(P);break}case"ArrowUp":{L(P);break}case"Home":{P.preventDefault(),I(0);break}case"End":{P.preventDefault(),ie();break}case"Enter":{P.preventDefault();let fe=H();if(fe){let ge=new Event(W0);fe.dispatchEvent(ge)}}}}},p.createElement("label",{"cmdk-label":"",htmlFor:M.inputId,id:M.labelId,style:aJ},h),Og(e,P=>p.createElement(CD.Provider,{value:A},p.createElement(SD.Provider,{value:M},P))))}),qX=p.forwardRef((e,t)=>{var n,r;let s=Nn(),l=p.useRef(null),c=p.useContext(wD),d=Kf(),h=RD(e),m=(r=(n=h.current)==null?void 0:n.forceMount)!=null?r:c==null?void 0:c.forceMount;Pl(()=>{if(!m)return d.item(s,c==null?void 0:c.id)},[m]);let g=TD(s,l,[e.value,e.children,l],e.keywords),v=Z1(),x=Ai(_=>_.value&&_.value===g.current),b=Ai(_=>m||d.filter()===!1?!0:_.search?_.filtered.items.get(s)>0:!0);p.useEffect(()=>{let _=l.current;if(!(!_||e.disabled))return _.addEventListener(W0,w),()=>_.removeEventListener(W0,w)},[b,e.onSelect,e.disabled]);function w(){var _,A;C(),(A=(_=h.current).onSelect)==null||A.call(_,g.current)}function C(){v.setState("value",g.current,!0)}if(!b)return null;let{disabled:E,value:R,onSelect:T,forceMount:j,keywords:O,...D}=e;return p.createElement(Ke.div,{ref:No(l,t),...D,id:s,"cmdk-item":"",role:"option","aria-disabled":!!E,"aria-selected":!!x,"data-disabled":!!E,"data-selected":!!x,onPointerMove:E||d.getDisablePointerSelection()?void 0:C,onClick:E?void 0:w},e.children)}),ZX=p.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:s,...l}=e,c=Nn(),d=p.useRef(null),h=p.useRef(null),m=Nn(),g=Kf(),v=Ai(b=>s||g.filter()===!1?!0:b.search?b.filtered.groups.has(c):!0);Pl(()=>g.group(c),[]),TD(c,d,[e.value,e.heading,h]);let x=p.useMemo(()=>({id:c,forceMount:s}),[s]);return p.createElement(Ke.div,{ref:No(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),Og(e,b=>p.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?m:void 0},p.createElement(wD.Provider,{value:x},b))))}),KX=p.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,s=p.useRef(null),l=Ai(c=>!c.search);return!n&&!l?null:p.createElement(Ke.div,{ref:No(s,t),...r,"cmdk-separator":"",role:"separator"})}),YX=p.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,s=e.value!=null,l=Z1(),c=Ai(m=>m.search),d=Ai(m=>m.selectedItemId),h=Kf();return p.useEffect(()=>{e.value!=null&&l.setState("search",e.value)},[e.value]),p.createElement(Ke.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)}})}),WX=p.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...s}=e,l=p.useRef(null),c=p.useRef(null),d=Ai(m=>m.selectedItemId),h=Kf();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(Ke.div,{ref:No(l,t),...s,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":d,"aria-label":r,id:h.listId},Og(e,m=>p.createElement("div",{ref:No(c,h.listInnerRef),"cmdk-list-sizer":""},m)))}),QX=p.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:s,contentClassName:l,container:c,...d}=e;return p.createElement(Yp,{open:n,onOpenChange:r},p.createElement(Wp,{container:c},p.createElement(Qp,{"cmdk-overlay":"",className:s}),p.createElement(Xp,{"aria-label":e.label,"cmdk-dialog":"",className:l},p.createElement(ED,{ref:t,...d}))))}),XX=p.forwardRef((e,t)=>Ai(n=>n.filtered.count===0)?p.createElement(Ke.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),JX=p.forwardRef((e,t)=>{let{progress:n,children:r,label:s="Loading...",...l}=e;return p.createElement(Ke.div,{ref:t,...l,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":s},Og(e,c=>p.createElement("div",{"aria-hidden":!0},c)))}),Mu=Object.assign(ED,{List:WX,Item:qX,Input:YX,Group:ZX,Separator:KX,Dialog:QX,Empty:XX,Loading:JX});function eJ(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function tJ(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function RD(e){let t=p.useRef(e);return Pl(()=>{t.current=e}),t}var Pl=typeof window>"u"?p.useEffect:p.useLayoutEffect;function Gc(e){let t=p.useRef();return t.current===void 0&&(t.current=e()),t}function Ai(e){let t=Z1(),n=()=>e(t.snapshot());return p.useSyncExternalStore(t.subscribe,n,n)}function TD(e,t,n,r=[]){let s=p.useRef(),l=Kf();return Pl(()=>{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(Bc,d),s.current=d}),s}var nJ=()=>{let[e,t]=p.useState(),n=Gc(()=>new Map);return Pl(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,s)=>{n.current.set(r,s),t({})}};function rJ(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function Og({asChild:e,children:t},n){return e&&p.isValidElement(t)?p.cloneElement(rJ(t),{ref:t.ref},n(t.props.children)):n(t)}var aJ={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};function jD({className:e,...t}){return o.jsx(Mu,{"data-slot":"command",className:J("bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",e),...t})}function _D({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(Fl,{className:"size-4 shrink-0 opacity-50"}),o.jsx(Mu.Input,{"data-slot":"command-input",className:J("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 sJ({className:e,...t}){return o.jsx(Mu.List,{"data-slot":"command-list",className:J("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",e),...t})}function ND({...e}){return o.jsx(Mu.Empty,{"data-slot":"command-empty",className:"py-6 text-center text-sm",...e})}function AD({className:e,...t}){return o.jsx(Mu.Group,{"data-slot":"command-group",className:J("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 DD({className:e,...t}){return o.jsx(Mu.Item,{"data-slot":"command-item",className:J("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 Mg="Popover",[OD]=kr(Mg,[Gs]),Yf=Gs(),[oJ,Zi]=OD(Mg),MD=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:s,onOpenChange:l,modal:c=!1}=e,d=Yf(t),h=p.useRef(null),[m,g]=p.useState(!1),[v,x]=zr({prop:r,defaultProp:s??!1,onChange:l,caller:Mg});return o.jsx(Su,{...d,children:o.jsx(oJ,{scope:t,contentId:Nn(),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})})};MD.displayName=Mg;var kD="PopoverAnchor",iJ=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Zi(kD,n),l=Yf(n),{onCustomAnchorAdd:c,onCustomAnchorRemove:d}=s;return p.useEffect(()=>(c(),()=>d()),[c,d]),o.jsx(Cu,{...l,...r,ref:t})});iJ.displayName=kD;var ID="PopoverTrigger",LD=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Zi(ID,n),l=Yf(n),c=vt(t,s.triggerRef),d=o.jsx(Ke.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":VD(s.open),...r,ref:c,onClick:Te(e.onClick,s.onOpenToggle)});return s.hasCustomAnchor?d:o.jsx(Cu,{asChild:!0,...l,children:d})});LD.displayName=ID;var K1="PopoverPortal",[lJ,cJ]=OD(K1,{forceMount:void 0}),PD=e=>{const{__scopePopover:t,forceMount:n,children:r,container:s}=e,l=Zi(K1,t);return o.jsx(lJ,{scope:t,forceMount:n,children:o.jsx(Sr,{present:n||l.open,children:o.jsx(Vl,{asChild:!0,container:s,children:r})})})};PD.displayName=K1;var mu="PopoverContent",UD=p.forwardRef((e,t)=>{const n=cJ(mu,e.__scopePopover),{forceMount:r=n.forceMount,...s}=e,l=Zi(mu,e.__scopePopover);return o.jsx(Sr,{present:r||l.open,children:l.modal?o.jsx(dJ,{...s,ref:t}):o.jsx(fJ,{...s,ref:t})})});UD.displayName=mu;var uJ=Ri("PopoverContent.RemoveScroll"),dJ=p.forwardRef((e,t)=>{const n=Zi(mu,e.__scopePopover),r=p.useRef(null),s=vt(t,r),l=p.useRef(!1);return p.useEffect(()=>{const c=r.current;if(c)return Zp(c)},[]),o.jsx(Ef,{as:uJ,allowPinchZoom:!0,children:o.jsx(FD,{...e,ref:s,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Te(e.onCloseAutoFocus,c=>{var d;c.preventDefault(),l.current||(d=n.triggerRef.current)==null||d.focus()}),onPointerDownOutside:Te(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:Te(e.onFocusOutside,c=>c.preventDefault(),{checkForDefaultPrevented:!1})})})}),fJ=p.forwardRef((e,t)=>{const n=Zi(mu,e.__scopePopover),r=p.useRef(!1),s=p.useRef(!1);return o.jsx(FD,{...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()}})}),FD=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=Zi(mu,n),b=Yf(n);return Gp(),o.jsx(wf,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:l,children:o.jsx(zl,{asChild:!0,disableOutsidePointerEvents:c,onInteractOutside:g,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:m,onDismiss:()=>x.onOpenChange(!1),children:o.jsx(Tf,{"data-state":VD(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)"}})})})}),zD="PopoverClose",hJ=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Zi(zD,n);return o.jsx(Ke.button,{type:"button",...r,ref:t,onClick:Te(e.onClick,()=>s.onOpenChange(!1))})});hJ.displayName=zD;var mJ="PopoverArrow",pJ=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Yf(n);return o.jsx(jf,{...s,...r,ref:t})});pJ.displayName=mJ;function VD(e){return e?"open":"closed"}var gJ=MD,vJ=LD,yJ=PD,xJ=UD;function Y1({...e}){return o.jsx(gJ,{"data-slot":"popover",...e})}function W1({...e}){return o.jsx(vJ,{"data-slot":"popover-trigger",...e})}function Q1({className:e,align:t="center",sideOffset:n=4,...r}){return o.jsx(yJ,{children:o.jsx(xJ,{"data-slot":"popover-content",align:t,sideOffset:n,className:J("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 X1({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 w={};return e.forEach(C=>{const E=C.group??"";Object.prototype.hasOwnProperty.call(w,E)||(w[E]=[]),w[E].push(C)}),w},[e]),x=e.find(w=>w.value===t),b=p.useCallback(w=>{n(w),requestAnimationFrame(()=>{g(""),h(!1)})},[n]);return o.jsxs(Y1,{open:d,onOpenChange:h,modal:!0,children:[o.jsx(W1,{asChild:!0,children:o.jsxs(Ce,{variant:"outline",role:"combobox","aria-expanded":d,className:J("w-full justify-between",!t&&"text-muted-foreground",l),disabled:c,children:[x?x.label:r,o.jsx(Sb,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),o.jsx(Q1,{className:"max-h-[300px] min-w-[300px] overflow-auto p-0",align:"start",sideOffset:5,children:o.jsxs(jD,{children:[o.jsx(_D,{placeholder:`Search ${r.toLowerCase()}...`,value:m,onValueChange:g}),o.jsx(ND,{children:s}),Object.entries(v).map(([w,C])=>o.jsx(AD,{heading:w,children:C.map(E=>o.jsxs(DD,{value:E.value,onSelect:()=>{b(E.value)},keywords:[E.label],children:[o.jsx(dr,{className:J("mr-2 h-4 w-4",t===E.value?"opacity-100":"opacity-0")}),E.label]},E.value))},w||"default"))]})})]})}var kg="Collapsible",[bJ,HD]=kr(kg),[SJ,J1]=bJ(kg),$D=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:s,disabled:l,onOpenChange:c,...d}=e,[h,m]=zr({prop:r,defaultProp:s??!1,onChange:c,caller:kg});return o.jsx(SJ,{scope:n,disabled:l,contentId:Nn(),open:h,onOpenToggle:p.useCallback(()=>m(g=>!g),[m]),children:o.jsx(Ke.div,{"data-state":rS(h),"data-disabled":l?"":void 0,...d,ref:t})})});$D.displayName=kg;var BD="CollapsibleTrigger",eS=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,s=J1(BD,n);return o.jsx(Ke.button,{type:"button","aria-controls":s.contentId,"aria-expanded":s.open||!1,"data-state":rS(s.open),"data-disabled":s.disabled?"":void 0,disabled:s.disabled,...r,ref:t,onClick:Te(e.onClick,s.onOpenToggle)})});eS.displayName=BD;var tS="CollapsibleContent",nS=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,s=J1(tS,e.__scopeCollapsible);return o.jsx(Sr,{present:n||s.open,children:({present:l})=>o.jsx(CJ,{...r,ref:t,present:l})})});nS.displayName=tS;var CJ=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:s,...l}=e,c=J1(tS,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),w=b.current,C=c.open||d,E=p.useRef(C),R=p.useRef(void 0);return p.useEffect(()=>{const T=requestAnimationFrame(()=>E.current=!1);return()=>cancelAnimationFrame(T)},[]),br(()=>{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,E.current||(T.style.transitionDuration=R.current.transitionDuration,T.style.animationName=R.current.animationName),h(r)}},[c.open,r]),o.jsx(Ke.div,{"data-state":rS(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":w?`${w}px`:void 0,...e.style},children:C&&s})});function rS(e){return e?"open":"closed"}var GD=$D,wJ=eS,EJ=nS,xs="Accordion",RJ=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[aS,TJ,jJ]=og(xs),[Ig]=kr(xs,[jJ,HD]),sS=HD(),qD=je.forwardRef((e,t)=>{const{type:n,...r}=e,s=r,l=r;return o.jsx(aS.Provider,{scope:e.__scopeAccordion,children:n==="multiple"?o.jsx(DJ,{...l,ref:t}):o.jsx(AJ,{...s,ref:t})})});qD.displayName=xs;var[ZD,_J]=Ig(xs),[KD,NJ]=Ig(xs,{collapsible:!1}),AJ=je.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},collapsible:l=!1,...c}=e,[d,h]=zr({prop:n,defaultProp:r??"",onChange:s,caller:xs});return o.jsx(ZD,{scope:e.__scopeAccordion,value:je.useMemo(()=>d?[d]:[],[d]),onItemOpen:h,onItemClose:je.useCallback(()=>l&&h(""),[l,h]),children:o.jsx(KD,{scope:e.__scopeAccordion,collapsible:l,children:o.jsx(YD,{...c,ref:t})})})}),DJ=je.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},...l}=e,[c,d]=zr({prop:n,defaultProp:r??[],onChange:s,caller:xs}),h=je.useCallback(g=>d((v=[])=>[...v,g]),[d]),m=je.useCallback(g=>d((v=[])=>v.filter(x=>x!==g)),[d]);return o.jsx(ZD,{scope:e.__scopeAccordion,value:c,onItemOpen:h,onItemClose:m,children:o.jsx(KD,{scope:e.__scopeAccordion,collapsible:!0,children:o.jsx(YD,{...l,ref:t})})})}),[OJ,Lg]=Ig(xs),YD=je.forwardRef((e,t)=>{const{__scopeAccordion:n,disabled:r,dir:s,orientation:l="vertical",...c}=e,d=je.useRef(null),h=vt(d,t),m=TJ(n),v=Af(s)==="ltr",x=Te(e.onKeyDown,b=>{var M;if(!RJ.includes(b.key))return;const w=b.target,C=m().filter(U=>{var B;return!((B=U.ref.current)!=null&&B.disabled)}),E=C.findIndex(U=>U.ref.current===w),R=C.length;if(E===-1)return;b.preventDefault();let T=E;const j=0,O=R-1,D=()=>{T=E+1,T>O&&(T=j)},_=()=>{T=E-1,T<j&&(T=O)};switch(b.key){case"Home":T=j;break;case"End":T=O;break;case"ArrowRight":l==="horizontal"&&(v?D():_());break;case"ArrowDown":l==="vertical"&&D();break;case"ArrowLeft":l==="horizontal"&&(v?_():D());break;case"ArrowUp":l==="vertical"&&_();break}const A=T%R;(M=C[A].ref.current)==null||M.focus()});return o.jsx(OJ,{scope:n,disabled:r,direction:s,orientation:l,children:o.jsx(aS.Slot,{scope:n,children:o.jsx(Ke.div,{...c,"data-orientation":l,ref:h,onKeyDown:r?void 0:x})})})}),Op="AccordionItem",[MJ,oS]=Ig(Op),WD=je.forwardRef((e,t)=>{const{__scopeAccordion:n,value:r,...s}=e,l=Lg(Op,n),c=_J(Op,n),d=sS(n),h=Nn(),m=r&&c.value.includes(r)||!1,g=l.disabled||e.disabled;return o.jsx(MJ,{scope:n,open:m,disabled:g,triggerId:h,children:o.jsx(GD,{"data-orientation":l.orientation,"data-state":nO(m),...d,...s,ref:t,disabled:g,open:m,onOpenChange:v=>{v?c.onItemOpen(r):c.onItemClose(r)}})})});WD.displayName=Op;var QD="AccordionHeader",XD=je.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Lg(xs,n),l=oS(QD,n);return o.jsx(Ke.h3,{"data-orientation":s.orientation,"data-state":nO(l.open),"data-disabled":l.disabled?"":void 0,...r,ref:t})});XD.displayName=QD;var Q0="AccordionTrigger",JD=je.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Lg(xs,n),l=oS(Q0,n),c=NJ(Q0,n),d=sS(n);return o.jsx(aS.ItemSlot,{scope:n,children:o.jsx(wJ,{"aria-disabled":l.open&&!c.collapsible||void 0,"data-orientation":s.orientation,id:l.triggerId,...d,...r,ref:t})})});JD.displayName=Q0;var eO="AccordionContent",tO=je.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Lg(xs,n),l=oS(eO,n),c=sS(n);return o.jsx(EJ,{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}})});tO.displayName=eO;function nO(e){return e?"open":"closed"}var kJ=qD,IJ=WD,LJ=XD,PJ=JD,UJ=tO;const iS={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(W9,{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}},rO=p.createContext("default");function hr({variant:e="default",...t}){return o.jsx(rO.Provider,{value:e,children:o.jsx(kJ,{"data-slot":"accordion",...t})})}function lS(e){const t=p.useContext(rO);return e??t??"default"}function Kn({className:e,variant:t,...n}){const r=lS(t),{itemClass:s}=iS[r];return o.jsx(IJ,{"data-slot":"accordion-item",className:J(s,e),...n})}function Yn({className:e,children:t,variant:n,...r}){const s=lS(n),{triggerClass:l,icon:c,chevronClass:d,headerClass:h}=iS[s];return o.jsx(LJ,{className:h,children:o.jsxs(PJ,{"data-slot":"accordion-trigger",className:J(l,e),...r,children:[c,t,o.jsx(Za,{className:d,"aria-hidden":"true"})]})})}function Wn({className:e,children:t,variant:n,...r}){const s=lS(n),{contentClass:l,contentInnerClass:c}=iS[s];return o.jsx(UJ,{"data-slot":"accordion-content",className:J(l,e),...r,children:o.jsx("div",{className:c,children:t})})}function fr({href:e,children:t,className:n,...r}){return o.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:J("text-muted-foreground hover:bg-muted inline-flex items-center px-1 font-medium hover:rounded-md",n),...r,children:[t,o.jsx(Tl,{className:"ml-1 inline h-3 w-3","aria-hidden":"true"})]})}function FJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"service-account-details",children:[o.jsx(Yn,{children:"How do I get a Service Account JSON key?"}),o.jsxs(Wn,{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(fr,{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 zJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"project-id-details",children:[o.jsx(Yn,{children:"How do I find my Project ID?"}),o.jsxs(Wn,{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(fr,{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 VJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"gbq-location-details",children:[o.jsx(Yn,{children:"How do I find my dataset location?"}),o.jsxs(Wn,{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(fr,{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 aO=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}},HJ=({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?aO(l):null;return o.jsxs(o.Fragment,{children:[o.jsxs(Vs,{title:"Connection Settings",children:[o.jsx(Qt,{control:e.control,name:"config.projectId",render:({field:d})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Enter the ID of your Google Cloud project where BigQuery usage will be billed",children:"Project ID"}),o.jsx(en,{children:o.jsx($t,{...d,placeholder:"Enter a Project Id"})}),o.jsx(ar,{children:o.jsx(zJ,{})}),o.jsx(ln,{})]})}),o.jsx(Qt,{control:e.control,name:"config.location",render:({field:d})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Choose the same region where your BigQuery data is stored to ensure queries work correctly",children:"Location"}),o.jsx(en,{children:o.jsx(X1,{options:aq,value:d.value,onValueChange:d.onChange,placeholder:"Select a location",emptyMessage:"No locations found",className:"w-full"})}),o.jsx(ar,{children:o.jsx(VJ,{})}),o.jsx(ln,{})]})})]}),o.jsx(Vs,{title:"Authentication",children:o.jsx(Qt,{control:e.control,name:"credentials.serviceAccount",render:({field:d})=>o.jsxs(Xt,{children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(Jt,{tooltip:"Paste a JSON key from a service account that has access to the selected storage provider",children:"Service Account"}),!t&&l&&o.jsx(Ce,{variant:"ghost",size:"sm",onClick:r,type:"button",children:"Edit"}),t&&o.jsx(Ce,{variant:"ghost",size:"sm",onClick:s,type:"button",children:"Cancel"})]}),o.jsx(en,{children:!t&&c?o.jsxs(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsx(fr,{href:c.url,children:c.email})}),o.jsx(_t,{children:o.jsx("p",{children:"View in Google Cloud Console"})})]}):o.jsx(Fi,{...d,className:"min-h-[150px] font-mono",rows:8,placeholder:"Paste your service account JSON here"})}),o.jsx(ar,{children:o.jsx(FJ,{})}),o.jsx(ln,{})]})})})]})};function $J(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"athena-region-details",children:[o.jsx(Yn,{children:"How do I find my Athena region?"}),o.jsxs(Wn,{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(fr,{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 BJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"athena-output-bucket-details",children:[o.jsx(Yn,{children:"How do I find a bucket?"}),o.jsxs(Wn,{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(fr,{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 GJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"athena-access-key-id-details",children:[o.jsx(Yn,{children:"How do I get my AWS Access Key ID?"}),o.jsxs(Wn,{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(fr,{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(d_,{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(fr,{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 qJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"athena-secret-access-key-details",children:[o.jsx(Yn,{children:"How do I get my AWS Secret Access Key?"}),o.jsxs(Wn,{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(fr,{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 ZJ=({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(Vs,{title:"Connection Settings",children:[o.jsx(Qt,{control:e.control,name:"config.region",render:({field:r})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Enter the AWS region where your Athena service is active",children:"Region"}),o.jsx(en,{children:o.jsx($t,{...r,placeholder:"Enter a region"})}),o.jsx(ar,{children:o.jsx($J,{})}),o.jsx(ln,{})]})}),o.jsx(Qt,{control:e.control,name:"config.outputBucket",render:({field:r})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Specify the S3 bucket where Athena query results will be stored",children:"Output Bucket"}),o.jsx(en,{children:o.jsx($t,{...r,placeholder:"Enter an output bucket"})}),o.jsx(ar,{children:o.jsx(BJ,{})}),o.jsx(ln,{})]})})]}),o.jsxs(Vs,{title:"Authentication",children:[o.jsx(Qt,{control:e.control,name:"credentials.accessKeyId",render:({field:r})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Your AWS Access Key ID used for authentication",children:"Access Key ID"}),o.jsx(en,{children:o.jsx($t,{...r,placeholder:"Enter an access key id"})}),o.jsx(ar,{children:o.jsx(GJ,{})}),o.jsx(ln,{})]})}),o.jsx(Qt,{control:e.control,name:"credentials.secretAccessKey",render:({field:r})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Your AWS Secret Access Key used for authentication",children:"Secret Access Key"}),o.jsx(en,{children:o.jsx($t,{...r,type:"password",placeholder:t||"Enter a secret access key"})}),o.jsx(ar,{children:o.jsx(qJ,{})}),o.jsx(ln,{})]})})]})]})};function KJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"bigquery-api-details",children:[o.jsx(Yn,{children:"How do I enable the BigQuery API?"}),o.jsxs(Wn,{children:[o.jsxs("p",{className:"mb-2",children:["To run queries and process data in Google BigQuery, you need to enable the"," ",o.jsx(fr,{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 YJ(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"athena-api-details",children:[o.jsx(Yn,{children:"How do I activate Athena API?"}),o.jsxs(Wn,{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(fr,{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 sO(e){return JSON.parse(JSON.stringify(e))}function WJ({initialData:e,onSubmit:t,onCancel:n,onDirtyChange:r}){const s=$i({resolver:Wl(wq),defaultValues:e}),{watch:l,control:c,formState:{isDirty:d,isSubmitting:h}}=s,m=l("type");je.useEffect(()=>{r==null||r(d)},[d,r]);const g=async v=>{const{dirtyFields:x}=s.formState,b=sO(v);return x.credentials||delete b.credentials,t(b)};return o.jsx(Zl,{...s,children:o.jsxs(Bi,{onSubmit:v=>{s.handleSubmit(g)(v)},noValidate:!0,children:[o.jsxs(Kl,{children:[o.jsxs(Vs,{title:"General",children:[o.jsx(Qt,{control:c,name:"title",render:({field:v})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Name the storage to clarify its purpose",children:"Title"}),o.jsx(en,{children:o.jsx($t,{...v,placeholder:"Storage title"})}),o.jsx(ln,{})]})}),o.jsx(Qt,{control:c,name:"type",render:({field:v})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"The selected source will be used to process data in your Data Marts",children:"Storage Type"}),o.jsx(en,{children:o.jsxs(Sa,{value:v.value,onValueChange:v.onChange,disabled:!!e,children:[o.jsx(wa,{className:"w-full",children:o.jsx(Ca,{placeholder:"Select a storage type"})}),o.jsx(Ea,{children:o.jsx(Ng,{children:Vi.getAllTypes().map(({type:x,displayName:b,icon:w,status:C})=>o.jsx(qn,{value:x,disabled:C===bo.COMING_SOON,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(w,{size:20}),b]})},x))})})]})}),o.jsxs(ar,{children:[m===Pe.GOOGLE_BIGQUERY&&o.jsx(KJ,{}),m===Pe.AWS_ATHENA&&o.jsx(YJ,{})]}),o.jsx(ln,{})]})})]}),m===Pe.GOOGLE_BIGQUERY&&o.jsx(HJ,{form:s}),m===Pe.AWS_ATHENA&&o.jsx(ZJ,{form:s})]}),o.jsxs(Yl,{children:[o.jsx(Ce,{variant:"default",type:"submit",className:"w-full","aria-label":"Save",disabled:!d||h,children:"Save"}),o.jsx(Ce,{variant:"outline",type:"button",onClick:n,className:"w-full","aria-label":"Cancel",children:"Cancel"})]})]})})}function oO({isOpen:e,onClose:t,dataStorage:n,onSaveSuccess:r}){const{updateDataStorage:s}=Ag(),[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(w=>{h(w)},[]),x=async w=>{if(n){const C=await s(n.id,w);C&&(r(C),t())}},b=p.useRef(!1);return p.useEffect(()=>{const w=n?"Edit":"Create";e&&!b.current?(Fe({event:"data_storage_config_open",category:"DataStorage",action:w,label:n==null?void 0:n.type}),b.current=!0):!e&&b.current&&(Fe({event:"data_storage_config_close",category:"DataStorage",action:w,label:n==null?void 0:n.type}),b.current=!1)},[e,n]),o.jsxs(o.Fragment,{children:[o.jsx(Mi,{open:e,onOpenChange:w=>{w||m()},children:o.jsxs(ki,{children:[o.jsxs(Ii,{children:[o.jsx(Li,{children:"Configure Storage Provider"}),o.jsx(Hl,{children:"Customize settings for your storage provider"})]}),o.jsx(WJ,{initialData:n??void 0,onSubmit:x,onCancel:m,onDirtyChange:v})]})}),o.jsx(xa,{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 QJ=({dataStorage:e,onDataStorageChange:t})=>{const[n,r]=p.useState(!1),s=Vi.getInfo(e.type),l=()=>{r(!0)},c=()=>{r(!1)},d=()=>{if(!p4(e))return o.jsxs("div",{className:"flex items-center space-x-2 text-sm",children:[o.jsx(Bp,{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(fr,{href:b,onClick:w=>{w.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(G1,{children:o.jsx(oO,{isOpen:n,onClose:c,dataStorage:e,onSaveSuccess:h=>{t&&t(h)}})})]})};function XJ({initialType:e,onTypeSelect:t}){var c;const[n,r]=p.useState(e??null);p.useEffect(()=>{e!==void 0&&e!==n&&r(e)},[e,n]);const 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(ba,{className:"text-foreground",children:"Definition Type"}),o.jsxs(Sa,{value:n??"",onValueChange:d=>{s(d)},children:[o.jsx(wa,{className:"dm-card-formcontrol w-full","aria-label":"Definition Type",children:o.jsx(Ca,{placeholder:"Select definition type",children:n&&((c=l.find(d=>d.type===n))==null?void 0:c.label)})}),o.jsx(Ea,{children:o.jsx(Ng,{children:l.map(d=>o.jsxs(qn,{value:d.type,children:[d.label,o.jsx("span",{className:"text-muted-foreground/80 ml-2",children:d.description})]},d.type))})})]})]})}const JJ=sn({definitionType:qs(qe.SQL),definition:sn({sqlQuery:on().min(1,"SQL query is required")})}),eee=e=>{const t=I4(e);return sn({definitionType:qs(qe.TABLE),definition:t})},tee=e=>{const t=I4(e);return sn({definitionType:qs(qe.VIEW),definition:t})},nee=e=>{const t=LZ(e);return sn({definitionType:qs(qe.TABLE_PATTERN),definition:t})},ree=sn({definitionType:qs(qe.CONNECTOR),definition:sn({connector:sn({source:sn({name:on().min(1,"Connector name is required"),configuration:tT(vB(pB())).min(1,"At least one configuration is required"),node:on().min(1,"Node is required"),fields:tT(on()).min(1,"At least one field is required")}),storage:sn({fullyQualifiedName:on().min(1,"fully qualified name is required")})})})}),aee=(e,t)=>{if(!e)return sn({definitionType:yB(c1(qe)),definition:sn({}).optional()});switch(e){case qe.SQL:return JJ;case qe.TABLE:return eee(t);case qe.VIEW:return tee(t);case qe.TABLE_PATTERN:return nee(t);case qe.CONNECTOR:return ree;default:return sn({})}};function see({control:e}){return o.jsx(Qt,{control:e,name:"definition.sqlQuery",render:({field:t})=>o.jsxs(Xt,{className:"dm-card-block",children:[o.jsx(Jt,{className:"text-foreground",children:"SQL Query"}),o.jsx(en,{children:o.jsx(kX,{initialValue:{sqlQuery:t.value},onChange:n=>{t.onChange(n.sqlQuery)}})}),o.jsx(ln,{})]})})}function oee({control:e,storageType:t}){const n=v4(t),r=y4(t);return o.jsx(Qt,{control:e,name:"definition.fullyQualifiedName",render:({field:s})=>o.jsxs(Xt,{className:"dm-card-block",children:[o.jsx(Jt,{children:"Fully Qualified Table Name"}),o.jsx(en,{children:o.jsx($t,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(ar,{className:"text-muted-foreground/75",children:r}),o.jsx(ln,{})]})})}function iee({control:e,storageType:t}){const n=v4(t),r=y4(t);return o.jsx(Qt,{control:e,name:"definition.fullyQualifiedName",render:({field:s})=>o.jsxs(Xt,{className:"dm-card-block",children:[o.jsx(Jt,{children:"Fully Qualified View Name"}),o.jsx(en,{children:o.jsx($t,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(ar,{className:"text-muted-foreground/75",children:r}),o.jsx(ln,{})]})})}function lee({control:e,storageType:t}){const n=_q(t),r=Nq(t);return o.jsx(Qt,{control:e,name:"definition.pattern",render:({field:s})=>o.jsxs(Xt,{className:"dm-card-block",children:[o.jsx(Jt,{children:"Table Pattern"}),o.jsx(en,{children:o.jsx($t,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(ar,{className:"text-muted-foreground/75",children:r}),o.jsx(ln,{})]})})}const X0=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{}}},cee=bf("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 cS({className:e,variant:t,...n}){return o.jsx("div",{"data-slot":"alert",role:"alert",className:J(cee({variant:t}),e),...n})}function iO({className:e,...t}){return o.jsx("div",{"data-slot":"alert-title",className:J("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",e),...t})}function uS({className:e,...t}){return o.jsx("div",{"data-slot":"alert-description",className:J("text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",e),...t})}var Pg="Tabs",[uee]=kr(Pg,[ig]),lO=ig(),[dee,dS]=uee(Pg),cO=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,onValueChange:s,defaultValue:l,orientation:c="horizontal",dir:d,activationMode:h="automatic",...m}=e,g=Af(d),[v,x]=zr({prop:r,onChange:s,defaultProp:l??"",caller:Pg});return o.jsx(dee,{scope:n,baseId:Nn(),value:v,onValueChange:x,orientation:c,dir:g,activationMode:h,children:o.jsx(Ke.div,{dir:g,"data-orientation":c,...m,ref:t})})});cO.displayName=Pg;var uO="TabsList",dO=p.forwardRef((e,t)=>{const{__scopeTabs:n,loop:r=!0,...s}=e,l=dS(uO,n),c=lO(n);return o.jsx(EN,{asChild:!0,...c,orientation:l.orientation,dir:l.dir,loop:r,children:o.jsx(Ke.div,{role:"tablist","aria-orientation":l.orientation,...s,ref:t})})});dO.displayName=uO;var fO="TabsTrigger",hO=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,disabled:s=!1,...l}=e,c=dS(fO,n),d=lO(n),h=gO(c.baseId,r),m=vO(c.baseId,r),g=r===c.value;return o.jsx(RN,{asChild:!0,...d,focusable:!s,active:g,children:o.jsx(Ke.button,{type:"button",role:"tab","aria-selected":g,"aria-controls":m,"data-state":g?"active":"inactive","data-disabled":s?"":void 0,disabled:s,id:h,...l,ref:t,onMouseDown:Te(e.onMouseDown,v=>{!s&&v.button===0&&v.ctrlKey===!1?c.onValueChange(r):v.preventDefault()}),onKeyDown:Te(e.onKeyDown,v=>{[" ","Enter"].includes(v.key)&&c.onValueChange(r)}),onFocus:Te(e.onFocus,()=>{const v=c.activationMode!=="manual";!g&&!s&&v&&c.onValueChange(r)})})})});hO.displayName=fO;var mO="TabsContent",pO=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,forceMount:s,children:l,...c}=e,d=dS(mO,n),h=gO(d.baseId,r),m=vO(d.baseId,r),g=r===d.value,v=p.useRef(g);return p.useEffect(()=>{const x=requestAnimationFrame(()=>v.current=!1);return()=>cancelAnimationFrame(x)},[]),o.jsx(Sr,{present:s||g,children:({present:x})=>o.jsx(Ke.div,{"data-state":g?"active":"inactive","data-orientation":d.orientation,role:"tabpanel","aria-labelledby":h,hidden:!x,id:m,tabIndex:0,...c,ref:t,style:{...e.style,animationDuration:v.current?"0s":void 0},children:x&&l})})});pO.displayName=mO;function gO(e,t){return`${e}-trigger-${t}`}function vO(e,t){return`${e}-content-${t}`}var fee=cO,hee=dO,mee=hO,pee=pO;function gee({className:e,...t}){return o.jsx(fee,{"data-slot":"tabs",className:J("flex flex-col gap-2",e),...t})}function vee({className:e,...t}){return o.jsx(hee,{"data-slot":"tabs-list",className:J("bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",e),...t})}function yee({className:e,...t}){return o.jsx(mee,{"data-slot":"tabs-trigger",className:J("data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),...t})}function xee({className:e,...t}){return o.jsx(pee,{"data-slot":"tabs-content",className:J("flex-1 outline-none",e),...t})}const bee=GD,See=eS,Cee=nS;function wee({children:e,className:t="",...n}){return o.jsx("div",{className:J("flex flex-1 flex-col overflow-hidden",t),...n,children:e})}function Eee({children:e,className:t="",...n}){return o.jsx("div",{className:J("bg-muted dark:bg-sidebar flex-1 overflow-y-auto p-4",t),...n,children:o.jsx("div",{className:"flex min-h-full flex-col gap-4",children:e})})}function Ree({children:e,className:t="",variant:n="horizontal",...r}){const s=n==="vertical"?"flex flex-col gap-1.5 pt-4":"flex items-center justify-between border-t px-4 py-3";return o.jsx("div",{className:J(s,t),...r,children:e})}function $d({children:e,className:t="",...n}){return o.jsx("div",{"data-slot":"wizard-step-item",className:J("group border-border flex flex-col gap-2 rounded-md border-b bg-white px-4 py-3 transition-shadow duration-200 hover:shadow-sm dark:border-transparent dark:bg-white/4",t),...n,children:e})}function Tee({label:e,children:t,className:n="",options:r,value:s,onValueChange:l,required:c=!1,tooltip:d,...h}){return o.jsx("div",{"data-slot":"wizard-step-item-one-of",className:J("group border-border flex flex-col gap-2 rounded-md border-b bg-white px-4 py-3 transition-shadow duration-200 hover:shadow-sm dark:border-transparent dark:bg-white/4",n),...h,children:o.jsxs(gee,{value:s,onValueChange:l,children:[o.jsxs("div",{className:"flex items-center",children:[o.jsx(wo,{required:c,tooltip:d,className:"w-full",children:e}),o.jsx(vee,{children:r.map(m=>o.jsx(yee,{value:m.value,children:m.label},m.value))})]}),t]})})}function jee({title:e,children:t,defaultOpen:n=!1,className:r=""}){const[s,l]=p.useState(n);return o.jsxs(bee,{open:s,onOpenChange:l,"data-slot":"wizard-collapsible",className:J("group flex flex-col gap-2 py-3",r),children:[o.jsx(See,{asChild:!0,children:o.jsxs("button",{type:"button",className:J("flex cursor-pointer items-center gap-1"),children:[o.jsx("span",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:e}),o.jsx(Ra,{className:J("text-foreground/75 h-3.5 w-3.5 transition-transform duration-200",s&&"rotate-90")})]})}),o.jsx(Cee,{className:"data-[state=open]:animate-collapsible-down data-[state=closed]:animate-collapsible-up overflow-hidden",children:o.jsx("div",{className:"flex flex-col gap-2 pt-2",children:t})})]})}function wo({children:e,required:t=!1,tooltip:n,tooltipProps:r,className:s="",...l}){return o.jsxs(ba,{"data-slot":"wizard-step-label",className:J("text-foreground flex items-center justify-between gap-2 text-sm font-medium",s),...l,children:[t?o.jsxs(Tt,{...r,children:[o.jsx(jt,{asChild:!0,children:o.jsxs("span",{className:"flex items-center gap-1",children:[e,o.jsx("span",{className:"ml-1 text-red-500",children:"*"})]})}),o.jsx(_t,{side:"top",align:"center",role:"tooltip",children:"Required"})]}):o.jsx("span",{children:e}),n&&o.jsxs(Tt,{...r,children:[o.jsx(jt,{asChild:!0,children:o.jsx("button",{type:"button",tabIndex:-1,className:"pointer-events-none opacity-0 transition group-hover:pointer-events-auto group-hover:opacity-100","aria-label":"Help information",children:o.jsx(Fr,{className:"text-muted-foreground/50 hover:text-muted-foreground size-4 shrink-0 transition-colors","aria-hidden":"true"})})}),o.jsx(_t,{side:"top",align:"center",role:"tooltip",children:n})]})]})}function wl({title:e,children:t,className:n="",...r}){return o.jsxs("section",{"data-slot":"wizard-step-section",className:J("mb-8",n),...r,children:[e&&o.jsx("h3",{className:"text-muted-foreground/75 mb-2 text-xs font-semibold tracking-wide uppercase",children:e}),o.jsx("div",{className:"flex flex-col gap-2",children:t})]})}function Di({icon:e,title:t,subtitle:n,docUrl:r,variant:s="default",className:l,...c}){return s==="compact"?o.jsxs("div",{"data-slot":"wizard-step-hero",className:J("border-border mb-6 flex items-center justify-between gap-4 border-b pb-4",l),...c,children:[o.jsxs("div",{className:"flex items-center gap-2",children:[e&&o.jsx("div",{children:e}),o.jsx("h2",{className:"text-md font-medium",children:t})]}),r!=null&&o.jsx(Ce,{variant:"outline",asChild:!0,children:o.jsxs(Ba,{to:r,target:"_blank",rel:"noopener noreferrer",children:["Documentation",o.jsx(Tl,{className:"h-4 w-4"})]})})]}):o.jsxs("div",{"data-slot":"wizard-step-hero",className:J("mb-6 flex flex-col items-center justify-center text-center",l),...c,children:[e&&o.jsx("div",{className:"mt-6 mb-3",children:e}),o.jsx("h2",{className:"text-xl font-medium",children:t}),n&&o.jsx("p",{className:"text-muted-foreground mt-2 text-sm",children:n}),r!=null&&o.jsx(Ce,{variant:"outline",className:"mt-3 mb-6",asChild:!0,children:o.jsxs(Ba,{to:r,target:"_blank",rel:"noopener noreferrer",children:["Documentation",o.jsx(Tl,{className:"h-4 w-4"})]})})]})}function Ro({children:e,className:t="",...n}){return o.jsx("div",{"data-slot":"wizard-step",className:J("space-y-4",t),...n,children:e})}function _ee({children:e,className:t="",...n}){return o.jsx("div",{className:J("grid grid-cols-1 gap-4 md:grid-cols-2",t),...n,children:e})}function Nee({icon:e,title:t,selected:n=!1,disabled:r=!1,onClick:s,onDoubleClick:l,className:c="",...d}){return o.jsxs("div",{className:J("border-border flex items-center gap-4 rounded-md border-b bg-white px-4 py-3 transition-shadow duration-200 select-none hover:shadow-sm dark:border-transparent dark:bg-white/4",r?"cursor-not-allowed opacity-50 hover:shadow-none":"cursor-pointer hover:shadow-sm dark:hover:bg-white/8",n&&!r?"ring-primary border-transparent ring-2 dark:bg-white/8":"",c),onClick:s,onDoubleClick:l,...d,children:[e&&o.jsx("span",{className:"shrink-0",children:e}),r?o.jsxs(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsx("span",{className:"cursor-not-allowed text-sm font-medium opacity-70",children:t})}),o.jsx(_t,{side:"top",align:"center",children:"Coming soon"})]}):o.jsx("span",{className:"text-sm font-medium",children:t})]})}function yO({type:e,id:t,name:n,value:r,label:s,checked:l,selected:c=!1,disabled:d=!1,tooltip:h,rightIcon:m,onChange:g,className:v="",...x}){const b=C=>{g&&g(e==="checkbox"?C.target.checked:C.target.value)},w=p.useRef(null);return o.jsxs("div",{"data-slot":"wizard-step-card-item",onClick:C=>{if(d)return;const E=C.target;E.tagName==="INPUT"||E.tagName==="LABEL"||E.closest("label")||w.current&&w.current.click()},className:J("group border-border flex items-center gap-2 rounded-md border-b bg-white px-4 py-3 transition-shadow duration-200 select-none hover:shadow-sm dark:border-transparent dark:bg-white/4",d?"cursor-not-allowed":"cursor-pointer hover:shadow-sm dark:hover:bg-white/8",c?"ring-primary border-transparent ring-2 dark:bg-white/8":"",v),children:[o.jsx("input",{ref:w,id:t,type:e,name:n,value:r,checked:l,disabled:d,onChange:b,className:J("text-primary focus:ring-primary border-border cursor-pointer",e==="radio"||e==="checkbox"?"h-4 w-4":"h-8 w-full rounded-md border px-2"),...x}),s&&o.jsx(wo,{htmlFor:t,className:J("cursor-pointer",d&&"cursor-not-allowed"),children:s}),(h||m)&&o.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[h&&o.jsxs(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsx(Fr,{className:"text-muted-foreground/75 pointer-events-none h-4 w-4 opacity-0 group-hover:pointer-events-auto group-hover:opacity-100","data-tooltip-trigger":!0})}),o.jsx(_t,{side:"top",align:"center",children:h})]}),m&&o.jsx("div",{className:"flex items-center",children:m})]})]})}function fS({variant:e="grid",items:t,className:n=""}){const r=t??(e==="grid"?12:6),s=e==="grid"?"grid grid-cols-1 gap-4 md:grid-cols-2":"flex flex-col gap-4";return o.jsx("div",{"data-slot":"wizard-step-loading",className:J(s,n),children:Array.from({length:r}).map((l,c)=>o.jsx(as,{className:"border-border h-12 rounded-md border-b bg-white dark:bg-white/4"},c))})}function Aee({connectors:e,selectedConnector:t,loading:n,error:r,onConnectorSelect:s,onConnectorDoubleClick:l}){return n?o.jsx(fS,{variant:"grid"}):r?o.jsxs(cS,{variant:"destructive",children:[o.jsx(Sf,{className:"h-4 w-4"}),o.jsx(uS,{children:"Failed to load available connectors. Please try again."})]}):o.jsxs(Ro,{children:[o.jsx(wl,{title:"Choose Connector",children:o.jsx(_ee,{children:e.map(c=>o.jsx(Nee,{icon:c.logoBase64?o.jsx(Ff,{base64:c.logoBase64,size:20}):null,title:c.displayName,selected:(t==null?void 0:t.name)===c.name,onClick:()=>{s(c)},onDoubleClick:()=>{s(c),l==null||l(c)}},c.name))})}),e.length===0&&o.jsx(Di,{icon:o.jsx(nf,{size:56,strokeWidth:1}),title:"No connectors available",subtitle:"Ask your administrator to configure connectors."})]})}function Dee({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(o.Fragment,{children:[o.jsx("div",{className:"flex-1",children:r&&o.jsxs(Ce,{variant:"outline",onClick:c,disabled:s,children:[o.jsx(JI,{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(Ce,{variant:"default",onClick:d,disabled:!n||s,children:g}):o.jsxs(Ce,{variant:"default",onClick:l,disabled:!n||s,children:[h,o.jsx(Ra,{className:"h-4 w-4"})]})})]})}function El({connector:e,size:t=24,variant:n="compact"}){return o.jsx(Di,{icon:o.jsx(Ff,{base64:e.logoBase64,size:t}),title:e.displayName,docUrl:e.docUrl,variant:n})}function nu({label:e}){return o.jsx("div",{className:"border-border text-muted-foreground mt-3 flex items-center justify-center gap-2 border-t pt-3 text-sm",children:o.jsx(Ce,{variant:"outline",asChild:!0,children:o.jsxs(Ba,{to:"https://github.com/OWOX/owox-data-marts/issues",target:"_blank",rel:"noopener noreferrer",children:[e," Open issue here",o.jsx(Tl,{className:"h-4 w-4"})]})})})}const J0="**********";function Oee({specification:e,configuration:t,onValueChange:n}){const{name:r,title:s}=e,l=s??r,c=r;return o.jsxs("div",{className:"flex items-center space-x-2",children:[o.jsx($t,{type:"checkbox",id:c,name:r,checked:t[r]||!1,onChange:d=>{n(r,d.target.checked)},className:"text-primary focus:ring-primary border-border h-4 w-4 rounded"}),o.jsx(ba,{htmlFor:c,className:"cursor-pointer text-sm",children:o.jsx(wo,{htmlFor:c,required:e.required,tooltip:e.description,children:l})})]})}function Mee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s}=e,l=e.title??e.name;return o.jsx($t,{id:r,name:r,type:"number",value:t[r]||"",placeholder:s??`Enter ${l.toLowerCase()}`,onChange:c=>{const d=c.target.value,h=d===""?void 0:parseFloat(d);n(r,h)}})}function kee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s,default:l}=e,c=e.title??e.name;return o.jsx(Fi,{id:r,name:r,value:Array.isArray(t[r])?t[r].join(`
|
|
724
724
|
`):Array.isArray(l)?l.join(`
|
|
725
725
|
`):"",placeholder:s??`Enter ${c.toLowerCase()} (one per line)`,rows:4,onChange:d=>{const h=d.target.value.split(`
|
|
726
|
-
`).filter(m=>m.trim());n(r,h)}})}function Iee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s,default:l}=e,c=e.title??e.name,d=h=>{if(!h||typeof h!="string"&&typeof h!="number")return"";const m=typeof h=="string"?h:h.toString();try{const g=new Date(m);return isNaN(g.getTime())?"":g.toISOString().split("T")[0]}catch{return""}};return o.jsx($t,{id:r,name:r,type:"date",value:t[r]||d(l)||"",placeholder:s??`Enter ${c.toLowerCase()}`,onChange:h=>{n(r,h.target.value)}})}function Lee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s,default:l}=e,c=e.title??e.name;return o.jsx($t,{id:r,name:r,type:"text",value:t[r]||l||"",placeholder:s??`Enter ${c.toLowerCase()}`,onChange:d=>{n(r,d.target.value)}})}function Pee({specification:e,configuration:t,onValueChange:n}){const r=e.title??e.name,{name:s,placeholder:l,default:c}=e;return o.jsx(Fi,{id:s,name:s,value:t[s]&&typeof t[s]=="object"?JSON.stringify(t[s],null,2):typeof c=="object"?JSON.stringify(c,null,2):"",placeholder:l??`Enter ${r.toLowerCase()} as JSON`,rows:6,className:"font-mono",onChange:d=>{try{const h=JSON.parse(d.target.value);n(s,h)}catch{n(s,d.target.value)}}})}function Uee({specification:e,configuration:t,onValueChange:n,isEditingExisting:r,isSecretEditing:s}){const l=e.title??e.name,c=r&&!s;return o.jsx($t,{id:e.name,...c?{}:{name:e.name},type:c?"password":"text",autoComplete:c?"new-password":"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,value:c?J0:t[e.name]||"",...c?{readOnly:!0,disabled:!0}:{},...c?{}:{placeholder:e.placeholder??`Enter ${l.toLowerCase()}`},...c?{}:{onChange:d=>{n(e.name,d.target.value)}}})}function Fee({specification:e,configuration:t,onValueChange:n,specOptions:r}){const{name:s,placeholder:l,default:c}=e,d=e.title??e.name,h=r.map(m=>({value:m,label:m}));return o.jsx(X1,{options:h,value:t[s]||c||"",onValueChange:m=>{n(s,m)},placeholder:l??`Select ${d.toLowerCase()}`,emptyMessage:"No options available",className:"w-full"})}function xO({specification:e,configuration:t,onValueChange:n,flags:r}){const{requiredType:s,options:l}=e,{isSecret:c=!1,isEditingExisting:d=!1,isSecretEditing:h=!1}=r??{};if(c)return o.jsx(Uee,{specification:e,configuration:t,onValueChange:n,isEditingExisting:d,isSecretEditing:h});if(l&&l.length>0)return o.jsx(Fee,{specification:e,configuration:t,onValueChange:n,specOptions:l});switch(s){case rs.BOOLEAN:return o.jsx(Oee,{specification:e,configuration:t,onValueChange:n});case rs.NUMBER:return o.jsx(Mee,{specification:e,configuration:t,onValueChange:n});case rs.ARRAY:return o.jsx(kee,{specification:e,configuration:t,onValueChange:n});case rs.OBJECT:return o.jsx(Pee,{specification:e,configuration:t,onValueChange:n});case rs.DATE:return o.jsx(Iee,{specification:e,configuration:t,onValueChange:n});case rs.STRING:default:return o.jsx(Lee,{specification:e,configuration:t,onValueChange:n})}}function zee({specification:e,configuration:t,isEditingExisting:n,isSecretEditing:r,isSecret:s,onValueChange:l,onSecretEditToggle:c}){return o.jsxs($d,{children:[e.requiredType!==rs.BOOLEAN&&o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(wo,{htmlFor:e.name,required:e.required,tooltip:e.description,children:e.title??e.name}),s&&n&&o.jsx(Ce,{variant:"ghost",size:"sm",type:"button",onClick:()=>{c(e.name,!r)},children:r?"Cancel":"Edit"})]}),xO({specification:e,configuration:t,onValueChange:l,flags:{isSecret:s,isEditingExisting:n,isSecretEditing:r}})]},e.name)}function Vee({specification:e,configuration:t,onValueChange:n,isEditingExisting:r,isSecretEditing:s,onSecretEditToggle:l}){const c=p.useMemo(()=>{var v,x;const g=t[e.name];if(g&&typeof g=="object"){const b=Object.keys(g);if(b.length>0)return b[0]}return((x=(v=e.oneOf)==null?void 0:v[0])==null?void 0:x.value)??""},[t,e.name,e.oneOf]),[d,h]=p.useState(c);if(p.useEffect(()=>{h(c)},[c]),!e.oneOf)return null;const m=(g,v,x)=>{const b=t[e.name]&&typeof t[e.name]=="object"?t[e.name]:{};n(e.name,{[g]:{...typeof b[g]=="object"&&b[g]!==null?b[g]:{},[v]:x}})};return o.jsx(Tee,{label:e.title??e.name,options:e.oneOf.map(g=>({value:g.value,label:g.label})),value:d,onValueChange:h,children:e.oneOf.map(g=>o.jsx(xee,{value:g.value,children:Object.entries(g.items).map(([v,x])=>{const b=t[e.name]&&typeof t[e.name]=="object"?t[e.name]:{},w=Array.isArray(x.attributes)&&Object.keys(b)[0]===g.value?x.attributes.includes("SECRET"):!1,C=typeof t[e.name]=="object"&&t[e.name]!==null?t[e.name]:{},E=typeof C[g.value]=="object"&&C[g.value]!==null?C[g.value]:{};return o.jsxs("div",{className:"mb-4",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(wo,{htmlFor:v,required:x.required,tooltip:x.description,className:"mb-2 justify-start",children:v}),w&&r&&o.jsx(Ce,{variant:"ghost",size:"sm",type:"button",onClick:()=>{l(e.name,!s)},children:s?"Cancel":"Edit"})]}),xO({specification:{...x,name:v},configuration:E,onValueChange:(R,T)=>{m(g.value,R,T)},flags:{isEditingExisting:r,isSecret:w,isSecretEditing:s}})]},v)})},g.value))},e.name)}function zT(e,t,n,r,s,l){return e.map(c=>{const d=Array.isArray(c.attributes)?c.attributes.includes("SECRET"):!1,h=s[c.name];return c.oneOf&&c.requiredType===rs.OBJECT?o.jsx(Vee,{specification:c,configuration:t,onValueChange:n,isEditingExisting:l,isSecretEditing:h,onSecretEditToggle:r},c.name):o.jsx(zee,{specification:c,configuration:t,isEditingExisting:l,isSecret:d,isSecretEditing:h,onValueChange:n,onSecretEditToggle:r},c.name)})}function VT({collapsibleTitle:e,items:t,configuration:n,onValueChange:r,onSecretEditToggle:s,secretEditing:l,isEditingExisting:c}){return e?o.jsx(jee,{title:e,children:zT(t,n,r,s,l,c)}):zT(t,n,r,s,l,c)}function Hee({currentConnectorName:e,onCopyConfiguration:t,connectorSpecification:n}){const[r,s]=p.useState([]),[l,c]=p.useState(!1),[d,h]=p.useState(!1),m=p.useCallback(async()=>{c(!0);try{const x=await rn.getDataMartsByConnectorName(e);s(x)}catch{s([])}finally{c(!1)}},[e]);p.useEffect(()=>{d&&m()},[d,m]);const g=(x,b)=>{const w=b._id;if(!w){console.error("Configuration does not have _id field");return}t({dataMartId:x.id,dataMartTitle:x.title,configId:w,configuration:b}),h(!1)},v=x=>{const w=[],C=R=>{if(!n)return!0;const T=n.find(j=>j.name===R);return(T==null?void 0:T.required)??!1},E=(R,T,j=0,O=!0)=>{if(R.startsWith("_")||O&&j===0&&!C(R))return;let D=null;if(T==null)D="N/A";else if(typeof T=="string")D=T;else if(typeof T=="number"||typeof T=="boolean")D=String(T);else if(Array.isArray(T))D=JSON.stringify(T);else if(typeof T=="object"){w.push({key:R,value:"{",indent:j}),Object.entries(T).forEach(([_,A])=>{E(_,A,j+1,!1)}),w.push({key:"",value:"}",indent:j});return}else D=JSON.stringify(T);w.push({key:R,value:D,indent:j})};for(const[R,T]of Object.entries(x))E(R,T);return o.jsx("div",{className:"space-y-1 font-mono text-xs",children:w.map(({key:R,value:T,indent:j},O)=>o.jsxs("div",{className:"flex gap-2",style:{paddingLeft:`${String(j*12)}px`},children:[R&&o.jsxs("span",{className:"font-medium",children:[R,":"]}),o.jsx("span",{className:"text-muted-foreground truncate",title:T,children:T})]},O))})};return o.jsx(ls,{children:o.jsxs(Cr,{open:d,onOpenChange:h,children:[o.jsx(wr,{asChild:!0,children:o.jsxs(Ce,{type:"button",variant:"ghost",size:"sm",className:"cursor-pointer",children:[o.jsx("span",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:"Auto-fill from…"}),o.jsx(Ra,{className:J("text-foreground/75 h-3.5 w-3.5 transition-transform duration-200",d&&"rotate-90")})]})}),o.jsx(Er,{side:"bottom",align:"end",className:"w-72",children:l?o.jsx(bt,{disabled:!0,children:"Loading…"}):r.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 p-4 text-center",children:[o.jsx("div",{className:"bg-muted/70 rounded-full p-3",children:o.jsx(lL,{className:"text-muted-foreground h-6 w-6",strokeWidth:1.5})}),o.jsx("span",{className:"text-foreground text-sm font-medium",children:"No matching Data Marts"}),o.jsx("span",{className:"text-muted-foreground text-sm",children:"You can auto-fill settings only from connector-based Data Marts with the same source."})]}):o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx("div",{className:"text-muted-foreground border-b p-2 text-sm",children:"Select one of your existing Data Marts to auto-fill settings in this form"}),o.jsx("div",{children:r.map(x=>{const w=x.definition.connector.source.configuration;return w.length===0?null:w.length===1?o.jsxs(Tt,{delayDuration:300,children:[o.jsx(jt,{asChild:!0,children:o.jsxs(bt,{onSelect:()=>{g(x,w[0])},children:[o.jsx(Xm,{className:"text-foreground h-4 w-4"}),x.title]})}),o.jsx(_t,{side:"right",className:"max-w-sm",children:v(w[0])})]},x.id):o.jsxs(Qb,{children:[o.jsxs(Xb,{className:"flex items-center gap-2",children:[o.jsx(Xm,{className:"text-foreground h-4 w-4"}),o.jsx("span",{children:x.title})]}),o.jsx(Jb,{children:w.map((C,E)=>o.jsxs(Tt,{delayDuration:300,children:[o.jsx(jt,{asChild:!0,children:o.jsxs(bt,{onSelect:()=>{g(x,C)},children:["Configuration ",E+1]})}),o.jsx(_t,{side:"right",className:"max-w-sm",children:v(C)})]},E))})]},x.id)})})]})})]})})}function HT({connector:e,connectorSpecification:t,onConfigurationChange:n,onValidationChange:r,initialConfiguration:s,loading:l=!1,isEditingExisting:c=!1}){const[d,h]=p.useState({}),m=p.useRef(!1),g=p.useRef(!1),[v,x]=p.useState({});p.useEffect(()=>{if(t){g.current=!0;const _={...s??{}};t.forEach(A=>{const M=Array.isArray(A.attributes)?A.attributes.includes("SECRET"):!1;_[A.name]===void 0&&A.default!==void 0&&(_[A.name]=A.default),c&&M&&(_[A.name]=J0)}),h(_),m.current=!0,setTimeout(()=>{g.current=!1},0)}},[t,s,c]),p.useEffect(()=>{m.current&&s&&Object.keys(s).length>0&&(g.current=!0,h({...s}),setTimeout(()=>{g.current=!1},0))},[s]),p.useEffect(()=>{m.current&&!g.current&&Object.keys(d).length>0&&(n==null||n(d))},[d,n]);const b=(_,A)=>{h(M=>({...M,[_]:A}))},w=p.useCallback(_=>!(_==null||typeof _=="string"&&_.trim()===""||Array.isArray(_)&&_.length===0),[]),C=p.useCallback((_,A)=>{var U;if(typeof _!="object"||_===null)return w(_);const M=(U=A.oneOf)==null?void 0:U.filter(B=>B.value===Object.keys(_)[0]);return M?M.every(B=>Object.entries(B.items).every(([,G])=>B.value in _?C(_[B.value],G):!1)):w(_[A.name])},[w]),E=p.useCallback((_,A)=>{const M=A.filter(K=>K.required&&K.oneOf),U=M.length===0?!0:M.some(K=>C(_[K.name],K)),G=A.filter(K=>K.required&&K.name!=="Fields").every(K=>w(_[K.name]));return U&&G},[w,C]),R=(_,A)=>{x(M=>({...M,[_]:A})),h(A?M=>({...M,[_]:""}):M=>({...M,[_]:J0}))},T=_=>{const A={...d};Object.entries(_.configuration).forEach(([M,U])=>{A[M]=U}),A._copiedFrom={dataMartId:_.dataMartId,dataMartTitle:_.dataMartTitle,configId:_.configId},h(A)};if(p.useEffect(()=>{if(t&&r){const _=E(d,t);r(_)}},[d,t,r,E]),l)return o.jsx(fS,{variant:"list"});if(!t||t.length===0)return o.jsxs(Ro,{children:[o.jsx(El,{connector:e}),o.jsx(Di,{icon:o.jsx(nf,{size:56,strokeWidth:1}),title:"No configuration found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),o.jsx(nu,{label:"Need configuration?"})]});const j=[...t].filter(_=>{var A;return _.name!=="Fields"&&!((A=_.attributes)!=null&&A.includes("HIDE_IN_CONFIG_FORM"))}).sort((_,A)=>{const M=U=>{const B=U.default!=null&&U.default!=="";return U.required&&!B?1:U.required&&B?2:!U.required&&!B?3:4};return M(_)-M(A)}),O=j.filter(_=>{var A;return!((A=_.attributes)!=null&&A.includes("ADVANCED"))}),D=j.filter(_=>{var A;return(A=_.attributes)==null?void 0:A.includes("ADVANCED")});return o.jsx(o.Fragment,{children:o.jsxs(Ro,{children:[o.jsx(El,{connector:e}),o.jsxs(wl,{children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("h3",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:"Configure Settings"}),o.jsx(Hee,{currentConnectorName:e.name,onCopyConfiguration:T,connectorSpecification:t})]}),O.length>0&&o.jsx(VT,{items:O,configuration:d,onValueChange:b,onSecretEditToggle:R,secretEditing:v,isEditingExisting:c}),D.length>0&&o.jsx(VT,{collapsibleTitle:"Advanced Settings",items:D,configuration:d,onValueChange:b,onSecretEditToggle:R,secretEditing:v,isEditingExisting:c})]})]})})}function $ee({connector:e,connectorFields:t,selectedField:n,connectorName:r,loading:s=!1,onFieldSelect:l}){const c=r?`Select data for ${r}`:"Select data";return s?o.jsx(fS,{variant:"list"}):!t||t.length===0?o.jsxs(Ro,{children:[o.jsx(El,{connector:e}),o.jsx(Di,{icon:o.jsx(nf,{size:56,strokeWidth:1}),title:r?`No nodes found for ${r}`:"No nodes found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),o.jsx(nu,{label:"Missing some data?"})]}):o.jsxs(Ro,{children:[o.jsx(El,{connector:e}),o.jsxs(wl,{title:c,children:[t.map(d=>o.jsx(yO,{type:"radio",id:d.name,name:"selectedField",value:d.name,label:d.overview??d.name,checked:n===d.name,onChange:h=>{l(h)},tooltip:d.name&&o.jsxs("div",{className:"flex flex-col gap-2 py-1",children:[o.jsxs("p",{children:[o.jsx("span",{className:"font-semibold",children:"Table name:"})," ",d.destinationName??d.name]}),d.description&&o.jsxs("p",{children:[o.jsx("span",{className:"font-semibold",children:"Description:"})," ",d.description]}),d.documentation&&o.jsxs(Ba,{to:d.documentation,target:"_blank",rel:"noopener noreferrer",className:"bg-muted/16 hover:bg-muted/20 dark:bg-muted/8 dark:hover:bg-muted/16 flex items-center justify-center gap-1 rounded-sm px-2 py-1 font-semibold",children:["Read more",o.jsx(Ra,{className:"h-3 w-3"})]})]}),selected:n===d.name},d.name)),o.jsx(nu,{label:"Missing some data?"})]})]})}var As=(e=>(e.ASC="asc",e.DESC="desc",e.ORIGINAL="original",e))(As||{});function $T({connector:e,connectorFields:t,selectedField:n,selectedFields:r,onFieldToggle:s}){const l=p.useRef(null),[c,d]=p.useState(""),[h,m]=p.useState(As.ORIGINAL),g=t==null?void 0:t.find(R=>R.name===n),v=p.useMemo(()=>(g==null?void 0:g.fields)??[],[g==null?void 0:g.fields]),x=p.useMemo(()=>(g==null?void 0:g.uniqueKeys)??[],[g==null?void 0:g.uniqueKeys]),b=p.useMemo(()=>{const R=new Map;return v.forEach((T,j)=>R.set(T.name,j)),R},[v]),w=p.useMemo(()=>{const R=v.filter(j=>j.name.toLowerCase().includes(c.toLowerCase().trim())),T=(j,O)=>{const D=x.includes(j.name),_=x.includes(O.name);if(D&&!_)return-1;if(!D&&_)return 1;if(h===As.ASC)return j.name.localeCompare(O.name);if(h===As.DESC)return O.name.localeCompare(j.name);const A=b.get(j.name)??0,M=b.get(O.name)??0;return A-M};return[...R].sort(T)},[v,c,x,h,b]),C=v.map(R=>R.name),E=r.filter(R=>C.includes(R)).length;return p.useEffect(()=>{if(x.length>0){const R=x.filter(T=>v.some(j=>j.name===T)&&!r.includes(T));R.length>0&&R.forEach(T=>{s(T,!0)})}},[n,x,v,r,s]),p.useEffect(()=>{const R=T=>{const O=(T.ctrlKey||T.metaKey)&&T.shiftKey&&T.key.toLowerCase()==="a",D=document.activeElement.tagName;if(!(D==="INPUT"||D==="TEXTAREA")&&O){T.preventDefault();const _=v.map(U=>U.name),M=_.filter(U=>!r.includes(U)).length>0;_.forEach(U=>{s(U,M)})}};return window.addEventListener("keydown",R),()=>{window.removeEventListener("keydown",R)}},[v,r,s]),!n||!t?o.jsxs(Ro,{children:[o.jsx(El,{connector:e}),o.jsx(Di,{icon:o.jsx(nf,{size:56,strokeWidth:1}),title:"No fields found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),o.jsx(nu,{label:"Need fields?"})]}):v.length?o.jsx(Ro,{children:o.jsxs(o.Fragment,{children:[o.jsx(El,{connector:e}),o.jsxs("div",{className:"border-border -mt-6 mb-6 flex w-full items-center gap-2 border-b",children:[o.jsxs("div",{className:"relative flex-1",children:[o.jsx(Fl,{className:"text-muted-foreground absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 cursor-text",onClick:()=>{var R;(R=l.current)==null||R.focus()}}),o.jsx("input",{ref:l,type:"text",placeholder:"Search field",value:c,onChange:R=>{d(R.target.value)},className:"h-12 w-full rounded-none border-0 pl-9 text-sm outline-none"}),c&&o.jsx("button",{type:"button",onClick:()=>{d("")},className:"text-muted-foreground hover:text-foreground absolute top-1/2 right-0 -translate-y-1/2",children:o.jsx(su,{className:"h-4 w-4"})})]}),o.jsxs(Cr,{children:[o.jsx(wr,{asChild:!0,children:o.jsxs(Ce,{variant:"ghost",size:"icon","aria-label":"Sort fields",children:[h===As.ASC&&o.jsx(q2,{className:"text-muted-foreground h-4 w-4"}),h===As.DESC&&o.jsx(G2,{className:"text-muted-foreground h-4 w-4"}),h===As.ORIGINAL&&o.jsx(Z2,{className:"text-muted-foreground h-4 w-4"})]})}),o.jsxs(Er,{align:"end",children:[o.jsxs(bt,{onSelect:()=>{m(As.ASC)},children:[o.jsx(q2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"A–Z"]}),o.jsxs(bt,{onSelect:()=>{m(As.DESC)},children:[o.jsx(G2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Z–A"]}),o.jsxs(bt,{onSelect:()=>{m(As.ORIGINAL)},children:[o.jsx(Z2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Original"]})]})]})]}),o.jsxs(wl,{title:`Selected ${String(E)} of ${String(C.length)} fields for "${n}" data`,children:[w.map(R=>{const T=x.includes(R.name);return o.jsx(yO,{type:"checkbox",id:`field-${R.name}`,name:"selectedFields",value:R.name,checked:r.includes(R.name),selected:r.includes(R.name)||T,disabled:T,onChange:j=>{s(R.name,j)},label:R.name,tooltip:o.jsxs("div",{className:"flex flex-col gap-2 py-1",children:[T&&o.jsxs("p",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"font-semibold",children:"Unique key"})," ",o.jsx(l0,{className:"text-secondary h-3 w-3"})]}),o.jsxs("p",{children:[o.jsx("span",{className:"font-semibold",children:"Type:"})," ",R.type]}),R.description&&o.jsxs("p",{children:[o.jsx("span",{className:"font-semibold",children:"Description:"})," ",R.description]})]}),rightIcon:T?o.jsx(l0,{className:"text-muted-foreground/75 h-4 w-4"}):void 0},R.name)}),w.length===0&&c&&o.jsxs("div",{className:"text-muted-foreground pt-8 pb-4 text-center text-sm",children:['No fields match "',c,'"']}),o.jsx(nu,{label:"Need another field?"})]})]})}):o.jsxs(Ro,{children:[o.jsx(El,{connector:e}),o.jsx(Di,{icon:o.jsx(nf,{size:56,strokeWidth:1}),title:"No fields found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),o.jsx(nu,{label:"Need fields?"})]})}const bO=p.createContext(void 0),SO={triggers:[],selectedTrigger:null,isLoading:!1,error:null};function Bee(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 SO;default:return e}}class Gee extends Bl{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 Uc=new Gee;var xn=(e=>(e.REPORT_RUN="REPORT_RUN",e.CONNECTOR_RUN="CONNECTOR_RUN",e))(xn||{});const Kc={SCHEDULED_REPORT_RUN:"scheduled-report-run-config"};class eb{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!==xn.REPORT_RUN)return t;const n=t.triggerConfig;if(!n.reportId)return t;try{const r=await yo.getReportById(n.reportId),s=gl(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:xn.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 qee{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:xn.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 Zx={getMapper(e){switch(e){case xn.REPORT_RUN:return new eb;case xn.CONNECTOR_RUN:return new qee;default:throw new Error(`Unknown scheduled trigger type: ${String(e)}`)}}},Ld={mapFromDto(e){return Zx.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 xn.REPORT_RUN:return new eb().enhanceWithReportData(n);case xn.CONNECTOR_RUN:{const r=t.definition;return{...n,triggerConfig:{...n.triggerConfig,connector:r}}}default:return n}},async mapFromDtoListWithReportData(e,t){const n=new eb,r=this.mapFromDtoList(e),s=r.filter(c=>c.type===xn.REPORT_RUN),l=await n.enhanceTriggersWithReportData(s);return r.map(c=>{switch(c.type){case xn.REPORT_RUN:return l.find(d=>d.id===c.id)??c;case xn.CONNECTOR_RUN:{const d=t.definition;return{...c,triggerConfig:{...c.triggerConfig,connector:d}}}default:return c}})},mapToCreateRequest(e){return Zx.getMapper(e.type).mapToCreateRequest(e)},mapToUpdateRequest(e){return Zx.getMapper(e.type).mapToUpdateRequest(e)}};function Zee({children:e}){const[t,n]=p.useReducer(Bee,SO),{dataMart:r}=Hi(),{fetchAvailableConnectors:s}=ql();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 w=await Uc.getScheduledTriggers(b),C=await Ld.mapFromDtoListWithReportData(w,r);n({type:"FETCH_TRIGGERS_SUCCESS",payload:C})}catch(w){const C=w instanceof Error?w.message:"Failed to fetch scheduled triggers";n({type:"FETCH_TRIGGERS_ERROR",payload:C}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"ListError",label:C})}},[r,s]),c=p.useCallback(async(b,w)=>{n({type:"FETCH_TRIGGERS_START"});try{const E=(await Uc.getScheduledTriggers(b)).filter(T=>T.type===w),R=await Ld.mapFromDtoListWithReportData(E,r);n({type:"FETCH_TRIGGERS_SUCCESS",payload:R})}catch(C){const E=C instanceof Error?C.message:"Failed to fetch scheduled triggers";n({type:"FETCH_TRIGGERS_ERROR",payload:E}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"ListError",label:E})}},[r]),d=p.useCallback(async(b,w)=>{n({type:"FETCH_TRIGGER_START"});try{const C=await Uc.getScheduledTrigger(b,w),E=await Ld.mapFromDtoWithReportData(C,r);n({type:"FETCH_TRIGGER_SUCCESS",payload:E})}catch(C){const E=C instanceof Error?C.message:"Failed to fetch scheduled trigger";n({type:"FETCH_TRIGGER_ERROR",payload:E}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"GetError",label:E})}},[r]),h=p.useCallback(async(b,w,C,E,R,T)=>{n({type:"CREATE_TRIGGER_START"});try{const j={type:w,cronExpression:C,timeZone:E,isActive:R,triggerConfig:T},O=await Uc.createScheduledTrigger(b,j),D=await Ld.mapFromDtoWithReportData(O,r);return n({type:"CREATE_TRIGGER_SUCCESS",payload:D}),Fe({event:"scheduled_trigger_created",category:"ScheduledTrigger",action:"Create",label:w}),an.success("Trigger created"),D}catch(j){const O=j instanceof Error?j.message:"Failed to create scheduled trigger";throw n({type:"CREATE_TRIGGER_ERROR",payload:O}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"CreateError",label:O}),j}},[r]),m=p.useCallback(async(b,w,C,E,R)=>{n({type:"UPDATE_TRIGGER_START"});try{const T={cronExpression:C,timeZone:E,isActive:R},j=await Uc.updateScheduledTrigger(b,w,T),O=await Ld.mapFromDtoWithReportData(j,r);n({type:"UPDATE_TRIGGER_SUCCESS",payload:O}),Fe({event:"scheduled_trigger_updated",category:"ScheduledTrigger",action:"Update",label:O.type}),an.success("Trigger updated")}catch(T){const j=T instanceof Error?T.message:"Failed to update scheduled trigger";throw n({type:"UPDATE_TRIGGER_ERROR",payload:j}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"UpdateError",label:j}),T}},[r]),g=p.useCallback(async(b,w)=>{n({type:"DELETE_TRIGGER_START"});try{await Uc.deleteScheduledTrigger(b,w),n({type:"DELETE_TRIGGER_SUCCESS",payload:w}),Fe({event:"scheduled_trigger_deleted",category:"ScheduledTrigger",action:"Delete",label:w}),an.success("Trigger deleted")}catch(C){const E=C instanceof Error?C.message:"Failed to delete scheduled trigger";throw n({type:"DELETE_TRIGGER_ERROR",payload:E}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"DeleteError",label:E}),C}},[]),v=p.useCallback(b=>{n({type:"SELECT_TRIGGER",payload:b})},[]),x=p.useCallback(()=>{n({type:"RESET"})},[]);return o.jsx(bO.Provider,{value:{...t,getScheduledTriggers:l,getScheduledTriggersByType:c,getScheduledTrigger:d,createScheduledTrigger:h,updateScheduledTrigger:m,deleteScheduledTrigger:g,selectScheduledTrigger:v,reset:x},children:e})}function CO(){const e=p.useContext(bO);if(e===void 0)throw new Error("useScheduledTriggerContext must be used within a ScheduledTriggerProvider");return e}function Kee(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}=CO();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,w)=>n(b,w),getScheduledTrigger:(b,w)=>r(b,w),createScheduledTrigger:(b,w,C,E,R,T)=>s(b,w,C,E,R,T),updateScheduledTrigger:(b,w,C,E,R)=>l(b,w,C,E,R),deleteScheduledTrigger:(b,w)=>c(b,w),selectScheduledTrigger:d}}const Yee=sn({type:qs(Kc.SCHEDULED_REPORT_RUN),reportId:on().min(1,"Report ID is required")}),Wee=mB(),Qee=sn({type:c1(xn),cronExpression:on().min(1,"Cron expression is required"),timeZone:on().min(1,"Time zone is required"),isActive:hB(),triggerConfig:gB([Yee,Wee])});function Xee({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:r}){const s=$i({resolver:Wl(Qee),defaultValues:{type:e?e.type:n??xn.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:Kc.SCHEDULED_REPORT_RUN,reportId:t??""}}});p.useEffect(()=>{t&&s.getValues("type")===xn.REPORT_RUN&&s.setValue("triggerConfig",{type:Kc.SCHEDULED_REPORT_RUN,reportId:t})},[t,s]),p.useEffect(()=>{n&&(s.setValue("type",n),n===xn.REPORT_RUN?s.setValue("triggerConfig",{type:Kc.SCHEDULED_REPORT_RUN,reportId:t??""}):s.setValue("triggerConfig",null))},[n,t,s]);const l=d=>{s.setValue("type",d),d===xn.REPORT_RUN?s.setValue("triggerConfig",{type:Kc.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 Jee({value:e,onChange:t,disabled:n}){const{reports:r,fetchReportsByDataMartId:s}=Gl(),{dataMart:l}=Hi();p.useEffect(()=>{l&&s(l.id)},[s,l]);const c=r.filter(d=>d.dataDestination.type===Lt.GOOGLE_SHEETS);return o.jsxs(Sa,{value:e,onValueChange:t,disabled:n,children:[o.jsx(wa,{className:"w-full",children:o.jsx(Ca,{placeholder:"Select a report"})}),o.jsx(Ea,{children:c.map(d=>o.jsx(qn,{value:d.id,children:d.title},d.id))})]})}var Ug="Switch",[ete]=kr(Ug),[tte,nte]=ete(Ug),wO=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),w=vt(t,j=>b(j)),C=p.useRef(!1),E=x?g||!!x.closest("form"):!0,[R,T]=zr({prop:s,defaultProp:l??!1,onChange:m,caller:Ug});return o.jsxs(tte,{scope:n,checked:R,disabled:d,children:[o.jsx(Ke.button,{type:"button",role:"switch","aria-checked":R,"aria-required":c,"data-state":jO(R),"data-disabled":d?"":void 0,disabled:d,value:h,...v,ref:w,onClick:Te(e.onClick,j=>{T(O=>!O),E&&(C.current=j.isPropagationStopped(),C.current||j.stopPropagation())})}),E&&o.jsx(TO,{control:x,bubbles:!C.current,name:r,value:h,checked:R,required:c,disabled:d,form:g,style:{transform:"translateX(-100%)"}})]})});wO.displayName=Ug;var EO="SwitchThumb",RO=p.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,s=nte(EO,n);return o.jsx(Ke.span,{"data-state":jO(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:t})});RO.displayName=EO;var rte="SwitchBubbleInput",TO=p.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...s},l)=>{const c=p.useRef(null),d=vt(c,l),h=$1(n),m=Ub(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 w=new Event("click",{bubbles:r});b.call(g,n),g.dispatchEvent(w)}},[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}})});TO.displayName=rte;function jO(e){return e?"checked":"unchecked"}var ate=wO,ste=RO;function _O({className:e,...t}){return o.jsx(ate,{"data-slot":"switch",className:J("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(ste,{"data-slot":"switch-thumb",className:J("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 ote(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 tb(e,t="UTC"){const n=ote(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 NO({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,w)=>b-w);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(Ar,{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(su,{className:"h-2 w-2"})})]},x.value))}):o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsxs(Ar,{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(su,{className:"h-2 w-2"})})]}),v.length>1&&o.jsxs(Ar,{variant:"outline",className:"h-5 text-xs",children:["+",v.length-1]})]})};return o.jsxs(Y1,{open:c,onOpenChange:d,modal:!0,children:[o.jsx(W1,{asChild:!0,children:o.jsxs(Ce,{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(Sb,{className:"ml-2 h-3 w-3 shrink-0 opacity-50"})]})}),o.jsx(Q1,{className:"max-h-[400px] w-full overflow-y-auto p-0",style:{padding:0},children:o.jsxs(jD,{className:"h-full overflow-visible",children:[o.jsx(_D,{placeholder:s,className:"h-8"}),o.jsxs(sJ,{className:"h-full max-h-[350px] overflow-y-auto",children:[o.jsx(ND,{children:"No items found."}),o.jsx(AD,{className:"h-full overflow-visible",children:e.map(v=>o.jsxs(DD,{value:v.value.toString(),onSelect:()=>h(v.value),className:"text-sm",children:[o.jsx(dr,{className:J("mr-2 h-3 w-3",t.includes(v.value)?"opacity-100":"opacity-0")}),v.label]},v.value))})]})]})})]})}const AO=[{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"}],Om=()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}};function DO(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=AO.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 ite(e,t,n=!0){const r=tb(e,t);return DO(r,n)}const lte=Array.from({length:31},(e,t)=>({value:t+1,label:`${String(t+1)}${t===0?"st":t===1?"nd":t===2?"rd":"th"}`})),nb=[5,10,15,30],rb=[1,2,3,4,6,8,12],cte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(ba,{children:"Type"}),o.jsxs(Sa,{value:e,onValueChange:r=>{t(r)},disabled:n,children:[o.jsx(wa,{className:"w-full",children:o.jsx(Ca,{})}),o.jsxs(Ea,{children:[o.jsx(qn,{value:"daily",children:"Daily"}),o.jsx(qn,{value:"weekly",children:"Weekly"}),o.jsx(qn,{value:"monthly",children:"Monthly"}),o.jsx(qn,{value:"interval",children:"Interval"})]})]})]}),ute=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(ba,{children:"Time"}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx($t,{className:"w-24",type:"time",value:e,onChange:r=>{t(r.target.value)},disabled:n})})]}),BT=({value:e,onChange:t,disabled:n,timezones:r})=>o.jsxs("div",{className:"w-full space-y-2",children:[o.jsx(ba,{children:"Timezone"}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx(X1,{options:r,value:e,onValueChange:t,placeholder:"Select timezone",emptyMessage:"No timezones found",disabled:n,className:"w-full"})})]}),dte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(ba,{children:"Days of Week"}),o.jsx("div",{className:n?"pointer-events-none":"",children:o.jsx(NO,{options:AO,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:3})})]}),fte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(ba,{children:"Days of Month"}),o.jsx("div",{className:n?"pointer-events-none":"",children:o.jsx(NO,{options:lte,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:4})})]}),hte=({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(ba,{children:"Type"}),o.jsxs(Sa,{value:e,onValueChange:l=>{n(l)},disabled:s,children:[o.jsx(wa,{className:"w-full",children:o.jsx(Ca,{})}),o.jsxs(Ea,{children:[o.jsx(qn,{value:"minutes",children:"Minutes"}),o.jsx(qn,{value:"hours",children:"Hours"})]})]})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(ba,{children:"Every"}),o.jsxs(Sa,{value:t.toString(),onValueChange:l=>{r(Number.parseInt(l)||1)},disabled:s,children:[o.jsx(wa,{className:"w-full",children:o.jsx(Ca,{})}),o.jsx(Ea,{children:(e==="minutes"?nb:rb).map(l=>o.jsxs(qn,{value:l.toString(),children:[l," ",e==="minutes"?"min":"hr"]},l))})]})]})]}),mte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-1",children:[o.jsx(ba,{className:"text-sm",children:"Cron Expression"}),o.jsx($t,{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 pte({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??Om()),[v,x]=p.useState(!1),b=p.useMemo(()=>FG.getTimezonesWithOffset().map(H=>({value:H.identifier,label:H.displayName,offset:H.offsetString,isDST:H.isDST})),[]),[w,C]=p.useState(()=>tb(e,m)),[E,R]=p.useState(""),[T,j]=p.useState("");p.useEffect(()=>{h(n)},[n]),p.useEffect(()=>{const H=t??Om();g(H)},[t]),p.useEffect(()=>{if(e){const H=tb(e,m);C(H)}},[e,m]);const O=H=>{const[$,I]=H.time.split(":").map(Number);switch(H.type){case"daily":return`${String(I)} ${String($)} * * *`;case"weekly":return`${String(I)} ${String($)} * * ${H.weekdays.join(",")}`;case"monthly":return`${String(I)} ${String($)} ${H.monthDays.join(",")} * *`;case"interval":return H.intervalType==="minutes"?`*/${String(H.intervalValue)} * * * *`:`0 */${String(H.intervalValue)} * * *`;case"custom":return H.customCron;default:return`${String(I)} ${String($)} * * *`}},D=p.useCallback(H=>{C($=>{if($.intervalType===H)return console.log("Type unchanged, skipping update"),$;const Y=(H==="minutes"?nb:rb)[0];return{...$,intervalType:H,intervalValue:Y}})},[]),_=p.useCallback(H=>{C($=>($.intervalType==="minutes"?nb:rb).includes(H)?{...$,intervalValue:H}:$)},[]),A=p.useMemo(()=>H=>DO(H,d),[d]);p.useEffect(()=>{const H=O(w);R(H),j(A(w))},[w,d,m,A]);const M=p.useRef(""),U=p.useRef(""),B=p.useRef(!1);p.useEffect(()=>{const H=O(w);r&&(M.current!==H||U.current!==m||B.current!==d)&&(r({cron:H,timezone:m,enabled:d}),M.current=H,U.current=m,B.current=d)},[w,m,d,r]);const G=H=>{h(H)},K=H=>{g(H),C($=>({...$,timezone:H}))},re=["daily","weekly","monthly"].includes(w.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(ba,{htmlFor:"schedule-enabled",className:"text-sm font-normal",children:d?"Enabled":"Disabled"}),o.jsx(_O,{id:"schedule-enabled",checked:d,onCheckedChange:G})]})]})}),o.jsxs("div",{className:"space-y-4 pt-0",children:[o.jsxs("div",{className:`space-y-4 ${d?"":"opacity-50"}`,children:[o.jsx(cte,{value:w.type,onChange:H=>{C($=>({...$,type:H}))},disabled:!d}),w.type!=="custom"&&w.type!=="interval"&&o.jsxs("div",{className:"flex gap-3",children:[o.jsx(ute,{value:w.time,onChange:H=>{C($=>({...$,time:H}))},disabled:!d}),re&&o.jsx(BT,{value:m,onChange:K,disabled:!d,timezones:b})]}),(w.type==="interval"||w.type==="custom")&&o.jsx(BT,{value:m,onChange:K,disabled:!d,timezones:b}),w.type==="weekly"&&o.jsx(dte,{value:w.weekdays,onChange:H=>{C($=>({...$,weekdays:H}))},disabled:!d}),w.type==="monthly"&&o.jsx(fte,{value:w.monthDays,onChange:H=>{C($=>({...$,monthDays:H}))},disabled:!d}),w.type==="interval"&&o.jsx(hte,{intervalType:w.intervalType,intervalValue:w.intervalValue,onTypeChange:D,onValueChange:_,disabled:!d}),w.type==="custom"&&o.jsx(mte,{value:w.customCron,onChange:H=>{C($=>({...$,customCron:H}))},disabled:!d})]}),l&&o.jsxs(o.Fragment,{children:[o.jsx(d_,{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(Wj,{className:"h-4 w-4"}),o.jsx("span",{className:"text-sm font-medium",children:"Preview"})]}),v?o.jsx(Us,{className:"text-muted-foreground h-4 w-4"}):o.jsx(Za,{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(Ar,{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(Ar,{variant:"secondary",className:"font-mono text-xs",children:E})]}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Timezone:"}),o.jsx(Ar,{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&&re&&m!==Om()&&o.jsxs(cS,{className:"border-amber-200 bg-amber-50",children:[o.jsx(Sf,{className:"h-4 w-4"}),o.jsx(iO,{children:"Time Zone"}),o.jsxs(uS,{children:["Schedule runs in ",m," (not your local ",Om()," ","time). Execution time may differ from expected."]})]})]})]})]}),c&&o.jsx(Ce,{className:"w-full",disabled:!d,children:"Save Schedule"})]})]})}function gte(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"trigger-type-options-description-details",children:[o.jsx(Yn,{children:"How do I choose a type?"}),o.jsxs(Wn,{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 vte(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"trigger-type-change-description-details",children:[o.jsx(Yn,{children:"How do I change the trigger type?"}),o.jsx(Wn,{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 yte(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"report-change-description-details",children:[o.jsx(Yn,{children:"How do I change a report?"}),o.jsx(Wn,{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 xte(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"report-select-description-details",children:[o.jsx(Yn,{children:"How do I choose the report?"}),o.jsxs(Wn,{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 bte({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}=Xee({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:async E=>{d(!0);try{await r(E)}finally{d(!1)}}});p.useEffect(()=>{l==null||l(v)},[v,l]);const{control:x,watch:b}=h,C=b("type")===xn.REPORT_RUN;return o.jsx(Zl,{...h,children:o.jsxs(Bi,{onSubmit:E=>void g(E),noValidate:!1,children:[o.jsxs(Kl,{children:[o.jsx(Qt,{control:x,name:"type",render:({field:E})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Choose what you want this trigger to run - a report or a connector",children:"Trigger Type"}),o.jsxs(Sa,{onValueChange:R=>{E.onChange(R),m(R)},defaultValue:E.value,disabled:!!n||!!e||!!b("triggerConfig.reportId"),children:[o.jsx(en,{children:o.jsx(wa,{className:"w-full",children:o.jsx(Ca,{placeholder:"Select trigger type"})})}),o.jsxs(Ea,{children:[o.jsx(qn,{value:xn.REPORT_RUN,children:"Report Run"}),o.jsx(qn,{value:xn.CONNECTOR_RUN,children:"Connector Run"})]})]}),o.jsx(ar,{children:e?o.jsx(vte,{}):o.jsx(gte,{})}),o.jsx(ln,{})]})}),C&&o.jsx(Qt,{control:x,name:"triggerConfig.reportId",render:({field:E})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Select the report that will be run by this trigger",children:"Report"}),o.jsx(en,{children:o.jsx(E4,{children:o.jsx(Jee,{value:E.value,onChange:E.onChange,disabled:!!t||!!e})})}),o.jsx(ar,{children:e!=null&&e.triggerConfig?o.jsx(yte,{}):o.jsx(xte,{})}),o.jsx(ln,{})]})}),o.jsx(pte,{showPreview:!1,cron:b("cronExpression"),timezone:b("timeZone"),enabled:b("isActive"),onChange:E=>{h.setValue("cronExpression",E.cron,{shouldDirty:!0}),h.setValue("timeZone",E.timezone,{shouldDirty:!0}),h.setValue("isActive",E.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(Yl,{children:[o.jsx(Ce,{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(Ce,{variant:"outline",type:"button",onClick:s,className:"w-full","aria-label":"Cancel",children:"Cancel"})]})]})})}function Ste({cronExpression:e,timeZone:t,isEnabled:n=!0}){const r=p.useMemo(()=>ite(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 Cte({table:e}){return o.jsx("div",{className:"text-right",children:o.jsxs(Cr,{children:[o.jsx(wr,{asChild:!0,children:o.jsx(Ce,{variant:"ghost",className:"dm-card-table-body-row-actionbtn","aria-label":"Toggle columns",children:o.jsx(Ka,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsx(Er,{align:"end",children:e.getAllColumns().filter(t=>t.getCanHide()&&t.id!=="actions").map(t=>o.jsx(bt,{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(dr,{className:"size-3.5 text-white"})})}),o.jsx("span",{children:t.columnDef.meta.title??t.id})]})},t.id))})]})})}function wte({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(Cr,{open:r,onOpenChange:s,children:[o.jsx(wr,{asChild:!0,children:o.jsx(Ce,{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(Ka,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsxs(Er,{align:"end",children:[o.jsxs(bt,{onClick:()=>{t(e.id)},children:[o.jsx(Cf,{className:"text-foreground h-4 w-4","aria-hidden":"true"}),"Edit trigger"]}),o.jsx(Ga,{}),o.jsxs(bt,{onClick:()=>{c(!0)},children:[o.jsx(ko,{className:"h-4 w-4 text-red-600","aria-hidden":"true"}),o.jsx("span",{className:"text-red-600",children:"Delete trigger"})]})]})]}),o.jsx(xa,{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 Ete(e,t){const n=t.find(r=>r.name===e.source.name);return(n==null?void 0:n.displayName)??e.source.name}function Rte({connector:e}){const{connectors:t}=ql(),n=Ete(e,t);return o.jsx(o.Fragment,{children:n})}function OO({connector:e}){return o.jsx(Rte,{connector:e})}function Tte(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 jte=e=>{const{connectors:t}=ql();return p.useMemo(()=>t.find(n=>n.name===e),[t,e])},_te=je.memo(function({connector:t,children:n}){const r=jte(t.source.name),{dataMart:s,runs:l,getDataMartRuns:c}=Hi();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(Ff,{base64:r.logoBase64,size:20}):null,[r==null?void 0:r.logoBase64]),h=p.useCallback(()=>{s!=null&&s.storage&&gq(s.storage,t.storage.fullyQualifiedName)},[s==null?void 0:s.storage,t.storage.fullyQualifiedName]),m=p.useMemo(()=>Tte(l),[l]),g=p.useMemo(()=>!m.lastRunDate||!m.lastRunStatus?null:{statusType:OZ(m.lastRunStatus),statusText:kZ(m.lastRunStatus),date:m.lastRunDate},[m]),v=p.useMemo(()=>(s==null?void 0:s.storage)&&vq(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(g1,{children:[o.jsx(v1,{asChild:!0,children:o.jsx("span",{children:n})}),o.jsxs(y1,{children:[o.jsxs(x1,{children:[o.jsx(b1,{children:d}),o.jsxs(S1,{children:[o.jsx(C1,{children:o.jsx(OO,{connector:t})}),o.jsx(w1,{children:x})]})]}),o.jsxs(E1,{children:[o.jsxs(gi,{children:[o.jsx(vi,{children:"Last run status:"}),o.jsx(yi,{children:g?o.jsx(Vf,{type:g.statusType,variant:"ghost",children:g.statusText}):"Not run yet"})]}),o.jsxs(gi,{children:[o.jsx(vi,{children:"Last run date:"}),o.jsx(yi,{children:g?o.jsx(kl,{date:g.date}):"Never run"})]}),o.jsxs(gi,{children:[o.jsx(vi,{children:"Total runs:"}),o.jsxs(yi,{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(R1,{children:o.jsxs(Ce,{className:"w-full",variant:"default",onClick:h,title:"Open Storage","aria-label":"Open Storage",children:[v,o.jsx(Tl,{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 Nte(e){const t=e.triggerConfig;return o.jsxs("div",{className:"inline gap-1",children:[t.report.title,o.jsx(AZ,{report:t.report,children:o.jsx(Fr,{className:"ml-1 inline-block h-4 w-4 align-text-bottom opacity-0 transition-opacity duration-200 group-hover:opacity-100"})})]})}function Ate(e){const t=e.triggerConfig,{connector:n}=t.connector;return o.jsxs("div",{className:"inline gap-1",children:[o.jsx(OO,{connector:n}),o.jsx(_te,{connector:n,children:o.jsx(Fr,{className:"ml-1 inline-block h-4 w-4 align-text-bottom opacity-0 transition-opacity duration-200 group-hover:opacity-100"})})]})}function Dte({trigger:e}){switch(e.type){case xn.REPORT_RUN:return Nte(e);case xn.CONNECTOR_RUN:return Ate(e);default:return o.jsx("div",{className:"text-muted-foreground text-sm",children:"—"})}}function Ote({onEditTrigger:e,onDeleteTrigger:t}){return[{accessorKey:"type",size:150,header:"Trigger Type",cell:({row:n})=>{const s=n.getValue("type")===xn.REPORT_RUN?"Report Run":"Connector Run";return o.jsx(Ar,{variant:"outline",children:s})},meta:{title:"Trigger Type"}},{accessorKey:"triggerConfig",size:35,header:"Run Target",cell:({row:n})=>o.jsx(Dte,{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(Ste,{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(kl,{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(kl,{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(Vf,{type:r?Tn.SUCCESS:Tn.NEUTRAL,variant:"ghost",showIcon:!1,children:r?"Enabled":"Disabled"})},meta:{title:"Trigger Status"}},{id:"actions",size:80,header:({table:n})=>o.jsx(Cte,{table:n}),cell:({row:n})=>o.jsx(wte,{trigger:n.original,onEditTrigger:e,onDeleteTrigger:t}),meta:{title:"Actions"}}]}function Mte({table:e,onPreviousClick:t,onNextClick:n}){return o.jsxs("div",{className:"dm-card-pagination",role:"navigation","aria-label":"Table pagination",children:[o.jsx(Ce,{variant:"outline",size:"sm",onClick:t,disabled:!e.getCanPreviousPage(),"aria-label":"Go to previous page",children:"Previous"}),o.jsx(Ce,{variant:"outline",size:"sm",onClick:n,disabled:!e.getCanNextPage(),"aria-label":"Go to next page",children:"Next"})]})}function hS({isOpen:e,onClose:t,dataMartId:n,preSelectedReportId:r,preSelectedType:s}){const{createScheduledTrigger:l,updateScheduledTrigger:c,selectedTrigger:d}=CO(),[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]),w=p.useCallback(O=>{v(O)},[]),C=p.useCallback(()=>{v(!1),t()},[t]),E=!!d,R=p.useMemo(()=>d?{type:d.type,cronExpression:d.cronExpression,timeZone:d.timeZone,isActive:d.isActive,triggerConfig:d.type===xn.REPORT_RUN?{type:Kc.SCHEDULED_REPORT_RUN,reportId:d.triggerConfig.reportId}:null}:void 0,[d]),T=async O=>{E?await c(n,d.id,O.cronExpression,O.timeZone,O.isActive):await l(n,O.type,O.cronExpression,O.timeZone,O.isActive,O.triggerConfig),C()},j=p.useRef(!1);return p.useEffect(()=>{const O=E?"Edit":"Create",D=(d==null?void 0:d.type)??s;e&&!j.current?(Fe({event:"scheduled_trigger_config_open",category:"ScheduledTrigger",action:O,label:D}),j.current=!0):!e&&j.current&&(Fe({event:"scheduled_trigger_config_close",category:"ScheduledTrigger",action:O,label:D}),j.current=!1)},[e,E,d,s]),o.jsxs(o.Fragment,{children:[o.jsx(Mi,{open:e,onOpenChange:O=>{O||x()},children:o.jsxs(ki,{children:[o.jsxs(Ii,{children:[o.jsxs(Li,{children:[E?"Edit":"Create"," Scheduled Trigger"]}),o.jsx(Hl,{children:"Configure automatic runs for your reports or connectors."})]}),o.jsx(bte,{preSelectedReportId:r,preSelectedType:s,initialData:R,onSubmit:T,onCancel:x,onDirtyChange:w})]})}),o.jsx(xa,{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 kte({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(()=>Ote({onEditTrigger:n,onDeleteTrigger:d}),[n,d]),{sorting:m,setSorting:g,columnVisibility:v,setColumnVisibility:x}=Bf({columns:h,storageKeyPrefix:"data-mart-scheduled-triggers",defaultSortingColumn:"type"}),b=Tu({data:e,columns:h,getCoreRowModel:Ru(),getPaginationRowModel:Eg(),onSortingChange:g,getSortedRowModel:$f(),getFilteredRowModel:Hf(),state:{sorting:m,columnVisibility:v},onColumnVisibilityChange:x,enableGlobalFilter:!0,enableColumnResizing:!1}),w=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(ju,{id:"scheduled-triggers-table",className:"dm-card-table",role:"table","aria-label":"Scheduled Triggers",children:[o.jsx(_u,{className:"dm-card-table-header",children:b.getHeaderGroups().map(R=>o.jsx(sr,{className:"dm-card-table-header-row",children:R.headers.map(T=>o.jsx(Au,{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(Nu,{className:"dm-card-table-body",children:b.getRowModel().rows.length?b.getRowModel().rows.map((R,T)=>o.jsx(sr,{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(ya,{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(sr,{children:o.jsx(ya,{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(Mte,{table:b,onPreviousClick:w,onNextClick:C}),o.jsx(hS,{isOpen:s,onClose:c,dataMartId:t})]})}function Ite({dataMartId:e}){const{triggers:t,deleteScheduledTrigger:n,selectScheduledTrigger:r,selectedTrigger:s}=Kee(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(kte,{triggers:t,dataMartId:e,onEditTrigger:d,onDeleteTrigger:g=>void m(g)}),o.jsx(hS,{isOpen:l,onClose:h,dataMartId:e})]})}function MO(){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(Xj,{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:["Set up automatic runs in the ",o.jsx("span",{className:"font-medium",children:"Triggers"})," tab once you’ve saved and published this Data Mart."]})]})]})})}function Lte({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,w]=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",E=p.useCallback((j,O,D,_)=>{s({fullyQualifiedName:`${j}.${O}`,isValid:!!(j&&O&&D===null&&_===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),_=C(O);h(j),g(O),x(D),w(_);const A=`${j}.${O}`,M=!!(j&&O&&D===null&&_===null);((t==null?void 0:t.fullyQualifiedName)!==A||t.isValid!==M)&&E(j,O,D,_)},[t,l,c,E]);const R=j=>{h(j);const O=C(j);x(O),E(j,m,O,b)},T=j=>{g(j);const O=C(j);w(O),E(d,j,v,O)};return o.jsxs(Ro,{children:[e===Pe.GOOGLE_BIGQUERY&&o.jsxs(o.Fragment,{children:[o.jsx(Di,{icon:o.jsx(VA,{}),title:"Google BigQuery",docUrl:"https://docs.owox.com/docs/storages/supported-storages/google-bigquery/",variant:"compact"}),o.jsxs(wl,{title:"Choose where to store your data",children:[o.jsxs($d,{children:[o.jsx(wo,{required:!0,htmlFor:"dataset-name",tooltip:"Enter dataset name for Google BigQuery where the connector data will be stored.",children:"Dataset name"}),o.jsx($t,{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}),o.jsx("p",{className:"text-muted-foreground text-sm",children:"Dataset is auto-created on first run if it doesn’t exist"}),v&&o.jsx("p",{id:"dataset-name-error",className:"text-destructive text-sm",children:v})]}),o.jsxs($d,{children:[o.jsx(wo,{required:!0,htmlFor:"table-name",tooltip:"Enter table name where the connector data will be stored.",children:"Table name"}),o.jsx($t,{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}),o.jsx("p",{className:"text-muted-foreground text-sm",children:"Table is auto-created on first run if it doesn’t exist"}),b&&o.jsx("p",{id:"table-name-error",className:"text-destructive text-sm",children:b})]})]})]}),e===Pe.AWS_ATHENA&&o.jsxs(o.Fragment,{children:[o.jsx(Di,{icon:o.jsx(HA,{}),title:"AWS Athena",docUrl:"https://docs.owox.com/docs/storages/supported-storages/aws-athena/",variant:"compact"}),o.jsxs(wl,{title:"Choose where to store your data",children:[o.jsxs($d,{children:[o.jsx(wo,{required:!0,htmlFor:"database-name",tooltip:"Enter database name for Amazon Athena where the connector data will be stored.",children:"Database name"}),o.jsx($t,{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}),o.jsx("p",{className:"text-muted-foreground text-sm",children:"Database is auto-created on first run if it doesn’t exist"}),v&&o.jsx("p",{id:"database-name-error",className:"text-destructive text-sm",children:v})]}),o.jsxs($d,{children:[o.jsx(wo,{required:!0,htmlFor:"athena-table-name",tooltip:"Enter table name where the connector data will be stored.",children:"Table name"}),o.jsx($t,{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}),o.jsx("p",{className:"text-muted-foreground text-sm",children:"Table is auto-created on first run if it doesn’t exist"}),b&&o.jsx("p",{id:"athena-table-name-error",className:"text-destructive text-sm",children:b})]})]})]}),o.jsx(wl,{title:"Schedule updates",children:o.jsx(MO,{})})]})}function Pte({onSubmit:e,dataStorageType:t,configurationOnly:n=!1,existingConnector:r=null,mode:s="full",initialStep:l,preselectedConnector:c}){const[d,h]=p.useState(null),[m,g]=p.useState(""),[v,x]=p.useState([]),[b,w]=p.useState(1),[C,E]=p.useState({}),[R,T]=p.useState(!1),[j,O]=p.useState(new Set),[D,_]=p.useState(new Set),{connectors:A,connectorSpecification:M,connectorFields:U,loading:B,loadingSpecification:G,loadingFields:K,error:re,fetchAvailableConnectors:H,fetchConnectorSpecification:$,fetchConnectorFields:I}=ql(),[Y,Z]=p.useState(null),be=(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,L=p.useCallback(async Ie=>{!j.has(Ie)&&!G&&(O(wt=>new Set(wt).add(Ie)),await $(Ie))},[j,G,$]),P=p.useCallback(async Ie=>{D.has(Ie)||(_(wt=>new Set(wt).add(Ie)),await I(Ie))},[D,I]);p.useEffect(()=>{if(!c||d||A.length===0)return;const Ie=A.find(wt=>wt.name===c);Ie&&(h(Ie),w(l??2),L(Ie.name),!n&&s!=="fields-only"&&P(Ie.name))},[c,A,d,l,n,s,L,P]),p.useEffect(()=>{if(A.length===0&&!B&&H(),r&&A.length>0&&!d){const{source:Ie,storage:wt}=r;g(Ie.node),x(Ie.fields),E(Ie.configuration[0]||{}),Z({fullyQualifiedName:wt.fullyQualifiedName,isValid:!0});const Ot=A.find(tn=>tn.name===Ie.name);Ot&&(h(Ot),L(Ot.name),!n&&s!=="fields-only"&&P(Ot.name),s==="fields-only"&&P(Ot.name))}if(n&&A.length>0&&!d&&!r){const Ie=A[0];h(Ie),L(Ie.name)}},[s,r,A,n,B,H,L,P,d]);const W=Ie=>{h(Ie),E({}),T(!1),O(wt=>{const Ot=new Set(wt);return Ot.delete(Ie.name),Ot}),L(Ie.name),P(Ie.name)},ae=Ie=>{g(Ie),x([])},fe=(Ie,wt)=>{x(wt?Ot=>Ot.includes(Ie)?Ot:[...Ot,Ie]:Ot=>Ot.filter(tn=>tn!==Ie))},ge=(Ie,wt)=>{x(wt?Ot=>{const tn=Ie.filter(V=>!Ot.includes(V));return[...Ot,...tn]}:Ot=>Ot.filter(tn=>!Ie.includes(tn)))},ue=Ie=>{Z(Ie)},Ne=p.useCallback(Ie=>{E(Ie)},[]),Re=p.useCallback(Ie=>{T(Ie)},[]);p.useEffect(()=>{M&&(M.some(wt=>wt.required&&wt.name!=="Fields")||T(!0))},[M]);const xe=()=>{b<be&&w(b+1)},et=()=>{b>1&&w(b-1)},Xe=()=>{if(n)return d!==null&&R;if(s==="fields-only")switch(b){case 1:return v.length>0;default:return!1}switch(b){case 1:return d!==null;case 2:return R;case 3:return m!=="";case 4:return v.length>0;case 5:return Y!==null&&Y.fullyQualifiedName!==""&&Y.isValid;default:return!1}},Bt=()=>b>1,ft=(Ie,wt)=>{if(!Ie)return wt;const Ot=Ie.find(tn=>tn.name===wt);return(Ot==null?void 0:Ot.destinationName)??wt},gn=()=>{if(n&&b===1)return M&&d?o.jsx(HT,{connector:d,connectorSpecification:M,onConfigurationChange:Ne,onValidationChange:Re,initialConfiguration:C,loading:G,isEditingExisting:!!(r!=null&&r.source.configuration.length)}):null;if(s==="fields-only")switch(b){case 1:return d&&m&&U?o.jsx($T,{connector:d,connectorFields:U,selectedField:m,selectedFields:v,onFieldToggle:fe,onSelectAllFields:ge}):null;default:return null}switch(b){case 1:return o.jsx(Aee,{connectors:A,selectedConnector:d,loading:B,error:re,onConnectorSelect:W,onConnectorDoubleClick:()=>{w(Ie=>Ie<be?Ie+1:Ie)}});case 2:return d&&M?o.jsx(HT,{connector:d,connectorSpecification:M,onConfigurationChange:Ne,onValidationChange:Re,initialConfiguration:C,loading:G,isEditingExisting:!1}):null;case 3:return d&&U?o.jsx($ee,{connectorFields:U,connector:d,selectedField:m,connectorName:d.displayName,loading:K,onFieldSelect:ae}):null;case 4:return d&&m&&U?o.jsx($T,{connector:d,connectorFields:U,selectedField:m,selectedFields:v,onFieldToggle:fe,onSelectAllFields:ge}):null;case 5:return m&&U?o.jsx(Lte,{dataStorageType:t,destinationName:ft(U,m),connectorName:(d==null?void 0:d.displayName)??"",target:Y,onTargetChange:ue}):null;default:return null}};return o.jsxs(wee,{children:[o.jsx(Eee,{children:gn()}),o.jsx(Ree,{variant:"horizontal",children:o.jsx(Dee,{currentStep:b,totalSteps:be,canGoNext:Xe(),canGoBack:Bt(),isLoading:G||K,onNext:xe,onBack:et,onFinish:()=>{n&&d?e({source:{name:d.name,configuration:[C],node:(r==null?void 0:r.source.node)??m,fields:(r==null?void 0:r.source.fields)??v},storage:(r==null?void 0:r.storage)??{fullyQualifiedName:(r==null?void 0:r.storage.fullyQualifiedName)??""}}):s==="fields-only"&&r?e({source:{...r.source,fields:v},storage:r.storage}):d&&Y&&e({source:{name:d.name,configuration:[C],node:m,fields:v},storage:{fullyQualifiedName:Y.fullyQualifiedName}})}})})]})}const kO=20,IO=20;function LO({vertical:e,horizontal:t}){if(window.Intercom)try{const n={};n.vertical_padding=e,n.horizontal_padding=t,Object.keys(n).length>0&&window.Intercom("update",n)}catch(n){console.warn("Failed to update Intercom padding",n)}}function Ute(e=30,t=0){LO({vertical:IO+e,horizontal:kO+t})}function ab(){LO({vertical:IO,horizontal:kO})}function PO({isOpen:e,onClose:t,dataStorageType:n,onSubmit:r,configurationOnly:s=!1,existingConnector:l=null,mode:c="full",initialStep:d,preselectedConnector:h}){return p.useEffect(()=>(e?Ute(55):ab(),()=>{ab()}),[e]),o.jsx(Mi,{open:e,onOpenChange:t,children:o.jsxs(ki,{children:[o.jsxs(Ii,{children:[o.jsx(Li,{children:c==="fields-only"?"Connector Fields":l!=null&&l.source.name?"Edit Connector":"Set Up Connector"}),o.jsx(Hl,{children:c==="fields-only"?"Select fields for your Data Mart":l!=null&&l.source.name?"Update configuration":"Follow these steps to set it up"})]}),o.jsx(Pte,{onSubmit:m=>{r(m),t()},dataStorageType:n,configurationOnly:s||c==="configuration-only",existingConnector:l,mode:c,initialStep:d,preselectedConnector:h})]})})}const mS=({dataStorageType:e,onSubmit:t,children:n,configurationOnly:r=!1,existingConnector:s=null,preset:l,isOpen:c,onClose:d})=>{const[h,m]=p.useState(!1),[g,v]=p.useState(1),[x,b]=p.useState();p.useEffect(()=>{c!==void 0&&m(c)},[c]);const w=()=>{b(void 0),v(1),m(!0)},C=()=>{m(!1),d==null||d()};return p.useEffect(()=>{l&&(l==="connector"?(b(void 0),v(1),m(!0)):(b(l),v(2),m(!0)))},[l]),o.jsxs(o.Fragment,{children:[n&&o.jsx("div",{onClick:w,style:{cursor:"pointer"},children:n}),o.jsx(hu,{children:o.jsx(PO,{isOpen:h,onClose:C,dataStorageType:e,onSubmit:t,configurationOnly:r,existingConnector:s,initialStep:g,preselectedConnector:x})})]})};function Fte({storageType:e,onSetupConnector:t,preset:n,isOpen:r,onClose:s}){return o.jsx(mS,{dataStorageType:e,onSubmit:t,configurationOnly:!1,preset:n,isOpen:r,onClose:s,children:o.jsxs(Ce,{type:"button",variant:"outline",className:"flex h-24 w-full cursor-pointer items-center justify-center gap-2 border-0 shadow-none dark:border-transparent dark:bg-transparent dark:hover:bg-white/4",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(Eb,{className:"h-4 w-4",strokeWidth:2.25})}),o.jsx("span",{children:"Setup Connector"}),o.jsx(Ra,{className:"h-6 w-6"})]})})}const zte=e=>{switch(e){case Pe.GOOGLE_BIGQUERY:return"Google BigQuery";case Pe.AWS_ATHENA:return"AWS Athena";default:return e}},qc=e=>typeof e=="object"&&"connector"in e,Pd=e=>{if(!qc(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 Vte({configIndex:e,connectorDef:t,onRemoveConfiguration:n,onUpdateConfiguration:r,dataMartStatus:s,totalConfigurations:l,dataStorage:c}){const d=Vi.getInfo(c.type),{connectors:h,fetchAvailableConnectors:m}=ql();p.useEffect(()=>{m()},[m]);const g=C=>{const E=h.find(R=>R.name===C);if(E!=null&&E.logoBase64)return()=>o.jsx(Ff,{base64:E.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:"Data:"})," ",o.jsx("span",{className:"text-muted-foreground font-medium",children:C}),o.jsx("span",{className:"text-muted-foreground",children:"•"}),o.jsxs(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsxs("span",{className:"text-muted-foreground flex items-center gap-1 font-medium",children:[o.jsx("span",{children:"Edit config"}),o.jsx(Ra,{className:"h-3 w-3"})]})}),o.jsx(_t,{children:"Edit connector configuration"})]})]})},x=(C,E,R)=>o.jsxs("span",{children:[o.jsxs("span",{className:"text-muted-foreground/75",children:[C,":"]})," ",o.jsx(fr,{href:R,onClick:T=>{T.stopPropagation()},children:E})]}),b=()=>{switch(c.type){case Pe.GOOGLE_BIGQUERY:{const C=c.config.projectId,E=t.connector.storage.fullyQualifiedName,R=E.split(".")[0],T=E.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(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsx(Fr,{className:"h-4 w-4"})}),o.jsx(_t,{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,E=t.connector.storage.fullyQualifiedName,[R,T]=E.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(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsx(Fr,{className:"h-4 w-4"})}),o.jsx(_t,{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"}},w=()=>!(s===ur.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(mS,{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:zte(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(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsx(Ce,{type:"button",variant:"ghost",onClick:()=>{w()&&n(e)},disabled:!w(),children:o.jsx(ko,{className:"h-4 w-4"})})}),!w()&&o.jsx(_t,{children:"Cannot remove the last configuration in published pipeline"})]})})]})}function Hte({storageType:e,onAddConfiguration:t,existingConnector:n}){return o.jsx("div",{children:o.jsx(mS,{dataStorageType:e,onSubmit:r=>{const s=r.source.configuration[0]||{};t(s)},configurationOnly:!0,existingConnector:n?{source:{...n.source,configuration:[]},storage:n.storage}:void 0,children:o.jsxs(Ce,{type:"button",variant:"outline",className:"dm-card-table-add-field-btn cursor-pointer",children:[o.jsx(Ta,{className:"h-4 w-4"}),o.jsx("span",{children:"Configuration"})]})})})}function $te({control:e,storageType:t,preset:n,autoOpen:r=!1}){const{dataMart:s,runDataMart:l}=gs(),{setValue:c,getValues:d,trigger:h}=Du(),[m,g]=p.useState(!1),[v,x]=p.useState(!1);p.useEffect(()=>{r&&x(!0)},[r]);const b=()=>{setTimeout(()=>void h("definition"),0)},w=(s==null?void 0:s.status)??ur.DRAFT,C=A=>{const M=A.source,U=A.storage;c("definition",{connector:{source:M,storage:U}},{shouldDirty:!0,shouldTouch:!0}),b()},E=async A=>{if(s){if(s.status.code!==ur.PUBLISHED){Dt.error("Manual run is only available for published data marts");return}await l({id:s.id,payload:A})}},R=A=>M=>{const B=d().definition;if(typeof B=="object"&&qc(B)){const G=[...B.connector.source.configuration];G[A]=M.source.configuration[0]||{};const K={connector:{...B.connector,source:{...B.connector.source,configuration:G}}};c("definition",K,{shouldDirty:!0,shouldTouch:!0}),b()}},T=A=>{const U=d().definition;if(typeof U=="object"&&qc(U)){const B={connector:{...U.connector,source:{...U.connector.source,fields:A.source.fields}}};c("definition",B,{shouldDirty:!0,shouldTouch:!0}),b()}g(!1)},j=A=>{E({runType:A.runType,data:A.data})},O=A=>{const M=A.connector.source.fields.length;return o.jsxs(Ce,{type:"button",variant:"outline",onClick:()=>{g(!0)},className:"dm-card-table-add-field-btn cursor-pointer",children:[o.jsx(uL,{className:"h-4 w-4"}),o.jsxs("span",{children:["Edit Fields (",String(M),")"]})]})},D=A=>{const U=d().definition;if(qc(U)&&U.connector.source.configuration.length<=1){const B=X0(qe.CONNECTOR);c("definition",B,{shouldDirty:!0,shouldTouch:!0}),b()}if(typeof U=="object"&&qc(U)&&U.connector.source.configuration.length>1){const B={...U.connector.source,configuration:U.connector.source.configuration.filter((K,re)=>re!==A)},G={connector:{...U.connector,source:B}};c("definition",G,{shouldDirty:!0,shouldTouch:!0}),b()}},_=A=>{const U=d().definition;if(qc(U)){const B={...U.connector.source,configuration:[...U.connector.source.configuration,A]},G={connector:{...U.connector,source:B}};c("definition",G,{shouldDirty:!0,shouldTouch:!0}),b()}};return o.jsxs(o.Fragment,{children:[o.jsx(Qt,{control:e,name:"definition",render:({field:A})=>o.jsxs(Xt,{className:"dark:bg-white/2",children:[o.jsx(en,{children:o.jsx("div",{className:"space-y-3",children:!Pd(A.value)||w===ur.DRAFT?o.jsx(Fte,{storageType:t,onSetupConnector:C,preset:n,isOpen:v,onClose:()=>{x(!1)}}):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(Hte,{storageType:t,onAddConfiguration:_,existingConnector:Pd(A.value)?{source:A.value.connector.source,storage:A.value.connector.storage}:void 0}),Pd(A.value)&&O(A.value)]}),o.jsx("div",{className:"flex items-center gap-2",children:s&&s.definitionType===qe.CONNECTOR&&o.jsx(uD,{configuration:s.definition,onManualRun:j,children:o.jsxs(Ce,{variant:"outline",children:[o.jsx(wb,{className:"h-4 w-4"}),o.jsx("span",{children:"Manual Run..."})]})})})]}),o.jsx("div",{className:"space-y-3",children:Pd(A.value)&&(s!=null&&s.storage)?A.value.connector.source.configuration.map((M,U)=>{const B=A.value;return o.jsx(hu,{children:o.jsx(Vte,{configIndex:U,connectorDef:B,dataStorage:s.storage,onRemoveConfiguration:D,onUpdateConfiguration:R,dataMartStatus:typeof w=="object"?w.code:w,totalConfigurations:B.connector.source.configuration.length},U)},U)}):null})]})})}),o.jsx(ln,{})]})}),o.jsx(hu,{children:o.jsx(PO,{isOpen:m,onClose:()=>{g(!1)},onSubmit:T,dataStorageType:t,existingConnector:Pd(d().definition)?{source:d().definition.connector.source,storage:d().definition.connector.storage}:void 0,mode:"fields-only"})})]})}function Bte({definitionType:e,storageType:t,preset:n}){const{control:r}=Du(),[s,l]=p.useState(!1);return p.useEffect(()=>{e===qe.CONNECTOR&&!n?l(!0):l(!1)},[e,n]),o.jsxs("div",{className:"space-y-2",children:[e===qe.SQL&&o.jsx(see,{control:r}),e===qe.TABLE&&o.jsx(oee,{control:r,storageType:t}),e===qe.VIEW&&o.jsx(iee,{control:r,storageType:t}),e===qe.TABLE_PATTERN&&o.jsx(lee,{control:r,storageType:t}),e===qe.CONNECTOR&&o.jsx($te,{control:r,storageType:t,preset:n,autoOpen:s})]})}function UO(){const[e]=gI(),t=e.get("preset");return p.useMemo(()=>{if(!t)return;const n=t.toLowerCase();return oY(n)},[t])}function Gte(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 qte(e,t){const[n,r]=p.useState(e);return p.useEffect(()=>{const s=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(s)}},[e,t]),n}const Zte=1e3,Kte=[Cl.SUCCESS,Cl.ERROR,Cl.CANCELLED];function Yte(e){const[t,n]=p.useState(!1),[r,s]=p.useState(null),l=p.useRef({triggerId:null,abortController:null}),c=p.useCallback(v=>l.current.triggerId===v,[]),d=p.useCallback(v=>{s({isValid:!1,error:v instanceof Error?v.message:"Validation failed"}),n(!1)},[]),h=p.useCallback(async()=>{const{triggerId:v,abortController:x}=l.current;if(v){x==null||x.abort(),l.current={triggerId:null,abortController:null},s(null),n(!1);try{await rn.abortSqlDryRunTrigger(e,v)}catch(b){console.error("Failed to cancel trigger:",b)}}},[e]),m=p.useCallback(async(v,x)=>{for(;!x.aborted&&c(v);)try{const b=await rn.getSqlDryRunTriggerStatus(e,v);if(Kte.includes(b)){const w=await rn.getSqlDryRunTriggerResponse(e,v);s({isValid:w.isValid,error:w.error??void 0,bytes:w.bytes}),n(!1),l.current={triggerId:null,abortController:null};return}await new Promise(w=>setTimeout(w,Zte))}catch(b){d(b),l.current={triggerId:null,abortController:null};return}},[e,c,d]),g=p.useCallback(async v=>{await h(),n(!0),s(null);try{const{triggerId:x}=await rn.createSqlDryRunTrigger(e,v),b=new AbortController;l.current={triggerId:x,abortController:b},await m(x,b.signal)}catch(x){d(x)}},[e,h,m,d]);return p.useEffect(()=>()=>{const{triggerId:v,abortController:x}=l.current;x==null||x.abort(),v&&rn.abortSqlDryRunTrigger(e,v).catch(()=>{})},[e]),{validateSql:g,isLoading:t,result:r,cancel:h}}const Wte=300;function Qte({sql:e,dataMartId:t,debounceDelay:n=Wte,className:r="",onValidationStateChange:s}){const l=qte(e.trim(),n),{validateSql:c,isLoading:d,result:h,cancel:m}=Yte(t);p.useEffect(()=>{if(!l){m();const v={isLoading:!1,isValid:null,error:null,bytes:null};s==null||s(v);return}c(l)},[l,c,m,s]),p.useEffect(()=>{const v={isLoading:d,isValid:(h==null?void 0:h.isValid)??null,error:(h==null?void 0:h.error)??null,bytes:(h==null?void 0:h.bytes)??null};s==null||s(v)},[d,h,s]);const g=()=>d?o.jsxs("div",{className:"flex h-5 items-center gap-2",children:[o.jsx(gu,{className:"h-4 w-4 animate-spin"}),o.jsx("span",{className:"text-sm",children:"Validating..."})]}):h?h.isValid?o.jsxs("div",{className:"flex h-5 items-center gap-2",children:[o.jsx(qj,{className:"h-4 w-4 text-green-600"}),o.jsx("span",{className:"text-sm font-medium text-green-600",children:"Valid SQL code"}),h.bytes!==void 0&&o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"mx-1 text-gray-400",children:"•"}),o.jsxs(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx(Jm,{className:"h-3 w-3 text-gray-600"}),o.jsx("span",{className:"text-xs text-gray-600",children:Gte(h.bytes)})]})}),o.jsx(_t,{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(ef,{className:"h-4 w-4 flex-shrink-0 text-red-600"}),h.error&&o.jsx("span",{className:"text-xs text-red-500",children:h.error})]}):o.jsxs("div",{className:"flex h-5 items-center gap-2 text-gray-500",children:[o.jsx(Jm,{className:"h-4 w-4"}),o.jsx("span",{className:"text-sm",children:"Type a query to get started"})]});return o.jsx("div",{className:`inline-flex h-9 items-center px-3 py-2 ${r}`,children:g()})}function Xte(){const{dataMart:e,updateDataMartDefinition:t,getDataMart:n}=gs(),r=UO();if(!e)throw new Error("Data mart not found");const{definitionType:s,definition:l,id:c,storage:{type:d}}=e,[h,m]=p.useState(s),[,g]=p.useState({isValid:null,isLoading:!1,error:null}),v=p.useCallback(()=>{if(!h)return;const $={definitionType:h,definition:X0(h)};return l?{definitionType:h,definition:l}:$},[h,l]),x=p.useCallback(()=>{if(!h)return;const $=aee(h,d);return Wl($)},[h,d]),b=$i({resolver:x(),defaultValues:v(),mode:"onChange"}),{handleSubmit:w,reset:C,watch:E,formState:{isDirty:R,isValid:T}}=b,j=($,I)=>{if($!==qe.SQL)return"";const Y=I;return(Y==null?void 0:Y.sqlQuery)??""},O=E("definition"),D=j(h,O);p.useEffect(()=>{h&&C(v())},[h,C,v]);const _=$=>X0($);p.useEffect(()=>{if(!h&&!s&&(r!=null&&r.definitionType)){m(r.definitionType);const $={definitionType:r.definitionType,definition:_(r.definitionType)};C($)}},[r,h,s,C]);const A=p.useCallback($=>{g({isLoading:$.isLoading,isValid:$.isValid,error:$.error})},[]),M=$=>{m($)},U=p.useCallback(()=>{c&&n(c)},[c,n]),{run:B}=q1(c,U),G=async $=>{if(h&&c)try{await t(c,$.definitionType,$.definition),await B(),C($)}catch(I){console.error("Failed to update data mart definition:",I)}},K=$=>{$.preventDefault(),w(G)($)},re=()=>{C(v())},H=()=>h?o.jsxs("form",{onSubmit:K,className:"space-y-4",children:[o.jsx(Bte,{definitionType:h,storageType:d,preset:r==null?void 0:r.connectorSourceTitle}),o.jsxs("div",{className:"flex items-center gap-4",children:[o.jsx(Ce,{variant:"default",type:"submit",disabled:!T||!R,children:"Save"}),o.jsx(Ce,{type:"button",variant:"ghost",onClick:re,disabled:!R,children:"Discard"}),h===qe.SQL&&D&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-6 w-px bg-gray-300"}),o.jsx(Qte,{sql:D,dataMartId:c,onValidationStateChange:A})]})]})]}):null;return o.jsx(m3,{...b,children:o.jsxs("div",{className:"space-y-4",children:[!s&&o.jsx(XJ,{initialType:h,onTypeSelect:M}),H()]})})}function Jte(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 FO(e){return e.type==="bigquery-data-mart-schema"}function zO(e){return e.type==="athena-data-mart-schema"}function GT(e){return e!==null&&typeof e=="object"&&"mode"in e}function qT(e){return e!==null&&typeof e=="object"&&"isPrimaryKey"in e}function ene(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 tne(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?FO(n)&&h.every(GT)?(r({...n,fields:h}),l(!0)):zO(n)&&h.every(qT)&&(r({...n,fields:h}),l(!0)):h.length>0&&(GT(h[0])?(r({type:"bigquery-data-mart-schema",fields:h}),l(!0)):qT(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 nne(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 rne(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 VO(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=>VO(c,t)):!1}function HO(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=HO(s.fields,t,c);g.length>0&&(r.includes(c)||r.push(c),r.push(...g))}}),r}function ane(e,t,n){const r=e.original;if(!n)return!0;const s=n.toLowerCase();return VO(r,s)}function sne(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 us=(e=>(e.CONNECTED="CONNECTED",e.CONNECTED_WITH_DEFINITION_MISMATCH="CONNECTED_WITH_DEFINITION_MISMATCH",e.DISCONNECTED="DISCONNECTED",e))(us||{}),hf=(e=>(e.NULLABLE="NULLABLE",e.REQUIRED="REQUIRED",e.REPEATED="REPEATED",e))(hf||{}),Pn=(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))(Pn||{}),pS=(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))(pS||{});function one(e){const[t,n]=p.useState(new Set),[r,s]=p.useState(null),l=p.useRef(""),c=p.useMemo(()=>{const w=C=>C.some(E=>E.type===Pn.RECORD||E.type===Pn.STRUCT||E.fields&&w(E.fields));return w(e)},[e]),d=p.useCallback(w=>{n(C=>{const E=new Set(C);return E.has(w)?E.delete(w):E.add(w),E})},[]),h=p.useCallback(()=>{const w=[],C=(E,R="")=>{E.forEach((T,j)=>{const O=R?`${R}.${String(j)}`:String(j);(T.type===Pn.RECORD||T.type===Pn.STRUCT)&&T.fields&&T.fields.length>0&&(w.push(O),C(T.fields,O))})};C(e),n(E=>w.every(T=>E.has(T))?new Set:new Set(w))},[e]),m=p.useMemo(()=>{const w=[],C=(E,R="",T=0)=>{E.forEach((j,O)=>{const D=R?`${R}.${String(O)}`:String(O),_=j.type===Pn.RECORD||j.type===Pn.STRUCT;w.push({...j,path:D,level:T}),_&&j.fields&&t.has(D)&&C(j.fields,D,T+1)})};return C(e),w},[e,t]),g=p.useCallback(w=>{if(w!==l.current)if(l.current=w,w){r===null&&s(new Set(t));const E=HO(e,w).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===Pn.RECORD||O.type===Pn.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 E.forEach(j=>{T.add(j)}),T})}else r!==null&&(n(r),s(null))},[e,t,r]),v=p.useCallback(w=>{const C=m[w];return C.type===Pn.RECORD||C.type===Pn.STRUCT},[m]),x=p.useMemo(()=>e.map(w=>({...w,fields:void 0})),[e]),b=p.useMemo(()=>{const w=[],C=(E,R="")=>{E.forEach((T,j)=>{const O=R?`${R}.${String(j)}`:String(j);(T.type===Pn.RECORD||T.type===Pn.STRUCT)&&T.fields&&T.fields.length>0&&(w.push(O),C(T.fields,O))})};return C(e),w.length===0?!1:w.every(E=>t.has(E))},[e,t]);return{expandedRecords:t,hasRecordFields:c,toggleRecordExpansion:d,toggleAllRecords:h,flattenedFields:m,handleSearchChange:g,isRecordType:v,topLevelFields:x,allExpanded:b}}function ine(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,w;for(let E=0;E<x.length-1;E++)w=b[x[E]],b=w.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:Pn.STRING,mode:hf.NULLABLE,isPrimaryKey:!1,status:us.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 w=v[v.length-1];x.splice(w,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:Pn.STRING,mode:hf.NULLABLE,isPrimaryKey:!1,status:us.DISCONNECTED};if(!x)(m=v[h]).fields??(m.fields=[]),v[h].fields.push(b);else{const w=x.split(".").map(Number);let C=v;for(let E=0;E<w.length;E++){const R=w[E];E===w.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 $O(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),w=[...e],[C]=w.splice(x,1);w.splice(b,0,C),t(w);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 w=v;for(let T=0;T<x.length-1;T++)w=w[x[T]].fields??[];const C=x[x.length-1],E=b[b.length-1],[R]=w.splice(C,1);w.splice(E,0,R),t(v)}}},[e,n,t])}}function lne(){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 Fg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function ku(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function gS(e){return"nodeType"in e}function ta(e){var t,n;return e?ku(e)?e:gS(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function vS(e){const{Document:t}=ta(e);return e instanceof t}function Wf(e){return ku(e)?!1:e instanceof ta(e).HTMLElement}function BO(e){return e instanceof ta(e).SVGElement}function Iu(e){return e?ku(e)?e.document:gS(e)?vS(e)?e:Wf(e)||BO(e)?e.ownerDocument:document:document:document}const Hs=Fg?p.useLayoutEffect:p.useEffect;function yS(e){const t=p.useRef(e);return Hs(()=>{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 cne(){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 mf(e,t){t===void 0&&(t=[e]);const n=p.useRef(e);return Hs(()=>{n.current!==e&&(n.current=e)},t),n}function Qf(e,t){const n=p.useRef();return p.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function Mp(e){const t=yS(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 sb(e){const t=p.useRef();return p.useEffect(()=>{t.current=e},[e]),t.current}let Yx={};function Xf(e,t){return p.useMemo(()=>{if(t)return t;const n=Yx[e]==null?0:Yx[e]+1;return Yx[e]=n,e+"-"+n},[e,t])}function GO(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 ru=GO(1),kp=GO(-1);function une(e){return"clientX"in e&&"clientY"in e}function xS(e){if(!e)return!1;const{KeyboardEvent:t}=ta(e.target);return t&&e instanceof t}function dne(e){if(!e)return!1;const{TouchEvent:t}=ta(e.target);return t&&e instanceof t}function ob(e){if(dne(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 une(e)?{x:e.clientX,y:e.clientY}:null}const pf=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[pf.Translate.toString(e),pf.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),ZT="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function fne(e){return e.matches(ZT)?e:e.querySelector(ZT)}const hne={display:"none"};function mne(e){let{id:t,value:n}=e;return je.createElement("div",{id:t,style:hne},n)}function pne(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 je.createElement("div",{id:t,style:s,role:"status","aria-live":r,"aria-atomic":!0},n)}function gne(){const[e,t]=p.useState("");return{announce:p.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const qO=p.createContext(null);function vne(e){const t=p.useContext(qO);p.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function yne(){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 xne={draggable:`
|
|
726
|
+
`).filter(m=>m.trim());n(r,h)}})}function Iee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s,default:l}=e,c=e.title??e.name,d=h=>{if(!h||typeof h!="string"&&typeof h!="number")return"";const m=typeof h=="string"?h:h.toString();try{const g=new Date(m);return isNaN(g.getTime())?"":g.toISOString().split("T")[0]}catch{return""}};return o.jsx($t,{id:r,name:r,type:"date",value:t[r]||d(l)||"",placeholder:s??`Enter ${c.toLowerCase()}`,onChange:h=>{n(r,h.target.value)}})}function Lee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s}=e,l=e.title??e.name;return o.jsx($t,{id:r,name:r,type:"text",value:t[r]||"",placeholder:s??`Enter ${l.toLowerCase()}`,onChange:c=>{n(r,c.target.value)}})}function Pee({specification:e,configuration:t,onValueChange:n}){const r=e.title??e.name,{name:s,placeholder:l,default:c}=e;return o.jsx(Fi,{id:s,name:s,value:t[s]&&typeof t[s]=="object"?JSON.stringify(t[s],null,2):typeof c=="object"?JSON.stringify(c,null,2):"",placeholder:l??`Enter ${r.toLowerCase()} as JSON`,rows:6,className:"font-mono",onChange:d=>{try{const h=JSON.parse(d.target.value);n(s,h)}catch{n(s,d.target.value)}}})}function Uee({specification:e,configuration:t,onValueChange:n,isEditingExisting:r,isSecretEditing:s}){const l=e.title??e.name,c=r&&!s;return o.jsx($t,{id:e.name,...c?{}:{name:e.name},type:c?"password":"text",autoComplete:c?"new-password":"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,value:c?J0:t[e.name]||"",...c?{readOnly:!0,disabled:!0}:{},...c?{}:{placeholder:e.placeholder??`Enter ${l.toLowerCase()}`},...c?{}:{onChange:d=>{n(e.name,d.target.value)}}})}function Fee({specification:e,configuration:t,onValueChange:n,specOptions:r}){const{name:s,placeholder:l,default:c}=e,d=e.title??e.name,h=r.map(m=>({value:m,label:m}));return o.jsx(X1,{options:h,value:t[s]||c||"",onValueChange:m=>{n(s,m)},placeholder:l??`Select ${d.toLowerCase()}`,emptyMessage:"No options available",className:"w-full"})}function xO({specification:e,configuration:t,onValueChange:n,flags:r}){const{requiredType:s,options:l}=e,{isSecret:c=!1,isEditingExisting:d=!1,isSecretEditing:h=!1}=r??{};if(c)return o.jsx(Uee,{specification:e,configuration:t,onValueChange:n,isEditingExisting:d,isSecretEditing:h});if(l&&l.length>0)return o.jsx(Fee,{specification:e,configuration:t,onValueChange:n,specOptions:l});switch(s){case rs.BOOLEAN:return o.jsx(Oee,{specification:e,configuration:t,onValueChange:n});case rs.NUMBER:return o.jsx(Mee,{specification:e,configuration:t,onValueChange:n});case rs.ARRAY:return o.jsx(kee,{specification:e,configuration:t,onValueChange:n});case rs.OBJECT:return o.jsx(Pee,{specification:e,configuration:t,onValueChange:n});case rs.DATE:return o.jsx(Iee,{specification:e,configuration:t,onValueChange:n});case rs.STRING:default:return o.jsx(Lee,{specification:e,configuration:t,onValueChange:n})}}function zee({specification:e,configuration:t,isEditingExisting:n,isSecretEditing:r,isSecret:s,onValueChange:l,onSecretEditToggle:c}){return o.jsxs($d,{children:[e.requiredType!==rs.BOOLEAN&&o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(wo,{htmlFor:e.name,required:e.required,tooltip:e.description,children:e.title??e.name}),s&&n&&o.jsx(Ce,{variant:"ghost",size:"sm",type:"button",onClick:()=>{c(e.name,!r)},children:r?"Cancel":"Edit"})]}),xO({specification:e,configuration:t,onValueChange:l,flags:{isSecret:s,isEditingExisting:n,isSecretEditing:r}})]},e.name)}function Vee({specification:e,configuration:t,onValueChange:n,isEditingExisting:r,isSecretEditing:s,onSecretEditToggle:l}){const c=p.useMemo(()=>{var v,x;const g=t[e.name];if(g&&typeof g=="object"){const b=Object.keys(g);if(b.length>0)return b[0]}return((x=(v=e.oneOf)==null?void 0:v[0])==null?void 0:x.value)??""},[t,e.name,e.oneOf]),[d,h]=p.useState(c);if(p.useEffect(()=>{h(c)},[c]),!e.oneOf)return null;const m=(g,v,x)=>{const b=t[e.name]&&typeof t[e.name]=="object"?t[e.name]:{};n(e.name,{[g]:{...typeof b[g]=="object"&&b[g]!==null?b[g]:{},[v]:x}})};return o.jsx(Tee,{label:e.title??e.name,options:e.oneOf.map(g=>({value:g.value,label:g.label})),value:d,onValueChange:h,children:e.oneOf.map(g=>o.jsx(xee,{value:g.value,children:Object.entries(g.items).map(([v,x])=>{const b=t[e.name]&&typeof t[e.name]=="object"?t[e.name]:{},w=Array.isArray(x.attributes)&&Object.keys(b)[0]===g.value?x.attributes.includes("SECRET"):!1,C=typeof t[e.name]=="object"&&t[e.name]!==null?t[e.name]:{},E=typeof C[g.value]=="object"&&C[g.value]!==null?C[g.value]:{};return o.jsxs("div",{className:"mb-4",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(wo,{htmlFor:v,required:x.required,tooltip:x.description,className:"mb-2 justify-start",children:v}),w&&r&&o.jsx(Ce,{variant:"ghost",size:"sm",type:"button",onClick:()=>{l(e.name,!s)},children:s?"Cancel":"Edit"})]}),xO({specification:{...x,name:v},configuration:E,onValueChange:(R,T)=>{m(g.value,R,T)},flags:{isEditingExisting:r,isSecret:w,isSecretEditing:s}})]},v)})},g.value))},e.name)}function zT(e,t,n,r,s,l){return e.map(c=>{const d=Array.isArray(c.attributes)?c.attributes.includes("SECRET"):!1,h=s[c.name];return c.oneOf&&c.requiredType===rs.OBJECT?o.jsx(Vee,{specification:c,configuration:t,onValueChange:n,isEditingExisting:l,isSecretEditing:h,onSecretEditToggle:r},c.name):o.jsx(zee,{specification:c,configuration:t,isEditingExisting:l,isSecret:d,isSecretEditing:h,onValueChange:n,onSecretEditToggle:r},c.name)})}function VT({collapsibleTitle:e,items:t,configuration:n,onValueChange:r,onSecretEditToggle:s,secretEditing:l,isEditingExisting:c}){return e?o.jsx(jee,{title:e,children:zT(t,n,r,s,l,c)}):zT(t,n,r,s,l,c)}function Hee({currentConnectorName:e,onCopyConfiguration:t,connectorSpecification:n}){const[r,s]=p.useState([]),[l,c]=p.useState(!1),[d,h]=p.useState(!1),m=p.useCallback(async()=>{c(!0);try{const x=await rn.getDataMartsByConnectorName(e);s(x)}catch{s([])}finally{c(!1)}},[e]);p.useEffect(()=>{d&&m()},[d,m]);const g=(x,b)=>{const w=b._id;if(!w){console.error("Configuration does not have _id field");return}t({dataMartId:x.id,dataMartTitle:x.title,configId:w,configuration:b}),h(!1)},v=x=>{const w=[],C=R=>{if(!n)return!0;const T=n.find(j=>j.name===R);return(T==null?void 0:T.required)??!1},E=(R,T,j=0,O=!0)=>{if(R.startsWith("_")||O&&j===0&&!C(R))return;let D=null;if(T==null)D="N/A";else if(typeof T=="string")D=T;else if(typeof T=="number"||typeof T=="boolean")D=String(T);else if(Array.isArray(T))D=JSON.stringify(T);else if(typeof T=="object"){w.push({key:R,value:"{",indent:j}),Object.entries(T).forEach(([_,A])=>{E(_,A,j+1,!1)}),w.push({key:"",value:"}",indent:j});return}else D=JSON.stringify(T);w.push({key:R,value:D,indent:j})};for(const[R,T]of Object.entries(x))E(R,T);return o.jsx("div",{className:"space-y-1 font-mono text-xs",children:w.map(({key:R,value:T,indent:j},O)=>o.jsxs("div",{className:"flex gap-2",style:{paddingLeft:`${String(j*12)}px`},children:[R&&o.jsxs("span",{className:"font-medium",children:[R,":"]}),o.jsx("span",{className:"text-muted-foreground truncate",title:T,children:T})]},O))})};return o.jsx(ls,{children:o.jsxs(Cr,{open:d,onOpenChange:h,children:[o.jsx(wr,{asChild:!0,children:o.jsxs(Ce,{type:"button",variant:"ghost",size:"sm",className:"cursor-pointer",children:[o.jsx("span",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:"Auto-fill from…"}),o.jsx(Ra,{className:J("text-foreground/75 h-3.5 w-3.5 transition-transform duration-200",d&&"rotate-90")})]})}),o.jsx(Er,{side:"bottom",align:"end",className:"w-72",children:l?o.jsx(bt,{disabled:!0,children:"Loading…"}):r.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 p-4 text-center",children:[o.jsx("div",{className:"bg-muted/70 rounded-full p-3",children:o.jsx(lL,{className:"text-muted-foreground h-6 w-6",strokeWidth:1.5})}),o.jsx("span",{className:"text-foreground text-sm font-medium",children:"No matching Data Marts"}),o.jsx("span",{className:"text-muted-foreground text-sm",children:"You can auto-fill settings only from connector-based Data Marts with the same source."})]}):o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx("div",{className:"text-muted-foreground border-b p-2 text-sm",children:"Select one of your existing Data Marts to auto-fill settings in this form"}),o.jsx("div",{children:r.map(x=>{const w=x.definition.connector.source.configuration;return w.length===0?null:w.length===1?o.jsxs(Tt,{delayDuration:300,children:[o.jsx(jt,{asChild:!0,children:o.jsxs(bt,{onSelect:()=>{g(x,w[0])},children:[o.jsx(Xm,{className:"text-foreground h-4 w-4"}),x.title]})}),o.jsx(_t,{side:"right",className:"max-w-sm",children:v(w[0])})]},x.id):o.jsxs(Qb,{children:[o.jsxs(Xb,{className:"flex items-center gap-2",children:[o.jsx(Xm,{className:"text-foreground h-4 w-4"}),o.jsx("span",{children:x.title})]}),o.jsx(Jb,{children:w.map((C,E)=>o.jsxs(Tt,{delayDuration:300,children:[o.jsx(jt,{asChild:!0,children:o.jsxs(bt,{onSelect:()=>{g(x,C)},children:["Configuration ",E+1]})}),o.jsx(_t,{side:"right",className:"max-w-sm",children:v(C)})]},E))})]},x.id)})})]})})]})})}function HT({connector:e,connectorSpecification:t,onConfigurationChange:n,onValidationChange:r,initialConfiguration:s,loading:l=!1,isEditingExisting:c=!1}){const[d,h]=p.useState({}),m=p.useRef(!1),g=p.useRef(!1),[v,x]=p.useState({});p.useEffect(()=>{if(t){g.current=!0;const _={...s??{}};t.forEach(A=>{const M=Array.isArray(A.attributes)?A.attributes.includes("SECRET"):!1;_[A.name]===void 0&&A.default!==void 0&&(_[A.name]=A.default),c&&M&&(_[A.name]=J0)}),h(_),m.current=!0,setTimeout(()=>{g.current=!1},0)}},[t,s,c]),p.useEffect(()=>{m.current&&s&&Object.keys(s).length>0&&(g.current=!0,h({...s}),setTimeout(()=>{g.current=!1},0))},[s]),p.useEffect(()=>{m.current&&!g.current&&Object.keys(d).length>0&&(n==null||n(d))},[d,n]);const b=(_,A)=>{h(M=>({...M,[_]:A}))},w=p.useCallback(_=>!(_==null||typeof _=="string"&&_.trim()===""||typeof _=="number"&&isNaN(_)||Array.isArray(_)&&_.length===0),[]),C=p.useCallback((_,A)=>{var U;if(typeof _!="object"||_===null)return w(_);const M=(U=A.oneOf)==null?void 0:U.filter(B=>B.value===Object.keys(_)[0]);return M?M.every(B=>Object.entries(B.items).every(([,G])=>B.value in _?C(_[B.value],G):!1)):w(_[A.name])},[w]),E=p.useCallback((_,A)=>{const M=A.filter(K=>K.required&&K.oneOf),U=M.length===0?!0:M.some(K=>C(_[K.name],K)),G=A.filter(K=>K.required&&K.name!=="Fields").every(K=>w(_[K.name]));return U&&G},[w,C]),R=(_,A)=>{x(M=>({...M,[_]:A})),h(A?M=>({...M,[_]:""}):M=>({...M,[_]:J0}))},T=_=>{const A={...d};Object.entries(_.configuration).forEach(([M,U])=>{A[M]=U}),A._copiedFrom={dataMartId:_.dataMartId,dataMartTitle:_.dataMartTitle,configId:_.configId},h(A)};if(p.useEffect(()=>{if(t&&r){const _=E(d,t);r(_)}},[d,t,r,E]),l)return o.jsx(fS,{variant:"list"});if(!t||t.length===0)return o.jsxs(Ro,{children:[o.jsx(El,{connector:e}),o.jsx(Di,{icon:o.jsx(nf,{size:56,strokeWidth:1}),title:"No configuration found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),o.jsx(nu,{label:"Need configuration?"})]});const j=[...t].filter(_=>{var A;return _.name!=="Fields"&&!((A=_.attributes)!=null&&A.includes("HIDE_IN_CONFIG_FORM"))}).sort((_,A)=>{const M=U=>{const B=U.default!=null&&U.default!=="";return U.required&&!B?1:U.required&&B?2:!U.required&&!B?3:4};return M(_)-M(A)}),O=j.filter(_=>{var A;return!((A=_.attributes)!=null&&A.includes("ADVANCED"))}),D=j.filter(_=>{var A;return(A=_.attributes)==null?void 0:A.includes("ADVANCED")});return o.jsx(o.Fragment,{children:o.jsxs(Ro,{children:[o.jsx(El,{connector:e}),o.jsxs(wl,{children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("h3",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:"Configure Settings"}),o.jsx(Hee,{currentConnectorName:e.name,onCopyConfiguration:T,connectorSpecification:t})]}),O.length>0&&o.jsx(VT,{items:O,configuration:d,onValueChange:b,onSecretEditToggle:R,secretEditing:v,isEditingExisting:c}),D.length>0&&o.jsx(VT,{collapsibleTitle:"Advanced Settings",items:D,configuration:d,onValueChange:b,onSecretEditToggle:R,secretEditing:v,isEditingExisting:c})]})]})})}function $ee({connector:e,connectorFields:t,selectedField:n,connectorName:r,loading:s=!1,onFieldSelect:l}){const c=r?`Select data for ${r}`:"Select data";return s?o.jsx(fS,{variant:"list"}):!t||t.length===0?o.jsxs(Ro,{children:[o.jsx(El,{connector:e}),o.jsx(Di,{icon:o.jsx(nf,{size:56,strokeWidth:1}),title:r?`No nodes found for ${r}`:"No nodes found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),o.jsx(nu,{label:"Missing some data?"})]}):o.jsxs(Ro,{children:[o.jsx(El,{connector:e}),o.jsxs(wl,{title:c,children:[t.map(d=>o.jsx(yO,{type:"radio",id:d.name,name:"selectedField",value:d.name,label:d.overview??d.name,checked:n===d.name,onChange:h=>{l(h)},tooltip:d.name&&o.jsxs("div",{className:"flex flex-col gap-2 py-1",children:[o.jsxs("p",{children:[o.jsx("span",{className:"font-semibold",children:"Table name:"})," ",d.destinationName??d.name]}),d.description&&o.jsxs("p",{children:[o.jsx("span",{className:"font-semibold",children:"Description:"})," ",d.description]}),d.documentation&&o.jsxs(Ba,{to:d.documentation,target:"_blank",rel:"noopener noreferrer",className:"bg-muted/16 hover:bg-muted/20 dark:bg-muted/8 dark:hover:bg-muted/16 flex items-center justify-center gap-1 rounded-sm px-2 py-1 font-semibold",children:["Read more",o.jsx(Ra,{className:"h-3 w-3"})]})]}),selected:n===d.name},d.name)),o.jsx(nu,{label:"Missing some data?"})]})]})}var As=(e=>(e.ASC="asc",e.DESC="desc",e.ORIGINAL="original",e))(As||{});function $T({connector:e,connectorFields:t,selectedField:n,selectedFields:r,onFieldToggle:s}){const l=p.useRef(null),[c,d]=p.useState(""),[h,m]=p.useState(As.ORIGINAL),g=t==null?void 0:t.find(R=>R.name===n),v=p.useMemo(()=>(g==null?void 0:g.fields)??[],[g==null?void 0:g.fields]),x=p.useMemo(()=>(g==null?void 0:g.uniqueKeys)??[],[g==null?void 0:g.uniqueKeys]),b=p.useMemo(()=>{const R=new Map;return v.forEach((T,j)=>R.set(T.name,j)),R},[v]),w=p.useMemo(()=>{const R=v.filter(j=>j.name.toLowerCase().includes(c.toLowerCase().trim())),T=(j,O)=>{const D=x.includes(j.name),_=x.includes(O.name);if(D&&!_)return-1;if(!D&&_)return 1;if(h===As.ASC)return j.name.localeCompare(O.name);if(h===As.DESC)return O.name.localeCompare(j.name);const A=b.get(j.name)??0,M=b.get(O.name)??0;return A-M};return[...R].sort(T)},[v,c,x,h,b]),C=v.map(R=>R.name),E=r.filter(R=>C.includes(R)).length;return p.useEffect(()=>{if(x.length>0){const R=x.filter(T=>v.some(j=>j.name===T)&&!r.includes(T));R.length>0&&R.forEach(T=>{s(T,!0)})}},[n,x,v,r,s]),p.useEffect(()=>{const R=T=>{const O=(T.ctrlKey||T.metaKey)&&T.shiftKey&&T.key.toLowerCase()==="a",D=document.activeElement.tagName;if(!(D==="INPUT"||D==="TEXTAREA")&&O){T.preventDefault();const _=v.map(U=>U.name),M=_.filter(U=>!r.includes(U)).length>0;_.forEach(U=>{s(U,M)})}};return window.addEventListener("keydown",R),()=>{window.removeEventListener("keydown",R)}},[v,r,s]),!n||!t?o.jsxs(Ro,{children:[o.jsx(El,{connector:e}),o.jsx(Di,{icon:o.jsx(nf,{size:56,strokeWidth:1}),title:"No fields found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),o.jsx(nu,{label:"Need fields?"})]}):v.length?o.jsx(Ro,{children:o.jsxs(o.Fragment,{children:[o.jsx(El,{connector:e}),o.jsxs("div",{className:"border-border -mt-6 mb-6 flex w-full items-center gap-2 border-b",children:[o.jsxs("div",{className:"relative flex-1",children:[o.jsx(Fl,{className:"text-muted-foreground absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 cursor-text",onClick:()=>{var R;(R=l.current)==null||R.focus()}}),o.jsx("input",{ref:l,type:"text",placeholder:"Search field",value:c,onChange:R=>{d(R.target.value)},className:"h-12 w-full rounded-none border-0 pl-9 text-sm outline-none"}),c&&o.jsx("button",{type:"button",onClick:()=>{d("")},className:"text-muted-foreground hover:text-foreground absolute top-1/2 right-0 -translate-y-1/2",children:o.jsx(su,{className:"h-4 w-4"})})]}),o.jsxs(Cr,{children:[o.jsx(wr,{asChild:!0,children:o.jsxs(Ce,{variant:"ghost",size:"icon","aria-label":"Sort fields",children:[h===As.ASC&&o.jsx(q2,{className:"text-muted-foreground h-4 w-4"}),h===As.DESC&&o.jsx(G2,{className:"text-muted-foreground h-4 w-4"}),h===As.ORIGINAL&&o.jsx(Z2,{className:"text-muted-foreground h-4 w-4"})]})}),o.jsxs(Er,{align:"end",children:[o.jsxs(bt,{onSelect:()=>{m(As.ASC)},children:[o.jsx(q2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"A–Z"]}),o.jsxs(bt,{onSelect:()=>{m(As.DESC)},children:[o.jsx(G2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Z–A"]}),o.jsxs(bt,{onSelect:()=>{m(As.ORIGINAL)},children:[o.jsx(Z2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Original"]})]})]})]}),o.jsxs(wl,{title:`Selected ${String(E)} of ${String(C.length)} fields for "${n}" data`,children:[w.map(R=>{const T=x.includes(R.name);return o.jsx(yO,{type:"checkbox",id:`field-${R.name}`,name:"selectedFields",value:R.name,checked:r.includes(R.name),selected:r.includes(R.name)||T,disabled:T,onChange:j=>{s(R.name,j)},label:R.name,tooltip:o.jsxs("div",{className:"flex flex-col gap-2 py-1",children:[T&&o.jsxs("p",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"font-semibold",children:"Unique key"})," ",o.jsx(l0,{className:"text-secondary h-3 w-3"})]}),o.jsxs("p",{children:[o.jsx("span",{className:"font-semibold",children:"Type:"})," ",R.type]}),R.description&&o.jsxs("p",{children:[o.jsx("span",{className:"font-semibold",children:"Description:"})," ",R.description]})]}),rightIcon:T?o.jsx(l0,{className:"text-muted-foreground/75 h-4 w-4"}):void 0},R.name)}),w.length===0&&c&&o.jsxs("div",{className:"text-muted-foreground pt-8 pb-4 text-center text-sm",children:['No fields match "',c,'"']}),o.jsx(nu,{label:"Need another field?"})]})]})}):o.jsxs(Ro,{children:[o.jsx(El,{connector:e}),o.jsx(Di,{icon:o.jsx(nf,{size:56,strokeWidth:1}),title:"No fields found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),o.jsx(nu,{label:"Need fields?"})]})}const bO=p.createContext(void 0),SO={triggers:[],selectedTrigger:null,isLoading:!1,error:null};function Bee(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 SO;default:return e}}class Gee extends Bl{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 Uc=new Gee;var xn=(e=>(e.REPORT_RUN="REPORT_RUN",e.CONNECTOR_RUN="CONNECTOR_RUN",e))(xn||{});const Kc={SCHEDULED_REPORT_RUN:"scheduled-report-run-config"};class eb{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!==xn.REPORT_RUN)return t;const n=t.triggerConfig;if(!n.reportId)return t;try{const r=await yo.getReportById(n.reportId),s=gl(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:xn.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 qee{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:xn.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 Zx={getMapper(e){switch(e){case xn.REPORT_RUN:return new eb;case xn.CONNECTOR_RUN:return new qee;default:throw new Error(`Unknown scheduled trigger type: ${String(e)}`)}}},Ld={mapFromDto(e){return Zx.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 xn.REPORT_RUN:return new eb().enhanceWithReportData(n);case xn.CONNECTOR_RUN:{const r=t.definition;return{...n,triggerConfig:{...n.triggerConfig,connector:r}}}default:return n}},async mapFromDtoListWithReportData(e,t){const n=new eb,r=this.mapFromDtoList(e),s=r.filter(c=>c.type===xn.REPORT_RUN),l=await n.enhanceTriggersWithReportData(s);return r.map(c=>{switch(c.type){case xn.REPORT_RUN:return l.find(d=>d.id===c.id)??c;case xn.CONNECTOR_RUN:{const d=t.definition;return{...c,triggerConfig:{...c.triggerConfig,connector:d}}}default:return c}})},mapToCreateRequest(e){return Zx.getMapper(e.type).mapToCreateRequest(e)},mapToUpdateRequest(e){return Zx.getMapper(e.type).mapToUpdateRequest(e)}};function Zee({children:e}){const[t,n]=p.useReducer(Bee,SO),{dataMart:r}=Hi(),{fetchAvailableConnectors:s}=ql();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 w=await Uc.getScheduledTriggers(b),C=await Ld.mapFromDtoListWithReportData(w,r);n({type:"FETCH_TRIGGERS_SUCCESS",payload:C})}catch(w){const C=w instanceof Error?w.message:"Failed to fetch scheduled triggers";n({type:"FETCH_TRIGGERS_ERROR",payload:C}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"ListError",label:C})}},[r,s]),c=p.useCallback(async(b,w)=>{n({type:"FETCH_TRIGGERS_START"});try{const E=(await Uc.getScheduledTriggers(b)).filter(T=>T.type===w),R=await Ld.mapFromDtoListWithReportData(E,r);n({type:"FETCH_TRIGGERS_SUCCESS",payload:R})}catch(C){const E=C instanceof Error?C.message:"Failed to fetch scheduled triggers";n({type:"FETCH_TRIGGERS_ERROR",payload:E}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"ListError",label:E})}},[r]),d=p.useCallback(async(b,w)=>{n({type:"FETCH_TRIGGER_START"});try{const C=await Uc.getScheduledTrigger(b,w),E=await Ld.mapFromDtoWithReportData(C,r);n({type:"FETCH_TRIGGER_SUCCESS",payload:E})}catch(C){const E=C instanceof Error?C.message:"Failed to fetch scheduled trigger";n({type:"FETCH_TRIGGER_ERROR",payload:E}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"GetError",label:E})}},[r]),h=p.useCallback(async(b,w,C,E,R,T)=>{n({type:"CREATE_TRIGGER_START"});try{const j={type:w,cronExpression:C,timeZone:E,isActive:R,triggerConfig:T},O=await Uc.createScheduledTrigger(b,j),D=await Ld.mapFromDtoWithReportData(O,r);return n({type:"CREATE_TRIGGER_SUCCESS",payload:D}),Fe({event:"scheduled_trigger_created",category:"ScheduledTrigger",action:"Create",label:w}),an.success("Trigger created"),D}catch(j){const O=j instanceof Error?j.message:"Failed to create scheduled trigger";throw n({type:"CREATE_TRIGGER_ERROR",payload:O}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"CreateError",label:O}),j}},[r]),m=p.useCallback(async(b,w,C,E,R)=>{n({type:"UPDATE_TRIGGER_START"});try{const T={cronExpression:C,timeZone:E,isActive:R},j=await Uc.updateScheduledTrigger(b,w,T),O=await Ld.mapFromDtoWithReportData(j,r);n({type:"UPDATE_TRIGGER_SUCCESS",payload:O}),Fe({event:"scheduled_trigger_updated",category:"ScheduledTrigger",action:"Update",label:O.type}),an.success("Trigger updated")}catch(T){const j=T instanceof Error?T.message:"Failed to update scheduled trigger";throw n({type:"UPDATE_TRIGGER_ERROR",payload:j}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"UpdateError",label:j}),T}},[r]),g=p.useCallback(async(b,w)=>{n({type:"DELETE_TRIGGER_START"});try{await Uc.deleteScheduledTrigger(b,w),n({type:"DELETE_TRIGGER_SUCCESS",payload:w}),Fe({event:"scheduled_trigger_deleted",category:"ScheduledTrigger",action:"Delete",label:w}),an.success("Trigger deleted")}catch(C){const E=C instanceof Error?C.message:"Failed to delete scheduled trigger";throw n({type:"DELETE_TRIGGER_ERROR",payload:E}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"DeleteError",label:E}),C}},[]),v=p.useCallback(b=>{n({type:"SELECT_TRIGGER",payload:b})},[]),x=p.useCallback(()=>{n({type:"RESET"})},[]);return o.jsx(bO.Provider,{value:{...t,getScheduledTriggers:l,getScheduledTriggersByType:c,getScheduledTrigger:d,createScheduledTrigger:h,updateScheduledTrigger:m,deleteScheduledTrigger:g,selectScheduledTrigger:v,reset:x},children:e})}function CO(){const e=p.useContext(bO);if(e===void 0)throw new Error("useScheduledTriggerContext must be used within a ScheduledTriggerProvider");return e}function Kee(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}=CO();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,w)=>n(b,w),getScheduledTrigger:(b,w)=>r(b,w),createScheduledTrigger:(b,w,C,E,R,T)=>s(b,w,C,E,R,T),updateScheduledTrigger:(b,w,C,E,R)=>l(b,w,C,E,R),deleteScheduledTrigger:(b,w)=>c(b,w),selectScheduledTrigger:d}}const Yee=sn({type:qs(Kc.SCHEDULED_REPORT_RUN),reportId:on().min(1,"Report ID is required")}),Wee=mB(),Qee=sn({type:c1(xn),cronExpression:on().min(1,"Cron expression is required"),timeZone:on().min(1,"Time zone is required"),isActive:hB(),triggerConfig:gB([Yee,Wee])});function Xee({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:r}){const s=$i({resolver:Wl(Qee),defaultValues:{type:e?e.type:n??xn.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:Kc.SCHEDULED_REPORT_RUN,reportId:t??""}}});p.useEffect(()=>{t&&s.getValues("type")===xn.REPORT_RUN&&s.setValue("triggerConfig",{type:Kc.SCHEDULED_REPORT_RUN,reportId:t})},[t,s]),p.useEffect(()=>{n&&(s.setValue("type",n),n===xn.REPORT_RUN?s.setValue("triggerConfig",{type:Kc.SCHEDULED_REPORT_RUN,reportId:t??""}):s.setValue("triggerConfig",null))},[n,t,s]);const l=d=>{s.setValue("type",d),d===xn.REPORT_RUN?s.setValue("triggerConfig",{type:Kc.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 Jee({value:e,onChange:t,disabled:n}){const{reports:r,fetchReportsByDataMartId:s}=Gl(),{dataMart:l}=Hi();p.useEffect(()=>{l&&s(l.id)},[s,l]);const c=r.filter(d=>d.dataDestination.type===Lt.GOOGLE_SHEETS);return o.jsxs(Sa,{value:e,onValueChange:t,disabled:n,children:[o.jsx(wa,{className:"w-full",children:o.jsx(Ca,{placeholder:"Select a report"})}),o.jsx(Ea,{children:c.map(d=>o.jsx(qn,{value:d.id,children:d.title},d.id))})]})}var Ug="Switch",[ete]=kr(Ug),[tte,nte]=ete(Ug),wO=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),w=vt(t,j=>b(j)),C=p.useRef(!1),E=x?g||!!x.closest("form"):!0,[R,T]=zr({prop:s,defaultProp:l??!1,onChange:m,caller:Ug});return o.jsxs(tte,{scope:n,checked:R,disabled:d,children:[o.jsx(Ke.button,{type:"button",role:"switch","aria-checked":R,"aria-required":c,"data-state":jO(R),"data-disabled":d?"":void 0,disabled:d,value:h,...v,ref:w,onClick:Te(e.onClick,j=>{T(O=>!O),E&&(C.current=j.isPropagationStopped(),C.current||j.stopPropagation())})}),E&&o.jsx(TO,{control:x,bubbles:!C.current,name:r,value:h,checked:R,required:c,disabled:d,form:g,style:{transform:"translateX(-100%)"}})]})});wO.displayName=Ug;var EO="SwitchThumb",RO=p.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,s=nte(EO,n);return o.jsx(Ke.span,{"data-state":jO(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:t})});RO.displayName=EO;var rte="SwitchBubbleInput",TO=p.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...s},l)=>{const c=p.useRef(null),d=vt(c,l),h=$1(n),m=Ub(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 w=new Event("click",{bubbles:r});b.call(g,n),g.dispatchEvent(w)}},[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}})});TO.displayName=rte;function jO(e){return e?"checked":"unchecked"}var ate=wO,ste=RO;function _O({className:e,...t}){return o.jsx(ate,{"data-slot":"switch",className:J("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(ste,{"data-slot":"switch-thumb",className:J("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 ote(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 tb(e,t="UTC"){const n=ote(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 NO({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,w)=>b-w);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(Ar,{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(su,{className:"h-2 w-2"})})]},x.value))}):o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsxs(Ar,{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(su,{className:"h-2 w-2"})})]}),v.length>1&&o.jsxs(Ar,{variant:"outline",className:"h-5 text-xs",children:["+",v.length-1]})]})};return o.jsxs(Y1,{open:c,onOpenChange:d,modal:!0,children:[o.jsx(W1,{asChild:!0,children:o.jsxs(Ce,{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(Sb,{className:"ml-2 h-3 w-3 shrink-0 opacity-50"})]})}),o.jsx(Q1,{className:"max-h-[400px] w-full overflow-y-auto p-0",style:{padding:0},children:o.jsxs(jD,{className:"h-full overflow-visible",children:[o.jsx(_D,{placeholder:s,className:"h-8"}),o.jsxs(sJ,{className:"h-full max-h-[350px] overflow-y-auto",children:[o.jsx(ND,{children:"No items found."}),o.jsx(AD,{className:"h-full overflow-visible",children:e.map(v=>o.jsxs(DD,{value:v.value.toString(),onSelect:()=>h(v.value),className:"text-sm",children:[o.jsx(dr,{className:J("mr-2 h-3 w-3",t.includes(v.value)?"opacity-100":"opacity-0")}),v.label]},v.value))})]})]})})]})}const AO=[{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"}],Om=()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}};function DO(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=AO.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 ite(e,t,n=!0){const r=tb(e,t);return DO(r,n)}const lte=Array.from({length:31},(e,t)=>({value:t+1,label:`${String(t+1)}${t===0?"st":t===1?"nd":t===2?"rd":"th"}`})),nb=[5,10,15,30],rb=[1,2,3,4,6,8,12],cte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(ba,{children:"Type"}),o.jsxs(Sa,{value:e,onValueChange:r=>{t(r)},disabled:n,children:[o.jsx(wa,{className:"w-full",children:o.jsx(Ca,{})}),o.jsxs(Ea,{children:[o.jsx(qn,{value:"daily",children:"Daily"}),o.jsx(qn,{value:"weekly",children:"Weekly"}),o.jsx(qn,{value:"monthly",children:"Monthly"}),o.jsx(qn,{value:"interval",children:"Interval"})]})]})]}),ute=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(ba,{children:"Time"}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx($t,{className:"w-24",type:"time",value:e,onChange:r=>{t(r.target.value)},disabled:n})})]}),BT=({value:e,onChange:t,disabled:n,timezones:r})=>o.jsxs("div",{className:"w-full space-y-2",children:[o.jsx(ba,{children:"Timezone"}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx(X1,{options:r,value:e,onValueChange:t,placeholder:"Select timezone",emptyMessage:"No timezones found",disabled:n,className:"w-full"})})]}),dte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(ba,{children:"Days of Week"}),o.jsx("div",{className:n?"pointer-events-none":"",children:o.jsx(NO,{options:AO,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:3})})]}),fte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(ba,{children:"Days of Month"}),o.jsx("div",{className:n?"pointer-events-none":"",children:o.jsx(NO,{options:lte,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:4})})]}),hte=({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(ba,{children:"Type"}),o.jsxs(Sa,{value:e,onValueChange:l=>{n(l)},disabled:s,children:[o.jsx(wa,{className:"w-full",children:o.jsx(Ca,{})}),o.jsxs(Ea,{children:[o.jsx(qn,{value:"minutes",children:"Minutes"}),o.jsx(qn,{value:"hours",children:"Hours"})]})]})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(ba,{children:"Every"}),o.jsxs(Sa,{value:t.toString(),onValueChange:l=>{r(Number.parseInt(l)||1)},disabled:s,children:[o.jsx(wa,{className:"w-full",children:o.jsx(Ca,{})}),o.jsx(Ea,{children:(e==="minutes"?nb:rb).map(l=>o.jsxs(qn,{value:l.toString(),children:[l," ",e==="minutes"?"min":"hr"]},l))})]})]})]}),mte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-1",children:[o.jsx(ba,{className:"text-sm",children:"Cron Expression"}),o.jsx($t,{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 pte({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??Om()),[v,x]=p.useState(!1),b=p.useMemo(()=>FG.getTimezonesWithOffset().map(H=>({value:H.identifier,label:H.displayName,offset:H.offsetString,isDST:H.isDST})),[]),[w,C]=p.useState(()=>tb(e,m)),[E,R]=p.useState(""),[T,j]=p.useState("");p.useEffect(()=>{h(n)},[n]),p.useEffect(()=>{const H=t??Om();g(H)},[t]),p.useEffect(()=>{if(e){const H=tb(e,m);C(H)}},[e,m]);const O=H=>{const[$,I]=H.time.split(":").map(Number);switch(H.type){case"daily":return`${String(I)} ${String($)} * * *`;case"weekly":return`${String(I)} ${String($)} * * ${H.weekdays.join(",")}`;case"monthly":return`${String(I)} ${String($)} ${H.monthDays.join(",")} * *`;case"interval":return H.intervalType==="minutes"?`*/${String(H.intervalValue)} * * * *`:`0 */${String(H.intervalValue)} * * *`;case"custom":return H.customCron;default:return`${String(I)} ${String($)} * * *`}},D=p.useCallback(H=>{C($=>{if($.intervalType===H)return console.log("Type unchanged, skipping update"),$;const Y=(H==="minutes"?nb:rb)[0];return{...$,intervalType:H,intervalValue:Y}})},[]),_=p.useCallback(H=>{C($=>($.intervalType==="minutes"?nb:rb).includes(H)?{...$,intervalValue:H}:$)},[]),A=p.useMemo(()=>H=>DO(H,d),[d]);p.useEffect(()=>{const H=O(w);R(H),j(A(w))},[w,d,m,A]);const M=p.useRef(""),U=p.useRef(""),B=p.useRef(!1);p.useEffect(()=>{const H=O(w);r&&(M.current!==H||U.current!==m||B.current!==d)&&(r({cron:H,timezone:m,enabled:d}),M.current=H,U.current=m,B.current=d)},[w,m,d,r]);const G=H=>{h(H)},K=H=>{g(H),C($=>({...$,timezone:H}))},re=["daily","weekly","monthly"].includes(w.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(ba,{htmlFor:"schedule-enabled",className:"text-sm font-normal",children:d?"Enabled":"Disabled"}),o.jsx(_O,{id:"schedule-enabled",checked:d,onCheckedChange:G})]})]})}),o.jsxs("div",{className:"space-y-4 pt-0",children:[o.jsxs("div",{className:`space-y-4 ${d?"":"opacity-50"}`,children:[o.jsx(cte,{value:w.type,onChange:H=>{C($=>({...$,type:H}))},disabled:!d}),w.type!=="custom"&&w.type!=="interval"&&o.jsxs("div",{className:"flex gap-3",children:[o.jsx(ute,{value:w.time,onChange:H=>{C($=>({...$,time:H}))},disabled:!d}),re&&o.jsx(BT,{value:m,onChange:K,disabled:!d,timezones:b})]}),(w.type==="interval"||w.type==="custom")&&o.jsx(BT,{value:m,onChange:K,disabled:!d,timezones:b}),w.type==="weekly"&&o.jsx(dte,{value:w.weekdays,onChange:H=>{C($=>({...$,weekdays:H}))},disabled:!d}),w.type==="monthly"&&o.jsx(fte,{value:w.monthDays,onChange:H=>{C($=>({...$,monthDays:H}))},disabled:!d}),w.type==="interval"&&o.jsx(hte,{intervalType:w.intervalType,intervalValue:w.intervalValue,onTypeChange:D,onValueChange:_,disabled:!d}),w.type==="custom"&&o.jsx(mte,{value:w.customCron,onChange:H=>{C($=>({...$,customCron:H}))},disabled:!d})]}),l&&o.jsxs(o.Fragment,{children:[o.jsx(d_,{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(Wj,{className:"h-4 w-4"}),o.jsx("span",{className:"text-sm font-medium",children:"Preview"})]}),v?o.jsx(Us,{className:"text-muted-foreground h-4 w-4"}):o.jsx(Za,{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(Ar,{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(Ar,{variant:"secondary",className:"font-mono text-xs",children:E})]}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Timezone:"}),o.jsx(Ar,{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&&re&&m!==Om()&&o.jsxs(cS,{className:"border-amber-200 bg-amber-50",children:[o.jsx(Sf,{className:"h-4 w-4"}),o.jsx(iO,{children:"Time Zone"}),o.jsxs(uS,{children:["Schedule runs in ",m," (not your local ",Om()," ","time). Execution time may differ from expected."]})]})]})]})]}),c&&o.jsx(Ce,{className:"w-full",disabled:!d,children:"Save Schedule"})]})]})}function gte(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"trigger-type-options-description-details",children:[o.jsx(Yn,{children:"How do I choose a type?"}),o.jsxs(Wn,{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 vte(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"trigger-type-change-description-details",children:[o.jsx(Yn,{children:"How do I change the trigger type?"}),o.jsx(Wn,{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 yte(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"report-change-description-details",children:[o.jsx(Yn,{children:"How do I change a report?"}),o.jsx(Wn,{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 xte(){return o.jsx(hr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Kn,{value:"report-select-description-details",children:[o.jsx(Yn,{children:"How do I choose the report?"}),o.jsxs(Wn,{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 bte({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}=Xee({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:async E=>{d(!0);try{await r(E)}finally{d(!1)}}});p.useEffect(()=>{l==null||l(v)},[v,l]);const{control:x,watch:b}=h,C=b("type")===xn.REPORT_RUN;return o.jsx(Zl,{...h,children:o.jsxs(Bi,{onSubmit:E=>void g(E),noValidate:!1,children:[o.jsxs(Kl,{children:[o.jsx(Qt,{control:x,name:"type",render:({field:E})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Choose what you want this trigger to run - a report or a connector",children:"Trigger Type"}),o.jsxs(Sa,{onValueChange:R=>{E.onChange(R),m(R)},defaultValue:E.value,disabled:!!n||!!e||!!b("triggerConfig.reportId"),children:[o.jsx(en,{children:o.jsx(wa,{className:"w-full",children:o.jsx(Ca,{placeholder:"Select trigger type"})})}),o.jsxs(Ea,{children:[o.jsx(qn,{value:xn.REPORT_RUN,children:"Report Run"}),o.jsx(qn,{value:xn.CONNECTOR_RUN,children:"Connector Run"})]})]}),o.jsx(ar,{children:e?o.jsx(vte,{}):o.jsx(gte,{})}),o.jsx(ln,{})]})}),C&&o.jsx(Qt,{control:x,name:"triggerConfig.reportId",render:({field:E})=>o.jsxs(Xt,{children:[o.jsx(Jt,{tooltip:"Select the report that will be run by this trigger",children:"Report"}),o.jsx(en,{children:o.jsx(E4,{children:o.jsx(Jee,{value:E.value,onChange:E.onChange,disabled:!!t||!!e})})}),o.jsx(ar,{children:e!=null&&e.triggerConfig?o.jsx(yte,{}):o.jsx(xte,{})}),o.jsx(ln,{})]})}),o.jsx(pte,{showPreview:!1,cron:b("cronExpression"),timezone:b("timeZone"),enabled:b("isActive"),onChange:E=>{h.setValue("cronExpression",E.cron,{shouldDirty:!0}),h.setValue("timeZone",E.timezone,{shouldDirty:!0}),h.setValue("isActive",E.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(Yl,{children:[o.jsx(Ce,{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(Ce,{variant:"outline",type:"button",onClick:s,className:"w-full","aria-label":"Cancel",children:"Cancel"})]})]})})}function Ste({cronExpression:e,timeZone:t,isEnabled:n=!0}){const r=p.useMemo(()=>ite(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 Cte({table:e}){return o.jsx("div",{className:"text-right",children:o.jsxs(Cr,{children:[o.jsx(wr,{asChild:!0,children:o.jsx(Ce,{variant:"ghost",className:"dm-card-table-body-row-actionbtn","aria-label":"Toggle columns",children:o.jsx(Ka,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsx(Er,{align:"end",children:e.getAllColumns().filter(t=>t.getCanHide()&&t.id!=="actions").map(t=>o.jsx(bt,{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(dr,{className:"size-3.5 text-white"})})}),o.jsx("span",{children:t.columnDef.meta.title??t.id})]})},t.id))})]})})}function wte({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(Cr,{open:r,onOpenChange:s,children:[o.jsx(wr,{asChild:!0,children:o.jsx(Ce,{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(Ka,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsxs(Er,{align:"end",children:[o.jsxs(bt,{onClick:()=>{t(e.id)},children:[o.jsx(Cf,{className:"text-foreground h-4 w-4","aria-hidden":"true"}),"Edit trigger"]}),o.jsx(Ga,{}),o.jsxs(bt,{onClick:()=>{c(!0)},children:[o.jsx(ko,{className:"h-4 w-4 text-red-600","aria-hidden":"true"}),o.jsx("span",{className:"text-red-600",children:"Delete trigger"})]})]})]}),o.jsx(xa,{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 Ete(e,t){const n=t.find(r=>r.name===e.source.name);return(n==null?void 0:n.displayName)??e.source.name}function Rte({connector:e}){const{connectors:t}=ql(),n=Ete(e,t);return o.jsx(o.Fragment,{children:n})}function OO({connector:e}){return o.jsx(Rte,{connector:e})}function Tte(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 jte=e=>{const{connectors:t}=ql();return p.useMemo(()=>t.find(n=>n.name===e),[t,e])},_te=je.memo(function({connector:t,children:n}){const r=jte(t.source.name),{dataMart:s,runs:l,getDataMartRuns:c}=Hi();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(Ff,{base64:r.logoBase64,size:20}):null,[r==null?void 0:r.logoBase64]),h=p.useCallback(()=>{s!=null&&s.storage&&gq(s.storage,t.storage.fullyQualifiedName)},[s==null?void 0:s.storage,t.storage.fullyQualifiedName]),m=p.useMemo(()=>Tte(l),[l]),g=p.useMemo(()=>!m.lastRunDate||!m.lastRunStatus?null:{statusType:OZ(m.lastRunStatus),statusText:kZ(m.lastRunStatus),date:m.lastRunDate},[m]),v=p.useMemo(()=>(s==null?void 0:s.storage)&&vq(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(g1,{children:[o.jsx(v1,{asChild:!0,children:o.jsx("span",{children:n})}),o.jsxs(y1,{children:[o.jsxs(x1,{children:[o.jsx(b1,{children:d}),o.jsxs(S1,{children:[o.jsx(C1,{children:o.jsx(OO,{connector:t})}),o.jsx(w1,{children:x})]})]}),o.jsxs(E1,{children:[o.jsxs(gi,{children:[o.jsx(vi,{children:"Last run status:"}),o.jsx(yi,{children:g?o.jsx(Vf,{type:g.statusType,variant:"ghost",children:g.statusText}):"Not run yet"})]}),o.jsxs(gi,{children:[o.jsx(vi,{children:"Last run date:"}),o.jsx(yi,{children:g?o.jsx(kl,{date:g.date}):"Never run"})]}),o.jsxs(gi,{children:[o.jsx(vi,{children:"Total runs:"}),o.jsxs(yi,{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(R1,{children:o.jsxs(Ce,{className:"w-full",variant:"default",onClick:h,title:"Open Storage","aria-label":"Open Storage",children:[v,o.jsx(Tl,{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 Nte(e){const t=e.triggerConfig;return o.jsxs("div",{className:"inline gap-1",children:[t.report.title,o.jsx(AZ,{report:t.report,children:o.jsx(Fr,{className:"ml-1 inline-block h-4 w-4 align-text-bottom opacity-0 transition-opacity duration-200 group-hover:opacity-100"})})]})}function Ate(e){const t=e.triggerConfig,{connector:n}=t.connector;return o.jsxs("div",{className:"inline gap-1",children:[o.jsx(OO,{connector:n}),o.jsx(_te,{connector:n,children:o.jsx(Fr,{className:"ml-1 inline-block h-4 w-4 align-text-bottom opacity-0 transition-opacity duration-200 group-hover:opacity-100"})})]})}function Dte({trigger:e}){switch(e.type){case xn.REPORT_RUN:return Nte(e);case xn.CONNECTOR_RUN:return Ate(e);default:return o.jsx("div",{className:"text-muted-foreground text-sm",children:"—"})}}function Ote({onEditTrigger:e,onDeleteTrigger:t}){return[{accessorKey:"type",size:150,header:"Trigger Type",cell:({row:n})=>{const s=n.getValue("type")===xn.REPORT_RUN?"Report Run":"Connector Run";return o.jsx(Ar,{variant:"outline",children:s})},meta:{title:"Trigger Type"}},{accessorKey:"triggerConfig",size:35,header:"Run Target",cell:({row:n})=>o.jsx(Dte,{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(Ste,{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(kl,{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(kl,{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(Vf,{type:r?Tn.SUCCESS:Tn.NEUTRAL,variant:"ghost",showIcon:!1,children:r?"Enabled":"Disabled"})},meta:{title:"Trigger Status"}},{id:"actions",size:80,header:({table:n})=>o.jsx(Cte,{table:n}),cell:({row:n})=>o.jsx(wte,{trigger:n.original,onEditTrigger:e,onDeleteTrigger:t}),meta:{title:"Actions"}}]}function Mte({table:e,onPreviousClick:t,onNextClick:n}){return o.jsxs("div",{className:"dm-card-pagination",role:"navigation","aria-label":"Table pagination",children:[o.jsx(Ce,{variant:"outline",size:"sm",onClick:t,disabled:!e.getCanPreviousPage(),"aria-label":"Go to previous page",children:"Previous"}),o.jsx(Ce,{variant:"outline",size:"sm",onClick:n,disabled:!e.getCanNextPage(),"aria-label":"Go to next page",children:"Next"})]})}function hS({isOpen:e,onClose:t,dataMartId:n,preSelectedReportId:r,preSelectedType:s}){const{createScheduledTrigger:l,updateScheduledTrigger:c,selectedTrigger:d}=CO(),[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]),w=p.useCallback(O=>{v(O)},[]),C=p.useCallback(()=>{v(!1),t()},[t]),E=!!d,R=p.useMemo(()=>d?{type:d.type,cronExpression:d.cronExpression,timeZone:d.timeZone,isActive:d.isActive,triggerConfig:d.type===xn.REPORT_RUN?{type:Kc.SCHEDULED_REPORT_RUN,reportId:d.triggerConfig.reportId}:null}:void 0,[d]),T=async O=>{E?await c(n,d.id,O.cronExpression,O.timeZone,O.isActive):await l(n,O.type,O.cronExpression,O.timeZone,O.isActive,O.triggerConfig),C()},j=p.useRef(!1);return p.useEffect(()=>{const O=E?"Edit":"Create",D=(d==null?void 0:d.type)??s;e&&!j.current?(Fe({event:"scheduled_trigger_config_open",category:"ScheduledTrigger",action:O,label:D}),j.current=!0):!e&&j.current&&(Fe({event:"scheduled_trigger_config_close",category:"ScheduledTrigger",action:O,label:D}),j.current=!1)},[e,E,d,s]),o.jsxs(o.Fragment,{children:[o.jsx(Mi,{open:e,onOpenChange:O=>{O||x()},children:o.jsxs(ki,{children:[o.jsxs(Ii,{children:[o.jsxs(Li,{children:[E?"Edit":"Create"," Scheduled Trigger"]}),o.jsx(Hl,{children:"Configure automatic runs for your reports or connectors."})]}),o.jsx(bte,{preSelectedReportId:r,preSelectedType:s,initialData:R,onSubmit:T,onCancel:x,onDirtyChange:w})]})}),o.jsx(xa,{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 kte({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(()=>Ote({onEditTrigger:n,onDeleteTrigger:d}),[n,d]),{sorting:m,setSorting:g,columnVisibility:v,setColumnVisibility:x}=Bf({columns:h,storageKeyPrefix:"data-mart-scheduled-triggers",defaultSortingColumn:"type"}),b=Tu({data:e,columns:h,getCoreRowModel:Ru(),getPaginationRowModel:Eg(),onSortingChange:g,getSortedRowModel:$f(),getFilteredRowModel:Hf(),state:{sorting:m,columnVisibility:v},onColumnVisibilityChange:x,enableGlobalFilter:!0,enableColumnResizing:!1}),w=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(ju,{id:"scheduled-triggers-table",className:"dm-card-table",role:"table","aria-label":"Scheduled Triggers",children:[o.jsx(_u,{className:"dm-card-table-header",children:b.getHeaderGroups().map(R=>o.jsx(sr,{className:"dm-card-table-header-row",children:R.headers.map(T=>o.jsx(Au,{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(Nu,{className:"dm-card-table-body",children:b.getRowModel().rows.length?b.getRowModel().rows.map((R,T)=>o.jsx(sr,{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(ya,{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(sr,{children:o.jsx(ya,{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(Mte,{table:b,onPreviousClick:w,onNextClick:C}),o.jsx(hS,{isOpen:s,onClose:c,dataMartId:t})]})}function Ite({dataMartId:e}){const{triggers:t,deleteScheduledTrigger:n,selectScheduledTrigger:r,selectedTrigger:s}=Kee(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(kte,{triggers:t,dataMartId:e,onEditTrigger:d,onDeleteTrigger:g=>void m(g)}),o.jsx(hS,{isOpen:l,onClose:h,dataMartId:e})]})}function MO(){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(Xj,{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:["Set up automatic runs in the ",o.jsx("span",{className:"font-medium",children:"Triggers"})," tab once you’ve saved and published this Data Mart."]})]})]})})}function Lte({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,w]=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",E=p.useCallback((j,O,D,_)=>{s({fullyQualifiedName:`${j}.${O}`,isValid:!!(j&&O&&D===null&&_===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),_=C(O);h(j),g(O),x(D),w(_);const A=`${j}.${O}`,M=!!(j&&O&&D===null&&_===null);((t==null?void 0:t.fullyQualifiedName)!==A||t.isValid!==M)&&E(j,O,D,_)},[t,l,c,E]);const R=j=>{h(j);const O=C(j);x(O),E(j,m,O,b)},T=j=>{g(j);const O=C(j);w(O),E(d,j,v,O)};return o.jsxs(Ro,{children:[e===Pe.GOOGLE_BIGQUERY&&o.jsxs(o.Fragment,{children:[o.jsx(Di,{icon:o.jsx(VA,{}),title:"Google BigQuery",docUrl:"https://docs.owox.com/docs/storages/supported-storages/google-bigquery/",variant:"compact"}),o.jsxs(wl,{title:"Choose where to store your data",children:[o.jsxs($d,{children:[o.jsx(wo,{required:!0,htmlFor:"dataset-name",tooltip:"Enter dataset name for Google BigQuery where the connector data will be stored.",children:"Dataset name"}),o.jsx($t,{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}),o.jsx("p",{className:"text-muted-foreground text-sm",children:"Dataset is auto-created on first run if it doesn’t exist"}),v&&o.jsx("p",{id:"dataset-name-error",className:"text-destructive text-sm",children:v})]}),o.jsxs($d,{children:[o.jsx(wo,{required:!0,htmlFor:"table-name",tooltip:"Enter table name where the connector data will be stored.",children:"Table name"}),o.jsx($t,{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}),o.jsx("p",{className:"text-muted-foreground text-sm",children:"Table is auto-created on first run if it doesn’t exist"}),b&&o.jsx("p",{id:"table-name-error",className:"text-destructive text-sm",children:b})]})]})]}),e===Pe.AWS_ATHENA&&o.jsxs(o.Fragment,{children:[o.jsx(Di,{icon:o.jsx(HA,{}),title:"AWS Athena",docUrl:"https://docs.owox.com/docs/storages/supported-storages/aws-athena/",variant:"compact"}),o.jsxs(wl,{title:"Choose where to store your data",children:[o.jsxs($d,{children:[o.jsx(wo,{required:!0,htmlFor:"database-name",tooltip:"Enter database name for Amazon Athena where the connector data will be stored.",children:"Database name"}),o.jsx($t,{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}),o.jsx("p",{className:"text-muted-foreground text-sm",children:"Database is auto-created on first run if it doesn’t exist"}),v&&o.jsx("p",{id:"database-name-error",className:"text-destructive text-sm",children:v})]}),o.jsxs($d,{children:[o.jsx(wo,{required:!0,htmlFor:"athena-table-name",tooltip:"Enter table name where the connector data will be stored.",children:"Table name"}),o.jsx($t,{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}),o.jsx("p",{className:"text-muted-foreground text-sm",children:"Table is auto-created on first run if it doesn’t exist"}),b&&o.jsx("p",{id:"athena-table-name-error",className:"text-destructive text-sm",children:b})]})]})]}),o.jsx(wl,{title:"Schedule updates",children:o.jsx(MO,{})})]})}function Pte({onSubmit:e,dataStorageType:t,configurationOnly:n=!1,existingConnector:r=null,mode:s="full",initialStep:l,preselectedConnector:c}){const[d,h]=p.useState(null),[m,g]=p.useState(""),[v,x]=p.useState([]),[b,w]=p.useState(1),[C,E]=p.useState({}),[R,T]=p.useState(!1),[j,O]=p.useState(new Set),[D,_]=p.useState(new Set),{connectors:A,connectorSpecification:M,connectorFields:U,loading:B,loadingSpecification:G,loadingFields:K,error:re,fetchAvailableConnectors:H,fetchConnectorSpecification:$,fetchConnectorFields:I}=ql(),[Y,Z]=p.useState(null),be=(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,L=p.useCallback(async Ie=>{!j.has(Ie)&&!G&&(O(wt=>new Set(wt).add(Ie)),await $(Ie))},[j,G,$]),P=p.useCallback(async Ie=>{D.has(Ie)||(_(wt=>new Set(wt).add(Ie)),await I(Ie))},[D,I]);p.useEffect(()=>{if(!c||d||A.length===0)return;const Ie=A.find(wt=>wt.name===c);Ie&&(h(Ie),w(l??2),L(Ie.name),!n&&s!=="fields-only"&&P(Ie.name))},[c,A,d,l,n,s,L,P]),p.useEffect(()=>{if(A.length===0&&!B&&H(),r&&A.length>0&&!d){const{source:Ie,storage:wt}=r;g(Ie.node),x(Ie.fields),E(Ie.configuration[0]||{}),Z({fullyQualifiedName:wt.fullyQualifiedName,isValid:!0});const Ot=A.find(tn=>tn.name===Ie.name);Ot&&(h(Ot),L(Ot.name),!n&&s!=="fields-only"&&P(Ot.name),s==="fields-only"&&P(Ot.name))}if(n&&A.length>0&&!d&&!r){const Ie=A[0];h(Ie),L(Ie.name)}},[s,r,A,n,B,H,L,P,d]);const W=Ie=>{h(Ie),E({}),T(!1),O(wt=>{const Ot=new Set(wt);return Ot.delete(Ie.name),Ot}),L(Ie.name),P(Ie.name)},ae=Ie=>{g(Ie),x([])},fe=(Ie,wt)=>{x(wt?Ot=>Ot.includes(Ie)?Ot:[...Ot,Ie]:Ot=>Ot.filter(tn=>tn!==Ie))},ge=(Ie,wt)=>{x(wt?Ot=>{const tn=Ie.filter(V=>!Ot.includes(V));return[...Ot,...tn]}:Ot=>Ot.filter(tn=>!Ie.includes(tn)))},ue=Ie=>{Z(Ie)},Ne=p.useCallback(Ie=>{E(Ie)},[]),Re=p.useCallback(Ie=>{T(Ie)},[]);p.useEffect(()=>{M&&(M.some(wt=>wt.required&&wt.name!=="Fields")||T(!0))},[M]);const xe=()=>{b<be&&w(b+1)},et=()=>{b>1&&w(b-1)},Xe=()=>{if(n)return d!==null&&R;if(s==="fields-only")switch(b){case 1:return v.length>0;default:return!1}switch(b){case 1:return d!==null;case 2:return R;case 3:return m!=="";case 4:return v.length>0;case 5:return Y!==null&&Y.fullyQualifiedName!==""&&Y.isValid;default:return!1}},Bt=()=>b>1,ft=(Ie,wt)=>{if(!Ie)return wt;const Ot=Ie.find(tn=>tn.name===wt);return(Ot==null?void 0:Ot.destinationName)??wt},gn=()=>{if(n&&b===1)return M&&d?o.jsx(HT,{connector:d,connectorSpecification:M,onConfigurationChange:Ne,onValidationChange:Re,initialConfiguration:C,loading:G,isEditingExisting:!!(r!=null&&r.source.configuration.length)}):null;if(s==="fields-only")switch(b){case 1:return d&&m&&U?o.jsx($T,{connector:d,connectorFields:U,selectedField:m,selectedFields:v,onFieldToggle:fe,onSelectAllFields:ge}):null;default:return null}switch(b){case 1:return o.jsx(Aee,{connectors:A,selectedConnector:d,loading:B,error:re,onConnectorSelect:W,onConnectorDoubleClick:()=>{w(Ie=>Ie<be?Ie+1:Ie)}});case 2:return d&&M?o.jsx(HT,{connector:d,connectorSpecification:M,onConfigurationChange:Ne,onValidationChange:Re,initialConfiguration:C,loading:G,isEditingExisting:!1}):null;case 3:return d&&U?o.jsx($ee,{connectorFields:U,connector:d,selectedField:m,connectorName:d.displayName,loading:K,onFieldSelect:ae}):null;case 4:return d&&m&&U?o.jsx($T,{connector:d,connectorFields:U,selectedField:m,selectedFields:v,onFieldToggle:fe,onSelectAllFields:ge}):null;case 5:return m&&U?o.jsx(Lte,{dataStorageType:t,destinationName:ft(U,m),connectorName:(d==null?void 0:d.displayName)??"",target:Y,onTargetChange:ue}):null;default:return null}};return o.jsxs(wee,{children:[o.jsx(Eee,{children:gn()}),o.jsx(Ree,{variant:"horizontal",children:o.jsx(Dee,{currentStep:b,totalSteps:be,canGoNext:Xe(),canGoBack:Bt(),isLoading:G||K,onNext:xe,onBack:et,onFinish:()=>{n&&d?e({source:{name:d.name,configuration:[C],node:(r==null?void 0:r.source.node)??m,fields:(r==null?void 0:r.source.fields)??v},storage:(r==null?void 0:r.storage)??{fullyQualifiedName:(r==null?void 0:r.storage.fullyQualifiedName)??""}}):s==="fields-only"&&r?e({source:{...r.source,fields:v},storage:r.storage}):d&&Y&&e({source:{name:d.name,configuration:[C],node:m,fields:v},storage:{fullyQualifiedName:Y.fullyQualifiedName}})}})})]})}const kO=20,IO=20;function LO({vertical:e,horizontal:t}){if(window.Intercom)try{const n={};n.vertical_padding=e,n.horizontal_padding=t,Object.keys(n).length>0&&window.Intercom("update",n)}catch(n){console.warn("Failed to update Intercom padding",n)}}function Ute(e=30,t=0){LO({vertical:IO+e,horizontal:kO+t})}function ab(){LO({vertical:IO,horizontal:kO})}function PO({isOpen:e,onClose:t,dataStorageType:n,onSubmit:r,configurationOnly:s=!1,existingConnector:l=null,mode:c="full",initialStep:d,preselectedConnector:h}){return p.useEffect(()=>(e?Ute(55):ab(),()=>{ab()}),[e]),o.jsx(Mi,{open:e,onOpenChange:t,children:o.jsxs(ki,{children:[o.jsxs(Ii,{children:[o.jsx(Li,{children:c==="fields-only"?"Connector Fields":l!=null&&l.source.name?"Edit Connector":"Set Up Connector"}),o.jsx(Hl,{children:c==="fields-only"?"Select fields for your Data Mart":l!=null&&l.source.name?"Update configuration":"Follow these steps to set it up"})]}),o.jsx(Pte,{onSubmit:m=>{r(m),t()},dataStorageType:n,configurationOnly:s||c==="configuration-only",existingConnector:l,mode:c,initialStep:d,preselectedConnector:h})]})})}const mS=({dataStorageType:e,onSubmit:t,children:n,configurationOnly:r=!1,existingConnector:s=null,preset:l,isOpen:c,onClose:d})=>{const[h,m]=p.useState(!1),[g,v]=p.useState(1),[x,b]=p.useState();p.useEffect(()=>{c!==void 0&&m(c)},[c]);const w=()=>{b(void 0),v(1),m(!0)},C=()=>{m(!1),d==null||d()};return p.useEffect(()=>{l&&(l==="connector"?(b(void 0),v(1),m(!0)):(b(l),v(2),m(!0)))},[l]),o.jsxs(o.Fragment,{children:[n&&o.jsx("div",{onClick:w,style:{cursor:"pointer"},children:n}),o.jsx(hu,{children:o.jsx(PO,{isOpen:h,onClose:C,dataStorageType:e,onSubmit:t,configurationOnly:r,existingConnector:s,initialStep:g,preselectedConnector:x})})]})};function Fte({storageType:e,onSetupConnector:t,preset:n,isOpen:r,onClose:s}){return o.jsx(mS,{dataStorageType:e,onSubmit:t,configurationOnly:!1,preset:n,isOpen:r,onClose:s,children:o.jsxs(Ce,{type:"button",variant:"outline",className:"flex h-24 w-full cursor-pointer items-center justify-center gap-2 border-0 shadow-none dark:border-transparent dark:bg-transparent dark:hover:bg-white/4",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(Eb,{className:"h-4 w-4",strokeWidth:2.25})}),o.jsx("span",{children:"Setup Connector"}),o.jsx(Ra,{className:"h-6 w-6"})]})})}const zte=e=>{switch(e){case Pe.GOOGLE_BIGQUERY:return"Google BigQuery";case Pe.AWS_ATHENA:return"AWS Athena";default:return e}},qc=e=>typeof e=="object"&&"connector"in e,Pd=e=>{if(!qc(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 Vte({configIndex:e,connectorDef:t,onRemoveConfiguration:n,onUpdateConfiguration:r,dataMartStatus:s,totalConfigurations:l,dataStorage:c}){const d=Vi.getInfo(c.type),{connectors:h,fetchAvailableConnectors:m}=ql();p.useEffect(()=>{m()},[m]);const g=C=>{const E=h.find(R=>R.name===C);if(E!=null&&E.logoBase64)return()=>o.jsx(Ff,{base64:E.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:"Data:"})," ",o.jsx("span",{className:"text-muted-foreground font-medium",children:C}),o.jsx("span",{className:"text-muted-foreground",children:"•"}),o.jsxs(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsxs("span",{className:"text-muted-foreground flex items-center gap-1 font-medium",children:[o.jsx("span",{children:"Edit config"}),o.jsx(Ra,{className:"h-3 w-3"})]})}),o.jsx(_t,{children:"Edit connector configuration"})]})]})},x=(C,E,R)=>o.jsxs("span",{children:[o.jsxs("span",{className:"text-muted-foreground/75",children:[C,":"]})," ",o.jsx(fr,{href:R,onClick:T=>{T.stopPropagation()},children:E})]}),b=()=>{switch(c.type){case Pe.GOOGLE_BIGQUERY:{const C=c.config.projectId,E=t.connector.storage.fullyQualifiedName,R=E.split(".")[0],T=E.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(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsx(Fr,{className:"h-4 w-4"})}),o.jsx(_t,{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,E=t.connector.storage.fullyQualifiedName,[R,T]=E.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(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsx(Fr,{className:"h-4 w-4"})}),o.jsx(_t,{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"}},w=()=>!(s===ur.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(mS,{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:zte(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(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsx(Ce,{type:"button",variant:"ghost",onClick:()=>{w()&&n(e)},disabled:!w(),children:o.jsx(ko,{className:"h-4 w-4"})})}),!w()&&o.jsx(_t,{children:"Cannot remove the last configuration in published pipeline"})]})})]})}function Hte({storageType:e,onAddConfiguration:t,existingConnector:n}){return o.jsx("div",{children:o.jsx(mS,{dataStorageType:e,onSubmit:r=>{const s=r.source.configuration[0]||{};t(s)},configurationOnly:!0,existingConnector:n?{source:{...n.source,configuration:[]},storage:n.storage}:void 0,children:o.jsxs(Ce,{type:"button",variant:"outline",className:"dm-card-table-add-field-btn cursor-pointer",children:[o.jsx(Ta,{className:"h-4 w-4"}),o.jsx("span",{children:"Configuration"})]})})})}function $te({control:e,storageType:t,preset:n,autoOpen:r=!1}){const{dataMart:s,runDataMart:l}=gs(),{setValue:c,getValues:d,trigger:h}=Du(),[m,g]=p.useState(!1),[v,x]=p.useState(!1);p.useEffect(()=>{r&&x(!0)},[r]);const b=()=>{setTimeout(()=>void h("definition"),0)},w=(s==null?void 0:s.status)??ur.DRAFT,C=A=>{const M=A.source,U=A.storage;c("definition",{connector:{source:M,storage:U}},{shouldDirty:!0,shouldTouch:!0}),b()},E=async A=>{if(s){if(s.status.code!==ur.PUBLISHED){Dt.error("Manual run is only available for published data marts");return}await l({id:s.id,payload:A})}},R=A=>M=>{const B=d().definition;if(typeof B=="object"&&qc(B)){const G=[...B.connector.source.configuration];G[A]=M.source.configuration[0]||{};const K={connector:{...B.connector,source:{...B.connector.source,configuration:G}}};c("definition",K,{shouldDirty:!0,shouldTouch:!0}),b()}},T=A=>{const U=d().definition;if(typeof U=="object"&&qc(U)){const B={connector:{...U.connector,source:{...U.connector.source,fields:A.source.fields}}};c("definition",B,{shouldDirty:!0,shouldTouch:!0}),b()}g(!1)},j=A=>{E({runType:A.runType,data:A.data})},O=A=>{const M=A.connector.source.fields.length;return o.jsxs(Ce,{type:"button",variant:"outline",onClick:()=>{g(!0)},className:"dm-card-table-add-field-btn cursor-pointer",children:[o.jsx(uL,{className:"h-4 w-4"}),o.jsxs("span",{children:["Edit Fields (",String(M),")"]})]})},D=A=>{const U=d().definition;if(qc(U)&&U.connector.source.configuration.length<=1){const B=X0(qe.CONNECTOR);c("definition",B,{shouldDirty:!0,shouldTouch:!0}),b()}if(typeof U=="object"&&qc(U)&&U.connector.source.configuration.length>1){const B={...U.connector.source,configuration:U.connector.source.configuration.filter((K,re)=>re!==A)},G={connector:{...U.connector,source:B}};c("definition",G,{shouldDirty:!0,shouldTouch:!0}),b()}},_=A=>{const U=d().definition;if(qc(U)){const B={...U.connector.source,configuration:[...U.connector.source.configuration,A]},G={connector:{...U.connector,source:B}};c("definition",G,{shouldDirty:!0,shouldTouch:!0}),b()}};return o.jsxs(o.Fragment,{children:[o.jsx(Qt,{control:e,name:"definition",render:({field:A})=>o.jsxs(Xt,{className:"dark:bg-white/2",children:[o.jsx(en,{children:o.jsx("div",{className:"space-y-3",children:!Pd(A.value)||w===ur.DRAFT?o.jsx(Fte,{storageType:t,onSetupConnector:C,preset:n,isOpen:v,onClose:()=>{x(!1)}}):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(Hte,{storageType:t,onAddConfiguration:_,existingConnector:Pd(A.value)?{source:A.value.connector.source,storage:A.value.connector.storage}:void 0}),Pd(A.value)&&O(A.value)]}),o.jsx("div",{className:"flex items-center gap-2",children:s&&s.definitionType===qe.CONNECTOR&&o.jsx(uD,{configuration:s.definition,onManualRun:j,children:o.jsxs(Ce,{variant:"outline",children:[o.jsx(wb,{className:"h-4 w-4"}),o.jsx("span",{children:"Manual Run..."})]})})})]}),o.jsx("div",{className:"space-y-3",children:Pd(A.value)&&(s!=null&&s.storage)?A.value.connector.source.configuration.map((M,U)=>{const B=A.value;return o.jsx(hu,{children:o.jsx(Vte,{configIndex:U,connectorDef:B,dataStorage:s.storage,onRemoveConfiguration:D,onUpdateConfiguration:R,dataMartStatus:typeof w=="object"?w.code:w,totalConfigurations:B.connector.source.configuration.length},U)},U)}):null})]})})}),o.jsx(ln,{})]})}),o.jsx(hu,{children:o.jsx(PO,{isOpen:m,onClose:()=>{g(!1)},onSubmit:T,dataStorageType:t,existingConnector:Pd(d().definition)?{source:d().definition.connector.source,storage:d().definition.connector.storage}:void 0,mode:"fields-only"})})]})}function Bte({definitionType:e,storageType:t,preset:n}){const{control:r}=Du(),[s,l]=p.useState(!1);return p.useEffect(()=>{e===qe.CONNECTOR&&!n?l(!0):l(!1)},[e,n]),o.jsxs("div",{className:"space-y-2",children:[e===qe.SQL&&o.jsx(see,{control:r}),e===qe.TABLE&&o.jsx(oee,{control:r,storageType:t}),e===qe.VIEW&&o.jsx(iee,{control:r,storageType:t}),e===qe.TABLE_PATTERN&&o.jsx(lee,{control:r,storageType:t}),e===qe.CONNECTOR&&o.jsx($te,{control:r,storageType:t,preset:n,autoOpen:s})]})}function UO(){const[e]=gI(),t=e.get("preset");return p.useMemo(()=>{if(!t)return;const n=t.toLowerCase();return oY(n)},[t])}function Gte(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 qte(e,t){const[n,r]=p.useState(e);return p.useEffect(()=>{const s=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(s)}},[e,t]),n}const Zte=1e3,Kte=[Cl.SUCCESS,Cl.ERROR,Cl.CANCELLED];function Yte(e){const[t,n]=p.useState(!1),[r,s]=p.useState(null),l=p.useRef({triggerId:null,abortController:null}),c=p.useCallback(v=>l.current.triggerId===v,[]),d=p.useCallback(v=>{s({isValid:!1,error:v instanceof Error?v.message:"Validation failed"}),n(!1)},[]),h=p.useCallback(async()=>{const{triggerId:v,abortController:x}=l.current;if(v){x==null||x.abort(),l.current={triggerId:null,abortController:null},s(null),n(!1);try{await rn.abortSqlDryRunTrigger(e,v)}catch(b){console.error("Failed to cancel trigger:",b)}}},[e]),m=p.useCallback(async(v,x)=>{for(;!x.aborted&&c(v);)try{const b=await rn.getSqlDryRunTriggerStatus(e,v);if(Kte.includes(b)){const w=await rn.getSqlDryRunTriggerResponse(e,v);s({isValid:w.isValid,error:w.error??void 0,bytes:w.bytes}),n(!1),l.current={triggerId:null,abortController:null};return}await new Promise(w=>setTimeout(w,Zte))}catch(b){d(b),l.current={triggerId:null,abortController:null};return}},[e,c,d]),g=p.useCallback(async v=>{await h(),n(!0),s(null);try{const{triggerId:x}=await rn.createSqlDryRunTrigger(e,v),b=new AbortController;l.current={triggerId:x,abortController:b},await m(x,b.signal)}catch(x){d(x)}},[e,h,m,d]);return p.useEffect(()=>()=>{const{triggerId:v,abortController:x}=l.current;x==null||x.abort(),v&&rn.abortSqlDryRunTrigger(e,v).catch(()=>{})},[e]),{validateSql:g,isLoading:t,result:r,cancel:h}}const Wte=300;function Qte({sql:e,dataMartId:t,debounceDelay:n=Wte,className:r="",onValidationStateChange:s}){const l=qte(e.trim(),n),{validateSql:c,isLoading:d,result:h,cancel:m}=Yte(t);p.useEffect(()=>{if(!l){m();const v={isLoading:!1,isValid:null,error:null,bytes:null};s==null||s(v);return}c(l)},[l,c,m,s]),p.useEffect(()=>{const v={isLoading:d,isValid:(h==null?void 0:h.isValid)??null,error:(h==null?void 0:h.error)??null,bytes:(h==null?void 0:h.bytes)??null};s==null||s(v)},[d,h,s]);const g=()=>d?o.jsxs("div",{className:"flex h-5 items-center gap-2",children:[o.jsx(gu,{className:"h-4 w-4 animate-spin"}),o.jsx("span",{className:"text-sm",children:"Validating..."})]}):h?h.isValid?o.jsxs("div",{className:"flex h-5 items-center gap-2",children:[o.jsx(qj,{className:"h-4 w-4 text-green-600"}),o.jsx("span",{className:"text-sm font-medium text-green-600",children:"Valid SQL code"}),h.bytes!==void 0&&o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"mx-1 text-gray-400",children:"•"}),o.jsxs(Tt,{children:[o.jsx(jt,{asChild:!0,children:o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx(Jm,{className:"h-3 w-3 text-gray-600"}),o.jsx("span",{className:"text-xs text-gray-600",children:Gte(h.bytes)})]})}),o.jsx(_t,{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(ef,{className:"h-4 w-4 flex-shrink-0 text-red-600"}),h.error&&o.jsx("span",{className:"text-xs text-red-500",children:h.error})]}):o.jsxs("div",{className:"flex h-5 items-center gap-2 text-gray-500",children:[o.jsx(Jm,{className:"h-4 w-4"}),o.jsx("span",{className:"text-sm",children:"Type a query to get started"})]});return o.jsx("div",{className:`inline-flex h-9 items-center px-3 py-2 ${r}`,children:g()})}function Xte(){const{dataMart:e,updateDataMartDefinition:t,getDataMart:n}=gs(),r=UO();if(!e)throw new Error("Data mart not found");const{definitionType:s,definition:l,id:c,storage:{type:d}}=e,[h,m]=p.useState(s),[,g]=p.useState({isValid:null,isLoading:!1,error:null}),v=p.useCallback(()=>{if(!h)return;const $={definitionType:h,definition:X0(h)};return l?{definitionType:h,definition:l}:$},[h,l]),x=p.useCallback(()=>{if(!h)return;const $=aee(h,d);return Wl($)},[h,d]),b=$i({resolver:x(),defaultValues:v(),mode:"onChange"}),{handleSubmit:w,reset:C,watch:E,formState:{isDirty:R,isValid:T}}=b,j=($,I)=>{if($!==qe.SQL)return"";const Y=I;return(Y==null?void 0:Y.sqlQuery)??""},O=E("definition"),D=j(h,O);p.useEffect(()=>{h&&C(v())},[h,C,v]);const _=$=>X0($);p.useEffect(()=>{if(!h&&!s&&(r!=null&&r.definitionType)){m(r.definitionType);const $={definitionType:r.definitionType,definition:_(r.definitionType)};C($)}},[r,h,s,C]);const A=p.useCallback($=>{g({isLoading:$.isLoading,isValid:$.isValid,error:$.error})},[]),M=$=>{m($)},U=p.useCallback(()=>{c&&n(c)},[c,n]),{run:B}=q1(c,U),G=async $=>{if(h&&c)try{await t(c,$.definitionType,$.definition),await B(),C($)}catch(I){console.error("Failed to update data mart definition:",I)}},K=$=>{$.preventDefault(),w(G)($)},re=()=>{C(v())},H=()=>h?o.jsxs("form",{onSubmit:K,className:"space-y-4",children:[o.jsx(Bte,{definitionType:h,storageType:d,preset:r==null?void 0:r.connectorSourceTitle}),o.jsxs("div",{className:"flex items-center gap-4",children:[o.jsx(Ce,{variant:"default",type:"submit",disabled:!T||!R,children:"Save"}),o.jsx(Ce,{type:"button",variant:"ghost",onClick:re,disabled:!R,children:"Discard"}),h===qe.SQL&&D&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-6 w-px bg-gray-300"}),o.jsx(Qte,{sql:D,dataMartId:c,onValidationStateChange:A})]})]})]}):null;return o.jsx(m3,{...b,children:o.jsxs("div",{className:"space-y-4",children:[!s&&o.jsx(XJ,{initialType:h,onTypeSelect:M}),H()]})})}function Jte(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 FO(e){return e.type==="bigquery-data-mart-schema"}function zO(e){return e.type==="athena-data-mart-schema"}function GT(e){return e!==null&&typeof e=="object"&&"mode"in e}function qT(e){return e!==null&&typeof e=="object"&&"isPrimaryKey"in e}function ene(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 tne(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?FO(n)&&h.every(GT)?(r({...n,fields:h}),l(!0)):zO(n)&&h.every(qT)&&(r({...n,fields:h}),l(!0)):h.length>0&&(GT(h[0])?(r({type:"bigquery-data-mart-schema",fields:h}),l(!0)):qT(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 nne(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 rne(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 VO(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=>VO(c,t)):!1}function HO(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=HO(s.fields,t,c);g.length>0&&(r.includes(c)||r.push(c),r.push(...g))}}),r}function ane(e,t,n){const r=e.original;if(!n)return!0;const s=n.toLowerCase();return VO(r,s)}function sne(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 us=(e=>(e.CONNECTED="CONNECTED",e.CONNECTED_WITH_DEFINITION_MISMATCH="CONNECTED_WITH_DEFINITION_MISMATCH",e.DISCONNECTED="DISCONNECTED",e))(us||{}),hf=(e=>(e.NULLABLE="NULLABLE",e.REQUIRED="REQUIRED",e.REPEATED="REPEATED",e))(hf||{}),Pn=(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))(Pn||{}),pS=(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))(pS||{});function one(e){const[t,n]=p.useState(new Set),[r,s]=p.useState(null),l=p.useRef(""),c=p.useMemo(()=>{const w=C=>C.some(E=>E.type===Pn.RECORD||E.type===Pn.STRUCT||E.fields&&w(E.fields));return w(e)},[e]),d=p.useCallback(w=>{n(C=>{const E=new Set(C);return E.has(w)?E.delete(w):E.add(w),E})},[]),h=p.useCallback(()=>{const w=[],C=(E,R="")=>{E.forEach((T,j)=>{const O=R?`${R}.${String(j)}`:String(j);(T.type===Pn.RECORD||T.type===Pn.STRUCT)&&T.fields&&T.fields.length>0&&(w.push(O),C(T.fields,O))})};C(e),n(E=>w.every(T=>E.has(T))?new Set:new Set(w))},[e]),m=p.useMemo(()=>{const w=[],C=(E,R="",T=0)=>{E.forEach((j,O)=>{const D=R?`${R}.${String(O)}`:String(O),_=j.type===Pn.RECORD||j.type===Pn.STRUCT;w.push({...j,path:D,level:T}),_&&j.fields&&t.has(D)&&C(j.fields,D,T+1)})};return C(e),w},[e,t]),g=p.useCallback(w=>{if(w!==l.current)if(l.current=w,w){r===null&&s(new Set(t));const E=HO(e,w).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===Pn.RECORD||O.type===Pn.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 E.forEach(j=>{T.add(j)}),T})}else r!==null&&(n(r),s(null))},[e,t,r]),v=p.useCallback(w=>{const C=m[w];return C.type===Pn.RECORD||C.type===Pn.STRUCT},[m]),x=p.useMemo(()=>e.map(w=>({...w,fields:void 0})),[e]),b=p.useMemo(()=>{const w=[],C=(E,R="")=>{E.forEach((T,j)=>{const O=R?`${R}.${String(j)}`:String(j);(T.type===Pn.RECORD||T.type===Pn.STRUCT)&&T.fields&&T.fields.length>0&&(w.push(O),C(T.fields,O))})};return C(e),w.length===0?!1:w.every(E=>t.has(E))},[e,t]);return{expandedRecords:t,hasRecordFields:c,toggleRecordExpansion:d,toggleAllRecords:h,flattenedFields:m,handleSearchChange:g,isRecordType:v,topLevelFields:x,allExpanded:b}}function ine(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,w;for(let E=0;E<x.length-1;E++)w=b[x[E]],b=w.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:Pn.STRING,mode:hf.NULLABLE,isPrimaryKey:!1,status:us.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 w=v[v.length-1];x.splice(w,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:Pn.STRING,mode:hf.NULLABLE,isPrimaryKey:!1,status:us.DISCONNECTED};if(!x)(m=v[h]).fields??(m.fields=[]),v[h].fields.push(b);else{const w=x.split(".").map(Number);let C=v;for(let E=0;E<w.length;E++){const R=w[E];E===w.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 $O(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),w=[...e],[C]=w.splice(x,1);w.splice(b,0,C),t(w);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 w=v;for(let T=0;T<x.length-1;T++)w=w[x[T]].fields??[];const C=x[x.length-1],E=b[b.length-1],[R]=w.splice(C,1);w.splice(E,0,R),t(v)}}},[e,n,t])}}function lne(){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 Fg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function ku(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function gS(e){return"nodeType"in e}function ta(e){var t,n;return e?ku(e)?e:gS(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function vS(e){const{Document:t}=ta(e);return e instanceof t}function Wf(e){return ku(e)?!1:e instanceof ta(e).HTMLElement}function BO(e){return e instanceof ta(e).SVGElement}function Iu(e){return e?ku(e)?e.document:gS(e)?vS(e)?e:Wf(e)||BO(e)?e.ownerDocument:document:document:document}const Hs=Fg?p.useLayoutEffect:p.useEffect;function yS(e){const t=p.useRef(e);return Hs(()=>{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 cne(){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 mf(e,t){t===void 0&&(t=[e]);const n=p.useRef(e);return Hs(()=>{n.current!==e&&(n.current=e)},t),n}function Qf(e,t){const n=p.useRef();return p.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function Mp(e){const t=yS(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 sb(e){const t=p.useRef();return p.useEffect(()=>{t.current=e},[e]),t.current}let Yx={};function Xf(e,t){return p.useMemo(()=>{if(t)return t;const n=Yx[e]==null?0:Yx[e]+1;return Yx[e]=n,e+"-"+n},[e,t])}function GO(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 ru=GO(1),kp=GO(-1);function une(e){return"clientX"in e&&"clientY"in e}function xS(e){if(!e)return!1;const{KeyboardEvent:t}=ta(e.target);return t&&e instanceof t}function dne(e){if(!e)return!1;const{TouchEvent:t}=ta(e.target);return t&&e instanceof t}function ob(e){if(dne(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 une(e)?{x:e.clientX,y:e.clientY}:null}const pf=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[pf.Translate.toString(e),pf.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),ZT="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function fne(e){return e.matches(ZT)?e:e.querySelector(ZT)}const hne={display:"none"};function mne(e){let{id:t,value:n}=e;return je.createElement("div",{id:t,style:hne},n)}function pne(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 je.createElement("div",{id:t,style:s,role:"status","aria-live":r,"aria-atomic":!0},n)}function gne(){const[e,t]=p.useState("");return{announce:p.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const qO=p.createContext(null);function vne(e){const t=p.useContext(qO);p.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function yne(){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 xne={draggable:`
|
|
727
727
|
To pick up a draggable item, press the space bar.
|
|
728
728
|
While dragging, use the arrow keys to move the item.
|
|
729
729
|
Press space again to drop the item in its new position, or press escape to cancel.
|
package/dist/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<link rel="icon" type="image/png" href="/favicon.png" />
|
|
7
7
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
8
8
|
<title>OWOX</title>
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-ChZ9gaAN.js"></script>
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/assets/index-B5G8zxJf.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body translate="no" class="notranslate">
|
package/package.json
CHANGED