@owox/web 0.12.0-next-20251031104058 → 0.12.0-next-20251103153640

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.
@@ -723,7 +723,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
723
723
  `},HT=fX(gX)(yD),vX={config:mX},yX=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 xD(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],xD(e[n],t[n]))}),FT(FT({},e),t)}var xX={type:"cancelation",msg:"operation is manually canceled"};function $x(e){var t=!1,n=new Promise(function(r,s){e.then(function(l){return t?s(xX):r(l)}),e.catch(s)});return n.cancel=function(){return t=!0},n}var bX=["monaco"],SX=uX.create({config:dX,isInitialized:!1,resolve:null,reject:null,monaco:null}),bD=qQ(SX,2),Yf=bD[0],Mg=bD[1];function CX(e){var t=vX.config(e),n=t.monaco,r=BQ(t,bX);Mg(function(s){return{config:xD(s.config,r),monaco:n}})}function wX(){var e=Yf(function(t){var n=t.monaco,r=t.isInitialized,s=t.resolve;return{monaco:n,isInitialized:r,resolve:s}});if(!e.isInitialized){if(Mg({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),$x(Bx);if(window.monaco&&window.monaco.editor)return SD(window.monaco),e.resolve(window.monaco),$x(Bx);yX(EX,TX)(jX)}return $x(Bx)}function EX(e){return document.body.appendChild(e)}function RX(e){var t=document.createElement("script");return e&&(t.src=e),t}function TX(e){var t=Yf(function(r){var s=r.config,l=r.reject;return{config:s,reject:l}}),n=RX("".concat(t.config.paths.vs,"/loader.js"));return n.onload=function(){return e()},n.onerror=t.reject,n}function jX(){var e=Yf(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;SD(r),e.resolve(r)},function(n){e.reject(n)})}function SD(e){Yf().monaco||Mg({monaco:e})}function _X(){return Yf(function(e){var t=e.monaco;return t})}var Bx=new Promise(function(e,t){return Mg({resolve:e,reject:t})}),CD={config:CX,init:wX,__getMonacoInstance:_X},NX={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},Gx=NX,AX={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},DX=AX;function OX({children:e}){return _e.createElement("div",{style:DX.container},e)}var MX=OX,kX=MX;function IX({width:e,height:t,isEditorReady:n,loading:r,_ref:s,className:l,wrapperProps:c}){return _e.createElement("section",{style:{...Gx.wrapper,width:e,height:t},...c},!n&&_e.createElement(kX,null,r),_e.createElement("div",{ref:s,style:{...Gx.fullWidth,...!n&&Gx.hide},className:l}))}var LX=IX,wD=p.memo(LX);function PX(e){p.useEffect(e,[])}var ED=PX;function UX(e,t,n=!0){let r=p.useRef(!0);p.useEffect(r.current||!n?()=>{r.current=!1}:e,t)}var fa=UX;function Yd(){}function Yc(e,t,n,r){return FX(e,r)||zX(e,t,n,r)}function FX(e,t){return e.editor.getModel(RD(e,t))}function zX(e,t,n,r){return e.editor.createModel(t,n,r?RD(e,r):void 0)}function RD(e,t){return e.Uri.parse(t)}function VX({original:e,modified:t,language:n,originalLanguage:r,modifiedLanguage:s,originalModelPath:l,modifiedModelPath:c,keepCurrentOriginalModel:d=!1,keepCurrentModifiedModel:f=!1,theme:m="light",loading:g="Loading...",options:v={},height:x="100%",width:b="100%",className:w,wrapperProps:C={},beforeMount:E=Yd,onMount:R=Yd}){let[T,_]=p.useState(!1),[O,A]=p.useState(!0),D=p.useRef(null),j=p.useRef(null),M=p.useRef(null),U=p.useRef(R),H=p.useRef(E),q=p.useRef(!1);ED(()=>{let $=CD.init();return $.then(I=>(j.current=I)&&A(!1)).catch(I=>(I==null?void 0:I.type)!=="cancelation"&&console.error("Monaco initialization: error:",I)),()=>D.current?G():$.cancel()}),fa(()=>{if(D.current&&j.current){let $=D.current.getOriginalEditor(),I=Yc(j.current,e||"",r||n||"text",l||"");I!==$.getModel()&&$.setModel(I)}},[l],T),fa(()=>{if(D.current&&j.current){let $=D.current.getModifiedEditor(),I=Yc(j.current,t||"",s||n||"text",c||"");I!==$.getModel()&&$.setModel(I)}},[c],T),fa(()=>{let $=D.current.getModifiedEditor();$.getOption(j.current.editor.EditorOption.readOnly)?$.setValue(t||""):t!==$.getValue()&&($.executeEdits("",[{range:$.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),$.pushUndoStop())},[t],T),fa(()=>{var $,I;(I=($=D.current)==null?void 0:$.getModel())==null||I.original.setValue(e||"")},[e],T),fa(()=>{let{original:$,modified:I}=D.current.getModel();j.current.editor.setModelLanguage($,r||n||"text"),j.current.editor.setModelLanguage(I,s||n||"text")},[n,r,s],T),fa(()=>{var $;($=j.current)==null||$.editor.setTheme(m)},[m],T),fa(()=>{var $;($=D.current)==null||$.updateOptions(v)},[v],T);let Y=p.useCallback(()=>{var B;if(!j.current)return;H.current(j.current);let $=Yc(j.current,e||"",r||n||"text",l||""),I=Yc(j.current,t||"",s||n||"text",c||"");(B=D.current)==null||B.setModel({original:$,modified:I})},[n,t,s,e,r,l,c]),ae=p.useCallback(()=>{var $;!q.current&&M.current&&(D.current=j.current.editor.createDiffEditor(M.current,{automaticLayout:!0,...v}),Y(),($=j.current)==null||$.editor.setTheme(m),_(!0),q.current=!0)},[v,m,Y]);p.useEffect(()=>{T&&U.current(D.current,j.current)},[T]),p.useEffect(()=>{!O&&!T&&ae()},[O,T,ae]);function G(){var I,B,K,ce;let $=(I=D.current)==null?void 0:I.getModel();d||((B=$==null?void 0:$.original)==null||B.dispose()),f||((K=$==null?void 0:$.modified)==null||K.dispose()),(ce=D.current)==null||ce.dispose()}return _e.createElement(wD,{width:b,height:x,isEditorReady:T,loading:g,_ref:M,className:w,wrapperProps:C})}var HX=VX;p.memo(HX);function $X(e){let t=p.useRef();return p.useEffect(()=>{t.current=e},[e]),t.current}var BX=$X,Mm=new Map;function GX({defaultValue:e,defaultLanguage:t,defaultPath:n,value:r,language:s,path:l,theme:c="light",line:d,loading:f="Loading...",options:m={},overrideServices:g={},saveViewState:v=!0,keepCurrentModel:x=!1,width:b="100%",height:w="100%",className:C,wrapperProps:E={},beforeMount:R=Yd,onMount:T=Yd,onChange:_,onValidate:O=Yd}){let[A,D]=p.useState(!1),[j,M]=p.useState(!0),U=p.useRef(null),H=p.useRef(null),q=p.useRef(null),Y=p.useRef(T),ae=p.useRef(R),G=p.useRef(),$=p.useRef(r),I=BX(l),B=p.useRef(!1),K=p.useRef(!1);ED(()=>{let L=CD.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)),()=>H.current?xe():L.cancel()}),fa(()=>{var P,W,ee,de;let L=Yc(U.current,e||r||"",t||s||"",l||n||"");L!==((P=H.current)==null?void 0:P.getModel())&&(v&&Mm.set(I,(W=H.current)==null?void 0:W.saveViewState()),(ee=H.current)==null||ee.setModel(L),v&&((de=H.current)==null||de.restoreViewState(Mm.get(l))))},[l],A),fa(()=>{var L;(L=H.current)==null||L.updateOptions(m)},[m],A),fa(()=>{!H.current||r===void 0||(H.current.getOption(U.current.editor.EditorOption.readOnly)?H.current.setValue(r):r!==H.current.getValue()&&(K.current=!0,H.current.executeEdits("",[{range:H.current.getModel().getFullModelRange(),text:r,forceMoveMarkers:!0}]),H.current.pushUndoStop(),K.current=!1))},[r],A),fa(()=>{var P,W;let L=(P=H.current)==null?void 0:P.getModel();L&&s&&((W=U.current)==null||W.editor.setModelLanguage(L,s))},[s],A),fa(()=>{var L;d!==void 0&&((L=H.current)==null||L.revealLine(d))},[d],A),fa(()=>{var L;(L=U.current)==null||L.editor.setTheme(c)},[c],A);let ce=p.useCallback(()=>{var L;if(!(!q.current||!U.current)&&!B.current){ae.current(U.current);let P=l||n,W=Yc(U.current,r||e||"",t||s||"",P||"");H.current=(L=U.current)==null?void 0:L.editor.create(q.current,{model:W,automaticLayout:!0,...m},g),v&&H.current.restoreViewState(Mm.get(P)),U.current.editor.setTheme(c),d!==void 0&&H.current.revealLine(d),D(!0),B.current=!0}},[e,t,n,r,s,l,m,g,v,c,d]);p.useEffect(()=>{A&&Y.current(H.current,U.current)},[A]),p.useEffect(()=>{!j&&!A&&ce()},[j,A,ce]),$.current=r,p.useEffect(()=>{var L,P;A&&_&&((L=G.current)==null||L.dispose(),G.current=(P=H.current)==null?void 0:P.onDidChangeModelContent(W=>{K.current||_(H.current.getValue(),W)}))},[A,_]),p.useEffect(()=>{if(A){let L=U.current.editor.onDidChangeMarkers(P=>{var ee;let W=(ee=H.current.getModel())==null?void 0:ee.uri;if(W&&P.find(de=>de.path===W.path)){let de=U.current.editor.getModelMarkers({resource:W});O==null||O(de)}});return()=>{L==null||L.dispose()}}return()=>{}},[A,O]);function xe(){var L,P;(L=G.current)==null||L.dispose(),x?v&&Mm.set(l,H.current.saveViewState()):(P=H.current.getModel())==null||P.dispose(),H.current.dispose()}return _e.createElement(wD,{width:b,height:w,isEditorReady:A,loading:f,_ref:q,className:C,wrapperProps:E})}var qX=GX,ZX=p.memo(qX);function KX({initialValue:e,onChange:t}){const[n,r]=p.useState((e==null?void 0:e.sqlQuery)??""),{resolvedTheme:s}=f4();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(ZX,{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 Y0({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(Ta,{className:"text-muted-foreground/75 dark:text-muted-foreground/50 h-4 w-4"})})]})]})}var $T=1,YX=.9,WX=.8,QX=.17,qx=.1,Zx=.999,XX=.9999,JX=.99,eJ=/[\\\/_+.#"@\[\(\{&]/,tJ=/[\\\/_+.#"@\[\(\{&]/g,nJ=/[\s-]/,TD=/[\s-]/g;function W0(e,t,n,r,s,l,c){if(l===t.length)return s===e.length?$T:JX;var d=`${s},${l}`;if(c[d]!==void 0)return c[d];for(var f=r.charAt(l),m=n.indexOf(f,s),g=0,v,x,b,w;m>=0;)v=W0(e,t,n,r,m+1,l+1,c),v>g&&(m===s?v*=$T:eJ.test(e.charAt(m-1))?(v*=WX,b=e.slice(s,m-1).match(tJ),b&&s>0&&(v*=Math.pow(Zx,b.length))):nJ.test(e.charAt(m-1))?(v*=YX,w=e.slice(s,m-1).match(TD),w&&s>0&&(v*=Math.pow(Zx,w.length))):(v*=QX,s>0&&(v*=Math.pow(Zx,m-s))),e.charAt(m)!==t.charAt(l)&&(v*=XX)),(v<qx&&n.charAt(m-1)===r.charAt(l+1)||r.charAt(l+1)===r.charAt(l)&&n.charAt(m-1)!==r.charAt(l))&&(x=W0(e,t,n,r,m+1,l+2,c),x*qx>v&&(v=x*qx)),v>g&&(g=v),m=n.indexOf(f,m+1);return c[d]=g,g}function BT(e){return e.toLowerCase().replace(TD," ")}function rJ(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,W0(e,t,BT(e),BT(t),0,0,{})}var Pd='[cmdk-group=""]',Kx='[cmdk-group-items=""]',aJ='[cmdk-group-heading=""]',jD='[cmdk-item=""]',GT=`${jD}:not([aria-disabled="true"])`,Q0="cmdk-item-select",Gc="data-value",sJ=(e,t,n)=>rJ(e,t,n),_D=p.createContext(void 0),Wf=()=>p.useContext(_D),ND=p.createContext(void 0),W1=()=>p.useContext(ND),AD=p.createContext(void 0),DD=p.forwardRef((e,t)=>{let n=qc(()=>{var P,W;return{search:"",value:(W=(P=e.value)!=null?P:e.defaultValue)!=null?W:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=qc(()=>new Set),s=qc(()=>new Map),l=qc(()=>new Map),c=qc(()=>new Set),d=OD(e),{label:f,children:m,value:g,onValueChange:v,filter:x,shouldFilter:b,loop:w,disablePointerSelection:C=!1,vimBindings:E=!0,...R}=e,T=On(),_=On(),O=On(),A=p.useRef(null),D=gJ();Fl(()=>{if(g!==void 0){let P=g.trim();n.current.value=P,j.emit()}},[g]),Fl(()=>{D(6,ae)},[]);let j=p.useMemo(()=>({subscribe:P=>(c.current.add(P),()=>c.current.delete(P)),snapshot:()=>n.current,setState:(P,W,ee)=>{var de,ve,ie,Ne;if(!Object.is(n.current[P],W)){if(n.current[P]=W,P==="search")Y(),H(),D(1,q);else if(P==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let we=document.getElementById(O);we?we.focus():(de=document.getElementById(T))==null||de.focus()}if(D(7,()=>{var we;n.current.selectedItemId=(we=G())==null?void 0:we.id,j.emit()}),ee||D(5,ae),((ve=d.current)==null?void 0:ve.value)!==void 0){let we=W??"";(Ne=(ie=d.current).onValueChange)==null||Ne.call(ie,we);return}}j.emit()}},emit:()=>{c.current.forEach(P=>P())}}),[]),M=p.useMemo(()=>({value:(P,W,ee)=>{var de;W!==((de=l.current.get(P))==null?void 0:de.value)&&(l.current.set(P,{value:W,keywords:ee}),n.current.filtered.items.set(P,U(W,ee)),D(2,()=>{H(),j.emit()}))},item:(P,W)=>(r.current.add(P),W&&(s.current.has(W)?s.current.get(W).add(P):s.current.set(W,new Set([P]))),D(3,()=>{Y(),H(),n.current.value||q(),j.emit()}),()=>{l.current.delete(P),r.current.delete(P),n.current.filtered.items.delete(P);let ee=G();D(4,()=>{Y(),(ee==null?void 0:ee.getAttribute("id"))===P&&q(),j.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:f||e["aria-label"],getDisablePointerSelection:()=>d.current.disablePointerSelection,listId:T,inputId:O,labelId:_,listInnerRef:A}),[]);function U(P,W){var ee,de;let ve=(de=(ee=d.current)==null?void 0:ee.filter)!=null?de:sJ;return P?ve(P,n.current.search,W):0}function H(){if(!n.current.search||d.current.shouldFilter===!1)return;let P=n.current.filtered.items,W=[];n.current.filtered.groups.forEach(de=>{let ve=s.current.get(de),ie=0;ve.forEach(Ne=>{let we=P.get(Ne);ie=Math.max(we,ie)}),W.push([de,ie])});let ee=A.current;$().sort((de,ve)=>{var ie,Ne;let we=de.getAttribute("id"),Te=ve.getAttribute("id");return((ie=P.get(Te))!=null?ie:0)-((Ne=P.get(we))!=null?Ne:0)}).forEach(de=>{let ve=de.closest(Kx);ve?ve.appendChild(de.parentElement===ve?de:de.closest(`${Kx} > *`)):ee.appendChild(de.parentElement===ee?de:de.closest(`${Kx} > *`))}),W.sort((de,ve)=>ve[1]-de[1]).forEach(de=>{var ve;let ie=(ve=A.current)==null?void 0:ve.querySelector(`${Pd}[${Gc}="${encodeURIComponent(de[0])}"]`);ie==null||ie.parentElement.appendChild(ie)})}function q(){let P=$().find(ee=>ee.getAttribute("aria-disabled")!=="true"),W=P==null?void 0:P.getAttribute(Gc);j.setState("value",W||void 0)}function Y(){var P,W,ee,de;if(!n.current.search||d.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let ve=0;for(let ie of r.current){let Ne=(W=(P=l.current.get(ie))==null?void 0:P.value)!=null?W:"",we=(de=(ee=l.current.get(ie))==null?void 0:ee.keywords)!=null?de:[],Te=U(Ne,we);n.current.filtered.items.set(ie,Te),Te>0&&ve++}for(let[ie,Ne]of s.current)for(let we of Ne)if(n.current.filtered.items.get(we)>0){n.current.filtered.groups.add(ie);break}n.current.filtered.count=ve}function ae(){var P,W,ee;let de=G();de&&(((P=de.parentElement)==null?void 0:P.firstChild)===de&&((ee=(W=de.closest(Pd))==null?void 0:W.querySelector(aJ))==null||ee.scrollIntoView({block:"nearest"})),de.scrollIntoView({block:"nearest"}))}function G(){var P;return(P=A.current)==null?void 0:P.querySelector(`${jD}[aria-selected="true"]`)}function $(){var P;return Array.from(((P=A.current)==null?void 0:P.querySelectorAll(GT))||[])}function I(P){let W=$()[P];W&&j.setState("value",W.getAttribute(Gc))}function B(P){var W;let ee=G(),de=$(),ve=de.findIndex(Ne=>Ne===ee),ie=de[ve+P];(W=d.current)!=null&&W.loop&&(ie=ve+P<0?de[de.length-1]:ve+P===de.length?de[0]:de[ve+P]),ie&&j.setState("value",ie.getAttribute(Gc))}function K(P){let W=G(),ee=W==null?void 0:W.closest(Pd),de;for(;ee&&!de;)ee=P>0?mJ(ee,Pd):pJ(ee,Pd),de=ee==null?void 0:ee.querySelector(GT);de?j.setState("value",de.getAttribute(Gc)):B(P)}let ce=()=>I($().length-1),xe=P=>{P.preventDefault(),P.metaKey?ce():P.altKey?K(1):B(1)},L=P=>{P.preventDefault(),P.metaKey?I(0):P.altKey?K(-1):B(-1)};return p.createElement(We.div,{ref:t,tabIndex:-1,...R,"cmdk-root":"",onKeyDown:P=>{var W;(W=R.onKeyDown)==null||W.call(R,P);let ee=P.nativeEvent.isComposing||P.keyCode===229;if(!(P.defaultPrevented||ee))switch(P.key){case"n":case"j":{E&&P.ctrlKey&&xe(P);break}case"ArrowDown":{xe(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(),ce();break}case"Enter":{P.preventDefault();let de=G();if(de){let ve=new Event(Q0);de.dispatchEvent(ve)}}}}},p.createElement("label",{"cmdk-label":"",htmlFor:M.inputId,id:M.labelId,style:yJ},f),kg(e,P=>p.createElement(ND.Provider,{value:j},p.createElement(_D.Provider,{value:M},P))))}),oJ=p.forwardRef((e,t)=>{var n,r;let s=On(),l=p.useRef(null),c=p.useContext(AD),d=Wf(),f=OD(e),m=(r=(n=f.current)==null?void 0:n.forceMount)!=null?r:c==null?void 0:c.forceMount;Fl(()=>{if(!m)return d.item(s,c==null?void 0:c.id)},[m]);let g=MD(s,l,[e.value,e.children,l],e.keywords),v=W1(),x=Mi(D=>D.value&&D.value===g.current),b=Mi(D=>m||d.filter()===!1?!0:D.search?D.filtered.items.get(s)>0:!0);p.useEffect(()=>{let D=l.current;if(!(!D||e.disabled))return D.addEventListener(Q0,w),()=>D.removeEventListener(Q0,w)},[b,e.onSelect,e.disabled]);function w(){var D,j;C(),(j=(D=f.current).onSelect)==null||j.call(D,g.current)}function C(){v.setState("value",g.current,!0)}if(!b)return null;let{disabled:E,value:R,onSelect:T,forceMount:_,keywords:O,...A}=e;return p.createElement(We.div,{ref:Do(l,t),...A,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)}),iJ=p.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:s,...l}=e,c=On(),d=p.useRef(null),f=p.useRef(null),m=On(),g=Wf(),v=Mi(b=>s||g.filter()===!1?!0:b.search?b.filtered.groups.has(c):!0);Fl(()=>g.group(c),[]),MD(c,d,[e.value,e.heading,f]);let x=p.useMemo(()=>({id:c,forceMount:s}),[s]);return p.createElement(We.div,{ref:Do(d,t),...l,"cmdk-group":"",role:"presentation",hidden:v?void 0:!0},n&&p.createElement("div",{ref:f,"cmdk-group-heading":"","aria-hidden":!0,id:m},n),kg(e,b=>p.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?m:void 0},p.createElement(AD.Provider,{value:x},b))))}),lJ=p.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,s=p.useRef(null),l=Mi(c=>!c.search);return!n&&!l?null:p.createElement(We.div,{ref:Do(s,t),...r,"cmdk-separator":"",role:"separator"})}),cJ=p.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,s=e.value!=null,l=W1(),c=Mi(m=>m.search),d=Mi(m=>m.selectedItemId),f=Wf();return p.useEffect(()=>{e.value!=null&&l.setState("search",e.value)},[e.value]),p.createElement(We.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":f.listId,"aria-labelledby":f.labelId,"aria-activedescendant":d,id:f.inputId,type:"text",value:s?e.value:c,onChange:m=>{s||l.setState("search",m.target.value),n==null||n(m.target.value)}})}),uJ=p.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...s}=e,l=p.useRef(null),c=p.useRef(null),d=Mi(m=>m.selectedItemId),f=Wf();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(We.div,{ref:Do(l,t),...s,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":d,"aria-label":r,id:f.listId},kg(e,m=>p.createElement("div",{ref:Do(c,f.listInnerRef),"cmdk-list-sizer":""},m)))}),dJ=p.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:s,contentClassName:l,container:c,...d}=e;return p.createElement(Qp,{open:n,onOpenChange:r},p.createElement(Xp,{container:c},p.createElement(Jp,{"cmdk-overlay":"",className:s}),p.createElement(eg,{"aria-label":e.label,"cmdk-dialog":"",className:l},p.createElement(DD,{ref:t,...d}))))}),fJ=p.forwardRef((e,t)=>Mi(n=>n.filtered.count===0)?p.createElement(We.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),hJ=p.forwardRef((e,t)=>{let{progress:n,children:r,label:s="Loading...",...l}=e;return p.createElement(We.div,{ref:t,...l,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":s},kg(e,c=>p.createElement("div",{"aria-hidden":!0},c)))}),Iu=Object.assign(DD,{List:uJ,Item:oJ,Input:cJ,Group:iJ,Separator:lJ,Dialog:dJ,Empty:fJ,Loading:hJ});function mJ(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function pJ(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function OD(e){let t=p.useRef(e);return Fl(()=>{t.current=e}),t}var Fl=typeof window>"u"?p.useEffect:p.useLayoutEffect;function qc(e){let t=p.useRef();return t.current===void 0&&(t.current=e()),t}function Mi(e){let t=W1(),n=()=>e(t.snapshot());return p.useSyncExternalStore(t.subscribe,n,n)}function MD(e,t,n,r=[]){let s=p.useRef(),l=Wf();return Fl(()=>{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}})(),f=r.map(m=>m.trim());l.value(e,d,f),(c=t.current)==null||c.setAttribute(Gc,d),s.current=d}),s}var gJ=()=>{let[e,t]=p.useState(),n=qc(()=>new Map);return Fl(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,s)=>{n.current.set(r,s),t({})}};function vJ(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function kg({asChild:e,children:t},n){return e&&p.isValidElement(t)?p.cloneElement(vJ(t),{ref:t.ref},n(t.props.children)):n(t)}var yJ={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};function kD({className:e,...t}){return o.jsx(Iu,{"data-slot":"command",className:J("bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",e),...t})}function ID({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(Vl,{className:"size-4 shrink-0 opacity-50"}),o.jsx(Iu.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 xJ({className:e,...t}){return o.jsx(Iu.List,{"data-slot":"command-list",className:J("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",e),...t})}function LD({...e}){return o.jsx(Iu.Empty,{"data-slot":"command-empty",className:"py-6 text-center text-sm",...e})}function PD({className:e,...t}){return o.jsx(Iu.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 UD({className:e,...t}){return o.jsx(Iu.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 Ig="Popover",[FD]=kr(Ig,[Gs]),Qf=Gs(),[bJ,Wi]=FD(Ig),zD=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:s,onOpenChange:l,modal:c=!1}=e,d=Qf(t),f=p.useRef(null),[m,g]=p.useState(!1),[v,x]=zr({prop:r,defaultProp:s??!1,onChange:l,caller:Ig});return o.jsx(wu,{...d,children:o.jsx(bJ,{scope:t,contentId:On(),triggerRef:f,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})})};zD.displayName=Ig;var VD="PopoverAnchor",SJ=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Wi(VD,n),l=Qf(n),{onCustomAnchorAdd:c,onCustomAnchorRemove:d}=s;return p.useEffect(()=>(c(),()=>d()),[c,d]),o.jsx(Eu,{...l,...r,ref:t})});SJ.displayName=VD;var HD="PopoverTrigger",$D=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Wi(HD,n),l=Qf(n),c=pt(t,s.triggerRef),d=o.jsx(We.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":KD(s.open),...r,ref:c,onClick:Re(e.onClick,s.onOpenToggle)});return s.hasCustomAnchor?d:o.jsx(Eu,{asChild:!0,...l,children:d})});$D.displayName=HD;var Q1="PopoverPortal",[CJ,wJ]=FD(Q1,{forceMount:void 0}),BD=e=>{const{__scopePopover:t,forceMount:n,children:r,container:s}=e,l=Wi(Q1,t);return o.jsx(CJ,{scope:t,forceMount:n,children:o.jsx(wr,{present:n||l.open,children:o.jsx($l,{asChild:!0,container:s,children:r})})})};BD.displayName=Q1;var gu="PopoverContent",GD=p.forwardRef((e,t)=>{const n=wJ(gu,e.__scopePopover),{forceMount:r=n.forceMount,...s}=e,l=Wi(gu,e.__scopePopover);return o.jsx(wr,{present:r||l.open,children:l.modal?o.jsx(RJ,{...s,ref:t}):o.jsx(TJ,{...s,ref:t})})});GD.displayName=gu;var EJ=_i("PopoverContent.RemoveScroll"),RJ=p.forwardRef((e,t)=>{const n=Wi(gu,e.__scopePopover),r=p.useRef(null),s=pt(t,r),l=p.useRef(!1);return p.useEffect(()=>{const c=r.current;if(c)return Yp(c)},[]),o.jsx(Tf,{as:EJ,allowPinchZoom:!0,children:o.jsx(qD,{...e,ref:s,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Re(e.onCloseAutoFocus,c=>{var d;c.preventDefault(),l.current||(d=n.triggerRef.current)==null||d.focus()}),onPointerDownOutside:Re(e.onPointerDownOutside,c=>{const d=c.detail.originalEvent,f=d.button===0&&d.ctrlKey===!0,m=d.button===2||f;l.current=m},{checkForDefaultPrevented:!1}),onFocusOutside:Re(e.onFocusOutside,c=>c.preventDefault(),{checkForDefaultPrevented:!1})})})}),TJ=p.forwardRef((e,t)=>{const n=Wi(gu,e.__scopePopover),r=p.useRef(!1),s=p.useRef(!1);return o.jsx(qD,{...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 f,m;(f=e.onInteractOutside)==null||f.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()}})}),qD=p.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:l,disableOutsidePointerEvents:c,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:g,...v}=e,x=Wi(gu,n),b=Qf(n);return Zp(),o.jsx(Rf,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:l,children:o.jsx(Hl,{asChild:!0,disableOutsidePointerEvents:c,onInteractOutside:g,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:m,onDismiss:()=>x.onOpenChange(!1),children:o.jsx(_f,{"data-state":KD(x.open),role:"dialog",id:x.contentId,...b,...v,ref:t,style:{...v.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),ZD="PopoverClose",jJ=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Wi(ZD,n);return o.jsx(We.button,{type:"button",...r,ref:t,onClick:Re(e.onClick,()=>s.onOpenChange(!1))})});jJ.displayName=ZD;var _J="PopoverArrow",NJ=p.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=Qf(n);return o.jsx(Nf,{...s,...r,ref:t})});NJ.displayName=_J;function KD(e){return e?"open":"closed"}var AJ=zD,DJ=$D,OJ=BD,MJ=GD;function X1({...e}){return o.jsx(AJ,{"data-slot":"popover",...e})}function J1({...e}){return o.jsx(DJ,{"data-slot":"popover-trigger",...e})}function eS({className:e,align:t="center",sideOffset:n=4,...r}){return o.jsx(OJ,{children:o.jsx(MJ,{"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 tS({options:e,value:t,onValueChange:n,placeholder:r="Select an option",emptyMessage:s="No results found.",className:l,disabled:c=!1}){const[d,f]=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(""),f(!1)})},[n]);return o.jsxs(X1,{open:d,onOpenChange:f,modal:!0,children:[o.jsx(J1,{asChild:!0,children:o.jsxs(Se,{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(wb,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),o.jsx(eS,{className:"max-h-[300px] min-w-[300px] overflow-auto p-0",align:"start",sideOffset:5,children:o.jsxs(kD,{children:[o.jsx(ID,{placeholder:`Search ${r.toLowerCase()}...`,value:m,onValueChange:g}),o.jsx(LD,{children:s}),Object.entries(v).map(([w,C])=>o.jsx(PD,{heading:w,children:C.map(E=>o.jsxs(UD,{value:E.value,onSelect:()=>{b(E.value)},keywords:[E.label],children:[o.jsx(fr,{className:J("mr-2 h-4 w-4",t===E.value?"opacity-100":"opacity-0")}),E.label]},E.value))},w||"default"))]})})]})}var Lg="Collapsible",[kJ,YD]=kr(Lg),[IJ,nS]=kJ(Lg),WD=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:s,disabled:l,onOpenChange:c,...d}=e,[f,m]=zr({prop:r,defaultProp:s??!1,onChange:c,caller:Lg});return o.jsx(IJ,{scope:n,disabled:l,contentId:On(),open:f,onOpenToggle:p.useCallback(()=>m(g=>!g),[m]),children:o.jsx(We.div,{"data-state":oS(f),"data-disabled":l?"":void 0,...d,ref:t})})});WD.displayName=Lg;var QD="CollapsibleTrigger",rS=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,s=nS(QD,n);return o.jsx(We.button,{type:"button","aria-controls":s.contentId,"aria-expanded":s.open||!1,"data-state":oS(s.open),"data-disabled":s.disabled?"":void 0,disabled:s.disabled,...r,ref:t,onClick:Re(e.onClick,s.onOpenToggle)})});rS.displayName=QD;var aS="CollapsibleContent",sS=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,s=nS(aS,e.__scopeCollapsible);return o.jsx(wr,{present:n||s.open,children:({present:l})=>o.jsx(LJ,{...r,ref:t,present:l})})});sS.displayName=aS;var LJ=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:s,...l}=e,c=nS(aS,n),[d,f]=p.useState(r),m=p.useRef(null),g=pt(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)},[]),Cr(()=>{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),f(r)}},[c.open,r]),o.jsx(We.div,{"data-state":oS(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 oS(e){return e?"open":"closed"}var XD=WD,PJ=rS,UJ=sS,xs="Accordion",FJ=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[iS,zJ,VJ]=lg(xs),[Pg]=kr(xs,[VJ,YD]),lS=YD(),JD=_e.forwardRef((e,t)=>{const{type:n,...r}=e,s=r,l=r;return o.jsx(iS.Provider,{scope:e.__scopeAccordion,children:n==="multiple"?o.jsx(GJ,{...l,ref:t}):o.jsx(BJ,{...s,ref:t})})});JD.displayName=xs;var[eO,HJ]=Pg(xs),[tO,$J]=Pg(xs,{collapsible:!1}),BJ=_e.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},collapsible:l=!1,...c}=e,[d,f]=zr({prop:n,defaultProp:r??"",onChange:s,caller:xs});return o.jsx(eO,{scope:e.__scopeAccordion,value:_e.useMemo(()=>d?[d]:[],[d]),onItemOpen:f,onItemClose:_e.useCallback(()=>l&&f(""),[l,f]),children:o.jsx(tO,{scope:e.__scopeAccordion,collapsible:l,children:o.jsx(nO,{...c,ref:t})})})}),GJ=_e.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},...l}=e,[c,d]=zr({prop:n,defaultProp:r??[],onChange:s,caller:xs}),f=_e.useCallback(g=>d((v=[])=>[...v,g]),[d]),m=_e.useCallback(g=>d((v=[])=>v.filter(x=>x!==g)),[d]);return o.jsx(eO,{scope:e.__scopeAccordion,value:c,onItemOpen:f,onItemClose:m,children:o.jsx(tO,{scope:e.__scopeAccordion,collapsible:!0,children:o.jsx(nO,{...l,ref:t})})})}),[qJ,Ug]=Pg(xs),nO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,disabled:r,dir:s,orientation:l="vertical",...c}=e,d=_e.useRef(null),f=pt(d,t),m=zJ(n),v=Of(s)==="ltr",x=Re(e.onKeyDown,b=>{var M;if(!FJ.includes(b.key))return;const w=b.target,C=m().filter(U=>{var H;return!((H=U.ref.current)!=null&&H.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,A=()=>{T=E+1,T>O&&(T=_)},D=()=>{T=E-1,T<_&&(T=O)};switch(b.key){case"Home":T=_;break;case"End":T=O;break;case"ArrowRight":l==="horizontal"&&(v?A():D());break;case"ArrowDown":l==="vertical"&&A();break;case"ArrowLeft":l==="horizontal"&&(v?D():A());break;case"ArrowUp":l==="vertical"&&D();break}const j=T%R;(M=C[j].ref.current)==null||M.focus()});return o.jsx(qJ,{scope:n,disabled:r,direction:s,orientation:l,children:o.jsx(iS.Slot,{scope:n,children:o.jsx(We.div,{...c,"data-orientation":l,ref:f,onKeyDown:r?void 0:x})})})}),kp="AccordionItem",[ZJ,cS]=Pg(kp),rO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,value:r,...s}=e,l=Ug(kp,n),c=HJ(kp,n),d=lS(n),f=On(),m=r&&c.value.includes(r)||!1,g=l.disabled||e.disabled;return o.jsx(ZJ,{scope:n,open:m,disabled:g,triggerId:f,children:o.jsx(XD,{"data-orientation":l.orientation,"data-state":cO(m),...d,...s,ref:t,disabled:g,open:m,onOpenChange:v=>{v?c.onItemOpen(r):c.onItemClose(r)}})})});rO.displayName=kp;var aO="AccordionHeader",sO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Ug(xs,n),l=cS(aO,n);return o.jsx(We.h3,{"data-orientation":s.orientation,"data-state":cO(l.open),"data-disabled":l.disabled?"":void 0,...r,ref:t})});sO.displayName=aO;var X0="AccordionTrigger",oO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Ug(xs,n),l=cS(X0,n),c=$J(X0,n),d=lS(n);return o.jsx(iS.ItemSlot,{scope:n,children:o.jsx(PJ,{"aria-disabled":l.open&&!c.collapsible||void 0,"data-orientation":s.orientation,id:l.triggerId,...d,...r,ref:t})})});oO.displayName=X0;var iO="AccordionContent",lO=_e.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=Ug(xs,n),l=cS(iO,n),c=lS(n);return o.jsx(UJ,{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}})});lO.displayName=iO;function cO(e){return e?"open":"closed"}var KJ=JD,YJ=rO,WJ=sO,QJ=oO,XJ=lO;const uS={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(cL,{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}},uO=p.createContext("default");function mr({variant:e="default",...t}){return o.jsx(uO.Provider,{value:e,children:o.jsx(KJ,{"data-slot":"accordion",...t})})}function dS(e){const t=p.useContext(uO);return e??t??"default"}function Wn({className:e,variant:t,...n}){const r=dS(t),{itemClass:s}=uS[r];return o.jsx(YJ,{"data-slot":"accordion-item",className:J(s,e),...n})}function Qn({className:e,children:t,variant:n,...r}){const s=dS(n),{triggerClass:l,icon:c,chevronClass:d,headerClass:f}=uS[s];return o.jsx(WJ,{className:f,children:o.jsxs(QJ,{"data-slot":"accordion-trigger",className:J(l,e),...r,children:[c,t,o.jsx(Ka,{className:d,"aria-hidden":"true"})]})})}function Xn({className:e,children:t,variant:n,...r}){const s=dS(n),{contentClass:l,contentInnerClass:c}=uS[s];return o.jsx(XJ,{"data-slot":"accordion-content",className:J(l,e),...r,children:o.jsx("div",{className:c,children:t})})}function hr({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(_l,{className:"ml-1 inline h-3 w-3","aria-hidden":"true"})]})}function JJ(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"service-account-details",children:[o.jsx(Qn,{children:"How do I get a Service Account JSON key?"}),o.jsxs(Xn,{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(hr,{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 eee(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"project-id-details",children:[o.jsx(Qn,{children:"How do I find my Project ID?"}),o.jsxs(Xn,{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(hr,{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 tee(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"gbq-location-details",children:[o.jsx(Qn,{children:"How do I find my dataset location?"}),o.jsxs(Xn,{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(hr,{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 dO=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}},nee=({form:e})=>{const[t,n]=p.useState(!1);if(e.watch("type")!==Ie.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?dO(l):null;return o.jsxs(o.Fragment,{children:[o.jsxs(Vs,{title:"Connection Settings",children:[o.jsx(Jt,{control:e.control,name:"config.projectId",render:({field:d})=>o.jsxs(en,{children:[o.jsx(tn,{tooltip:"Enter the ID of your Google Cloud project where BigQuery usage will be billed",children:"Project ID"}),o.jsx(nn,{children:o.jsx(Ht,{...d,placeholder:"Enter a Project Id"})}),o.jsx(or,{children:o.jsx(eee,{})}),o.jsx(un,{})]})}),o.jsx(Jt,{control:e.control,name:"config.location",render:({field:d})=>o.jsxs(en,{children:[o.jsx(tn,{tooltip:"Choose the same region where your BigQuery data is stored to ensure queries work correctly",children:"Location"}),o.jsx(nn,{children:o.jsx(tS,{options:yq,value:d.value,onValueChange:d.onChange,placeholder:"Select a location",emptyMessage:"No locations found",className:"w-full"})}),o.jsx(or,{children:o.jsx(tee,{})}),o.jsx(un,{})]})})]}),o.jsx(Vs,{title:"Authentication",children:o.jsx(Jt,{control:e.control,name:"credentials.serviceAccount",render:({field:d})=>o.jsxs(en,{children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(tn,{tooltip:"Paste a JSON key from a service account that has access to the selected storage provider",children:"Service Account"}),!t&&l&&o.jsx(Se,{variant:"ghost",size:"sm",onClick:r,type:"button",children:"Edit"}),t&&o.jsx(Se,{variant:"ghost",size:"sm",onClick:s,type:"button",children:"Cancel"})]}),o.jsx(nn,{children:!t&&c?o.jsxs(wt,{children:[o.jsx(Et,{asChild:!0,children:o.jsx(hr,{href:c.url,children:c.email})}),o.jsx(Rt,{children:o.jsx("p",{children:"View in Google Cloud Console"})})]}):o.jsx(Hi,{...d,className:"min-h-[150px] font-mono",rows:8,placeholder:"Paste your service account JSON here"})}),o.jsx(or,{children:o.jsx(JJ,{})}),o.jsx(un,{})]})})})]})};function ree(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"athena-region-details",children:[o.jsx(Qn,{children:"How do I find my Athena region?"}),o.jsxs(Xn,{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(hr,{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 aee(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"athena-output-bucket-details",children:[o.jsx(Qn,{children:"How do I find a bucket?"}),o.jsxs(Xn,{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(hr,{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 see(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"athena-access-key-id-details",children:[o.jsx(Qn,{children:"How do I get my AWS Access Key ID?"}),o.jsxs(Xn,{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(hr,{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(y_,{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(hr,{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 oee(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"athena-secret-access-key-details",children:[o.jsx(Qn,{children:"How do I get my AWS Secret Access Key?"}),o.jsxs(Xn,{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(hr,{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 iee=({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")!==Ie.AWS_ATHENA?null:o.jsxs(o.Fragment,{children:[o.jsxs(Vs,{title:"Connection Settings",children:[o.jsx(Jt,{control:e.control,name:"config.region",render:({field:r})=>o.jsxs(en,{children:[o.jsx(tn,{tooltip:"Enter the AWS region where your Athena service is active",children:"Region"}),o.jsx(nn,{children:o.jsx(Ht,{...r,placeholder:"Enter a region"})}),o.jsx(or,{children:o.jsx(ree,{})}),o.jsx(un,{})]})}),o.jsx(Jt,{control:e.control,name:"config.outputBucket",render:({field:r})=>o.jsxs(en,{children:[o.jsx(tn,{tooltip:"Specify the S3 bucket where Athena query results will be stored",children:"Output Bucket"}),o.jsx(nn,{children:o.jsx(Ht,{...r,placeholder:"Enter an output bucket"})}),o.jsx(or,{children:o.jsx(aee,{})}),o.jsx(un,{})]})})]}),o.jsxs(Vs,{title:"Authentication",children:[o.jsx(Jt,{control:e.control,name:"credentials.accessKeyId",render:({field:r})=>o.jsxs(en,{children:[o.jsx(tn,{tooltip:"Your AWS Access Key ID used for authentication",children:"Access Key ID"}),o.jsx(nn,{children:o.jsx(Ht,{...r,placeholder:"Enter an access key id"})}),o.jsx(or,{children:o.jsx(see,{})}),o.jsx(un,{})]})}),o.jsx(Jt,{control:e.control,name:"credentials.secretAccessKey",render:({field:r})=>o.jsxs(en,{children:[o.jsx(tn,{tooltip:"Your AWS Secret Access Key used for authentication",children:"Secret Access Key"}),o.jsx(nn,{children:o.jsx(Ht,{...r,type:"password",placeholder:t||"Enter a secret access key"})}),o.jsx(or,{children:o.jsx(oee,{})}),o.jsx(un,{})]})})]})]})};function lee(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"bigquery-api-details",children:[o.jsx(Qn,{children:"How do I enable the BigQuery API?"}),o.jsxs(Xn,{children:[o.jsxs("p",{className:"mb-2",children:["To run queries and process data in Google BigQuery, you need to enable the"," ",o.jsx(hr,{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 cee(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"athena-api-details",children:[o.jsx(Qn,{children:"How do I activate Athena API?"}),o.jsxs(Xn,{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(hr,{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 fO(e){return JSON.parse(JSON.stringify(e))}function uee({initialData:e,onSubmit:t,onCancel:n,onDirtyChange:r}){const s=qi({resolver:Xl(Pq),defaultValues:e}),{watch:l,control:c,formState:{isDirty:d,isSubmitting:f}}=s,m=l("type");_e.useEffect(()=>{r==null||r(d)},[d,r]);const g=async v=>{const{dirtyFields:x}=s.formState,b=fO(v);return x.credentials||delete b.credentials,t(b)};return o.jsx(Yl,{...s,children:o.jsxs(Zi,{onSubmit:v=>{s.handleSubmit(g)(v)},noValidate:!0,children:[o.jsxs(Wl,{children:[o.jsxs(Vs,{title:"General",children:[o.jsx(Jt,{control:c,name:"title",render:({field:v})=>o.jsxs(en,{children:[o.jsx(tn,{tooltip:"Name the storage to clarify its purpose",children:"Title"}),o.jsx(nn,{children:o.jsx(Ht,{...v,placeholder:"Storage title"})}),o.jsx(un,{})]})}),o.jsx(Jt,{control:c,name:"type",render:({field:v})=>o.jsxs(en,{children:[o.jsx(tn,{tooltip:"The selected source will be used to process data in your Data Marts",children:"Storage Type"}),o.jsx(nn,{children:o.jsxs(Ca,{value:v.value,onValueChange:v.onChange,disabled:!!e,children:[o.jsx(Ea,{className:"w-full",children:o.jsx(wa,{placeholder:"Select a storage type"})}),o.jsx(Ra,{children:o.jsx(Dg,{children:Bi.getAllTypes().map(({type:x,displayName:b,icon:w,status:C})=>o.jsx(Kn,{value:x,disabled:C===Co.COMING_SOON,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(w,{size:20}),b]})},x))})})]})}),o.jsxs(or,{children:[m===Ie.GOOGLE_BIGQUERY&&o.jsx(lee,{}),m===Ie.AWS_ATHENA&&o.jsx(cee,{})]}),o.jsx(un,{})]})})]}),m===Ie.GOOGLE_BIGQUERY&&o.jsx(nee,{form:s}),m===Ie.AWS_ATHENA&&o.jsx(iee,{form:s})]}),o.jsxs(Ql,{children:[o.jsx(Se,{variant:"default",type:"submit",className:"w-full","aria-label":"Save",disabled:!d||f,children:"Save"}),o.jsx(Se,{variant:"outline",type:"button",onClick:n,className:"w-full","aria-label":"Cancel",children:"Cancel"})]})]})})}function hO({isOpen:e,onClose:t,dataStorage:n,onSaveSuccess:r}){const{updateDataStorage:s}=Og(),[l,c]=p.useState(!1),[d,f]=p.useState(!1),m=p.useCallback(()=>{d?c(!0):t()},[d,t]),g=p.useCallback(()=>{c(!1),f(!1),t()},[t]),v=p.useCallback(w=>{f(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?(Ue({event:"data_storage_config_open",category:"DataStorage",action:w,label:n==null?void 0:n.type}),b.current=!0):!e&&b.current&&(Ue({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(Li,{open:e,onOpenChange:w=>{w||m()},children:o.jsxs(Pi,{children:[o.jsxs(Ui,{children:[o.jsx(Fi,{children:"Configure Storage Provider"}),o.jsx(Bl,{children:"Customize settings for your storage provider"})]}),o.jsx(uee,{initialData:n??void 0,onSubmit:x,onCancel:m,onDirtyChange:v})]})}),o.jsx(ba,{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 dee=({dataStorage:e,onDataStorageChange:t})=>{const[n,r]=p.useState(!1),s=Bi.getInfo(e.type),l=()=>{r(!0)},c=()=>{r(!1)},d=()=>{if(!C4(e))return o.jsxs("div",{className:"flex items-center space-x-2 text-sm",children:[o.jsx(qp,{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(hr,{href:b,onClick:w=>{w.stopPropagation()},children:x})]});switch(e.type){case Ie.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 Ie.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(Y0,{title:e.title,icon:s.icon,subtitle:d(),onClick:l}),o.jsx(K1,{children:o.jsx(hO,{isOpen:n,onClose:c,dataStorage:e,onSaveSuccess:f=>{t&&t(f)}})})]})};function fee({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:Ke.SQL,label:"SQL",description:"SQL query"},{type:Ke.TABLE,label:"Table",description:"Existing table"},{type:Ke.VIEW,label:"View",description:"Existing view"},{type:Ke.TABLE_PATTERN,label:"Pattern",description:"Table pattern"},{type:Ke.CONNECTOR,label:"Connector",description:"Data import from Source to Storage"}];return o.jsxs("div",{className:"dm-card-block",children:[o.jsx(Sa,{className:"text-foreground",children:"Definition Type"}),o.jsxs(Ca,{value:n??"",onValueChange:d=>{s(d)},children:[o.jsx(Ea,{className:"dm-card-formcontrol w-full","aria-label":"Definition Type",children:o.jsx(wa,{placeholder:"Select definition type",children:n&&((c=l.find(d=>d.type===n))==null?void 0:c.label)})}),o.jsx(Ra,{children:o.jsx(Dg,{children:l.map(d=>o.jsxs(Kn,{value:d.type,children:[d.label,o.jsx("span",{className:"text-muted-foreground/80 ml-2",children:d.description})]},d.type))})})]})]})}const hee=ln({definitionType:qs(Ke.SQL),definition:ln({sqlQuery:cn().min(1,"SQL query is required")})}),mee=e=>{const t=H4(e);return ln({definitionType:qs(Ke.TABLE),definition:t})},pee=e=>{const t=H4(e);return ln({definitionType:qs(Ke.VIEW),definition:t})},gee=e=>{const t=WZ(e);return ln({definitionType:qs(Ke.TABLE_PATTERN),definition:t})},vee=ln({definitionType:qs(Ke.CONNECTOR),definition:ln({connector:ln({source:ln({name:cn().min(1,"Connector name is required"),configuration:iT(DB(NB())).min(1,"At least one configuration is required"),node:cn().min(1,"Node is required"),fields:iT(cn()).min(1,"At least one field is required")}),storage:ln({fullyQualifiedName:cn().min(1,"fully qualified name is required")})})})}),yee=(e,t)=>{if(!e)return ln({definitionType:OB(f1(Ke)),definition:ln({}).optional()});switch(e){case Ke.SQL:return hee;case Ke.TABLE:return mee(t);case Ke.VIEW:return pee(t);case Ke.TABLE_PATTERN:return gee(t);case Ke.CONNECTOR:return vee;default:return ln({})}};function xee({control:e}){return o.jsx(Jt,{control:e,name:"definition.sqlQuery",render:({field:t})=>o.jsxs(en,{className:"dm-card-block",children:[o.jsx(tn,{className:"text-foreground",children:"SQL Query"}),o.jsx(nn,{children:o.jsx(KX,{initialValue:{sqlQuery:t.value},onChange:n=>{t.onChange(n.sqlQuery)}})}),o.jsx(un,{})]})})}function bee({control:e,storageType:t}){const n=E4(t),r=R4(t);return o.jsx(Jt,{control:e,name:"definition.fullyQualifiedName",render:({field:s})=>o.jsxs(en,{className:"dm-card-block",children:[o.jsx(tn,{children:"Fully Qualified Table Name"}),o.jsx(nn,{children:o.jsx(Ht,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(or,{className:"text-muted-foreground/75",children:r}),o.jsx(un,{})]})})}function See({control:e,storageType:t}){const n=E4(t),r=R4(t);return o.jsx(Jt,{control:e,name:"definition.fullyQualifiedName",render:({field:s})=>o.jsxs(en,{className:"dm-card-block",children:[o.jsx(tn,{children:"Fully Qualified View Name"}),o.jsx(nn,{children:o.jsx(Ht,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(or,{className:"text-muted-foreground/75",children:r}),o.jsx(un,{})]})})}function Cee({control:e,storageType:t}){const n=Hq(t),r=$q(t);return o.jsx(Jt,{control:e,name:"definition.pattern",render:({field:s})=>o.jsxs(en,{className:"dm-card-block",children:[o.jsx(tn,{children:"Table Pattern"}),o.jsx(nn,{children:o.jsx(Ht,{placeholder:n,value:s.value||"",onChange:s.onChange,className:"dm-card-formcontrol"})}),o.jsx(or,{className:"text-muted-foreground/75",children:r}),o.jsx(un,{})]})})}const J0=e=>{switch(e){case Ke.SQL:return{sqlQuery:""};case Ke.TABLE:return{fullyQualifiedName:""};case Ke.VIEW:return{fullyQualifiedName:""};case Ke.TABLE_PATTERN:return{pattern:""};case Ke.CONNECTOR:return{connector:{source:{name:"",configuration:[],node:"",fields:[]},storage:{fullyQualifiedName:""}}};default:return{}}},wee=Cf("relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",{variants:{variant:{default:"bg-card text-card-foreground",destructive:"text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90"}},defaultVariants:{variant:"default"}});function fS({className:e,variant:t,...n}){return o.jsx("div",{"data-slot":"alert",role:"alert",className:J(wee({variant:t}),e),...n})}function mO({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 hS({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 Fg="Tabs",[Eee]=kr(Fg,[cg]),pO=cg(),[Ree,mS]=Eee(Fg),gO=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,onValueChange:s,defaultValue:l,orientation:c="horizontal",dir:d,activationMode:f="automatic",...m}=e,g=Of(d),[v,x]=zr({prop:r,onChange:s,defaultProp:l??"",caller:Fg});return o.jsx(Ree,{scope:n,baseId:On(),value:v,onValueChange:x,orientation:c,dir:g,activationMode:f,children:o.jsx(We.div,{dir:g,"data-orientation":c,...m,ref:t})})});gO.displayName=Fg;var vO="TabsList",yO=p.forwardRef((e,t)=>{const{__scopeTabs:n,loop:r=!0,...s}=e,l=mS(vO,n),c=pO(n);return o.jsx(DN,{asChild:!0,...c,orientation:l.orientation,dir:l.dir,loop:r,children:o.jsx(We.div,{role:"tablist","aria-orientation":l.orientation,...s,ref:t})})});yO.displayName=vO;var xO="TabsTrigger",bO=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,disabled:s=!1,...l}=e,c=mS(xO,n),d=pO(n),f=wO(c.baseId,r),m=EO(c.baseId,r),g=r===c.value;return o.jsx(ON,{asChild:!0,...d,focusable:!s,active:g,children:o.jsx(We.button,{type:"button",role:"tab","aria-selected":g,"aria-controls":m,"data-state":g?"active":"inactive","data-disabled":s?"":void 0,disabled:s,id:f,...l,ref:t,onMouseDown:Re(e.onMouseDown,v=>{!s&&v.button===0&&v.ctrlKey===!1?c.onValueChange(r):v.preventDefault()}),onKeyDown:Re(e.onKeyDown,v=>{[" ","Enter"].includes(v.key)&&c.onValueChange(r)}),onFocus:Re(e.onFocus,()=>{const v=c.activationMode!=="manual";!g&&!s&&v&&c.onValueChange(r)})})})});bO.displayName=xO;var SO="TabsContent",CO=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,forceMount:s,children:l,...c}=e,d=mS(SO,n),f=wO(d.baseId,r),m=EO(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(wr,{present:s||g,children:({present:x})=>o.jsx(We.div,{"data-state":g?"active":"inactive","data-orientation":d.orientation,role:"tabpanel","aria-labelledby":f,hidden:!x,id:m,tabIndex:0,...c,ref:t,style:{...e.style,animationDuration:v.current?"0s":void 0},children:x&&l})})});CO.displayName=SO;function wO(e,t){return`${e}-trigger-${t}`}function EO(e,t){return`${e}-content-${t}`}var Tee=gO,jee=yO,_ee=bO,Nee=CO;function Aee({className:e,...t}){return o.jsx(Tee,{"data-slot":"tabs",className:J("flex flex-col gap-2",e),...t})}function Dee({className:e,...t}){return o.jsx(jee,{"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 Oee({className:e,...t}){return o.jsx(_ee,{"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 Mee({className:e,...t}){return o.jsx(Nee,{"data-slot":"tabs-content",className:J("flex-1 outline-none",e),...t})}const kee=XD,Iee=rS,Lee=sS;function Pee({children:e,className:t="",...n}){return o.jsx("div",{className:J("flex flex-1 flex-col overflow-hidden",t),...n,children:e})}function Uee({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 Fee({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 Gd({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 zee({label:e,children:t,className:n="",options:r,value:s,onValueChange:l,required:c=!1,tooltip:d,...f}){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),...f,children:o.jsxs(Aee,{value:s,onValueChange:l,children:[o.jsxs("div",{className:"flex items-center",children:[o.jsx(Ro,{required:c,tooltip:d,className:"w-full",children:e}),o.jsx(Dee,{children:r.map(m=>o.jsx(Oee,{value:m.value,children:m.label},m.value))})]}),t]})})}function Vee({title:e,children:t,defaultOpen:n=!1,className:r=""}){const[s,l]=p.useState(n);return o.jsxs(kee,{open:s,onOpenChange:l,"data-slot":"wizard-collapsible",className:J("group flex flex-col gap-2 py-3",r),children:[o.jsx(Iee,{asChild:!0,children:o.jsxs("button",{type:"button",className:J("flex cursor-pointer items-center gap-1"),children:[o.jsx("span",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:e}),o.jsx(Ta,{className:J("text-foreground/75 h-3.5 w-3.5 transition-transform duration-200",s&&"rotate-90")})]})}),o.jsx(Lee,{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 Ro({children:e,required:t=!1,tooltip:n,tooltipProps:r,className:s="",...l}){return o.jsxs(Sa,{"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(wt,{...r,children:[o.jsx(Et,{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(Rt,{side:"top",align:"center",role:"tooltip",children:"Required"})]}):o.jsx("span",{children:e}),n&&o.jsxs(wt,{...r,children:[o.jsx(Et,{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(Rt,{side:"top",align:"center",role:"tooltip",children:n})]})]})}function Rl({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 ki({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(Se,{variant:"outline",asChild:!0,children:o.jsxs(Ga,{to:r,target:"_blank",rel:"noopener noreferrer",children:["Documentation",o.jsx(_l,{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(Se,{variant:"outline",className:"mt-3 mb-6",asChild:!0,children:o.jsxs(Ga,{to:r,target:"_blank",rel:"noopener noreferrer",children:["Documentation",o.jsx(_l,{className:"h-4 w-4"})]})})]})}function jo({children:e,className:t="",...n}){return o.jsx("div",{"data-slot":"wizard-step",className:J("space-y-4",t),...n,children:e})}function Hee({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 $ee({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(wt,{children:[o.jsx(Et,{asChild:!0,children:o.jsx("span",{className:"cursor-not-allowed text-sm font-medium opacity-70",children:t})}),o.jsx(Rt,{side:"top",align:"center",children:"Coming soon"})]}):o.jsx("span",{className:"text-sm font-medium",children:t})]})}function RO({type:e,id:t,name:n,value:r,label:s,checked:l,selected:c=!1,disabled:d=!1,tooltip:f,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(Ro,{htmlFor:t,className:J("cursor-pointer",d&&"cursor-not-allowed"),children:s}),(f||m)&&o.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[f&&o.jsxs(wt,{children:[o.jsx(Et,{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(Rt,{side:"top",align:"center",children:f})]}),m&&o.jsx("div",{className:"flex items-center",children:m})]})]})}function pS({variant:e="grid",items:t,className:n=""}){const r=t??(e==="grid"?12:6),s=e==="grid"?"grid grid-cols-1 gap-4 md:grid-cols-2":"flex flex-col gap-4";return o.jsx("div",{"data-slot":"wizard-step-loading",className:J(s,n),children:Array.from({length:r}).map((l,c)=>o.jsx(as,{className:"border-border h-12 rounded-md border-b bg-white dark:bg-white/4"},c))})}function Bee({connectors:e,selectedConnector:t,loading:n,error:r,onConnectorSelect:s,onConnectorDoubleClick:l}){return n?o.jsx(pS,{variant:"grid"}):r?o.jsxs(fS,{variant:"destructive",children:[o.jsx(wf,{className:"h-4 w-4"}),o.jsx(hS,{children:"Failed to load available connectors. Please try again."})]}):o.jsxs(jo,{children:[o.jsx(Rl,{title:"Choose Connector",children:o.jsx(Hee,{children:e.map(c=>o.jsx($ee,{icon:c.logoBase64?o.jsx(Vf,{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(ki,{icon:o.jsx(af,{size:56,strokeWidth:1}),title:"No connectors available",subtitle:"Ask your administrator to configure connectors."})]})}function Gee({currentStep:e,totalSteps:t,canGoNext:n,canGoBack:r,isLoading:s=!1,onNext:l,onBack:c,onFinish:d,nextLabel:f="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(Se,{variant:"outline",onClick:c,disabled:s,children:[o.jsx(f9,{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(Se,{variant:"default",onClick:d,disabled:!n||s,children:g}):o.jsxs(Se,{variant:"default",onClick:l,disabled:!n||s,children:[f,o.jsx(Ta,{className:"h-4 w-4"})]})})]})}function Tl({connector:e,size:t=24,variant:n="compact"}){return o.jsx(ki,{icon:o.jsx(Vf,{base64:e.logoBase64,size:t}),title:e.displayName,docUrl:e.docUrl,variant:n})}function au({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(Se,{variant:"outline",asChild:!0,children:o.jsxs(Ga,{to:"https://github.com/OWOX/owox-data-marts/issues",target:"_blank",rel:"noopener noreferrer",children:[e," Open issue here",o.jsx(_l,{className:"h-4 w-4"})]})})})}const eb="**********";function qee({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(Ht,{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(Sa,{htmlFor:c,className:"cursor-pointer text-sm",children:o.jsx(Ro,{htmlFor:c,required:e.required,tooltip:e.description,children:l})})]})}function Zee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s}=e,l=e.title??e.name;return o.jsx(Ht,{id:r,name:r,type:"number",value:t[r]||"",placeholder:s??`Enter ${l.toLowerCase()}`,onChange:c=>{const d=c.target.value,f=d===""?void 0:parseFloat(d);n(r,f)}})}function Kee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s,default:l}=e,c=e.title??e.name;return o.jsx(Hi,{id:r,name:r,value:Array.isArray(t[r])?t[r].join(`
