@owox/web 0.11.0-next-20251024191328 → 0.11.0-next-20251025220131

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.
@@ -718,7 +718,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
718
718
  `},OT=KQ(XQ)(fD),JQ={config:WQ},eX=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 hD(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],hD(e[n],t[n]))}),NT(NT({},e),t)}var tX={type:"cancelation",msg:"operation is manually canceled"};function zx(e){var t=!1,n=new Promise(function(r,s){e.then(function(l){return t?s(tX):r(l)}),e.catch(s)});return n.cancel=function(){return t=!0},n}var nX=["monaco"],rX=qQ.create({config:ZQ,isInitialized:!1,resolve:null,reject:null,monaco:null}),mD=jQ(rX,2),Zf=mD[0],Ag=mD[1];function aX(e){var t=JQ.config(e),n=t.monaco,r=TQ(t,nX);Ag(function(s){return{config:hD(s.config,r),monaco:n}})}function sX(){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(Ag({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),zx(Vx);if(window.monaco&&window.monaco.editor)return pD(window.monaco),e.resolve(window.monaco),zx(Vx);eX(oX,lX)(cX)}return zx(Vx)}function oX(e){return document.body.appendChild(e)}function iX(e){var t=document.createElement("script");return e&&(t.src=e),t}function lX(e){var t=Zf(function(r){var s=r.config,l=r.reject;return{config:s,reject:l}}),n=iX("".concat(t.config.paths.vs,"/loader.js"));return n.onload=function(){return e()},n.onerror=t.reject,n}function cX(){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;pD(r),e.resolve(r)},function(n){e.reject(n)})}function pD(e){Zf().monaco||Ag({monaco:e})}function uX(){return Zf(function(e){var t=e.monaco;return t})}var Vx=new Promise(function(e,t){return Ag({resolve:e,reject:t})}),gD={config:aX,init:sX,__getMonacoInstance:uX},dX={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},Hx=dX,fX={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},hX=fX;function mX({children:e}){return _e.createElement("div",{style:hX.container},e)}var pX=mX,gX=pX;function vX({width:e,height:t,isEditorReady:n,loading:r,_ref:s,className:l,wrapperProps:c}){return _e.createElement("section",{style:{...Hx.wrapper,width:e,height:t},...c},!n&&_e.createElement(gX,null,r),_e.createElement("div",{ref:s,style:{...Hx.fullWidth,...!n&&Hx.hide},className:l}))}var yX=vX,vD=p.memo(yX);function xX(e){p.useEffect(e,[])}var yD=xX;function bX(e,t,n=!0){let r=p.useRef(!0);p.useEffect(r.current||!n?()=>{r.current=!1}:e,t)}var da=bX;function Zd(){}function Zc(e,t,n,r){return SX(e,r)||CX(e,t,n,r)}function SX(e,t){return e.editor.getModel(xD(e,t))}function CX(e,t,n,r){return e.editor.createModel(t,n,r?xD(e,r):void 0)}function xD(e,t){return e.Uri.parse(t)}function wX({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,_]=p.useState(!1),[O,D]=p.useState(!0),N=p.useRef(null),A=p.useRef(null),M=p.useRef(null),U=p.useRef(R),Z=p.useRef(E),$=p.useRef(!1);yD(()=>{let B=gD.init();return B.then(I=>(A.current=I)&&D(!1)).catch(I=>(I==null?void 0:I.type)!=="cancelation"&&console.error("Monaco initialization: error:",I)),()=>N.current?H():B.cancel()}),da(()=>{if(N.current&&A.current){let B=N.current.getOriginalEditor(),I=Zc(A.current,e||"",r||n||"text",l||"");I!==B.getModel()&&B.setModel(I)}},[l],T),da(()=>{if(N.current&&A.current){let B=N.current.getModifiedEditor(),I=Zc(A.current,t||"",s||n||"text",c||"");I!==B.getModel()&&B.setModel(I)}},[c],T),da(()=>{let B=N.current.getModifiedEditor();B.getOption(A.current.editor.EditorOption.readOnly)?B.setValue(t||""):t!==B.getValue()&&(B.executeEdits("",[{range:B.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),B.pushUndoStop())},[t],T),da(()=>{var B,I;(I=(B=N.current)==null?void 0:B.getModel())==null||I.original.setValue(e||"")},[e],T),da(()=>{let{original:B,modified:I}=N.current.getModel();A.current.editor.setModelLanguage(B,r||n||"text"),A.current.editor.setModelLanguage(I,s||n||"text")},[n,r,s],T),da(()=>{var B;(B=A.current)==null||B.editor.setTheme(m)},[m],T),da(()=>{var B;(B=N.current)==null||B.updateOptions(v)},[v],T);let Q=p.useCallback(()=>{var K;if(!A.current)return;Z.current(A.current);let B=Zc(A.current,e||"",r||n||"text",l||""),I=Zc(A.current,t||"",s||n||"text",c||"");(K=N.current)==null||K.setModel({original:B,modified:I})},[n,t,s,e,r,l,c]),re=p.useCallback(()=>{var B;!$.current&&M.current&&(N.current=A.current.editor.createDiffEditor(M.current,{automaticLayout:!0,...v}),Q(),(B=A.current)==null||B.editor.setTheme(m),_(!0),$.current=!0)},[v,m,Q]);p.useEffect(()=>{T&&U.current(N.current,A.current)},[T]),p.useEffect(()=>{!O&&!T&&re()},[O,T,re]);function H(){var I,K,q,ie;let B=(I=N.current)==null?void 0:I.getModel();d||((K=B==null?void 0:B.original)==null||K.dispose()),h||((q=B==null?void 0:B.modified)==null||q.dispose()),(ie=N.current)==null||ie.dispose()}return _e.createElement(vD,{width:b,height:x,isEditorReady:T,loading:g,_ref:M,className:w,wrapperProps:C})}var EX=wX;p.memo(EX);function RX(e){let t=p.useRef();return p.useEffect(()=>{t.current=e},[e]),t.current}var TX=RX,Dm=new Map;function _X({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:_,onValidate:O=Zd}){let[D,N]=p.useState(!1),[A,M]=p.useState(!0),U=p.useRef(null),Z=p.useRef(null),$=p.useRef(null),Q=p.useRef(T),re=p.useRef(R),H=p.useRef(),B=p.useRef(r),I=TX(l),K=p.useRef(!1),q=p.useRef(!1);yD(()=>{let L=gD.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)),()=>Z.current?be():L.cancel()}),da(()=>{var P,Y,ae,fe;let L=Zc(U.current,e||r||"",t||s||"",l||n||"");L!==((P=Z.current)==null?void 0:P.getModel())&&(v&&Dm.set(I,(Y=Z.current)==null?void 0:Y.saveViewState()),(ae=Z.current)==null||ae.setModel(L),v&&((fe=Z.current)==null||fe.restoreViewState(Dm.get(l))))},[l],D),da(()=>{var L;(L=Z.current)==null||L.updateOptions(m)},[m],D),da(()=>{!Z.current||r===void 0||(Z.current.getOption(U.current.editor.EditorOption.readOnly)?Z.current.setValue(r):r!==Z.current.getValue()&&(q.current=!0,Z.current.executeEdits("",[{range:Z.current.getModel().getFullModelRange(),text:r,forceMoveMarkers:!0}]),Z.current.pushUndoStop(),q.current=!1))},[r],D),da(()=>{var P,Y;let L=(P=Z.current)==null?void 0:P.getModel();L&&s&&((Y=U.current)==null||Y.editor.setModelLanguage(L,s))},[s],D),da(()=>{var L;d!==void 0&&((L=Z.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(!(!$.current||!U.current)&&!K.current){re.current(U.current);let P=l||n,Y=Zc(U.current,r||e||"",t||s||"",P||"");Z.current=(L=U.current)==null?void 0:L.editor.create($.current,{model:Y,automaticLayout:!0,...m},g),v&&Z.current.restoreViewState(Dm.get(P)),U.current.editor.setTheme(c),d!==void 0&&Z.current.revealLine(d),N(!0),K.current=!0}},[e,t,n,r,s,l,m,g,v,c,d]);p.useEffect(()=>{D&&Q.current(Z.current,U.current)},[D]),p.useEffect(()=>{!A&&!D&&ie()},[A,D,ie]),B.current=r,p.useEffect(()=>{var L,P;D&&_&&((L=H.current)==null||L.dispose(),H.current=(P=Z.current)==null?void 0:P.onDidChangeModelContent(Y=>{q.current||_(Z.current.getValue(),Y)}))},[D,_]),p.useEffect(()=>{if(D){let L=U.current.editor.onDidChangeMarkers(P=>{var ae;let Y=(ae=Z.current.getModel())==null?void 0:ae.uri;if(Y&&P.find(fe=>fe.path===Y.path)){let fe=U.current.editor.getModelMarkers({resource:Y});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,Z.current.saveViewState()):(P=Z.current.getModel())==null||P.dispose(),Z.current.dispose()}return _e.createElement(vD,{width:b,height:w,isEditorReady:D,loading:h,_ref:$,className:C,wrapperProps:E})}var jX=_X,NX=p.memo(jX);function AX({initialValue:e,onChange:t}){const[n,r]=p.useState((e==null?void 0:e.sqlQuery)??""),{resolvedTheme:s}=o4();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(NX,{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 Z0({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(ps,{className:"text-muted-foreground/75 dark:text-muted-foreground/50 h-4 w-4"})})]})]})}var MT=1,DX=.9,OX=.8,MX=.17,$x=.1,Bx=.999,kX=.9999,IX=.99,LX=/[\\\/_+.#"@\[\(\{&]/,PX=/[\\\/_+.#"@\[\(\{&]/g,UX=/[\s-]/,bD=/[\s-]/g;function K0(e,t,n,r,s,l,c){if(l===t.length)return s===e.length?MT:IX;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=K0(e,t,n,r,m+1,l+1,c),v>g&&(m===s?v*=MT:LX.test(e.charAt(m-1))?(v*=OX,b=e.slice(s,m-1).match(PX),b&&s>0&&(v*=Math.pow(Bx,b.length))):UX.test(e.charAt(m-1))?(v*=DX,w=e.slice(s,m-1).match(bD),w&&s>0&&(v*=Math.pow(Bx,w.length))):(v*=MX,s>0&&(v*=Math.pow(Bx,m-s))),e.charAt(m)!==t.charAt(l)&&(v*=kX)),(v<$x&&n.charAt(m-1)===r.charAt(l+1)||r.charAt(l+1)===r.charAt(l)&&n.charAt(m-1)!==r.charAt(l))&&(x=K0(e,t,n,r,m+1,l+2,c),x*$x>v&&(v=x*$x)),v>g&&(g=v),m=n.indexOf(h,m+1);return c[d]=g,g}function kT(e){return e.toLowerCase().replace(bD," ")}function FX(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,K0(e,t,kT(e),kT(t),0,0,{})}var Id='[cmdk-group=""]',Gx='[cmdk-group-items=""]',zX='[cmdk-group-heading=""]',SD='[cmdk-item=""]',IT=`${SD}:not([aria-disabled="true"])`,Y0="cmdk-item-select",Bc="data-value",VX=(e,t,n)=>FX(e,t,n),CD=p.createContext(void 0),Kf=()=>p.useContext(CD),wD=p.createContext(void 0),$1=()=>p.useContext(wD),ED=p.createContext(void 0),RD=p.forwardRef((e,t)=>{let n=Gc(()=>{var P,Y;return{search:"",value:(Y=(P=e.value)!=null?P:e.defaultValue)!=null?Y:"",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=TD(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(),_=Nn(),O=Nn(),D=p.useRef(null),N=XX();Pl(()=>{if(g!==void 0){let P=g.trim();n.current.value=P,A.emit()}},[g]),Pl(()=>{N(6,re)},[]);let A=p.useMemo(()=>({subscribe:P=>(c.current.add(P),()=>c.current.delete(P)),snapshot:()=>n.current,setState:(P,Y,ae)=>{var fe,ge,ue,Ne;if(!Object.is(n.current[P],Y)){if(n.current[P]=Y,P==="search")Q(),Z(),N(1,$);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(N(7,()=>{var Re;n.current.selectedItemId=(Re=H())==null?void 0:Re.id,A.emit()}),ae||N(5,re),((ge=d.current)==null?void 0:ge.value)!==void 0){let Re=Y??"";(Ne=(ue=d.current).onValueChange)==null||Ne.call(ue,Re);return}}A.emit()}},emit:()=>{c.current.forEach(P=>P())}}),[]),M=p.useMemo(()=>({value:(P,Y,ae)=>{var fe;Y!==((fe=l.current.get(P))==null?void 0:fe.value)&&(l.current.set(P,{value:Y,keywords:ae}),n.current.filtered.items.set(P,U(Y,ae)),N(2,()=>{Z(),A.emit()}))},item:(P,Y)=>(r.current.add(P),Y&&(s.current.has(Y)?s.current.get(Y).add(P):s.current.set(Y,new Set([P]))),N(3,()=>{Q(),Z(),n.current.value||$(),A.emit()}),()=>{l.current.delete(P),r.current.delete(P),n.current.filtered.items.delete(P);let ae=H();N(4,()=>{Q(),(ae==null?void 0:ae.getAttribute("id"))===P&&$(),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:_,listInnerRef:D}),[]);function U(P,Y){var ae,fe;let ge=(fe=(ae=d.current)==null?void 0:ae.filter)!=null?fe:VX;return P?ge(P,n.current.search,Y):0}function Z(){if(!n.current.search||d.current.shouldFilter===!1)return;let P=n.current.filtered.items,Y=[];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)}),Y.push([fe,ue])});let ae=D.current;B().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(Gx);ge?ge.appendChild(fe.parentElement===ge?fe:fe.closest(`${Gx} > *`)):ae.appendChild(fe.parentElement===ae?fe:fe.closest(`${Gx} > *`))}),Y.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 $(){let P=B().find(ae=>ae.getAttribute("aria-disabled")!=="true"),Y=P==null?void 0:P.getAttribute(Bc);A.setState("value",Y||void 0)}function Q(){var P,Y,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=(Y=(P=l.current.get(ue))==null?void 0:P.value)!=null?Y:"",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,Y,ae;let fe=H();fe&&(((P=fe.parentElement)==null?void 0:P.firstChild)===fe&&((ae=(Y=fe.closest(Id))==null?void 0:Y.querySelector(zX))==null||ae.scrollIntoView({block:"nearest"})),fe.scrollIntoView({block:"nearest"}))}function H(){var P;return(P=D.current)==null?void 0:P.querySelector(`${SD}[aria-selected="true"]`)}function B(){var P;return Array.from(((P=D.current)==null?void 0:P.querySelectorAll(IT))||[])}function I(P){let Y=B()[P];Y&&A.setState("value",Y.getAttribute(Bc))}function K(P){var Y;let ae=H(),fe=B(),ge=fe.findIndex(Ne=>Ne===ae),ue=fe[ge+P];(Y=d.current)!=null&&Y.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 q(P){let Y=H(),ae=Y==null?void 0:Y.closest(Id),fe;for(;ae&&!fe;)ae=P>0?WX(ae,Id):QX(ae,Id),fe=ae==null?void 0:ae.querySelector(IT);fe?A.setState("value",fe.getAttribute(Bc)):K(P)}let ie=()=>I(B().length-1),be=P=>{P.preventDefault(),P.metaKey?ie():P.altKey?q(1):K(1)},L=P=>{P.preventDefault(),P.metaKey?I(0):P.altKey?q(-1):K(-1)};return p.createElement(Ke.div,{ref:t,tabIndex:-1,...R,"cmdk-root":"",onKeyDown:P=>{var Y;(Y=R.onKeyDown)==null||Y.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(Y0);fe.dispatchEvent(ge)}}}}},p.createElement("label",{"cmdk-label":"",htmlFor:M.inputId,id:M.labelId,style:eJ},h),Dg(e,P=>p.createElement(wD.Provider,{value:A},p.createElement(CD.Provider,{value:M},P))))}),HX=p.forwardRef((e,t)=>{var n,r;let s=Nn(),l=p.useRef(null),c=p.useContext(ED),d=Kf(),h=TD(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=_D(s,l,[e.value,e.children,l],e.keywords),v=$1(),x=Ai(N=>N.value&&N.value===g.current),b=Ai(N=>m||d.filter()===!1?!0:N.search?N.filtered.items.get(s)>0:!0);p.useEffect(()=>{let N=l.current;if(!(!N||e.disabled))return N.addEventListener(Y0,w),()=>N.removeEventListener(Y0,w)},[b,e.onSelect,e.disabled]);function w(){var N,A;C(),(A=(N=h.current).onSelect)==null||A.call(N,g.current)}function C(){v.setState("value",g.current,!0)}if(!b)return null;let{disabled:E,value:R,onSelect:T,forceMount:_,keywords:O,...D}=e;return p.createElement(Ke.div,{ref:jo(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)}),$X=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),[]),_D(c,d,[e.value,e.heading,h]);let x=p.useMemo(()=>({id:c,forceMount:s}),[s]);return p.createElement(Ke.div,{ref:jo(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),Dg(e,b=>p.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?m:void 0},p.createElement(ED.Provider,{value:x},b))))}),BX=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:jo(s,t),...r,"cmdk-separator":"",role:"separator"})}),GX=p.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,s=e.value!=null,l=$1(),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)}})}),qX=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:jo(l,t),...s,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":d,"aria-label":r,id:h.listId},Dg(e,m=>p.createElement("div",{ref:jo(c,h.listInnerRef),"cmdk-list-sizer":""},m)))}),ZX=p.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:s,contentClassName:l,container:c,...d}=e;return p.createElement(Kp,{open:n,onOpenChange:r},p.createElement(Yp,{container:c},p.createElement(Wp,{"cmdk-overlay":"",className:s}),p.createElement(Qp,{"aria-label":e.label,"cmdk-dialog":"",className:l},p.createElement(RD,{ref:t,...d}))))}),KX=p.forwardRef((e,t)=>Ai(n=>n.filtered.count===0)?p.createElement(Ke.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),YX=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},Dg(e,c=>p.createElement("div",{"aria-hidden":!0},c)))}),Mu=Object.assign(RD,{List:qX,Item:HX,Input:GX,Group:$X,Separator:BX,Dialog:ZX,Empty:KX,Loading:YX});function WX(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function QX(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function TD(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=$1(),n=()=>e(t.snapshot());return p.useSyncExternalStore(t.subscribe,n,n)}function _D(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 XX=()=>{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 JX(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function Dg({asChild:e,children:t},n){return e&&p.isValidElement(t)?p.cloneElement(JX(t),{ref:t.ref},n(t.props.children)):n(t)}var eJ={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 ND({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 tJ({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 AD({...e}){return o.jsx(Mu.Empty,{"data-slot":"command-empty",className:"py-6 text-center text-sm",...e})}function DD({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 OD({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 Og="Popover",[MD]=Dr(Og,[Bs]),Yf=Bs(),[nJ,Zi]=MD(Og),kD=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:Og});return o.jsx(Su,{...d,children:o.jsx(nJ,{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})})};kD.displayName=Og;var ID="PopoverAnchor",rJ=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Zi(ID,n),l=Yf(n),{onCustomAnchorAdd:c,onCustomAnchorRemove:d}=s;return p.useEffect(()=>(c(),()=>d()),[c,d]),o.jsx(Cu,{...l,...r,ref:t})});rJ.displayName=ID;var LD="PopoverTrigger",PD=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Zi(LD,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":HD(s.open),...r,ref:c,onClick:Te(e.onClick,s.onOpenToggle)});return s.hasCustomAnchor?d:o.jsx(Cu,{asChild:!0,...l,children:d})});PD.displayName=LD;var B1="PopoverPortal",[aJ,sJ]=MD(B1,{forceMount:void 0}),UD=e=>{const{__scopePopover:t,forceMount:n,children:r,container:s}=e,l=Zi(B1,t);return o.jsx(aJ,{scope:t,forceMount:n,children:o.jsx(Sr,{present:n||l.open,children:o.jsx(Vl,{asChild:!0,container:s,children:r})})})};UD.displayName=B1;var mu="PopoverContent",FD=p.forwardRef((e,t)=>{const n=sJ(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(iJ,{...s,ref:t}):o.jsx(lJ,{...s,ref:t})})});FD.displayName=mu;var oJ=Ri("PopoverContent.RemoveScroll"),iJ=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 qp(c)},[]),o.jsx(Ef,{as:oJ,allowPinchZoom:!0,children:o.jsx(zD,{...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})})})}),lJ=p.forwardRef((e,t)=>{const n=Zi(mu,e.__scopePopover),r=p.useRef(!1),s=p.useRef(!1);return o.jsx(zD,{...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()}})}),zD=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 Bp(),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":HD(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)"}})})})}),VD="PopoverClose",cJ=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Zi(VD,n);return o.jsx(Ke.button,{type:"button",...r,ref:t,onClick:Te(e.onClick,()=>s.onOpenChange(!1))})});cJ.displayName=VD;var uJ="PopoverArrow",dJ=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Yf(n);return o.jsx(_f,{...s,...r,ref:t})});dJ.displayName=uJ;function HD(e){return e?"open":"closed"}var fJ=kD,hJ=PD,mJ=UD,pJ=FD;function G1({...e}){return o.jsx(fJ,{"data-slot":"popover",...e})}function q1({...e}){return o.jsx(hJ,{"data-slot":"popover-trigger",...e})}function Z1({className:e,align:t="center",sideOffset:n=4,...r}){return o.jsx(mJ,{children:o.jsx(pJ,{"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 K1({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(G1,{open:d,onOpenChange:h,modal:!0,children:[o.jsx(q1,{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(bb,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),o.jsx(Z1,{className:"max-h-[300px] min-w-[300px] overflow-auto p-0",align:"start",sideOffset:5,children:o.jsxs(jD,{children:[o.jsx(ND,{placeholder:`Search ${r.toLowerCase()}...`,value:m,onValueChange:g}),o.jsx(AD,{children:s}),Object.entries(v).map(([w,C])=>o.jsx(DD,{heading:w,children:C.map(E=>o.jsxs(OD,{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 Mg="Collapsible",[gJ,$D]=Dr(Mg),[vJ,Y1]=gJ(Mg),BD=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:Mg});return o.jsx(vJ,{scope:n,disabled:l,contentId:Nn(),open:h,onOpenToggle:p.useCallback(()=>m(g=>!g),[m]),children:o.jsx(Ke.div,{"data-state":J1(h),"data-disabled":l?"":void 0,...d,ref:t})})});BD.displayName=Mg;var GD="CollapsibleTrigger",W1=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,s=Y1(GD,n);return o.jsx(Ke.button,{type:"button","aria-controls":s.contentId,"aria-expanded":s.open||!1,"data-state":J1(s.open),"data-disabled":s.disabled?"":void 0,disabled:s.disabled,...r,ref:t,onClick:Te(e.onClick,s.onOpenToggle)})});W1.displayName=GD;var Q1="CollapsibleContent",X1=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,s=Y1(Q1,e.__scopeCollapsible);return o.jsx(Sr,{present:n||s.open,children:({present:l})=>o.jsx(yJ,{...r,ref:t,present:l})})});X1.displayName=Q1;var yJ=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:s,...l}=e,c=Y1(Q1,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 _=T.getBoundingClientRect();v.current=_.height,b.current=_.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":J1(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 J1(e){return e?"open":"closed"}var qD=BD,xJ=W1,bJ=X1,ys="Accordion",SJ=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[eS,CJ,wJ]=sg(ys),[kg]=Dr(ys,[wJ,$D]),tS=$D(),ZD=_e.forwardRef((e,t)=>{const{type:n,...r}=e,s=r,l=r;return o.jsx(eS.Provider,{scope:e.__scopeAccordion,children:n==="multiple"?o.jsx(_J,{...l,ref:t}):o.jsx(TJ,{...s,ref:t})})});ZD.displayName=ys;var[KD,EJ]=kg(ys),[YD,RJ]=kg(ys,{collapsible:!1}),TJ=_e.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:ys});return o.jsx(KD,{scope:e.__scopeAccordion,value:_e.useMemo(()=>d?[d]:[],[d]),onItemOpen:h,onItemClose:_e.useCallback(()=>l&&h(""),[l,h]),children:o.jsx(YD,{scope:e.__scopeAccordion,collapsible:l,children:o.jsx(WD,{...c,ref:t})})})}),_J=_e.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},...l}=e,[c,d]=zr({prop:n,defaultProp:r??[],onChange:s,caller:ys}),h=_e.useCallback(g=>d((v=[])=>[...v,g]),[d]),m=_e.useCallback(g=>d((v=[])=>v.filter(x=>x!==g)),[d]);return o.jsx(KD,{scope:e.__scopeAccordion,value:c,onItemOpen:h,onItemClose:m,children:o.jsx(YD,{scope:e.__scopeAccordion,collapsible:!0,children:o.jsx(WD,{...l,ref:t})})})}),[jJ,Ig]=kg(ys),WD=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,disabled:r,dir:s,orientation:l="vertical",...c}=e,d=_e.useRef(null),h=vt(d,t),m=CJ(n),v=Af(s)==="ltr",x=Te(e.onKeyDown,b=>{var M;if(!SJ.includes(b.key))return;const w=b.target,C=m().filter(U=>{var Z;return!((Z=U.ref.current)!=null&&Z.disabled)}),E=C.findIndex(U=>U.ref.current===w),R=C.length;if(E===-1)return;b.preventDefault();let T=E;const _=0,O=R-1,D=()=>{T=E+1,T>O&&(T=_)},N=()=>{T=E-1,T<_&&(T=O)};switch(b.key){case"Home":T=_;break;case"End":T=O;break;case"ArrowRight":l==="horizontal"&&(v?D():N());break;case"ArrowDown":l==="vertical"&&D();break;case"ArrowLeft":l==="horizontal"&&(v?N():D());break;case"ArrowUp":l==="vertical"&&N();break}const A=T%R;(M=C[A].ref.current)==null||M.focus()});return o.jsx(jJ,{scope:n,disabled:r,direction:s,orientation:l,children:o.jsx(eS.Slot,{scope:n,children:o.jsx(Ke.div,{...c,"data-orientation":l,ref:h,onKeyDown:r?void 0:x})})})}),Dp="AccordionItem",[NJ,nS]=kg(Dp),QD=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,value:r,...s}=e,l=Ig(Dp,n),c=EJ(Dp,n),d=tS(n),h=Nn(),m=r&&c.value.includes(r)||!1,g=l.disabled||e.disabled;return o.jsx(NJ,{scope:n,open:m,disabled:g,triggerId:h,children:o.jsx(qD,{"data-orientation":l.orientation,"data-state":rO(m),...d,...s,ref:t,disabled:g,open:m,onOpenChange:v=>{v?c.onItemOpen(r):c.onItemClose(r)}})})});QD.displayName=Dp;var XD="AccordionHeader",JD=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Ig(ys,n),l=nS(XD,n);return o.jsx(Ke.h3,{"data-orientation":s.orientation,"data-state":rO(l.open),"data-disabled":l.disabled?"":void 0,...r,ref:t})});JD.displayName=XD;var W0="AccordionTrigger",eO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Ig(ys,n),l=nS(W0,n),c=RJ(W0,n),d=tS(n);return o.jsx(eS.ItemSlot,{scope:n,children:o.jsx(xJ,{"aria-disabled":l.open&&!c.collapsible||void 0,"data-orientation":s.orientation,id:l.triggerId,...d,...r,ref:t})})});eO.displayName=W0;var tO="AccordionContent",nO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Ig(ys,n),l=nS(tO,n),c=tS(n);return o.jsx(bJ,{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}})});nO.displayName=tO;function rO(e){return e?"open":"closed"}var AJ=ZD,DJ=QD,OJ=JD,MJ=eO,kJ=nO;const rS={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(Y9,{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}},aO=p.createContext("default");function hr({variant:e="default",...t}){return o.jsx(aO.Provider,{value:e,children:o.jsx(AJ,{"data-slot":"accordion",...t})})}function aS(e){const t=p.useContext(aO);return e??t??"default"}function Kn({className:e,variant:t,...n}){const r=aS(t),{itemClass:s}=rS[r];return o.jsx(DJ,{"data-slot":"accordion-item",className:J(s,e),...n})}function Yn({className:e,children:t,variant:n,...r}){const s=aS(n),{triggerClass:l,icon:c,chevronClass:d,headerClass:h}=rS[s];return o.jsx(OJ,{className:h,children:o.jsxs(MJ,{"data-slot":"accordion-trigger",className:J(l,e),...r,children:[c,t,o.jsx(Ra,{className:d,"aria-hidden":"true"})]})})}function Wn({className:e,children:t,variant:n,...r}){const s=aS(n),{contentClass:l,contentInnerClass:c}=rS[s];return o.jsx(kJ,{"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 IJ(){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 LJ(){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 PJ(){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 sO=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}},UJ=({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?sO(l):null;return o.jsxs(o.Fragment,{children:[o.jsxs(zs,{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(LJ,{})}),o.jsx(on,{})]})}),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(K1,{options:eq,value:d.value,onValueChange:d.onChange,placeholder:"Select a location",emptyMessage:"No locations found",className:"w-full"})}),o.jsx(ar,{children:o.jsx(PJ,{})}),o.jsx(on,{})]})})]}),o.jsx(zs,{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(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(fr,{href:c.url,children:c.email})}),o.jsx(Ot,{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(IJ,{})}),o.jsx(on,{})]})})})]})};function FJ(){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 zJ(){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 VJ(){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(cj,{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 HJ(){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 $J=({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(zs,{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(FJ,{})}),o.jsx(on,{})]})}),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(zJ,{})}),o.jsx(on,{})]})})]}),o.jsxs(zs,{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(VJ,{})}),o.jsx(on,{})]})}),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(HJ,{})}),o.jsx(on,{})]})})]})]})};function BJ(){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 GJ(){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 oO(e){return JSON.parse(JSON.stringify(e))}function qJ({initialData:e,onSubmit:t,onCancel:n,onDirtyChange:r}){const s=$i({resolver:Wl(xq),defaultValues:e}),{watch:l,control:c,formState:{isDirty:d,isSubmitting:h}}=s,m=l("type");_e.useEffect(()=>{r==null||r(d)},[d,r]);const g=async v=>{const{dirtyFields:x}=s.formState,b=oO(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(zs,{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(on,{})]})}),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(jg,{children:Vi.getAllTypes().map(({type:x,displayName:b,icon:w,status:C})=>o.jsx(qn,{value:x,disabled:C===xo.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(BJ,{}),m===Pe.AWS_ATHENA&&o.jsx(GJ,{})]}),o.jsx(on,{})]})})]}),m===Pe.GOOGLE_BIGQUERY&&o.jsx(UJ,{form:s}),m===Pe.AWS_ATHENA&&o.jsx($J,{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 iO({isOpen:e,onClose:t,dataStorage:n,onSaveSuccess:r}){const{updateDataStorage:s}=Ng(),[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(qJ,{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 ZJ=({dataStorage:e,onDataStorageChange:t})=>{const[n,r]=p.useState(!1),s=Vi.getInfo(e.type),l=()=>{r(!0)},c=()=>{r(!1)},d=()=>{if(!g4(e))return o.jsxs("div",{className:"flex items-center space-x-2 text-sm",children:[o.jsx($p,{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(Z0,{title:e.title,icon:s.icon,subtitle:d(),onClick:l}),o.jsx(V1,{children:o.jsx(iO,{isOpen:n,onClose:c,dataStorage:e,onSaveSuccess:h=>{t&&t(h)}})})]})};function KJ({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(jg,{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 YJ=an({definitionType:Gs(qe.SQL),definition:an({sqlQuery:sn().min(1,"SQL query is required")})}),WJ=e=>{const t=L4(e);return an({definitionType:Gs(qe.TABLE),definition:t})},QJ=e=>{const t=L4(e);return an({definitionType:Gs(qe.VIEW),definition:t})},XJ=e=>{const t=OZ(e);return an({definitionType:Gs(qe.TABLE_PATTERN),definition:t})},JJ=an({definitionType:Gs(qe.CONNECTOR),definition:an({connector:an({source:an({name:sn().min(1,"Connector name is required"),configuration:QR(hB(dB())).min(1,"At least one configuration is required"),node:sn().min(1,"Node is required"),fields:QR(sn()).min(1,"At least one field is required")}),storage:an({fullyQualifiedName:sn().min(1,"fully qualified name is required")})})})}),eee=(e,t)=>{if(!e)return an({definitionType:mB(s1(qe)),definition:an({}).optional()});switch(e){case qe.SQL:return YJ;case qe.TABLE:return WJ(t);case qe.VIEW:return QJ(t);case qe.TABLE_PATTERN:return XJ(t);case qe.CONNECTOR:return JJ;default:return an({})}};function tee({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(AX,{initialValue:{sqlQuery:t.value},onChange:n=>{t.onChange(n.sqlQuery)}})}),o.jsx(on,{})]})})}function nee({control:e,storageType:t}){const n=y4(t),r=x4(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(on,{})]})})}function ree({control:e,storageType:t}){const n=y4(t),r=x4(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(on,{})]})})}function aee({control:e,storageType:t}){const n=Eq(t),r=Rq(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(on,{})]})})}const Q0=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{}}},see=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 sS({className:e,variant:t,...n}){return o.jsx("div",{"data-slot":"alert",role:"alert",className:J(see({variant:t}),e),...n})}function lO({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 oS({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 Lg="Tabs",[oee]=Dr(Lg,[og]),cO=og(),[iee,iS]=oee(Lg),uO=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:Lg});return o.jsx(iee,{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})})});uO.displayName=Lg;var dO="TabsList",fO=p.forwardRef((e,t)=>{const{__scopeTabs:n,loop:r=!0,...s}=e,l=iS(dO,n),c=cO(n);return o.jsx(CN,{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})})});fO.displayName=dO;var hO="TabsTrigger",mO=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,disabled:s=!1,...l}=e,c=iS(hO,n),d=cO(n),h=vO(c.baseId,r),m=yO(c.baseId,r),g=r===c.value;return o.jsx(wN,{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)})})})});mO.displayName=hO;var pO="TabsContent",gO=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,forceMount:s,children:l,...c}=e,d=iS(pO,n),h=vO(d.baseId,r),m=yO(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})})});gO.displayName=pO;function vO(e,t){return`${e}-trigger-${t}`}function yO(e,t){return`${e}-content-${t}`}var lee=uO,cee=fO,uee=mO,dee=gO;function fee({className:e,...t}){return o.jsx(lee,{"data-slot":"tabs",className:J("flex flex-col gap-2",e),...t})}function hee({className:e,...t}){return o.jsx(cee,{"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 mee({className:e,...t}){return o.jsx(uee,{"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 pee({className:e,...t}){return o.jsx(dee,{"data-slot":"tabs-content",className:J("flex-1 outline-none",e),...t})}const gee=qD,vee=W1,yee=X1;function xee({children:e,className:t="",...n}){return o.jsx("div",{className:J("flex flex-1 flex-col overflow-hidden",t),...n,children:e})}function bee({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 See({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 Cee({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(fee,{value:s,onValueChange:l,children:[o.jsxs("div",{className:"flex items-center",children:[o.jsx(Co,{required:c,tooltip:d,className:"w-full",children:e}),o.jsx(hee,{children:r.map(m=>o.jsx(mee,{value:m.value,children:m.label},m.value))})]}),t]})})}function wee({title:e,children:t,defaultOpen:n=!1,className:r=""}){const[s,l]=p.useState(n);return o.jsxs(gee,{open:s,onOpenChange:l,"data-slot":"wizard-collapsible",className:J("group flex flex-col gap-2 py-3",r),children:[o.jsx(vee,{asChild:!0,children:o.jsxs("button",{type:"button",className:J("text-foreground flex w-full items-center justify-between gap-2 px-4 py-3 text-sm font-medium",!s&&"border-border rounded-md border-b bg-white transition-shadow duration-200 outline-none hover:shadow-sm dark:border-transparent dark:bg-white/4"),children:[o.jsx("span",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:e}),o.jsx(Ra,{className:J("h-4 w-4 transition-transform duration-200",s&&"rotate-180")})]})}),o.jsx(yee,{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 Co({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(At,{...r,children:[o.jsx(Dt,{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(Ot,{side:"top",align:"center",role:"tooltip",children:"Required"})]}):o.jsx("span",{children:e}),n&&o.jsxs(At,{...r,children:[o.jsx(Dt,{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(Ot,{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 Eo({children:e,className:t="",...n}){return o.jsx("div",{"data-slot":"wizard-step",className:J("space-y-4",t),...n,children:e})}function Eee({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 Ree({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(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx("span",{className:"cursor-not-allowed text-sm font-medium opacity-70",children:t})}),o.jsx(Ot,{side:"top",align:"center",children:"Coming soon"})]}):o.jsx("span",{className:"text-sm font-medium",children:t})]})}function xO({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(Co,{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(At,{children:[o.jsx(Dt,{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(Ot,{side:"top",align:"center",children:h})]}),m&&o.jsx("div",{className:"flex items-center",children:m})]})]})}function lS({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(rs,{className:"border-border h-12 rounded-md border-b bg-white dark:bg-white/4"},c))})}function Tee({connectors:e,selectedConnector:t,loading:n,error:r,onConnectorSelect:s,onConnectorDoubleClick:l}){return n?o.jsx(lS,{variant:"grid"}):r?o.jsxs(sS,{variant:"destructive",children:[o.jsx(Sf,{className:"h-4 w-4"}),o.jsx(oS,{children:"Failed to load available connectors. Please try again."})]}):o.jsxs(Eo,{children:[o.jsx(wl,{title:"Choose Connector",children:o.jsx(Eee,{children:e.map(c=>o.jsx(Ree,{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 _ee({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(XI,{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(ps,{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 X0="**********";function jee({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(Co,{htmlFor:c,required:e.required,tooltip:e.description,children:l})})]})}function Nee({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 Aee({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(`
719
719
  `):Array.isArray(l)?l.join(`
720
720
  `):"",placeholder:s??`Enter ${c.toLowerCase()} (one per line)`,rows:4,onChange:d=>{const h=d.target.value.split(`
721
- `).filter(m=>m.trim());n(r,h)}})}function Dee({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 Oee({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 Mee({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 kee({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?X0: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 Iee({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(K1,{options:h,value:t[s]||c||"",onValueChange:m=>{n(s,m)},placeholder:l??`Select ${d.toLowerCase()}`,emptyMessage:"No options available",className:"w-full"})}function bO({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(kee,{specification:e,configuration:t,onValueChange:n,isEditingExisting:d,isSecretEditing:h});if(l&&l.length>0)return o.jsx(Iee,{specification:e,configuration:t,onValueChange:n,specOptions:l});switch(s){case ns.BOOLEAN:return o.jsx(jee,{specification:e,configuration:t,onValueChange:n});case ns.NUMBER:return o.jsx(Nee,{specification:e,configuration:t,onValueChange:n});case ns.ARRAY:return o.jsx(Aee,{specification:e,configuration:t,onValueChange:n});case ns.OBJECT:return o.jsx(Mee,{specification:e,configuration:t,onValueChange:n});case ns.DATE:return o.jsx(Dee,{specification:e,configuration:t,onValueChange:n});case ns.STRING:default:return o.jsx(Oee,{specification:e,configuration:t,onValueChange:n})}}function Lee({specification:e,configuration:t,isEditingExisting:n,isSecretEditing:r,isSecret:s,onValueChange:l,onSecretEditToggle:c}){return o.jsxs($d,{children:[e.requiredType!==ns.BOOLEAN&&o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(Co,{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"})]}),bO({specification:e,configuration:t,onValueChange:l,flags:{isSecret:s,isEditingExisting:n,isSecretEditing:r}})]},e.name)}function Pee({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(Cee,{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(pee,{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(Co,{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"})]}),bO({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 LT(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===ns.OBJECT?o.jsx(Pee,{specification:c,configuration:t,onValueChange:n,isEditingExisting:l,isSecretEditing:h,onSecretEditToggle:r},c.name):o.jsx(Lee,{specification:c,configuration:t,isEditingExisting:l,isSecret:d,isSecretEditing:h,onValueChange:n,onSecretEditToggle:r},c.name)})}function PT({collapsibleTitle:e,items:t,configuration:n,onValueChange:r,onSecretEditToggle:s,secretEditing:l,isEditingExisting:c}){return e?o.jsx(wee,{title:e,children:LT(t,n,r,s,l,c)}):LT(t,n,r,s,l,c)}function UT({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 D={...s??{}};t.forEach(N=>{const A=Array.isArray(N.attributes)?N.attributes.includes("SECRET"):!1;D[N.name]===void 0&&N.default!==void 0&&(D[N.name]=N.default),c&&A&&(D[N.name]=X0)}),h(D),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=(D,N)=>{h(A=>({...A,[D]:N}))},w=p.useCallback(D=>!(D==null||typeof D=="string"&&D.trim()===""||Array.isArray(D)&&D.length===0),[]),C=p.useCallback((D,N)=>{var M;if(typeof D!="object"||D===null)return w(D);const A=(M=N.oneOf)==null?void 0:M.filter(U=>U.value===Object.keys(D)[0]);return A?A.every(U=>Object.entries(U.items).every(([,Z])=>U.value in D?C(D[U.value],Z):!1)):w(D[N.name])},[w]),E=p.useCallback((D,N)=>{const M=N.filter($=>$.required&&$.oneOf).some($=>C(D[$.name],$)),Z=N.filter($=>$.required&&$.name!=="Fields").every($=>w(D[$.name]));return M&&Z},[w,C]),R=(D,N)=>{x(A=>({...A,[D]:N})),h(N?A=>({...A,[D]:""}):A=>({...A,[D]:X0}))};if(p.useEffect(()=>{if(t&&r){const D=E(d,t);r(D)}},[d,t,r,E]),l)return o.jsx(lS,{variant:"list"});if(!t||t.length===0)return o.jsxs(Eo,{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 T=[...t].filter(D=>{var N;return D.name!=="Fields"&&!((N=D.attributes)!=null&&N.includes("HIDE_IN_CONFIG_FORM"))}).sort((D,N)=>{const A=M=>{const U=M.default!=null&&M.default!=="";return M.required&&!U?1:M.required&&U?2:!M.required&&!U?3:4};return A(D)-A(N)}),_=T.filter(D=>{var N;return!((N=D.attributes)!=null&&N.includes("ADVANCED"))}),O=T.filter(D=>{var N;return(N=D.attributes)==null?void 0:N.includes("ADVANCED")});return o.jsx(o.Fragment,{children:o.jsxs(Eo,{children:[o.jsx(El,{connector:e}),o.jsxs(wl,{title:"Configure Settings",children:[_.length>0&&o.jsx(PT,{items:_,configuration:d,onValueChange:b,onSecretEditToggle:R,secretEditing:v,isEditingExisting:c}),O.length>0&&o.jsx(PT,{collapsibleTitle:"Advanced Fields",items:O,configuration:d,onValueChange:b,onSecretEditToggle:R,secretEditing:v,isEditingExisting:c})]})]})})}function Uee({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(lS,{variant:"list"}):!t||t.length===0?o.jsxs(Eo,{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(Eo,{children:[o.jsx(El,{connector:e}),o.jsxs(wl,{title:c,children:[t.map(d=>o.jsx(xO,{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(ps,{className:"h-3 w-3"})]})]}),selected:n===d.name},d.name)),o.jsx(nu,{label:"Missing some data?"})]})]})}var Ns=(e=>(e.ASC="asc",e.DESC="desc",e.ORIGINAL="original",e))(Ns||{});function FT({connector:e,connectorFields:t,selectedField:n,selectedFields:r,onFieldToggle:s}){const l=p.useRef(null),[c,d]=p.useState(""),[h,m]=p.useState(Ns.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,_)=>R.set(T.name,_)),R},[v]),w=p.useMemo(()=>{const R=v.filter(_=>_.name.toLowerCase().includes(c.toLowerCase().trim())),T=(_,O)=>{const D=x.includes(_.name),N=x.includes(O.name);if(D&&!N)return-1;if(!D&&N)return 1;if(h===Ns.ASC)return _.name.localeCompare(O.name);if(h===Ns.DESC)return O.name.localeCompare(_.name);const A=b.get(_.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(_=>_.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 N=v.map(U=>U.name),M=N.filter(U=>!r.includes(U)).length>0;N.forEach(U=>{s(U,M)})}};return window.addEventListener("keydown",R),()=>{window.removeEventListener("keydown",R)}},[v,r,s]),!n||!t?o.jsxs(Eo,{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(Eo,{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(Mr,{children:[o.jsx(kr,{asChild:!0,children:o.jsxs(Ce,{variant:"ghost",size:"icon","aria-label":"Sort fields",children:[h===Ns.ASC&&o.jsx(H2,{className:"text-muted-foreground h-4 w-4"}),h===Ns.DESC&&o.jsx(V2,{className:"text-muted-foreground h-4 w-4"}),h===Ns.ORIGINAL&&o.jsx($2,{className:"text-muted-foreground h-4 w-4"})]})}),o.jsxs(Ir,{align:"end",children:[o.jsxs(_t,{onSelect:()=>{m(Ns.ASC)},children:[o.jsx(H2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"A–Z"]}),o.jsxs(_t,{onSelect:()=>{m(Ns.DESC)},children:[o.jsx(V2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Z–A"]}),o.jsxs(_t,{onSelect:()=>{m(Ns.ORIGINAL)},children:[o.jsx($2,{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(xO,{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:_=>{s(R.name,_)},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(i0,{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(i0,{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(Eo,{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 SO=p.createContext(void 0),CO={triggers:[],selectedTrigger:null,isLoading:!1,error:null};function Fee(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 CO;default:return e}}class zee 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 zee;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 J0{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 vo.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 Vee{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 qx={getMapper(e){switch(e){case xn.REPORT_RUN:return new J0;case xn.CONNECTOR_RUN:return new Vee;default:throw new Error(`Unknown scheduled trigger type: ${String(e)}`)}}},Ld={mapFromDto(e){return qx.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 J0().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 J0,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 qx.getMapper(e.type).mapToCreateRequest(e)},mapToUpdateRequest(e){return qx.getMapper(e.type).mapToUpdateRequest(e)}};function Hee({children:e}){const[t,n]=p.useReducer(Fee,CO),{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 _={type:w,cronExpression:C,timeZone:E,isActive:R,triggerConfig:T},O=await Uc.createScheduledTrigger(b,_),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}),rn.success("Trigger created"),D}catch(_){const O=_ instanceof Error?_.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}),_}},[r]),m=p.useCallback(async(b,w,C,E,R)=>{n({type:"UPDATE_TRIGGER_START"});try{const T={cronExpression:C,timeZone:E,isActive:R},_=await Uc.updateScheduledTrigger(b,w,T),O=await Ld.mapFromDtoWithReportData(_,r);n({type:"UPDATE_TRIGGER_SUCCESS",payload:O}),Fe({event:"scheduled_trigger_updated",category:"ScheduledTrigger",action:"Update",label:O.type}),rn.success("Trigger updated")}catch(T){const _=T instanceof Error?T.message:"Failed to update scheduled trigger";throw n({type:"UPDATE_TRIGGER_ERROR",payload:_}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"UpdateError",label:_}),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}),rn.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(SO.Provider,{value:{...t,getScheduledTriggers:l,getScheduledTriggersByType:c,getScheduledTrigger:d,createScheduledTrigger:h,updateScheduledTrigger:m,deleteScheduledTrigger:g,selectScheduledTrigger:v,reset:x},children:e})}function wO(){const e=p.useContext(SO);if(e===void 0)throw new Error("useScheduledTriggerContext must be used within a ScheduledTriggerProvider");return e}function $ee(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}=wO();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 Bee=an({type:Gs(Kc.SCHEDULED_REPORT_RUN),reportId:sn().min(1,"Report ID is required")}),Gee=uB(),qee=an({type:s1(xn),cronExpression:sn().min(1,"Cron expression is required"),timeZone:sn().min(1,"Time zone is required"),isActive:cB(),triggerConfig:fB([Bee,Gee])});function Zee({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 Kee({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===Ut.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 Pg="Switch",[Yee]=Dr(Pg),[Wee,Qee]=Yee(Pg),EO=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,_=>b(_)),C=p.useRef(!1),E=x?g||!!x.closest("form"):!0,[R,T]=zr({prop:s,defaultProp:l??!1,onChange:m,caller:Pg});return o.jsxs(Wee,{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,_=>{T(O=>!O),E&&(C.current=_.isPropagationStopped(),C.current||_.stopPropagation())})}),E&&o.jsx(_O,{control:x,bubbles:!C.current,name:r,value:h,checked:R,required:c,disabled:d,form:g,style:{transform:"translateX(-100%)"}})]})});EO.displayName=Pg;var RO="SwitchThumb",TO=p.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,s=Qee(RO,n);return o.jsx(Ke.span,{"data-state":jO(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:t})});TO.displayName=RO;var Xee="SwitchBubbleInput",_O=p.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...s},l)=>{const c=p.useRef(null),d=vt(c,l),h=F1(n),m=Pb(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}})});_O.displayName=Xee;function jO(e){return e?"checked":"unchecked"}var Jee=EO,ete=TO;function NO({className:e,...t}){return o.jsx(Jee,{"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(ete,{"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 tte(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 eb(e,t="UTC"){const n=tte(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 AO({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(_r,{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(_r,{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(_r,{variant:"outline",className:"h-5 text-xs",children:["+",v.length-1]})]})};return o.jsxs(G1,{open:c,onOpenChange:d,modal:!0,children:[o.jsx(q1,{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(bb,{className:"ml-2 h-3 w-3 shrink-0 opacity-50"})]})}),o.jsx(Z1,{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(ND,{placeholder:s,className:"h-8"}),o.jsxs(tJ,{className:"h-full max-h-[350px] overflow-y-auto",children:[o.jsx(AD,{children:"No items found."}),o.jsx(DD,{className:"h-full overflow-visible",children:e.map(v=>o.jsxs(OD,{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 DO=[{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 OO(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=DO.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 nte(e,t,n=!0){const r=eb(e,t);return OO(r,n)}const rte=Array.from({length:31},(e,t)=>({value:t+1,label:`${String(t+1)}${t===0?"st":t===1?"nd":t===2?"rd":"th"}`})),tb=[5,10,15,30],nb=[1,2,3,4,6,8,12],ate=({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"})]})]})]}),ste=({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})})]}),zT=({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(K1,{options:r,value:e,onValueChange:t,placeholder:"Select timezone",emptyMessage:"No timezones found",disabled:n,className:"w-full"})})]}),ote=({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(AO,{options:DO,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:3})})]}),ite=({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(AO,{options:rte,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:4})})]}),lte=({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"?tb:nb).map(l=>o.jsxs(qn,{value:l.toString(),children:[l," ",e==="minutes"?"min":"hr"]},l))})]})]})]}),cte=({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 ute({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(()=>IG.getTimezonesWithOffset().map(H=>({value:H.identifier,label:H.displayName,offset:H.offsetString,isDST:H.isDST})),[]),[w,C]=p.useState(()=>eb(e,m)),[E,R]=p.useState(""),[T,_]=p.useState("");p.useEffect(()=>{h(n)},[n]),p.useEffect(()=>{const H=t??Om();g(H)},[t]),p.useEffect(()=>{if(e){const H=eb(e,m);C(H)}},[e,m]);const O=H=>{const[B,I]=H.time.split(":").map(Number);switch(H.type){case"daily":return`${String(I)} ${String(B)} * * *`;case"weekly":return`${String(I)} ${String(B)} * * ${H.weekdays.join(",")}`;case"monthly":return`${String(I)} ${String(B)} ${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(B)} * * *`}},D=p.useCallback(H=>{C(B=>{if(B.intervalType===H)return console.log("Type unchanged, skipping update"),B;const K=(H==="minutes"?tb:nb)[0];return{...B,intervalType:H,intervalValue:K}})},[]),N=p.useCallback(H=>{C(B=>(B.intervalType==="minutes"?tb:nb).includes(H)?{...B,intervalValue:H}:B)},[]),A=p.useMemo(()=>H=>OO(H,d),[d]);p.useEffect(()=>{const H=O(w);R(H),_(A(w))},[w,d,m,A]);const M=p.useRef(""),U=p.useRef(""),Z=p.useRef(!1);p.useEffect(()=>{const H=O(w);r&&(M.current!==H||U.current!==m||Z.current!==d)&&(r({cron:H,timezone:m,enabled:d}),M.current=H,U.current=m,Z.current=d)},[w,m,d,r]);const $=H=>{h(H)},Q=H=>{g(H),C(B=>({...B,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(NO,{id:"schedule-enabled",checked:d,onCheckedChange:$})]})]})}),o.jsxs("div",{className:"space-y-4 pt-0",children:[o.jsxs("div",{className:`space-y-4 ${d?"":"opacity-50"}`,children:[o.jsx(ate,{value:w.type,onChange:H=>{C(B=>({...B,type:H}))},disabled:!d}),w.type!=="custom"&&w.type!=="interval"&&o.jsxs("div",{className:"flex gap-3",children:[o.jsx(ste,{value:w.time,onChange:H=>{C(B=>({...B,time:H}))},disabled:!d}),re&&o.jsx(zT,{value:m,onChange:Q,disabled:!d,timezones:b})]}),(w.type==="interval"||w.type==="custom")&&o.jsx(zT,{value:m,onChange:Q,disabled:!d,timezones:b}),w.type==="weekly"&&o.jsx(ote,{value:w.weekdays,onChange:H=>{C(B=>({...B,weekdays:H}))},disabled:!d}),w.type==="monthly"&&o.jsx(ite,{value:w.monthDays,onChange:H=>{C(B=>({...B,monthDays:H}))},disabled:!d}),w.type==="interval"&&o.jsx(lte,{intervalType:w.intervalType,intervalValue:w.intervalValue,onTypeChange:D,onValueChange:N,disabled:!d}),w.type==="custom"&&o.jsx(cte,{value:w.customCron,onChange:H=>{C(B=>({...B,customCron:H}))},disabled:!d})]}),l&&o.jsxs(o.Fragment,{children:[o.jsx(cj,{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(K_,{className:"h-4 w-4"}),o.jsx("span",{className:"text-sm font-medium",children:"Preview"})]}),v?o.jsx(Ps,{className:"text-muted-foreground h-4 w-4"}):o.jsx(Ra,{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(_r,{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(_r,{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(_r,{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(sS,{className:"border-amber-200 bg-amber-50",children:[o.jsx(Sf,{className:"h-4 w-4"}),o.jsx(lO,{children:"Time Zone"}),o.jsxs(oS,{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 dte(){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 fte(){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 hte(){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 mte(){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 pte({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}=Zee({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(fte,{}):o.jsx(dte,{})}),o.jsx(on,{})]})}),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(R4,{children:o.jsx(Kee,{value:E.value,onChange:E.onChange,disabled:!!t||!!e})})}),o.jsx(ar,{children:e!=null&&e.triggerConfig?o.jsx(hte,{}):o.jsx(mte,{})}),o.jsx(on,{})]})}),o.jsx(ute,{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 gte({cronExpression:e,timeZone:t,isEnabled:n=!0}){const r=p.useMemo(()=>nte(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 vte({table:e}){return o.jsx("div",{className:"text-right",children:o.jsxs(Mr,{children:[o.jsx(kr,{asChild:!0,children:o.jsx(Ce,{variant:"ghost",className:"dm-card-table-body-row-actionbtn","aria-label":"Toggle columns",children:o.jsx(Za,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsx(Ir,{align:"end",children:e.getAllColumns().filter(t=>t.getCanHide()&&t.id!=="actions").map(t=>o.jsx(_t,{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 yte({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(Mr,{open:r,onOpenChange:s,children:[o.jsx(kr,{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(Za,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsxs(Ir,{align:"end",children:[o.jsxs(_t,{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(_t,{onClick:()=>{c(!0)},children:[o.jsx(Mo,{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 xte(e,t){const n=t.find(r=>r.name===e.source.name);return(n==null?void 0:n.displayName)??e.source.name}function bte({connector:e}){const{connectors:t}=ql(),n=xte(e,t);return o.jsx(o.Fragment,{children:n})}function MO({connector:e}){return o.jsx(bte,{connector:e})}function Ste(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 Cte=e=>{const{connectors:t}=ql();return p.useMemo(()=>t.find(n=>n.name===e),[t,e])},wte=_e.memo(function({connector:t,children:n}){const r=Cte(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&&fq(s.storage,t.storage.fullyQualifiedName)},[s==null?void 0:s.storage,t.storage.fullyQualifiedName]),m=p.useMemo(()=>Ste(l),[l]),g=p.useMemo(()=>!m.lastRunDate||!m.lastRunStatus?null:{statusType:jZ(m.lastRunStatus),statusText:AZ(m.lastRunStatus),date:m.lastRunDate},[m]),v=p.useMemo(()=>(s==null?void 0:s.storage)&&hq(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(f1,{children:[o.jsx(h1,{asChild:!0,children:o.jsx("span",{children:n})}),o.jsxs(m1,{children:[o.jsxs(p1,{children:[o.jsx(g1,{children:d}),o.jsxs(v1,{children:[o.jsx(y1,{children:o.jsx(MO,{connector:t})}),o.jsx(x1,{children:x})]})]}),o.jsxs(b1,{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(S1,{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 Ete(e){const t=e.triggerConfig;return o.jsxs("div",{className:"inline gap-1",children:[t.report.title,o.jsx(TZ,{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 Rte(e){const t=e.triggerConfig,{connector:n}=t.connector;return o.jsxs("div",{className:"inline gap-1",children:[o.jsx(MO,{connector:n}),o.jsx(wte,{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 Tte({trigger:e}){switch(e.type){case xn.REPORT_RUN:return Ete(e);case xn.CONNECTOR_RUN:return Rte(e);default:return o.jsx("div",{className:"text-muted-foreground text-sm",children:"—"})}}function _te({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(_r,{variant:"outline",children:s})},meta:{title:"Trigger Type"}},{accessorKey:"triggerConfig",size:35,header:"Run Target",cell:({row:n})=>o.jsx(Tte,{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(gte,{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(vte,{table:n}),cell:({row:n})=>o.jsx(yte,{trigger:n.original,onEditTrigger:e,onDeleteTrigger:t}),meta:{title:"Actions"}}]}function jte({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 cS({isOpen:e,onClose:t,dataMartId:n,preSelectedReportId:r,preSelectedType:s}){const{createScheduledTrigger:l,updateScheduledTrigger:c,selectedTrigger:d}=wO(),[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()},_=p.useRef(!1);return p.useEffect(()=>{const O=E?"Edit":"Create",D=(d==null?void 0:d.type)??s;e&&!_.current?(Fe({event:"scheduled_trigger_config_open",category:"ScheduledTrigger",action:O,label:D}),_.current=!0):!e&&_.current&&(Fe({event:"scheduled_trigger_config_close",category:"ScheduledTrigger",action:O,label:D}),_.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(pte,{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 Nte({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(()=>_te({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:wg(),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(_u,{id:"scheduled-triggers-table",className:"dm-card-table",role:"table","aria-label":"Scheduled Triggers",children:[o.jsx(ju,{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((_,O)=>o.jsx(ya,{className:`whitespace-normal ${_.column.id==="actions"?"actions-cell":""}`,role:"cell","aria-colindex":O+1,style:_.column.id==="type"?{width:150,minWidth:150,maxWidth:150}:_.column.id==="actions"?{width:80,minWidth:80,maxWidth:80}:{width:`${String(_.column.getSize())}%`},children:typeof _.column.columnDef.cell=="function"?_.column.columnDef.cell(_.getContext()):_.column.columnDef.cell},_.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(jte,{table:b,onPreviousClick:w,onNextClick:C}),o.jsx(cS,{isOpen:s,onClose:c,dataMartId:t})]})}function Ate({dataMartId:e}){const{triggers:t,deleteScheduledTrigger:n,selectScheduledTrigger:r,selectedTrigger:s}=$ee(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(Nte,{triggers:t,dataMartId:e,onEditTrigger:d,onDeleteTrigger:g=>void m(g)}),o.jsx(cS,{isOpen:l,onClose:h,dataMartId:e})]})}function kO(){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(W_,{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 Dte({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=_=>_.trim()?/^[A-Za-z][A-Za-z0-9_]*$/.test(_)?null:"Use letters, numbers, and underscores; start with a letter":"This field is required",E=p.useCallback((_,O,D,N)=>{s({fullyQualifiedName:`${_}.${O}`,isValid:!!(_&&O&&D===null&&N===null)})},[s]);p.useEffect(()=>{let _="",O="";if(t!=null&&t.fullyQualifiedName){const U=t.fullyQualifiedName.split(".");_=U[0]??"",O=U[1]??""}else _=`${c}_owox`,O=l;const D=C(_),N=C(O);h(_),g(O),x(D),w(N);const A=`${_}.${O}`,M=!!(_&&O&&D===null&&N===null);((t==null?void 0:t.fullyQualifiedName)!==A||t.isValid!==M)&&E(_,O,D,N)},[t,l,c,E]);const R=_=>{h(_);const O=C(_);x(O),E(_,m,O,b)},T=_=>{g(_);const O=C(_);w(O),E(d,_,v,O)};return o.jsxs(Eo,{children:[e===Pe.GOOGLE_BIGQUERY&&o.jsxs(o.Fragment,{children:[o.jsx(Di,{icon:o.jsx(HA,{}),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(Co,{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:_=>{R(_.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(Co,{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:_=>{T(_.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($A,{}),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(Co,{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:_=>{R(_.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(Co,{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:_=>{T(_.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(kO,{})})]})}function Ote({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),[_,O]=p.useState(new Set),[D,N]=p.useState(new Set),{connectors:A,connectorSpecification:M,connectorFields:U,loading:Z,loadingSpecification:$,loadingFields:Q,error:re,fetchAvailableConnectors:H,fetchConnectorSpecification:B,fetchConnectorFields:I}=ql(),[K,q]=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=>{!_.has(Ie)&&!$&&(O(Ct=>new Set(Ct).add(Ie)),await B(Ie))},[_,$,B]),P=p.useCallback(async Ie=>{D.has(Ie)||(N(Ct=>new Set(Ct).add(Ie)),await I(Ie))},[D,I]);p.useEffect(()=>{if(!c||d||A.length===0)return;const Ie=A.find(Ct=>Ct.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&&!Z&&H(),r&&A.length>0&&!d){const{source:Ie,storage:Ct}=r;g(Ie.node),x(Ie.fields),E(Ie.configuration[0]||{}),q({fullyQualifiedName:Ct.fullyQualifiedName,isValid:!0});const jt=A.find(tn=>tn.name===Ie.name);jt&&(h(jt),L(jt.name),!n&&s!=="fields-only"&&P(jt.name),s==="fields-only"&&P(jt.name))}if(n&&A.length>0&&!d&&!r){const Ie=A[0];h(Ie),L(Ie.name)}},[s,r,A,n,Z,H,L,P,d]);const Y=Ie=>{h(Ie),E({}),T(!1),O(Ct=>{const jt=new Set(Ct);return jt.delete(Ie.name),jt}),L(Ie.name),P(Ie.name)},ae=Ie=>{g(Ie),x([])},fe=(Ie,Ct)=>{x(Ct?jt=>jt.includes(Ie)?jt:[...jt,Ie]:jt=>jt.filter(tn=>tn!==Ie))},ge=(Ie,Ct)=>{x(Ct?jt=>{const tn=Ie.filter(V=>!jt.includes(V));return[...jt,...tn]}:jt=>jt.filter(tn=>!Ie.includes(tn)))},ue=Ie=>{q(Ie)},Ne=p.useCallback(Ie=>{E(Ie)},[]),Re=p.useCallback(Ie=>{T(Ie)},[]);p.useEffect(()=>{M&&(M.some(Ct=>Ct.required&&Ct.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 K!==null&&K.fullyQualifiedName!==""&&K.isValid;default:return!1}},Bt=()=>b>1,ft=(Ie,Ct)=>{if(!Ie)return Ct;const jt=Ie.find(tn=>tn.name===Ct);return(jt==null?void 0:jt.destinationName)??Ct},gn=()=>{if(n&&b===1)return M&&d?o.jsx(UT,{connector:d,connectorSpecification:M,onConfigurationChange:Ne,onValidationChange:Re,initialConfiguration:C,loading:$,isEditingExisting:!!(r!=null&&r.source.configuration.length)}):null;if(s==="fields-only")switch(b){case 1:return d&&m&&U?o.jsx(FT,{connector:d,connectorFields:U,selectedField:m,selectedFields:v,onFieldToggle:fe,onSelectAllFields:ge}):null;default:return null}switch(b){case 1:return o.jsx(Tee,{connectors:A,selectedConnector:d,loading:Z,error:re,onConnectorSelect:Y,onConnectorDoubleClick:()=>{w(Ie=>Ie<be?Ie+1:Ie)}});case 2:return d&&M?o.jsx(UT,{connector:d,connectorSpecification:M,onConfigurationChange:Ne,onValidationChange:Re,initialConfiguration:C,loading:$,isEditingExisting:!1}):null;case 3:return d&&U?o.jsx(Uee,{connectorFields:U,connector:d,selectedField:m,connectorName:d.displayName,loading:Q,onFieldSelect:ae}):null;case 4:return d&&m&&U?o.jsx(FT,{connector:d,connectorFields:U,selectedField:m,selectedFields:v,onFieldToggle:fe,onSelectAllFields:ge}):null;case 5:return m&&U?o.jsx(Dte,{dataStorageType:t,destinationName:ft(U,m),connectorName:(d==null?void 0:d.displayName)??"",target:K,onTargetChange:ue}):null;default:return null}};return o.jsxs(xee,{children:[o.jsx(bee,{children:gn()}),o.jsx(See,{variant:"horizontal",children:o.jsx(_ee,{currentStep:b,totalSteps:be,canGoNext:Xe(),canGoBack:Bt(),isLoading:$||Q,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&&K&&e({source:{name:d.name,configuration:[C],node:m,fields:v},storage:{fullyQualifiedName:K.fullyQualifiedName}})}})})]})}const IO=20,LO=20;function PO({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 Mte(e=30,t=0){PO({vertical:LO+e,horizontal:IO+t})}function rb(){PO({vertical:LO,horizontal:IO})}function UO({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?Mte(55):rb(),()=>{rb()}),[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(Ote,{onSubmit:m=>{r(m),t()},dataStorageType:n,configurationOnly:s||c==="configuration-only",existingConnector:l,mode:c,initialStep:d,preselectedConnector:h})]})})}const uS=({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(UO,{isOpen:h,onClose:C,dataStorageType:e,onSubmit:t,configurationOnly:r,existingConnector:s,initialStep:g,preselectedConnector:x})})]})};function kte({storageType:e,onSetupConnector:t,preset:n,isOpen:r,onClose:s}){return o.jsx(uS,{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(wb,{className:"h-4 w-4",strokeWidth:2.25})}),o.jsx("span",{children:"Setup Connector"}),o.jsx(ps,{className:"h-6 w-6"})]})})}const Ite=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 Lte({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(At,{children:[o.jsx(Dt,{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(ps,{className:"h-3 w-3"})]})}),o.jsx(Ot,{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],_=`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,_),o.jsx("span",{className:"text-muted-foreground",children:"•"}),x("Table",T,O),o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(Fr,{className:"h-4 w-4"})}),o.jsx(Ot,{children:"The dataset and table are automatically created during the first run of the data mart, if they don't already exist"})]})]})}case Pe.AWS_ATHENA:{const C=c.config.region,E=t.connector.storage.fullyQualifiedName,[R,T]=E.split("."),_=`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,_),o.jsx("span",{className:"text-muted-foreground",children:"•"}),x("Table",T,_),o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(Fr,{className:"h-4 w-4"})}),o.jsx(Ot,{children:"The database and table are automatically created during the first run of the data mart, if they don't already exist"})]})]})}default:return"Unknown storage type configuration"}},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(uS,{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(Z0,{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(Z0,{title:Ite(c.type),icon:d.icon,subtitle:b(),className:"bg-background min-h-[80px] cursor-default border-0 hover:shadow-none dark:bg-white/2"})]})}),o.jsx("div",{className:"shrink-0 px-4",children:o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(Ce,{type:"button",variant:"ghost",onClick:()=>{w()&&n(e)},disabled:!w(),children:o.jsx(Mo,{className:"h-4 w-4"})})}),!w()&&o.jsx(Ot,{children:"Cannot remove the last configuration in published pipeline"})]})})]})}function Pte({storageType:e,onAddConfiguration:t,existingConnector:n}){return o.jsx("div",{children:o.jsx(uS,{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 Ute({control:e,storageType:t,preset:n,autoOpen:r=!1}){const{dataMart:s,runDataMart:l}=ms(),{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){Nt.error("Manual run is only available for published data marts");return}await l({id:s.id,payload:A})}},R=A=>M=>{const Z=d().definition;if(typeof Z=="object"&&qc(Z)){const $=[...Z.connector.source.configuration];$[A]=M.source.configuration[0]||{};const Q={connector:{...Z.connector,source:{...Z.connector.source,configuration:$}}};c("definition",Q,{shouldDirty:!0,shouldTouch:!0}),b()}},T=A=>{const U=d().definition;if(typeof U=="object"&&qc(U)){const Z={connector:{...U.connector,source:{...U.connector.source,fields:A.source.fields}}};c("definition",Z,{shouldDirty:!0,shouldTouch:!0}),b()}g(!1)},_=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(iL,{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 Z=Q0(qe.CONNECTOR);c("definition",Z,{shouldDirty:!0,shouldTouch:!0}),b()}if(typeof U=="object"&&qc(U)&&U.connector.source.configuration.length>1){const Z={...U.connector.source,configuration:U.connector.source.configuration.filter((Q,re)=>re!==A)},$={connector:{...U.connector,source:Z}};c("definition",$,{shouldDirty:!0,shouldTouch:!0}),b()}},N=A=>{const U=d().definition;if(qc(U)){const Z={...U.connector.source,configuration:[...U.connector.source.configuration,A]},$={connector:{...U.connector,source:Z}};c("definition",$,{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(kte,{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(Pte,{storageType:t,onAddConfiguration:N,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(dD,{configuration:s.definition,onManualRun:_,children:o.jsxs(Ce,{variant:"outline",children:[o.jsx(Cb,{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 Z=A.value;return o.jsx(hu,{children:o.jsx(Lte,{configIndex:U,connectorDef:Z,dataStorage:s.storage,onRemoveConfiguration:D,onUpdateConfiguration:R,dataMartStatus:typeof w=="object"?w.code:w,totalConfigurations:Z.connector.source.configuration.length},U)},U)}):null})]})})}),o.jsx(on,{})]})}),o.jsx(hu,{children:o.jsx(UO,{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 Fte({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(tee,{control:r}),e===qe.TABLE&&o.jsx(nee,{control:r,storageType:t}),e===qe.VIEW&&o.jsx(ree,{control:r,storageType:t}),e===qe.TABLE_PATTERN&&o.jsx(aee,{control:r,storageType:t}),e===qe.CONNECTOR&&o.jsx(Ute,{control:r,storageType:t,preset:n,autoOpen:s})]})}function FO(){const[e]=pI(),t=e.get("preset");return p.useMemo(()=>{if(!t)return;const n=t.toLowerCase();return nY(n)},[t])}function zte(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 Vte(e,t){const[n,r]=p.useState(e);return p.useEffect(()=>{const s=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(s)}},[e,t]),n}const Hte=1e3,$te=[Cl.SUCCESS,Cl.ERROR,Cl.CANCELLED];function Bte(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 cn.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 cn.getSqlDryRunTriggerStatus(e,v);if($te.includes(b)){const w=await cn.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,Hte))}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 cn.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&&cn.abortSqlDryRunTrigger(e,v).catch(()=>{})},[e]),{validateSql:g,isLoading:t,result:r,cancel:h}}const Gte=300;function qte({sql:e,dataMartId:t,debounceDelay:n=Gte,className:r="",onValidationStateChange:s}){const l=Vte(e.trim(),n),{validateSql:c,isLoading:d,result:h,cancel:m}=Bte(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($_,{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(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx(Xm,{className:"h-3 w-3 text-gray-600"}),o.jsx("span",{className:"text-xs text-gray-600",children:zte(h.bytes)})]})}),o.jsx(Ot,{children:o.jsx("p",{className:"text-xs",children:"This is an estimated volume and may differ from the actual value"})})]})]})]}):o.jsxs("div",{className:"flex h-9 items-center gap-2",children:[o.jsx(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(Xm,{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 Zte(){const{dataMart:e,updateDataMartDefinition:t,getDataMart:n}=ms(),r=FO();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 B={definitionType:h,definition:Q0(h)};return l?{definitionType:h,definition:l}:B},[h,l]),x=p.useCallback(()=>{if(!h)return;const B=eee(h,d);return Wl(B)},[h,d]),b=$i({resolver:x(),defaultValues:v(),mode:"onChange"}),{handleSubmit:w,reset:C,watch:E,formState:{isDirty:R,isValid:T}}=b,_=(B,I)=>{if(B!==qe.SQL)return"";const K=I;return(K==null?void 0:K.sqlQuery)??""},O=E("definition"),D=_(h,O);p.useEffect(()=>{h&&C(v())},[h,C,v]);const N=B=>Q0(B);p.useEffect(()=>{if(!h&&!s&&(r!=null&&r.definitionType)){m(r.definitionType);const B={definitionType:r.definitionType,definition:N(r.definitionType)};C(B)}},[r,h,s,C]);const A=p.useCallback(B=>{g({isLoading:B.isLoading,isValid:B.isValid,error:B.error})},[]),M=B=>{m(B)},U=p.useCallback(()=>{c&&n(c)},[c,n]),{run:Z}=H1(c,U),$=async B=>{if(h&&c)try{await t(c,B.definitionType,B.definition),await Z(),C(B)}catch(I){console.error("Failed to update data mart definition:",I)}},Q=B=>{B.preventDefault(),w($)(B)},re=()=>{C(v())},H=()=>h?o.jsxs("form",{onSubmit:Q,className:"space-y-4",children:[o.jsx(Fte,{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(p3,{...b,children:o.jsxs("div",{className:"space-y-4",children:[!s&&o.jsx(KJ,{initialType:h,onTypeSelect:M}),H()]})})}function Kte(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 zO(e){return e.type==="bigquery-data-mart-schema"}function VO(e){return e.type==="athena-data-mart-schema"}function VT(e){return e!==null&&typeof e=="object"&&"mode"in e}function HT(e){return e!==null&&typeof e=="object"&&"isPrimaryKey"in e}function Yte(e){return e==null?"":typeof e=="string"||typeof e=="number"||typeof e=="boolean"?String(e):""}function Zx(e){return e==null?e:JSON.parse(JSON.stringify(e))}function Wte(e){const t=Zx(e),[n,r]=p.useState(t),[s,l]=p.useState(!1);p.useEffect(()=>{const h=Zx(e);r(h),l(!1)},[e]);const c=p.useCallback(h=>{n?zO(n)&&h.every(VT)?(r({...n,fields:h}),l(!0)):VO(n)&&h.every(HT)&&(r({...n,fields:h}),l(!0)):h.length>0&&(VT(h[0])?(r({type:"bigquery-data-mart-schema",fields:h}),l(!0)):HT(h[0])&&(r({type:"athena-data-mart-schema",fields:h}),l(!0)))},[n]),d=p.useCallback(()=>{const h=Zx(e);r(h),l(!1)},[e]);return{schema:n,isDirty:s,updateSchema:c,resetSchema:d,setIsDirty:l}}function Qte(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 Xte(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 HO(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=>HO(c,t)):!1}function $O(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=$O(s.fields,t,c);g.length>0&&(r.includes(c)||r.push(c),r.push(...g))}}),r}function Jte(e,t,n){const r=e.original;if(!n)return!0;const s=n.toLowerCase();return HO(r,s)}function ene(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 ls=(e=>(e.CONNECTED="CONNECTED",e.CONNECTED_WITH_DEFINITION_MISMATCH="CONNECTED_WITH_DEFINITION_MISMATCH",e.DISCONNECTED="DISCONNECTED",e))(ls||{}),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||{}),dS=(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))(dS||{});function tne(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,_)=>{const O=R?`${R}.${String(_)}`:String(_);(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((_,O)=>{const D=R?`${R}.${String(O)}`:String(O),N=_.type===Pn.RECORD||_.type===Pn.STRUCT;w.push({..._,path:D,level:T}),N&&_.fields&&t.has(D)&&C(_.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=$O(e,w).filter(R=>{const T=R.split(".").map(Number);let _=e,O;for(let D=0;D<T.length;D++){if(O=_[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&&(_=O.fields??[])}return!1});n(R=>{const T=new Set(R);return E.forEach(_=>{T.add(_)}),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,_)=>{const O=R?`${R}.${String(_)}`:String(_);(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 nne(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:ls.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:ls.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 BO(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 rne(){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 Ug=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 fS(e){return"nodeType"in e}function ta(e){var t,n;return e?ku(e)?e:fS(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function hS(e){const{Document:t}=ta(e);return e instanceof t}function Wf(e){return ku(e)?!1:e instanceof ta(e).HTMLElement}function GO(e){return e instanceof ta(e).SVGElement}function Iu(e){return e?ku(e)?e.document:fS(e)?hS(e)?e:Wf(e)||GO(e)?e.ownerDocument:document:document:document}const Vs=Ug?p.useLayoutEffect:p.useEffect;function mS(e){const t=p.useRef(e);return Vs(()=>{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 ane(){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 Vs(()=>{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 Op(e){const t=mS(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 ab(e){const t=p.useRef();return p.useEffect(()=>{t.current=e},[e]),t.current}let Kx={};function Xf(e,t){return p.useMemo(()=>{if(t)return t;const n=Kx[e]==null?0:Kx[e]+1;return Kx[e]=n,e+"-"+n},[e,t])}function qO(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=qO(1),Mp=qO(-1);function sne(e){return"clientX"in e&&"clientY"in e}function pS(e){if(!e)return!1;const{KeyboardEvent:t}=ta(e.target);return t&&e instanceof t}function one(e){if(!e)return!1;const{TouchEvent:t}=ta(e.target);return t&&e instanceof t}function sb(e){if(one(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 sne(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}}}),$T="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function ine(e){return e.matches($T)?e:e.querySelector($T)}const lne={display:"none"};function cne(e){let{id:t,value:n}=e;return _e.createElement("div",{id:t,style:lne},n)}function une(e){let{id:t,announcement:n,ariaLiveType:r="assertive"}=e;const s={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return _e.createElement("div",{id:t,style:s,role:"status","aria-live":r,"aria-atomic":!0},n)}function dne(){const[e,t]=p.useState("");return{announce:p.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const ZO=p.createContext(null);function fne(e){const t=p.useContext(ZO);p.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function hne(){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 mne={draggable:`
721
+ `).filter(m=>m.trim());n(r,h)}})}function Dee({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 Oee({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 Mee({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 kee({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?X0: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 Iee({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(K1,{options:h,value:t[s]||c||"",onValueChange:m=>{n(s,m)},placeholder:l??`Select ${d.toLowerCase()}`,emptyMessage:"No options available",className:"w-full"})}function bO({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(kee,{specification:e,configuration:t,onValueChange:n,isEditingExisting:d,isSecretEditing:h});if(l&&l.length>0)return o.jsx(Iee,{specification:e,configuration:t,onValueChange:n,specOptions:l});switch(s){case ns.BOOLEAN:return o.jsx(jee,{specification:e,configuration:t,onValueChange:n});case ns.NUMBER:return o.jsx(Nee,{specification:e,configuration:t,onValueChange:n});case ns.ARRAY:return o.jsx(Aee,{specification:e,configuration:t,onValueChange:n});case ns.OBJECT:return o.jsx(Mee,{specification:e,configuration:t,onValueChange:n});case ns.DATE:return o.jsx(Dee,{specification:e,configuration:t,onValueChange:n});case ns.STRING:default:return o.jsx(Oee,{specification:e,configuration:t,onValueChange:n})}}function Lee({specification:e,configuration:t,isEditingExisting:n,isSecretEditing:r,isSecret:s,onValueChange:l,onSecretEditToggle:c}){return o.jsxs($d,{children:[e.requiredType!==ns.BOOLEAN&&o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(Co,{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"})]}),bO({specification:e,configuration:t,onValueChange:l,flags:{isSecret:s,isEditingExisting:n,isSecretEditing:r}})]},e.name)}function Pee({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(Cee,{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(pee,{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(Co,{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"})]}),bO({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 LT(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===ns.OBJECT?o.jsx(Pee,{specification:c,configuration:t,onValueChange:n,isEditingExisting:l,isSecretEditing:h,onSecretEditToggle:r},c.name):o.jsx(Lee,{specification:c,configuration:t,isEditingExisting:l,isSecret:d,isSecretEditing:h,onValueChange:n,onSecretEditToggle:r},c.name)})}function PT({collapsibleTitle:e,items:t,configuration:n,onValueChange:r,onSecretEditToggle:s,secretEditing:l,isEditingExisting:c}){return e?o.jsx(wee,{title:e,children:LT(t,n,r,s,l,c)}):LT(t,n,r,s,l,c)}function UT({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 D={...s??{}};t.forEach(N=>{const A=Array.isArray(N.attributes)?N.attributes.includes("SECRET"):!1;D[N.name]===void 0&&N.default!==void 0&&(D[N.name]=N.default),c&&A&&(D[N.name]=X0)}),h(D),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=(D,N)=>{h(A=>({...A,[D]:N}))},w=p.useCallback(D=>!(D==null||typeof D=="string"&&D.trim()===""||Array.isArray(D)&&D.length===0),[]),C=p.useCallback((D,N)=>{var M;if(typeof D!="object"||D===null)return w(D);const A=(M=N.oneOf)==null?void 0:M.filter(U=>U.value===Object.keys(D)[0]);return A?A.every(U=>Object.entries(U.items).every(([,Z])=>U.value in D?C(D[U.value],Z):!1)):w(D[N.name])},[w]),E=p.useCallback((D,N)=>{const A=N.filter($=>$.required&&$.oneOf),M=A.length===0?!0:A.some($=>C(D[$.name],$)),Z=N.filter($=>$.required&&$.name!=="Fields").every($=>w(D[$.name]));return M&&Z},[w,C]),R=(D,N)=>{x(A=>({...A,[D]:N})),h(N?A=>({...A,[D]:""}):A=>({...A,[D]:X0}))};if(p.useEffect(()=>{if(t&&r){const D=E(d,t);r(D)}},[d,t,r,E]),l)return o.jsx(lS,{variant:"list"});if(!t||t.length===0)return o.jsxs(Eo,{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 T=[...t].filter(D=>{var N;return D.name!=="Fields"&&!((N=D.attributes)!=null&&N.includes("HIDE_IN_CONFIG_FORM"))}).sort((D,N)=>{const A=M=>{const U=M.default!=null&&M.default!=="";return M.required&&!U?1:M.required&&U?2:!M.required&&!U?3:4};return A(D)-A(N)}),_=T.filter(D=>{var N;return!((N=D.attributes)!=null&&N.includes("ADVANCED"))}),O=T.filter(D=>{var N;return(N=D.attributes)==null?void 0:N.includes("ADVANCED")});return o.jsx(o.Fragment,{children:o.jsxs(Eo,{children:[o.jsx(El,{connector:e}),o.jsxs(wl,{title:"Configure Settings",children:[_.length>0&&o.jsx(PT,{items:_,configuration:d,onValueChange:b,onSecretEditToggle:R,secretEditing:v,isEditingExisting:c}),O.length>0&&o.jsx(PT,{collapsibleTitle:"Advanced Fields",items:O,configuration:d,onValueChange:b,onSecretEditToggle:R,secretEditing:v,isEditingExisting:c})]})]})})}function Uee({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(lS,{variant:"list"}):!t||t.length===0?o.jsxs(Eo,{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(Eo,{children:[o.jsx(El,{connector:e}),o.jsxs(wl,{title:c,children:[t.map(d=>o.jsx(xO,{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(ps,{className:"h-3 w-3"})]})]}),selected:n===d.name},d.name)),o.jsx(nu,{label:"Missing some data?"})]})]})}var Ns=(e=>(e.ASC="asc",e.DESC="desc",e.ORIGINAL="original",e))(Ns||{});function FT({connector:e,connectorFields:t,selectedField:n,selectedFields:r,onFieldToggle:s}){const l=p.useRef(null),[c,d]=p.useState(""),[h,m]=p.useState(Ns.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,_)=>R.set(T.name,_)),R},[v]),w=p.useMemo(()=>{const R=v.filter(_=>_.name.toLowerCase().includes(c.toLowerCase().trim())),T=(_,O)=>{const D=x.includes(_.name),N=x.includes(O.name);if(D&&!N)return-1;if(!D&&N)return 1;if(h===Ns.ASC)return _.name.localeCompare(O.name);if(h===Ns.DESC)return O.name.localeCompare(_.name);const A=b.get(_.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(_=>_.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 N=v.map(U=>U.name),M=N.filter(U=>!r.includes(U)).length>0;N.forEach(U=>{s(U,M)})}};return window.addEventListener("keydown",R),()=>{window.removeEventListener("keydown",R)}},[v,r,s]),!n||!t?o.jsxs(Eo,{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(Eo,{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(Mr,{children:[o.jsx(kr,{asChild:!0,children:o.jsxs(Ce,{variant:"ghost",size:"icon","aria-label":"Sort fields",children:[h===Ns.ASC&&o.jsx(H2,{className:"text-muted-foreground h-4 w-4"}),h===Ns.DESC&&o.jsx(V2,{className:"text-muted-foreground h-4 w-4"}),h===Ns.ORIGINAL&&o.jsx($2,{className:"text-muted-foreground h-4 w-4"})]})}),o.jsxs(Ir,{align:"end",children:[o.jsxs(_t,{onSelect:()=>{m(Ns.ASC)},children:[o.jsx(H2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"A–Z"]}),o.jsxs(_t,{onSelect:()=>{m(Ns.DESC)},children:[o.jsx(V2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Z–A"]}),o.jsxs(_t,{onSelect:()=>{m(Ns.ORIGINAL)},children:[o.jsx($2,{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(xO,{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:_=>{s(R.name,_)},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(i0,{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(i0,{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(Eo,{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 SO=p.createContext(void 0),CO={triggers:[],selectedTrigger:null,isLoading:!1,error:null};function Fee(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 CO;default:return e}}class zee 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 zee;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 J0{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 vo.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 Vee{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 qx={getMapper(e){switch(e){case xn.REPORT_RUN:return new J0;case xn.CONNECTOR_RUN:return new Vee;default:throw new Error(`Unknown scheduled trigger type: ${String(e)}`)}}},Ld={mapFromDto(e){return qx.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 J0().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 J0,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 qx.getMapper(e.type).mapToCreateRequest(e)},mapToUpdateRequest(e){return qx.getMapper(e.type).mapToUpdateRequest(e)}};function Hee({children:e}){const[t,n]=p.useReducer(Fee,CO),{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 _={type:w,cronExpression:C,timeZone:E,isActive:R,triggerConfig:T},O=await Uc.createScheduledTrigger(b,_),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}),rn.success("Trigger created"),D}catch(_){const O=_ instanceof Error?_.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}),_}},[r]),m=p.useCallback(async(b,w,C,E,R)=>{n({type:"UPDATE_TRIGGER_START"});try{const T={cronExpression:C,timeZone:E,isActive:R},_=await Uc.updateScheduledTrigger(b,w,T),O=await Ld.mapFromDtoWithReportData(_,r);n({type:"UPDATE_TRIGGER_SUCCESS",payload:O}),Fe({event:"scheduled_trigger_updated",category:"ScheduledTrigger",action:"Update",label:O.type}),rn.success("Trigger updated")}catch(T){const _=T instanceof Error?T.message:"Failed to update scheduled trigger";throw n({type:"UPDATE_TRIGGER_ERROR",payload:_}),Fe({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"UpdateError",label:_}),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}),rn.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(SO.Provider,{value:{...t,getScheduledTriggers:l,getScheduledTriggersByType:c,getScheduledTrigger:d,createScheduledTrigger:h,updateScheduledTrigger:m,deleteScheduledTrigger:g,selectScheduledTrigger:v,reset:x},children:e})}function wO(){const e=p.useContext(SO);if(e===void 0)throw new Error("useScheduledTriggerContext must be used within a ScheduledTriggerProvider");return e}function $ee(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}=wO();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 Bee=an({type:Gs(Kc.SCHEDULED_REPORT_RUN),reportId:sn().min(1,"Report ID is required")}),Gee=uB(),qee=an({type:s1(xn),cronExpression:sn().min(1,"Cron expression is required"),timeZone:sn().min(1,"Time zone is required"),isActive:cB(),triggerConfig:fB([Bee,Gee])});function Zee({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 Kee({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===Ut.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 Pg="Switch",[Yee]=Dr(Pg),[Wee,Qee]=Yee(Pg),EO=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,_=>b(_)),C=p.useRef(!1),E=x?g||!!x.closest("form"):!0,[R,T]=zr({prop:s,defaultProp:l??!1,onChange:m,caller:Pg});return o.jsxs(Wee,{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,_=>{T(O=>!O),E&&(C.current=_.isPropagationStopped(),C.current||_.stopPropagation())})}),E&&o.jsx(_O,{control:x,bubbles:!C.current,name:r,value:h,checked:R,required:c,disabled:d,form:g,style:{transform:"translateX(-100%)"}})]})});EO.displayName=Pg;var RO="SwitchThumb",TO=p.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,s=Qee(RO,n);return o.jsx(Ke.span,{"data-state":jO(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:t})});TO.displayName=RO;var Xee="SwitchBubbleInput",_O=p.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...s},l)=>{const c=p.useRef(null),d=vt(c,l),h=F1(n),m=Pb(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}})});_O.displayName=Xee;function jO(e){return e?"checked":"unchecked"}var Jee=EO,ete=TO;function NO({className:e,...t}){return o.jsx(Jee,{"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(ete,{"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 tte(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 eb(e,t="UTC"){const n=tte(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 AO({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(_r,{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(_r,{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(_r,{variant:"outline",className:"h-5 text-xs",children:["+",v.length-1]})]})};return o.jsxs(G1,{open:c,onOpenChange:d,modal:!0,children:[o.jsx(q1,{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(bb,{className:"ml-2 h-3 w-3 shrink-0 opacity-50"})]})}),o.jsx(Z1,{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(ND,{placeholder:s,className:"h-8"}),o.jsxs(tJ,{className:"h-full max-h-[350px] overflow-y-auto",children:[o.jsx(AD,{children:"No items found."}),o.jsx(DD,{className:"h-full overflow-visible",children:e.map(v=>o.jsxs(OD,{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 DO=[{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 OO(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=DO.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 nte(e,t,n=!0){const r=eb(e,t);return OO(r,n)}const rte=Array.from({length:31},(e,t)=>({value:t+1,label:`${String(t+1)}${t===0?"st":t===1?"nd":t===2?"rd":"th"}`})),tb=[5,10,15,30],nb=[1,2,3,4,6,8,12],ate=({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"})]})]})]}),ste=({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})})]}),zT=({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(K1,{options:r,value:e,onValueChange:t,placeholder:"Select timezone",emptyMessage:"No timezones found",disabled:n,className:"w-full"})})]}),ote=({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(AO,{options:DO,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:3})})]}),ite=({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(AO,{options:rte,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:4})})]}),lte=({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"?tb:nb).map(l=>o.jsxs(qn,{value:l.toString(),children:[l," ",e==="minutes"?"min":"hr"]},l))})]})]})]}),cte=({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 ute({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(()=>IG.getTimezonesWithOffset().map(H=>({value:H.identifier,label:H.displayName,offset:H.offsetString,isDST:H.isDST})),[]),[w,C]=p.useState(()=>eb(e,m)),[E,R]=p.useState(""),[T,_]=p.useState("");p.useEffect(()=>{h(n)},[n]),p.useEffect(()=>{const H=t??Om();g(H)},[t]),p.useEffect(()=>{if(e){const H=eb(e,m);C(H)}},[e,m]);const O=H=>{const[B,I]=H.time.split(":").map(Number);switch(H.type){case"daily":return`${String(I)} ${String(B)} * * *`;case"weekly":return`${String(I)} ${String(B)} * * ${H.weekdays.join(",")}`;case"monthly":return`${String(I)} ${String(B)} ${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(B)} * * *`}},D=p.useCallback(H=>{C(B=>{if(B.intervalType===H)return console.log("Type unchanged, skipping update"),B;const K=(H==="minutes"?tb:nb)[0];return{...B,intervalType:H,intervalValue:K}})},[]),N=p.useCallback(H=>{C(B=>(B.intervalType==="minutes"?tb:nb).includes(H)?{...B,intervalValue:H}:B)},[]),A=p.useMemo(()=>H=>OO(H,d),[d]);p.useEffect(()=>{const H=O(w);R(H),_(A(w))},[w,d,m,A]);const M=p.useRef(""),U=p.useRef(""),Z=p.useRef(!1);p.useEffect(()=>{const H=O(w);r&&(M.current!==H||U.current!==m||Z.current!==d)&&(r({cron:H,timezone:m,enabled:d}),M.current=H,U.current=m,Z.current=d)},[w,m,d,r]);const $=H=>{h(H)},Q=H=>{g(H),C(B=>({...B,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(NO,{id:"schedule-enabled",checked:d,onCheckedChange:$})]})]})}),o.jsxs("div",{className:"space-y-4 pt-0",children:[o.jsxs("div",{className:`space-y-4 ${d?"":"opacity-50"}`,children:[o.jsx(ate,{value:w.type,onChange:H=>{C(B=>({...B,type:H}))},disabled:!d}),w.type!=="custom"&&w.type!=="interval"&&o.jsxs("div",{className:"flex gap-3",children:[o.jsx(ste,{value:w.time,onChange:H=>{C(B=>({...B,time:H}))},disabled:!d}),re&&o.jsx(zT,{value:m,onChange:Q,disabled:!d,timezones:b})]}),(w.type==="interval"||w.type==="custom")&&o.jsx(zT,{value:m,onChange:Q,disabled:!d,timezones:b}),w.type==="weekly"&&o.jsx(ote,{value:w.weekdays,onChange:H=>{C(B=>({...B,weekdays:H}))},disabled:!d}),w.type==="monthly"&&o.jsx(ite,{value:w.monthDays,onChange:H=>{C(B=>({...B,monthDays:H}))},disabled:!d}),w.type==="interval"&&o.jsx(lte,{intervalType:w.intervalType,intervalValue:w.intervalValue,onTypeChange:D,onValueChange:N,disabled:!d}),w.type==="custom"&&o.jsx(cte,{value:w.customCron,onChange:H=>{C(B=>({...B,customCron:H}))},disabled:!d})]}),l&&o.jsxs(o.Fragment,{children:[o.jsx(cj,{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(K_,{className:"h-4 w-4"}),o.jsx("span",{className:"text-sm font-medium",children:"Preview"})]}),v?o.jsx(Ps,{className:"text-muted-foreground h-4 w-4"}):o.jsx(Ra,{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(_r,{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(_r,{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(_r,{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(sS,{className:"border-amber-200 bg-amber-50",children:[o.jsx(Sf,{className:"h-4 w-4"}),o.jsx(lO,{children:"Time Zone"}),o.jsxs(oS,{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 dte(){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 fte(){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 hte(){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 mte(){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 pte({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}=Zee({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(fte,{}):o.jsx(dte,{})}),o.jsx(on,{})]})}),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(R4,{children:o.jsx(Kee,{value:E.value,onChange:E.onChange,disabled:!!t||!!e})})}),o.jsx(ar,{children:e!=null&&e.triggerConfig?o.jsx(hte,{}):o.jsx(mte,{})}),o.jsx(on,{})]})}),o.jsx(ute,{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 gte({cronExpression:e,timeZone:t,isEnabled:n=!0}){const r=p.useMemo(()=>nte(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 vte({table:e}){return o.jsx("div",{className:"text-right",children:o.jsxs(Mr,{children:[o.jsx(kr,{asChild:!0,children:o.jsx(Ce,{variant:"ghost",className:"dm-card-table-body-row-actionbtn","aria-label":"Toggle columns",children:o.jsx(Za,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsx(Ir,{align:"end",children:e.getAllColumns().filter(t=>t.getCanHide()&&t.id!=="actions").map(t=>o.jsx(_t,{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 yte({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(Mr,{open:r,onOpenChange:s,children:[o.jsx(kr,{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(Za,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsxs(Ir,{align:"end",children:[o.jsxs(_t,{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(_t,{onClick:()=>{c(!0)},children:[o.jsx(Mo,{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 xte(e,t){const n=t.find(r=>r.name===e.source.name);return(n==null?void 0:n.displayName)??e.source.name}function bte({connector:e}){const{connectors:t}=ql(),n=xte(e,t);return o.jsx(o.Fragment,{children:n})}function MO({connector:e}){return o.jsx(bte,{connector:e})}function Ste(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 Cte=e=>{const{connectors:t}=ql();return p.useMemo(()=>t.find(n=>n.name===e),[t,e])},wte=_e.memo(function({connector:t,children:n}){const r=Cte(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&&fq(s.storage,t.storage.fullyQualifiedName)},[s==null?void 0:s.storage,t.storage.fullyQualifiedName]),m=p.useMemo(()=>Ste(l),[l]),g=p.useMemo(()=>!m.lastRunDate||!m.lastRunStatus?null:{statusType:jZ(m.lastRunStatus),statusText:AZ(m.lastRunStatus),date:m.lastRunDate},[m]),v=p.useMemo(()=>(s==null?void 0:s.storage)&&hq(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(f1,{children:[o.jsx(h1,{asChild:!0,children:o.jsx("span",{children:n})}),o.jsxs(m1,{children:[o.jsxs(p1,{children:[o.jsx(g1,{children:d}),o.jsxs(v1,{children:[o.jsx(y1,{children:o.jsx(MO,{connector:t})}),o.jsx(x1,{children:x})]})]}),o.jsxs(b1,{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(S1,{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 Ete(e){const t=e.triggerConfig;return o.jsxs("div",{className:"inline gap-1",children:[t.report.title,o.jsx(TZ,{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 Rte(e){const t=e.triggerConfig,{connector:n}=t.connector;return o.jsxs("div",{className:"inline gap-1",children:[o.jsx(MO,{connector:n}),o.jsx(wte,{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 Tte({trigger:e}){switch(e.type){case xn.REPORT_RUN:return Ete(e);case xn.CONNECTOR_RUN:return Rte(e);default:return o.jsx("div",{className:"text-muted-foreground text-sm",children:"—"})}}function _te({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(_r,{variant:"outline",children:s})},meta:{title:"Trigger Type"}},{accessorKey:"triggerConfig",size:35,header:"Run Target",cell:({row:n})=>o.jsx(Tte,{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(gte,{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(vte,{table:n}),cell:({row:n})=>o.jsx(yte,{trigger:n.original,onEditTrigger:e,onDeleteTrigger:t}),meta:{title:"Actions"}}]}function jte({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 cS({isOpen:e,onClose:t,dataMartId:n,preSelectedReportId:r,preSelectedType:s}){const{createScheduledTrigger:l,updateScheduledTrigger:c,selectedTrigger:d}=wO(),[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()},_=p.useRef(!1);return p.useEffect(()=>{const O=E?"Edit":"Create",D=(d==null?void 0:d.type)??s;e&&!_.current?(Fe({event:"scheduled_trigger_config_open",category:"ScheduledTrigger",action:O,label:D}),_.current=!0):!e&&_.current&&(Fe({event:"scheduled_trigger_config_close",category:"ScheduledTrigger",action:O,label:D}),_.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(pte,{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 Nte({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(()=>_te({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:wg(),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(_u,{id:"scheduled-triggers-table",className:"dm-card-table",role:"table","aria-label":"Scheduled Triggers",children:[o.jsx(ju,{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((_,O)=>o.jsx(ya,{className:`whitespace-normal ${_.column.id==="actions"?"actions-cell":""}`,role:"cell","aria-colindex":O+1,style:_.column.id==="type"?{width:150,minWidth:150,maxWidth:150}:_.column.id==="actions"?{width:80,minWidth:80,maxWidth:80}:{width:`${String(_.column.getSize())}%`},children:typeof _.column.columnDef.cell=="function"?_.column.columnDef.cell(_.getContext()):_.column.columnDef.cell},_.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(jte,{table:b,onPreviousClick:w,onNextClick:C}),o.jsx(cS,{isOpen:s,onClose:c,dataMartId:t})]})}function Ate({dataMartId:e}){const{triggers:t,deleteScheduledTrigger:n,selectScheduledTrigger:r,selectedTrigger:s}=$ee(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(Nte,{triggers:t,dataMartId:e,onEditTrigger:d,onDeleteTrigger:g=>void m(g)}),o.jsx(cS,{isOpen:l,onClose:h,dataMartId:e})]})}function kO(){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(W_,{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 Dte({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=_=>_.trim()?/^[A-Za-z][A-Za-z0-9_]*$/.test(_)?null:"Use letters, numbers, and underscores; start with a letter":"This field is required",E=p.useCallback((_,O,D,N)=>{s({fullyQualifiedName:`${_}.${O}`,isValid:!!(_&&O&&D===null&&N===null)})},[s]);p.useEffect(()=>{let _="",O="";if(t!=null&&t.fullyQualifiedName){const U=t.fullyQualifiedName.split(".");_=U[0]??"",O=U[1]??""}else _=`${c}_owox`,O=l;const D=C(_),N=C(O);h(_),g(O),x(D),w(N);const A=`${_}.${O}`,M=!!(_&&O&&D===null&&N===null);((t==null?void 0:t.fullyQualifiedName)!==A||t.isValid!==M)&&E(_,O,D,N)},[t,l,c,E]);const R=_=>{h(_);const O=C(_);x(O),E(_,m,O,b)},T=_=>{g(_);const O=C(_);w(O),E(d,_,v,O)};return o.jsxs(Eo,{children:[e===Pe.GOOGLE_BIGQUERY&&o.jsxs(o.Fragment,{children:[o.jsx(Di,{icon:o.jsx(HA,{}),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(Co,{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:_=>{R(_.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(Co,{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:_=>{T(_.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($A,{}),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(Co,{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:_=>{R(_.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(Co,{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:_=>{T(_.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(kO,{})})]})}function Ote({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),[_,O]=p.useState(new Set),[D,N]=p.useState(new Set),{connectors:A,connectorSpecification:M,connectorFields:U,loading:Z,loadingSpecification:$,loadingFields:Q,error:re,fetchAvailableConnectors:H,fetchConnectorSpecification:B,fetchConnectorFields:I}=ql(),[K,q]=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=>{!_.has(Ie)&&!$&&(O(Ct=>new Set(Ct).add(Ie)),await B(Ie))},[_,$,B]),P=p.useCallback(async Ie=>{D.has(Ie)||(N(Ct=>new Set(Ct).add(Ie)),await I(Ie))},[D,I]);p.useEffect(()=>{if(!c||d||A.length===0)return;const Ie=A.find(Ct=>Ct.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&&!Z&&H(),r&&A.length>0&&!d){const{source:Ie,storage:Ct}=r;g(Ie.node),x(Ie.fields),E(Ie.configuration[0]||{}),q({fullyQualifiedName:Ct.fullyQualifiedName,isValid:!0});const jt=A.find(tn=>tn.name===Ie.name);jt&&(h(jt),L(jt.name),!n&&s!=="fields-only"&&P(jt.name),s==="fields-only"&&P(jt.name))}if(n&&A.length>0&&!d&&!r){const Ie=A[0];h(Ie),L(Ie.name)}},[s,r,A,n,Z,H,L,P,d]);const Y=Ie=>{h(Ie),E({}),T(!1),O(Ct=>{const jt=new Set(Ct);return jt.delete(Ie.name),jt}),L(Ie.name),P(Ie.name)},ae=Ie=>{g(Ie),x([])},fe=(Ie,Ct)=>{x(Ct?jt=>jt.includes(Ie)?jt:[...jt,Ie]:jt=>jt.filter(tn=>tn!==Ie))},ge=(Ie,Ct)=>{x(Ct?jt=>{const tn=Ie.filter(V=>!jt.includes(V));return[...jt,...tn]}:jt=>jt.filter(tn=>!Ie.includes(tn)))},ue=Ie=>{q(Ie)},Ne=p.useCallback(Ie=>{E(Ie)},[]),Re=p.useCallback(Ie=>{T(Ie)},[]);p.useEffect(()=>{M&&(M.some(Ct=>Ct.required&&Ct.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 K!==null&&K.fullyQualifiedName!==""&&K.isValid;default:return!1}},Bt=()=>b>1,ft=(Ie,Ct)=>{if(!Ie)return Ct;const jt=Ie.find(tn=>tn.name===Ct);return(jt==null?void 0:jt.destinationName)??Ct},gn=()=>{if(n&&b===1)return M&&d?o.jsx(UT,{connector:d,connectorSpecification:M,onConfigurationChange:Ne,onValidationChange:Re,initialConfiguration:C,loading:$,isEditingExisting:!!(r!=null&&r.source.configuration.length)}):null;if(s==="fields-only")switch(b){case 1:return d&&m&&U?o.jsx(FT,{connector:d,connectorFields:U,selectedField:m,selectedFields:v,onFieldToggle:fe,onSelectAllFields:ge}):null;default:return null}switch(b){case 1:return o.jsx(Tee,{connectors:A,selectedConnector:d,loading:Z,error:re,onConnectorSelect:Y,onConnectorDoubleClick:()=>{w(Ie=>Ie<be?Ie+1:Ie)}});case 2:return d&&M?o.jsx(UT,{connector:d,connectorSpecification:M,onConfigurationChange:Ne,onValidationChange:Re,initialConfiguration:C,loading:$,isEditingExisting:!1}):null;case 3:return d&&U?o.jsx(Uee,{connectorFields:U,connector:d,selectedField:m,connectorName:d.displayName,loading:Q,onFieldSelect:ae}):null;case 4:return d&&m&&U?o.jsx(FT,{connector:d,connectorFields:U,selectedField:m,selectedFields:v,onFieldToggle:fe,onSelectAllFields:ge}):null;case 5:return m&&U?o.jsx(Dte,{dataStorageType:t,destinationName:ft(U,m),connectorName:(d==null?void 0:d.displayName)??"",target:K,onTargetChange:ue}):null;default:return null}};return o.jsxs(xee,{children:[o.jsx(bee,{children:gn()}),o.jsx(See,{variant:"horizontal",children:o.jsx(_ee,{currentStep:b,totalSteps:be,canGoNext:Xe(),canGoBack:Bt(),isLoading:$||Q,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&&K&&e({source:{name:d.name,configuration:[C],node:m,fields:v},storage:{fullyQualifiedName:K.fullyQualifiedName}})}})})]})}const IO=20,LO=20;function PO({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 Mte(e=30,t=0){PO({vertical:LO+e,horizontal:IO+t})}function rb(){PO({vertical:LO,horizontal:IO})}function UO({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?Mte(55):rb(),()=>{rb()}),[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(Ote,{onSubmit:m=>{r(m),t()},dataStorageType:n,configurationOnly:s||c==="configuration-only",existingConnector:l,mode:c,initialStep:d,preselectedConnector:h})]})})}const uS=({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(UO,{isOpen:h,onClose:C,dataStorageType:e,onSubmit:t,configurationOnly:r,existingConnector:s,initialStep:g,preselectedConnector:x})})]})};function kte({storageType:e,onSetupConnector:t,preset:n,isOpen:r,onClose:s}){return o.jsx(uS,{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(wb,{className:"h-4 w-4",strokeWidth:2.25})}),o.jsx("span",{children:"Setup Connector"}),o.jsx(ps,{className:"h-6 w-6"})]})})}const Ite=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 Lte({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(At,{children:[o.jsx(Dt,{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(ps,{className:"h-3 w-3"})]})}),o.jsx(Ot,{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],_=`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,_),o.jsx("span",{className:"text-muted-foreground",children:"•"}),x("Table",T,O),o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(Fr,{className:"h-4 w-4"})}),o.jsx(Ot,{children:"The dataset and table are automatically created during the first run of the data mart, if they don't already exist"})]})]})}case Pe.AWS_ATHENA:{const C=c.config.region,E=t.connector.storage.fullyQualifiedName,[R,T]=E.split("."),_=`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,_),o.jsx("span",{className:"text-muted-foreground",children:"•"}),x("Table",T,_),o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(Fr,{className:"h-4 w-4"})}),o.jsx(Ot,{children:"The database and table are automatically created during the first run of the data mart, if they don't already exist"})]})]})}default:return"Unknown storage type configuration"}},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(uS,{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(Z0,{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(Z0,{title:Ite(c.type),icon:d.icon,subtitle:b(),className:"bg-background min-h-[80px] cursor-default border-0 hover:shadow-none dark:bg-white/2"})]})}),o.jsx("div",{className:"shrink-0 px-4",children:o.jsxs(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsx(Ce,{type:"button",variant:"ghost",onClick:()=>{w()&&n(e)},disabled:!w(),children:o.jsx(Mo,{className:"h-4 w-4"})})}),!w()&&o.jsx(Ot,{children:"Cannot remove the last configuration in published pipeline"})]})})]})}function Pte({storageType:e,onAddConfiguration:t,existingConnector:n}){return o.jsx("div",{children:o.jsx(uS,{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 Ute({control:e,storageType:t,preset:n,autoOpen:r=!1}){const{dataMart:s,runDataMart:l}=ms(),{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){Nt.error("Manual run is only available for published data marts");return}await l({id:s.id,payload:A})}},R=A=>M=>{const Z=d().definition;if(typeof Z=="object"&&qc(Z)){const $=[...Z.connector.source.configuration];$[A]=M.source.configuration[0]||{};const Q={connector:{...Z.connector,source:{...Z.connector.source,configuration:$}}};c("definition",Q,{shouldDirty:!0,shouldTouch:!0}),b()}},T=A=>{const U=d().definition;if(typeof U=="object"&&qc(U)){const Z={connector:{...U.connector,source:{...U.connector.source,fields:A.source.fields}}};c("definition",Z,{shouldDirty:!0,shouldTouch:!0}),b()}g(!1)},_=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(iL,{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 Z=Q0(qe.CONNECTOR);c("definition",Z,{shouldDirty:!0,shouldTouch:!0}),b()}if(typeof U=="object"&&qc(U)&&U.connector.source.configuration.length>1){const Z={...U.connector.source,configuration:U.connector.source.configuration.filter((Q,re)=>re!==A)},$={connector:{...U.connector,source:Z}};c("definition",$,{shouldDirty:!0,shouldTouch:!0}),b()}},N=A=>{const U=d().definition;if(qc(U)){const Z={...U.connector.source,configuration:[...U.connector.source.configuration,A]},$={connector:{...U.connector,source:Z}};c("definition",$,{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(kte,{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(Pte,{storageType:t,onAddConfiguration:N,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(dD,{configuration:s.definition,onManualRun:_,children:o.jsxs(Ce,{variant:"outline",children:[o.jsx(Cb,{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 Z=A.value;return o.jsx(hu,{children:o.jsx(Lte,{configIndex:U,connectorDef:Z,dataStorage:s.storage,onRemoveConfiguration:D,onUpdateConfiguration:R,dataMartStatus:typeof w=="object"?w.code:w,totalConfigurations:Z.connector.source.configuration.length},U)},U)}):null})]})})}),o.jsx(on,{})]})}),o.jsx(hu,{children:o.jsx(UO,{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 Fte({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(tee,{control:r}),e===qe.TABLE&&o.jsx(nee,{control:r,storageType:t}),e===qe.VIEW&&o.jsx(ree,{control:r,storageType:t}),e===qe.TABLE_PATTERN&&o.jsx(aee,{control:r,storageType:t}),e===qe.CONNECTOR&&o.jsx(Ute,{control:r,storageType:t,preset:n,autoOpen:s})]})}function FO(){const[e]=pI(),t=e.get("preset");return p.useMemo(()=>{if(!t)return;const n=t.toLowerCase();return nY(n)},[t])}function zte(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 Vte(e,t){const[n,r]=p.useState(e);return p.useEffect(()=>{const s=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(s)}},[e,t]),n}const Hte=1e3,$te=[Cl.SUCCESS,Cl.ERROR,Cl.CANCELLED];function Bte(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 cn.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 cn.getSqlDryRunTriggerStatus(e,v);if($te.includes(b)){const w=await cn.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,Hte))}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 cn.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&&cn.abortSqlDryRunTrigger(e,v).catch(()=>{})},[e]),{validateSql:g,isLoading:t,result:r,cancel:h}}const Gte=300;function qte({sql:e,dataMartId:t,debounceDelay:n=Gte,className:r="",onValidationStateChange:s}){const l=Vte(e.trim(),n),{validateSql:c,isLoading:d,result:h,cancel:m}=Bte(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($_,{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(At,{children:[o.jsx(Dt,{asChild:!0,children:o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx(Xm,{className:"h-3 w-3 text-gray-600"}),o.jsx("span",{className:"text-xs text-gray-600",children:zte(h.bytes)})]})}),o.jsx(Ot,{children:o.jsx("p",{className:"text-xs",children:"This is an estimated volume and may differ from the actual value"})})]})]})]}):o.jsxs("div",{className:"flex h-9 items-center gap-2",children:[o.jsx(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(Xm,{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 Zte(){const{dataMart:e,updateDataMartDefinition:t,getDataMart:n}=ms(),r=FO();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 B={definitionType:h,definition:Q0(h)};return l?{definitionType:h,definition:l}:B},[h,l]),x=p.useCallback(()=>{if(!h)return;const B=eee(h,d);return Wl(B)},[h,d]),b=$i({resolver:x(),defaultValues:v(),mode:"onChange"}),{handleSubmit:w,reset:C,watch:E,formState:{isDirty:R,isValid:T}}=b,_=(B,I)=>{if(B!==qe.SQL)return"";const K=I;return(K==null?void 0:K.sqlQuery)??""},O=E("definition"),D=_(h,O);p.useEffect(()=>{h&&C(v())},[h,C,v]);const N=B=>Q0(B);p.useEffect(()=>{if(!h&&!s&&(r!=null&&r.definitionType)){m(r.definitionType);const B={definitionType:r.definitionType,definition:N(r.definitionType)};C(B)}},[r,h,s,C]);const A=p.useCallback(B=>{g({isLoading:B.isLoading,isValid:B.isValid,error:B.error})},[]),M=B=>{m(B)},U=p.useCallback(()=>{c&&n(c)},[c,n]),{run:Z}=H1(c,U),$=async B=>{if(h&&c)try{await t(c,B.definitionType,B.definition),await Z(),C(B)}catch(I){console.error("Failed to update data mart definition:",I)}},Q=B=>{B.preventDefault(),w($)(B)},re=()=>{C(v())},H=()=>h?o.jsxs("form",{onSubmit:Q,className:"space-y-4",children:[o.jsx(Fte,{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(p3,{...b,children:o.jsxs("div",{className:"space-y-4",children:[!s&&o.jsx(KJ,{initialType:h,onTypeSelect:M}),H()]})})}function Kte(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 zO(e){return e.type==="bigquery-data-mart-schema"}function VO(e){return e.type==="athena-data-mart-schema"}function VT(e){return e!==null&&typeof e=="object"&&"mode"in e}function HT(e){return e!==null&&typeof e=="object"&&"isPrimaryKey"in e}function Yte(e){return e==null?"":typeof e=="string"||typeof e=="number"||typeof e=="boolean"?String(e):""}function Zx(e){return e==null?e:JSON.parse(JSON.stringify(e))}function Wte(e){const t=Zx(e),[n,r]=p.useState(t),[s,l]=p.useState(!1);p.useEffect(()=>{const h=Zx(e);r(h),l(!1)},[e]);const c=p.useCallback(h=>{n?zO(n)&&h.every(VT)?(r({...n,fields:h}),l(!0)):VO(n)&&h.every(HT)&&(r({...n,fields:h}),l(!0)):h.length>0&&(VT(h[0])?(r({type:"bigquery-data-mart-schema",fields:h}),l(!0)):HT(h[0])&&(r({type:"athena-data-mart-schema",fields:h}),l(!0)))},[n]),d=p.useCallback(()=>{const h=Zx(e);r(h),l(!1)},[e]);return{schema:n,isDirty:s,updateSchema:c,resetSchema:d,setIsDirty:l}}function Qte(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 Xte(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 HO(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=>HO(c,t)):!1}function $O(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=$O(s.fields,t,c);g.length>0&&(r.includes(c)||r.push(c),r.push(...g))}}),r}function Jte(e,t,n){const r=e.original;if(!n)return!0;const s=n.toLowerCase();return HO(r,s)}function ene(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 ls=(e=>(e.CONNECTED="CONNECTED",e.CONNECTED_WITH_DEFINITION_MISMATCH="CONNECTED_WITH_DEFINITION_MISMATCH",e.DISCONNECTED="DISCONNECTED",e))(ls||{}),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||{}),dS=(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))(dS||{});function tne(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,_)=>{const O=R?`${R}.${String(_)}`:String(_);(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((_,O)=>{const D=R?`${R}.${String(O)}`:String(O),N=_.type===Pn.RECORD||_.type===Pn.STRUCT;w.push({..._,path:D,level:T}),N&&_.fields&&t.has(D)&&C(_.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=$O(e,w).filter(R=>{const T=R.split(".").map(Number);let _=e,O;for(let D=0;D<T.length;D++){if(O=_[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&&(_=O.fields??[])}return!1});n(R=>{const T=new Set(R);return E.forEach(_=>{T.add(_)}),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,_)=>{const O=R?`${R}.${String(_)}`:String(_);(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 nne(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:ls.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:ls.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 BO(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 rne(){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 Ug=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 fS(e){return"nodeType"in e}function ta(e){var t,n;return e?ku(e)?e:fS(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function hS(e){const{Document:t}=ta(e);return e instanceof t}function Wf(e){return ku(e)?!1:e instanceof ta(e).HTMLElement}function GO(e){return e instanceof ta(e).SVGElement}function Iu(e){return e?ku(e)?e.document:fS(e)?hS(e)?e:Wf(e)||GO(e)?e.ownerDocument:document:document:document}const Vs=Ug?p.useLayoutEffect:p.useEffect;function mS(e){const t=p.useRef(e);return Vs(()=>{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 ane(){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 Vs(()=>{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 Op(e){const t=mS(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 ab(e){const t=p.useRef();return p.useEffect(()=>{t.current=e},[e]),t.current}let Kx={};function Xf(e,t){return p.useMemo(()=>{if(t)return t;const n=Kx[e]==null?0:Kx[e]+1;return Kx[e]=n,e+"-"+n},[e,t])}function qO(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=qO(1),Mp=qO(-1);function sne(e){return"clientX"in e&&"clientY"in e}function pS(e){if(!e)return!1;const{KeyboardEvent:t}=ta(e.target);return t&&e instanceof t}function one(e){if(!e)return!1;const{TouchEvent:t}=ta(e.target);return t&&e instanceof t}function sb(e){if(one(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 sne(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}}}),$T="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function ine(e){return e.matches($T)?e:e.querySelector($T)}const lne={display:"none"};function cne(e){let{id:t,value:n}=e;return _e.createElement("div",{id:t,style:lne},n)}function une(e){let{id:t,announcement:n,ariaLiveType:r="assertive"}=e;const s={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return _e.createElement("div",{id:t,style:s,role:"status","aria-live":r,"aria-atomic":!0},n)}function dne(){const[e,t]=p.useState("");return{announce:p.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const ZO=p.createContext(null);function fne(e){const t=p.useContext(ZO);p.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function hne(){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 mne={draggable:`
722
722
  To pick up a draggable item, press the space bar.
723
723
  While dragging, use the arrow keys to move the item.
724
724
  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-C-_xW__x.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-r3n7JZCs.js"></script>
10
10
  <link rel="stylesheet" crossorigin href="/assets/index-BX0gTxck.css">
11
11
  </head>
12
12
  <body translate="no" class="notranslate">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owox/web",
3
- "version": "0.11.0-next-20251024191328",
3
+ "version": "0.11.0-next-20251025220131",
4
4
  "description": "Web interface for OWOX Data Marts - an open-source solution for Data Analysts",
5
5
  "author": "OWOX",
6
6
  "license": "ELv2",