724
724
  `):Array.isArray(l)?l.join(`
725
725
  `):"",placeholder:s??`Enter ${c.toLowerCase()} (one per line)`,rows:4,onChange:d=>{const f=d.target.value.split(`
726
- `).filter(m=>m.trim());n(r,f)}})}function Yee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s,default:l}=e,c=e.title??e.name,d=f=>{if(!f||typeof f!="string"&&typeof f!="number")return"";const m=typeof f=="string"?f:f.toString();try{const g=new Date(m);return isNaN(g.getTime())?"":g.toISOString().split("T")[0]}catch{return""}};return o.jsx(Ht,{id:r,name:r,type:"date",value:t[r]||d(l)||"",placeholder:s??`Enter ${c.toLowerCase()}`,onChange:f=>{n(r,f.target.value)}})}function Wee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s}=e,l=e.title??e.name;return o.jsx(Ht,{id:r,name:r,type:"text",value:t[r]||"",placeholder:s??`Enter ${l.toLowerCase()}`,onChange:c=>{n(r,c.target.value)}})}function Qee({specification:e,configuration:t,onValueChange:n}){const r=e.title??e.name,{name:s,placeholder:l,default:c}=e;return o.jsx(Hi,{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 f=JSON.parse(d.target.value);n(s,f)}catch{n(s,d.target.value)}}})}function Xee({specification:e,configuration:t,onValueChange:n,isEditingExisting:r,isSecretEditing:s}){const l=e.title??e.name,c=r&&!s;return o.jsx(Ht,{id:e.name,...c?{}:{name:e.name},type:c?"password":"text",autoComplete:c?"new-password":"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,value:c?eb: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 Jee({specification:e,configuration:t,onValueChange:n,specOptions:r}){const{name:s,placeholder:l,default:c}=e,d=e.title??e.name,f=r.map(m=>({value:m,label:m}));return o.jsx(tS,{options:f,value:t[s]||c||"",onValueChange:m=>{n(s,m)},placeholder:l??`Select ${d.toLowerCase()}`,emptyMessage:"No options available",className:"w-full"})}function TO({specification:e,configuration:t,onValueChange:n,flags:r}){const{requiredType:s,options:l}=e,{isSecret:c=!1,isEditingExisting:d=!1,isSecretEditing:f=!1}=r??{};if(c)return o.jsx(Xee,{specification:e,configuration:t,onValueChange:n,isEditingExisting:d,isSecretEditing:f});if(l&&l.length>0)return o.jsx(Jee,{specification:e,configuration:t,onValueChange:n,specOptions:l});switch(s){case rs.BOOLEAN:return o.jsx(qee,{specification:e,configuration:t,onValueChange:n});case rs.NUMBER:return o.jsx(Zee,{specification:e,configuration:t,onValueChange:n});case rs.ARRAY:return o.jsx(Kee,{specification:e,configuration:t,onValueChange:n});case rs.OBJECT:return o.jsx(Qee,{specification:e,configuration:t,onValueChange:n});case rs.DATE:return o.jsx(Yee,{specification:e,configuration:t,onValueChange:n});case rs.STRING:default:return o.jsx(Wee,{specification:e,configuration:t,onValueChange:n})}}function ete({specification:e,configuration:t,isEditingExisting:n,isSecretEditing:r,isSecret:s,onValueChange:l,onSecretEditToggle:c}){return o.jsxs(Gd,{children:[e.requiredType!==rs.BOOLEAN&&o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(Ro,{htmlFor:e.name,required:e.required,tooltip:e.description,children:e.title??e.name}),s&&n&&o.jsx(Se,{variant:"ghost",size:"sm",type:"button",onClick:()=>{c(e.name,!r)},children:r?"Cancel":"Edit"})]}),TO({specification:e,configuration:t,onValueChange:l,flags:{isSecret:s,isEditingExisting:n,isSecretEditing:r}})]},e.name)}function tte({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,f]=p.useState(c);if(p.useEffect(()=>{f(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(zee,{label:e.title??e.name,options:e.oneOf.map(g=>({value:g.value,label:g.label})),value:d,onValueChange:f,children:e.oneOf.map(g=>o.jsx(Mee,{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(Ro,{htmlFor:v,required:x.required,tooltip:x.description,className:"mb-2 justify-start",children:v}),w&&r&&o.jsx(Se,{variant:"ghost",size:"sm",type:"button",onClick:()=>{l(e.name,!s)},children:s?"Cancel":"Edit"})]}),TO({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 qT(e,t,n,r,s,l){return e.map(c=>{const d=Array.isArray(c.attributes)?c.attributes.includes("SECRET"):!1,f=s[c.name];return c.oneOf&&c.requiredType===rs.OBJECT?o.jsx(tte,{specification:c,configuration:t,onValueChange:n,isEditingExisting:l,isSecretEditing:f,onSecretEditToggle:r},c.name):o.jsx(ete,{specification:c,configuration:t,isEditingExisting:l,isSecret:d,isSecretEditing:f,onValueChange:n,onSecretEditToggle:r},c.name)})}function ZT({collapsibleTitle:e,items:t,configuration:n,onValueChange:r,onSecretEditToggle:s,secretEditing:l,isEditingExisting:c}){return e?o.jsx(Vee,{title:e,children:qT(t,n,r,s,l,c)}):qT(t,n,r,s,l,c)}function nte({currentConnectorName:e,onCopyConfiguration:t,connectorSpecification:n}){const[r,s]=p.useState([]),[l,c]=p.useState(!1),[d,f]=p.useState(!1),m=p.useCallback(async()=>{c(!0);try{const x=await sn.getDataMartsByConnectorName(e);s(x)}catch{s([])}finally{c(!1)}},[e]);p.useEffect(()=>{d&&m()},[d,m]);const g=(x,b)=>{const w=b._id;if(!w){console.error("Configuration does not have _id field");return}t({dataMartId:x.id,dataMartTitle:x.title,configId:w,configuration:b}),f(!1)},v=x=>{const w=[],C=R=>{if(!n)return!0;const T=n.find(_=>_.name===R);return(T==null?void 0:T.required)??!1},E=(R,T,_=0,O=!0)=>{if(R.startsWith("_")||O&&_===0&&!C(R))return;let A=null;if(T==null)A="N/A";else if(typeof T=="string")A=T;else if(typeof T=="number"||typeof T=="boolean")A=String(T);else if(Array.isArray(T))A=JSON.stringify(T);else if(typeof T=="object"){w.push({key:R,value:"{",indent:_}),Object.entries(T).forEach(([D,j])=>{E(D,j,_+1,!1)}),w.push({key:"",value:"}",indent:_});return}else A=JSON.stringify(T);w.push({key:R,value:A,indent:_})};for(const[R,T]of Object.entries(x))E(R,T);return o.jsx("div",{className:"space-y-1 font-mono text-xs",children:w.map(({key:R,value:T,indent:_},O)=>o.jsxs("div",{className:"flex gap-2",style:{paddingLeft:`${String(_*12)}px`},children:[R&&o.jsxs("span",{className:"font-medium",children:[R,":"]}),o.jsx("span",{className:"text-muted-foreground truncate",title:T,children:T})]},O))})};return o.jsx(ls,{children:o.jsxs(Er,{open:d,onOpenChange:f,children:[o.jsx(Rr,{asChild:!0,children:o.jsxs(Se,{type:"button",variant:"ghost",size:"sm",className:"cursor-pointer",children:[o.jsx("span",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:"Auto-fill from…"}),o.jsx(Ta,{className:J("text-foreground/75 h-3.5 w-3.5 transition-transform duration-200",d&&"rotate-90")})]})}),o.jsx(Tr,{side:"bottom",align:"end",className:"w-72",children:l?o.jsx(yt,{disabled:!0,children:"Loading…"}):r.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 p-4 text-center",children:[o.jsx("div",{className:"bg-muted/70 rounded-full p-3",children:o.jsx(SL,{className:"text-muted-foreground h-6 w-6",strokeWidth:1.5})}),o.jsx("span",{className:"text-foreground text-sm font-medium",children:"No matching Data Marts"}),o.jsx("span",{className:"text-muted-foreground text-sm",children:"You can auto-fill settings only from connector-based Data Marts with the same source."})]}):o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx("div",{className:"text-muted-foreground border-b p-2 text-sm",children:"Select one of your existing Data Marts to auto-fill settings in this form"}),o.jsx("div",{children:r.map(x=>{const w=x.definition.connector.source.configuration;return w.length===0?null:w.length===1?o.jsxs(wt,{delayDuration:300,children:[o.jsx(Et,{asChild:!0,children:o.jsxs(yt,{onSelect:()=>{g(x,w[0])},children:[o.jsx(ep,{className:"text-foreground h-4 w-4"}),x.title]})}),o.jsx(Rt,{side:"right",className:"max-w-sm",children:v(w[0])})]},x.id):o.jsxs(Jb,{children:[o.jsxs(e1,{className:"flex items-center gap-2",children:[o.jsx(ep,{className:"text-foreground h-4 w-4"}),o.jsx("span",{children:x.title})]}),o.jsx(t1,{children:w.map((C,E)=>o.jsxs(wt,{delayDuration:300,children:[o.jsx(Et,{asChild:!0,children:o.jsxs(yt,{onSelect:()=>{g(x,C)},children:["Configuration ",E+1]})}),o.jsx(Rt,{side:"right",className:"max-w-sm",children:v(C)})]},E))})]},x.id)})})]})})]})})}function KT({connector:e,connectorSpecification:t,onConfigurationChange:n,onValidationChange:r,initialConfiguration:s,loading:l=!1,isEditingExisting:c=!1}){const[d,f]=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(j=>{const M=Array.isArray(j.attributes)?j.attributes.includes("SECRET"):!1;D[j.name]===void 0&&j.default!==void 0&&(D[j.name]=j.default),c&&M&&(D[j.name]=eb)}),f(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,f({...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,j)=>{f(M=>({...M,[D]:j}))},w=p.useCallback(D=>!(D==null||typeof D=="string"&&D.trim()===""||typeof D=="number"&&isNaN(D)||Array.isArray(D)&&D.length===0),[]),C=p.useCallback((D,j)=>{var U;if(typeof D!="object"||D===null)return w(D);const M=(U=j.oneOf)==null?void 0:U.filter(H=>H.value===Object.keys(D)[0]);return M?M.every(H=>Object.entries(H.items).every(([,q])=>H.value in D?C(D[H.value],q):!1)):w(D[j.name])},[w]),E=p.useCallback((D,j)=>{const M=j.filter(Y=>Y.required&&Y.oneOf),U=M.length===0?!0:M.some(Y=>C(D[Y.name],Y)),q=j.filter(Y=>Y.required&&Y.name!=="Fields").every(Y=>w(D[Y.name]));return U&&q},[w,C]),R=(D,j)=>{x(M=>({...M,[D]:j})),f(j?M=>({...M,[D]:""}):M=>({...M,[D]:eb}))},T=D=>{const j={...d};Object.entries(D.configuration).forEach(([M,U])=>{j[M]=U}),j._copiedFrom={dataMartId:D.dataMartId,dataMartTitle:D.dataMartTitle,configId:D.configId},f(j)};if(p.useEffect(()=>{if(t&&r){const D=E(d,t);r(D)}},[d,t,r,E]),l)return o.jsx(pS,{variant:"list"});if(!t||t.length===0)return o.jsxs(jo,{children:[o.jsx(Tl,{connector:e}),o.jsx(ki,{icon:o.jsx(af,{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(au,{label:"Need configuration?"})]});const _=[...t].filter(D=>{var j;return D.name!=="Fields"&&!((j=D.attributes)!=null&&j.includes("HIDE_IN_CONFIG_FORM"))}).sort((D,j)=>{const M=U=>{const H=U.default!=null&&U.default!=="";return U.required&&!H?1:U.required&&H?2:!U.required&&!H?3:4};return M(D)-M(j)}),O=_.filter(D=>{var j;return!((j=D.attributes)!=null&&j.includes("ADVANCED"))}),A=_.filter(D=>{var j;return(j=D.attributes)==null?void 0:j.includes("ADVANCED")});return o.jsx(o.Fragment,{children:o.jsxs(jo,{children:[o.jsx(Tl,{connector:e}),o.jsxs(Rl,{children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("h3",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:"Configure Settings"}),o.jsx(nte,{currentConnectorName:e.name,onCopyConfiguration:T,connectorSpecification:t})]}),O.length>0&&o.jsx(ZT,{items:O,configuration:d,onValueChange:b,onSecretEditToggle:R,secretEditing:v,isEditingExisting:c}),A.length>0&&o.jsx(ZT,{collapsibleTitle:"Advanced Settings",items:A,configuration:d,onValueChange:b,onSecretEditToggle:R,secretEditing:v,isEditingExisting:c})]})]})})}function rte({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(pS,{variant:"list"}):!t||t.length===0?o.jsxs(jo,{children:[o.jsx(Tl,{connector:e}),o.jsx(ki,{icon:o.jsx(af,{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(au,{label:"Missing some data?"})]}):o.jsxs(jo,{children:[o.jsx(Tl,{connector:e}),o.jsxs(Rl,{title:c,children:[t.map(d=>o.jsx(RO,{type:"radio",id:d.name,name:"selectedField",value:d.name,label:d.overview??d.name,checked:n===d.name,onChange:f=>{l(f)},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(Ga,{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(Ta,{className:"h-3 w-3"})]})]}),selected:n===d.name},d.name)),o.jsx(au,{label:"Missing some data?"})]})]})}var Ns=(e=>(e.ASC="asc",e.DESC="desc",e.ORIGINAL="original",e))(Ns||{});function YT({connector:e,connectorFields:t,selectedField:n,selectedFields:r,onFieldToggle:s}){const l=p.useRef(null),[c,d]=p.useState(""),[f,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 A=x.includes(_.name),D=x.includes(O.name);if(A&&!D)return-1;if(!A&&D)return 1;if(f===Ns.ASC)return _.name.localeCompare(O.name);if(f===Ns.DESC)return O.name.localeCompare(_.name);const j=b.get(_.name)??0,M=b.get(O.name)??0;return j-M};return[...R].sort(T)},[v,c,x,f,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",A=document.activeElement.tagName;if(!(A==="INPUT"||A==="TEXTAREA")&&O){T.preventDefault();const D=v.map(U=>U.name),M=D.filter(U=>!r.includes(U)).length>0;D.forEach(U=>{s(U,M)})}};return window.addEventListener("keydown",R),()=>{window.removeEventListener("keydown",R)}},[v,r,s]),!n||!t?o.jsxs(jo,{children:[o.jsx(Tl,{connector:e}),o.jsx(ki,{icon:o.jsx(af,{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(au,{label:"Need fields?"})]}):v.length?o.jsx(jo,{children:o.jsxs(o.Fragment,{children:[o.jsx(Tl,{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(Vl,{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(iu,{className:"h-4 w-4"})})]}),o.jsxs(Er,{children:[o.jsx(Rr,{asChild:!0,children:o.jsxs(Se,{variant:"ghost",size:"icon","aria-label":"Sort fields",children:[f===Ns.ASC&&o.jsx(X2,{className:"text-muted-foreground h-4 w-4"}),f===Ns.DESC&&o.jsx(Q2,{className:"text-muted-foreground h-4 w-4"}),f===Ns.ORIGINAL&&o.jsx(J2,{className:"text-muted-foreground h-4 w-4"})]})}),o.jsxs(Tr,{align:"end",children:[o.jsxs(yt,{onSelect:()=>{m(Ns.ASC)},children:[o.jsx(X2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"A–Z"]}),o.jsxs(yt,{onSelect:()=>{m(Ns.DESC)},children:[o.jsx(Q2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Z–A"]}),o.jsxs(yt,{onSelect:()=>{m(Ns.ORIGINAL)},children:[o.jsx(J2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Original"]})]})]})]}),o.jsxs(Rl,{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(RO,{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(u0,{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(u0,{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(au,{label:"Need another field?"})]})]})}):o.jsxs(jo,{children:[o.jsx(Tl,{connector:e}),o.jsx(ki,{icon:o.jsx(af,{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(au,{label:"Need fields?"})]})}const jO=p.createContext(void 0),_O={triggers:[],selectedTrigger:null,isLoading:!1,error:null};function ate(e,t){switch(t.type){case"FETCH_TRIGGERS_START":case"FETCH_TRIGGER_START":case"CREATE_TRIGGER_START":case"UPDATE_TRIGGER_START":case"DELETE_TRIGGER_START":return{...e,isLoading:!0,error:null};case"FETCH_TRIGGERS_SUCCESS":return{...e,triggers:t.payload,isLoading:!1};case"FETCH_TRIGGER_SUCCESS":return{...e,selectedTrigger:t.payload,isLoading:!1};case"CREATE_TRIGGER_SUCCESS":return{...e,triggers:[...e.triggers,t.payload],isLoading:!1};case"UPDATE_TRIGGER_SUCCESS":return{...e,triggers:e.triggers.map(n=>n.id===t.payload.id?t.payload:n),selectedTrigger:e.selectedTrigger&&e.selectedTrigger.id===t.payload.id?t.payload:e.selectedTrigger,isLoading:!1};case"DELETE_TRIGGER_SUCCESS":return{...e,triggers:e.triggers.filter(n=>n.id!==t.payload),selectedTrigger:e.selectedTrigger&&e.selectedTrigger.id===t.payload?null:e.selectedTrigger,isLoading:!1};case"FETCH_TRIGGERS_ERROR":case"FETCH_TRIGGER_ERROR":case"CREATE_TRIGGER_ERROR":case"UPDATE_TRIGGER_ERROR":case"DELETE_TRIGGER_ERROR":return{...e,isLoading:!1,error:t.payload};case"SELECT_TRIGGER":return{...e,selectedTrigger:t.payload};case"RESET":return _O;default:return e}}class ste extends ql{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 Fc=new ste;var Sn=(e=>(e.REPORT_RUN="REPORT_RUN",e.CONNECTOR_RUN="CONNECTOR_RUN",e))(Sn||{});const Wc={SCHEDULED_REPORT_RUN:"scheduled-report-run-config"};class tb{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!==Sn.REPORT_RUN)return t;const n=t.triggerConfig;if(!n.reportId)return t;try{const r=await bo.getReportById(n.reportId),s=yl(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:Sn.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 ote{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:Sn.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 Yx={getMapper(e){switch(e){case Sn.REPORT_RUN:return new tb;case Sn.CONNECTOR_RUN:return new ote;default:throw new Error(`Unknown scheduled trigger type: ${String(e)}`)}}},Ud={mapFromDto(e){return Yx.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 Sn.REPORT_RUN:return new tb().enhanceWithReportData(n);case Sn.CONNECTOR_RUN:{const r=t.definition;return{...n,triggerConfig:{...n.triggerConfig,connector:r}}}default:return n}},async mapFromDtoListWithReportData(e,t){const n=new tb,r=this.mapFromDtoList(e),s=r.filter(c=>c.type===Sn.REPORT_RUN),l=await n.enhanceTriggersWithReportData(s);return r.map(c=>{switch(c.type){case Sn.REPORT_RUN:return l.find(d=>d.id===c.id)??c;case Sn.CONNECTOR_RUN:{const d=t.definition;return{...c,triggerConfig:{...c.triggerConfig,connector:d}}}default:return c}})},mapToCreateRequest(e){return Yx.getMapper(e.type).mapToCreateRequest(e)},mapToUpdateRequest(e){return Yx.getMapper(e.type).mapToUpdateRequest(e)}};function ite({children:e}){const[t,n]=p.useReducer(ate,_O),{dataMart:r}=Gi(),{fetchAvailableConnectors:s}=Kl();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 Fc.getScheduledTriggers(b),C=await Ud.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}),Ue({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 Fc.getScheduledTriggers(b)).filter(T=>T.type===w),R=await Ud.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}),Ue({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 Fc.getScheduledTrigger(b,w),E=await Ud.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}),Ue({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"GetError",label:E})}},[r]),f=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 Fc.createScheduledTrigger(b,_),A=await Ud.mapFromDtoWithReportData(O,r);return n({type:"CREATE_TRIGGER_SUCCESS",payload:A}),Ue({event:"scheduled_trigger_created",category:"ScheduledTrigger",action:"Create",label:w}),on.success("Trigger created"),A}catch(_){const O=_ instanceof Error?_.message:"Failed to create scheduled trigger";throw n({type:"CREATE_TRIGGER_ERROR",payload:O}),Ue({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 Fc.updateScheduledTrigger(b,w,T),O=await Ud.mapFromDtoWithReportData(_,r);n({type:"UPDATE_TRIGGER_SUCCESS",payload:O}),Ue({event:"scheduled_trigger_updated",category:"ScheduledTrigger",action:"Update",label:O.type}),on.success("Trigger updated")}catch(T){const _=T instanceof Error?T.message:"Failed to update scheduled trigger";throw n({type:"UPDATE_TRIGGER_ERROR",payload:_}),Ue({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"UpdateError",label:_}),T}},[r]),g=p.useCallback(async(b,w)=>{n({type:"DELETE_TRIGGER_START"});try{await Fc.deleteScheduledTrigger(b,w),n({type:"DELETE_TRIGGER_SUCCESS",payload:w}),Ue({event:"scheduled_trigger_deleted",category:"ScheduledTrigger",action:"Delete",label:w}),on.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}),Ue({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(jO.Provider,{value:{...t,getScheduledTriggers:l,getScheduledTriggersByType:c,getScheduledTrigger:d,createScheduledTrigger:f,updateScheduledTrigger:m,deleteScheduledTrigger:g,selectScheduledTrigger:v,reset:x},children:e})}function NO(){const e=p.useContext(jO);if(e===void 0)throw new Error("useScheduledTriggerContext must be used within a ScheduledTriggerProvider");return e}function lte(e){const{getScheduledTriggers:t,getScheduledTriggersByType:n,getScheduledTrigger:r,createScheduledTrigger:s,updateScheduledTrigger:l,deleteScheduledTrigger:c,selectScheduledTrigger:d,reset:f,triggers:m,selectedTrigger:g,isLoading:v,error:x}=NO();return p.useEffect(()=>(e?t(e):f(),()=>{f()}),[e,t,f]),{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 cte=ln({type:qs(Wc.SCHEDULED_REPORT_RUN),reportId:cn().min(1,"Report ID is required")}),ute=_B(),dte=ln({type:f1(Sn),cronExpression:cn().min(1,"Cron expression is required"),timeZone:cn().min(1,"Time zone is required"),isActive:jB(),triggerConfig:AB([cte,ute])});function fte({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:r}){const s=qi({resolver:Xl(dte),defaultValues:{type:e?e.type:n??Sn.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:Wc.SCHEDULED_REPORT_RUN,reportId:t??""}}});p.useEffect(()=>{t&&s.getValues("type")===Sn.REPORT_RUN&&s.setValue("triggerConfig",{type:Wc.SCHEDULED_REPORT_RUN,reportId:t})},[t,s]),p.useEffect(()=>{n&&(s.setValue("type",n),n===Sn.REPORT_RUN?s.setValue("triggerConfig",{type:Wc.SCHEDULED_REPORT_RUN,reportId:t??""}):s.setValue("triggerConfig",null))},[n,t,s]);const l=d=>{s.setValue("type",d),d===Sn.REPORT_RUN?s.setValue("triggerConfig",{type:Wc.SCHEDULED_REPORT_RUN,reportId:t??""}):s.setValue("triggerConfig",null)},c=async d=>{try{await r(d)}catch(f){console.error("Error submitting form:",f)}};return{form:s,handleTypeChange:l,handleSubmit:s.handleSubmit(c),isDirty:s.formState.isDirty}}function hte({value:e,onChange:t,disabled:n}){const{reports:r,fetchReportsByDataMartId:s}=Zl(),{dataMart:l}=Gi();p.useEffect(()=>{l&&s(l.id)},[s,l]);const c=r.filter(d=>d.dataDestination.type===Lt.GOOGLE_SHEETS);return o.jsxs(Ca,{value:e,onValueChange:t,disabled:n,children:[o.jsx(Ea,{className:"w-full",children:o.jsx(wa,{placeholder:"Select a report"})}),o.jsx(Ra,{children:c.map(d=>o.jsx(Kn,{value:d.id,children:d.title},d.id))})]})}var zg="Switch",[mte]=kr(zg),[pte,gte]=mte(zg),AO=p.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:s,defaultChecked:l,required:c,disabled:d,value:f="on",onCheckedChange:m,form:g,...v}=e,[x,b]=p.useState(null),w=pt(t,_=>b(_)),C=p.useRef(!1),E=x?g||!!x.closest("form"):!0,[R,T]=zr({prop:s,defaultProp:l??!1,onChange:m,caller:zg});return o.jsxs(pte,{scope:n,checked:R,disabled:d,children:[o.jsx(We.button,{type:"button",role:"switch","aria-checked":R,"aria-required":c,"data-state":kO(R),"data-disabled":d?"":void 0,disabled:d,value:f,...v,ref:w,onClick:Re(e.onClick,_=>{T(O=>!O),E&&(C.current=_.isPropagationStopped(),C.current||_.stopPropagation())})}),E&&o.jsx(MO,{control:x,bubbles:!C.current,name:r,value:f,checked:R,required:c,disabled:d,form:g,style:{transform:"translateX(-100%)"}})]})});AO.displayName=zg;var DO="SwitchThumb",OO=p.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,s=gte(DO,n);return o.jsx(We.span,{"data-state":kO(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:t})});OO.displayName=DO;var vte="SwitchBubbleInput",MO=p.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...s},l)=>{const c=p.useRef(null),d=pt(c,l),f=q1(n),m=zb(t);return p.useEffect(()=>{const g=c.current;if(!g)return;const v=window.HTMLInputElement.prototype,b=Object.getOwnPropertyDescriptor(v,"checked").set;if(f!==n&&b){const w=new Event("click",{bubbles:r});b.call(g,n),g.dispatchEvent(w)}},[f,n,r]),o.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...s,tabIndex:-1,ref:d,style:{...s.style,...m,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});MO.displayName=vte;function kO(e){return e?"checked":"unchecked"}var yte=AO,xte=OO;function IO({className:e,...t}){return o.jsx(yte,{"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(xte,{"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 bte(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 nb(e,t="UTC"){const n=bte(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 f=Number.parseInt(r),m=Number.parseInt(s),g=!isNaN(f)&&!isNaN(m)?`${m.toString().padStart(2,"0")}:${f.toString().padStart(2,"0")}`:"09:00";if(!isNaN(f)&&!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(f)&&!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(f)&&!isNaN(m)&&l!=="*"&&c==="*"&&d==="*"){const v=l.split(",").map(x=>Number.parseInt(x.trim())).filter(x=>!isNaN(x)&&x>=1&&x<=31);if(v.length>0)return{type:"monthly",time:g,weekdays:[1,2,3,4,5],monthDays:v,customCron:e,intervalType:"minutes",intervalValue:15,timezone:t}}return{type:"custom",time:"09:00",weekdays:[1,2,3,4,5],monthDays:[1],customCron:e,intervalType:"minutes",intervalValue:15,timezone:t}}function LO({options:e,selected:t,onSelectionChange:n,placeholder:r="Select items...",searchPlaceholder:s="Search...",maxDisplayItems:l=3}){const[c,d]=p.useState(!1),f=v=>{const x=t.includes(v)?t.filter(b=>b!==v):[...t,v].sort((b,w)=>b-w);n(x)},m=(v,x)=>{x.preventDefault(),x.stopPropagation(),n(t.filter(b=>b!==v))},g=()=>{if(t.length===0)return o.jsx("span",{className:"text-muted-foreground text-sm",children:r});const v=t.map(x=>e.find(b=>b.value===x)).filter(Boolean);return v.length<=l?o.jsx("div",{className:"flex flex-wrap gap-1",children:v.map(x=>o.jsxs(Ar,{variant:"secondary",className:"h-5 text-xs",children:[x.label,o.jsx("span",{className:"hover:bg-secondary-foreground/20 ml-1 inline-flex cursor-pointer items-center justify-center rounded-full p-0.5",onClick:b=>m(x.value,b),children:o.jsx(iu,{className:"h-2 w-2"})})]},x.value))}):o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsxs(Ar,{variant:"secondary",className:"h-5 text-xs",children:[v[0].label,o.jsx("span",{className:"hover:bg-secondary-foreground/20 ml-1 inline-flex cursor-pointer items-center justify-center rounded-full p-0.5",onClick:x=>m(v[0].value,x),children:o.jsx(iu,{className:"h-2 w-2"})})]}),v.length>1&&o.jsxs(Ar,{variant:"outline",className:"h-5 text-xs",children:["+",v.length-1]})]})};return o.jsxs(X1,{open:c,onOpenChange:d,modal:!0,children:[o.jsx(J1,{asChild:!0,children:o.jsxs(Se,{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(wb,{className:"ml-2 h-3 w-3 shrink-0 opacity-50"})]})}),o.jsx(eS,{className:"max-h-[400px] w-full overflow-y-auto p-0",style:{padding:0},children:o.jsxs(kD,{className:"h-full overflow-visible",children:[o.jsx(ID,{placeholder:s,className:"h-8"}),o.jsxs(xJ,{className:"h-full max-h-[350px] overflow-y-auto",children:[o.jsx(LD,{children:"No items found."}),o.jsx(PD,{className:"h-full overflow-visible",children:e.map(v=>o.jsxs(UD,{value:v.value.toString(),onSelect:()=>f(v.value),className:"text-sm",children:[o.jsx(fr,{className:J("mr-2 h-3 w-3",t.includes(v.value)?"opacity-100":"opacity-0")}),v.label]},v.value))})]})]})})]})}const PO=[{value:1,label:"Monday"},{value:2,label:"Tuesday"},{value:3,label:"Wednesday"},{value:4,label:"Thursday"},{value:5,label:"Friday"},{value:6,label:"Saturday"},{value:0,label:"Sunday"}],km=()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}};function UO(e,t){if(!t)return"Schedule is disabled";const n=e.time;switch(e.type){case"daily":return`Daily at ${n}`;case"weekly":return`Weekly on ${e.weekdays.map(s=>{var l;return(l=PO.find(c=>c.value===s))==null?void 0:l.label}).join(", ")} at ${n}`;case"monthly":{const s=[...e.monthDays].sort((c,d)=>c-d).map(c=>c===1?"1st":c===2?"2nd":c===3?"3rd":`${String(c)}th`);return`Monthly on the ${s.length===1?s[0]:s.length===2?`${s[0]} and ${s[1]}`:`${s.slice(0,-1).join(", ")}, and ${s[s.length-1]}`} at ${n}`}case"interval":return e.intervalType==="minutes"?`Every ${String(e.intervalValue)} minute${e.intervalValue!==1?"s":""}`:`Every ${String(e.intervalValue)} hour${e.intervalValue!==1?"s":""}`;case"custom":return"Custom schedule";default:return""}}function Ste(e,t,n=!0){const r=nb(e,t);return UO(r,n)}const Cte=Array.from({length:31},(e,t)=>({value:t+1,label:`${String(t+1)}${t===0?"st":t===1?"nd":t===2?"rd":"th"}`})),rb=[5,10,15,30],ab=[1,2,3,4,6,8,12],wte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(Sa,{children:"Type"}),o.jsxs(Ca,{value:e,onValueChange:r=>{t(r)},disabled:n,children:[o.jsx(Ea,{className:"w-full",children:o.jsx(wa,{})}),o.jsxs(Ra,{children:[o.jsx(Kn,{value:"daily",children:"Daily"}),o.jsx(Kn,{value:"weekly",children:"Weekly"}),o.jsx(Kn,{value:"monthly",children:"Monthly"}),o.jsx(Kn,{value:"interval",children:"Interval"})]})]})]}),Ete=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(Sa,{children:"Time"}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx(Ht,{className:"w-24",type:"time",value:e,onChange:r=>{t(r.target.value)},disabled:n})})]}),WT=({value:e,onChange:t,disabled:n,timezones:r})=>o.jsxs("div",{className:"w-full space-y-2",children:[o.jsx(Sa,{children:"Timezone"}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx(tS,{options:r,value:e,onValueChange:t,placeholder:"Select timezone",emptyMessage:"No timezones found",disabled:n,className:"w-full"})})]}),Rte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(Sa,{children:"Days of Week"}),o.jsx("div",{className:n?"pointer-events-none":"",children:o.jsx(LO,{options:PO,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:3})})]}),Tte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(Sa,{children:"Days of Month"}),o.jsx("div",{className:n?"pointer-events-none":"",children:o.jsx(LO,{options:Cte,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:4})})]}),jte=({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(Sa,{children:"Type"}),o.jsxs(Ca,{value:e,onValueChange:l=>{n(l)},disabled:s,children:[o.jsx(Ea,{className:"w-full",children:o.jsx(wa,{})}),o.jsxs(Ra,{children:[o.jsx(Kn,{value:"minutes",children:"Minutes"}),o.jsx(Kn,{value:"hours",children:"Hours"})]})]})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Sa,{children:"Every"}),o.jsxs(Ca,{value:t.toString(),onValueChange:l=>{r(Number.parseInt(l)||1)},disabled:s,children:[o.jsx(Ea,{className:"w-full",children:o.jsx(wa,{})}),o.jsx(Ra,{children:(e==="minutes"?rb:ab).map(l=>o.jsxs(Kn,{value:l.toString(),children:[l," ",e==="minutes"?"min":"hr"]},l))})]})]})]}),_te=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-1",children:[o.jsx(Sa,{className:"text-sm",children:"Cron Expression"}),o.jsx(Ht,{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 Nte({cron:e="0 9 * * *",timezone:t,enabled:n=!0,onChange:r,className:s,showPreview:l=!0,showSaveButton:c=!1}){const[d,f]=p.useState(n),[m,g]=p.useState(t??km()),[v,x]=p.useState(!1),b=p.useMemo(()=>JG.getTimezonesWithOffset().map(G=>({value:G.identifier,label:G.displayName,offset:G.offsetString,isDST:G.isDST})),[]),[w,C]=p.useState(()=>nb(e,m)),[E,R]=p.useState(""),[T,_]=p.useState("");p.useEffect(()=>{f(n)},[n]),p.useEffect(()=>{const G=t??km();g(G)},[t]),p.useEffect(()=>{if(e){const G=nb(e,m);C(G)}},[e,m]);const O=G=>{const[$,I]=G.time.split(":").map(Number);switch(G.type){case"daily":return`${String(I)} ${String($)} * * *`;case"weekly":return`${String(I)} ${String($)} * * ${G.weekdays.join(",")}`;case"monthly":return`${String(I)} ${String($)} ${G.monthDays.join(",")} * *`;case"interval":return G.intervalType==="minutes"?`*/${String(G.intervalValue)} * * * *`:`0 */${String(G.intervalValue)} * * *`;case"custom":return G.customCron;default:return`${String(I)} ${String($)} * * *`}},A=p.useCallback(G=>{C($=>{if($.intervalType===G)return console.log("Type unchanged, skipping update"),$;const B=(G==="minutes"?rb:ab)[0];return{...$,intervalType:G,intervalValue:B}})},[]),D=p.useCallback(G=>{C($=>($.intervalType==="minutes"?rb:ab).includes(G)?{...$,intervalValue:G}:$)},[]),j=p.useMemo(()=>G=>UO(G,d),[d]);p.useEffect(()=>{const G=O(w);R(G),_(j(w))},[w,d,m,j]);const M=p.useRef(""),U=p.useRef(""),H=p.useRef(!1);p.useEffect(()=>{const G=O(w);r&&(M.current!==G||U.current!==m||H.current!==d)&&(r({cron:G,timezone:m,enabled:d}),M.current=G,U.current=m,H.current=d)},[w,m,d,r]);const q=G=>{f(G)},Y=G=>{g(G),C($=>({...$,timezone:G}))},ae=["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(Sa,{htmlFor:"schedule-enabled",className:"text-sm font-normal",children:d?"Enabled":"Disabled"}),o.jsx(IO,{id:"schedule-enabled",checked:d,onCheckedChange:q})]})]})}),o.jsxs("div",{className:"space-y-4 pt-0",children:[o.jsxs("div",{className:`space-y-4 ${d?"":"opacity-50"}`,children:[o.jsx(wte,{value:w.type,onChange:G=>{C($=>({...$,type:G}))},disabled:!d}),w.type!=="custom"&&w.type!=="interval"&&o.jsxs("div",{className:"flex gap-3",children:[o.jsx(Ete,{value:w.time,onChange:G=>{C($=>({...$,time:G}))},disabled:!d}),ae&&o.jsx(WT,{value:m,onChange:Y,disabled:!d,timezones:b})]}),(w.type==="interval"||w.type==="custom")&&o.jsx(WT,{value:m,onChange:Y,disabled:!d,timezones:b}),w.type==="weekly"&&o.jsx(Rte,{value:w.weekdays,onChange:G=>{C($=>({...$,weekdays:G}))},disabled:!d}),w.type==="monthly"&&o.jsx(Tte,{value:w.monthDays,onChange:G=>{C($=>({...$,monthDays:G}))},disabled:!d}),w.type==="interval"&&o.jsx(jte,{intervalType:w.intervalType,intervalValue:w.intervalValue,onTypeChange:A,onValueChange:D,disabled:!d}),w.type==="custom"&&o.jsx(_te,{value:w.customCron,onChange:G=>{C($=>({...$,customCron:G}))},disabled:!d})]}),l&&o.jsxs(o.Fragment,{children:[o.jsx(y_,{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(r_,{className:"h-4 w-4"}),o.jsx("span",{className:"text-sm font-medium",children:"Preview"})]}),v?o.jsx(Us,{className:"text-muted-foreground h-4 w-4"}):o.jsx(Ka,{className:"text-muted-foreground h-4 w-4"})]}),v&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"grid gap-4",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Status:"}),o.jsx(Ar,{variant:d?"default":"secondary",className:"text-xs",children:d?"Enabled":"Disabled"})]}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Cron:"}),o.jsx(Ar,{variant:"secondary",className:"font-mono text-xs",children:E})]}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Timezone:"}),o.jsx(Ar,{variant:"outline",className:"text-xs",children:m})]}),o.jsxs("div",{className:"flex items-start justify-between gap-2",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Schedule:"}),o.jsx("span",{className:"flex-1 text-right text-xs",children:T})]})]}),d&&ae&&m!==km()&&o.jsxs(fS,{className:"border-amber-200 bg-amber-50",children:[o.jsx(wf,{className:"h-4 w-4"}),o.jsx(mO,{children:"Time Zone"}),o.jsxs(hS,{children:["Schedule runs in ",m," (not your local ",km()," ","time). Execution time may differ from expected."]})]})]})]})]}),c&&o.jsx(Se,{className:"w-full",disabled:!d,children:"Save Schedule"})]})]})}function Ate(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"trigger-type-options-description-details",children:[o.jsx(Qn,{children:"How do I choose a type?"}),o.jsxs(Xn,{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 Dte(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"trigger-type-change-description-details",children:[o.jsx(Qn,{children:"How do I change the trigger type?"}),o.jsx(Xn,{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 Ote(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"report-change-description-details",children:[o.jsx(Qn,{children:"How do I change a report?"}),o.jsx(Xn,{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(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"report-select-description-details",children:[o.jsx(Qn,{children:"How do I choose the report?"}),o.jsxs(Xn,{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 kte({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:r,onCancel:s,onDirtyChange:l}){const[c,d]=p.useState(!1),{form:f,handleTypeChange:m,handleSubmit:g,isDirty:v}=fte({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}=f,C=b("type")===Sn.REPORT_RUN;return o.jsx(Yl,{...f,children:o.jsxs(Zi,{onSubmit:E=>void g(E),noValidate:!1,children:[o.jsxs(Wl,{children:[o.jsx(Jt,{control:x,name:"type",render:({field:E})=>o.jsxs(en,{children:[o.jsx(tn,{tooltip:"Choose what you want this trigger to run - a report or a connector",children:"Trigger Type"}),o.jsxs(Ca,{onValueChange:R=>{E.onChange(R),m(R)},defaultValue:E.value,disabled:!!n||!!e||!!b("triggerConfig.reportId"),children:[o.jsx(nn,{children:o.jsx(Ea,{className:"w-full",children:o.jsx(wa,{placeholder:"Select trigger type"})})}),o.jsxs(Ra,{children:[o.jsx(Kn,{value:Sn.REPORT_RUN,children:"Report Run"}),o.jsx(Kn,{value:Sn.CONNECTOR_RUN,children:"Connector Run"})]})]}),o.jsx(or,{children:e?o.jsx(Dte,{}):o.jsx(Ate,{})}),o.jsx(un,{})]})}),C&&o.jsx(Jt,{control:x,name:"triggerConfig.reportId",render:({field:E})=>o.jsxs(en,{children:[o.jsx(tn,{tooltip:"Select the report that will be run by this trigger",children:"Report"}),o.jsx(nn,{children:o.jsx(D4,{children:o.jsx(hte,{value:E.value,onChange:E.onChange,disabled:!!t||!!e})})}),o.jsx(or,{children:e!=null&&e.triggerConfig?o.jsx(Ote,{}):o.jsx(Mte,{})}),o.jsx(un,{})]})}),o.jsx(Nte,{showPreview:!1,cron:b("cronExpression"),timezone:b("timeZone"),enabled:b("isActive"),onChange:E=>{f.setValue("cronExpression",E.cron,{shouldDirty:!0}),f.setValue("timeZone",E.timezone,{shouldDirty:!0}),f.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(Ql,{children:[o.jsx(Se,{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(Se,{variant:"outline",type:"button",onClick:s,className:"w-full","aria-label":"Cancel",children:"Cancel"})]})]})})}function Ite({cronExpression:e,timeZone:t,isEnabled:n=!0}){const r=p.useMemo(()=>Ste(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 Lte({table:e}){return o.jsx("div",{className:"text-right",children:o.jsxs(Er,{children:[o.jsx(Rr,{asChild:!0,children:o.jsx(Se,{variant:"ghost",className:"dm-card-table-body-row-actionbtn","aria-label":"Toggle columns",children:o.jsx(Ya,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsx(Tr,{align:"end",children:e.getAllColumns().filter(t=>t.getCanHide()&&t.id!=="actions").map(t=>o.jsx(yt,{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(fr,{className:"size-3.5 text-white"})})}),o.jsx("span",{children:t.columnDef.meta.title??t.id})]})},t.id))})]})})}function Pte({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:f=>{f.stopPropagation()},children:[o.jsxs(Er,{open:r,onOpenChange:s,children:[o.jsx(Rr,{asChild:!0,children:o.jsx(Se,{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(Ya,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsxs(Tr,{align:"end",children:[o.jsxs(yt,{onClick:()=>{t(e.id)},children:[o.jsx(Ef,{className:"text-foreground h-4 w-4","aria-hidden":"true"}),"Edit trigger"]}),o.jsx(qa,{}),o.jsxs(yt,{onClick:()=>{c(!0)},children:[o.jsx(Lo,{className:"h-4 w-4 text-red-600","aria-hidden":"true"}),o.jsx("span",{className:"text-red-600",children:"Delete trigger"})]})]})]}),o.jsx(ba,{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 Ute(e,t){const n=t.find(r=>r.name===e.source.name);return(n==null?void 0:n.displayName)??e.source.name}function Fte({connector:e}){const{connectors:t}=Kl(),n=Ute(e,t);return o.jsx(o.Fragment,{children:n})}function FO({connector:e}){return o.jsx(Fte,{connector:e})}function zte(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 Vte=e=>{const{connectors:t}=Kl();return p.useMemo(()=>t.find(n=>n.name===e),[t,e])},Hte=_e.memo(function({connector:t,children:n}){const r=Vte(t.source.name),{dataMart:s,runs:l,getDataMartRuns:c}=Gi();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(Vf,{base64:r.logoBase64,size:20}):null,[r==null?void 0:r.logoBase64]),f=p.useCallback(()=>{s!=null&&s.storage&&Aq(s.storage,t.storage.fullyQualifiedName)},[s==null?void 0:s.storage,t.storage.fullyQualifiedName]),m=p.useMemo(()=>zte(l),[l]),g=p.useMemo(()=>!m.lastRunDate||!m.lastRunStatus?null:{statusType:qZ(m.lastRunStatus),statusText:KZ(m.lastRunStatus),date:m.lastRunDate},[m]),v=p.useMemo(()=>(s==null?void 0:s.storage)&&Dq(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(x1,{children:[o.jsx(b1,{asChild:!0,children:o.jsx("span",{children:n})}),o.jsxs(S1,{children:[o.jsxs(C1,{children:[o.jsx(w1,{children:d}),o.jsxs(E1,{children:[o.jsx(R1,{children:o.jsx(FO,{connector:t})}),o.jsx(T1,{children:x})]})]}),o.jsxs(j1,{children:[o.jsxs(bi,{children:[o.jsx(Si,{children:"Last run status:"}),o.jsx(Ci,{children:g?o.jsx($f,{type:g.statusType,variant:"ghost",children:g.statusText}):"Not run yet"})]}),o.jsxs(bi,{children:[o.jsx(Si,{children:"Last run date:"}),o.jsx(Ci,{children:g?o.jsx(Ll,{date:g.date}):"Never run"})]}),o.jsxs(bi,{children:[o.jsx(Si,{children:"Total runs:"}),o.jsxs(Ci,{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(_1,{children:o.jsxs(Se,{className:"w-full",variant:"default",onClick:f,title:"Open Storage","aria-label":"Open Storage",children:[v,o.jsx(_l,{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 $te(e){const t=e.triggerConfig;return o.jsxs("div",{className:"inline gap-1",children:[t.report.title,o.jsx(BZ,{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 Bte(e){const t=e.triggerConfig,{connector:n}=t.connector;return o.jsxs("div",{className:"inline gap-1",children:[o.jsx(FO,{connector:n}),o.jsx(Hte,{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 Gte({trigger:e}){switch(e.type){case Sn.REPORT_RUN:return $te(e);case Sn.CONNECTOR_RUN:return Bte(e);default:return o.jsx("div",{className:"text-muted-foreground text-sm",children:"—"})}}function qte({onEditTrigger:e,onDeleteTrigger:t}){return[{accessorKey:"type",size:150,header:"Trigger Type",cell:({row:n})=>{const s=n.getValue("type")===Sn.REPORT_RUN?"Report Run":"Connector Run";return o.jsx(Ar,{variant:"outline",children:s})},meta:{title:"Trigger Type"}},{accessorKey:"triggerConfig",size:35,header:"Run Target",cell:({row:n})=>o.jsx(Gte,{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(Ite,{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(Ll,{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(Ll,{date:new Date(r)}):o.jsx("span",{className:"text-muted-foreground text-sm",children:"Never run"})})},meta:{title:"Last Run"}},{accessorKey:"isActive",size:15,header:"Trigger Status",cell:({row:n})=>{const r=n.getValue("isActive");return o.jsx($f,{type:r?Nn.SUCCESS:Nn.NEUTRAL,variant:"ghost",showIcon:!1,children:r?"Enabled":"Disabled"})},meta:{title:"Trigger Status"}},{id:"actions",size:80,header:({table:n})=>o.jsx(Lte,{table:n}),cell:({row:n})=>o.jsx(Pte,{trigger:n.original,onEditTrigger:e,onDeleteTrigger:t}),meta:{title:"Actions"}}]}function Zte({table:e,onPreviousClick:t,onNextClick:n}){return o.jsxs("div",{className:"dm-card-pagination",role:"navigation","aria-label":"Table pagination",children:[o.jsx(Se,{variant:"outline",size:"sm",onClick:t,disabled:!e.getCanPreviousPage(),"aria-label":"Go to previous page",children:"Previous"}),o.jsx(Se,{variant:"outline",size:"sm",onClick:n,disabled:!e.getCanNextPage(),"aria-label":"Go to next page",children:"Next"})]})}function gS({isOpen:e,onClose:t,dataMartId:n,preSelectedReportId:r,preSelectedType:s}){const{createScheduledTrigger:l,updateScheduledTrigger:c,selectedTrigger:d}=NO(),[f,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===Sn.REPORT_RUN?{type:Wc.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",A=(d==null?void 0:d.type)??s;e&&!_.current?(Ue({event:"scheduled_trigger_config_open",category:"ScheduledTrigger",action:O,label:A}),_.current=!0):!e&&_.current&&(Ue({event:"scheduled_trigger_config_close",category:"ScheduledTrigger",action:O,label:A}),_.current=!1)},[e,E,d,s]),o.jsxs(o.Fragment,{children:[o.jsx(Li,{open:e,onOpenChange:O=>{O||x()},children:o.jsxs(Pi,{children:[o.jsxs(Ui,{children:[o.jsxs(Fi,{children:[E?"Edit":"Create"," Scheduled Trigger"]}),o.jsx(Bl,{children:"Configure automatic runs for your reports or connectors."})]}),o.jsx(kte,{preSelectedReportId:r,preSelectedType:s,initialData:R,onSubmit:T,onCancel:x,onDirtyChange:w})]})}),o.jsx(ba,{open:f,onOpenChange:m,title:"Unsaved Changes",description:"You have unsaved changes. Exit without saving?",confirmLabel:"Yes, leave now",cancelLabel:"No, stay here",onConfirm:b,variant:"destructive"})]})}function Kte({triggers:e,dataMartId:t,onEditTrigger:n,onDeleteTrigger:r}){const[s,l]=p.useState(!1),c=p.useCallback(()=>{l(!1)},[]),d=p.useCallback(R=>{r(R)},[r]),f=p.useMemo(()=>qte({onEditTrigger:n,onDeleteTrigger:d}),[n,d]),{sorting:m,setSorting:g,columnVisibility:v,setColumnVisibility:x}=qf({columns:f,storageKeyPrefix:"data-mart-scheduled-triggers",defaultSortingColumn:"type"}),b=_u({data:e,columns:f,getCoreRowModel:ju(),getPaginationRowModel:Tg(),onSortingChange:g,getSortedRowModel:Gf(),getFilteredRowModel:Bf(),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(Nu,{id:"scheduled-triggers-table",className:"dm-card-table",role:"table","aria-label":"Scheduled Triggers",children:[o.jsx(Au,{className:"dm-card-table-header",children:b.getHeaderGroups().map(R=>o.jsx(ir,{className:"dm-card-table-header-row",children:R.headers.map(T=>o.jsx(Ou,{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(Du,{className:"dm-card-table-body",children:b.getRowModel().rows.length?b.getRowModel().rows.map((R,T)=>o.jsx(ir,{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(xa,{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(ir,{children:o.jsx(xa,{colSpan:f.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(Zte,{table:b,onPreviousClick:w,onNextClick:C}),o.jsx(gS,{isOpen:s,onClose:c,dataMartId:t})]})}function Yte({dataMartId:e}){const{triggers:t,deleteScheduledTrigger:n,selectScheduledTrigger:r,selectedTrigger:s}=lte(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)},f=()=>{c(!1),r(null)},m=async g=>{try{await n(e,g)}catch(v){console.error("Error deleting trigger:",v)}};return o.jsxs(o.Fragment,{children:[o.jsx(Kte,{triggers:t,dataMartId:e,onEditTrigger:d,onDeleteTrigger:g=>void m(g)}),o.jsx(gS,{isOpen:l,onClose:f,dataMartId:e})]})}function zO(){return o.jsx("div",{className:"dm-card-block !gap-1.5 !py-3",children:o.jsxs("div",{className:"text-foreground flex items-start gap-1.5 text-sm",children:[o.jsx(s_,{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 Wte({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,f]=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,A,D)=>{s({fullyQualifiedName:`${_}.${O}`,isValid:!!(_&&O&&A===null&&D===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 A=C(_),D=C(O);f(_),g(O),x(A),w(D);const j=`${_}.${O}`,M=!!(_&&O&&A===null&&D===null);((t==null?void 0:t.fullyQualifiedName)!==j||t.isValid!==M)&&E(_,O,A,D)},[t,l,c,E]);const R=_=>{f(_);const O=C(_);x(O),E(_,m,O,b)},T=_=>{g(_);const O=C(_);w(O),E(d,_,v,O)};return o.jsxs(jo,{children:[e===Ie.GOOGLE_BIGQUERY&&o.jsxs(o.Fragment,{children:[o.jsx(ki,{icon:o.jsx(KA,{}),title:"Google BigQuery",docUrl:"https://docs.owox.com/docs/storages/supported-storages/google-bigquery/",variant:"compact"}),o.jsxs(Rl,{title:"Choose where to store your data",children:[o.jsxs(Gd,{children:[o.jsx(Ro,{required:!0,htmlFor:"dataset-name",tooltip:"Enter dataset name for Google BigQuery where the connector data will be stored.",children:"Dataset name"}),o.jsx(Ht,{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(Gd,{children:[o.jsx(Ro,{required:!0,htmlFor:"table-name",tooltip:"Enter table name where the connector data will be stored.",children:"Table name"}),o.jsx(Ht,{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===Ie.AWS_ATHENA&&o.jsxs(o.Fragment,{children:[o.jsx(ki,{icon:o.jsx(YA,{}),title:"AWS Athena",docUrl:"https://docs.owox.com/docs/storages/supported-storages/aws-athena/",variant:"compact"}),o.jsxs(Rl,{title:"Choose where to store your data",children:[o.jsxs(Gd,{children:[o.jsx(Ro,{required:!0,htmlFor:"database-name",tooltip:"Enter database name for Amazon Athena where the connector data will be stored.",children:"Database name"}),o.jsx(Ht,{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(Gd,{children:[o.jsx(Ro,{required:!0,htmlFor:"athena-table-name",tooltip:"Enter table name where the connector data will be stored.",children:"Table name"}),o.jsx(Ht,{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(Rl,{title:"Schedule updates",children:o.jsx(zO,{})})]})}function Qte({onSubmit:e,dataStorageType:t,configurationOnly:n=!1,existingConnector:r=null,mode:s="full",initialStep:l,preselectedConnector:c}){const[d,f]=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),[A,D]=p.useState(new Set),{connectors:j,connectorSpecification:M,connectorFields:U,loading:H,loadingSpecification:q,loadingFields:Y,error:ae,fetchAvailableConnectors:G,fetchConnectorSpecification:$,fetchConnectorFields:I}=Kl(),[B,K]=p.useState(null),xe=(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 Me=>{!_.has(Me)&&!q&&(O(_t=>new Set(_t).add(Me)),await $(Me))},[_,q,$]),P=p.useCallback(async Me=>{A.has(Me)||(D(_t=>new Set(_t).add(Me)),await I(Me))},[A,I]);p.useEffect(()=>{if(!c||d||j.length===0)return;const Me=j.find(_t=>_t.name===c);Me&&(f(Me),w(l??2),L(Me.name),!n&&s!=="fields-only"&&P(Me.name))},[c,j,d,l,n,s,L,P]),p.useEffect(()=>{if(j.length===0&&!H&&G(),r&&j.length>0&&!d){const{source:Me,storage:_t}=r;g(Me.node),x(Me.fields),E(Me.configuration[0]||{}),K({fullyQualifiedName:_t.fullyQualifiedName,isValid:!0});const Nt=j.find(rn=>rn.name===Me.name);Nt&&(f(Nt),L(Nt.name),!n&&s!=="fields-only"&&P(Nt.name),s==="fields-only"&&P(Nt.name))}if(n&&j.length>0&&!d&&!r){const Me=j[0];f(Me),L(Me.name)}},[s,r,j,n,H,G,L,P,d]);const W=Me=>{f(Me),E({}),T(!1),O(_t=>{const Nt=new Set(_t);return Nt.delete(Me.name),Nt}),L(Me.name),P(Me.name)},ee=Me=>{g(Me),x([])},de=(Me,_t)=>{x(_t?Nt=>Nt.includes(Me)?Nt:[...Nt,Me]:Nt=>Nt.filter(rn=>rn!==Me))},ve=(Me,_t)=>{x(_t?Nt=>{const rn=Me.filter(V=>!Nt.includes(V));return[...Nt,...rn]}:Nt=>Nt.filter(rn=>!Me.includes(rn)))},ie=Me=>{K(Me)},Ne=p.useCallback(Me=>{E(Me)},[]),we=p.useCallback(Me=>{T(Me)},[]);p.useEffect(()=>{M&&(M.some(_t=>_t.required&&_t.name!=="Fields")||T(!0))},[M]);const Te=()=>{b<xe&&w(b+1)},$e=()=>{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 B!==null&&B.fullyQualifiedName!==""&&B.isValid;default:return!1}},Vt=()=>b>1,jt=(Me,_t)=>{if(!Me)return _t;const Nt=Me.find(rn=>rn.name===_t);return(Nt==null?void 0:Nt.destinationName)??_t},$t=()=>{if(n&&b===1)return M&&d?o.jsx(KT,{connector:d,connectorSpecification:M,onConfigurationChange:Ne,onValidationChange:we,initialConfiguration:C,loading:q,isEditingExisting:!!(r!=null&&r.source.configuration.length)}):null;if(s==="fields-only")switch(b){case 1:return d&&m&&U?o.jsx(YT,{connector:d,connectorFields:U,selectedField:m,selectedFields:v,onFieldToggle:de,onSelectAllFields:ve}):null;default:return null}switch(b){case 1:return o.jsx(Bee,{connectors:j,selectedConnector:d,loading:H,error:ae,onConnectorSelect:W,onConnectorDoubleClick:()=>{w(Me=>Me<xe?Me+1:Me)}});case 2:return d&&M?o.jsx(KT,{connector:d,connectorSpecification:M,onConfigurationChange:Ne,onValidationChange:we,initialConfiguration:C,loading:q,isEditingExisting:!1}):null;case 3:return d&&U?o.jsx(rte,{connectorFields:U,connector:d,selectedField:m,connectorName:d.displayName,loading:Y,onFieldSelect:ee}):null;case 4:return d&&m&&U?o.jsx(YT,{connector:d,connectorFields:U,selectedField:m,selectedFields:v,onFieldToggle:de,onSelectAllFields:ve}):null;case 5:return m&&U?o.jsx(Wte,{dataStorageType:t,destinationName:jt(U,m),connectorName:(d==null?void 0:d.displayName)??"",target:B,onTargetChange:ie}):null;default:return null}};return o.jsxs(Pee,{children:[o.jsx(Uee,{children:$t()}),o.jsx(Fee,{variant:"horizontal",children:o.jsx(Gee,{currentStep:b,totalSteps:xe,canGoNext:Xe(),canGoBack:Vt(),isLoading:q||Y,onNext:Te,onBack:$e,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&&B&&e({source:{name:d.name,configuration:[C],node:m,fields:v},storage:{fullyQualifiedName:B.fullyQualifiedName}})}})})]})}const VO=20,HO=20;function $O({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 Xte(e=30,t=0){$O({vertical:HO+e,horizontal:VO+t})}function sb(){$O({vertical:HO,horizontal:VO})}function BO({isOpen:e,onClose:t,dataStorageType:n,onSubmit:r,configurationOnly:s=!1,existingConnector:l=null,mode:c="full",initialStep:d,preselectedConnector:f}){return p.useEffect(()=>(e?Xte(55):sb(),()=>{sb()}),[e]),o.jsx(Li,{open:e,onOpenChange:t,children:o.jsxs(Pi,{children:[o.jsxs(Ui,{children:[o.jsx(Fi,{children:c==="fields-only"?"Connector Fields":l!=null&&l.source.name?"Edit Connector":"Set Up Connector"}),o.jsx(Bl,{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(Qte,{onSubmit:m=>{r(m),t()},dataStorageType:n,configurationOnly:s||c==="configuration-only",existingConnector:l,mode:c,initialStep:d,preselectedConnector:f})]})})}const vS=({dataStorageType:e,onSubmit:t,children:n,configurationOnly:r=!1,existingConnector:s=null,preset:l,isOpen:c,onClose:d})=>{const[f,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(pu,{children:o.jsx(BO,{isOpen:f,onClose:C,dataStorageType:e,onSubmit:t,configurationOnly:r,existingConnector:s,initialStep:g,preselectedConnector:x})})]})};function Jte({storageType:e,onSetupConnector:t,preset:n,isOpen:r,onClose:s}){return o.jsx(vS,{dataStorageType:e,onSubmit:t,configurationOnly:!1,preset:n,isOpen:r,onClose:s,children:o.jsxs(Se,{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(Tb,{className:"h-4 w-4",strokeWidth:2.25})}),o.jsx("span",{children:"Setup Connector"}),o.jsx(Ta,{className:"h-6 w-6"})]})})}const ene=e=>{switch(e){case Ie.GOOGLE_BIGQUERY:return"Google BigQuery";case Ie.AWS_ATHENA:return"AWS Athena";default:return e}},Zc=e=>typeof e=="object"&&"connector"in e,Fd=e=>{if(!Zc(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 tne({configIndex:e,connectorDef:t,onRemoveConfiguration:n,onUpdateConfiguration:r,dataMartStatus:s,totalConfigurations:l,dataStorage:c}){const d=Bi.getInfo(c.type),{connectors:f,fetchAvailableConnectors:m}=Kl();p.useEffect(()=>{m()},[m]);const g=C=>{const E=f.find(R=>R.name===C);if(E!=null&&E.logoBase64)return()=>o.jsx(Vf,{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(wt,{children:[o.jsx(Et,{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(Ta,{className:"h-3 w-3"})]})}),o.jsx(Rt,{children:"Edit connector configuration"})]})]})},x=(C,E,R)=>o.jsxs("span",{children:[o.jsxs("span",{className:"text-muted-foreground/75",children:[C,":"]})," ",o.jsx(hr,{href:R,onClick:T=>{T.stopPropagation()},children:E})]}),b=()=>{switch(c.type){case Ie.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(wt,{children:[o.jsx(Et,{asChild:!0,children:o.jsx(Fr,{className:"h-4 w-4"})}),o.jsx(Rt,{children:"The dataset and table are automatically created during the first run of the data mart, if they don't already exist"})]})]})}case Ie.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(wt,{children:[o.jsx(Et,{asChild:!0,children:o.jsx(Fr,{className:"h-4 w-4"})}),o.jsx(Rt,{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===dr.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(vS,{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(Y0,{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(Y0,{title:ene(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(wt,{children:[o.jsx(Et,{asChild:!0,children:o.jsx(Se,{type:"button",variant:"ghost",onClick:()=>{w()&&n(e)},disabled:!w(),children:o.jsx(Lo,{className:"h-4 w-4"})})}),!w()&&o.jsx(Rt,{children:"Cannot remove the last configuration in published pipeline"})]})})]})}function nne({storageType:e,onAddConfiguration:t,existingConnector:n}){return o.jsx("div",{children:o.jsx(vS,{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(Se,{type:"button",variant:"outline",className:"dm-card-table-add-field-btn cursor-pointer",children:[o.jsx(ja,{className:"h-4 w-4"}),o.jsx("span",{children:"Configuration"})]})})})}function rne({control:e,storageType:t,preset:n,autoOpen:r=!1}){const{dataMart:s,runDataMart:l}=gs(),{setValue:c,getValues:d,trigger:f}=Mu(),[m,g]=p.useState(!1),[v,x]=p.useState(!1);p.useEffect(()=>{r&&x(!0)},[r]);const b=()=>{setTimeout(()=>void f("definition"),0)},w=(s==null?void 0:s.status)??dr.DRAFT,C=j=>{const M=j.source,U=j.storage;c("definition",{connector:{source:M,storage:U}},{shouldDirty:!0,shouldTouch:!0}),b()},E=async j=>{if(s){if(s.status.code!==dr.PUBLISHED){Ot.error("Manual run is only available for published data marts");return}await l({id:s.id,payload:j})}},R=j=>M=>{const H=d().definition;if(typeof H=="object"&&Zc(H)){const q=[...H.connector.source.configuration];q[j]=M.source.configuration[0]||{};const Y={connector:{...H.connector,source:{...H.connector.source,configuration:q}}};c("definition",Y,{shouldDirty:!0,shouldTouch:!0}),b()}},T=j=>{const U=d().definition;if(typeof U=="object"&&Zc(U)){const H={connector:{...U.connector,source:{...U.connector.source,fields:j.source.fields}}};c("definition",H,{shouldDirty:!0,shouldTouch:!0}),b()}g(!1)},_=j=>{E({runType:j.runType,data:j.data})},O=j=>{const M=j.connector.source.fields.length;return o.jsxs(Se,{type:"button",variant:"outline",onClick:()=>{g(!0)},className:"dm-card-table-add-field-btn cursor-pointer",children:[o.jsx(wL,{className:"h-4 w-4"}),o.jsxs("span",{children:["Edit Fields (",String(M),")"]})]})},A=j=>{const U=d().definition;if(Zc(U)&&U.connector.source.configuration.length<=1){const H=J0(Ke.CONNECTOR);c("definition",H,{shouldDirty:!0,shouldTouch:!0}),b()}if(typeof U=="object"&&Zc(U)&&U.connector.source.configuration.length>1){const H={...U.connector.source,configuration:U.connector.source.configuration.filter((Y,ae)=>ae!==j)},q={connector:{...U.connector,source:H}};c("definition",q,{shouldDirty:!0,shouldTouch:!0}),b()}},D=j=>{const U=d().definition;if(Zc(U)){const H={...U.connector.source,configuration:[...U.connector.source.configuration,j]},q={connector:{...U.connector,source:H}};c("definition",q,{shouldDirty:!0,shouldTouch:!0}),b()}};return o.jsxs(o.Fragment,{children:[o.jsx(Jt,{control:e,name:"definition",render:({field:j})=>o.jsxs(en,{className:"dark:bg-white/2",children:[o.jsx(nn,{children:o.jsx("div",{className:"space-y-3",children:!Fd(j.value)||w===dr.DRAFT?o.jsx(Jte,{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(nne,{storageType:t,onAddConfiguration:D,existingConnector:Fd(j.value)?{source:j.value.connector.source,storage:j.value.connector.storage}:void 0}),Fd(j.value)&&O(j.value)]}),o.jsx("div",{className:"flex items-center gap-2",children:s&&s.definitionType===Ke.CONNECTOR&&o.jsx(vD,{configuration:s.definition,onManualRun:_,children:o.jsxs(Se,{variant:"outline",children:[o.jsx(Rb,{className:"h-4 w-4"}),o.jsx("span",{children:"Manual Run..."})]})})})]}),o.jsx("div",{className:"space-y-3",children:Fd(j.value)&&(s!=null&&s.storage)?j.value.connector.source.configuration.map((M,U)=>{const H=j.value;return o.jsx(pu,{children:o.jsx(tne,{configIndex:U,connectorDef:H,dataStorage:s.storage,onRemoveConfiguration:A,onUpdateConfiguration:R,dataMartStatus:typeof w=="object"?w.code:w,totalConfigurations:H.connector.source.configuration.length},U)},U)}):null})]})})}),o.jsx(un,{})]})}),o.jsx(pu,{children:o.jsx(BO,{isOpen:m,onClose:()=>{g(!1)},onSubmit:T,dataStorageType:t,existingConnector:Fd(d().definition)?{source:d().definition.connector.source,storage:d().definition.connector.storage}:void 0,mode:"fields-only"})})]})}function ane({definitionType:e,storageType:t,preset:n}){const{control:r}=Mu(),[s,l]=p.useState(!1);return p.useEffect(()=>{e===Ke.CONNECTOR&&!n?l(!0):l(!1)},[e,n]),o.jsxs("div",{className:"space-y-2",children:[e===Ke.SQL&&o.jsx(xee,{control:r}),e===Ke.TABLE&&o.jsx(bee,{control:r,storageType:t}),e===Ke.VIEW&&o.jsx(See,{control:r,storageType:t}),e===Ke.TABLE_PATTERN&&o.jsx(Cee,{control:r,storageType:t}),e===Ke.CONNECTOR&&o.jsx(rne,{control:r,storageType:t,preset:n,autoOpen:s})]})}function GO(){const[e]=NI(),t=e.get("preset");return p.useMemo(()=>{if(!t)return;const n=t.toLowerCase();return bY(n)},[t])}function sne(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 one(e,t){const[n,r]=p.useState(e);return p.useEffect(()=>{const s=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(s)}},[e,t]),n}const ine=1e3,lne=[El.SUCCESS,El.ERROR,El.CANCELLED];function cne(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)},[]),f=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 sn.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 sn.getSqlDryRunTriggerStatus(e,v);if(lne.includes(b)){const w=await sn.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,ine))}catch(b){d(b),l.current={triggerId:null,abortController:null};return}},[e,c,d]),g=p.useCallback(async v=>{await f(),n(!0),s(null);try{const{triggerId:x}=await sn.createSqlDryRunTrigger(e,v),b=new AbortController;l.current={triggerId:x,abortController:b},await m(x,b.signal)}catch(x){d(x)}},[e,f,m,d]);return p.useEffect(()=>()=>{const{triggerId:v,abortController:x}=l.current;x==null||x.abort(),v&&sn.abortSqlDryRunTrigger(e,v).catch(()=>{})},[e]),{validateSql:g,isLoading:t,result:r,cancel:f}}const une=300;function dne({sql:e,dataMartId:t,debounceDelay:n=une,className:r="",onValidationStateChange:s}){const l=one(e.trim(),n),{validateSql:c,isLoading:d,result:f,cancel:m}=cne(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:(f==null?void 0:f.isValid)??null,error:(f==null?void 0:f.error)??null,bytes:(f==null?void 0:f.bytes)??null};s==null||s(v)},[d,f,s]);const g=()=>d?o.jsxs("div",{className:"flex h-5 items-center gap-2",children:[o.jsx(yu,{className:"h-4 w-4 animate-spin"}),o.jsx("span",{className:"text-sm",children:"Validating..."})]}):f?f.isValid?o.jsxs("div",{className:"flex h-5 items-center gap-2",children:[o.jsx(Jj,{className:"h-4 w-4 text-green-600"}),o.jsx("span",{className:"text-sm font-medium text-green-600",children:"Valid SQL code"}),f.bytes!==void 0&&o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"mx-1 text-gray-400",children:"•"}),o.jsxs(wt,{children:[o.jsx(Et,{asChild:!0,children:o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx(tp,{className:"h-3 w-3 text-gray-600"}),o.jsx("span",{className:"text-xs text-gray-600",children:sne(f.bytes)})]})}),o.jsx(Rt,{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(nf,{className:"h-4 w-4 flex-shrink-0 text-red-600"}),f.error&&o.jsx("span",{className:"text-xs text-red-500",children:f.error})]}):o.jsxs("div",{className:"flex h-5 items-center gap-2 text-gray-500",children:[o.jsx(tp,{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 fne(){const{dataMart:e,updateDataMartDefinition:t,getDataMart:n}=gs(),r=GO();if(!e)throw new Error("Data mart not found");const{definitionType:s,definition:l,id:c,storage:{type:d}}=e,[f,m]=p.useState(s),[,g]=p.useState({isValid:null,isLoading:!1,error:null}),v=p.useCallback(()=>{if(!f)return;const $={definitionType:f,definition:J0(f)};return l?{definitionType:f,definition:l}:$},[f,l]),x=p.useCallback(()=>{if(!f)return;const $=yee(f,d);return Xl($)},[f,d]),b=qi({resolver:x(),defaultValues:v(),mode:"onChange"}),{handleSubmit:w,reset:C,watch:E,formState:{isDirty:R,isValid:T}}=b,_=($,I)=>{if($!==Ke.SQL)return"";const B=I;return(B==null?void 0:B.sqlQuery)??""},O=E("definition"),A=_(f,O);p.useEffect(()=>{f&&C(v())},[f,C,v]);const D=$=>J0($);p.useEffect(()=>{if(!f&&!s&&(r!=null&&r.definitionType)){m(r.definitionType);const $={definitionType:r.definitionType,definition:D(r.definitionType)};C($)}},[r,f,s,C]);const j=p.useCallback($=>{g({isLoading:$.isLoading,isValid:$.isValid,error:$.error})},[]),M=$=>{m($)},U=p.useCallback(()=>{c&&n(c)},[c,n]),{run:H}=Y1(c,U),q=async $=>{if(f&&c)try{await t(c,$.definitionType,$.definition),await H(),C($)}catch(I){console.error("Failed to update data mart definition:",I)}},Y=$=>{$.preventDefault(),w(q)($)},ae=()=>{C(v())},G=()=>f?o.jsxs("form",{onSubmit:Y,className:"space-y-4",children:[o.jsx(ane,{definitionType:f,storageType:d,preset:r==null?void 0:r.connectorSourceTitle}),o.jsxs("div",{className:"flex items-center gap-4",children:[o.jsx(Se,{variant:"default",type:"submit",disabled:!T||!R,children:"Save"}),o.jsx(Se,{type:"button",variant:"ghost",onClick:ae,disabled:!R,children:"Discard"}),f===Ke.SQL&&A&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-6 w-px bg-gray-300"}),o.jsx(dne,{sql:A,dataMartId:c,onValidationStateChange:j})]})]})]}):null;return o.jsx(S3,{...b,children:o.jsxs("div",{className:"space-y-4",children:[!s&&o.jsx(fee,{initialType:f,onTypeSelect:M}),G()]})})}function hne(e){switch(e){case Ie.GOOGLE_BIGQUERY:return{type:"bigquery-data-mart-schema",fields:[]};case Ie.AWS_ATHENA:return{type:"athena-data-mart-schema",fields:[]};default:throw new Error(`Unsupported storage type: ${e}`)}}function qO(e){return e.type==="bigquery-data-mart-schema"}function ZO(e){return e.type==="athena-data-mart-schema"}function QT(e){return e!==null&&typeof e=="object"&&"mode"in e}function XT(e){return e!==null&&typeof e=="object"&&"isPrimaryKey"in e}function mne(e){return e==null?"":typeof e=="string"||typeof e=="number"||typeof e=="boolean"?String(e):""}function Wx(e){return e==null?e:JSON.parse(JSON.stringify(e))}function pne(e){const t=Wx(e),[n,r]=p.useState(t),[s,l]=p.useState(!1);p.useEffect(()=>{const f=Wx(e);r(f),l(!1)},[e]);const c=p.useCallback(f=>{n?qO(n)&&f.every(QT)?(r({...n,fields:f}),l(!0)):ZO(n)&&f.every(XT)&&(r({...n,fields:f}),l(!0)):f.length>0&&(QT(f[0])?(r({type:"bigquery-data-mart-schema",fields:f}),l(!0)):XT(f[0])&&(r({type:"athena-data-mart-schema",fields:f}),l(!0)))},[n]),d=p.useCallback(()=>{const f=Wx(e);r(f),l(!1)},[e]);return{schema:n,isDirty:s,updateSchema:c,resetSchema:d,setIsDirty:l}}function gne(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 vne(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 KO(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=>KO(c,t)):!1}function YO(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,f=s.alias?s.alias.toLowerCase().includes(t):!1,m=s.description?s.description.toLowerCase().includes(t):!1;if((d||f||m)&&r.push(c),s.fields&&s.fields.length>0){const g=YO(s.fields,t,c);g.length>0&&(r.includes(c)||r.push(c),r.push(...g))}}),r}function yne(e,t,n){const r=e.original;if(!n)return!0;const s=n.toLowerCase();return KO(r,s)}function xne(e){const[t,n]=p.useState(""),r=p.useCallback(l=>{n(l),e.setGlobalFilter(l)},[e]),s=t.toLowerCase();return{value:t,onChange:r,searchValue:s}}var us=(e=>(e.CONNECTED="CONNECTED",e.CONNECTED_WITH_DEFINITION_MISMATCH="CONNECTED_WITH_DEFINITION_MISMATCH",e.DISCONNECTED="DISCONNECTED",e))(us||{}),pf=(e=>(e.NULLABLE="NULLABLE",e.REQUIRED="REQUIRED",e.REPEATED="REPEATED",e))(pf||{}),Un=(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))(Un||{}),yS=(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))(yS||{});function bne(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===Un.RECORD||E.type===Un.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})},[]),f=p.useCallback(()=>{const w=[],C=(E,R="")=>{E.forEach((T,_)=>{const O=R?`${R}.${String(_)}`:String(_);(T.type===Un.RECORD||T.type===Un.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 A=R?`${R}.${String(O)}`:String(O),D=_.type===Un.RECORD||_.type===Un.STRUCT;w.push({..._,path:A,level:T}),D&&_.fields&&t.has(A)&&C(_.fields,A,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=YO(e,w).filter(R=>{const T=R.split(".").map(Number);let _=e,O;for(let A=0;A<T.length;A++){if(O=_[T[A]],!O)return!1;if((O.type===Un.RECORD||O.type===Un.STRUCT)&&O.fields&&O.fields.length>0)return!0;A<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===Un.RECORD||C.type===Un.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===Un.RECORD||T.type===Un.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:f,flattenedFields:m,handleSearchChange:g,isRecordType:v,topLevelFields:x,allExpanded:b}}function Sne(e,t,n,r){const s=p.useCallback((f,m)=>{if(n){const g=[...e],v=t[f].path;if(!v)g[f]={...g[f],...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 f={name:"",type:Un.STRING,mode:pf.NULLABLE,isPrimaryKey:!1,status:us.DISCONNECTED};n([...e,f])}},[e,n]),c=p.useCallback(f=>{if(n){const m=[...e],g=t[f].path;if(!g)m.splice(f,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(f=>{var m,g;if(n&&r){const v=[...e],x=t[f].path,b={name:"",type:Un.STRING,mode:pf.NULLABLE,isPrimaryKey:!1,status:us.DISCONNECTED};if(!x)(m=v[f]).fields??(m.fields=[]),v[f].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 WO(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),f=n.findIndex((x,b)=>(x.path??String(b))===c.id);if(d===-1||f===-1)return;const m=n[d].path,g=n[f].path,v=[...e];if(!m&&!g){const[x]=v.splice(d,1);v.splice(f,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 Cne(){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 Vg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Lu(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function xS(e){return"nodeType"in e}function na(e){var t,n;return e?Lu(e)?e:xS(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function bS(e){const{Document:t}=na(e);return e instanceof t}function Xf(e){return Lu(e)?!1:e instanceof na(e).HTMLElement}function QO(e){return e instanceof na(e).SVGElement}function Pu(e){return e?Lu(e)?e.document:xS(e)?bS(e)?e:Xf(e)||QO(e)?e.ownerDocument:document:document:document}const Hs=Vg?p.useLayoutEffect:p.useEffect;function SS(e){const t=p.useRef(e);return Hs(()=>{t.current=e}),p.useCallback(function(){for(var n=arguments.length,r=new Array(n),s=0;s<n;s++)r[s]=arguments[s];return t.current==null?void 0:t.current(...r)},[])}function wne(){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 gf(e,t){t===void 0&&(t=[e]);const n=p.useRef(e);return Hs(()=>{n.current!==e&&(n.current=e)},t),n}function Jf(e,t){const n=p.useRef();return p.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function Ip(e){const t=SS(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 ob(e){const t=p.useRef();return p.useEffect(()=>{t.current=e},[e]),t.current}let Qx={};function eh(e,t){return p.useMemo(()=>{if(t)return t;const n=Qx[e]==null?0:Qx[e]+1;return Qx[e]=n,e+"-"+n},[e,t])}function XO(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[f,m]of d){const g=l[f];g!=null&&(l[f]=g+e*m)}return l},{...t})}}const su=XO(1),Lp=XO(-1);function Ene(e){return"clientX"in e&&"clientY"in e}function CS(e){if(!e)return!1;const{KeyboardEvent:t}=na(e.target);return t&&e instanceof t}function Rne(e){if(!e)return!1;const{TouchEvent:t}=na(e.target);return t&&e instanceof t}function ib(e){if(Rne(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 Ene(e)?{x:e.clientX,y:e.clientY}:null}const vf=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[vf.Translate.toString(e),vf.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),JT="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function Tne(e){return e.matches(JT)?e:e.querySelector(JT)}const jne={display:"none"};function _ne(e){let{id:t,value:n}=e;return _e.createElement("div",{id:t,style:jne},n)}function Nne(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 Ane(){const[e,t]=p.useState("");return{announce:p.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const JO=p.createContext(null);function Dne(e){const t=p.useContext(JO);p.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function One(){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:`
726
+ `).filter(m=>m.trim());n(r,f)}})}function Yee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s,default:l}=e,c=e.title??e.name,d=f=>{if(!f||typeof f!="string"&&typeof f!="number")return"";const m=typeof f=="string"?f:f.toString();try{const g=new Date(m);return isNaN(g.getTime())?"":g.toISOString().split("T")[0]}catch{return""}};return o.jsx(Ht,{id:r,name:r,type:"date",value:t[r]||d(l)||"",placeholder:s??`Enter ${c.toLowerCase()}`,onChange:f=>{n(r,f.target.value)}})}function Wee({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s}=e,l=e.title??e.name;return o.jsx(Ht,{id:r,name:r,type:"text",value:t[r]||"",placeholder:s??`Enter ${l.toLowerCase()}`,onChange:c=>{n(r,c.target.value)}})}function Qee({specification:e,configuration:t,onValueChange:n}){const r=e.title??e.name,{name:s,placeholder:l,default:c}=e;return o.jsx(Hi,{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 f=JSON.parse(d.target.value);n(s,f)}catch{n(s,d.target.value)}}})}function Xee({specification:e,configuration:t,onValueChange:n,isEditingExisting:r,isSecretEditing:s}){const l=e.title??e.name,c=r&&!s;return o.jsx(Ht,{id:e.name,...c?{}:{name:e.name},type:c?"password":"text",autoComplete:c?"new-password":"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,value:c?eb: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 Jee({specification:e,configuration:t,onValueChange:n,specOptions:r}){const{name:s,placeholder:l,default:c}=e,d=e.title??e.name,f=r.map(m=>({value:m,label:m}));return o.jsx(tS,{options:f,value:t[s]||c||"",onValueChange:m=>{n(s,m)},placeholder:l??`Select ${d.toLowerCase()}`,emptyMessage:"No options available",className:"w-full"})}function TO({specification:e,configuration:t,onValueChange:n,flags:r}){const{requiredType:s,options:l}=e,{isSecret:c=!1,isEditingExisting:d=!1,isSecretEditing:f=!1}=r??{};if(c)return o.jsx(Xee,{specification:e,configuration:t,onValueChange:n,isEditingExisting:d,isSecretEditing:f});if(l&&l.length>0)return o.jsx(Jee,{specification:e,configuration:t,onValueChange:n,specOptions:l});switch(s){case rs.BOOLEAN:return o.jsx(qee,{specification:e,configuration:t,onValueChange:n});case rs.NUMBER:return o.jsx(Zee,{specification:e,configuration:t,onValueChange:n});case rs.ARRAY:return o.jsx(Kee,{specification:e,configuration:t,onValueChange:n});case rs.OBJECT:return o.jsx(Qee,{specification:e,configuration:t,onValueChange:n});case rs.DATE:return o.jsx(Yee,{specification:e,configuration:t,onValueChange:n});case rs.STRING:default:return o.jsx(Wee,{specification:e,configuration:t,onValueChange:n})}}function ete({specification:e,configuration:t,isEditingExisting:n,isSecretEditing:r,isSecret:s,onValueChange:l,onSecretEditToggle:c}){return o.jsxs(Gd,{children:[e.requiredType!==rs.BOOLEAN&&o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx(Ro,{htmlFor:e.name,required:e.required,tooltip:e.description,children:e.title??e.name}),s&&n&&o.jsx(Se,{variant:"ghost",size:"sm",type:"button",onClick:()=>{c(e.name,!r)},children:r?"Cancel":"Edit"})]}),TO({specification:e,configuration:t,onValueChange:l,flags:{isSecret:s,isEditingExisting:n,isSecretEditing:r}})]},e.name)}function tte({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,f]=p.useState(c);if(p.useEffect(()=>{f(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(zee,{label:e.title??e.name,options:e.oneOf.map(g=>({value:g.value,label:g.label})),value:d,onValueChange:f,children:e.oneOf.map(g=>o.jsx(Mee,{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(Ro,{htmlFor:v,required:x.required,tooltip:x.description,className:"mb-2 justify-start",children:v}),w&&r&&o.jsx(Se,{variant:"ghost",size:"sm",type:"button",onClick:()=>{l(e.name,!s)},children:s?"Cancel":"Edit"})]}),TO({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 qT(e,t,n,r,s,l){return e.map(c=>{const d=Array.isArray(c.attributes)?c.attributes.includes("SECRET"):!1,f=s[c.name];return c.oneOf&&c.requiredType===rs.OBJECT?o.jsx(tte,{specification:c,configuration:t,onValueChange:n,isEditingExisting:l,isSecretEditing:f,onSecretEditToggle:r},c.name):o.jsx(ete,{specification:c,configuration:t,isEditingExisting:l,isSecret:d,isSecretEditing:f,onValueChange:n,onSecretEditToggle:r},c.name)})}function ZT({collapsibleTitle:e,items:t,configuration:n,onValueChange:r,onSecretEditToggle:s,secretEditing:l,isEditingExisting:c}){return e?o.jsx(Vee,{title:e,children:qT(t,n,r,s,l,c)}):qT(t,n,r,s,l,c)}function nte({currentConnectorName:e,onCopyConfiguration:t,connectorSpecification:n}){const[r,s]=p.useState([]),[l,c]=p.useState(!1),[d,f]=p.useState(!1),m=p.useCallback(async()=>{c(!0);try{const x=await sn.getDataMartsByConnectorName(e);s(x)}catch{s([])}finally{c(!1)}},[e]);p.useEffect(()=>{d&&m()},[d,m]);const g=(x,b)=>{const w=b._id;if(!w){console.error("Configuration does not have _id field");return}t({dataMartId:x.id,dataMartTitle:x.title,configId:w,configuration:b}),f(!1)},v=x=>{const w=[],C=R=>{if(!n)return!0;const T=n.find(_=>_.name===R);return(T==null?void 0:T.required)??!1},E=(R,T,_=0,O=!0)=>{if(R.startsWith("_")||O&&_===0&&!C(R))return;let A=null;if(T==null)A="N/A";else if(typeof T=="string")A=T;else if(typeof T=="number"||typeof T=="boolean")A=String(T);else if(Array.isArray(T))A=JSON.stringify(T);else if(typeof T=="object"){w.push({key:R,value:"{",indent:_}),Object.entries(T).forEach(([D,j])=>{E(D,j,_+1,!1)}),w.push({key:"",value:"}",indent:_});return}else A=JSON.stringify(T);w.push({key:R,value:A,indent:_})};for(const[R,T]of Object.entries(x))E(R,T);return o.jsx("div",{className:"space-y-1 font-mono text-xs",children:w.map(({key:R,value:T,indent:_},O)=>o.jsxs("div",{className:"flex gap-2",style:{paddingLeft:`${String(_*12)}px`},children:[R&&o.jsxs("span",{className:"font-medium",children:[R,":"]}),o.jsx("span",{className:"text-muted-foreground truncate",title:T,children:T})]},O))})};return o.jsx(ls,{children:o.jsxs(Er,{open:d,onOpenChange:f,children:[o.jsx(Rr,{asChild:!0,children:o.jsxs(Se,{type:"button",variant:"ghost",size:"sm",className:"cursor-pointer",children:[o.jsx("span",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:"Auto-fill from…"}),o.jsx(Ta,{className:J("text-foreground/75 h-3.5 w-3.5 transition-transform duration-200",d&&"rotate-90")})]})}),o.jsx(Tr,{side:"bottom",align:"end",className:"w-72",children:l?o.jsx(yt,{disabled:!0,children:"Loading…"}):r.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 p-4 text-center",children:[o.jsx("div",{className:"bg-muted/70 rounded-full p-3",children:o.jsx(SL,{className:"text-muted-foreground h-6 w-6",strokeWidth:1.5})}),o.jsx("span",{className:"text-foreground text-sm font-medium",children:"No matching Data Marts"}),o.jsx("span",{className:"text-muted-foreground text-sm",children:"You can auto-fill settings only from connector-based Data Marts with the same source."})]}):o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx("div",{className:"text-muted-foreground border-b p-2 text-sm",children:"Select one of your existing Data Marts to auto-fill settings in this form"}),o.jsx("div",{children:r.map(x=>{const w=x.definition.connector.source.configuration;return w.length===0?null:w.length===1?o.jsxs(wt,{delayDuration:300,children:[o.jsx(Et,{asChild:!0,children:o.jsxs(yt,{onSelect:()=>{g(x,w[0])},children:[o.jsx(ep,{className:"text-foreground h-4 w-4"}),x.title]})}),o.jsx(Rt,{side:"right",className:"max-w-sm",children:v(w[0])})]},x.id):o.jsxs(Jb,{children:[o.jsxs(e1,{className:"flex items-center gap-2",children:[o.jsx(ep,{className:"text-foreground h-4 w-4"}),o.jsx("span",{children:x.title})]}),o.jsx(t1,{children:w.map((C,E)=>o.jsxs(wt,{delayDuration:300,children:[o.jsx(Et,{asChild:!0,children:o.jsxs(yt,{onSelect:()=>{g(x,C)},children:["Configuration ",E+1]})}),o.jsx(Rt,{side:"right",className:"max-w-sm",children:v(C)})]},E))})]},x.id)})})]})})]})})}function KT({connector:e,connectorSpecification:t,onConfigurationChange:n,onValidationChange:r,initialConfiguration:s,loading:l=!1,isEditingExisting:c=!1}){const[d,f]=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(j=>{const M=Array.isArray(j.attributes)?j.attributes.includes("SECRET"):!1;D[j.name]===void 0&&j.default!==void 0&&(D[j.name]=j.default),c&&M&&(D[j.name]=eb)}),f(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,f({...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,j)=>{f(M=>({...M,[D]:j}))},w=p.useCallback(D=>!(D==null||typeof D=="string"&&D.trim()===""||typeof D=="number"&&isNaN(D)||Array.isArray(D)&&D.length===0),[]),C=p.useCallback((D,j)=>{var U;if(typeof D!="object"||D===null)return w(D);const M=(U=j.oneOf)==null?void 0:U.filter(H=>H.value===Object.keys(D)[0]);return M?M.every(H=>Object.entries(H.items).every(([,q])=>H.value in D?C(D[H.value],q):!1)):w(D[j.name])},[w]),E=p.useCallback((D,j)=>{const M=j.filter(Y=>Y.required&&Y.oneOf),U=M.length===0?!0:M.some(Y=>C(D[Y.name],Y)),q=j.filter(Y=>Y.required&&Y.name!=="Fields").every(Y=>w(D[Y.name]));return U&&q},[w,C]),R=(D,j)=>{x(M=>({...M,[D]:j})),f(j?M=>({...M,[D]:""}):M=>({...M,[D]:eb}))},T=D=>{const j={...d};Object.entries(D.configuration).forEach(([M,U])=>{["_id","_copiedFrom"].includes(M)||(j[M]=U)}),j._copiedFrom={dataMartId:D.dataMartId,dataMartTitle:D.dataMartTitle,configId:D.configId},f(j)};if(p.useEffect(()=>{if(t&&r){const D=E(d,t);r(D)}},[d,t,r,E]),l)return o.jsx(pS,{variant:"list"});if(!t||t.length===0)return o.jsxs(jo,{children:[o.jsx(Tl,{connector:e}),o.jsx(ki,{icon:o.jsx(af,{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(au,{label:"Need configuration?"})]});const _=[...t].filter(D=>{var j;return D.name!=="Fields"&&!((j=D.attributes)!=null&&j.includes("HIDE_IN_CONFIG_FORM"))}).sort((D,j)=>{const M=U=>{const H=U.default!=null&&U.default!=="";return U.required&&!H?1:U.required&&H?2:!U.required&&!H?3:4};return M(D)-M(j)}),O=_.filter(D=>{var j;return!((j=D.attributes)!=null&&j.includes("ADVANCED"))}),A=_.filter(D=>{var j;return(j=D.attributes)==null?void 0:j.includes("ADVANCED")});return o.jsx(o.Fragment,{children:o.jsxs(jo,{children:[o.jsx(Tl,{connector:e}),o.jsxs(Rl,{children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("h3",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:"Configure Settings"}),o.jsx(nte,{currentConnectorName:e.name,onCopyConfiguration:T,connectorSpecification:t})]}),O.length>0&&o.jsx(ZT,{items:O,configuration:d,onValueChange:b,onSecretEditToggle:R,secretEditing:v,isEditingExisting:c}),A.length>0&&o.jsx(ZT,{collapsibleTitle:"Advanced Settings",items:A,configuration:d,onValueChange:b,onSecretEditToggle:R,secretEditing:v,isEditingExisting:c})]})]})})}function rte({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(pS,{variant:"list"}):!t||t.length===0?o.jsxs(jo,{children:[o.jsx(Tl,{connector:e}),o.jsx(ki,{icon:o.jsx(af,{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(au,{label:"Missing some data?"})]}):o.jsxs(jo,{children:[o.jsx(Tl,{connector:e}),o.jsxs(Rl,{title:c,children:[t.map(d=>o.jsx(RO,{type:"radio",id:d.name,name:"selectedField",value:d.name,label:d.overview??d.name,checked:n===d.name,onChange:f=>{l(f)},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(Ga,{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(Ta,{className:"h-3 w-3"})]})]}),selected:n===d.name},d.name)),o.jsx(au,{label:"Missing some data?"})]})]})}var Ns=(e=>(e.ASC="asc",e.DESC="desc",e.ORIGINAL="original",e))(Ns||{});function YT({connector:e,connectorFields:t,selectedField:n,selectedFields:r,onFieldToggle:s}){const l=p.useRef(null),[c,d]=p.useState(""),[f,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 A=x.includes(_.name),D=x.includes(O.name);if(A&&!D)return-1;if(!A&&D)return 1;if(f===Ns.ASC)return _.name.localeCompare(O.name);if(f===Ns.DESC)return O.name.localeCompare(_.name);const j=b.get(_.name)??0,M=b.get(O.name)??0;return j-M};return[...R].sort(T)},[v,c,x,f,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",A=document.activeElement.tagName;if(!(A==="INPUT"||A==="TEXTAREA")&&O){T.preventDefault();const D=v.map(U=>U.name),M=D.filter(U=>!r.includes(U)).length>0;D.forEach(U=>{s(U,M)})}};return window.addEventListener("keydown",R),()=>{window.removeEventListener("keydown",R)}},[v,r,s]),!n||!t?o.jsxs(jo,{children:[o.jsx(Tl,{connector:e}),o.jsx(ki,{icon:o.jsx(af,{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(au,{label:"Need fields?"})]}):v.length?o.jsx(jo,{children:o.jsxs(o.Fragment,{children:[o.jsx(Tl,{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(Vl,{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(iu,{className:"h-4 w-4"})})]}),o.jsxs(Er,{children:[o.jsx(Rr,{asChild:!0,children:o.jsxs(Se,{variant:"ghost",size:"icon","aria-label":"Sort fields",children:[f===Ns.ASC&&o.jsx(X2,{className:"text-muted-foreground h-4 w-4"}),f===Ns.DESC&&o.jsx(Q2,{className:"text-muted-foreground h-4 w-4"}),f===Ns.ORIGINAL&&o.jsx(J2,{className:"text-muted-foreground h-4 w-4"})]})}),o.jsxs(Tr,{align:"end",children:[o.jsxs(yt,{onSelect:()=>{m(Ns.ASC)},children:[o.jsx(X2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"A–Z"]}),o.jsxs(yt,{onSelect:()=>{m(Ns.DESC)},children:[o.jsx(Q2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Z–A"]}),o.jsxs(yt,{onSelect:()=>{m(Ns.ORIGINAL)},children:[o.jsx(J2,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Original"]})]})]})]}),o.jsxs(Rl,{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(RO,{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(u0,{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(u0,{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(au,{label:"Need another field?"})]})]})}):o.jsxs(jo,{children:[o.jsx(Tl,{connector:e}),o.jsx(ki,{icon:o.jsx(af,{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(au,{label:"Need fields?"})]})}const jO=p.createContext(void 0),_O={triggers:[],selectedTrigger:null,isLoading:!1,error:null};function ate(e,t){switch(t.type){case"FETCH_TRIGGERS_START":case"FETCH_TRIGGER_START":case"CREATE_TRIGGER_START":case"UPDATE_TRIGGER_START":case"DELETE_TRIGGER_START":return{...e,isLoading:!0,error:null};case"FETCH_TRIGGERS_SUCCESS":return{...e,triggers:t.payload,isLoading:!1};case"FETCH_TRIGGER_SUCCESS":return{...e,selectedTrigger:t.payload,isLoading:!1};case"CREATE_TRIGGER_SUCCESS":return{...e,triggers:[...e.triggers,t.payload],isLoading:!1};case"UPDATE_TRIGGER_SUCCESS":return{...e,triggers:e.triggers.map(n=>n.id===t.payload.id?t.payload:n),selectedTrigger:e.selectedTrigger&&e.selectedTrigger.id===t.payload.id?t.payload:e.selectedTrigger,isLoading:!1};case"DELETE_TRIGGER_SUCCESS":return{...e,triggers:e.triggers.filter(n=>n.id!==t.payload),selectedTrigger:e.selectedTrigger&&e.selectedTrigger.id===t.payload?null:e.selectedTrigger,isLoading:!1};case"FETCH_TRIGGERS_ERROR":case"FETCH_TRIGGER_ERROR":case"CREATE_TRIGGER_ERROR":case"UPDATE_TRIGGER_ERROR":case"DELETE_TRIGGER_ERROR":return{...e,isLoading:!1,error:t.payload};case"SELECT_TRIGGER":return{...e,selectedTrigger:t.payload};case"RESET":return _O;default:return e}}class ste extends ql{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 Fc=new ste;var Sn=(e=>(e.REPORT_RUN="REPORT_RUN",e.CONNECTOR_RUN="CONNECTOR_RUN",e))(Sn||{});const Wc={SCHEDULED_REPORT_RUN:"scheduled-report-run-config"};class tb{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!==Sn.REPORT_RUN)return t;const n=t.triggerConfig;if(!n.reportId)return t;try{const r=await bo.getReportById(n.reportId),s=yl(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:Sn.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 ote{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:Sn.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 Yx={getMapper(e){switch(e){case Sn.REPORT_RUN:return new tb;case Sn.CONNECTOR_RUN:return new ote;default:throw new Error(`Unknown scheduled trigger type: ${String(e)}`)}}},Ud={mapFromDto(e){return Yx.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 Sn.REPORT_RUN:return new tb().enhanceWithReportData(n);case Sn.CONNECTOR_RUN:{const r=t.definition;return{...n,triggerConfig:{...n.triggerConfig,connector:r}}}default:return n}},async mapFromDtoListWithReportData(e,t){const n=new tb,r=this.mapFromDtoList(e),s=r.filter(c=>c.type===Sn.REPORT_RUN),l=await n.enhanceTriggersWithReportData(s);return r.map(c=>{switch(c.type){case Sn.REPORT_RUN:return l.find(d=>d.id===c.id)??c;case Sn.CONNECTOR_RUN:{const d=t.definition;return{...c,triggerConfig:{...c.triggerConfig,connector:d}}}default:return c}})},mapToCreateRequest(e){return Yx.getMapper(e.type).mapToCreateRequest(e)},mapToUpdateRequest(e){return Yx.getMapper(e.type).mapToUpdateRequest(e)}};function ite({children:e}){const[t,n]=p.useReducer(ate,_O),{dataMart:r}=Gi(),{fetchAvailableConnectors:s}=Kl();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 Fc.getScheduledTriggers(b),C=await Ud.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}),Ue({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 Fc.getScheduledTriggers(b)).filter(T=>T.type===w),R=await Ud.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}),Ue({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 Fc.getScheduledTrigger(b,w),E=await Ud.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}),Ue({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"GetError",label:E})}},[r]),f=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 Fc.createScheduledTrigger(b,_),A=await Ud.mapFromDtoWithReportData(O,r);return n({type:"CREATE_TRIGGER_SUCCESS",payload:A}),Ue({event:"scheduled_trigger_created",category:"ScheduledTrigger",action:"Create",label:w}),on.success("Trigger created"),A}catch(_){const O=_ instanceof Error?_.message:"Failed to create scheduled trigger";throw n({type:"CREATE_TRIGGER_ERROR",payload:O}),Ue({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 Fc.updateScheduledTrigger(b,w,T),O=await Ud.mapFromDtoWithReportData(_,r);n({type:"UPDATE_TRIGGER_SUCCESS",payload:O}),Ue({event:"scheduled_trigger_updated",category:"ScheduledTrigger",action:"Update",label:O.type}),on.success("Trigger updated")}catch(T){const _=T instanceof Error?T.message:"Failed to update scheduled trigger";throw n({type:"UPDATE_TRIGGER_ERROR",payload:_}),Ue({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"UpdateError",label:_}),T}},[r]),g=p.useCallback(async(b,w)=>{n({type:"DELETE_TRIGGER_START"});try{await Fc.deleteScheduledTrigger(b,w),n({type:"DELETE_TRIGGER_SUCCESS",payload:w}),Ue({event:"scheduled_trigger_deleted",category:"ScheduledTrigger",action:"Delete",label:w}),on.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}),Ue({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(jO.Provider,{value:{...t,getScheduledTriggers:l,getScheduledTriggersByType:c,getScheduledTrigger:d,createScheduledTrigger:f,updateScheduledTrigger:m,deleteScheduledTrigger:g,selectScheduledTrigger:v,reset:x},children:e})}function NO(){const e=p.useContext(jO);if(e===void 0)throw new Error("useScheduledTriggerContext must be used within a ScheduledTriggerProvider");return e}function lte(e){const{getScheduledTriggers:t,getScheduledTriggersByType:n,getScheduledTrigger:r,createScheduledTrigger:s,updateScheduledTrigger:l,deleteScheduledTrigger:c,selectScheduledTrigger:d,reset:f,triggers:m,selectedTrigger:g,isLoading:v,error:x}=NO();return p.useEffect(()=>(e?t(e):f(),()=>{f()}),[e,t,f]),{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 cte=ln({type:qs(Wc.SCHEDULED_REPORT_RUN),reportId:cn().min(1,"Report ID is required")}),ute=_B(),dte=ln({type:f1(Sn),cronExpression:cn().min(1,"Cron expression is required"),timeZone:cn().min(1,"Time zone is required"),isActive:jB(),triggerConfig:AB([cte,ute])});function fte({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:r}){const s=qi({resolver:Xl(dte),defaultValues:{type:e?e.type:n??Sn.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:Wc.SCHEDULED_REPORT_RUN,reportId:t??""}}});p.useEffect(()=>{t&&s.getValues("type")===Sn.REPORT_RUN&&s.setValue("triggerConfig",{type:Wc.SCHEDULED_REPORT_RUN,reportId:t})},[t,s]),p.useEffect(()=>{n&&(s.setValue("type",n),n===Sn.REPORT_RUN?s.setValue("triggerConfig",{type:Wc.SCHEDULED_REPORT_RUN,reportId:t??""}):s.setValue("triggerConfig",null))},[n,t,s]);const l=d=>{s.setValue("type",d),d===Sn.REPORT_RUN?s.setValue("triggerConfig",{type:Wc.SCHEDULED_REPORT_RUN,reportId:t??""}):s.setValue("triggerConfig",null)},c=async d=>{try{await r(d)}catch(f){console.error("Error submitting form:",f)}};return{form:s,handleTypeChange:l,handleSubmit:s.handleSubmit(c),isDirty:s.formState.isDirty}}function hte({value:e,onChange:t,disabled:n}){const{reports:r,fetchReportsByDataMartId:s}=Zl(),{dataMart:l}=Gi();p.useEffect(()=>{l&&s(l.id)},[s,l]);const c=r.filter(d=>d.dataDestination.type===Lt.GOOGLE_SHEETS);return o.jsxs(Ca,{value:e,onValueChange:t,disabled:n,children:[o.jsx(Ea,{className:"w-full",children:o.jsx(wa,{placeholder:"Select a report"})}),o.jsx(Ra,{children:c.map(d=>o.jsx(Kn,{value:d.id,children:d.title},d.id))})]})}var zg="Switch",[mte]=kr(zg),[pte,gte]=mte(zg),AO=p.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:s,defaultChecked:l,required:c,disabled:d,value:f="on",onCheckedChange:m,form:g,...v}=e,[x,b]=p.useState(null),w=pt(t,_=>b(_)),C=p.useRef(!1),E=x?g||!!x.closest("form"):!0,[R,T]=zr({prop:s,defaultProp:l??!1,onChange:m,caller:zg});return o.jsxs(pte,{scope:n,checked:R,disabled:d,children:[o.jsx(We.button,{type:"button",role:"switch","aria-checked":R,"aria-required":c,"data-state":kO(R),"data-disabled":d?"":void 0,disabled:d,value:f,...v,ref:w,onClick:Re(e.onClick,_=>{T(O=>!O),E&&(C.current=_.isPropagationStopped(),C.current||_.stopPropagation())})}),E&&o.jsx(MO,{control:x,bubbles:!C.current,name:r,value:f,checked:R,required:c,disabled:d,form:g,style:{transform:"translateX(-100%)"}})]})});AO.displayName=zg;var DO="SwitchThumb",OO=p.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,s=gte(DO,n);return o.jsx(We.span,{"data-state":kO(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:t})});OO.displayName=DO;var vte="SwitchBubbleInput",MO=p.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...s},l)=>{const c=p.useRef(null),d=pt(c,l),f=q1(n),m=zb(t);return p.useEffect(()=>{const g=c.current;if(!g)return;const v=window.HTMLInputElement.prototype,b=Object.getOwnPropertyDescriptor(v,"checked").set;if(f!==n&&b){const w=new Event("click",{bubbles:r});b.call(g,n),g.dispatchEvent(w)}},[f,n,r]),o.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...s,tabIndex:-1,ref:d,style:{...s.style,...m,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});MO.displayName=vte;function kO(e){return e?"checked":"unchecked"}var yte=AO,xte=OO;function IO({className:e,...t}){return o.jsx(yte,{"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(xte,{"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 bte(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 nb(e,t="UTC"){const n=bte(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 f=Number.parseInt(r),m=Number.parseInt(s),g=!isNaN(f)&&!isNaN(m)?`${m.toString().padStart(2,"0")}:${f.toString().padStart(2,"0")}`:"09:00";if(!isNaN(f)&&!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(f)&&!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(f)&&!isNaN(m)&&l!=="*"&&c==="*"&&d==="*"){const v=l.split(",").map(x=>Number.parseInt(x.trim())).filter(x=>!isNaN(x)&&x>=1&&x<=31);if(v.length>0)return{type:"monthly",time:g,weekdays:[1,2,3,4,5],monthDays:v,customCron:e,intervalType:"minutes",intervalValue:15,timezone:t}}return{type:"custom",time:"09:00",weekdays:[1,2,3,4,5],monthDays:[1],customCron:e,intervalType:"minutes",intervalValue:15,timezone:t}}function LO({options:e,selected:t,onSelectionChange:n,placeholder:r="Select items...",searchPlaceholder:s="Search...",maxDisplayItems:l=3}){const[c,d]=p.useState(!1),f=v=>{const x=t.includes(v)?t.filter(b=>b!==v):[...t,v].sort((b,w)=>b-w);n(x)},m=(v,x)=>{x.preventDefault(),x.stopPropagation(),n(t.filter(b=>b!==v))},g=()=>{if(t.length===0)return o.jsx("span",{className:"text-muted-foreground text-sm",children:r});const v=t.map(x=>e.find(b=>b.value===x)).filter(Boolean);return v.length<=l?o.jsx("div",{className:"flex flex-wrap gap-1",children:v.map(x=>o.jsxs(Ar,{variant:"secondary",className:"h-5 text-xs",children:[x.label,o.jsx("span",{className:"hover:bg-secondary-foreground/20 ml-1 inline-flex cursor-pointer items-center justify-center rounded-full p-0.5",onClick:b=>m(x.value,b),children:o.jsx(iu,{className:"h-2 w-2"})})]},x.value))}):o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsxs(Ar,{variant:"secondary",className:"h-5 text-xs",children:[v[0].label,o.jsx("span",{className:"hover:bg-secondary-foreground/20 ml-1 inline-flex cursor-pointer items-center justify-center rounded-full p-0.5",onClick:x=>m(v[0].value,x),children:o.jsx(iu,{className:"h-2 w-2"})})]}),v.length>1&&o.jsxs(Ar,{variant:"outline",className:"h-5 text-xs",children:["+",v.length-1]})]})};return o.jsxs(X1,{open:c,onOpenChange:d,modal:!0,children:[o.jsx(J1,{asChild:!0,children:o.jsxs(Se,{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(wb,{className:"ml-2 h-3 w-3 shrink-0 opacity-50"})]})}),o.jsx(eS,{className:"max-h-[400px] w-full overflow-y-auto p-0",style:{padding:0},children:o.jsxs(kD,{className:"h-full overflow-visible",children:[o.jsx(ID,{placeholder:s,className:"h-8"}),o.jsxs(xJ,{className:"h-full max-h-[350px] overflow-y-auto",children:[o.jsx(LD,{children:"No items found."}),o.jsx(PD,{className:"h-full overflow-visible",children:e.map(v=>o.jsxs(UD,{value:v.value.toString(),onSelect:()=>f(v.value),className:"text-sm",children:[o.jsx(fr,{className:J("mr-2 h-3 w-3",t.includes(v.value)?"opacity-100":"opacity-0")}),v.label]},v.value))})]})]})})]})}const PO=[{value:1,label:"Monday"},{value:2,label:"Tuesday"},{value:3,label:"Wednesday"},{value:4,label:"Thursday"},{value:5,label:"Friday"},{value:6,label:"Saturday"},{value:0,label:"Sunday"}],km=()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}};function UO(e,t){if(!t)return"Schedule is disabled";const n=e.time;switch(e.type){case"daily":return`Daily at ${n}`;case"weekly":return`Weekly on ${e.weekdays.map(s=>{var l;return(l=PO.find(c=>c.value===s))==null?void 0:l.label}).join(", ")} at ${n}`;case"monthly":{const s=[...e.monthDays].sort((c,d)=>c-d).map(c=>c===1?"1st":c===2?"2nd":c===3?"3rd":`${String(c)}th`);return`Monthly on the ${s.length===1?s[0]:s.length===2?`${s[0]} and ${s[1]}`:`${s.slice(0,-1).join(", ")}, and ${s[s.length-1]}`} at ${n}`}case"interval":return e.intervalType==="minutes"?`Every ${String(e.intervalValue)} minute${e.intervalValue!==1?"s":""}`:`Every ${String(e.intervalValue)} hour${e.intervalValue!==1?"s":""}`;case"custom":return"Custom schedule";default:return""}}function Ste(e,t,n=!0){const r=nb(e,t);return UO(r,n)}const Cte=Array.from({length:31},(e,t)=>({value:t+1,label:`${String(t+1)}${t===0?"st":t===1?"nd":t===2?"rd":"th"}`})),rb=[5,10,15,30],ab=[1,2,3,4,6,8,12],wte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(Sa,{children:"Type"}),o.jsxs(Ca,{value:e,onValueChange:r=>{t(r)},disabled:n,children:[o.jsx(Ea,{className:"w-full",children:o.jsx(wa,{})}),o.jsxs(Ra,{children:[o.jsx(Kn,{value:"daily",children:"Daily"}),o.jsx(Kn,{value:"weekly",children:"Weekly"}),o.jsx(Kn,{value:"monthly",children:"Monthly"}),o.jsx(Kn,{value:"interval",children:"Interval"})]})]})]}),Ete=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(Sa,{children:"Time"}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx(Ht,{className:"w-24",type:"time",value:e,onChange:r=>{t(r.target.value)},disabled:n})})]}),WT=({value:e,onChange:t,disabled:n,timezones:r})=>o.jsxs("div",{className:"w-full space-y-2",children:[o.jsx(Sa,{children:"Timezone"}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx(tS,{options:r,value:e,onValueChange:t,placeholder:"Select timezone",emptyMessage:"No timezones found",disabled:n,className:"w-full"})})]}),Rte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(Sa,{children:"Days of Week"}),o.jsx("div",{className:n?"pointer-events-none":"",children:o.jsx(LO,{options:PO,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:3})})]}),Tte=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-2",children:[o.jsx(Sa,{children:"Days of Month"}),o.jsx("div",{className:n?"pointer-events-none":"",children:o.jsx(LO,{options:Cte,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:4})})]}),jte=({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(Sa,{children:"Type"}),o.jsxs(Ca,{value:e,onValueChange:l=>{n(l)},disabled:s,children:[o.jsx(Ea,{className:"w-full",children:o.jsx(wa,{})}),o.jsxs(Ra,{children:[o.jsx(Kn,{value:"minutes",children:"Minutes"}),o.jsx(Kn,{value:"hours",children:"Hours"})]})]})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Sa,{children:"Every"}),o.jsxs(Ca,{value:t.toString(),onValueChange:l=>{r(Number.parseInt(l)||1)},disabled:s,children:[o.jsx(Ea,{className:"w-full",children:o.jsx(wa,{})}),o.jsx(Ra,{children:(e==="minutes"?rb:ab).map(l=>o.jsxs(Kn,{value:l.toString(),children:[l," ",e==="minutes"?"min":"hr"]},l))})]})]})]}),_te=({value:e,onChange:t,disabled:n})=>o.jsxs("div",{className:"space-y-1",children:[o.jsx(Sa,{className:"text-sm",children:"Cron Expression"}),o.jsx(Ht,{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 Nte({cron:e="0 9 * * *",timezone:t,enabled:n=!0,onChange:r,className:s,showPreview:l=!0,showSaveButton:c=!1}){const[d,f]=p.useState(n),[m,g]=p.useState(t??km()),[v,x]=p.useState(!1),b=p.useMemo(()=>JG.getTimezonesWithOffset().map(G=>({value:G.identifier,label:G.displayName,offset:G.offsetString,isDST:G.isDST})),[]),[w,C]=p.useState(()=>nb(e,m)),[E,R]=p.useState(""),[T,_]=p.useState("");p.useEffect(()=>{f(n)},[n]),p.useEffect(()=>{const G=t??km();g(G)},[t]),p.useEffect(()=>{if(e){const G=nb(e,m);C(G)}},[e,m]);const O=G=>{const[$,I]=G.time.split(":").map(Number);switch(G.type){case"daily":return`${String(I)} ${String($)} * * *`;case"weekly":return`${String(I)} ${String($)} * * ${G.weekdays.join(",")}`;case"monthly":return`${String(I)} ${String($)} ${G.monthDays.join(",")} * *`;case"interval":return G.intervalType==="minutes"?`*/${String(G.intervalValue)} * * * *`:`0 */${String(G.intervalValue)} * * *`;case"custom":return G.customCron;default:return`${String(I)} ${String($)} * * *`}},A=p.useCallback(G=>{C($=>{if($.intervalType===G)return console.log("Type unchanged, skipping update"),$;const B=(G==="minutes"?rb:ab)[0];return{...$,intervalType:G,intervalValue:B}})},[]),D=p.useCallback(G=>{C($=>($.intervalType==="minutes"?rb:ab).includes(G)?{...$,intervalValue:G}:$)},[]),j=p.useMemo(()=>G=>UO(G,d),[d]);p.useEffect(()=>{const G=O(w);R(G),_(j(w))},[w,d,m,j]);const M=p.useRef(""),U=p.useRef(""),H=p.useRef(!1);p.useEffect(()=>{const G=O(w);r&&(M.current!==G||U.current!==m||H.current!==d)&&(r({cron:G,timezone:m,enabled:d}),M.current=G,U.current=m,H.current=d)},[w,m,d,r]);const q=G=>{f(G)},Y=G=>{g(G),C($=>({...$,timezone:G}))},ae=["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(Sa,{htmlFor:"schedule-enabled",className:"text-sm font-normal",children:d?"Enabled":"Disabled"}),o.jsx(IO,{id:"schedule-enabled",checked:d,onCheckedChange:q})]})]})}),o.jsxs("div",{className:"space-y-4 pt-0",children:[o.jsxs("div",{className:`space-y-4 ${d?"":"opacity-50"}`,children:[o.jsx(wte,{value:w.type,onChange:G=>{C($=>({...$,type:G}))},disabled:!d}),w.type!=="custom"&&w.type!=="interval"&&o.jsxs("div",{className:"flex gap-3",children:[o.jsx(Ete,{value:w.time,onChange:G=>{C($=>({...$,time:G}))},disabled:!d}),ae&&o.jsx(WT,{value:m,onChange:Y,disabled:!d,timezones:b})]}),(w.type==="interval"||w.type==="custom")&&o.jsx(WT,{value:m,onChange:Y,disabled:!d,timezones:b}),w.type==="weekly"&&o.jsx(Rte,{value:w.weekdays,onChange:G=>{C($=>({...$,weekdays:G}))},disabled:!d}),w.type==="monthly"&&o.jsx(Tte,{value:w.monthDays,onChange:G=>{C($=>({...$,monthDays:G}))},disabled:!d}),w.type==="interval"&&o.jsx(jte,{intervalType:w.intervalType,intervalValue:w.intervalValue,onTypeChange:A,onValueChange:D,disabled:!d}),w.type==="custom"&&o.jsx(_te,{value:w.customCron,onChange:G=>{C($=>({...$,customCron:G}))},disabled:!d})]}),l&&o.jsxs(o.Fragment,{children:[o.jsx(y_,{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(r_,{className:"h-4 w-4"}),o.jsx("span",{className:"text-sm font-medium",children:"Preview"})]}),v?o.jsx(Us,{className:"text-muted-foreground h-4 w-4"}):o.jsx(Ka,{className:"text-muted-foreground h-4 w-4"})]}),v&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"grid gap-4",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Status:"}),o.jsx(Ar,{variant:d?"default":"secondary",className:"text-xs",children:d?"Enabled":"Disabled"})]}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Cron:"}),o.jsx(Ar,{variant:"secondary",className:"font-mono text-xs",children:E})]}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Timezone:"}),o.jsx(Ar,{variant:"outline",className:"text-xs",children:m})]}),o.jsxs("div",{className:"flex items-start justify-between gap-2",children:[o.jsx("span",{className:"text-muted-foreground text-xs",children:"Schedule:"}),o.jsx("span",{className:"flex-1 text-right text-xs",children:T})]})]}),d&&ae&&m!==km()&&o.jsxs(fS,{className:"border-amber-200 bg-amber-50",children:[o.jsx(wf,{className:"h-4 w-4"}),o.jsx(mO,{children:"Time Zone"}),o.jsxs(hS,{children:["Schedule runs in ",m," (not your local ",km()," ","time). Execution time may differ from expected."]})]})]})]})]}),c&&o.jsx(Se,{className:"w-full",disabled:!d,children:"Save Schedule"})]})]})}function Ate(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"trigger-type-options-description-details",children:[o.jsx(Qn,{children:"How do I choose a type?"}),o.jsxs(Xn,{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 Dte(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"trigger-type-change-description-details",children:[o.jsx(Qn,{children:"How do I change the trigger type?"}),o.jsx(Xn,{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 Ote(){return o.jsx(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"report-change-description-details",children:[o.jsx(Qn,{children:"How do I change a report?"}),o.jsx(Xn,{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(mr,{variant:"common",type:"single",collapsible:!0,children:o.jsxs(Wn,{value:"report-select-description-details",children:[o.jsx(Qn,{children:"How do I choose the report?"}),o.jsxs(Xn,{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 kte({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:r,onCancel:s,onDirtyChange:l}){const[c,d]=p.useState(!1),{form:f,handleTypeChange:m,handleSubmit:g,isDirty:v}=fte({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}=f,C=b("type")===Sn.REPORT_RUN;return o.jsx(Yl,{...f,children:o.jsxs(Zi,{onSubmit:E=>void g(E),noValidate:!1,children:[o.jsxs(Wl,{children:[o.jsx(Jt,{control:x,name:"type",render:({field:E})=>o.jsxs(en,{children:[o.jsx(tn,{tooltip:"Choose what you want this trigger to run - a report or a connector",children:"Trigger Type"}),o.jsxs(Ca,{onValueChange:R=>{E.onChange(R),m(R)},defaultValue:E.value,disabled:!!n||!!e||!!b("triggerConfig.reportId"),children:[o.jsx(nn,{children:o.jsx(Ea,{className:"w-full",children:o.jsx(wa,{placeholder:"Select trigger type"})})}),o.jsxs(Ra,{children:[o.jsx(Kn,{value:Sn.REPORT_RUN,children:"Report Run"}),o.jsx(Kn,{value:Sn.CONNECTOR_RUN,children:"Connector Run"})]})]}),o.jsx(or,{children:e?o.jsx(Dte,{}):o.jsx(Ate,{})}),o.jsx(un,{})]})}),C&&o.jsx(Jt,{control:x,name:"triggerConfig.reportId",render:({field:E})=>o.jsxs(en,{children:[o.jsx(tn,{tooltip:"Select the report that will be run by this trigger",children:"Report"}),o.jsx(nn,{children:o.jsx(D4,{children:o.jsx(hte,{value:E.value,onChange:E.onChange,disabled:!!t||!!e})})}),o.jsx(or,{children:e!=null&&e.triggerConfig?o.jsx(Ote,{}):o.jsx(Mte,{})}),o.jsx(un,{})]})}),o.jsx(Nte,{showPreview:!1,cron:b("cronExpression"),timezone:b("timeZone"),enabled:b("isActive"),onChange:E=>{f.setValue("cronExpression",E.cron,{shouldDirty:!0}),f.setValue("timeZone",E.timezone,{shouldDirty:!0}),f.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(Ql,{children:[o.jsx(Se,{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(Se,{variant:"outline",type:"button",onClick:s,className:"w-full","aria-label":"Cancel",children:"Cancel"})]})]})})}function Ite({cronExpression:e,timeZone:t,isEnabled:n=!0}){const r=p.useMemo(()=>Ste(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 Lte({table:e}){return o.jsx("div",{className:"text-right",children:o.jsxs(Er,{children:[o.jsx(Rr,{asChild:!0,children:o.jsx(Se,{variant:"ghost",className:"dm-card-table-body-row-actionbtn","aria-label":"Toggle columns",children:o.jsx(Ya,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsx(Tr,{align:"end",children:e.getAllColumns().filter(t=>t.getCanHide()&&t.id!=="actions").map(t=>o.jsx(yt,{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(fr,{className:"size-3.5 text-white"})})}),o.jsx("span",{children:t.columnDef.meta.title??t.id})]})},t.id))})]})})}function Pte({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:f=>{f.stopPropagation()},children:[o.jsxs(Er,{open:r,onOpenChange:s,children:[o.jsx(Rr,{asChild:!0,children:o.jsx(Se,{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(Ya,{className:"dm-card-table-body-row-actionbtn-icon"})})}),o.jsxs(Tr,{align:"end",children:[o.jsxs(yt,{onClick:()=>{t(e.id)},children:[o.jsx(Ef,{className:"text-foreground h-4 w-4","aria-hidden":"true"}),"Edit trigger"]}),o.jsx(qa,{}),o.jsxs(yt,{onClick:()=>{c(!0)},children:[o.jsx(Lo,{className:"h-4 w-4 text-red-600","aria-hidden":"true"}),o.jsx("span",{className:"text-red-600",children:"Delete trigger"})]})]})]}),o.jsx(ba,{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 Ute(e,t){const n=t.find(r=>r.name===e.source.name);return(n==null?void 0:n.displayName)??e.source.name}function Fte({connector:e}){const{connectors:t}=Kl(),n=Ute(e,t);return o.jsx(o.Fragment,{children:n})}function FO({connector:e}){return o.jsx(Fte,{connector:e})}function zte(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 Vte=e=>{const{connectors:t}=Kl();return p.useMemo(()=>t.find(n=>n.name===e),[t,e])},Hte=_e.memo(function({connector:t,children:n}){const r=Vte(t.source.name),{dataMart:s,runs:l,getDataMartRuns:c}=Gi();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(Vf,{base64:r.logoBase64,size:20}):null,[r==null?void 0:r.logoBase64]),f=p.useCallback(()=>{s!=null&&s.storage&&Aq(s.storage,t.storage.fullyQualifiedName)},[s==null?void 0:s.storage,t.storage.fullyQualifiedName]),m=p.useMemo(()=>zte(l),[l]),g=p.useMemo(()=>!m.lastRunDate||!m.lastRunStatus?null:{statusType:qZ(m.lastRunStatus),statusText:KZ(m.lastRunStatus),date:m.lastRunDate},[m]),v=p.useMemo(()=>(s==null?void 0:s.storage)&&Dq(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(x1,{children:[o.jsx(b1,{asChild:!0,children:o.jsx("span",{children:n})}),o.jsxs(S1,{children:[o.jsxs(C1,{children:[o.jsx(w1,{children:d}),o.jsxs(E1,{children:[o.jsx(R1,{children:o.jsx(FO,{connector:t})}),o.jsx(T1,{children:x})]})]}),o.jsxs(j1,{children:[o.jsxs(bi,{children:[o.jsx(Si,{children:"Last run status:"}),o.jsx(Ci,{children:g?o.jsx($f,{type:g.statusType,variant:"ghost",children:g.statusText}):"Not run yet"})]}),o.jsxs(bi,{children:[o.jsx(Si,{children:"Last run date:"}),o.jsx(Ci,{children:g?o.jsx(Ll,{date:g.date}):"Never run"})]}),o.jsxs(bi,{children:[o.jsx(Si,{children:"Total runs:"}),o.jsxs(Ci,{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(_1,{children:o.jsxs(Se,{className:"w-full",variant:"default",onClick:f,title:"Open Storage","aria-label":"Open Storage",children:[v,o.jsx(_l,{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 $te(e){const t=e.triggerConfig;return o.jsxs("div",{className:"inline gap-1",children:[t.report.title,o.jsx(BZ,{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 Bte(e){const t=e.triggerConfig,{connector:n}=t.connector;return o.jsxs("div",{className:"inline gap-1",children:[o.jsx(FO,{connector:n}),o.jsx(Hte,{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 Gte({trigger:e}){switch(e.type){case Sn.REPORT_RUN:return $te(e);case Sn.CONNECTOR_RUN:return Bte(e);default:return o.jsx("div",{className:"text-muted-foreground text-sm",children:"—"})}}function qte({onEditTrigger:e,onDeleteTrigger:t}){return[{accessorKey:"type",size:150,header:"Trigger Type",cell:({row:n})=>{const s=n.getValue("type")===Sn.REPORT_RUN?"Report Run":"Connector Run";return o.jsx(Ar,{variant:"outline",children:s})},meta:{title:"Trigger Type"}},{accessorKey:"triggerConfig",size:35,header:"Run Target",cell:({row:n})=>o.jsx(Gte,{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(Ite,{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(Ll,{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(Ll,{date:new Date(r)}):o.jsx("span",{className:"text-muted-foreground text-sm",children:"Never run"})})},meta:{title:"Last Run"}},{accessorKey:"isActive",size:15,header:"Trigger Status",cell:({row:n})=>{const r=n.getValue("isActive");return o.jsx($f,{type:r?Nn.SUCCESS:Nn.NEUTRAL,variant:"ghost",showIcon:!1,children:r?"Enabled":"Disabled"})},meta:{title:"Trigger Status"}},{id:"actions",size:80,header:({table:n})=>o.jsx(Lte,{table:n}),cell:({row:n})=>o.jsx(Pte,{trigger:n.original,onEditTrigger:e,onDeleteTrigger:t}),meta:{title:"Actions"}}]}function Zte({table:e,onPreviousClick:t,onNextClick:n}){return o.jsxs("div",{className:"dm-card-pagination",role:"navigation","aria-label":"Table pagination",children:[o.jsx(Se,{variant:"outline",size:"sm",onClick:t,disabled:!e.getCanPreviousPage(),"aria-label":"Go to previous page",children:"Previous"}),o.jsx(Se,{variant:"outline",size:"sm",onClick:n,disabled:!e.getCanNextPage(),"aria-label":"Go to next page",children:"Next"})]})}function gS({isOpen:e,onClose:t,dataMartId:n,preSelectedReportId:r,preSelectedType:s}){const{createScheduledTrigger:l,updateScheduledTrigger:c,selectedTrigger:d}=NO(),[f,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===Sn.REPORT_RUN?{type:Wc.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",A=(d==null?void 0:d.type)??s;e&&!_.current?(Ue({event:"scheduled_trigger_config_open",category:"ScheduledTrigger",action:O,label:A}),_.current=!0):!e&&_.current&&(Ue({event:"scheduled_trigger_config_close",category:"ScheduledTrigger",action:O,label:A}),_.current=!1)},[e,E,d,s]),o.jsxs(o.Fragment,{children:[o.jsx(Li,{open:e,onOpenChange:O=>{O||x()},children:o.jsxs(Pi,{children:[o.jsxs(Ui,{children:[o.jsxs(Fi,{children:[E?"Edit":"Create"," Scheduled Trigger"]}),o.jsx(Bl,{children:"Configure automatic runs for your reports or connectors."})]}),o.jsx(kte,{preSelectedReportId:r,preSelectedType:s,initialData:R,onSubmit:T,onCancel:x,onDirtyChange:w})]})}),o.jsx(ba,{open:f,onOpenChange:m,title:"Unsaved Changes",description:"You have unsaved changes. Exit without saving?",confirmLabel:"Yes, leave now",cancelLabel:"No, stay here",onConfirm:b,variant:"destructive"})]})}function Kte({triggers:e,dataMartId:t,onEditTrigger:n,onDeleteTrigger:r}){const[s,l]=p.useState(!1),c=p.useCallback(()=>{l(!1)},[]),d=p.useCallback(R=>{r(R)},[r]),f=p.useMemo(()=>qte({onEditTrigger:n,onDeleteTrigger:d}),[n,d]),{sorting:m,setSorting:g,columnVisibility:v,setColumnVisibility:x}=qf({columns:f,storageKeyPrefix:"data-mart-scheduled-triggers",defaultSortingColumn:"type"}),b=_u({data:e,columns:f,getCoreRowModel:ju(),getPaginationRowModel:Tg(),onSortingChange:g,getSortedRowModel:Gf(),getFilteredRowModel:Bf(),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(Nu,{id:"scheduled-triggers-table",className:"dm-card-table",role:"table","aria-label":"Scheduled Triggers",children:[o.jsx(Au,{className:"dm-card-table-header",children:b.getHeaderGroups().map(R=>o.jsx(ir,{className:"dm-card-table-header-row",children:R.headers.map(T=>o.jsx(Ou,{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(Du,{className:"dm-card-table-body",children:b.getRowModel().rows.length?b.getRowModel().rows.map((R,T)=>o.jsx(ir,{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(xa,{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(ir,{children:o.jsx(xa,{colSpan:f.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(Zte,{table:b,onPreviousClick:w,onNextClick:C}),o.jsx(gS,{isOpen:s,onClose:c,dataMartId:t})]})}function Yte({dataMartId:e}){const{triggers:t,deleteScheduledTrigger:n,selectScheduledTrigger:r,selectedTrigger:s}=lte(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)},f=()=>{c(!1),r(null)},m=async g=>{try{await n(e,g)}catch(v){console.error("Error deleting trigger:",v)}};return o.jsxs(o.Fragment,{children:[o.jsx(Kte,{triggers:t,dataMartId:e,onEditTrigger:d,onDeleteTrigger:g=>void m(g)}),o.jsx(gS,{isOpen:l,onClose:f,dataMartId:e})]})}function zO(){return o.jsx("div",{className:"dm-card-block !gap-1.5 !py-3",children:o.jsxs("div",{className:"text-foreground flex items-start gap-1.5 text-sm",children:[o.jsx(s_,{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 Wte({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,f]=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,A,D)=>{s({fullyQualifiedName:`${_}.${O}`,isValid:!!(_&&O&&A===null&&D===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 A=C(_),D=C(O);f(_),g(O),x(A),w(D);const j=`${_}.${O}`,M=!!(_&&O&&A===null&&D===null);((t==null?void 0:t.fullyQualifiedName)!==j||t.isValid!==M)&&E(_,O,A,D)},[t,l,c,E]);const R=_=>{f(_);const O=C(_);x(O),E(_,m,O,b)},T=_=>{g(_);const O=C(_);w(O),E(d,_,v,O)};return o.jsxs(jo,{children:[e===Ie.GOOGLE_BIGQUERY&&o.jsxs(o.Fragment,{children:[o.jsx(ki,{icon:o.jsx(KA,{}),title:"Google BigQuery",docUrl:"https://docs.owox.com/docs/storages/supported-storages/google-bigquery/",variant:"compact"}),o.jsxs(Rl,{title:"Choose where to store your data",children:[o.jsxs(Gd,{children:[o.jsx(Ro,{required:!0,htmlFor:"dataset-name",tooltip:"Enter dataset name for Google BigQuery where the connector data will be stored.",children:"Dataset name"}),o.jsx(Ht,{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(Gd,{children:[o.jsx(Ro,{required:!0,htmlFor:"table-name",tooltip:"Enter table name where the connector data will be stored.",children:"Table name"}),o.jsx(Ht,{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===Ie.AWS_ATHENA&&o.jsxs(o.Fragment,{children:[o.jsx(ki,{icon:o.jsx(YA,{}),title:"AWS Athena",docUrl:"https://docs.owox.com/docs/storages/supported-storages/aws-athena/",variant:"compact"}),o.jsxs(Rl,{title:"Choose where to store your data",children:[o.jsxs(Gd,{children:[o.jsx(Ro,{required:!0,htmlFor:"database-name",tooltip:"Enter database name for Amazon Athena where the connector data will be stored.",children:"Database name"}),o.jsx(Ht,{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(Gd,{children:[o.jsx(Ro,{required:!0,htmlFor:"athena-table-name",tooltip:"Enter table name where the connector data will be stored.",children:"Table name"}),o.jsx(Ht,{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(Rl,{title:"Schedule updates",children:o.jsx(zO,{})})]})}function Qte({onSubmit:e,dataStorageType:t,configurationOnly:n=!1,existingConnector:r=null,mode:s="full",initialStep:l,preselectedConnector:c}){const[d,f]=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),[A,D]=p.useState(new Set),{connectors:j,connectorSpecification:M,connectorFields:U,loading:H,loadingSpecification:q,loadingFields:Y,error:ae,fetchAvailableConnectors:G,fetchConnectorSpecification:$,fetchConnectorFields:I}=Kl(),[B,K]=p.useState(null),xe=(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 Me=>{!_.has(Me)&&!q&&(O(_t=>new Set(_t).add(Me)),await $(Me))},[_,q,$]),P=p.useCallback(async Me=>{A.has(Me)||(D(_t=>new Set(_t).add(Me)),await I(Me))},[A,I]);p.useEffect(()=>{if(!c||d||j.length===0)return;const Me=j.find(_t=>_t.name===c);Me&&(f(Me),w(l??2),L(Me.name),!n&&s!=="fields-only"&&P(Me.name))},[c,j,d,l,n,s,L,P]),p.useEffect(()=>{if(j.length===0&&!H&&G(),r&&j.length>0&&!d){const{source:Me,storage:_t}=r;g(Me.node),x(Me.fields),E(Me.configuration[0]||{}),K({fullyQualifiedName:_t.fullyQualifiedName,isValid:!0});const Nt=j.find(rn=>rn.name===Me.name);Nt&&(f(Nt),L(Nt.name),!n&&s!=="fields-only"&&P(Nt.name),s==="fields-only"&&P(Nt.name))}if(n&&j.length>0&&!d&&!r){const Me=j[0];f(Me),L(Me.name)}},[s,r,j,n,H,G,L,P,d]);const W=Me=>{f(Me),E({}),T(!1),O(_t=>{const Nt=new Set(_t);return Nt.delete(Me.name),Nt}),L(Me.name),P(Me.name)},ee=Me=>{g(Me),x([])},de=(Me,_t)=>{x(_t?Nt=>Nt.includes(Me)?Nt:[...Nt,Me]:Nt=>Nt.filter(rn=>rn!==Me))},ve=(Me,_t)=>{x(_t?Nt=>{const rn=Me.filter(V=>!Nt.includes(V));return[...Nt,...rn]}:Nt=>Nt.filter(rn=>!Me.includes(rn)))},ie=Me=>{K(Me)},Ne=p.useCallback(Me=>{E(Me)},[]),we=p.useCallback(Me=>{T(Me)},[]);p.useEffect(()=>{M&&(M.some(_t=>_t.required&&_t.name!=="Fields")||T(!0))},[M]);const Te=()=>{b<xe&&w(b+1)},$e=()=>{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 B!==null&&B.fullyQualifiedName!==""&&B.isValid;default:return!1}},Vt=()=>b>1,jt=(Me,_t)=>{if(!Me)return _t;const Nt=Me.find(rn=>rn.name===_t);return(Nt==null?void 0:Nt.destinationName)??_t},$t=()=>{if(n&&b===1)return M&&d?o.jsx(KT,{connector:d,connectorSpecification:M,onConfigurationChange:Ne,onValidationChange:we,initialConfiguration:C,loading:q,isEditingExisting:!!(r!=null&&r.source.configuration.length)}):null;if(s==="fields-only")switch(b){case 1:return d&&m&&U?o.jsx(YT,{connector:d,connectorFields:U,selectedField:m,selectedFields:v,onFieldToggle:de,onSelectAllFields:ve}):null;default:return null}switch(b){case 1:return o.jsx(Bee,{connectors:j,selectedConnector:d,loading:H,error:ae,onConnectorSelect:W,onConnectorDoubleClick:()=>{w(Me=>Me<xe?Me+1:Me)}});case 2:return d&&M?o.jsx(KT,{connector:d,connectorSpecification:M,onConfigurationChange:Ne,onValidationChange:we,initialConfiguration:C,loading:q,isEditingExisting:!1}):null;case 3:return d&&U?o.jsx(rte,{connectorFields:U,connector:d,selectedField:m,connectorName:d.displayName,loading:Y,onFieldSelect:ee}):null;case 4:return d&&m&&U?o.jsx(YT,{connector:d,connectorFields:U,selectedField:m,selectedFields:v,onFieldToggle:de,onSelectAllFields:ve}):null;case 5:return m&&U?o.jsx(Wte,{dataStorageType:t,destinationName:jt(U,m),connectorName:(d==null?void 0:d.displayName)??"",target:B,onTargetChange:ie}):null;default:return null}};return o.jsxs(Pee,{children:[o.jsx(Uee,{children:$t()}),o.jsx(Fee,{variant:"horizontal",children:o.jsx(Gee,{currentStep:b,totalSteps:xe,canGoNext:Xe(),canGoBack:Vt(),isLoading:q||Y,onNext:Te,onBack:$e,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&&B&&e({source:{name:d.name,configuration:[C],node:m,fields:v},storage:{fullyQualifiedName:B.fullyQualifiedName}})}})})]})}const VO=20,HO=20;function $O({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 Xte(e=30,t=0){$O({vertical:HO+e,horizontal:VO+t})}function sb(){$O({vertical:HO,horizontal:VO})}function BO({isOpen:e,onClose:t,dataStorageType:n,onSubmit:r,configurationOnly:s=!1,existingConnector:l=null,mode:c="full",initialStep:d,preselectedConnector:f}){return p.useEffect(()=>(e?Xte(55):sb(),()=>{sb()}),[e]),o.jsx(Li,{open:e,onOpenChange:t,children:o.jsxs(Pi,{children:[o.jsxs(Ui,{children:[o.jsx(Fi,{children:c==="fields-only"?"Connector Fields":l!=null&&l.source.name?"Edit Connector":"Set Up Connector"}),o.jsx(Bl,{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(Qte,{onSubmit:m=>{r(m),t()},dataStorageType:n,configurationOnly:s||c==="configuration-only",existingConnector:l,mode:c,initialStep:d,preselectedConnector:f})]})})}const vS=({dataStorageType:e,onSubmit:t,children:n,configurationOnly:r=!1,existingConnector:s=null,preset:l,isOpen:c,onClose:d})=>{const[f,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(pu,{children:o.jsx(BO,{isOpen:f,onClose:C,dataStorageType:e,onSubmit:t,configurationOnly:r,existingConnector:s,initialStep:g,preselectedConnector:x})})]})};function Jte({storageType:e,onSetupConnector:t,preset:n,isOpen:r,onClose:s}){return o.jsx(vS,{dataStorageType:e,onSubmit:t,configurationOnly:!1,preset:n,isOpen:r,onClose:s,children:o.jsxs(Se,{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(Tb,{className:"h-4 w-4",strokeWidth:2.25})}),o.jsx("span",{children:"Setup Connector"}),o.jsx(Ta,{className:"h-6 w-6"})]})})}const ene=e=>{switch(e){case Ie.GOOGLE_BIGQUERY:return"Google BigQuery";case Ie.AWS_ATHENA:return"AWS Athena";default:return e}},Zc=e=>typeof e=="object"&&"connector"in e,Fd=e=>{if(!Zc(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 tne({configIndex:e,connectorDef:t,onRemoveConfiguration:n,onUpdateConfiguration:r,dataMartStatus:s,totalConfigurations:l,dataStorage:c}){const d=Bi.getInfo(c.type),{connectors:f,fetchAvailableConnectors:m}=Kl();p.useEffect(()=>{m()},[m]);const g=C=>{const E=f.find(R=>R.name===C);if(E!=null&&E.logoBase64)return()=>o.jsx(Vf,{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(wt,{children:[o.jsx(Et,{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(Ta,{className:"h-3 w-3"})]})}),o.jsx(Rt,{children:"Edit connector configuration"})]})]})},x=(C,E,R)=>o.jsxs("span",{children:[o.jsxs("span",{className:"text-muted-foreground/75",children:[C,":"]})," ",o.jsx(hr,{href:R,onClick:T=>{T.stopPropagation()},children:E})]}),b=()=>{switch(c.type){case Ie.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(wt,{children:[o.jsx(Et,{asChild:!0,children:o.jsx(Fr,{className:"h-4 w-4"})}),o.jsx(Rt,{children:"The dataset and table are automatically created during the first run of the data mart, if they don't already exist"})]})]})}case Ie.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(wt,{children:[o.jsx(Et,{asChild:!0,children:o.jsx(Fr,{className:"h-4 w-4"})}),o.jsx(Rt,{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===dr.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(vS,{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(Y0,{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(Y0,{title:ene(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(wt,{children:[o.jsx(Et,{asChild:!0,children:o.jsx(Se,{type:"button",variant:"ghost",onClick:()=>{w()&&n(e)},disabled:!w(),children:o.jsx(Lo,{className:"h-4 w-4"})})}),!w()&&o.jsx(Rt,{children:"Cannot remove the last configuration in published pipeline"})]})})]})}function nne({storageType:e,onAddConfiguration:t,existingConnector:n}){return o.jsx("div",{children:o.jsx(vS,{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(Se,{type:"button",variant:"outline",className:"dm-card-table-add-field-btn cursor-pointer",children:[o.jsx(ja,{className:"h-4 w-4"}),o.jsx("span",{children:"Configuration"})]})})})}function rne({control:e,storageType:t,preset:n,autoOpen:r=!1}){const{dataMart:s,runDataMart:l}=gs(),{setValue:c,getValues:d,trigger:f}=Mu(),[m,g]=p.useState(!1),[v,x]=p.useState(!1);p.useEffect(()=>{r&&x(!0)},[r]);const b=()=>{setTimeout(()=>void f("definition"),0)},w=(s==null?void 0:s.status)??dr.DRAFT,C=j=>{const M=j.source,U=j.storage;c("definition",{connector:{source:M,storage:U}},{shouldDirty:!0,shouldTouch:!0}),b()},E=async j=>{if(s){if(s.status.code!==dr.PUBLISHED){Ot.error("Manual run is only available for published data marts");return}await l({id:s.id,payload:j})}},R=j=>M=>{const H=d().definition;if(typeof H=="object"&&Zc(H)){const q=[...H.connector.source.configuration];q[j]=M.source.configuration[0]||{};const Y={connector:{...H.connector,source:{...H.connector.source,configuration:q}}};c("definition",Y,{shouldDirty:!0,shouldTouch:!0}),b()}},T=j=>{const U=d().definition;if(typeof U=="object"&&Zc(U)){const H={connector:{...U.connector,source:{...U.connector.source,fields:j.source.fields}}};c("definition",H,{shouldDirty:!0,shouldTouch:!0}),b()}g(!1)},_=j=>{E({runType:j.runType,data:j.data})},O=j=>{const M=j.connector.source.fields.length;return o.jsxs(Se,{type:"button",variant:"outline",onClick:()=>{g(!0)},className:"dm-card-table-add-field-btn cursor-pointer",children:[o.jsx(wL,{className:"h-4 w-4"}),o.jsxs("span",{children:["Edit Fields (",String(M),")"]})]})},A=j=>{const U=d().definition;if(Zc(U)&&U.connector.source.configuration.length<=1){const H=J0(Ke.CONNECTOR);c("definition",H,{shouldDirty:!0,shouldTouch:!0}),b()}if(typeof U=="object"&&Zc(U)&&U.connector.source.configuration.length>1){const H={...U.connector.source,configuration:U.connector.source.configuration.filter((Y,ae)=>ae!==j)},q={connector:{...U.connector,source:H}};c("definition",q,{shouldDirty:!0,shouldTouch:!0}),b()}},D=j=>{const U=d().definition;if(Zc(U)){const H={...U.connector.source,configuration:[...U.connector.source.configuration,j]},q={connector:{...U.connector,source:H}};c("definition",q,{shouldDirty:!0,shouldTouch:!0}),b()}};return o.jsxs(o.Fragment,{children:[o.jsx(Jt,{control:e,name:"definition",render:({field:j})=>o.jsxs(en,{className:"dark:bg-white/2",children:[o.jsx(nn,{children:o.jsx("div",{className:"space-y-3",children:!Fd(j.value)||w===dr.DRAFT?o.jsx(Jte,{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(nne,{storageType:t,onAddConfiguration:D,existingConnector:Fd(j.value)?{source:j.value.connector.source,storage:j.value.connector.storage}:void 0}),Fd(j.value)&&O(j.value)]}),o.jsx("div",{className:"flex items-center gap-2",children:s&&s.definitionType===Ke.CONNECTOR&&o.jsx(vD,{configuration:s.definition,onManualRun:_,children:o.jsxs(Se,{variant:"outline",children:[o.jsx(Rb,{className:"h-4 w-4"}),o.jsx("span",{children:"Manual Run..."})]})})})]}),o.jsx("div",{className:"space-y-3",children:Fd(j.value)&&(s!=null&&s.storage)?j.value.connector.source.configuration.map((M,U)=>{const H=j.value;return o.jsx(pu,{children:o.jsx(tne,{configIndex:U,connectorDef:H,dataStorage:s.storage,onRemoveConfiguration:A,onUpdateConfiguration:R,dataMartStatus:typeof w=="object"?w.code:w,totalConfigurations:H.connector.source.configuration.length},U)},U)}):null})]})})}),o.jsx(un,{})]})}),o.jsx(pu,{children:o.jsx(BO,{isOpen:m,onClose:()=>{g(!1)},onSubmit:T,dataStorageType:t,existingConnector:Fd(d().definition)?{source:d().definition.connector.source,storage:d().definition.connector.storage}:void 0,mode:"fields-only"})})]})}function ane({definitionType:e,storageType:t,preset:n}){const{control:r}=Mu(),[s,l]=p.useState(!1);return p.useEffect(()=>{e===Ke.CONNECTOR&&!n?l(!0):l(!1)},[e,n]),o.jsxs("div",{className:"space-y-2",children:[e===Ke.SQL&&o.jsx(xee,{control:r}),e===Ke.TABLE&&o.jsx(bee,{control:r,storageType:t}),e===Ke.VIEW&&o.jsx(See,{control:r,storageType:t}),e===Ke.TABLE_PATTERN&&o.jsx(Cee,{control:r,storageType:t}),e===Ke.CONNECTOR&&o.jsx(rne,{control:r,storageType:t,preset:n,autoOpen:s})]})}function GO(){const[e]=NI(),t=e.get("preset");return p.useMemo(()=>{if(!t)return;const n=t.toLowerCase();return bY(n)},[t])}function sne(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 one(e,t){const[n,r]=p.useState(e);return p.useEffect(()=>{const s=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(s)}},[e,t]),n}const ine=1e3,lne=[El.SUCCESS,El.ERROR,El.CANCELLED];function cne(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)},[]),f=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 sn.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 sn.getSqlDryRunTriggerStatus(e,v);if(lne.includes(b)){const w=await sn.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,ine))}catch(b){d(b),l.current={triggerId:null,abortController:null};return}},[e,c,d]),g=p.useCallback(async v=>{await f(),n(!0),s(null);try{const{triggerId:x}=await sn.createSqlDryRunTrigger(e,v),b=new AbortController;l.current={triggerId:x,abortController:b},await m(x,b.signal)}catch(x){d(x)}},[e,f,m,d]);return p.useEffect(()=>()=>{const{triggerId:v,abortController:x}=l.current;x==null||x.abort(),v&&sn.abortSqlDryRunTrigger(e,v).catch(()=>{})},[e]),{validateSql:g,isLoading:t,result:r,cancel:f}}const une=300;function dne({sql:e,dataMartId:t,debounceDelay:n=une,className:r="",onValidationStateChange:s}){const l=one(e.trim(),n),{validateSql:c,isLoading:d,result:f,cancel:m}=cne(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:(f==null?void 0:f.isValid)??null,error:(f==null?void 0:f.error)??null,bytes:(f==null?void 0:f.bytes)??null};s==null||s(v)},[d,f,s]);const g=()=>d?o.jsxs("div",{className:"flex h-5 items-center gap-2",children:[o.jsx(yu,{className:"h-4 w-4 animate-spin"}),o.jsx("span",{className:"text-sm",children:"Validating..."})]}):f?f.isValid?o.jsxs("div",{className:"flex h-5 items-center gap-2",children:[o.jsx(Jj,{className:"h-4 w-4 text-green-600"}),o.jsx("span",{className:"text-sm font-medium text-green-600",children:"Valid SQL code"}),f.bytes!==void 0&&o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"mx-1 text-gray-400",children:"•"}),o.jsxs(wt,{children:[o.jsx(Et,{asChild:!0,children:o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx(tp,{className:"h-3 w-3 text-gray-600"}),o.jsx("span",{className:"text-xs text-gray-600",children:sne(f.bytes)})]})}),o.jsx(Rt,{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(nf,{className:"h-4 w-4 flex-shrink-0 text-red-600"}),f.error&&o.jsx("span",{className:"text-xs text-red-500",children:f.error})]}):o.jsxs("div",{className:"flex h-5 items-center gap-2 text-gray-500",children:[o.jsx(tp,{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 fne(){const{dataMart:e,updateDataMartDefinition:t,getDataMart:n}=gs(),r=GO();if(!e)throw new Error("Data mart not found");const{definitionType:s,definition:l,id:c,storage:{type:d}}=e,[f,m]=p.useState(s),[,g]=p.useState({isValid:null,isLoading:!1,error:null}),v=p.useCallback(()=>{if(!f)return;const $={definitionType:f,definition:J0(f)};return l?{definitionType:f,definition:l}:$},[f,l]),x=p.useCallback(()=>{if(!f)return;const $=yee(f,d);return Xl($)},[f,d]),b=qi({resolver:x(),defaultValues:v(),mode:"onChange"}),{handleSubmit:w,reset:C,watch:E,formState:{isDirty:R,isValid:T}}=b,_=($,I)=>{if($!==Ke.SQL)return"";const B=I;return(B==null?void 0:B.sqlQuery)??""},O=E("definition"),A=_(f,O);p.useEffect(()=>{f&&C(v())},[f,C,v]);const D=$=>J0($);p.useEffect(()=>{if(!f&&!s&&(r!=null&&r.definitionType)){m(r.definitionType);const $={definitionType:r.definitionType,definition:D(r.definitionType)};C($)}},[r,f,s,C]);const j=p.useCallback($=>{g({isLoading:$.isLoading,isValid:$.isValid,error:$.error})},[]),M=$=>{m($)},U=p.useCallback(()=>{c&&n(c)},[c,n]),{run:H}=Y1(c,U),q=async $=>{if(f&&c)try{await t(c,$.definitionType,$.definition),await H(),C($)}catch(I){console.error("Failed to update data mart definition:",I)}},Y=$=>{$.preventDefault(),w(q)($)},ae=()=>{C(v())},G=()=>f?o.jsxs("form",{onSubmit:Y,className:"space-y-4",children:[o.jsx(ane,{definitionType:f,storageType:d,preset:r==null?void 0:r.connectorSourceTitle}),o.jsxs("div",{className:"flex items-center gap-4",children:[o.jsx(Se,{variant:"default",type:"submit",disabled:!T||!R,children:"Save"}),o.jsx(Se,{type:"button",variant:"ghost",onClick:ae,disabled:!R,children:"Discard"}),f===Ke.SQL&&A&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-6 w-px bg-gray-300"}),o.jsx(dne,{sql:A,dataMartId:c,onValidationStateChange:j})]})]})]}):null;return o.jsx(S3,{...b,children:o.jsxs("div",{className:"space-y-4",children:[!s&&o.jsx(fee,{initialType:f,onTypeSelect:M}),G()]})})}function hne(e){switch(e){case Ie.GOOGLE_BIGQUERY:return{type:"bigquery-data-mart-schema",fields:[]};case Ie.AWS_ATHENA:return{type:"athena-data-mart-schema",fields:[]};default:throw new Error(`Unsupported storage type: ${e}`)}}function qO(e){return e.type==="bigquery-data-mart-schema"}function ZO(e){return e.type==="athena-data-mart-schema"}function QT(e){return e!==null&&typeof e=="object"&&"mode"in e}function XT(e){return e!==null&&typeof e=="object"&&"isPrimaryKey"in e}function mne(e){return e==null?"":typeof e=="string"||typeof e=="number"||typeof e=="boolean"?String(e):""}function Wx(e){return e==null?e:JSON.parse(JSON.stringify(e))}function pne(e){const t=Wx(e),[n,r]=p.useState(t),[s,l]=p.useState(!1);p.useEffect(()=>{const f=Wx(e);r(f),l(!1)},[e]);const c=p.useCallback(f=>{n?qO(n)&&f.every(QT)?(r({...n,fields:f}),l(!0)):ZO(n)&&f.every(XT)&&(r({...n,fields:f}),l(!0)):f.length>0&&(QT(f[0])?(r({type:"bigquery-data-mart-schema",fields:f}),l(!0)):XT(f[0])&&(r({type:"athena-data-mart-schema",fields:f}),l(!0)))},[n]),d=p.useCallback(()=>{const f=Wx(e);r(f),l(!1)},[e]);return{schema:n,isDirty:s,updateSchema:c,resetSchema:d,setIsDirty:l}}function gne(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 vne(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 KO(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=>KO(c,t)):!1}function YO(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,f=s.alias?s.alias.toLowerCase().includes(t):!1,m=s.description?s.description.toLowerCase().includes(t):!1;if((d||f||m)&&r.push(c),s.fields&&s.fields.length>0){const g=YO(s.fields,t,c);g.length>0&&(r.includes(c)||r.push(c),r.push(...g))}}),r}function yne(e,t,n){const r=e.original;if(!n)return!0;const s=n.toLowerCase();return KO(r,s)}function xne(e){const[t,n]=p.useState(""),r=p.useCallback(l=>{n(l),e.setGlobalFilter(l)},[e]),s=t.toLowerCase();return{value:t,onChange:r,searchValue:s}}var us=(e=>(e.CONNECTED="CONNECTED",e.CONNECTED_WITH_DEFINITION_MISMATCH="CONNECTED_WITH_DEFINITION_MISMATCH",e.DISCONNECTED="DISCONNECTED",e))(us||{}),pf=(e=>(e.NULLABLE="NULLABLE",e.REQUIRED="REQUIRED",e.REPEATED="REPEATED",e))(pf||{}),Un=(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))(Un||{}),yS=(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))(yS||{});function bne(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===Un.RECORD||E.type===Un.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})},[]),f=p.useCallback(()=>{const w=[],C=(E,R="")=>{E.forEach((T,_)=>{const O=R?`${R}.${String(_)}`:String(_);(T.type===Un.RECORD||T.type===Un.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 A=R?`${R}.${String(O)}`:String(O),D=_.type===Un.RECORD||_.type===Un.STRUCT;w.push({..._,path:A,level:T}),D&&_.fields&&t.has(A)&&C(_.fields,A,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=YO(e,w).filter(R=>{const T=R.split(".").map(Number);let _=e,O;for(let A=0;A<T.length;A++){if(O=_[T[A]],!O)return!1;if((O.type===Un.RECORD||O.type===Un.STRUCT)&&O.fields&&O.fields.length>0)return!0;A<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===Un.RECORD||C.type===Un.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===Un.RECORD||T.type===Un.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:f,flattenedFields:m,handleSearchChange:g,isRecordType:v,topLevelFields:x,allExpanded:b}}function Sne(e,t,n,r){const s=p.useCallback((f,m)=>{if(n){const g=[...e],v=t[f].path;if(!v)g[f]={...g[f],...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 f={name:"",type:Un.STRING,mode:pf.NULLABLE,isPrimaryKey:!1,status:us.DISCONNECTED};n([...e,f])}},[e,n]),c=p.useCallback(f=>{if(n){const m=[...e],g=t[f].path;if(!g)m.splice(f,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(f=>{var m,g;if(n&&r){const v=[...e],x=t[f].path,b={name:"",type:Un.STRING,mode:pf.NULLABLE,isPrimaryKey:!1,status:us.DISCONNECTED};if(!x)(m=v[f]).fields??(m.fields=[]),v[f].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 WO(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),f=n.findIndex((x,b)=>(x.path??String(b))===c.id);if(d===-1||f===-1)return;const m=n[d].path,g=n[f].path,v=[...e];if(!m&&!g){const[x]=v.splice(d,1);v.splice(f,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 Cne(){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 Vg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Lu(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function xS(e){return"nodeType"in e}function na(e){var t,n;return e?Lu(e)?e:xS(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function bS(e){const{Document:t}=na(e);return e instanceof t}function Xf(e){return Lu(e)?!1:e instanceof na(e).HTMLElement}function QO(e){return e instanceof na(e).SVGElement}function Pu(e){return e?Lu(e)?e.document:xS(e)?bS(e)?e:Xf(e)||QO(e)?e.ownerDocument:document:document:document}const Hs=Vg?p.useLayoutEffect:p.useEffect;function SS(e){const t=p.useRef(e);return Hs(()=>{t.current=e}),p.useCallback(function(){for(var n=arguments.length,r=new Array(n),s=0;s<n;s++)r[s]=arguments[s];return t.current==null?void 0:t.current(...r)},[])}function wne(){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 gf(e,t){t===void 0&&(t=[e]);const n=p.useRef(e);return Hs(()=>{n.current!==e&&(n.current=e)},t),n}function Jf(e,t){const n=p.useRef();return p.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function Ip(e){const t=SS(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 ob(e){const t=p.useRef();return p.useEffect(()=>{t.current=e},[e]),t.current}let Qx={};function eh(e,t){return p.useMemo(()=>{if(t)return t;const n=Qx[e]==null?0:Qx[e]+1;return Qx[e]=n,e+"-"+n},[e,t])}function XO(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[f,m]of d){const g=l[f];g!=null&&(l[f]=g+e*m)}return l},{...t})}}const su=XO(1),Lp=XO(-1);function Ene(e){return"clientX"in e&&"clientY"in e}function CS(e){if(!e)return!1;const{KeyboardEvent:t}=na(e.target);return t&&e instanceof t}function Rne(e){if(!e)return!1;const{TouchEvent:t}=na(e.target);return t&&e instanceof t}function ib(e){if(Rne(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 Ene(e)?{x:e.clientX,y:e.clientY}:null}const vf=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[vf.Translate.toString(e),vf.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),JT="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function Tne(e){return e.matches(JT)?e:e.querySelector(JT)}const jne={display:"none"};function _ne(e){let{id:t,value:n}=e;return _e.createElement("div",{id:t,style:jne},n)}function Nne(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 Ane(){const[e,t]=p.useState("");return{announce:p.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const JO=p.createContext(null);function Dne(e){const t=p.useContext(JO);p.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function One(){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:`
727
727
  To pick up a draggable item, press the space bar.
728
728
  While dragging, use the arrow keys to move the item.
729
729
  Press space again to drop the item in its new position, or press escape to cancel.
package/dist/index.html CHANGED
@@ -6,7 +6,7 @@
6
6
  <link rel="icon" type="image/png" href="/favicon.png" />
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
8
  <title>OWOX</title>
9
- <script type="module" crossorigin src="/assets/index-CRC8tuQU.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-DRAkoewz.js"></script>
10
10
  <link rel="stylesheet" crossorigin href="/assets/index-DSINwVio.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.12.0-next-20251031104058",
3
+ "version": "0.12.0-next-20251103153640",
4
4
  "description": "Web interface for OWOX Data Marts - an open-source solution for Data Analysts",
5
5
  "author": "OWOX",
6
6
  "license": "ELv2",