@owox/web 0.15.0 → 0.16.0-next-20251212073834
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.
|
@@ -795,7 +795,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
795
795
|
-----END PRIVATE KEY-----`,rows:6})}),a.jsx(xn,{children:a.jsx(Wse,{})}),a.jsx(Mt,{})]})}),a.jsx(_t,{control:e.control,name:"credentials.privateKeyPassphrase",render:({field:n})=>a.jsxs(xt,{children:[a.jsx(yt,{tooltip:"Enter the passphrase if your private key is encrypted",children:"Passphrase (Optional)"}),a.jsx(Ct,{children:a.jsx(It,{...n,type:"password",value:n.value??"",placeholder:"Enter passphrase if key is encrypted"})}),a.jsx(xn,{children:a.jsx(Xse,{})}),a.jsx(Mt,{})]})})]})]})]})},Jse=()=>a.jsx(a.Fragment,{children:a.jsx(Cn,{variant:"common",type:"single",collapsible:!0,className:"mt-2",children:a.jsxs(Kt,{value:"snowflake-setup",children:[a.jsx(Zt,{children:"How do I get started with Snowflake?"}),a.jsxs(Yt,{children:[a.jsx("p",{className:"mb-2",children:"To use Snowflake as your storage provider, you'll need an active Snowflake account with appropriate permissions."}),a.jsx("p",{className:"mb-2",children:"Here's how to get started:"}),a.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[a.jsxs("li",{children:["Sign up for a"," ",a.jsx(gn,{className:"underline",href:"https://signup.snowflake.com/",children:"Snowflake account"})," ","if you don't have one yet."]}),a.jsx("li",{children:"Make sure you have the necessary privileges to create and access databases, schemas, and warehouses."}),a.jsx("li",{children:"Choose your authentication method: Username & Password for quick setup, or Key-Pair authentication for production environments."}),a.jsx("li",{children:"Fill in the connection details below (account identifier and warehouse)."}),a.jsx("li",{children:"You can access tables using the full path format: database.schema.table (similar to BigQuery and Athena)."})]})]})]})})});function eoe(){return a.jsx(Cn,{variant:"common",type:"single",collapsible:!0,children:a.jsxs(Kt,{value:"bigquery-api-details",children:[a.jsx(Zt,{children:"How do I enable the BigQuery API?"}),a.jsxs(Yt,{children:[a.jsxs("p",{className:"mb-2",children:["To run queries and process data in Google BigQuery, you need to enable the"," ",a.jsx(gn,{className:"underline",href:"https://console.cloud.google.com/apis/library/bigquery.googleapis.com",children:"BigQuery API"})," ","in your Google Cloud project."]}),a.jsx("p",{className:"mb-2",children:"Here's how to do it:"}),a.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[a.jsx("li",{children:"Open the link above and make sure the correct project is selected."}),a.jsxs("li",{children:["If the API isn't enabled yet, click ",a.jsx("strong",{children:"Enable"}),"."]}),a.jsx("li",{children:"If it's already enabled, you'll see the API dashboard — that's fine."})]})]})]})})}function toe(){return a.jsx(Cn,{variant:"common",type:"single",collapsible:!0,children:a.jsxs(Kt,{value:"athena-api-details",children:[a.jsx(Zt,{children:"How do I activate Athena API?"}),a.jsxs(Yt,{children:[a.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."}),a.jsx("p",{className:"mb-2",children:"Here's how to activate Athena:"}),a.jsxs("ol",{className:"list-inside list-decimal space-y-2 text-sm",children:[a.jsxs("li",{children:["Open"," ",a.jsx(gn,{className:"underline",href:"https://console.aws.amazon.com/athena/",children:"the AWS Athena console"})," ","and sign in to your AWS account."]}),a.jsx("li",{children:"If you haven't used Athena before, you may need to set up a query result location (an S3 bucket)."}),a.jsx("li",{children:"You can start running queries immediately after setup."})]})]})]})})}function noe({initialData:e,onSubmit:t,onCancel:n,onDirtyChange:r}){const s=Ro({resolver:yi(PX),defaultValues:e}),{watch:i,control:c,formState:{isDirty:u,isSubmitting:f}}=s,m=i("type");re.useEffect(()=>{r==null||r(u)},[u,r]);const y=async g=>{const{dirtyFields:x}=s.formState,v=cO(g);return x.credentials||delete v.credentials,t(v)};return a.jsx(_l,{...s,children:a.jsxs(gi,{onSubmit:g=>{s.handleSubmit(y)(g)},noValidate:!0,children:[a.jsxs(Nl,{children:[a.jsxs(Yr,{title:"General",children:[a.jsx(_t,{control:c,name:"title",render:({field:g})=>a.jsxs(xt,{children:[a.jsx(yt,{tooltip:"Name the storage to clarify its purpose",children:"Title"}),a.jsx(Ct,{children:a.jsx(It,{...g,placeholder:"Storage title"})}),a.jsx(Mt,{})]})}),a.jsx(_t,{control:c,name:"type",render:({field:g})=>a.jsxs(xt,{children:[a.jsx(yt,{tooltip:"The selected source will be used to process data in your Data Marts",children:"Storage Type"}),a.jsx(Ct,{children:a.jsxs(ca,{value:g.value,onValueChange:g.onChange,disabled:!!e,children:[a.jsx(da,{className:"w-full",children:a.jsx(ua,{placeholder:"Select a storage type"})}),a.jsx(fa,{children:a.jsx(Uy,{children:Sl.getAllTypes().map(({type:x,displayName:v,icon:C,status:S})=>a.jsx(Gn,{value:x,disabled:S===Xo.COMING_SOON,children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(C,{size:20}),v]})},x))})})]})}),a.jsxs(xn,{children:[m===Re.GOOGLE_BIGQUERY&&a.jsx(eoe,{}),m===Re.AWS_ATHENA&&a.jsx(toe,{}),m===Re.SNOWFLAKE&&a.jsx(Jse,{})]}),a.jsx(Mt,{})]})})]}),m===Re.GOOGLE_BIGQUERY&&a.jsx(zse,{form:s}),m===Re.AWS_ATHENA&&a.jsx(Bse,{form:s}),m===Re.SNOWFLAKE&&a.jsx(Qse,{form:s})]}),a.jsxs(Oc,{children:[a.jsx(Ee,{variant:"default",type:"submit",className:"w-full","aria-label":"Save",disabled:!u||f,children:"Save"}),a.jsx(Ee,{variant:"outline",type:"button",onClick:n,className:"w-full","aria-label":"Cancel",children:"Cancel"})]})]})})}function Ic(e){const[t,n]=h.useState(!1),[r,s]=h.useState(!1),i=h.useCallback(()=>{r?n(!0):e()},[r,e]),c=h.useCallback(()=>{n(!1),s(!1),e()},[e]),u=h.useCallback(m=>{s(m)},[]),f=h.useCallback(()=>{s(!1),e()},[e]);return{showUnsavedDialog:t,setShowUnsavedDialog:n,isDirty:r,handleClose:i,confirmClose:c,handleFormDirtyChange:u,handleFormSubmitSuccess:f}}function uI({isOpen:e,onClose:t,dataStorage:n,onSaveSuccess:r}){const{updateDataStorage:s}=zy(),{showUnsavedDialog:i,setShowUnsavedDialog:c,handleClose:u,confirmClose:f,handleFormDirtyChange:m,handleFormSubmitSuccess:y}=Ic(t),g=async v=>{if(n){const C=await s(n.id,v);C&&(r(C),y())}},x=h.useRef(!1);return h.useEffect(()=>{const v=n?"Edit":"Create";e&&!x.current?(Le({event:"data_storage_config_open",category:"DataStorage",action:v,label:n==null?void 0:n.type}),x.current=!0):!e&&x.current&&(Le({event:"data_storage_config_close",category:"DataStorage",action:v,label:n==null?void 0:n.type}),x.current=!1)},[e,n]),a.jsxs(a.Fragment,{children:[a.jsx(ci,{open:e,onOpenChange:v=>{v||u()},children:a.jsxs(ui,{children:[a.jsxs(di,{children:[a.jsx(fi,{children:"Configure Storage Provider"}),a.jsx(yl,{children:"Customize settings for your storage provider"})]}),a.jsx(noe,{initialData:n??void 0,onSubmit:g,onCancel:u,onDirtyChange:m})]})}),a.jsx(br,{open:i,onOpenChange:c,title:"Unsaved Changes",description:"You have unsaved changes. Exit without saving?",confirmLabel:"Yes, leave now",cancelLabel:"No, stay here",onConfirm:f,variant:"destructive"})]})}const roe=({dataStorage:e,onDataStorageChange:t})=>{const[n,r]=h.useState(!1),s=Sl.getInfo(e.type),i=()=>{r(!0)},c=()=>{r(!1)},u=()=>{if(!XD(e))return a.jsxs("div",{className:"flex items-center space-x-2 text-sm",children:[a.jsx(xh,{className:"h-4 w-4 text-red-500"}),a.jsx("span",{className:"text-red-500",children:"Storage configuration is incomplete"})]});const m=(g,x)=>a.jsxs("span",{children:[a.jsxs("span",{className:"text-muted-foreground/75",children:[g,":"]})," ",a.jsx("span",{className:"text-muted-foreground font-medium",children:x})]}),y=(g,x,v)=>a.jsxs("span",{children:[a.jsxs("span",{className:"text-muted-foreground/75",children:[g,":"]})," ",a.jsx(gn,{href:v,onClick:C=>{C.stopPropagation()},children:x})]});switch(e.type){case Re.GOOGLE_BIGQUERY:{const g=e.config.projectId,x=e.config.location,v=`https://console.cloud.google.com/bigquery?project=${g}`;return a.jsxs("div",{className:"flex flex-wrap gap-2",children:[y("Project ID",g,v),a.jsx("span",{className:"text-muted-foreground",children:"•"}),m("Location",x)]})}case Re.AWS_ATHENA:{const g=e.config.region,x=e.config.outputBucket,v=`https://s3.console.aws.amazon.com/s3/buckets/${x}?region=${g}`;return a.jsxs("div",{className:"flex flex-wrap gap-2",children:[m("Region",g),a.jsx("span",{className:"text-muted-foreground",children:"•"}),y("Bucket",x,v)]})}case Re.SNOWFLAKE:{const g=e.config.account,x=e.config.warehouse;return a.jsxs("div",{className:"flex flex-wrap gap-2",children:[y("Account",g,"https://app.snowflake.com/"),a.jsx("span",{className:"text-muted-foreground",children:"•"}),m("Warehouse",x)]})}default:return"Unknown storage type configuration"}};return a.jsxs(a.Fragment,{children:[a.jsx(vb,{title:e.title,icon:s.icon,subtitle:u(),onClick:i}),a.jsx(C2,{children:a.jsx(uI,{isOpen:n,onClose:c,dataStorage:e,onSaveSuccess:f=>{t&&t(f)}})})]})};function aoe({initialType:e,onTypeSelect:t}){var c;const[n,r]=h.useState(e??null);h.useEffect(()=>{e!==void 0&&e!==n&&r(e)},[e,n]);const s=u=>{r(u),t(u)},i=[{type:$e.SQL,label:"SQL",description:"SQL query"},{type:$e.TABLE,label:"Table",description:"Existing table"},{type:$e.VIEW,label:"View",description:"Existing view"},{type:$e.TABLE_PATTERN,label:"Pattern",description:"Table pattern"},{type:$e.CONNECTOR,label:"Connector",description:"Data import from Source to Storage"}];return a.jsxs("div",{className:"dm-card-block",children:[a.jsx(Ta,{className:"text-foreground",children:"Definition Type"}),a.jsxs(ca,{value:n??"",onValueChange:u=>{s(u)},children:[a.jsx(da,{className:"dm-card-formcontrol w-full","aria-label":"Definition Type",children:a.jsx(ua,{placeholder:"Select definition type",children:n&&((c=i.find(u=>u.type===n))==null?void 0:c.label)})}),a.jsx(fa,{children:a.jsx(Uy,{children:i.map(u=>a.jsxs(Gn,{value:u.type,children:[u.label,a.jsx("span",{className:"text-muted-foreground/80 ml-2",children:u.description})]},u.type))})})]})]})}const soe=rn({definitionType:Br($e.SQL),definition:rn({sqlQuery:Dt().min(1,"SQL query is required")})}),ooe=e=>{const t=xO(e);return rn({definitionType:Br($e.TABLE),definition:t})},ioe=e=>{const t=xO(e);return rn({definitionType:Br($e.VIEW),definition:t})},loe=e=>{const t=JQ(e);return rn({definitionType:Br($e.TABLE_PATTERN),definition:t})},coe=rn({definitionType:Br($e.CONNECTOR),definition:rn({connector:rn({source:rn({name:Dt().min(1,"Connector name is required"),configuration:X1(QZ(WZ())).min(1,"At least one configuration is required"),node:Dt().min(1,"Node is required"),fields:X1(Dt()).min(1,"At least one field is required")}),storage:rn({fullyQualifiedName:Dt().min(1,"fully qualified name is required")})})})}),uoe=(e,t)=>{if(!e)return rn({definitionType:JZ(Sy($e)),definition:rn({}).optional()});switch(e){case $e.SQL:return soe;case $e.TABLE:return ooe(t);case $e.VIEW:return ioe(t);case $e.TABLE_PATTERN:return loe(t);case $e.CONNECTOR:return coe;default:return rn({})}};function doe({control:e}){return a.jsx(_t,{control:e,name:"definition.sqlQuery",render:({field:t})=>a.jsxs(xt,{className:"dm-card-block",children:[a.jsx(yt,{className:"text-foreground",children:"SQL Query"}),a.jsx(Ct,{children:a.jsx(Bae,{initialValue:t.value?{sqlQuery:t.value}:void 0,onChange:n=>{t.onChange(n.sqlQuery)}})}),a.jsx(Mt,{})]})})}function foe({control:e,storageType:t}){const n=eO(t),r=tO(t);return a.jsx(_t,{control:e,name:"definition.fullyQualifiedName",render:({field:s})=>a.jsxs(xt,{className:"dm-card-block",children:[a.jsx(yt,{children:"Fully Qualified Table Name"}),a.jsx(Ct,{children:a.jsx(It,{placeholder:n,value:s.value,onChange:s.onChange,className:"dm-card-formcontrol"})}),a.jsx(xn,{className:"text-muted-foreground/75",children:r}),a.jsx(Mt,{})]})})}function hoe({control:e,storageType:t}){const n=eO(t),r=tO(t);return a.jsx(_t,{control:e,name:"definition.fullyQualifiedName",render:({field:s})=>a.jsxs(xt,{className:"dm-card-block",children:[a.jsx(yt,{children:"Fully Qualified View Name"}),a.jsx(Ct,{children:a.jsx(It,{placeholder:n,value:s.value,onChange:s.onChange,className:"dm-card-formcontrol"})}),a.jsx(xn,{className:"text-muted-foreground/75",children:r}),a.jsx(Mt,{})]})})}function moe({control:e,storageType:t}){const n=BX(t),r=GX(t);return a.jsx(_t,{control:e,name:"definition.pattern",render:({field:s})=>a.jsxs(xt,{className:"dm-card-block",children:[a.jsx(yt,{children:"Table Pattern"}),a.jsx(Ct,{children:a.jsx(It,{placeholder:n,value:s.value,onChange:s.onChange,className:"dm-card-formcontrol"})}),a.jsx(xn,{className:"text-muted-foreground/75",children:r}),a.jsx(Mt,{})]})})}const B2=e=>{switch(e){case $e.SQL:return{sqlQuery:""};case $e.TABLE:return{fullyQualifiedName:""};case $e.VIEW:return{fullyQualifiedName:""};case $e.TABLE_PATTERN:return{pattern:""};case $e.CONNECTOR:return{connector:{source:{name:"",configuration:[],node:"",fields:[]},storage:{fullyQualifiedName:""}}};default:return{}}},poe=Cc("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 G2({className:e,variant:t,...n}){return a.jsx("div",{"data-slot":"alert",role:"alert",className:se(poe({variant:t}),e),...n})}function dI({className:e,...t}){return a.jsx("div",{"data-slot":"alert-title",className:se("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",e),...t})}function q2({className:e,...t}){return a.jsx("div",{"data-slot":"alert-description",className:se("text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",e),...t})}function goe({connectors:e,selectedConnector:t,loading:n,error:r,onConnectorSelect:s,onConnectorDoubleClick:i}){return n?a.jsx(D2,{variant:"grid"}):r?a.jsxs(G2,{variant:"destructive",children:[a.jsx(gh,{className:"h-4 w-4"}),a.jsx(q2,{children:"Failed to load available connectors. Please try again."})]}):a.jsxs(ni,{children:[a.jsx(al,{title:"Choose Connector",children:a.jsx(ire,{children:e.map(c=>a.jsx(lre,{icon:c.logoBase64?a.jsx(_c,{base64:c.logoBase64,size:20}):null,title:c.displayName,selected:(t==null?void 0:t.name)===c.name,onClick:()=>{s(c)},onDoubleClick:()=>{s(c),i==null||i(c)}},c.name))})}),e.length===0&&a.jsx(ti,{icon:a.jsx(Kf,{size:56,strokeWidth:1}),title:"No connectors available",subtitle:"Ask your administrator to configure connectors."})]})}function yoe({currentStep:e,totalSteps:t,canGoNext:n,canGoBack:r,isLoading:s=!1,onNext:i,onBack:c,onFinish:u,nextLabel:f="Next",backLabel:m="Back",finishLabel:y="Save"}){const g=e===t;return t===1?a.jsx("div",{className:"w-full",children:a.jsx(Ee,{className:"w-full",variant:"default",onClick:u,disabled:!n||s,children:y})}):a.jsxs("div",{className:"flex w-full items-center justify-between gap-4",children:[a.jsx("div",{className:"flex-1",children:r&&a.jsxs(Ee,{variant:"outline",onClick:c,disabled:s,children:[a.jsx(RP,{className:"h-4 w-4"}),m]})}),a.jsxs("div",{className:"text-muted-foreground/75 px-4 text-sm",children:["Step ",e," of ",t]}),a.jsx("div",{className:"flex flex-1 justify-end",children:g?a.jsx(Ee,{variant:"default",onClick:u,disabled:!n||s,children:y}):a.jsxs(Ee,{variant:"default",onClick:i,disabled:!n||s,children:[f,a.jsx(_a,{className:"h-4 w-4"})]})})]})}function oc({connector:e,size:t=24,variant:n="compact"}){return a.jsx(ti,{icon:a.jsx(_c,{base64:e.logoBase64,size:t}),title:e.displayName,docUrl:e.docUrl,variant:n})}function $u({label:e}){return a.jsx("div",{className:"border-border text-muted-foreground mt-3 flex items-center justify-center gap-2 border-t pt-3 text-sm",children:a.jsx(Ee,{variant:"outline",asChild:!0,children:a.jsxs(Wr,{to:"https://github.com/OWOX/owox-data-marts/issues",target:"_blank",rel:"noopener noreferrer",children:[e," Open issue here",a.jsx(ai,{className:"h-4 w-4"})]})})})}const Cb="**********";function xoe({specification:e,configuration:t,onValueChange:n}){const{name:r,title:s}=e,i=s??r,c=r;return a.jsxs("div",{className:"flex items-center space-x-2",children:[a.jsx(It,{type:"checkbox",id:c,name:r,checked:t[r]||!1,onChange:u=>{n(r,u.target.checked)},className:"text-primary focus:ring-primary border-border h-4 w-4 rounded"}),a.jsx(Ta,{htmlFor:c,className:"cursor-pointer text-sm",children:a.jsx(Ga,{htmlFor:c,required:e.required,tooltip:e.description,children:i})})]})}function voe({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s}=e,i=e.title??e.name;return a.jsx(It,{id:r,name:r,type:"number",value:t[r]||"",placeholder:s??`Enter ${i.toLowerCase()}`,onChange:c=>{const u=c.target.value,f=u===""?void 0:parseFloat(u);n(r,f)}})}function boe({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s,default:i}=e,c=e.title??e.name;return a.jsx(wo,{id:r,name:r,value:Array.isArray(t[r])?t[r].join(`
|
|
796
796
|
`):Array.isArray(i)?i.join(`
|
|
797
797
|
`):"",placeholder:s??`Enter ${c.toLowerCase()} (one per line)`,rows:4,onChange:u=>{const f=u.target.value.split(`
|
|
798
|
-
`).filter(m=>m.trim());n(r,f)}})}function Soe({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s,default:i}=e,c=e.title??e.name,u=f=>{if(!f||typeof f!="string"&&typeof f!="number")return"";const m=typeof f=="string"?f:f.toString();try{const y=new Date(m);return isNaN(y.getTime())?"":y.toISOString().split("T")[0]}catch{return""}};return a.jsx(It,{id:r,name:r,type:"date",value:t[r]||u(i)||"",placeholder:s??`Enter ${c.toLowerCase()}`,onChange:f=>{n(r,f.target.value)}})}function Coe({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s}=e,i=e.title??e.name;return a.jsx(It,{id:r,name:r,type:"text",value:t[r]||"",placeholder:s??`Enter ${i.toLowerCase()}`,onChange:c=>{n(r,c.target.value)}})}function Eoe({specification:e,configuration:t,onValueChange:n}){const r=e.title??e.name,{name:s,placeholder:i,default:c}=e;return a.jsx(wo,{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:i??`Enter ${r.toLowerCase()} as JSON`,rows:6,className:"font-mono",onChange:u=>{try{const f=JSON.parse(u.target.value);n(s,f)}catch{n(s,u.target.value)}}})}function woe({specification:e,configuration:t,onValueChange:n,isEditingExisting:r,isSecretEditing:s}){const i=e.title??e.name,c=r&&!s;return a.jsx(It,{id:e.name,...c?{}:{name:e.name},type:c?"password":"text",autoComplete:c?"new-password":"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,value:c?Cb:t[e.name]||"",...c?{readOnly:!0,disabled:!0}:{},...c?{}:{placeholder:e.placeholder??`Enter ${i.toLowerCase()}`},...c?{}:{onChange:u=>{n(e.name,u.target.value)}}})}function Roe({specification:e,configuration:t,onValueChange:n,specOptions:r}){const{name:s,placeholder:i,default:c}=e,u=e.title??e.name,f=r.map(m=>({value:m,label:m}));return a.jsx(V2,{options:f,value:t[s]||c||"",onValueChange:m=>{n(s,m)},placeholder:i??`Select ${u.toLowerCase()}`,emptyMessage:"No options available",className:"w-full"})}function joe(){const e=h.useRef(new Pf),t=h.useCallback(async(s,i,c)=>await e.current.exchangeCredentials(s,{fieldPath:c,payload:i}),[]),n=h.useCallback(async(s,i)=>{try{return await e.current.checkOAuthStatus(s,i)}catch{return{valid:!1}}},[]),r=h.useCallback(async(s,i)=>await e.current.getOAuthSettings(s,i),[]);return{exchangeCredentials:t,checkStatus:n,getSettings:r}}let wf=null;function Toe({appId:e,scope:t,onSuccess:n,onError:r,disabled:s=!1,children:i}){const[c,u]=h.useState(!1),[f,m]=h.useState(!1),[y,g]=h.useState(null);h.useEffect(()=>{if(window.FB){m(!0);return}if(document.getElementById("facebook-jssdk")){const E=setInterval(()=>{window.FB&&(m(!0),clearInterval(E))},100);return()=>{clearInterval(E)}}if(!e)return;if(wf&&wf!==e){console.warn("Facebook SDK already initialized with different appId");return}wf??(wf=e),window.fbAsyncInit=function(){window.FB&&wf&&(window.FB.init({appId:wf,cookie:!0,xfbml:!0,version:"v23.0"}),m(!0))};const S=document.createElement("script");S.id="facebook-jssdk",S.src="https://connect.facebook.net/en_US/sdk.js",S.async=!0,S.defer=!0,S.crossOrigin="anonymous",document.body.appendChild(S)},[e]);const x=()=>{if(!window.FB||!f){const S=new Error("Facebook SDK not loaded or not ready");g(S.message),r==null||r(S);return}u(!0),g(null),window.FB.login(S=>{var E;if(S.status==="connected"&&S.authResponse){const{accessToken:R,expiresIn:j,userID:_}=S.authResponse;(E=window.FB)==null||E.api("/me?fields=name,email",I=>{const A={accessToken:R,expiresIn:j,userID:_,userName:I.name,userEmail:I.email};n(A),u(!1)})}else{const R=new Error("User cancelled login or did not fully authorize");g(R.message),r==null||r(R),u(!1)}},{scope:t})},v=s||c||!f,C=()=>c?"Connecting...":i||(f?"Continue with Facebook":"Loading...");return a.jsxs("div",{className:"flex flex-col gap-2",children:[a.jsxs(Ee,{type:"button",onClick:x,disabled:v,className:"flex items-center justify-center gap-2 rounded-md border-none bg-[#1877F2] px-4 py-2.5 text-sm font-semibold text-white hover:bg-[#166FE5] disabled:cursor-not-allowed disabled:opacity-60",children:[a.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:a.jsx("path",{d:"M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036 26.805 26.805 0 0 0-.733-.009c-.707 0-1.259.096-1.675.309a1.686 1.686 0 0 0-.679.622c-.258.42-.374.995-.374 1.752v1.297h3.919l-.386 2.103-.287 1.564h-3.246v8.245C19.396 23.238 24 18.179 24 12.044c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.628 3.874 10.35 9.101 11.647Z"})}),C()]}),y&&a.jsx("div",{className:"mt-1 text-xs text-red-600",children:y})]})}function _oe({isLoading:e,status:t,settings:n,onOAuthSuccess:r}){const s=i=>{r({accessToken:i.accessToken})};return a.jsx("div",{className:"mt-2 mb-2",children:a.jsx(Toe,{appId:n==null?void 0:n.vars.AppId,scope:n==null?void 0:n.vars.Scopes,onSuccess:s,disabled:e,children:t!=null&&t.user?a.jsxs(a.Fragment,{children:["Authenticated as ",a.jsx("strong",{children:t.user.name??t.user.id})]}):"Continue with Facebook"})})}function fI({specification:e,option:t,configuration:n,onValueChange:r,connectorName:s,onSecretEditToggle:i,secretEditing:c={},isEditingExisting:u=!1}){const[f,m]=h.useState(!1),[y,g]=h.useState(null),[x,v]=h.useState(null),[C,S]=h.useState(null),E=h.useMemo(()=>{const V=n[e.name],Z=t!=null&&t.value&&V?V[t.value]:V;return Z==null?void 0:Z._source_credential_id},[n,e.name,t==null?void 0:t.value]),R=h.useMemo(()=>t?`${e.name}.${t.value}`:e.name,[e.name,t]),j=h.useMemo(()=>{const V=n[e.name];if(t!=null&&t.value&&V){const Z=V[t.value];return Z&&typeof Z=="object"&&!Array.isArray(Z)?Z:{}}return V&&typeof V=="object"&&!Array.isArray(V)?V:{}},[n,e.name,t==null?void 0:t.value]),_=h.useMemo(()=>{const V=j;return"_source_credential_id"in V?!1:!!(t!=null&&t.items&&Object.keys(t.items).some(F=>F in V&&V[F]!==void 0&&V[F]!==""))},[j,t]),[I,A]=h.useState(_);h.useEffect(()=>{const V="_source_credential_id"in j,Z=(t==null?void 0:t.items)&&Object.keys(t.items).some(F=>F in j&&j[F]!==void 0&&j[F]!=="");V&&I?A(!1):Z&&!I&&A(!0)},[j,t,I]);const O=(V,Z)=>{if(!(t!=null&&t.value))return;const F=n[e.name]&&typeof n[e.name]=="object"?n[e.name]:{};r(e.name,{...F,[t.value]:{...typeof F[t.value]=="object"&&F[t.value]!==null?F[t.value]:{},[V]:Z}})},{checkStatus:T,getSettings:D,exchangeCredentials:k}=joe(),B=async V=>{try{m(!0),S(null);const Z=await k(s,V,R),F=n[e.name];t?r(e.name,{...F,[t.value]:{_source_credential_id:Z.credentialId}}):r(e.name,{_source_credential_id:Z.credentialId})}catch(Z){const F=Z instanceof Error?Z.message:"Failed to exchange OAuth credentials";console.error("Failed to exchange OAuth credentials:",Z),S(F)}finally{m(!1)}};h.useEffect(()=>{if(!E){g(null),m(!1);return}let V=!1;return(async()=>{try{m(!0);const F=await T(s,E);V||g(F)}catch(F){V||(console.error("Failed to validate credentials:",F),g({valid:!1}))}finally{V||m(!1)}})(),()=>{V=!0}},[E,s,T]),h.useEffect(()=>{(async()=>{try{const Z=await D(s,R);v(Z)}catch(Z){console.error("Failed to fetch settings:",Z),v(null)}})()},[s,R,D]);const G=!!(x!=null&&x.isEnabled);if((I||!G)&&(t!=null&&t.items))return a.jsxs("div",{className:"space-y-4",children:[Object.entries(t.items).map(([V,Z])=>{const F=Array.isArray(Z.attributes)?Z.attributes.includes("SECRET")&&j[V]!==void 0:!1,M=c[e.name]??!1;return a.jsxs("div",{className:"mb-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx(Ga,{htmlFor:V,required:Z.required,tooltip:Z.description,className:"mb-2 justify-start",children:Z.title??V}),F&&u&&i&&a.jsx(Ee,{variant:"ghost",size:"sm",type:"button",onClick:()=>{i(e.name,!M)},children:M?"Cancel":"Edit"})]}),K2({specification:{...Z,name:V},configuration:j,onValueChange:($,H)=>{O($,H)},flags:{isEditingExisting:u,isSecret:F,isSecretEditing:M},connectorName:s})]},V)}),G&&a.jsx(Ee,{variant:"link",size:"sm",type:"button",onClick:()=>{r(e.name,{[t.value]:{}}),A(!1),m(!1)},className:"px-0",children:"Back to OAuth"})]});const Y=(()=>{switch(s){case"FacebookMarketing":return a.jsx(_oe,{isLoading:f,status:y,settings:x,onOAuthSuccess:B});default:return null}})();return a.jsxs("div",{className:"space-y-3",children:[Y,C&&a.jsx("div",{className:"text-destructive text-sm",children:C}),(t==null?void 0:t.items)&&Object.keys(t.items).length>0&&a.jsx(Ee,{variant:"link",size:"sm",type:"button",onClick:()=>{r(e.name,{[t.value]:{}}),A(!0)},className:"px-0",children:"Manually"})]})}function K2({specification:e,configuration:t,onValueChange:n,flags:r,connectorName:s}){const{requiredType:i,options:c}=e,{isSecret:u=!1,isEditingExisting:f=!1,isSecretEditing:m=!1}=r??{};if(e.attributes&&Array.isArray(e.attributes)&&e.attributes.includes("OAUTH_FLOW"))return a.jsx(fI,{specification:e,configuration:t,onValueChange:n,connectorName:s});if(u)return a.jsx(woe,{specification:e,configuration:t,onValueChange:n,isEditingExisting:f,isSecretEditing:m});if(c&&c.length>0)return a.jsx(Roe,{specification:e,configuration:t,onValueChange:n,specOptions:c});switch(i){case As.BOOLEAN:return a.jsx(xoe,{specification:e,configuration:t,onValueChange:n});case As.NUMBER:return a.jsx(voe,{specification:e,configuration:t,onValueChange:n});case As.ARRAY:return a.jsx(boe,{specification:e,configuration:t,onValueChange:n});case As.OBJECT:return a.jsx(Eoe,{specification:e,configuration:t,onValueChange:n});case As.DATE:return a.jsx(Soe,{specification:e,configuration:t,onValueChange:n});case As.STRING:default:return a.jsx(Coe,{specification:e,configuration:t,onValueChange:n})}}function Noe({specification:e,configuration:t,isEditingExisting:n,isSecretEditing:r,isSecret:s,onValueChange:i,onSecretEditToggle:c,connectorName:u}){return a.jsxs(Bi,{children:[e.requiredType!==As.BOOLEAN&&a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx(Ga,{htmlFor:e.name,required:e.required,tooltip:e.description,children:e.title??e.name}),s&&n&&a.jsx(Ee,{variant:"ghost",size:"sm",type:"button",onClick:()=>{c(e.name,!r)},children:r?"Cancel":"Edit"})]}),K2({specification:e,configuration:t,onValueChange:i,flags:{isSecret:s,isEditingExisting:n,isSecretEditing:r},connectorName:u})]},e.name)}function Aoe({specification:e,configuration:t,onValueChange:n,isEditingExisting:r,isSecretEditing:s,onSecretEditToggle:i,connectorName:c}){const u=h.useMemo(()=>{var v,C;const x=t[e.name];if(x&&typeof x=="object"){const S=Object.keys(x);if(S.length>0)return S[0]}return((C=(v=e.oneOf)==null?void 0:v[0])==null?void 0:C.value)??""},[t,e.name,e.oneOf]),[f,m]=h.useState(u);if(h.useEffect(()=>{m(u)},[u]),h.useEffect(()=>{if(f){const x=t[e.name];x&&typeof x=="object"&&f in x||n(e.name,{[f]:{}})}},[f,e.name]),!e.oneOf)return null;const y=x=>{m(x)},g=(x,v,C)=>{const S=t[e.name]&&typeof t[e.name]=="object"?t[e.name]:{};n(e.name,{[x]:{...typeof S[x]=="object"&&S[x]!==null?S[x]:{},[v]:C}})};return a.jsx(ore,{label:e.title??e.name,options:e.oneOf.map(x=>({value:x.value,label:x.label})),value:f,onValueChange:y,children:e.oneOf.map(x=>{const v=x.attributes&&Array.isArray(x.attributes)&&x.attributes.includes("OAUTH_FLOW");return a.jsx(Zne,{value:x.value,children:v?a.jsx(fI,{specification:e,option:x,configuration:t,onValueChange:n,connectorName:c,onSecretEditToggle:i,secretEditing:{[e.name]:s},isEditingExisting:r}):Object.entries(x.items).map(([C,S])=>{const E=t[e.name]&&typeof t[e.name]=="object"?t[e.name]:{},R=Array.isArray(S.attributes)&&Object.keys(E)[0]===x.value?S.attributes.includes("SECRET"):!1,j=typeof t[e.name]=="object"&&t[e.name]!==null?t[e.name]:{},_=typeof j[x.value]=="object"&&j[x.value]!==null?j[x.value]:{};return a.jsxs("div",{className:"mb-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx(Ga,{htmlFor:C,required:S.required,tooltip:S.description,className:"mb-2 justify-start",children:C}),R&&r&&a.jsx(Ee,{variant:"ghost",size:"sm",type:"button",onClick:()=>{i(e.name,!s)},children:s?"Cancel":"Edit"})]}),K2({specification:{...S,name:C},configuration:_,onValueChange:(I,A)=>{g(x.value,I,A)},flags:{isEditingExisting:r,isSecret:R,isSecretEditing:s},connectorName:c})]},C)})},x.value)})},e.name)}function W_(e,t,n,r,s,i,c){return e.map(u=>{const f=Array.isArray(u.attributes)?u.attributes.includes("SECRET"):!1,m=s[u.name];return u.oneOf&&u.requiredType===As.OBJECT?a.jsx(Aoe,{specification:u,configuration:t,onValueChange:n,isEditingExisting:i,isSecretEditing:m,onSecretEditToggle:r,connectorName:c},u.name):a.jsx(Noe,{specification:u,configuration:t,isEditingExisting:i,isSecret:f,isSecretEditing:m,onValueChange:n,onSecretEditToggle:r,connectorName:c},u.name)})}function X_({collapsibleTitle:e,items:t,configuration:n,onValueChange:r,onSecretEditToggle:s,secretEditing:i,isEditingExisting:c,connectorName:u}){return e?a.jsx(x6,{title:e,children:W_(t,n,r,s,i,c,u)}):W_(t,n,r,s,i,c,u)}function Doe({currentConnectorName:e,onCopyConfiguration:t,connectorSpecification:n}){const[r,s]=h.useState([]),[i,c]=h.useState(!1),[u,f]=h.useState(!1),m=h.useCallback(async()=>{c(!0);try{const x=await Tn.getDataMartsByConnectorName(e);s(x)}catch{s([])}finally{c(!1)}},[e]);h.useEffect(()=>{u&&m()},[u,m]);const y=(x,v)=>{const C=v._id;if(!C){console.error("Configuration does not have _id field");return}t({dataMartId:x.id,dataMartTitle:x.title,configId:C,configuration:v}),f(!1)},g=x=>{const C=[],S=R=>{if(!n)return!0;const j=n.find(_=>_.name===R);return(j==null?void 0:j.required)??!1},E=(R,j,_=0,I=!0)=>{if(R.startsWith("_")||I&&_===0&&!S(R))return;let A=null;if(j==null)A="N/A";else if(typeof j=="string")A=j;else if(typeof j=="number"||typeof j=="boolean")A=String(j);else if(Array.isArray(j))A=JSON.stringify(j);else if(typeof j=="object"){C.push({key:R,value:"{",indent:_}),Object.entries(j).forEach(([O,T])=>{E(O,T,_+1,!1)}),C.push({key:"",value:"}",indent:_});return}else A=JSON.stringify(j);C.push({key:R,value:A,indent:_})};for(const[R,j]of Object.entries(x))E(R,j);return a.jsx("div",{className:"space-y-1 font-mono text-xs",children:C.map(({key:R,value:j,indent:_},I)=>a.jsxs("div",{className:"flex gap-2",style:{paddingLeft:`${String(_*12)}px`},children:[R&&a.jsxs("span",{className:"font-medium",children:[R,":"]}),a.jsx("span",{className:"text-muted-foreground truncate",title:j,children:j})]},I))})};return a.jsx(Ya,{children:a.jsxs(_r,{open:u,onOpenChange:f,children:[a.jsx(Nr,{asChild:!0,children:a.jsxs(Ee,{type:"button",variant:"ghost",size:"sm",className:"cursor-pointer",children:[a.jsx("span",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:"Copy from…"}),a.jsx(_a,{className:se("text-foreground/75 h-3.5 w-3.5 transition-transform duration-200",u&&"rotate-90")})]})}),a.jsx(Ar,{side:"bottom",align:"end",className:"w-72",children:i?a.jsx(Nt,{disabled:!0,children:"Loading…"}):r.length===0?a.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 p-4 text-center",children:[a.jsx("div",{className:"bg-muted/70 rounded-full p-3",children:a.jsx(GU,{className:"text-muted-foreground h-6 w-6",strokeWidth:1.5})}),a.jsx("span",{className:"text-foreground text-sm font-medium",children:"No matching Data Marts"}),a.jsx("span",{className:"text-muted-foreground text-sm",children:"You can reuse configuration settings only from connector-based Data Marts that use the same source."})]}):a.jsxs("div",{className:"flex flex-col gap-2",children:[a.jsx("div",{className:"text-muted-foreground border-b p-2 text-sm",children:"Select one of your existing Data Marts to reuse its configuration settings."}),a.jsx("div",{children:r.map(x=>{const C=x.definition.connector.source.configuration;return C.length===0?null:C.length===1?a.jsxs(Et,{delayDuration:300,children:[a.jsx(wt,{asChild:!0,children:a.jsxs(Nt,{onSelect:()=>{y(x,C[0])},children:[a.jsx(tg,{className:"text-foreground h-4 w-4"}),x.title]})}),a.jsx(Rt,{side:"right",className:"max-w-sm",children:g(C[0])})]},x.id):a.jsxs(TS,{children:[a.jsxs(_S,{className:"flex items-center gap-2",children:[a.jsx(tg,{className:"text-foreground h-4 w-4"}),a.jsx("span",{children:x.title})]}),a.jsx(NS,{children:C.map((S,E)=>a.jsxs(Et,{delayDuration:300,children:[a.jsx(wt,{asChild:!0,children:a.jsxs(Nt,{onSelect:()=>{y(x,S)},children:["Configuration ",E+1]})}),a.jsx(Rt,{side:"right",className:"max-w-sm",children:g(S)})]},E))})]},x.id)})})]})})]})})}function Q_({connector:e,connectorSpecification:t,onConfigurationChange:n,onValidationChange:r,initialConfiguration:s,loading:i=!1,isEditingExisting:c=!1}){const[u,f]=h.useState({}),m=h.useRef(!1),y=h.useRef(!1),[g,x]=h.useState({});h.useEffect(()=>{if(t){y.current=!0;const O={...s??{}};t.forEach(T=>{const D=Array.isArray(T.attributes)?T.attributes.includes("SECRET"):!1;O[T.name]===void 0&&T.default!==void 0&&(O[T.name]=T.default),c&&D&&(O[T.name]=Cb)}),f(O),m.current=!0,setTimeout(()=>{y.current=!1},0)}},[t,s,c]),h.useEffect(()=>{m.current&&s&&Object.keys(s).length>0&&(y.current=!0,f({...s}),setTimeout(()=>{y.current=!1},0))},[s]),h.useEffect(()=>{m.current&&!y.current&&Object.keys(u).length>0&&(n==null||n(u))},[u,n]);const v=(O,T)=>{f(D=>({...D,[O]:T}))},C=h.useCallback(O=>!(O==null||typeof O=="string"&&O.trim()===""||typeof O=="number"&&isNaN(O)||Array.isArray(O)&&O.length===0),[]),S=h.useCallback((O,T)=>{var k,B;if(typeof O!="object"||O===null)return C(O);if((k=T.attributes)!=null&&k.includes("OAUTH_FLOW")&&"_source_credential_id"in O)return!0;const D=(B=T.oneOf)==null?void 0:B.filter(G=>G.value===Object.keys(O)[0]);return D?D.every(G=>{var Y;if((Y=G.attributes)!=null&&Y.includes("OAUTH_FLOW")){const V=O[G.value];if(typeof V=="object"&&V!==null){if("_source_credential_id"in V)return!0;const Z=Object.entries(G.items).filter(([,F])=>F.required);if(Z.length>0)return Z.every(([F])=>{const M=V[F];return C(M)})}return!1}return Object.entries(G.items).every(([,V])=>G.value in O?S(O[G.value],V):!1)}):C(O[T.name])},[C]),E=h.useCallback((O,T)=>{const D=T.filter(Y=>Y.required&&Y.oneOf),k=D.length===0?!0:D.some(Y=>S(O[Y.name],Y)),G=T.filter(Y=>Y.required&&Y.name!=="Fields").every(Y=>C(O[Y.name]));return k&&G},[C,S]),R=(O,T)=>{x(D=>({...D,[O]:T})),f(T?D=>({...D,[O]:""}):D=>({...D,[O]:Cb}))},j=O=>{const T={...u};Object.entries(O.configuration).forEach(([D,k])=>{["_id","_copiedFrom"].includes(D)||(T[D]=k)}),T._copiedFrom={dataMartId:O.dataMartId,dataMartTitle:O.dataMartTitle,configId:O.configId},f(T)};if(h.useEffect(()=>{if(t&&r){const O=E(u,t);r(O)}},[u,t,r,E]),i)return a.jsx(D2,{variant:"list"});if(!t||t.length===0)return a.jsxs(ni,{children:[a.jsx(oc,{connector:e}),a.jsx(ti,{icon:a.jsx(Kf,{size:56,strokeWidth:1}),title:"No configuration found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),a.jsx($u,{label:"Need configuration?"})]});const _=[...t].filter(O=>{var T;return O.name!=="Fields"&&!((T=O.attributes)!=null&&T.includes("HIDE_IN_CONFIG_FORM"))}).sort((O,T)=>{const D=k=>{const B=k.default!=null&&k.default!=="";return k.required&&!B?1:k.required&&B?2:!k.required&&!B?3:4};return D(O)-D(T)}),I=_.filter(O=>{var T;return!((T=O.attributes)!=null&&T.includes("ADVANCED"))}),A=_.filter(O=>{var T;return(T=O.attributes)==null?void 0:T.includes("ADVANCED")});return a.jsx(a.Fragment,{children:a.jsxs(ni,{children:[a.jsx(oc,{connector:e}),a.jsxs(al,{children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("h3",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:"Configure Settings"}),a.jsx(Doe,{currentConnectorName:e.name,onCopyConfiguration:j,connectorSpecification:t})]}),I.length>0&&a.jsx(X_,{items:I,configuration:u,onValueChange:v,onSecretEditToggle:R,secretEditing:g,isEditingExisting:c,connectorName:e.name}),A.length>0&&a.jsx(X_,{collapsibleTitle:"Advanced Settings",items:A,configuration:u,onValueChange:v,onSecretEditToggle:R,secretEditing:g,isEditingExisting:c,connectorName:e.name})]})]})})}function Ooe({connector:e,connectorFields:t,selectedField:n,connectorName:r,loading:s=!1,onFieldSelect:i}){const c=r?`Select data for ${r}`:"Select data";return s?a.jsx(D2,{variant:"list"}):!t||t.length===0?a.jsxs(ni,{children:[a.jsx(oc,{connector:e}),a.jsx(ti,{icon:a.jsx(Kf,{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."}),a.jsx($u,{label:"Missing some data?"})]}):a.jsxs(ni,{children:[a.jsx(oc,{connector:e}),a.jsxs(al,{title:c,children:[t.map(u=>a.jsx(v6,{type:"radio",id:u.name,name:"selectedField",value:u.name,label:u.overview??u.name,checked:n===u.name,onChange:f=>{i(f)},tooltip:u.name&&a.jsxs("div",{className:"flex flex-col gap-2 py-1",children:[a.jsxs("p",{children:[a.jsx("span",{className:"font-semibold",children:"Table name:"})," ",u.destinationName??u.name]}),u.description&&a.jsxs("p",{children:[a.jsx("span",{className:"font-semibold",children:"Description:"})," ",u.description]}),u.documentation&&a.jsxs(Wr,{to:u.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",a.jsx(_a,{className:"h-3 w-3"})]})]}),selected:n===u.name},u.name)),a.jsx($u,{label:"Missing some data?"})]})]})}var ao=(e=>(e.ASC="asc",e.DESC="desc",e.ORIGINAL="original",e))(ao||{});function J_({connector:e,connectorFields:t,selectedField:n,selectedFields:r,onFieldToggle:s}){const i=h.useRef(null),[c,u]=h.useState(""),[f,m]=h.useState(ao.ORIGINAL),y=t==null?void 0:t.find(R=>R.name===n),g=h.useMemo(()=>(y==null?void 0:y.fields)??[],[y==null?void 0:y.fields]),x=h.useMemo(()=>(y==null?void 0:y.uniqueKeys)??[],[y==null?void 0:y.uniqueKeys]),v=h.useMemo(()=>{const R=new Map;return g.forEach((j,_)=>R.set(j.name,_)),R},[g]),C=h.useMemo(()=>{const R=g.filter(_=>_.name.toLowerCase().includes(c.toLowerCase().trim())),j=(_,I)=>{const A=x.includes(_.name),O=x.includes(I.name);if(A&&!O)return-1;if(!A&&O)return 1;if(f===ao.ASC)return _.name.localeCompare(I.name);if(f===ao.DESC)return I.name.localeCompare(_.name);const T=v.get(_.name)??0,D=v.get(I.name)??0;return T-D};return[...R].sort(j)},[g,c,x,f,v]),S=g.map(R=>R.name),E=r.filter(R=>S.includes(R)).length;return h.useEffect(()=>{if(x.length>0){const R=x.filter(j=>g.some(_=>_.name===j)&&!r.includes(j));R.length>0&&R.forEach(j=>{s(j,!0)})}},[n,x,g,r,s]),h.useEffect(()=>{const R=j=>{const I=(j.ctrlKey||j.metaKey)&&j.shiftKey&&j.key.toLowerCase()==="a",A=document.activeElement.tagName;if(!(A==="INPUT"||A==="TEXTAREA")&&I){j.preventDefault();const O=g.map(k=>k.name),D=O.filter(k=>!r.includes(k)).length>0;O.forEach(k=>{s(k,D)})}};return window.addEventListener("keydown",R),()=>{window.removeEventListener("keydown",R)}},[g,r,s]),!n||!t?a.jsxs(ni,{children:[a.jsx(oc,{connector:e}),a.jsx(ti,{icon:a.jsx(Kf,{size:56,strokeWidth:1}),title:"No fields found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),a.jsx($u,{label:"Need fields?"})]}):g.length?a.jsx(ni,{children:a.jsxs(a.Fragment,{children:[a.jsx(oc,{connector:e}),a.jsxs("div",{className:"border-border -mt-6 mb-6 flex w-full items-center gap-2 border-b",children:[a.jsxs("div",{className:"relative flex-1",children:[a.jsx(wc,{className:"text-muted-foreground absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 cursor-text",onClick:()=>{var R;(R=i.current)==null||R.focus()}}),a.jsx("input",{ref:i,type:"text",placeholder:"Search field",value:c,onChange:R=>{u(R.target.value)},className:"h-12 w-full rounded-none border-0 pl-9 text-sm outline-none"}),c&&a.jsx("button",{type:"button",onClick:()=>{u("")},className:"text-muted-foreground hover:text-foreground absolute top-1/2 right-0 -translate-y-1/2",children:a.jsx(Zu,{className:"h-4 w-4"})})]}),a.jsxs(_r,{children:[a.jsx(Nr,{asChild:!0,children:a.jsxs(Ee,{variant:"ghost",size:"icon","aria-label":"Sort fields",children:[f===ao.ASC&&a.jsx(Wj,{className:"text-muted-foreground h-4 w-4"}),f===ao.DESC&&a.jsx(Yj,{className:"text-muted-foreground h-4 w-4"}),f===ao.ORIGINAL&&a.jsx(Xj,{className:"text-muted-foreground h-4 w-4"})]})}),a.jsxs(Ar,{align:"end",children:[a.jsxs(Nt,{onSelect:()=>{m(ao.ASC)},children:[a.jsx(Wj,{className:"text-muted-foreground mr-2 h-4 w-4"}),"A–Z"]}),a.jsxs(Nt,{onSelect:()=>{m(ao.DESC)},children:[a.jsx(Yj,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Z–A"]}),a.jsxs(Nt,{onSelect:()=>{m(ao.ORIGINAL)},children:[a.jsx(Xj,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Original"]})]})]})]}),a.jsxs(al,{title:`Selected ${String(E)} of ${String(S.length)} fields for "${n}" data`,children:[C.map(R=>{const j=x.includes(R.name);return a.jsx(v6,{type:"checkbox",id:`field-${R.name}`,name:"selectedFields",value:R.name,checked:r.includes(R.name),selected:r.includes(R.name)||j,disabled:j,onChange:_=>{s(R.name,_)},label:R.name,tooltip:a.jsxs("div",{className:"flex flex-col gap-2 py-1",children:[j&&a.jsxs("p",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"font-semibold",children:"Unique key"})," ",a.jsx(N1,{className:"text-secondary h-3 w-3"})]}),a.jsxs("p",{children:[a.jsx("span",{className:"font-semibold",children:"Type:"})," ",R.type]}),R.description&&a.jsxs("p",{children:[a.jsx("span",{className:"font-semibold",children:"Description:"})," ",R.description]})]}),rightIcon:j?a.jsx(N1,{className:"text-muted-foreground/75 h-4 w-4"}):void 0},R.name)}),C.length===0&&c&&a.jsxs("div",{className:"text-muted-foreground pt-8 pb-4 text-center text-sm",children:['No fields match "',c,'"']}),a.jsx($u,{label:"Need another field?"})]})]})}):a.jsxs(ni,{children:[a.jsx(oc,{connector:e}),a.jsx(ti,{icon:a.jsx(Kf,{size:56,strokeWidth:1}),title:"No fields found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),a.jsx($u,{label:"Need fields?"})]})}const hI=h.createContext(void 0),mI={triggers:[],selectedTrigger:null,isLoading:!1,error:null};function Ioe(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 mI;default:return e}}class Moe extends bl{constructor(){super("/data-marts")}async getScheduledTriggers(t){return this.get(`/${t}/scheduled-triggers`)}async getScheduledTrigger(t,n){return this.get(`/${t}/scheduled-triggers/${n}`)}async createScheduledTrigger(t,n){return this.post(`/${t}/scheduled-triggers`,n)}async updateScheduledTrigger(t,n,r){return this.put(`/${t}/scheduled-triggers/${n}`,r)}async deleteScheduledTrigger(t,n){return this.delete(`/${t}/scheduled-triggers/${n}`)}}const so=new Moe;var Fn=(e=>(e.REPORT_RUN="REPORT_RUN",e.CONNECTOR_RUN="CONNECTOR_RUN",e))(Fn||{});const sl={SCHEDULED_REPORT_RUN:"scheduled-report-run-config"};class Eb{mapFromDto(t){return{id:t.id,type:t.type,cronExpression:t.cronExpression,timeZone:t.timeZone,isActive:t.isActive,nextRun:t.nextRunTimestamp?new Date(t.nextRunTimestamp):null,lastRun:t.lastRunTimestamp?new Date(t.lastRunTimestamp):null,triggerConfig:t.triggerConfig,createdById:t.createdById,createdAt:new Date(t.createdAt),modifiedAt:new Date(t.modifiedAt)}}async enhanceWithReportData(t){if(t.type!==Fn.REPORT_RUN)return t;const n=t.triggerConfig;if(!n.reportId)return t;try{const r=await Yo.getReportById(n.reportId),s=Jl(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:Fn.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 koe{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:Fn.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 i1={getMapper(e){switch(e){case Fn.REPORT_RUN:return new Eb;case Fn.CONNECTOR_RUN:return new koe;default:throw new Error(`Unknown scheduled trigger type: ${String(e)}`)}}},Rf={mapFromDto(e){return i1.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 Fn.REPORT_RUN:return new Eb().enhanceWithReportData(n);case Fn.CONNECTOR_RUN:{const r=t.definition;return{...n,triggerConfig:{...n.triggerConfig,connector:r}}}default:return n}},async mapFromDtoListWithReportData(e,t){const n=new Eb,r=this.mapFromDtoList(e),s=r.filter(c=>c.type===Fn.REPORT_RUN),i=await n.enhanceTriggersWithReportData(s);return r.map(c=>{switch(c.type){case Fn.REPORT_RUN:return i.find(u=>u.id===c.id)??c;case Fn.CONNECTOR_RUN:{const u=t.definition;return{...c,triggerConfig:{...c.triggerConfig,connector:u}}}default:return c}})},mapToCreateRequest(e){return i1.getMapper(e.type).mapToCreateRequest(e)},mapToUpdateRequest(e){return i1.getMapper(e.type).mapToUpdateRequest(e)}};function Loe({children:e}){const[t,n]=h.useReducer(Ioe,mI),{dataMart:r}=Ss(),{fetchAvailableConnectors:s}=Dc();if(!r)throw new Error("Trigger provider must be used within a data mart context");const i=h.useCallback(async v=>{await s(),n({type:"FETCH_TRIGGERS_START"});try{const C=await so.getScheduledTriggers(v),S=await Rf.mapFromDtoListWithReportData(C,r);n({type:"FETCH_TRIGGERS_SUCCESS",payload:S})}catch(C){const S=C instanceof Error?C.message:"Failed to fetch scheduled triggers";n({type:"FETCH_TRIGGERS_ERROR",payload:S}),Le({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"ListError",label:S})}},[r,s]),c=h.useCallback(async(v,C)=>{n({type:"FETCH_TRIGGERS_START"});try{const E=(await so.getScheduledTriggers(v)).filter(j=>j.type===C),R=await Rf.mapFromDtoListWithReportData(E,r);n({type:"FETCH_TRIGGERS_SUCCESS",payload:R})}catch(S){const E=S instanceof Error?S.message:"Failed to fetch scheduled triggers";n({type:"FETCH_TRIGGERS_ERROR",payload:E}),Le({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"ListError",label:E})}},[r]),u=h.useCallback(async(v,C)=>{n({type:"FETCH_TRIGGER_START"});try{const S=await so.getScheduledTrigger(v,C),E=await Rf.mapFromDtoWithReportData(S,r);n({type:"FETCH_TRIGGER_SUCCESS",payload:E})}catch(S){const E=S instanceof Error?S.message:"Failed to fetch scheduled trigger";n({type:"FETCH_TRIGGER_ERROR",payload:E}),Le({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"GetError",label:E})}},[r]),f=h.useCallback(async(v,C,S,E,R,j)=>{n({type:"CREATE_TRIGGER_START"});try{const _={type:C,cronExpression:S,timeZone:E,isActive:R,triggerConfig:j},I=await so.createScheduledTrigger(v,_),A=await Rf.mapFromDtoWithReportData(I,r);return n({type:"CREATE_TRIGGER_SUCCESS",payload:A}),Le({event:"scheduled_trigger_created",category:"ScheduledTrigger",action:"Create",label:C}),Dn.success("Trigger created"),A}catch(_){const I=_ instanceof Error?_.message:"Failed to create scheduled trigger";throw n({type:"CREATE_TRIGGER_ERROR",payload:I}),Le({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"CreateError",label:I}),_}},[r]),m=h.useCallback(async(v,C,S,E,R)=>{n({type:"UPDATE_TRIGGER_START"});try{const j={cronExpression:S,timeZone:E,isActive:R},_=await so.updateScheduledTrigger(v,C,j),I=await Rf.mapFromDtoWithReportData(_,r);n({type:"UPDATE_TRIGGER_SUCCESS",payload:I}),Le({event:"scheduled_trigger_updated",category:"ScheduledTrigger",action:"Update",label:I.type}),Dn.success("Trigger updated")}catch(j){const _=j instanceof Error?j.message:"Failed to update scheduled trigger";throw n({type:"UPDATE_TRIGGER_ERROR",payload:_}),Le({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"UpdateError",label:_}),j}},[r]),y=h.useCallback(async(v,C)=>{n({type:"DELETE_TRIGGER_START"});try{await so.deleteScheduledTrigger(v,C),n({type:"DELETE_TRIGGER_SUCCESS",payload:C}),Le({event:"scheduled_trigger_deleted",category:"ScheduledTrigger",action:"Delete",label:C}),Dn.success("Trigger deleted")}catch(S){const E=S instanceof Error?S.message:"Failed to delete scheduled trigger";throw n({type:"DELETE_TRIGGER_ERROR",payload:E}),Le({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"DeleteError",label:E}),S}},[]),g=h.useCallback(v=>{n({type:"SELECT_TRIGGER",payload:v})},[]),x=h.useCallback(()=>{n({type:"RESET"})},[]);return a.jsx(hI.Provider,{value:{...t,getScheduledTriggers:i,getScheduledTriggersByType:c,getScheduledTrigger:u,createScheduledTrigger:f,updateScheduledTrigger:m,deleteScheduledTrigger:y,selectScheduledTrigger:g,reset:x},children:e})}function pI(){const e=h.useContext(hI);if(e===void 0)throw new Error("useScheduledTriggerContext must be used within a ScheduledTriggerProvider");return e}function Poe(e){const{getScheduledTriggers:t,getScheduledTriggersByType:n,getScheduledTrigger:r,createScheduledTrigger:s,updateScheduledTrigger:i,deleteScheduledTrigger:c,selectScheduledTrigger:u,reset:f,triggers:m,selectedTrigger:y,isLoading:g,error:x}=pI();return h.useEffect(()=>(e?t(e):f(),()=>{f()}),[e,t,f]),{triggers:m,selectedTrigger:y,isLoading:g,error:x,getScheduledTriggers:v=>t(v),getScheduledTriggersByType:(v,C)=>n(v,C),getScheduledTrigger:(v,C)=>r(v,C),createScheduledTrigger:(v,C,S,E,R,j)=>s(v,C,S,E,R,j),updateScheduledTrigger:(v,C,S,E,R)=>i(v,C,S,E,R),deleteScheduledTrigger:(v,C)=>c(v,C),selectScheduledTrigger:u}}const Uoe=rn({type:Br(sl.SCHEDULED_REPORT_RUN),reportId:Dt().min(1,"Report ID is required")}),zoe=YZ(),Foe=rn({type:Sy(Fn),cronExpression:Dt().min(1,"Cron expression is required"),timeZone:Dt().min(1,"Time zone is required"),isActive:ZZ(),triggerConfig:XZ([Uoe,zoe])});function Hoe({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:r}){const s=Ro({resolver:yi(Foe),defaultValues:{type:e?e.type:n??Fn.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:sl.SCHEDULED_REPORT_RUN,reportId:t??""}}});h.useEffect(()=>{t&&s.getValues("type")===Fn.REPORT_RUN&&s.setValue("triggerConfig",{type:sl.SCHEDULED_REPORT_RUN,reportId:t})},[t,s]),h.useEffect(()=>{n&&(s.setValue("type",n),n===Fn.REPORT_RUN?s.setValue("triggerConfig",{type:sl.SCHEDULED_REPORT_RUN,reportId:t??""}):s.setValue("triggerConfig",null))},[n,t,s]);const i=u=>{s.setValue("type",u),u===Fn.REPORT_RUN?s.setValue("triggerConfig",{type:sl.SCHEDULED_REPORT_RUN,reportId:t??""}):s.setValue("triggerConfig",null)},c=async u=>{try{await r(u)}catch(f){console.error("Error submitting form:",f)}};return{form:s,handleTypeChange:i,handleSubmit:s.handleSubmit(c),isDirty:s.formState.isDirty}}const $oe=[Ne.GOOGLE_SHEETS,Ne.EMAIL,Ne.SLACK,Ne.MS_TEAMS,Ne.GOOGLE_CHAT];function Voe({value:e,onChange:t,disabled:n}){const{reports:r,fetchReportsByDataMartId:s}=ts(),{dataMart:i}=Ss();h.useEffect(()=>{i&&s(i.id)},[s,i]);const c=r.filter(u=>$oe.includes(u.dataDestination.type));return a.jsxs(ca,{value:e,onValueChange:t,disabled:n,children:[a.jsx(da,{className:"w-full",children:a.jsx(ua,{placeholder:"Select a report"})}),a.jsx(fa,{children:c.map(u=>{const f=aa.getInfo(u.dataDestination.type).icon;return a.jsx(Gn,{value:u.id,children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(f,{className:"h-4 w-4",size:16}),a.jsx("span",{children:u.title})]})},u.id)})})]})}var Ky="Switch",[Boe]=Sr(Ky),[Goe,qoe]=Boe(Ky),gI=h.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:s,defaultChecked:i,required:c,disabled:u,value:f="on",onCheckedChange:m,form:y,...g}=e,[x,v]=h.useState(null),C=ht(t,_=>v(_)),S=h.useRef(!1),E=x?y||!!x.closest("form"):!0,[R,j]=ia({prop:s,defaultProp:i??!1,onChange:m,caller:Ky});return a.jsxs(Goe,{scope:n,checked:R,disabled:u,children:[a.jsx(Je.button,{type:"button",role:"switch","aria-checked":R,"aria-required":c,"data-state":bI(R),"data-disabled":u?"":void 0,disabled:u,value:f,...g,ref:C,onClick:Ie(e.onClick,_=>{j(I=>!I),E&&(S.current=_.isPropagationStopped(),S.current||_.stopPropagation())})}),E&&a.jsx(vI,{control:x,bubbles:!S.current,name:r,value:f,checked:R,required:c,disabled:u,form:y,style:{transform:"translateX(-100%)"}})]})});gI.displayName=Ky;var yI="SwitchThumb",xI=h.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,s=qoe(yI,n);return a.jsx(Je.span,{"data-state":bI(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:t})});xI.displayName=yI;var Koe="SwitchBubbleInput",vI=h.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...s},i)=>{const c=h.useRef(null),u=ht(c,i),f=b2(n),m=mS(t);return h.useEffect(()=>{const y=c.current;if(!y)return;const g=window.HTMLInputElement.prototype,v=Object.getOwnPropertyDescriptor(g,"checked").set;if(f!==n&&v){const C=new Event("click",{bubbles:r});v.call(y,n),y.dispatchEvent(C)}},[f,n,r]),a.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...s,tabIndex:-1,ref:u,style:{...s.style,...m,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});vI.displayName=Koe;function bI(e){return e?"checked":"unchecked"}var Zoe=gI,Yoe=xI;function Z2({className:e,...t}){return a.jsx(Zoe,{"data-slot":"switch",className:se("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 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 dark:data-[state=unchecked]:bg-white/16",e),...t,children:a.jsx(Yoe,{"data-slot":"switch-thumb",className:se("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 Woe(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 wb(e,t="UTC"){const n=Woe(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:i,month:c,dayOfWeek:u}=n;if(r.startsWith("*/")&&s==="*"&&i==="*"&&c==="*"&&u==="*"){const g=Number.parseInt(r.substring(2));if(!isNaN(g))return{type:"interval",time:"09:00",weekdays:[1,2,3,4,5],monthDays:[1],customCron:e,intervalType:"minutes",intervalValue:g,timezone:t}}if(r!=="*"&&s.startsWith("*/")&&i==="*"&&c==="*"&&u==="*"){const g=Number.parseInt(s.substring(2));if(!isNaN(g)&&r==="0")return{type:"interval",time:"09:00",weekdays:[1,2,3,4,5],monthDays:[1],customCron:e,intervalType:"hours",intervalValue:g,timezone:t}}const f=Number.parseInt(r),m=Number.parseInt(s),y=!isNaN(f)&&!isNaN(m)?`${m.toString().padStart(2,"0")}:${f.toString().padStart(2,"0")}`:"09:00";if(!isNaN(f)&&!isNaN(m)&&i==="*"&&c==="*"&&u==="*")return{type:"daily",time:y,weekdays:[1,2,3,4,5],monthDays:[1],customCron:e,intervalType:"minutes",intervalValue:15,timezone:t};if(!isNaN(f)&&!isNaN(m)&&i==="*"&&c==="*"&&u!=="*"){const g=u.split(",").map(x=>Number.parseInt(x.trim())).filter(x=>!isNaN(x)&&x>=0&&x<=6);if(g.length>0)return{type:"weekly",time:y,weekdays:g,monthDays:[1],customCron:e,intervalType:"minutes",intervalValue:15,timezone:t}}if(!isNaN(f)&&!isNaN(m)&&i!=="*"&&c==="*"&&u==="*"){const g=i.split(",").map(x=>Number.parseInt(x.trim())).filter(x=>!isNaN(x)&&x>=1&&x<=31);if(g.length>0)return{type:"monthly",time:y,weekdays:[1,2,3,4,5],monthDays:g,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 SI({options:e,selected:t,onSelectionChange:n,placeholder:r="Select items...",searchPlaceholder:s="Search...",maxDisplayItems:i=3}){const[c,u]=h.useState(!1),f=g=>{const x=t.includes(g)?t.filter(v=>v!==g):[...t,g].sort((v,C)=>v-C);n(x)},m=(g,x)=>{x.preventDefault(),x.stopPropagation(),n(t.filter(v=>v!==g))},y=()=>{if(t.length===0)return a.jsx("span",{className:"text-muted-foreground text-sm",children:r});const g=t.map(x=>e.find(v=>v.value===x)).filter(Boolean);return g.length<=i?a.jsx("div",{className:"flex flex-wrap gap-1",children:g.map(x=>a.jsxs(jr,{variant:"secondary",className:"h-5 text-xs",children:[x.label,a.jsx("span",{className:"hover:bg-secondary-foreground/20 ml-1 inline-flex cursor-pointer items-center justify-center rounded-full p-0.5",onClick:v=>m(x.value,v),children:a.jsx(Zu,{className:"h-2 w-2"})})]},x.value))}):a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsxs(jr,{variant:"secondary",className:"h-5 text-xs",children:[g[0].label,a.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(g[0].value,x),children:a.jsx(Zu,{className:"h-2 w-2"})})]}),g.length>1&&a.jsxs(jr,{variant:"outline",className:"h-5 text-xs",children:["+",g.length-1]})]})};return a.jsxs(F2,{open:c,onOpenChange:u,modal:!0,children:[a.jsx(H2,{asChild:!0,children:a.jsxs(Ee,{variant:"outline",role:"combobox","aria-expanded":c,className:"h-9 min-h-9 w-full justify-between bg-transparent py-1",children:[a.jsx("div",{className:"flex-1 text-left",children:y()}),a.jsx(Qb,{className:"ml-2 h-3 w-3 shrink-0 opacity-50"})]})}),a.jsx($2,{className:"max-h-[400px] w-full overflow-y-auto p-0",style:{padding:0},children:a.jsxs(Y6,{className:"h-full overflow-visible",children:[a.jsx(W6,{placeholder:s,className:"h-8"}),a.jsxs(pse,{className:"h-full max-h-[350px] overflow-y-auto",children:[a.jsx(X6,{children:"No items found."}),a.jsx(Q6,{className:"h-full overflow-visible",children:e.map(g=>a.jsxs(J6,{value:g.value.toString(),onSelect:()=>f(g.value),className:"text-sm",children:[a.jsx(oa,{className:se("mr-2 h-3 w-3",t.includes(g.value)?"opacity-100":"opacity-0")}),g.label]},g.value))})]})]})})]})}const CI=[{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"}],Op=()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}};function EI(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 i;return(i=CI.find(c=>c.value===s))==null?void 0:i.label}).join(", ")} at ${n}`;case"monthly":{const s=[...e.monthDays].sort((c,u)=>c-u).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 Xoe(e,t,n=!0){const r=wb(e,t);return EI(r,n)}const Qoe=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],jb=[1,2,3,4,6,8,12],Joe=({value:e,onChange:t,disabled:n})=>a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ta,{children:"Type"}),a.jsxs(ca,{value:e,onValueChange:r=>{t(r)},disabled:n,children:[a.jsx(da,{className:"w-full",children:a.jsx(ua,{})}),a.jsxs(fa,{children:[a.jsx(Gn,{value:"daily",children:"Daily"}),a.jsx(Gn,{value:"weekly",children:"Weekly"}),a.jsx(Gn,{value:"monthly",children:"Monthly"}),a.jsx(Gn,{value:"interval",children:"Interval"})]})]})]}),eie=({value:e,onChange:t,disabled:n})=>a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ta,{children:"Time"}),a.jsx("div",{className:"flex items-center gap-2",children:a.jsx(It,{className:"w-24",type:"time",value:e,onChange:r=>{t(r.target.value)},disabled:n})})]}),eN=({value:e,onChange:t,disabled:n,timezones:r})=>a.jsxs("div",{className:"w-full space-y-2",children:[a.jsx(Ta,{children:"Timezone"}),a.jsx("div",{className:"flex items-center gap-2",children:a.jsx(V2,{options:r,value:e,onValueChange:t,placeholder:"Select timezone",emptyMessage:"No timezones found",disabled:n,className:"w-full"})})]}),tie=({value:e,onChange:t,disabled:n})=>a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ta,{children:"Days of Week"}),a.jsx("div",{className:n?"pointer-events-none":"",children:a.jsx(SI,{options:CI,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:3})})]}),nie=({value:e,onChange:t,disabled:n})=>a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ta,{children:"Days of Month"}),a.jsx("div",{className:n?"pointer-events-none":"",children:a.jsx(SI,{options:Qoe,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:4})})]}),rie=({intervalType:e,intervalValue:t,onTypeChange:n,onValueChange:r,disabled:s})=>a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ta,{children:"Type"}),a.jsxs(ca,{value:e,onValueChange:i=>{n(i)},disabled:s,children:[a.jsx(da,{className:"w-full",children:a.jsx(ua,{})}),a.jsxs(fa,{children:[a.jsx(Gn,{value:"minutes",children:"Minutes"}),a.jsx(Gn,{value:"hours",children:"Hours"})]})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ta,{children:"Every"}),a.jsxs(ca,{value:t.toString(),onValueChange:i=>{r(Number.parseInt(i)||1)},disabled:s,children:[a.jsx(da,{className:"w-full",children:a.jsx(ua,{})}),a.jsx(fa,{children:(e==="minutes"?Rb:jb).map(i=>a.jsxs(Gn,{value:i.toString(),children:[i," ",e==="minutes"?"min":"hr"]},i))})]})]})]}),aie=({value:e,onChange:t,disabled:n})=>a.jsxs("div",{className:"space-y-1",children:[a.jsx(Ta,{className:"text-sm",children:"Cron Expression"}),a.jsx(It,{value:e,onChange:r=>{t(r.target.value)},placeholder:"0 9 * * *",className:"h-9 font-mono text-sm",disabled:n}),a.jsx("p",{className:"text-muted-foreground text-xs",children:"Format: minute hour day month day-of-week"})]});function Tb({cron:e="0 9 * * *",timezone:t,enabled:n=!0,onChange:r,className:s,showPreview:i=!0,showSaveButton:c=!1,hideEnableSwitch:u=!1}){const[f,m]=h.useState(n),[y,g]=h.useState(t??Op()),[x,v]=h.useState(!1),C=h.useMemo(()=>vW.getTimezonesWithOffset().map(F=>({value:F.identifier,label:F.displayName,offset:F.offsetString,isDST:F.isDST})),[]),[S,E]=h.useState(()=>wb(e,y)),[R,j]=h.useState(""),[_,I]=h.useState("");h.useEffect(()=>{m(n)},[n]),h.useEffect(()=>{const F=t??Op();g(F)},[t]),h.useEffect(()=>{if(e){const F=wb(e,y);E(F)}},[e,y]);const A=F=>{const[M,$]=F.time.split(":").map(Number);switch(F.type){case"daily":return`${String($)} ${String(M)} * * *`;case"weekly":return`${String($)} ${String(M)} * * ${F.weekdays.join(",")}`;case"monthly":return`${String($)} ${String(M)} ${F.monthDays.join(",")} * *`;case"interval":return F.intervalType==="minutes"?`*/${String(F.intervalValue)} * * * *`:`0 */${String(F.intervalValue)} * * *`;case"custom":return F.customCron;default:return`${String($)} ${String(M)} * * *`}},O=h.useCallback(F=>{E(M=>{if(M.intervalType===F)return console.log("Type unchanged, skipping update"),M;const H=(F==="minutes"?Rb:jb)[0];return{...M,intervalType:F,intervalValue:H}})},[]),T=h.useCallback(F=>{E(M=>(M.intervalType==="minutes"?Rb:jb).includes(F)?{...M,intervalValue:F}:M)},[]),D=h.useMemo(()=>F=>EI(F,f),[f]);h.useEffect(()=>{const F=A(S);j(F),I(D(S))},[S,f,y,D]);const k=h.useRef(""),B=h.useRef(""),G=h.useRef(!1);h.useEffect(()=>{const F=A(S);r&&(k.current!==F||B.current!==y||G.current!==f)&&(r({cron:F,timezone:y,enabled:f}),k.current=F,B.current=y,G.current=f)},[S,y,f,r]);const Y=F=>{m(F)},V=F=>{g(F),E(M=>({...M,timezone:F}))},Z=["daily","weekly","monthly"].includes(S.type);return a.jsxs("div",{className:s,children:[!u&&a.jsx("div",{className:"mb-4 space-y-4 pt-0",children:a.jsx("div",{className:"flex items-center justify-end",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ta,{htmlFor:"schedule-enabled",className:"text-sm font-normal",children:f?"Enabled":"Disabled"}),a.jsx(Z2,{id:"schedule-enabled",checked:f,onCheckedChange:Y})]})})}),a.jsxs("div",{className:"space-y-4 pt-0",children:[a.jsxs("div",{className:`space-y-4 ${f?"":"opacity-50"}`,children:[a.jsx(Joe,{value:S.type,onChange:F=>{E(M=>({...M,type:F}))},disabled:!f}),S.type!=="custom"&&S.type!=="interval"&&a.jsxs("div",{className:"flex gap-3",children:[a.jsx(eie,{value:S.time,onChange:F=>{E(M=>({...M,time:F}))},disabled:!f}),Z&&a.jsx(eN,{value:y,onChange:V,disabled:!f,timezones:C})]}),(S.type==="interval"||S.type==="custom")&&a.jsx(eN,{value:y,onChange:V,disabled:!f,timezones:C}),S.type==="weekly"&&a.jsx(tie,{value:S.weekdays,onChange:F=>{E(M=>({...M,weekdays:F}))},disabled:!f}),S.type==="monthly"&&a.jsx(nie,{value:S.monthDays,onChange:F=>{E(M=>({...M,monthDays:F}))},disabled:!f}),S.type==="interval"&&a.jsx(rie,{intervalType:S.intervalType,intervalValue:S.intervalValue,onTypeChange:O,onValueChange:T,disabled:!f}),S.type==="custom"&&a.jsx(aie,{value:S.customCron,onChange:F=>{E(M=>({...M,customCron:F}))},disabled:!f})]}),i&&a.jsxs(a.Fragment,{children:[a.jsx(BA,{className:"my-3"}),a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"flex cursor-pointer items-center justify-between",onClick:()=>{v(!x)},children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(TA,{className:"h-4 w-4"}),a.jsx("span",{className:"text-sm font-medium",children:"Preview"})]}),x?a.jsx(qu,{className:"text-muted-foreground h-4 w-4"}):a.jsx(Bs,{className:"text-muted-foreground h-4 w-4"})]}),x&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"grid gap-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-muted-foreground text-xs",children:"Status:"}),a.jsx(jr,{variant:f?"default":"secondary",className:"text-xs",children:f?"Enabled":"Disabled"})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-muted-foreground text-xs",children:"Cron:"}),a.jsx(jr,{variant:"secondary",className:"font-mono text-xs",children:R})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-muted-foreground text-xs",children:"Timezone:"}),a.jsx(jr,{variant:"outline",className:"text-xs",children:y})]}),a.jsxs("div",{className:"flex items-start justify-between gap-2",children:[a.jsx("span",{className:"text-muted-foreground text-xs",children:"Schedule:"}),a.jsx("span",{className:"flex-1 text-right text-xs",children:_})]})]}),f&&Z&&y!==Op()&&a.jsxs(G2,{className:"border-amber-200 bg-amber-50",children:[a.jsx(gh,{className:"h-4 w-4"}),a.jsx(dI,{children:"Time Zone"}),a.jsxs(q2,{children:["Schedule runs in ",y," (not your local ",Op()," ","time). Execution time may differ from expected."]})]})]})]})]}),c&&a.jsx(Ee,{className:"w-full",disabled:!f,children:"Save Schedule"})]})]})}function sie(){return a.jsx(Cn,{variant:"common",type:"single",collapsible:!0,children:a.jsxs(Kt,{value:"trigger-type-options-description-details",children:[a.jsx(Zt,{children:"How do I choose a type?"}),a.jsxs(Yt,{children:[a.jsxs("p",{className:"mb-2",children:[a.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)."]}),a.jsxs("p",{className:"mb-2",children:[a.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 oie(){return a.jsx(Cn,{variant:"common",type:"single",collapsible:!0,children:a.jsxs(Kt,{value:"trigger-type-change-description-details",children:[a.jsx(Zt,{children:"How do I change the trigger type?"}),a.jsx(Yt,{children:a.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 iie(){return a.jsx(Cn,{variant:"common",type:"single",collapsible:!0,children:a.jsxs(Kt,{value:"report-change-description-details",children:[a.jsx(Zt,{children:"How do I change a report?"}),a.jsx(Yt,{children:a.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 lie(){return a.jsx(Cn,{variant:"common",type:"single",collapsible:!0,children:a.jsxs(Kt,{value:"report-select-description-details",children:[a.jsx(Zt,{children:"How do I choose the report?"}),a.jsxs(Yt,{children:[a.jsx("p",{className:"mb-2",children:"For a Report Run trigger, select one of the available Destinations (e.g., a Google Sheets report)."}),a.jsxs("p",{children:["You can use an existing one or create a new one on the ",a.jsx("strong",{children:"Destinations"})," tab"," ","of this Data Mart."]})]})]})})}function cie({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:r,onCancel:s,onDirtyChange:i}){const[c,u]=h.useState(!1),{form:f,handleTypeChange:m,handleSubmit:y,isDirty:g}=Hoe({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:async E=>{u(!0);try{await r(E)}finally{u(!1)}}});h.useEffect(()=>{i==null||i(g)},[g,i]);const{control:x,watch:v}=f,S=v("type")===Fn.REPORT_RUN;return a.jsx(_l,{...f,children:a.jsxs(gi,{onSubmit:E=>void y(E),noValidate:!1,children:[a.jsxs(Nl,{children:[a.jsx(_t,{control:x,name:"type",render:({field:E})=>a.jsxs(xt,{children:[a.jsx(yt,{tooltip:"Choose what you want this trigger to run - a report or a connector",children:"Trigger Type"}),a.jsxs(ca,{onValueChange:R=>{E.onChange(R),m(R)},defaultValue:E.value,disabled:!!n||!!e||!!v("triggerConfig.reportId"),children:[a.jsx(Ct,{children:a.jsx(da,{className:"w-full",children:a.jsx(ua,{placeholder:"Select trigger type"})})}),a.jsxs(fa,{children:[a.jsx(Gn,{value:Fn.REPORT_RUN,children:"Report Run"}),a.jsx(Gn,{value:Fn.CONNECTOR_RUN,children:"Connector Run"})]})]}),a.jsx(xn,{children:e?a.jsx(oie,{}):a.jsx(sie,{})}),a.jsx(Mt,{})]})}),S&&a.jsx(_t,{control:x,name:"triggerConfig.reportId",render:({field:E})=>a.jsxs(xt,{children:[a.jsx(yt,{tooltip:"Select the report that will be run by this trigger",children:"Report"}),a.jsx(Ct,{children:a.jsx(BS,{children:a.jsx(Voe,{value:E.value,onChange:E.onChange,disabled:!!t||!!e})})}),a.jsx(xn,{children:e!=null&&e.triggerConfig?a.jsx(iie,{}):a.jsx(lie,{})}),a.jsx(Mt,{})]})}),a.jsx(Tb,{showPreview:!1,cron:v("cronExpression"),timezone:v("timeZone"),enabled:v("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"})]}),a.jsxs(Oc,{children:[a.jsx(Ee,{variant:"default",type:"submit",className:"w-full","aria-label":e?"Save changes":"Create trigger",disabled:!g||c,children:c?e?"Saving...":"Creating...":e?"Save changes":"Create trigger"}),s&&a.jsx(Ee,{variant:"outline",type:"button",onClick:s,className:"w-full","aria-label":"Cancel",children:"Cancel"})]})]})})}function uie({cronExpression:e,timeZone:t,isEnabled:n=!0}){const r=h.useMemo(()=>Xoe(e,t,n),[e,t,n]);return a.jsxs("div",{children:[a.jsx("div",{children:r}),n&&a.jsx("code",{className:"text-muted-foreground mt-1 block text-xs",children:t})]})}function die({trigger:e,onEditTrigger:t,onDeleteTrigger:n}){const[r,s]=h.useState(!1),[i,c]=h.useState(!1),u=()=>{c(!1),n(e.id)};return a.jsxs("div",{className:"text-right",onClick:f=>{f.stopPropagation()},children:[a.jsxs(_r,{open:r,onOpenChange:s,children:[a.jsx(Nr,{asChild:!0,children:a.jsx(Ee,{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:a.jsx(Gs,{className:"dm-card-table-body-row-actionbtn-icon"})})}),a.jsxs(Ar,{align:"end",children:[a.jsxs(Nt,{onClick:()=>{t(e.id)},children:[a.jsx(sd,{className:"text-foreground h-4 w-4","aria-hidden":"true"}),"Edit trigger"]}),a.jsx(ja,{}),a.jsxs(Nt,{onClick:()=>{c(!0)},children:[a.jsx(es,{className:"h-4 w-4 text-red-600","aria-hidden":"true"}),a.jsx("span",{className:"text-red-600",children:"Delete trigger"})]})]})]}),a.jsx(br,{open:i,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:u,variant:"destructive"})]})}function fie({connector:e}){const{connectors:t}=Dc(),n=Yee(e,t);return a.jsx(a.Fragment,{children:n})}function wI({connector:e}){return a.jsx(fie,{connector:e})}function hie(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 mie=e=>{const{connectors:t}=Dc();return h.useMemo(()=>t.find(n=>n.name===e),[t,e])},pie=re.memo(function({connector:t,children:n}){const r=mie(t.source.name),{dataMart:s,runs:i,getDataMartRuns:c}=Ss();h.useEffect(()=>{s!=null&&s.id&&c(s.id)},[s==null?void 0:s.id,c]);const u=h.useMemo(()=>r!=null&&r.logoBase64?a.jsx(_c,{base64:r.logoBase64,size:20}):null,[r==null?void 0:r.logoBase64]),f=h.useCallback(()=>{s!=null&&s.storage&&RX(s.storage,t.storage.fullyQualifiedName)},[s==null?void 0:s.storage,t.storage.fullyQualifiedName]),m=h.useMemo(()=>hie(i),[i]),y=h.useMemo(()=>!m.lastRunDate||!m.lastRunStatus?null:{statusType:KQ(m.lastRunStatus),statusText:YQ(m.lastRunStatus),date:m.lastRunDate},[m]),g=h.useMemo(()=>(s==null?void 0:s.storage)&&jX(s.storage),[s]),x=h.useMemo(()=>{const v=t.source.fields.length.toString();return`${t.source.node} • ${v} fields`},[t.source.node,t.source.fields.length]);return a.jsxs(Ny,{children:[a.jsx(Ay,{asChild:!0,children:a.jsx("span",{children:n})}),a.jsxs(Dy,{children:[a.jsxs(ZS,{children:[a.jsx(YS,{children:u}),a.jsxs(WS,{children:[a.jsx(XS,{children:a.jsx(wI,{connector:t})}),a.jsx(QS,{children:x})]})]}),a.jsxs(JS,{children:[a.jsxs(el,{children:[a.jsx(tl,{children:"Last run status:"}),a.jsx(nl,{children:y?a.jsx(Ph,{type:y.statusType,variant:"ghost",children:y.statusText}):"Not run yet"})]}),a.jsxs(el,{children:[a.jsx(tl,{children:"Last run date:"}),a.jsx(nl,{children:y?a.jsx(Hs,{date:y.date}):"Never run"})]}),a.jsxs(el,{children:[a.jsx(tl,{children:"Total runs:"}),a.jsxs(nl,{children:[m.totalRuns," runs",m.firstRunDate&&a.jsxs(a.Fragment,{children:[", since"," ",m.firstRunDate.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})]})]})]})]}),a.jsx(e2,{children:a.jsxs(Ee,{className:"w-full",variant:"default",onClick:f,title:"Open Storage","aria-label":"Open Storage",children:[g,a.jsx(ai,{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 gie(e){const t=e.triggerConfig,n=aa.getInfo(t.report.dataDestination.type).icon;return a.jsxs("div",{className:"group inline-flex items-center gap-2 whitespace-nowrap",children:[a.jsx(n,{className:"h-4 w-4",size:16}),t.report.title,a.jsx(GQ,{report:t.report,children:a.jsx(Fr,{className:"inline-block h-4 w-4 align-text-bottom opacity-0 transition-opacity duration-200 group-hover:opacity-100"})})]})}function yie(e){var s;const t=e.triggerConfig,{connector:n}=t.connector,r=(s=n.info)!=null&&s.logoBase64?a.jsx(_c,{base64:n.info.logoBase64,className:"h-4 w-4",size:16}):a.jsx(lc,{className:"h-4 w-4",size:16});return a.jsxs("div",{className:"group inline-flex items-center gap-2 whitespace-nowrap",children:[r,a.jsx(wI,{connector:n}),a.jsx(pie,{connector:n,children:a.jsx(Fr,{className:"inline-block h-4 w-4 align-text-bottom opacity-0 transition-opacity duration-200 group-hover:opacity-100"})})]})}function xie({trigger:e}){switch(e.type){case Fn.REPORT_RUN:return gie(e);case Fn.CONNECTOR_RUN:return yie(e);default:return a.jsx("div",{className:"text-muted-foreground text-sm",children:"—"})}}function vie({onEditTrigger:e,onDeleteTrigger:t}){return[{accessorKey:"type",size:150,header:"Trigger Type",cell:({row:n})=>{const s=n.getValue("type")===Fn.REPORT_RUN?"Report Run":"Connector Run";return a.jsx(jr,{variant:"outline",children:s})},meta:{title:"Trigger Type"}},{accessorKey:"triggerConfig",size:35,header:"Run Target",cell:({row:n})=>a.jsx(xie,{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,i=n.getValue("isActive");return a.jsx(uie,{cronExpression:String(r),timeZone:s,isEnabled:i})},meta:{title:"Schedule"}},{accessorKey:"nextRun",size:15,header:"Next Run",cell:({row:n})=>{const r=n.original.nextRun;return a.jsx("div",{className:"text-muted-foreground text-sm",children:r?a.jsx(Hs,{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 a.jsx("div",{className:"text-sm",children:r?a.jsx(Hs,{date:new Date(r)}):a.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 a.jsx(Ph,{type:r?Jn.SUCCESS:Jn.NEUTRAL,variant:"ghost",showIcon:!1,children:r?"Enabled":"Disabled"})},meta:{title:"Trigger Status"}},{id:"actions",size:80,header:({table:n})=>a.jsx(gd,{table:n}),cell:({row:n})=>a.jsx(die,{trigger:n.original,onEditTrigger:e,onDeleteTrigger:t}),meta:{title:"Actions"}}]}function bie({table:e,onPreviousClick:t,onNextClick:n}){return a.jsxs("div",{className:"dm-card-pagination",role:"navigation","aria-label":"Table pagination",children:[a.jsx(Ee,{variant:"outline",size:"sm",onClick:t,disabled:!e.getCanPreviousPage(),"aria-label":"Go to previous page",children:"Previous"}),a.jsx(Ee,{variant:"outline",size:"sm",onClick:n,disabled:!e.getCanNextPage(),"aria-label":"Go to next page",children:"Next"})]})}function Y2({isOpen:e,onClose:t,dataMartId:n,preSelectedReportId:r,preSelectedType:s}){const{createScheduledTrigger:i,updateScheduledTrigger:c,selectedTrigger:u}=pI(),{showUnsavedDialog:f,setShowUnsavedDialog:m,handleClose:y,confirmClose:g,handleFormDirtyChange:x,handleFormSubmitSuccess:v}=Ic(t),C=!!u,S=h.useMemo(()=>u?{type:u.type,cronExpression:u.cronExpression,timeZone:u.timeZone,isActive:u.isActive,triggerConfig:u.type===Fn.REPORT_RUN?{type:sl.SCHEDULED_REPORT_RUN,reportId:u.triggerConfig.reportId}:null}:void 0,[u]),E=async j=>{C?await c(n,u.id,j.cronExpression,j.timeZone,j.isActive):await i(n,j.type,j.cronExpression,j.timeZone,j.isActive,j.triggerConfig),v()},R=h.useRef(!1);return h.useEffect(()=>{const j=C?"Edit":"Create",_=(u==null?void 0:u.type)??s;e&&!R.current?(Le({event:"scheduled_trigger_config_open",category:"ScheduledTrigger",action:j,label:_}),R.current=!0):!e&&R.current&&(Le({event:"scheduled_trigger_config_close",category:"ScheduledTrigger",action:j,label:_}),R.current=!1)},[e,C,u,s]),a.jsxs(a.Fragment,{children:[a.jsx(ci,{open:e,onOpenChange:j=>{j||y()},children:a.jsxs(ui,{children:[a.jsxs(di,{children:[a.jsxs(fi,{children:[C?"Edit":"Create"," Scheduled Trigger"]}),a.jsx(yl,{children:"Configure automatic runs for your reports or connectors."})]}),a.jsx(cie,{preSelectedReportId:r,preSelectedType:s,initialData:S,onSubmit:E,onCancel:y,onDirtyChange:x})]})}),a.jsx(br,{open:f,onOpenChange:m,title:"Unsaved Changes",description:"You have unsaved changes. Exit without saving?",confirmLabel:"Yes, leave now",cancelLabel:"No, stay here",onConfirm:g,variant:"destructive"})]})}function Sie({triggers:e,dataMartId:t,onEditTrigger:n,onDeleteTrigger:r}){const[s,i]=h.useState(!1),c=h.useCallback(()=>{i(!1)},[]),u=h.useCallback(R=>{r(R)},[r]),f=h.useMemo(()=>vie({onEditTrigger:n,onDeleteTrigger:u}),[n,u]),{sorting:m,setSorting:y,columnVisibility:g,setColumnVisibility:x}=Ac({columns:f,storageKeyPrefix:"data-mart-scheduled-triggers",defaultSortingColumn:"type"}),v=El({data:e,columns:f,getCoreRowModel:Cl(),getPaginationRowModel:Fh(),onSortingChange:y,getSortedRowModel:Nc(),getFilteredRowModel:pd(),state:{sorting:m,columnVisibility:g},onColumnVisibilityChange:x,enableGlobalFilter:!0,enableColumnResizing:!1}),C=h.useCallback(()=>{v.previousPage()},[v]),S=h.useCallback(()=>{v.nextPage()},[v]);return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"dm-card-table-wrap",children:a.jsxs(wl,{id:"scheduled-triggers-table",className:"dm-card-table",role:"table","aria-label":"Scheduled Triggers",children:[a.jsx(Rl,{className:"dm-card-table-header",children:v.getHeaderGroups().map(R=>a.jsx(Hn,{className:"dm-card-table-header-row",children:R.headers.map(j=>a.jsx(Tl,{className:"[&:has([role=checkbox])]:pl-6 [&>[role=checkbox]]:translate-y-[2px]",scope:"col",style:j.column.id==="type"?{width:150,minWidth:150,maxWidth:150}:j.column.id==="actions"?{width:80,minWidth:80,maxWidth:80}:{width:`${String(j.getSize())}%`},children:j.isPlaceholder?null:typeof j.column.columnDef.header=="function"?j.column.columnDef.header(j.getContext()):j.column.columnDef.header},j.id))},R.id))}),a.jsx(jl,{className:"dm-card-table-body",children:v.getRowModel().rows.length?v.getRowModel().rows.map((R,j)=>a.jsx(Hn,{onClick:()=>{n(R.original.id)},className:"dm-card-table-body-row group",role:"row","aria-rowindex":j+1,children:R.getVisibleCells().map((_,I)=>a.jsx($r,{className:`whitespace-normal ${_.column.id==="actions"?"actions-cell":""}`,role:"cell","aria-colindex":I+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)):a.jsx(Hn,{children:a.jsx($r,{colSpan:f.length,className:"dm-card-table-body-row-empty",role:"cell",children:a.jsx("span",{role:"status","aria-live":"polite",children:"No scheduled triggers found."})})})})]})}),a.jsx(bie,{table:v,onPreviousClick:C,onNextClick:S}),a.jsx(Y2,{isOpen:s,onClose:c,dataMartId:t})]})}function Cie({dataMartId:e}){const{triggers:t,deleteScheduledTrigger:n,selectScheduledTrigger:r,selectedTrigger:s}=Poe(e),[i,c]=h.useState(!1);h.useEffect(()=>{s&&c(!0)},[s]);const u=y=>{const g=t.find(x=>x.id===y);g&&r(g)},f=()=>{c(!1),r(null)},m=async y=>{try{await n(e,y)}catch(g){console.error("Error deleting trigger:",g)}};return a.jsxs(a.Fragment,{children:[a.jsx(Sie,{triggers:t,dataMartId:e,onEditTrigger:u,onDeleteTrigger:y=>void m(y)}),a.jsx(Y2,{isOpen:i,onClose:f,dataMartId:e})]})}function W2(){return a.jsx("div",{className:"dm-card-block !gap-1.5 !py-3",children:a.jsxs("div",{className:"text-foreground flex items-start gap-1.5 text-sm",children:[a.jsx(Xb,{className:"h-5 w-5 shrink-0","aria-hidden":"true"}),a.jsxs("div",{children:[a.jsx("p",{className:"font-medium",children:"Time Triggers"}),a.jsxs("p",{className:"text-muted-foreground",children:["Set up automatic runs in the ",a.jsx("span",{className:"font-medium",children:"Triggers"})," tab once you’ve saved and published this Data Mart."]})]})]})})}function Ip(e){return e.startsWith('"')&&e.endsWith('"')?e:`"${e}"`}function kg(e){return e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function Eie({dataStorageType:e,target:t,destinationName:n,connectorName:r,onTargetChange:s}){const i=n.replace(/[^a-zA-Z0-9_]/g,"_"),c=r.replace(/[^a-zA-Z0-9_]/g,"_").toLowerCase(),[u,f]=h.useState(""),[m,y]=h.useState(""),[g,x]=h.useState(""),[v,C]=h.useState(null),[S,E]=h.useState(null),[R,j]=h.useState(null),_=(D,k=!1)=>D.trim()?k&&D.startsWith('"')&&D.endsWith('"')?D.slice(1,-1)?null:"Quoted identifier cannot be empty":/^[A-Za-z][A-Za-z0-9_]*$/.test(D)?null:"Use letters, numbers, and underscores; start with a letter":"This field is required",I=h.useCallback((D,k,B,G,Y,V)=>{let Z;if(e===Re.SNOWFLAKE&&Y){const M=Ip(Y),$=Ip(k);Z=`${D}.${M}.${$}`}else Z=`${D}.${k}`;const F=e===Re.SNOWFLAKE?!!(D&&Y&&k&&B===null&&V===null&&G===null):!!(D&&k&&B===null&&G===null);s({fullyQualifiedName:Z,isValid:F})},[s,e]);h.useEffect(()=>{let D="",k="",B="";if(t!=null&&t.fullyQualifiedName){const M=t.fullyQualifiedName.match(/(?:[^."]+|"[^"]*")+/g)??[];if(e===Re.SNOWFLAKE&&M.length===3){const $=M[0],H=M[1],oe=M[2];$&&H&&oe&&(D=$,k=kg(H),B=kg(oe))}else if(M.length>=2){const $=M[0],H=M[1];$&&H&&(D=$,B=H)}}else D=`${c}_owox`,e===Re.SNOWFLAKE&&(k="PUBLIC"),B=i;const G=_(D),Y=e===Re.SNOWFLAKE?_(k,!0):null,V=_(B,e===Re.SNOWFLAKE);f(D),y(k),x(B),C(G),E(Y),j(V);const Z=e===Re.SNOWFLAKE&&k?`${D}.${Ip(k)}.${Ip(B)}`:`${D}.${B}`,F=e===Re.SNOWFLAKE?!!(D&&k&&B&&G===null&&Y===null&&V===null):!!(D&&B&&G===null&&V===null);((t==null?void 0:t.fullyQualifiedName)!==Z||t.isValid!==F)&&I(D,B,G,V,k,Y)},[t,i,c,e,I]);const A=D=>{f(D);const k=_(D);C(k),I(D,g,k,R,m,S)},O=D=>{y(D);const k=_(D,!0);E(k),I(u,g,v,R,D,k)},T=D=>{x(D);const k=_(D,e===Re.SNOWFLAKE);j(k),I(u,D,v,k,m,S)};return a.jsxs(ni,{children:[e===Re.GOOGLE_BIGQUERY&&a.jsxs(a.Fragment,{children:[a.jsx(ti,{icon:a.jsx(SD,{}),title:"Google BigQuery",docUrl:"https://docs.owox.com/docs/storages/supported-storages/google-bigquery/",variant:"compact"}),a.jsxs(al,{title:"Choose where to store your data",children:[a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"dataset-name",tooltip:"Enter dataset name for Google BigQuery where the connector data will be stored.",children:"Dataset name"}),a.jsx(It,{type:"text",id:"dataset-name",placeholder:"Enter dataset name",autoComplete:"off",className:"box-border w-full",value:u,"aria-invalid":!!v,"aria-describedby":v?"dataset-name-error":void 0,onChange:D=>{A(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Dataset is auto-created on first run if it doesn’t exist"}),v&&a.jsx("p",{id:"dataset-name-error",className:"text-destructive text-sm",children:v})]}),a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"table-name",tooltip:"Enter table name where the connector data will be stored.",children:"Table name"}),a.jsx(It,{type:"text",id:"table-name",placeholder:"Enter table name",autoComplete:"off",className:"box-border w-full",value:g,"aria-invalid":!!R,"aria-describedby":R?"table-name-error":void 0,onChange:D=>{T(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Table is auto-created on first run if it doesn’t exist"}),R&&a.jsx("p",{id:"table-name-error",className:"text-destructive text-sm",children:R})]})]})]}),e===Re.AWS_ATHENA&&a.jsxs(a.Fragment,{children:[a.jsx(ti,{icon:a.jsx(CD,{}),title:"AWS Athena",docUrl:"https://docs.owox.com/docs/storages/supported-storages/aws-athena/",variant:"compact"}),a.jsxs(al,{title:"Choose where to store your data",children:[a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"database-name",tooltip:"Enter database name for Amazon Athena where the connector data will be stored.",children:"Database name"}),a.jsx(It,{type:"text",id:"database-name",placeholder:"Enter database name",autoComplete:"off",className:"box-border w-full",value:u,"aria-invalid":!!v,"aria-describedby":v?"database-name-error":void 0,onChange:D=>{A(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Database is auto-created on first run if it doesn’t exist"}),v&&a.jsx("p",{id:"database-name-error",className:"text-destructive text-sm",children:v})]}),a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"athena-table-name",tooltip:"Enter table name where the connector data will be stored.",children:"Table name"}),a.jsx(It,{type:"text",id:"athena-table-name",placeholder:"Enter table name",autoComplete:"off",className:"box-border w-full",value:g,"aria-invalid":!!R,"aria-describedby":R?"athena-table-name-error":void 0,onChange:D=>{T(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Table is auto-created on first run if it doesn’t exist"}),R&&a.jsx("p",{id:"athena-table-name-error",className:"text-destructive text-sm",children:R})]})]})]}),e===Re.SNOWFLAKE&&a.jsxs(a.Fragment,{children:[a.jsx(ti,{icon:a.jsx(ED,{}),title:"Snowflake",docUrl:"https://docs.owox.com/docs/storages/supported-storages/snowflake/",variant:"compact"}),a.jsxs(al,{title:"Choose where to store your data",children:[a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"snowflake-database-name",tooltip:"Enter database name for Snowflake where the connector data will be stored.",children:"Database name"}),a.jsx(It,{type:"text",id:"snowflake-database-name",placeholder:"Enter database name",autoComplete:"off",className:"box-border w-full",value:u,"aria-invalid":!!v,"aria-describedby":v?"snowflake-database-name-error":void 0,onChange:D=>{A(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Database is auto-created on first run if it doesn't exist"}),v&&a.jsx("p",{id:"snowflake-database-name-error",className:"text-destructive text-sm",children:v})]}),a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"snowflake-schema-name",tooltip:"Enter schema name for Snowflake where the connector data will be stored. Identifiers will be quoted automatically to preserve case sensitivity.",children:"Schema name"}),a.jsx(It,{type:"text",id:"snowflake-schema-name",placeholder:"PUBLIC",autoComplete:"off",className:"box-border w-full",value:m,"aria-invalid":!!S,"aria-describedby":S?"snowflake-schema-name-error":void 0,onChange:D=>{O(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Schema is auto-created on first run if it doesn't exist"}),S&&a.jsx("p",{id:"snowflake-schema-name-error",className:"text-destructive text-sm",children:S})]}),a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"snowflake-table-name",tooltip:"Enter table name where the connector data will be stored. Identifiers will be quoted automatically to preserve case sensitivity.",children:"Table name"}),a.jsx(It,{type:"text",id:"snowflake-table-name",placeholder:"my_table",autoComplete:"off",className:"box-border w-full",value:g,"aria-invalid":!!R,"aria-describedby":R?"snowflake-table-name-error":void 0,onChange:D=>{T(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Table is auto-created on first run if it doesn't exist"}),R&&a.jsx("p",{id:"snowflake-table-name-error",className:"text-destructive text-sm",children:R})]})]})]}),a.jsx(al,{title:"Schedule updates",children:a.jsx(W2,{})})]})}function wie({onSubmit:e,dataStorageType:t,configurationOnly:n=!1,existingConnector:r=null,mode:s="full",initialStep:i,preselectedConnector:c,onDirtyChange:u}){const[f,m]=h.useState(!1),[y,g]=h.useState(null),[x,v]=h.useState(""),[C,S]=h.useState([]),[E,R]=h.useState(1),[j,_]=h.useState({}),[I,A]=h.useState(!1),[O,T]=h.useState(new Set),[D,k]=h.useState(new Set),{connectors:B,connectorSpecification:G,connectorFields:Y,loading:V,loadingSpecification:Z,loadingFields:F,error:M,fetchAvailableConnectors:$,fetchConnectorSpecification:H,fetchConnectorFields:oe}=Dc();h.useEffect(()=>{u==null||u(f)},[f,u]);const[ge,P]=h.useState(null),U=h.useMemo(()=>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"}],[n,s]),z=U.length,X=h.useCallback(async Me=>{!O.has(Me)&&!Z&&(T(q=>new Set(q).add(Me)),await H(Me))},[O,Z,H]),W=h.useCallback(async Me=>{D.has(Me)||(k(q=>new Set(q).add(Me)),await oe(Me))},[D,oe]);h.useEffect(()=>{if(!c||y||B.length===0)return;const Me=B.find(q=>q.name===c);Me&&(g(Me),R(i??2),X(Me.name),!n&&s!=="fields-only"&&W(Me.name))},[c,B,y,i,n,s,X,W]),h.useEffect(()=>{if(B.length===0&&!V&&$(),r&&B.length>0&&!y){const{source:Me,storage:q}=r;v(Me.node),S(Me.fields),_(Me.configuration[0]||{}),P({fullyQualifiedName:q.fullyQualifiedName,isValid:!0});const ne=B.find(ce=>ce.name===Me.name);ne&&(g(ne),X(ne.name),!n&&s!=="fields-only"&&W(ne.name),s==="fields-only"&&W(ne.name))}if(n&&B.length>0&&!y&&!r){const Me=B[0];g(Me),X(Me.name)}},[s,r,B,n,V,$,X,W,y]);const ae=Me=>{g(Me),_({}),A(!1),m(!0),T(q=>{const ne=new Set(q);return ne.delete(Me.name),ne}),X(Me.name),W(Me.name),Le({event:"connector_setup",category:Me.name,action:"connector_selected",label:Me.displayName})},J=Me=>{v(Me),S([]),m(!0)},le=(Me,q)=>{S(q?ne=>ne.includes(Me)?ne:[...ne,Me]:ne=>ne.filter(ce=>ce!==Me)),m(!0)},ye=(Me,q)=>{S(q?ne=>{const ce=Me.filter(Oe=>!ne.includes(Oe));return[...ne,...ce]}:ne=>ne.filter(ce=>!Me.includes(ce))),m(!0)},Ce=Me=>{P(Me),m(!0)},Ve=h.useCallback(Me=>{_(Me),m(!0)},[]),De=h.useCallback(Me=>{A(Me)},[]);h.useEffect(()=>{G&&(G.some(q=>q.required&&q.name!=="Fields")||A(!0))},[G]),h.useEffect(()=>{var q;const Me=((q=U[E-1])==null?void 0:q.title)??`Step ${String(E)}`;Le({event:"connector_setup",category:(y==null?void 0:y.name)??"unknown",action:"step",label:Me})},[E,y]);const et=()=>{E<z&&R(E+1)},rt=()=>{E>1&&R(E-1)},dn=()=>{if(n)return y!==null&&I;if(s==="fields-only")switch(E){case 1:return C.length>0;default:return!1}switch(E){case 1:return y!==null;case 2:return I;case 3:return x!=="";case 4:return C.length>0;case 5:return ge!==null&&ge.fullyQualifiedName!==""&&ge.isValid;default:return!1}},zt=()=>E>1,On=(Me,q)=>{if(!Me)return q;const ne=Me.find(ce=>ce.name===q);return(ne==null?void 0:ne.destinationName)??q},yn=()=>{if(n&&E===1)return G&&y?a.jsx(Q_,{connector:y,connectorSpecification:G,onConfigurationChange:Ve,onValidationChange:De,initialConfiguration:j,loading:Z,isEditingExisting:!!(r!=null&&r.source.configuration.length)}):null;if(s==="fields-only")switch(E){case 1:return y&&x&&Y?a.jsx(J_,{connector:y,connectorFields:Y,selectedField:x,selectedFields:C,onFieldToggle:le,onSelectAllFields:ye}):null;default:return null}switch(E){case 1:return a.jsx(goe,{connectors:B,selectedConnector:y,loading:V,error:M,onConnectorSelect:ae,onConnectorDoubleClick:()=>{R(Me=>Me<z?Me+1:Me)}});case 2:return y&&G?a.jsx(Q_,{connector:y,connectorSpecification:G,onConfigurationChange:Ve,onValidationChange:De,initialConfiguration:j,loading:Z,isEditingExisting:!1}):null;case 3:return y&&Y?a.jsx(Ooe,{connectorFields:Y,connector:y,selectedField:x,connectorName:y.displayName,loading:F,onFieldSelect:J}):null;case 4:return y&&x&&Y?a.jsx(J_,{connector:y,connectorFields:Y,selectedField:x,selectedFields:C,onFieldToggle:le,onSelectAllFields:ye}):null;case 5:return x&&Y?a.jsx(Eie,{dataStorageType:t,destinationName:On(Y,x),connectorName:(y==null?void 0:y.displayName)??"",target:ge,onTargetChange:Ce}):null;default:return null}};return a.jsxs(rre,{children:[a.jsx(are,{children:yn()}),a.jsx(sre,{variant:"horizontal",children:a.jsx(yoe,{currentStep:E,totalSteps:z,canGoNext:dn(),canGoBack:zt(),isLoading:Z||F,onNext:et,onBack:rt,onFinish:()=>{n&&y?(e({source:{name:y.name,configuration:[j],node:(r==null?void 0:r.source.node)??x,fields:(r==null?void 0:r.source.fields)??C},storage:(r==null?void 0:r.storage)??{fullyQualifiedName:(r==null?void 0:r.storage.fullyQualifiedName)??""}}),Le({event:"connector_setup",category:y.name,action:"created",label:"configuration-only"})):s==="fields-only"&&r?(e({source:{...r.source,fields:C},storage:r.storage}),Le({event:"connector_setup",category:r.source.name,action:"created",label:"fields-only"})):y&&ge&&(e({source:{name:y.name,configuration:[j],node:x,fields:C},storage:{fullyQualifiedName:ge.fullyQualifiedName}}),Le({event:"connector_setup",category:y.name,action:"created",label:"full"})),m(!1)}})})]})}const RI=20,jI=20;function TI({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 _I(e=30,t=0){TI({vertical:jI+e,horizontal:RI+t})}function ah(){TI({vertical:jI,horizontal:RI})}function NI({isOpen:e,onClose:t,dataStorageType:n,onSubmit:r,configurationOnly:s=!1,existingConnector:i=null,mode:c="full",initialStep:u,preselectedConnector:f}){h.useEffect(()=>(e?_I(55):ah(),()=>{ah()}),[e]);const{showUnsavedDialog:m,setShowUnsavedDialog:y,handleClose:g,confirmClose:x,handleFormDirtyChange:v,handleFormSubmitSuccess:C}=Ic(t);return a.jsxs(a.Fragment,{children:[a.jsx(ci,{open:e,onOpenChange:S=>{S||g()},children:a.jsxs(ui,{children:[a.jsxs(di,{children:[a.jsx(fi,{children:c==="fields-only"?"Connector Fields":i!=null&&i.source.name?"Edit Connector":"Set Up Connector"}),a.jsx(yl,{children:c==="fields-only"?"Select fields for your Data Mart":i!=null&&i.source.name?"Update configuration":"Follow these steps to set it up"})]}),a.jsx(wie,{onSubmit:S=>{r(S),C()},dataStorageType:n,configurationOnly:s||c==="configuration-only",existingConnector:i,mode:c,initialStep:u,preselectedConnector:f,onDirtyChange:v})]})}),a.jsx(br,{open:m,onOpenChange:y,title:"Unsaved Changes",description:"You have unsaved changes. Exit without saving?",confirmLabel:"Yes, leave now",cancelLabel:"No, stay here",onConfirm:x,variant:"destructive"})]})}const X2=({dataStorageType:e,onSubmit:t,children:n,configurationOnly:r=!1,existingConnector:s=null,preset:i,isOpen:c,onClose:u})=>{const[f,m]=h.useState(!1),[y,g]=h.useState(1),[x,v]=h.useState();h.useEffect(()=>{c!==void 0&&m(c)},[c]);const C=()=>{v(void 0),g(1),m(!0)},S=()=>{m(!1),u==null||u()};return h.useEffect(()=>{i&&(i==="connector"?(v(void 0),g(1),m(!0)):(v(i),g(2),m(!0)))},[i]),a.jsxs(a.Fragment,{children:[n&&a.jsx("div",{onClick:C,style:{cursor:"pointer"},children:n}),a.jsx(nd,{children:a.jsx(NI,{isOpen:f,onClose:S,dataStorageType:e,onSubmit:t,configurationOnly:r,existingConnector:s,initialStep:y,preselectedConnector:x})})]})};function Rie({storageType:e,onSetupConnector:t,preset:n,isOpen:r,onClose:s}){return a.jsx(X2,{dataStorageType:e,onSubmit:t,configurationOnly:!1,preset:n,isOpen:r,onClose:s,children:a.jsxs(Ee,{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:[a.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:a.jsx(eS,{className:"h-4 w-4",strokeWidth:2.25})}),a.jsx("span",{children:"Setup Connector"}),a.jsx(_a,{className:"h-6 w-6"})]})})}const jie=e=>{switch(e){case Re.GOOGLE_BIGQUERY:return"Google BigQuery";case Re.AWS_ATHENA:return"AWS Athena";case Re.SNOWFLAKE:return"Snowflake";default:return e}},Au=e=>typeof e=="object"&&"connector"in e,jf=e=>{if(!Au(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.split("."),i=s.length===2||s.length===3;return r&&i};function Tie({configIndex:e,connectorDef:t,onRemoveConfiguration:n,onUpdateConfiguration:r,totalConfigurations:s,dataStorage:i}){const c=Sl.getInfo(i.type),{connectors:u,fetchAvailableConnectors:f}=Dc();h.useEffect(()=>{f()},[f]);const m=C=>{const S=u.find(E=>E.name===C);if(S!=null&&S.logoBase64)return()=>a.jsx(_c,{base64:S.logoBase64,size:24})},y=()=>{const C=t.connector.source.node||"No node selected";return a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsx("span",{className:"text-muted-foreground/75",children:"Data:"})," ",a.jsx("span",{className:"text-muted-foreground font-medium",children:C}),a.jsx("span",{className:"text-muted-foreground",children:"•"}),a.jsxs(Et,{children:[a.jsx(wt,{asChild:!0,children:a.jsxs("span",{className:"text-muted-foreground flex items-center gap-1 font-medium",children:[a.jsx("span",{children:"Edit config"}),a.jsx(_a,{className:"h-3 w-3"})]})}),a.jsx(Rt,{children:"Edit connector configuration"})]})]})},g=(C,S,E)=>a.jsxs("span",{children:[a.jsxs("span",{className:"text-muted-foreground/75",children:[C,":"]})," ",a.jsx(gn,{href:E,onClick:R=>{R.stopPropagation()},children:S})]}),x=()=>{switch(i.type){case Re.GOOGLE_BIGQUERY:{const C=i.config.projectId,S=t.connector.storage.fullyQualifiedName,E=S.split(".")[0],R=S.split(".")[1],j=`https://console.cloud.google.com/bigquery?project=${C}&ws=!1m4!1m3!3m2!1s${C}!2s${E}`,_=`https://console.cloud.google.com/bigquery?project=${C}&ws=!1m4!1m3!3m2!1s${C}!2s${E}!3s${R}`;return a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[g("Dataset",E,j),a.jsx("span",{className:"text-muted-foreground",children:"•"}),g("Table",R,_),a.jsxs(Et,{children:[a.jsx(wt,{asChild:!0,children:a.jsx(Fr,{className:"h-4 w-4"})}),a.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 Re.AWS_ATHENA:{const C=i.config.region,S=t.connector.storage.fullyQualifiedName,[E,R]=S.split("."),j=`https://console.aws.amazon.com/athena/home?region=${C}#/query-editor`;return a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[g("Database",E,j),a.jsx("span",{className:"text-muted-foreground",children:"•"}),g("Table",R,j),a.jsxs(Et,{children:[a.jsx(wt,{asChild:!0,children:a.jsx(Fr,{className:"h-4 w-4"})}),a.jsx(Rt,{children:"The database and table are automatically created during the first run of the data mart, if they don't already exist"})]})]})}case Re.SNOWFLAKE:{const C=i.config.account,E=t.connector.storage.fullyQualifiedName.split("."),R=E[0],j=E[1],_=E[2],I=`https://${C}.snowflakecomputing.com`,A=`${I}/#/data/databases/${R}`,O=`${I}/#/data/databases/${R}/schemas/${j}`,T=`${I}/#/data/databases/${R}/schemas/${j}/table/${_}`;return a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[g("Database",R,A),a.jsx("span",{className:"text-muted-foreground",children:"•"}),g("Schema",kg(j),O),a.jsx("span",{className:"text-muted-foreground",children:"•"}),g("Table",kg(_),T),a.jsxs(Et,{children:[a.jsx(wt,{asChild:!0,children:a.jsx(Fr,{className:"h-4 w-4"})}),a.jsx(Rt,{children:"The database, schema 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"}},v=()=>s!==1;return a.jsxs("div",{className:"border-border flex w-full items-center rounded-lg border-1 p-1 dark:bg-white/2",children:[a.jsx("div",{className:"flex-grow",children:a.jsxs("div",{className:"grid grid-cols-2 items-center gap-4",children:[a.jsx(X2,{dataStorageType:i.type,onSubmit:r(e),configurationOnly:!0,existingConnector:{source:{...t.connector.source,configuration:[t.connector.source.configuration[e]]},storage:t.connector.storage},children:a.jsx(vb,{icon:m(t.connector.source.name),title:t.connector.source.name||"Connector",subtitle:y(),className:"bg-background hover:bg-muted min-h-[80px] cursor-pointer border-0 transition-colors hover:shadow-none"})}),a.jsx(vb,{title:jie(i.type),icon:c.icon,subtitle:x(),className:"bg-background min-h-[80px] cursor-default border-0 hover:shadow-none dark:bg-white/2"})]})}),a.jsx("div",{className:"shrink-0 px-4",children:a.jsxs(Et,{children:[a.jsx(wt,{asChild:!0,children:a.jsx("span",{children:a.jsx(Ee,{type:"button",variant:"ghost",onClick:()=>{v()&&n(e)},disabled:!v(),children:a.jsx(es,{className:"h-4 w-4"})})})}),!v()&&a.jsx(Rt,{children:"Remove last configuration only after adding a new one."})]})})]})}function _ie({storageType:e,onAddConfiguration:t,existingConnector:n}){return a.jsx("div",{children:a.jsx(X2,{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:a.jsxs(Ee,{type:"button",variant:"outline",className:"dm-card-table-add-field-btn cursor-pointer",children:[a.jsx(ha,{className:"h-4 w-4"}),a.jsx("span",{children:"Configuration"})]})})})}function Nie({control:e,storageType:t,preset:n,autoOpen:r=!1,saveDataMartDefinition:s}){const{dataMart:i,runDataMart:c}=vs(),{setValue:u,getValues:f,trigger:m}=yd(),[y,g]=h.useState(!1),[x,v]=h.useState(!1);h.useEffect(()=>{r&&v(!0)},[r]);const C=(i==null?void 0:i.status)??zr.DRAFT,S=async Z=>{u("definition",Z,{shouldDirty:!0,shouldTouch:!0}),await m("definition")&&s&&s()},E=async Z=>{const F=Z.source,M=Z.storage;await S({connector:{source:F,storage:M}})},R=async Z=>{if(i){if(i.status.code!==zr.PUBLISHED){Tt.error("Manual run is only available for published data marts");return}await c({id:i.id,payload:Z})}},j=Z=>async F=>{const $=f().definition;if(typeof $=="object"&&Au($)){const H=[...$.connector.source.configuration];H[Z]=F.source.configuration[0]||{};const oe={connector:{...$.connector,source:{...$.connector.source,configuration:H}}};await S(oe)}},_=async Z=>{const M=f().definition;if(typeof M=="object"&&Au(M)){const $={connector:{...M.connector,source:{...M.connector.source,fields:Z.source.fields}}};await S($)}g(!1)},I=Z=>{R({runType:Z.runType,data:Z.data})},A=Z=>{const F=Z.connector.source.fields.length;return a.jsxs(Ee,{type:"button",variant:"outline",onClick:()=>{g(!0)},className:"dm-card-table-add-field-btn cursor-pointer",children:[a.jsx(KU,{className:"h-4 w-4"}),a.jsxs("span",{children:["Edit Fields (",String(F),")"]})]})},[O,T]=h.useState(null),[D,k]=h.useState(!1),B=Z=>{T(Z),k(!0)},G=async()=>{O!==null&&(await Y(O),T(null),k(!1))},Y=async Z=>{const M=f().definition;if(Au(M)&&M.connector.source.configuration.length<=1){const $=B2($e.CONNECTOR);await S($)}if(typeof M=="object"&&Au(M)&&M.connector.source.configuration.length>1){const $={...M.connector.source,configuration:M.connector.source.configuration.filter((oe,ge)=>ge!==Z)},H={connector:{...M.connector,source:$}};await S(H)}},V=async Z=>{const M=f().definition;if(Au(M)){const $={...M.connector.source,configuration:[...M.connector.source.configuration,Z]},H={connector:{...M.connector,source:$}};await S(H)}};return a.jsxs(a.Fragment,{children:[a.jsx(_t,{control:e,name:"definition",render:({field:Z})=>a.jsxs(xt,{className:"dark:bg-white/2",children:[a.jsx(Ct,{children:a.jsx("div",{className:"space-y-3",children:!jf(Z.value)||C===zr.DRAFT?a.jsx(Rie,{storageType:t,onSetupConnector:F=>{E(F),v(!1)},preset:n,isOpen:x,onClose:()=>{v(!1)}}):a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(_ie,{storageType:t,onAddConfiguration:F=>void V(F),existingConnector:jf(Z.value)?{source:Z.value.connector.source,storage:Z.value.connector.storage}:void 0}),jf(Z.value)&&A(Z.value)]}),a.jsx("div",{className:"flex items-center gap-2",children:i&&i.definitionType===$e.CONNECTOR&&a.jsx(O6,{configuration:i.definition,onManualRun:I,children:a.jsxs(Ee,{variant:"outline",children:[a.jsx(Xg,{className:"h-4 w-4"}),a.jsx("span",{children:"Manual Run..."})]})})})]}),a.jsx("div",{className:"space-y-3",children:jf(Z.value)&&(i!=null&&i.storage)?Z.value.connector.source.configuration.map((F,M)=>{const $=Z.value;return a.jsx(nd,{children:a.jsx(Tie,{configIndex:M,connectorDef:$,dataStorage:i.storage,onRemoveConfiguration:H=>{B(H)},onUpdateConfiguration:H=>j(H),dataMartStatus:typeof C=="object"?C.code:C,totalConfigurations:$.connector.source.configuration.length},M)},M)}):null})]})})}),a.jsx(Mt,{})]})}),a.jsx(nd,{children:a.jsx(NI,{isOpen:y,onClose:()=>{g(!1)},onSubmit:Z=>void _(Z),dataStorageType:t,existingConnector:jf(f().definition)?{source:f().definition.connector.source,storage:f().definition.connector.storage}:void 0,mode:"fields-only"})}),a.jsx(br,{open:D,onOpenChange:k,title:"Delete Configuration",description:"Are you sure you want to delete this configuration? This action cannot be undone.",confirmLabel:"Delete",cancelLabel:"Cancel",onConfirm:()=>{G()},onCancel:()=>{T(null)},variant:"destructive"})]})}function Aie({definitionType:e,storageType:t,preset:n,saveDataMartDefinition:r}){const{control:s}=yd(),[i,c]=h.useState(!1);return h.useEffect(()=>{e===$e.CONNECTOR&&!n?c(!0):c(!1)},[e,n]),a.jsxs("div",{className:"space-y-2",children:[e===$e.SQL&&a.jsx(doe,{control:s}),e===$e.TABLE&&a.jsx(foe,{control:s,storageType:t}),e===$e.VIEW&&a.jsx(hoe,{control:s,storageType:t}),e===$e.TABLE_PATTERN&&a.jsx(moe,{control:s,storageType:t}),e===$e.CONNECTOR&&a.jsx(Nie,{control:s,storageType:t,preset:n,autoOpen:i,saveDataMartDefinition:r})]})}function AI(){const[e]=zL(),t=e.get("preset");return h.useMemo(()=>{if(!t)return;const n=t.toLowerCase();return yee(n)},[t])}function Die(e,t){const[n,r]=h.useState(e);return h.useEffect(()=>{const s=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(s)}},[e,t]),n}const Oie=1e3,Iie=[Xa.SUCCESS,Xa.ERROR,Xa.CANCELLED];function Mie(e){const[t,n]=h.useState(!1),[r,s]=h.useState(null),i=h.useRef({triggerId:null,abortController:null}),c=h.useCallback(g=>i.current.triggerId===g,[]),u=h.useCallback(g=>{s({isValid:!1,error:g instanceof Error?g.message:"Validation failed"}),n(!1)},[]),f=h.useCallback(async()=>{const{triggerId:g,abortController:x}=i.current;if(g){x==null||x.abort(),i.current={triggerId:null,abortController:null},s(null),n(!1);try{await Tn.abortSqlDryRunTrigger(e,g)}catch(v){console.error("Failed to cancel trigger:",v)}}},[e]),m=h.useCallback(async(g,x)=>{for(;!x.aborted&&c(g);)try{const v=await Tn.getSqlDryRunTriggerStatus(e,g);if(Iie.includes(v)){const C=await Tn.getSqlDryRunTriggerResponse(e,g);s({isValid:C.isValid,error:C.error??void 0,bytes:C.bytes}),n(!1),i.current={triggerId:null,abortController:null};return}await new Promise(C=>setTimeout(C,Oie))}catch(v){u(v),i.current={triggerId:null,abortController:null};return}},[e,c,u]),y=h.useCallback(async g=>{await f(),n(!0),s(null);try{const{triggerId:x}=await Tn.createSqlDryRunTrigger(e,g),v=new AbortController;i.current={triggerId:x,abortController:v},await m(x,v.signal)}catch(x){u(x)}},[e,f,m,u]);return h.useEffect(()=>()=>{const{triggerId:g,abortController:x}=i.current;x==null||x.abort(),g&&Tn.abortSqlDryRunTrigger(e,g).catch(()=>{})},[e]),{validateSql:y,isLoading:t,result:r,cancel:f}}const kie=300;function Lie({sql:e,dataMartId:t,debounceDelay:n=kie,className:r="",onValidationStateChange:s}){const i=Die(e.trim(),n),{validateSql:c,isLoading:u,result:f,cancel:m}=Mie(t);h.useEffect(()=>{if(!i){m();const g={isLoading:!1,isValid:null,error:null,bytes:null};s==null||s(g);return}c(i)},[i,c,m,s]),h.useEffect(()=>{const g={isLoading:u,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(g)},[u,f,s]);const y=()=>u?a.jsxs("div",{className:"flex h-5 items-center gap-2",children:[a.jsx(Ec,{className:"h-4 w-4 animate-spin"}),a.jsx("span",{className:"text-sm",children:"Validating..."})]}):f?f.isValid?a.jsxs("div",{className:"flex h-5 items-center gap-2",children:[a.jsx(IP,{className:"h-4 w-4 text-green-600"}),a.jsx("span",{className:"text-sm font-medium text-green-600",children:"Valid SQL code"}),f.bytes!==void 0&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"mx-1 text-gray-400",children:"•"}),a.jsxs(Et,{children:[a.jsx(wt,{asChild:!0,children:a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx(lc,{className:"h-3 w-3 text-gray-600"}),a.jsx("span",{className:"text-xs text-gray-600",children:NQ(f.bytes)})]})}),a.jsx(Rt,{children:a.jsx("p",{className:"text-xs",children:"This is an estimated volume and may differ from the actual value"})})]})]})]}):a.jsxs("div",{className:"flex h-9 items-center gap-2",children:[a.jsx(ng,{className:"h-4 w-4 flex-shrink-0 text-red-600"}),f.error&&a.jsx("span",{className:"text-xs text-red-500",children:f.error})]}):a.jsxs("div",{className:"flex h-5 items-center gap-2 text-gray-500",children:[a.jsx(lc,{className:"h-4 w-4"}),a.jsx("span",{className:"text-sm",children:"Type a query to get started"})]});return a.jsx("div",{className:`inline-flex h-9 items-center px-3 py-2 ${r}`,children:y()})}const Pie={isValid:null,isLoading:!1,error:null},Uie=(e,t)=>{if(e!==$e.SQL)return"";const n=t;return(n==null?void 0:n.sqlQuery)??""},zie=e=>B2(e);function Fie({definitionType:e,initialDefinitionType:t,setDefinitionType:n}){const{dataMart:r,updateDataMartDefinition:s,runSchemaActualization:i}=vs(),c=AI();if(!r)throw new Error("Data mart not found");const{definition:u,id:f,storage:{type:m}}=r,[,y]=h.useState(Pie),[g,x]=h.useState(!1),v=h.useCallback(()=>{if(!e)return;const V={definitionType:e,definition:B2(e)};return u?{definitionType:e,definition:u}:V},[e,u]),C=h.useCallback(()=>{if(!e)return;const V=uoe(e,m);return yi(V)},[e,m]),S=Ro({resolver:C(),defaultValues:v(),mode:"onChange"}),{handleSubmit:E,reset:R,watch:j,formState:{isDirty:_,isValid:I}}=S,A=j("definition"),O=Uie(e,A);h.useEffect(()=>{e&&R(v())},[e,R,v]),h.useEffect(()=>{if(!e&&!t&&(c!=null&&c.definitionType)){n(c.definitionType);const V={definitionType:c.definitionType,definition:zie(c.definitionType)};R(V)}},[c,e,t,R,n]);const T=h.useCallback(V=>{y({isLoading:V.isLoading,isValid:V.isValid,error:V.error})},[]),D=h.useCallback(V=>{n(V)},[n]),k=h.useCallback(async V=>{if(e&&f)try{await s(f,V.definitionType,V.definition),x(!0),R(V)}catch(Z){console.error("Failed to update data mart definition:",Z)}},[f,e,s,R]);h.useEffect(()=>{g&&(x(!1),i==null||i())},[g,i]);const B=h.useCallback(V=>{V==null||V.preventDefault(),E(k)(V)},[E,k]),G=h.useCallback(()=>{R(v())},[R,v]),Y=()=>e?a.jsxs("form",{onSubmit:B,className:"space-y-4",children:[a.jsx(Aie,{definitionType:e,storageType:m,preset:c==null?void 0:c.connectorSourceTitle,saveDataMartDefinition:B}),e!==$e.CONNECTOR&&a.jsxs("div",{className:"flex items-center gap-4",children:[a.jsx(Ee,{variant:"default",type:"submit",disabled:!I||!_,children:"Save"}),a.jsx(Ee,{type:"button",variant:"ghost",onClick:G,disabled:!_,children:"Discard"}),e===$e.SQL&&O&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"h-6 w-px bg-gray-300"}),a.jsx(Lie,{sql:O,dataMartId:f,onValidationStateChange:T})]})]})]}):null;return a.jsx(i5,{...S,children:a.jsxs("div",{className:"space-y-4",children:[!t&&a.jsx(aoe,{initialType:e,onTypeSelect:D}),Y()]})})}function Hie(e){switch(e){case Re.GOOGLE_BIGQUERY:return{type:"bigquery-data-mart-schema",fields:[]};case Re.AWS_ATHENA:return{type:"athena-data-mart-schema",fields:[]};case Re.SNOWFLAKE:return{type:"snowflake-data-mart-schema",fields:[]};default:throw new Error(`Unsupported storage type: ${e}`)}}function DI(e){return e.type==="bigquery-data-mart-schema"}function OI(e){return e.type==="athena-data-mart-schema"}function II(e){return e.type==="snowflake-data-mart-schema"}function tN(e){return e!==null&&typeof e=="object"&&"mode"in e}function nN(e){return e!==null&&typeof e=="object"&&"isPrimaryKey"in e}function rN(e){return e!==null&&typeof e=="object"&&"isPrimaryKey"in e&&!("mode"in e)}function $ie(e){return e==null?"":typeof e=="string"||typeof e=="number"||typeof e=="boolean"?String(e):""}function l1(e){return e==null?e:JSON.parse(JSON.stringify(e))}function Vie(e){const t=l1(e),[n,r]=h.useState(t),[s,i]=h.useState(!1);h.useEffect(()=>{const f=l1(e);r(f),i(!1)},[e]);const c=h.useCallback(f=>{n?DI(n)&&f.every(tN)?(r({...n,fields:f}),i(!0)):OI(n)&&f.every(nN)?(r({...n,fields:f}),i(!0)):II(n)&&f.every(rN)&&(r({...n,fields:f}),i(!0)):f.length>0&&(tN(f[0])?(r({type:"bigquery-data-mart-schema",fields:f}),i(!0)):nN(f[0])?(r({type:"athena-data-mart-schema",fields:f}),i(!0)):rN(f[0])&&(r({type:"snowflake-data-mart-schema",fields:f}),i(!0)))},[n]),u=h.useCallback(()=>{const f=l1(e);r(f),i(!1)},[e]);return{schema:n,isDirty:s,updateSchema:c,resetSchema:u,setIsDirty:i}}function Bie(e,t){const n=h.useRef(!1),r=h.useRef(!1),[s,i]=h.useState("idle");return h.useEffect(()=>{e||(n.current||r.current)&&(i(t?"error":"success"),n.current=!1,r.current=!1)},[e,t]),{operationStatus:s,startSaveOperation:()=>{n.current=!0,i("idle")},startActualizeOperation:()=>{r.current=!0,i("idle")},resetOperationStatus:()=>{i("idle")}}}function Gie(e){const t=h.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]=h.useState({});return h.useEffect(()=>{r(t)},[t]),{columnVisibility:n,setColumnVisibility:r,defaultHiddenColumns:t}}function MI(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 i=e;return i.fields&&i.fields.length>0?i.fields.some(c=>MI(c,t)):!1}function kI(e,t,n=""){const r=[];return e.forEach((s,i)=>{const c=n?`${n}.${String(i)}`:String(i),u=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((u||f||m)&&r.push(c),s.fields&&s.fields.length>0){const y=kI(s.fields,t,c);y.length>0&&(r.includes(c)||r.push(c),r.push(...y))}}),r}function qie(e,t,n){const r=e.original;if(!n)return!0;const s=n.toLowerCase();return MI(r,s)}function Kie(e){const[t,n]=h.useState(""),r=h.useCallback(i=>{n(i),e.setGlobalFilter(i)},[e]),s=t.toLowerCase();return{value:t,onChange:r,searchValue:s}}function Zie(e){const[t,n]=h.useState(new Set),[r,s]=h.useState(null),i=h.useRef(""),c=h.useMemo(()=>{const C=S=>S.some(E=>E.type===ar.RECORD||E.type===ar.STRUCT||E.fields&&C(E.fields));return C(e)},[e]),u=h.useCallback(C=>{n(S=>{const E=new Set(S);return E.has(C)?E.delete(C):E.add(C),E})},[]),f=h.useCallback(()=>{const C=[],S=(E,R="")=>{E.forEach((j,_)=>{const I=R?`${R}.${String(_)}`:String(_);(j.type===ar.RECORD||j.type===ar.STRUCT)&&j.fields&&j.fields.length>0&&(C.push(I),S(j.fields,I))})};S(e),n(E=>C.every(j=>E.has(j))?new Set:new Set(C))},[e]),m=h.useMemo(()=>{const C=[],S=(E,R="",j=0)=>{E.forEach((_,I)=>{const A=R?`${R}.${String(I)}`:String(I),O=_.type===ar.RECORD||_.type===ar.STRUCT;C.push({..._,path:A,level:j}),O&&_.fields&&t.has(A)&&S(_.fields,A,j+1)})};return S(e),C},[e,t]),y=h.useCallback(C=>{if(C!==i.current)if(i.current=C,C){r===null&&s(new Set(t));const E=kI(e,C).filter(R=>{const j=R.split(".").map(Number);let _=e,I;for(let A=0;A<j.length;A++){if(I=_[j[A]],!I)return!1;if((I.type===ar.RECORD||I.type===ar.STRUCT)&&I.fields&&I.fields.length>0)return!0;A<j.length-1&&(_=I.fields??[])}return!1});n(R=>{const j=new Set(R);return E.forEach(_=>{j.add(_)}),j})}else r!==null&&(n(r),s(null))},[e,t,r]),g=h.useCallback(C=>{const S=m[C];return S.type===ar.RECORD||S.type===ar.STRUCT},[m]),x=h.useMemo(()=>e.map(C=>({...C,fields:void 0})),[e]),v=h.useMemo(()=>{const C=[],S=(E,R="")=>{E.forEach((j,_)=>{const I=R?`${R}.${String(_)}`:String(_);(j.type===ar.RECORD||j.type===ar.STRUCT)&&j.fields&&j.fields.length>0&&(C.push(I),S(j.fields,I))})};return S(e),C.length===0?!1:C.every(E=>t.has(E))},[e,t]);return{expandedRecords:t,hasRecordFields:c,toggleRecordExpansion:u,toggleAllRecords:f,flattenedFields:m,handleSearchChange:y,isRecordType:g,topLevelFields:x,allExpanded:v}}function Yie(e,t,n,r){const s=h.useCallback((f,m)=>{if(n){const y=[...e],g=t[f].path;if(!g)y[f]={...y[f],...m};else{const x=g.split(".").map(Number);let v=y,C;for(let E=0;E<x.length-1;E++)C=v[x[E]],v=C.fields??[];const S=x[x.length-1];v[S]&&(v[S]={...v[S],...m})}n(y)}},[e,t,n]),i=h.useCallback(()=>{if(n){const f={name:"",type:ar.STRING,mode:th.NULLABLE,isPrimaryKey:!1,status:Qa.DISCONNECTED};n([...e,f])}},[e,n]),c=h.useCallback(f=>{if(n){const m=[...e],y=t[f].path;if(!y)m.splice(f,1);else{const g=y.split(".").map(Number);let x=m,v;for(let S=0;S<g.length-1;S++)v=x[g[S]],x=v.fields??[];const C=g[g.length-1];x.splice(C,1)}n(m)}},[e,t,n]),u=h.useCallback(f=>{var m,y;if(n&&r){const g=[...e],x=t[f].path,v={name:"",type:ar.STRING,mode:th.NULLABLE,isPrimaryKey:!1,status:Qa.DISCONNECTED};if(!x)(m=g[f]).fields??(m.fields=[]),g[f].fields.push(v);else{const C=x.split(".").map(Number);let S=g;for(let E=0;E<C.length;E++){const R=C[E];E===C.length-1?((y=S[R]).fields??(y.fields=[]),S[R].fields.push(v)):S=S[R].fields??[]}}n(g)}},[e,t,n,r]);return{updateField:s,handleAddRow:i,handleDeleteRow:c,handleAddNestedField:u}}function Q2(e,t,n){return{handleDragEnd:h.useCallback(s=>{const{active:i,over:c}=s;if(!c||i.id===c.id||!t)return;if(!n){const x=Number(i.id),v=Number(c.id),C=[...e],[S]=C.splice(x,1);C.splice(v,0,S),t(C);return}const u=n.findIndex((x,v)=>(x.path??String(v))===i.id),f=n.findIndex((x,v)=>(x.path??String(v))===c.id);if(u===-1||f===-1)return;const m=n[u].path,y=n[f].path,g=[...e];if(!m&&!y){const[x]=g.splice(u,1);g.splice(f,0,x),t(g);return}if(m&&y){const x=m.split(".").map(Number),v=y.split(".").map(Number);if(x.length===v.length&&x.slice(0,-1).join(".")===v.slice(0,-1).join(".")){let C=g;for(let j=0;j<x.length-1;j++)C=C[x[j]].fields??[];const S=x[x.length-1],E=v[v.length-1],[R]=C.splice(S,1);C.splice(E,0,R),t(g)}}},[e,n,t])}}function Wie(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return h.useMemo(()=>r=>{t.forEach(s=>s(r))},t)}const Zy=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function bd(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function J2(e){return"nodeType"in e}function Na(e){var t,n;return e?bd(e)?e:J2(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function eC(e){const{Document:t}=Na(e);return e instanceof t}function qh(e){return bd(e)?!1:e instanceof Na(e).HTMLElement}function LI(e){return e instanceof Na(e).SVGElement}function Sd(e){return e?bd(e)?e.document:J2(e)?eC(e)?e:qh(e)||LI(e)?e.ownerDocument:document:document:document}const So=Zy?h.useLayoutEffect:h.useEffect;function tC(e){const t=h.useRef(e);return So(()=>{t.current=e}),h.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 Xie(){const e=h.useRef(null),t=h.useCallback((r,s)=>{e.current=setInterval(r,s)},[]),n=h.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,n]}function sh(e,t){t===void 0&&(t=[e]);const n=h.useRef(e);return So(()=>{n.current!==e&&(n.current=e)},t),n}function Kh(e,t){const n=h.useRef();return h.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function Lg(e){const t=tC(e),n=h.useRef(null),r=h.useCallback(s=>{s!==n.current&&(t==null||t(s,n.current)),n.current=s},[]);return[n,r]}function _b(e){const t=h.useRef();return h.useEffect(()=>{t.current=e},[e]),t.current}let c1={};function Zh(e,t){return h.useMemo(()=>{if(t)return t;const n=c1[e]==null?0:c1[e]+1;return c1[e]=n,e+"-"+n},[e,t])}function PI(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((i,c)=>{const u=Object.entries(c);for(const[f,m]of u){const y=i[f];y!=null&&(i[f]=y+e*m)}return i},{...t})}}const Vu=PI(1),Pg=PI(-1);function Qie(e){return"clientX"in e&&"clientY"in e}function nC(e){if(!e)return!1;const{KeyboardEvent:t}=Na(e.target);return t&&e instanceof t}function Jie(e){if(!e)return!1;const{TouchEvent:t}=Na(e.target);return t&&e instanceof t}function Nb(e){if(Jie(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 Qie(e)?{x:e.clientX,y:e.clientY}:null}const oh=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[oh.Translate.toString(e),oh.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),aN="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function ele(e){return e.matches(aN)?e:e.querySelector(aN)}const tle={display:"none"};function nle(e){let{id:t,value:n}=e;return re.createElement("div",{id:t,style:tle},n)}function rle(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 re.createElement("div",{id:t,style:s,role:"status","aria-live":r,"aria-atomic":!0},n)}function ale(){const[e,t]=h.useState("");return{announce:h.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const UI=h.createContext(null);function sle(e){const t=h.useContext(UI);h.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function ole(){const[e]=h.useState(()=>new Set),t=h.useCallback(r=>(e.add(r),()=>e.delete(r)),[e]);return[h.useCallback(r=>{let{type:s,event:i}=r;e.forEach(c=>{var u;return(u=c[s])==null?void 0:u.call(c,i)})},[e]),t]}const ile={draggable:`
|
|
798
|
+
`).filter(m=>m.trim());n(r,f)}})}function Soe({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s,default:i}=e,c=e.title??e.name,u=f=>{if(!f||typeof f!="string"&&typeof f!="number")return"";const m=typeof f=="string"?f:f.toString();try{const y=new Date(m);return isNaN(y.getTime())?"":y.toISOString().split("T")[0]}catch{return""}};return a.jsx(It,{id:r,name:r,type:"date",value:t[r]||u(i)||"",placeholder:s??`Enter ${c.toLowerCase()}`,onChange:f=>{n(r,f.target.value)}})}function Coe({specification:e,configuration:t,onValueChange:n}){const{name:r,placeholder:s}=e,i=e.title??e.name;return a.jsx(It,{id:r,name:r,type:"text",value:t[r]||"",placeholder:s??`Enter ${i.toLowerCase()}`,onChange:c=>{n(r,c.target.value)}})}function Eoe({specification:e,configuration:t,onValueChange:n}){const r=e.title??e.name,{name:s,placeholder:i,default:c}=e;return a.jsx(wo,{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:i??`Enter ${r.toLowerCase()} as JSON`,rows:6,className:"font-mono",onChange:u=>{try{const f=JSON.parse(u.target.value);n(s,f)}catch{n(s,u.target.value)}}})}function woe({specification:e,configuration:t,onValueChange:n,isEditingExisting:r,isSecretEditing:s}){const i=e.title??e.name,c=r&&!s;return a.jsx(It,{id:e.name,...c?{}:{name:e.name},type:c?"password":"text",autoComplete:c?"new-password":"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,value:c?Cb:t[e.name]||"",...c?{readOnly:!0,disabled:!0}:{},...c?{}:{placeholder:e.placeholder??`Enter ${i.toLowerCase()}`},...c?{}:{onChange:u=>{n(e.name,u.target.value)}}})}function Roe({specification:e,configuration:t,onValueChange:n,specOptions:r}){const{name:s,placeholder:i,default:c}=e,u=e.title??e.name,f=r.map(m=>({value:m,label:m}));return a.jsx(V2,{options:f,value:t[s]||c||"",onValueChange:m=>{n(s,m)},placeholder:i??`Select ${u.toLowerCase()}`,emptyMessage:"No options available",className:"w-full"})}function joe(){const e=h.useRef(new Pf),t=h.useCallback(async(s,i,c)=>await e.current.exchangeCredentials(s,{fieldPath:c,payload:i}),[]),n=h.useCallback(async(s,i)=>{try{return await e.current.checkOAuthStatus(s,i)}catch{return{valid:!1}}},[]),r=h.useCallback(async(s,i)=>await e.current.getOAuthSettings(s,i),[]);return{exchangeCredentials:t,checkStatus:n,getSettings:r}}let wf=null;function Toe({appId:e,scope:t,onSuccess:n,onError:r,disabled:s=!1,children:i}){const[c,u]=h.useState(!1),[f,m]=h.useState(!1),[y,g]=h.useState(null);h.useEffect(()=>{if(window.FB){m(!0);return}if(document.getElementById("facebook-jssdk")){const E=setInterval(()=>{window.FB&&(m(!0),clearInterval(E))},100);return()=>{clearInterval(E)}}if(!e)return;if(wf&&wf!==e){console.warn("Facebook SDK already initialized with different appId");return}wf??(wf=e),window.fbAsyncInit=function(){window.FB&&wf&&(window.FB.init({appId:wf,cookie:!0,xfbml:!0,version:"v23.0"}),m(!0))};const S=document.createElement("script");S.id="facebook-jssdk",S.src="https://connect.facebook.net/en_US/sdk.js",S.async=!0,S.defer=!0,S.crossOrigin="anonymous",document.body.appendChild(S)},[e]);const x=()=>{if(!window.FB||!f){const S=new Error("Facebook SDK not loaded or not ready");g(S.message),r==null||r(S);return}u(!0),g(null),window.FB.login(S=>{var E;if(S.status==="connected"&&S.authResponse){const{accessToken:R,expiresIn:j,userID:_}=S.authResponse;(E=window.FB)==null||E.api("/me?fields=name,email",I=>{const A={accessToken:R,expiresIn:j,userID:_,userName:I.name,userEmail:I.email};n(A),u(!1)})}else{const R=new Error("User cancelled login or did not fully authorize");g(R.message),r==null||r(R),u(!1)}},{scope:t})},v=s||c||!f,C=()=>c?"Connecting...":i||(f?"Continue with Facebook":"Loading...");return a.jsxs("div",{className:"flex flex-col gap-2",children:[a.jsxs(Ee,{type:"button",onClick:x,disabled:v,className:"flex items-center justify-center gap-2 rounded-md border-none bg-[#1877F2] px-4 py-2.5 text-sm font-semibold text-white hover:bg-[#166FE5] disabled:cursor-not-allowed disabled:opacity-60",children:[a.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:a.jsx("path",{d:"M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036 26.805 26.805 0 0 0-.733-.009c-.707 0-1.259.096-1.675.309a1.686 1.686 0 0 0-.679.622c-.258.42-.374.995-.374 1.752v1.297h3.919l-.386 2.103-.287 1.564h-3.246v8.245C19.396 23.238 24 18.179 24 12.044c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.628 3.874 10.35 9.101 11.647Z"})}),C()]}),y&&a.jsx("div",{className:"mt-1 text-xs text-red-600",children:y})]})}function _oe({isLoading:e,status:t,settings:n,onOAuthSuccess:r}){const s=i=>{r({accessToken:i.accessToken})};return a.jsx("div",{className:"mt-2 mb-2",children:a.jsx(Toe,{appId:n==null?void 0:n.vars.AppId,scope:n==null?void 0:n.vars.Scopes,onSuccess:s,disabled:e,children:t!=null&&t.user?a.jsxs(a.Fragment,{children:["Authenticated as ",a.jsx("strong",{children:t.user.name??t.user.id})]}):"Continue with Facebook"})})}function fI({specification:e,option:t,configuration:n,onValueChange:r,connectorName:s,onSecretEditToggle:i,secretEditing:c={},isEditingExisting:u=!1}){const[f,m]=h.useState(!1),[y,g]=h.useState(null),[x,v]=h.useState(null),[C,S]=h.useState(null),E=h.useMemo(()=>{const V=n[e.name],Z=t!=null&&t.value&&V?V[t.value]:V;return Z==null?void 0:Z._source_credential_id},[n,e.name,t==null?void 0:t.value]),R=h.useMemo(()=>t?`${e.name}.${t.value}`:e.name,[e.name,t]),j=h.useMemo(()=>{const V=n[e.name];if(t!=null&&t.value&&V){const Z=V[t.value];return Z&&typeof Z=="object"&&!Array.isArray(Z)?Z:{}}return V&&typeof V=="object"&&!Array.isArray(V)?V:{}},[n,e.name,t==null?void 0:t.value]),_=h.useMemo(()=>{const V=j;return"_source_credential_id"in V?!1:!!(t!=null&&t.items&&Object.keys(t.items).some(F=>F in V&&V[F]!==void 0&&V[F]!==""))},[j,t]),[I,A]=h.useState(_);h.useEffect(()=>{const V="_source_credential_id"in j,Z=(t==null?void 0:t.items)&&Object.keys(t.items).some(F=>F in j&&j[F]!==void 0&&j[F]!=="");V&&I?A(!1):Z&&!I&&A(!0)},[j,t,I]);const O=(V,Z)=>{if(!(t!=null&&t.value))return;const F=n[e.name]&&typeof n[e.name]=="object"?n[e.name]:{};r(e.name,{...F,[t.value]:{...typeof F[t.value]=="object"&&F[t.value]!==null?F[t.value]:{},[V]:Z}})},{checkStatus:T,getSettings:D,exchangeCredentials:k}=joe(),B=async V=>{try{m(!0),S(null);const Z=await k(s,V,R),F=n[e.name];t?r(e.name,{...F,[t.value]:{_source_credential_id:Z.credentialId}}):r(e.name,{_source_credential_id:Z.credentialId})}catch(Z){const F=Z instanceof Error?Z.message:"Failed to exchange OAuth credentials";console.error("Failed to exchange OAuth credentials:",Z),S(F)}finally{m(!1)}};h.useEffect(()=>{if(!E){g(null),m(!1);return}let V=!1;return(async()=>{try{m(!0);const F=await T(s,E);V||g(F)}catch(F){V||(console.error("Failed to validate credentials:",F),g({valid:!1}))}finally{V||m(!1)}})(),()=>{V=!0}},[E,s,T]),h.useEffect(()=>{(async()=>{try{const Z=await D(s,R);v(Z)}catch(Z){console.error("Failed to fetch settings:",Z),v(null)}})()},[s,R,D]);const G=!!(x!=null&&x.isEnabled);if((I||!G)&&(t!=null&&t.items))return a.jsxs("div",{className:"space-y-4",children:[Object.entries(t.items).map(([V,Z])=>{const F=Array.isArray(Z.attributes)?Z.attributes.includes("SECRET")&&j[V]!==void 0:!1,M=c[e.name]??!1;return a.jsxs("div",{className:"mb-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx(Ga,{htmlFor:V,required:Z.required,tooltip:Z.description,className:"mb-2 justify-start",children:Z.title??V}),F&&u&&i&&a.jsx(Ee,{variant:"ghost",size:"sm",type:"button",onClick:()=>{i(e.name,!M)},children:M?"Cancel":"Edit"})]}),K2({specification:{...Z,name:V},configuration:j,onValueChange:($,H)=>{O($,H)},flags:{isEditingExisting:u,isSecret:F,isSecretEditing:M},connectorName:s})]},V)}),G&&a.jsx(Ee,{variant:"link",size:"sm",type:"button",onClick:()=>{r(e.name,{[t.value]:{}}),A(!1),m(!1)},className:"px-0",children:"Back to OAuth"})]});const Y=(()=>{switch(s){case"FacebookMarketing":return a.jsx(_oe,{isLoading:f,status:y,settings:x,onOAuthSuccess:B});default:return null}})();return a.jsxs("div",{className:"space-y-3",children:[Y,C&&a.jsx("div",{className:"text-destructive text-sm",children:C}),(t==null?void 0:t.items)&&Object.keys(t.items).length>0&&a.jsx(Ee,{variant:"link",size:"sm",type:"button",onClick:()=>{r(e.name,{[t.value]:{}}),A(!0)},className:"px-0",children:"Manually"})]})}function K2({specification:e,configuration:t,onValueChange:n,flags:r,connectorName:s}){const{requiredType:i,options:c}=e,{isSecret:u=!1,isEditingExisting:f=!1,isSecretEditing:m=!1}=r??{};if(e.attributes&&Array.isArray(e.attributes)&&e.attributes.includes("OAUTH_FLOW"))return a.jsx(fI,{specification:e,configuration:t,onValueChange:n,connectorName:s});if(u)return a.jsx(woe,{specification:e,configuration:t,onValueChange:n,isEditingExisting:f,isSecretEditing:m});if(c&&c.length>0)return a.jsx(Roe,{specification:e,configuration:t,onValueChange:n,specOptions:c});switch(i){case As.BOOLEAN:return a.jsx(xoe,{specification:e,configuration:t,onValueChange:n});case As.NUMBER:return a.jsx(voe,{specification:e,configuration:t,onValueChange:n});case As.ARRAY:return a.jsx(boe,{specification:e,configuration:t,onValueChange:n});case As.OBJECT:return a.jsx(Eoe,{specification:e,configuration:t,onValueChange:n});case As.DATE:return a.jsx(Soe,{specification:e,configuration:t,onValueChange:n});case As.STRING:default:return a.jsx(Coe,{specification:e,configuration:t,onValueChange:n})}}function Noe({specification:e,configuration:t,isEditingExisting:n,isSecretEditing:r,isSecret:s,onValueChange:i,onSecretEditToggle:c,connectorName:u}){return a.jsxs(Bi,{children:[e.requiredType!==As.BOOLEAN&&a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx(Ga,{htmlFor:e.name,required:e.required,tooltip:e.description,children:e.title??e.name}),s&&n&&a.jsx(Ee,{variant:"ghost",size:"sm",type:"button",onClick:()=>{c(e.name,!r)},children:r?"Cancel":"Edit"})]}),K2({specification:e,configuration:t,onValueChange:i,flags:{isSecret:s,isEditingExisting:n,isSecretEditing:r},connectorName:u})]},e.name)}function Aoe({specification:e,configuration:t,onValueChange:n,isEditingExisting:r,isSecretEditing:s,onSecretEditToggle:i,connectorName:c}){const u=h.useMemo(()=>{var v,C;const x=t[e.name];if(x&&typeof x=="object"){const S=Object.keys(x);if(S.length>0)return S[0]}return((C=(v=e.oneOf)==null?void 0:v[0])==null?void 0:C.value)??""},[t,e.name,e.oneOf]),[f,m]=h.useState(u);if(h.useEffect(()=>{m(u)},[u]),h.useEffect(()=>{if(f){const x=t[e.name];x&&typeof x=="object"&&f in x||n(e.name,{[f]:{}})}},[f,e.name]),!e.oneOf)return null;const y=x=>{m(x)},g=(x,v,C)=>{const S=t[e.name]&&typeof t[e.name]=="object"?t[e.name]:{};n(e.name,{[x]:{...typeof S[x]=="object"&&S[x]!==null?S[x]:{},[v]:C}})};return a.jsx(ore,{label:e.title??e.name,options:e.oneOf.map(x=>({value:x.value,label:x.label})),value:f,onValueChange:y,children:e.oneOf.map(x=>{const v=x.attributes&&Array.isArray(x.attributes)&&x.attributes.includes("OAUTH_FLOW");return a.jsx(Zne,{value:x.value,children:v?a.jsx(fI,{specification:e,option:x,configuration:t,onValueChange:n,connectorName:c,onSecretEditToggle:i,secretEditing:{[e.name]:s},isEditingExisting:r}):Object.entries(x.items).map(([C,S])=>{const E=t[e.name]&&typeof t[e.name]=="object"?t[e.name]:{},R=Array.isArray(S.attributes)&&Object.keys(E)[0]===x.value?S.attributes.includes("SECRET"):!1,j=typeof t[e.name]=="object"&&t[e.name]!==null?t[e.name]:{},_=typeof j[x.value]=="object"&&j[x.value]!==null?j[x.value]:{};return a.jsxs("div",{className:"mb-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx(Ga,{htmlFor:C,required:S.required,tooltip:S.description,className:"mb-2 justify-start",children:C}),R&&r&&a.jsx(Ee,{variant:"ghost",size:"sm",type:"button",onClick:()=>{i(e.name,!s)},children:s?"Cancel":"Edit"})]}),K2({specification:{...S,name:C},configuration:_,onValueChange:(I,A)=>{g(x.value,I,A)},flags:{isEditingExisting:r,isSecret:R,isSecretEditing:s},connectorName:c})]},C)})},x.value)})},e.name)}function W_(e,t,n,r,s,i,c){return e.map(u=>{const f=Array.isArray(u.attributes)?u.attributes.includes("SECRET"):!1,m=s[u.name];return u.oneOf&&u.requiredType===As.OBJECT?a.jsx(Aoe,{specification:u,configuration:t,onValueChange:n,isEditingExisting:i,isSecretEditing:m,onSecretEditToggle:r,connectorName:c},u.name):a.jsx(Noe,{specification:u,configuration:t,isEditingExisting:i,isSecret:f,isSecretEditing:m,onValueChange:n,onSecretEditToggle:r,connectorName:c},u.name)})}function X_({collapsibleTitle:e,items:t,configuration:n,onValueChange:r,onSecretEditToggle:s,secretEditing:i,isEditingExisting:c,connectorName:u}){return e?a.jsx(x6,{title:e,children:W_(t,n,r,s,i,c,u)}):W_(t,n,r,s,i,c,u)}function Doe({currentConnectorName:e,onCopyConfiguration:t,connectorSpecification:n}){const[r,s]=h.useState([]),[i,c]=h.useState(!1),[u,f]=h.useState(!1),m=h.useCallback(async()=>{c(!0);try{const x=await Tn.getDataMartsByConnectorName(e);s(x)}catch{s([])}finally{c(!1)}},[e]);h.useEffect(()=>{u&&m()},[u,m]);const y=(x,v)=>{const C=v._id;if(!C){console.error("Configuration does not have _id field");return}t({dataMartId:x.id,dataMartTitle:x.title,configId:C,configuration:v}),f(!1)},g=x=>{const C=[],S=R=>{if(!n)return!0;const j=n.find(_=>_.name===R);return(j==null?void 0:j.required)??!1},E=(R,j,_=0,I=!0)=>{if(R.startsWith("_")||I&&_===0&&!S(R))return;let A=null;if(j==null)A="N/A";else if(typeof j=="string")A=j;else if(typeof j=="number"||typeof j=="boolean")A=String(j);else if(Array.isArray(j))A=JSON.stringify(j);else if(typeof j=="object"){C.push({key:R,value:"{",indent:_}),Object.entries(j).forEach(([O,T])=>{E(O,T,_+1,!1)}),C.push({key:"",value:"}",indent:_});return}else A=JSON.stringify(j);C.push({key:R,value:A,indent:_})};for(const[R,j]of Object.entries(x))E(R,j);return a.jsx("div",{className:"space-y-1 font-mono text-xs",children:C.map(({key:R,value:j,indent:_},I)=>a.jsxs("div",{className:"flex gap-2",style:{paddingLeft:`${String(_*12)}px`},children:[R&&a.jsxs("span",{className:"font-medium",children:[R,":"]}),a.jsx("span",{className:"text-muted-foreground truncate",title:j,children:j})]},I))})};return a.jsx(Ya,{children:a.jsxs(_r,{open:u,onOpenChange:f,children:[a.jsx(Nr,{asChild:!0,children:a.jsxs(Ee,{type:"button",variant:"ghost",size:"sm",className:"cursor-pointer",children:[a.jsx("span",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:"Copy from…"}),a.jsx(_a,{className:se("text-foreground/75 h-3.5 w-3.5 transition-transform duration-200",u&&"rotate-90")})]})}),a.jsx(Ar,{side:"bottom",align:"end",className:"w-72",children:i?a.jsx(Nt,{disabled:!0,children:"Loading…"}):r.length===0?a.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 p-4 text-center",children:[a.jsx("div",{className:"bg-muted/70 rounded-full p-3",children:a.jsx(GU,{className:"text-muted-foreground h-6 w-6",strokeWidth:1.5})}),a.jsx("span",{className:"text-foreground text-sm font-medium",children:"No matching Data Marts"}),a.jsx("span",{className:"text-muted-foreground text-sm",children:"You can reuse configuration settings only from connector-based Data Marts that use the same source."})]}):a.jsxs("div",{className:"flex flex-col gap-2",children:[a.jsx("div",{className:"text-muted-foreground border-b p-2 text-sm",children:"Select one of your existing Data Marts to reuse its configuration settings."}),a.jsx("div",{children:r.map(x=>{const C=x.definition.connector.source.configuration;return C.length===0?null:C.length===1?a.jsxs(Et,{delayDuration:300,children:[a.jsx(wt,{asChild:!0,children:a.jsxs(Nt,{onSelect:()=>{y(x,C[0])},children:[a.jsx(tg,{className:"text-foreground h-4 w-4"}),x.title]})}),a.jsx(Rt,{side:"right",className:"max-w-sm",children:g(C[0])})]},x.id):a.jsxs(TS,{children:[a.jsxs(_S,{className:"flex items-center gap-2",children:[a.jsx(tg,{className:"text-foreground h-4 w-4"}),a.jsx("span",{children:x.title})]}),a.jsx(NS,{children:C.map((S,E)=>a.jsxs(Et,{delayDuration:300,children:[a.jsx(wt,{asChild:!0,children:a.jsxs(Nt,{onSelect:()=>{y(x,S)},children:["Configuration ",E+1]})}),a.jsx(Rt,{side:"right",className:"max-w-sm",children:g(S)})]},E))})]},x.id)})})]})})]})})}function Q_({connector:e,connectorSpecification:t,onConfigurationChange:n,onValidationChange:r,initialConfiguration:s,loading:i=!1,isEditingExisting:c=!1}){const[u,f]=h.useState({}),m=h.useRef(!1),y=h.useRef(!1),[g,x]=h.useState({});h.useEffect(()=>{if(t){y.current=!0;const O={...s??{}};t.forEach(T=>{const D=Array.isArray(T.attributes)?T.attributes.includes("SECRET"):!1;O[T.name]===void 0&&T.default!==void 0&&(O[T.name]=T.default),c&&D&&(O[T.name]=Cb)}),f(O),m.current=!0,setTimeout(()=>{y.current=!1},0)}},[t,s,c]),h.useEffect(()=>{m.current&&s&&Object.keys(s).length>0&&(y.current=!0,f({...s}),setTimeout(()=>{y.current=!1},0))},[s]),h.useEffect(()=>{m.current&&!y.current&&Object.keys(u).length>0&&(n==null||n(u))},[u,n]);const v=(O,T)=>{f(D=>({...D,[O]:T}))},C=h.useCallback(O=>!(O==null||typeof O=="string"&&O.trim()===""||typeof O=="number"&&isNaN(O)||Array.isArray(O)&&O.length===0),[]),S=h.useCallback((O,T)=>{var k,B;if(typeof O!="object"||O===null)return C(O);if((k=T.attributes)!=null&&k.includes("OAUTH_FLOW")&&"_source_credential_id"in O)return!0;const D=(B=T.oneOf)==null?void 0:B.filter(G=>G.value===Object.keys(O)[0]);return D?D.every(G=>{var Y;if((Y=G.attributes)!=null&&Y.includes("OAUTH_FLOW")){const V=O[G.value];if(typeof V=="object"&&V!==null){if("_source_credential_id"in V)return!0;const Z=Object.entries(G.items).filter(([,F])=>F.required);if(Z.length>0)return Z.every(([F])=>{const M=V[F];return C(M)})}return!1}return Object.entries(G.items).every(([,V])=>G.value in O?S(O[G.value],V):!1)}):C(O[T.name])},[C]),E=h.useCallback((O,T)=>{const D=T.filter(Y=>Y.required&&Y.oneOf),k=D.length===0?!0:D.some(Y=>S(O[Y.name],Y)),G=T.filter(Y=>Y.required&&Y.name!=="Fields").every(Y=>C(O[Y.name]));return k&&G},[C,S]),R=(O,T)=>{x(D=>({...D,[O]:T})),f(T?D=>({...D,[O]:""}):D=>({...D,[O]:Cb}))},j=O=>{const T={...u};Object.entries(O.configuration).forEach(([D,k])=>{["_id","_copiedFrom"].includes(D)||(T[D]=k)}),T._copiedFrom={dataMartId:O.dataMartId,dataMartTitle:O.dataMartTitle,configId:O.configId},f(T)};if(h.useEffect(()=>{if(t&&r){const O=E(u,t);r(O)}},[u,t,r,E]),i)return a.jsx(D2,{variant:"list"});if(!t||t.length===0)return a.jsxs(ni,{children:[a.jsx(oc,{connector:e}),a.jsx(ti,{icon:a.jsx(Kf,{size:56,strokeWidth:1}),title:"No configuration found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),a.jsx($u,{label:"Need configuration?"})]});const _=[...t].filter(O=>{var T;return O.name!=="Fields"&&!((T=O.attributes)!=null&&T.includes("HIDE_IN_CONFIG_FORM"))}).sort((O,T)=>{const D=k=>{const B=k.default!=null&&k.default!=="";return k.required&&!B?1:k.required&&B?2:!k.required&&!B?3:4};return D(O)-D(T)}),I=_.filter(O=>{var T;return!((T=O.attributes)!=null&&T.includes("ADVANCED"))}),A=_.filter(O=>{var T;return(T=O.attributes)==null?void 0:T.includes("ADVANCED")});return a.jsx(a.Fragment,{children:a.jsxs(ni,{children:[a.jsx(oc,{connector:e}),a.jsxs(al,{children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("h3",{className:"text-muted-foreground/75 text-xs font-semibold tracking-wide uppercase",children:"Configure Settings"}),a.jsx(Doe,{currentConnectorName:e.name,onCopyConfiguration:j,connectorSpecification:t})]}),I.length>0&&a.jsx(X_,{items:I,configuration:u,onValueChange:v,onSecretEditToggle:R,secretEditing:g,isEditingExisting:c,connectorName:e.name}),A.length>0&&a.jsx(X_,{collapsibleTitle:"Advanced Settings",items:A,configuration:u,onValueChange:v,onSecretEditToggle:R,secretEditing:g,isEditingExisting:c,connectorName:e.name})]})]})})}function Ooe({connector:e,connectorFields:t,selectedField:n,connectorName:r,loading:s=!1,onFieldSelect:i}){const c=r?`Select data for ${r}`:"Select data";return s?a.jsx(D2,{variant:"list"}):!t||t.length===0?a.jsxs(ni,{children:[a.jsx(oc,{connector:e}),a.jsx(ti,{icon:a.jsx(Kf,{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."}),a.jsx($u,{label:"Missing some data?"})]}):a.jsxs(ni,{children:[a.jsx(oc,{connector:e}),a.jsxs(al,{title:c,children:[t.map(u=>a.jsx(v6,{type:"radio",id:u.name,name:"selectedField",value:u.name,label:u.overview??u.name,checked:n===u.name,onChange:f=>{i(f)},tooltip:u.name&&a.jsxs("div",{className:"flex flex-col gap-2 py-1",children:[a.jsxs("p",{children:[a.jsx("span",{className:"font-semibold",children:"Table name:"})," ",u.destinationName??u.name]}),u.description&&a.jsxs("p",{children:[a.jsx("span",{className:"font-semibold",children:"Description:"})," ",u.description]}),u.documentation&&a.jsxs(Wr,{to:u.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",a.jsx(_a,{className:"h-3 w-3"})]})]}),selected:n===u.name},u.name)),a.jsx($u,{label:"Missing some data?"})]})]})}var ao=(e=>(e.ASC="asc",e.DESC="desc",e.ORIGINAL="original",e))(ao||{});function J_({connector:e,connectorFields:t,selectedField:n,selectedFields:r,onFieldToggle:s}){const i=h.useRef(null),[c,u]=h.useState(""),[f,m]=h.useState(ao.ORIGINAL),y=t==null?void 0:t.find(R=>R.name===n),g=h.useMemo(()=>(y==null?void 0:y.fields)??[],[y==null?void 0:y.fields]),x=h.useMemo(()=>(y==null?void 0:y.uniqueKeys)??[],[y==null?void 0:y.uniqueKeys]),v=h.useMemo(()=>{const R=new Map;return g.forEach((j,_)=>R.set(j.name,_)),R},[g]),C=h.useMemo(()=>{const R=g.filter(_=>_.name.toLowerCase().includes(c.toLowerCase().trim())),j=(_,I)=>{const A=x.includes(_.name),O=x.includes(I.name);if(A&&!O)return-1;if(!A&&O)return 1;if(f===ao.ASC)return _.name.localeCompare(I.name);if(f===ao.DESC)return I.name.localeCompare(_.name);const T=v.get(_.name)??0,D=v.get(I.name)??0;return T-D};return[...R].sort(j)},[g,c,x,f,v]),S=g.map(R=>R.name),E=r.filter(R=>S.includes(R)).length;return h.useEffect(()=>{if(x.length>0){const R=x.filter(j=>g.some(_=>_.name===j)&&!r.includes(j));R.length>0&&R.forEach(j=>{s(j,!0)})}},[n,x,g,r,s]),h.useEffect(()=>{const R=j=>{const I=(j.ctrlKey||j.metaKey)&&j.shiftKey&&j.key.toLowerCase()==="a",A=document.activeElement.tagName;if(!(A==="INPUT"||A==="TEXTAREA")&&I){j.preventDefault();const O=g.map(k=>k.name),D=O.filter(k=>!r.includes(k)).length>0;O.forEach(k=>{s(k,D)})}};return window.addEventListener("keydown",R),()=>{window.removeEventListener("keydown",R)}},[g,r,s]),!n||!t?a.jsxs(ni,{children:[a.jsx(oc,{connector:e}),a.jsx(ti,{icon:a.jsx(Kf,{size:56,strokeWidth:1}),title:"No fields found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),a.jsx($u,{label:"Need fields?"})]}):g.length?a.jsx(ni,{children:a.jsxs(a.Fragment,{children:[a.jsx(oc,{connector:e}),a.jsxs("div",{className:"border-border -mt-6 mb-6 flex w-full items-center gap-2 border-b",children:[a.jsxs("div",{className:"relative flex-1",children:[a.jsx(wc,{className:"text-muted-foreground absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 cursor-text",onClick:()=>{var R;(R=i.current)==null||R.focus()}}),a.jsx("input",{ref:i,type:"text",placeholder:"Search field",value:c,onChange:R=>{u(R.target.value)},className:"h-12 w-full rounded-none border-0 pl-9 text-sm outline-none"}),c&&a.jsx("button",{type:"button",onClick:()=>{u("")},className:"text-muted-foreground hover:text-foreground absolute top-1/2 right-0 -translate-y-1/2",children:a.jsx(Zu,{className:"h-4 w-4"})})]}),a.jsxs(_r,{children:[a.jsx(Nr,{asChild:!0,children:a.jsxs(Ee,{variant:"ghost",size:"icon","aria-label":"Sort fields",children:[f===ao.ASC&&a.jsx(Wj,{className:"text-muted-foreground h-4 w-4"}),f===ao.DESC&&a.jsx(Yj,{className:"text-muted-foreground h-4 w-4"}),f===ao.ORIGINAL&&a.jsx(Xj,{className:"text-muted-foreground h-4 w-4"})]})}),a.jsxs(Ar,{align:"end",children:[a.jsxs(Nt,{onSelect:()=>{m(ao.ASC)},children:[a.jsx(Wj,{className:"text-muted-foreground mr-2 h-4 w-4"}),"A–Z"]}),a.jsxs(Nt,{onSelect:()=>{m(ao.DESC)},children:[a.jsx(Yj,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Z–A"]}),a.jsxs(Nt,{onSelect:()=>{m(ao.ORIGINAL)},children:[a.jsx(Xj,{className:"text-muted-foreground mr-2 h-4 w-4"}),"Original"]})]})]})]}),a.jsxs(al,{title:`Selected ${String(E)} of ${String(S.length)} fields for "${n}" data`,children:[C.map(R=>{const j=x.includes(R.name);return a.jsx(v6,{type:"checkbox",id:`field-${R.name}`,name:"selectedFields",value:R.name,checked:r.includes(R.name),selected:r.includes(R.name)||j,disabled:j,onChange:_=>{s(R.name,_)},label:R.name,tooltip:a.jsxs("div",{className:"flex flex-col gap-2 py-1",children:[j&&a.jsxs("p",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"font-semibold",children:"Unique key"})," ",a.jsx(N1,{className:"text-secondary h-3 w-3"})]}),a.jsxs("p",{children:[a.jsx("span",{className:"font-semibold",children:"Type:"})," ",R.type]}),R.description&&a.jsxs("p",{children:[a.jsx("span",{className:"font-semibold",children:"Description:"})," ",R.description]})]}),rightIcon:j?a.jsx(N1,{className:"text-muted-foreground/75 h-4 w-4"}):void 0},R.name)}),C.length===0&&c&&a.jsxs("div",{className:"text-muted-foreground pt-8 pb-4 text-center text-sm",children:['No fields match "',c,'"']}),a.jsx($u,{label:"Need another field?"})]})]})}):a.jsxs(ni,{children:[a.jsx(oc,{connector:e}),a.jsx(ti,{icon:a.jsx(Kf,{size:56,strokeWidth:1}),title:"No fields found",subtitle:"This connector might not be fully implemented yet or there could be other issues."}),a.jsx($u,{label:"Need fields?"})]})}const hI=h.createContext(void 0),mI={triggers:[],selectedTrigger:null,isLoading:!1,error:null};function Ioe(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 mI;default:return e}}class Moe extends bl{constructor(){super("/data-marts")}async getScheduledTriggers(t){return this.get(`/${t}/scheduled-triggers`)}async getScheduledTrigger(t,n){return this.get(`/${t}/scheduled-triggers/${n}`)}async createScheduledTrigger(t,n){return this.post(`/${t}/scheduled-triggers`,n)}async updateScheduledTrigger(t,n,r){return this.put(`/${t}/scheduled-triggers/${n}`,r)}async deleteScheduledTrigger(t,n){return this.delete(`/${t}/scheduled-triggers/${n}`)}}const so=new Moe;var Fn=(e=>(e.REPORT_RUN="REPORT_RUN",e.CONNECTOR_RUN="CONNECTOR_RUN",e))(Fn||{});const sl={SCHEDULED_REPORT_RUN:"scheduled-report-run-config"};class Eb{mapFromDto(t){return{id:t.id,type:t.type,cronExpression:t.cronExpression,timeZone:t.timeZone,isActive:t.isActive,nextRun:t.nextRunTimestamp?new Date(t.nextRunTimestamp):null,lastRun:t.lastRunTimestamp?new Date(t.lastRunTimestamp):null,triggerConfig:t.triggerConfig,createdById:t.createdById,createdAt:new Date(t.createdAt),modifiedAt:new Date(t.modifiedAt)}}async enhanceWithReportData(t){if(t.type!==Fn.REPORT_RUN)return t;const n=t.triggerConfig;if(!n.reportId)return t;try{const r=await Yo.getReportById(n.reportId),s=Jl(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:Fn.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 koe{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:Fn.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 i1={getMapper(e){switch(e){case Fn.REPORT_RUN:return new Eb;case Fn.CONNECTOR_RUN:return new koe;default:throw new Error(`Unknown scheduled trigger type: ${String(e)}`)}}},Rf={mapFromDto(e){return i1.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 Fn.REPORT_RUN:return new Eb().enhanceWithReportData(n);case Fn.CONNECTOR_RUN:{const r=t.definition;return{...n,triggerConfig:{...n.triggerConfig,connector:r}}}default:return n}},async mapFromDtoListWithReportData(e,t){const n=new Eb,r=this.mapFromDtoList(e),s=r.filter(c=>c.type===Fn.REPORT_RUN),i=await n.enhanceTriggersWithReportData(s);return r.map(c=>{switch(c.type){case Fn.REPORT_RUN:return i.find(u=>u.id===c.id)??c;case Fn.CONNECTOR_RUN:{const u=t.definition;return{...c,triggerConfig:{...c.triggerConfig,connector:u}}}default:return c}})},mapToCreateRequest(e){return i1.getMapper(e.type).mapToCreateRequest(e)},mapToUpdateRequest(e){return i1.getMapper(e.type).mapToUpdateRequest(e)}};function Loe({children:e}){const[t,n]=h.useReducer(Ioe,mI),{dataMart:r}=Ss(),{fetchAvailableConnectors:s}=Dc();if(!r)throw new Error("Trigger provider must be used within a data mart context");const i=h.useCallback(async v=>{await s(),n({type:"FETCH_TRIGGERS_START"});try{const C=await so.getScheduledTriggers(v),S=await Rf.mapFromDtoListWithReportData(C,r);n({type:"FETCH_TRIGGERS_SUCCESS",payload:S})}catch(C){const S=C instanceof Error?C.message:"Failed to fetch scheduled triggers";n({type:"FETCH_TRIGGERS_ERROR",payload:S}),Le({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"ListError",label:S})}},[r,s]),c=h.useCallback(async(v,C)=>{n({type:"FETCH_TRIGGERS_START"});try{const E=(await so.getScheduledTriggers(v)).filter(j=>j.type===C),R=await Rf.mapFromDtoListWithReportData(E,r);n({type:"FETCH_TRIGGERS_SUCCESS",payload:R})}catch(S){const E=S instanceof Error?S.message:"Failed to fetch scheduled triggers";n({type:"FETCH_TRIGGERS_ERROR",payload:E}),Le({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"ListError",label:E})}},[r]),u=h.useCallback(async(v,C)=>{n({type:"FETCH_TRIGGER_START"});try{const S=await so.getScheduledTrigger(v,C),E=await Rf.mapFromDtoWithReportData(S,r);n({type:"FETCH_TRIGGER_SUCCESS",payload:E})}catch(S){const E=S instanceof Error?S.message:"Failed to fetch scheduled trigger";n({type:"FETCH_TRIGGER_ERROR",payload:E}),Le({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"GetError",label:E})}},[r]),f=h.useCallback(async(v,C,S,E,R,j)=>{n({type:"CREATE_TRIGGER_START"});try{const _={type:C,cronExpression:S,timeZone:E,isActive:R,triggerConfig:j},I=await so.createScheduledTrigger(v,_),A=await Rf.mapFromDtoWithReportData(I,r);return n({type:"CREATE_TRIGGER_SUCCESS",payload:A}),Le({event:"scheduled_trigger_created",category:"ScheduledTrigger",action:"Create",label:C}),Dn.success("Trigger created"),A}catch(_){const I=_ instanceof Error?_.message:"Failed to create scheduled trigger";throw n({type:"CREATE_TRIGGER_ERROR",payload:I}),Le({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"CreateError",label:I}),_}},[r]),m=h.useCallback(async(v,C,S,E,R)=>{n({type:"UPDATE_TRIGGER_START"});try{const j={cronExpression:S,timeZone:E,isActive:R},_=await so.updateScheduledTrigger(v,C,j),I=await Rf.mapFromDtoWithReportData(_,r);n({type:"UPDATE_TRIGGER_SUCCESS",payload:I}),Le({event:"scheduled_trigger_updated",category:"ScheduledTrigger",action:"Update",label:I.type}),Dn.success("Trigger updated")}catch(j){const _=j instanceof Error?j.message:"Failed to update scheduled trigger";throw n({type:"UPDATE_TRIGGER_ERROR",payload:_}),Le({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"UpdateError",label:_}),j}},[r]),y=h.useCallback(async(v,C)=>{n({type:"DELETE_TRIGGER_START"});try{await so.deleteScheduledTrigger(v,C),n({type:"DELETE_TRIGGER_SUCCESS",payload:C}),Le({event:"scheduled_trigger_deleted",category:"ScheduledTrigger",action:"Delete",label:C}),Dn.success("Trigger deleted")}catch(S){const E=S instanceof Error?S.message:"Failed to delete scheduled trigger";throw n({type:"DELETE_TRIGGER_ERROR",payload:E}),Le({event:"scheduled_trigger_error",category:"ScheduledTrigger",action:"DeleteError",label:E}),S}},[]),g=h.useCallback(v=>{n({type:"SELECT_TRIGGER",payload:v})},[]),x=h.useCallback(()=>{n({type:"RESET"})},[]);return a.jsx(hI.Provider,{value:{...t,getScheduledTriggers:i,getScheduledTriggersByType:c,getScheduledTrigger:u,createScheduledTrigger:f,updateScheduledTrigger:m,deleteScheduledTrigger:y,selectScheduledTrigger:g,reset:x},children:e})}function pI(){const e=h.useContext(hI);if(e===void 0)throw new Error("useScheduledTriggerContext must be used within a ScheduledTriggerProvider");return e}function Poe(e){const{getScheduledTriggers:t,getScheduledTriggersByType:n,getScheduledTrigger:r,createScheduledTrigger:s,updateScheduledTrigger:i,deleteScheduledTrigger:c,selectScheduledTrigger:u,reset:f,triggers:m,selectedTrigger:y,isLoading:g,error:x}=pI();return h.useEffect(()=>(e?t(e):f(),()=>{f()}),[e,t,f]),{triggers:m,selectedTrigger:y,isLoading:g,error:x,getScheduledTriggers:v=>t(v),getScheduledTriggersByType:(v,C)=>n(v,C),getScheduledTrigger:(v,C)=>r(v,C),createScheduledTrigger:(v,C,S,E,R,j)=>s(v,C,S,E,R,j),updateScheduledTrigger:(v,C,S,E,R)=>i(v,C,S,E,R),deleteScheduledTrigger:(v,C)=>c(v,C),selectScheduledTrigger:u}}const Uoe=rn({type:Br(sl.SCHEDULED_REPORT_RUN),reportId:Dt().min(1,"Report ID is required")}),zoe=YZ(),Foe=rn({type:Sy(Fn),cronExpression:Dt().min(1,"Cron expression is required"),timeZone:Dt().min(1,"Time zone is required"),isActive:ZZ(),triggerConfig:XZ([Uoe,zoe])});function Hoe({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:r}){const s=Ro({resolver:yi(Foe),defaultValues:{type:e?e.type:n??Fn.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:sl.SCHEDULED_REPORT_RUN,reportId:t??""}}});h.useEffect(()=>{t&&s.getValues("type")===Fn.REPORT_RUN&&s.setValue("triggerConfig",{type:sl.SCHEDULED_REPORT_RUN,reportId:t})},[t,s]),h.useEffect(()=>{n&&(s.setValue("type",n),n===Fn.REPORT_RUN?s.setValue("triggerConfig",{type:sl.SCHEDULED_REPORT_RUN,reportId:t??""}):s.setValue("triggerConfig",null))},[n,t,s]);const i=u=>{s.setValue("type",u),u===Fn.REPORT_RUN?s.setValue("triggerConfig",{type:sl.SCHEDULED_REPORT_RUN,reportId:t??""}):s.setValue("triggerConfig",null)},c=async u=>{try{await r(u)}catch(f){console.error("Error submitting form:",f)}};return{form:s,handleTypeChange:i,handleSubmit:s.handleSubmit(c),isDirty:s.formState.isDirty}}const $oe=[Ne.GOOGLE_SHEETS,Ne.EMAIL,Ne.SLACK,Ne.MS_TEAMS,Ne.GOOGLE_CHAT];function Voe({value:e,onChange:t,disabled:n}){const{reports:r,fetchReportsByDataMartId:s}=ts(),{dataMart:i}=Ss();h.useEffect(()=>{i&&s(i.id)},[s,i]);const c=r.filter(u=>$oe.includes(u.dataDestination.type));return a.jsxs(ca,{value:e,onValueChange:t,disabled:n,children:[a.jsx(da,{className:"w-full",children:a.jsx(ua,{placeholder:"Select a report"})}),a.jsx(fa,{children:c.map(u=>{const f=aa.getInfo(u.dataDestination.type).icon;return a.jsx(Gn,{value:u.id,children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(f,{className:"h-4 w-4",size:16}),a.jsx("span",{children:u.title})]})},u.id)})})]})}var Ky="Switch",[Boe]=Sr(Ky),[Goe,qoe]=Boe(Ky),gI=h.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:s,defaultChecked:i,required:c,disabled:u,value:f="on",onCheckedChange:m,form:y,...g}=e,[x,v]=h.useState(null),C=ht(t,_=>v(_)),S=h.useRef(!1),E=x?y||!!x.closest("form"):!0,[R,j]=ia({prop:s,defaultProp:i??!1,onChange:m,caller:Ky});return a.jsxs(Goe,{scope:n,checked:R,disabled:u,children:[a.jsx(Je.button,{type:"button",role:"switch","aria-checked":R,"aria-required":c,"data-state":bI(R),"data-disabled":u?"":void 0,disabled:u,value:f,...g,ref:C,onClick:Ie(e.onClick,_=>{j(I=>!I),E&&(S.current=_.isPropagationStopped(),S.current||_.stopPropagation())})}),E&&a.jsx(vI,{control:x,bubbles:!S.current,name:r,value:f,checked:R,required:c,disabled:u,form:y,style:{transform:"translateX(-100%)"}})]})});gI.displayName=Ky;var yI="SwitchThumb",xI=h.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,s=qoe(yI,n);return a.jsx(Je.span,{"data-state":bI(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:t})});xI.displayName=yI;var Koe="SwitchBubbleInput",vI=h.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...s},i)=>{const c=h.useRef(null),u=ht(c,i),f=b2(n),m=mS(t);return h.useEffect(()=>{const y=c.current;if(!y)return;const g=window.HTMLInputElement.prototype,v=Object.getOwnPropertyDescriptor(g,"checked").set;if(f!==n&&v){const C=new Event("click",{bubbles:r});v.call(y,n),y.dispatchEvent(C)}},[f,n,r]),a.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...s,tabIndex:-1,ref:u,style:{...s.style,...m,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});vI.displayName=Koe;function bI(e){return e?"checked":"unchecked"}var Zoe=gI,Yoe=xI;function Z2({className:e,...t}){return a.jsx(Zoe,{"data-slot":"switch",className:se("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 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 dark:data-[state=unchecked]:bg-white/16",e),...t,children:a.jsx(Yoe,{"data-slot":"switch-thumb",className:se("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 Woe(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 wb(e,t="UTC"){const n=Woe(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:i,month:c,dayOfWeek:u}=n;if(r.startsWith("*/")&&s==="*"&&i==="*"&&c==="*"&&u==="*"){const g=Number.parseInt(r.substring(2));if(!isNaN(g))return{type:"interval",time:"09:00",weekdays:[1,2,3,4,5],monthDays:[1],customCron:e,intervalType:"minutes",intervalValue:g,timezone:t}}if(r!=="*"&&s.startsWith("*/")&&i==="*"&&c==="*"&&u==="*"){const g=Number.parseInt(s.substring(2));if(!isNaN(g)&&r==="0")return{type:"interval",time:"09:00",weekdays:[1,2,3,4,5],monthDays:[1],customCron:e,intervalType:"hours",intervalValue:g,timezone:t}}const f=Number.parseInt(r),m=Number.parseInt(s),y=!isNaN(f)&&!isNaN(m)?`${m.toString().padStart(2,"0")}:${f.toString().padStart(2,"0")}`:"09:00";if(!isNaN(f)&&!isNaN(m)&&i==="*"&&c==="*"&&u==="*")return{type:"daily",time:y,weekdays:[1,2,3,4,5],monthDays:[1],customCron:e,intervalType:"minutes",intervalValue:15,timezone:t};if(!isNaN(f)&&!isNaN(m)&&i==="*"&&c==="*"&&u!=="*"){const g=u.split(",").map(x=>Number.parseInt(x.trim())).filter(x=>!isNaN(x)&&x>=0&&x<=6);if(g.length>0)return{type:"weekly",time:y,weekdays:g,monthDays:[1],customCron:e,intervalType:"minutes",intervalValue:15,timezone:t}}if(!isNaN(f)&&!isNaN(m)&&i!=="*"&&c==="*"&&u==="*"){const g=i.split(",").map(x=>Number.parseInt(x.trim())).filter(x=>!isNaN(x)&&x>=1&&x<=31);if(g.length>0)return{type:"monthly",time:y,weekdays:[1,2,3,4,5],monthDays:g,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 SI({options:e,selected:t,onSelectionChange:n,placeholder:r="Select items...",searchPlaceholder:s="Search...",maxDisplayItems:i=3}){const[c,u]=h.useState(!1),f=g=>{const x=t.includes(g)?t.filter(v=>v!==g):[...t,g].sort((v,C)=>v-C);n(x)},m=(g,x)=>{x.preventDefault(),x.stopPropagation(),n(t.filter(v=>v!==g))},y=()=>{if(t.length===0)return a.jsx("span",{className:"text-muted-foreground text-sm",children:r});const g=t.map(x=>e.find(v=>v.value===x)).filter(Boolean);return g.length<=i?a.jsx("div",{className:"flex flex-wrap gap-1",children:g.map(x=>a.jsxs(jr,{variant:"secondary",className:"h-5 text-xs",children:[x.label,a.jsx("span",{className:"hover:bg-secondary-foreground/20 ml-1 inline-flex cursor-pointer items-center justify-center rounded-full p-0.5",onClick:v=>m(x.value,v),children:a.jsx(Zu,{className:"h-2 w-2"})})]},x.value))}):a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsxs(jr,{variant:"secondary",className:"h-5 text-xs",children:[g[0].label,a.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(g[0].value,x),children:a.jsx(Zu,{className:"h-2 w-2"})})]}),g.length>1&&a.jsxs(jr,{variant:"outline",className:"h-5 text-xs",children:["+",g.length-1]})]})};return a.jsxs(F2,{open:c,onOpenChange:u,modal:!0,children:[a.jsx(H2,{asChild:!0,children:a.jsxs(Ee,{variant:"outline",role:"combobox","aria-expanded":c,className:"h-9 min-h-9 w-full justify-between bg-transparent py-1",children:[a.jsx("div",{className:"flex-1 text-left",children:y()}),a.jsx(Qb,{className:"ml-2 h-3 w-3 shrink-0 opacity-50"})]})}),a.jsx($2,{className:"max-h-[400px] w-full overflow-y-auto p-0",style:{padding:0},children:a.jsxs(Y6,{className:"h-full overflow-visible",children:[a.jsx(W6,{placeholder:s,className:"h-8"}),a.jsxs(pse,{className:"h-full max-h-[350px] overflow-y-auto",children:[a.jsx(X6,{children:"No items found."}),a.jsx(Q6,{className:"h-full overflow-visible",children:e.map(g=>a.jsxs(J6,{value:g.value.toString(),onSelect:()=>f(g.value),className:"text-sm",children:[a.jsx(oa,{className:se("mr-2 h-3 w-3",t.includes(g.value)?"opacity-100":"opacity-0")}),g.label]},g.value))})]})]})})]})}const CI=[{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"}],Op=()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}};function EI(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 i;return(i=CI.find(c=>c.value===s))==null?void 0:i.label}).join(", ")} at ${n}`;case"monthly":{const s=[...e.monthDays].sort((c,u)=>c-u).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 Xoe(e,t,n=!0){const r=wb(e,t);return EI(r,n)}const Qoe=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],jb=[1,2,3,4,6,8,12],Joe=({value:e,onChange:t,disabled:n})=>a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ta,{children:"Type"}),a.jsxs(ca,{value:e,onValueChange:r=>{t(r)},disabled:n,children:[a.jsx(da,{className:"w-full",children:a.jsx(ua,{})}),a.jsxs(fa,{children:[a.jsx(Gn,{value:"daily",children:"Daily"}),a.jsx(Gn,{value:"weekly",children:"Weekly"}),a.jsx(Gn,{value:"monthly",children:"Monthly"}),a.jsx(Gn,{value:"interval",children:"Interval"})]})]})]}),eie=({value:e,onChange:t,disabled:n})=>a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ta,{children:"Time"}),a.jsx("div",{className:"flex items-center gap-2",children:a.jsx(It,{className:"w-24",type:"time",value:e,onChange:r=>{t(r.target.value)},disabled:n})})]}),eN=({value:e,onChange:t,disabled:n,timezones:r})=>a.jsxs("div",{className:"w-full space-y-2",children:[a.jsx(Ta,{children:"Timezone"}),a.jsx("div",{className:"flex items-center gap-2",children:a.jsx(V2,{options:r,value:e,onValueChange:t,placeholder:"Select timezone",emptyMessage:"No timezones found",disabled:n,className:"w-full"})})]}),tie=({value:e,onChange:t,disabled:n})=>a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ta,{children:"Days of Week"}),a.jsx("div",{className:n?"pointer-events-none":"",children:a.jsx(SI,{options:CI,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:3})})]}),nie=({value:e,onChange:t,disabled:n})=>a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ta,{children:"Days of Month"}),a.jsx("div",{className:n?"pointer-events-none":"",children:a.jsx(SI,{options:Qoe,selected:e,onSelectionChange:t,placeholder:"Select days...",maxDisplayItems:4})})]}),rie=({intervalType:e,intervalValue:t,onTypeChange:n,onValueChange:r,disabled:s})=>a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ta,{children:"Type"}),a.jsxs(ca,{value:e,onValueChange:i=>{n(i)},disabled:s,children:[a.jsx(da,{className:"w-full",children:a.jsx(ua,{})}),a.jsxs(fa,{children:[a.jsx(Gn,{value:"minutes",children:"Minutes"}),a.jsx(Gn,{value:"hours",children:"Hours"})]})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ta,{children:"Every"}),a.jsxs(ca,{value:t.toString(),onValueChange:i=>{r(Number.parseInt(i)||1)},disabled:s,children:[a.jsx(da,{className:"w-full",children:a.jsx(ua,{})}),a.jsx(fa,{children:(e==="minutes"?Rb:jb).map(i=>a.jsxs(Gn,{value:i.toString(),children:[i," ",e==="minutes"?"min":"hr"]},i))})]})]})]}),aie=({value:e,onChange:t,disabled:n})=>a.jsxs("div",{className:"space-y-1",children:[a.jsx(Ta,{className:"text-sm",children:"Cron Expression"}),a.jsx(It,{value:e,onChange:r=>{t(r.target.value)},placeholder:"0 9 * * *",className:"h-9 font-mono text-sm",disabled:n}),a.jsx("p",{className:"text-muted-foreground text-xs",children:"Format: minute hour day month day-of-week"})]});function Tb({cron:e="0 9 * * *",timezone:t,enabled:n=!0,onChange:r,className:s,showPreview:i=!0,showSaveButton:c=!1,hideEnableSwitch:u=!1}){const[f,m]=h.useState(n),[y,g]=h.useState(t??Op()),[x,v]=h.useState(!1),C=h.useMemo(()=>vW.getTimezonesWithOffset().map(F=>({value:F.identifier,label:F.displayName,offset:F.offsetString,isDST:F.isDST})),[]),[S,E]=h.useState(()=>wb(e,y)),[R,j]=h.useState(""),[_,I]=h.useState("");h.useEffect(()=>{m(n)},[n]),h.useEffect(()=>{const F=t??Op();g(F)},[t]),h.useEffect(()=>{if(e){const F=wb(e,y);E(F)}},[e,y]);const A=F=>{const[M,$]=F.time.split(":").map(Number);switch(F.type){case"daily":return`${String($)} ${String(M)} * * *`;case"weekly":return`${String($)} ${String(M)} * * ${F.weekdays.join(",")}`;case"monthly":return`${String($)} ${String(M)} ${F.monthDays.join(",")} * *`;case"interval":return F.intervalType==="minutes"?`*/${String(F.intervalValue)} * * * *`:`0 */${String(F.intervalValue)} * * *`;case"custom":return F.customCron;default:return`${String($)} ${String(M)} * * *`}},O=h.useCallback(F=>{E(M=>{if(M.intervalType===F)return console.log("Type unchanged, skipping update"),M;const H=(F==="minutes"?Rb:jb)[0];return{...M,intervalType:F,intervalValue:H}})},[]),T=h.useCallback(F=>{E(M=>(M.intervalType==="minutes"?Rb:jb).includes(F)?{...M,intervalValue:F}:M)},[]),D=h.useMemo(()=>F=>EI(F,f),[f]);h.useEffect(()=>{const F=A(S);j(F),I(D(S))},[S,f,y,D]);const k=h.useRef(""),B=h.useRef(""),G=h.useRef(!1);h.useEffect(()=>{const F=A(S);r&&(k.current!==F||B.current!==y||G.current!==f)&&(r({cron:F,timezone:y,enabled:f}),k.current=F,B.current=y,G.current=f)},[S,y,f,r]);const Y=F=>{m(F)},V=F=>{g(F),E(M=>({...M,timezone:F}))},Z=["daily","weekly","monthly"].includes(S.type);return a.jsxs("div",{className:s,children:[!u&&a.jsx("div",{className:"mb-4 space-y-4 pt-0",children:a.jsx("div",{className:"flex items-center justify-end",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ta,{htmlFor:"schedule-enabled",className:"text-sm font-normal",children:f?"Enabled":"Disabled"}),a.jsx(Z2,{id:"schedule-enabled",checked:f,onCheckedChange:Y})]})})}),a.jsxs("div",{className:"space-y-4 pt-0",children:[a.jsxs("div",{className:`space-y-4 ${f?"":"opacity-50"}`,children:[a.jsx(Joe,{value:S.type,onChange:F=>{E(M=>({...M,type:F}))},disabled:!f}),S.type!=="custom"&&S.type!=="interval"&&a.jsxs("div",{className:"flex gap-3",children:[a.jsx(eie,{value:S.time,onChange:F=>{E(M=>({...M,time:F}))},disabled:!f}),Z&&a.jsx(eN,{value:y,onChange:V,disabled:!f,timezones:C})]}),(S.type==="interval"||S.type==="custom")&&a.jsx(eN,{value:y,onChange:V,disabled:!f,timezones:C}),S.type==="weekly"&&a.jsx(tie,{value:S.weekdays,onChange:F=>{E(M=>({...M,weekdays:F}))},disabled:!f}),S.type==="monthly"&&a.jsx(nie,{value:S.monthDays,onChange:F=>{E(M=>({...M,monthDays:F}))},disabled:!f}),S.type==="interval"&&a.jsx(rie,{intervalType:S.intervalType,intervalValue:S.intervalValue,onTypeChange:O,onValueChange:T,disabled:!f}),S.type==="custom"&&a.jsx(aie,{value:S.customCron,onChange:F=>{E(M=>({...M,customCron:F}))},disabled:!f})]}),i&&a.jsxs(a.Fragment,{children:[a.jsx(BA,{className:"my-3"}),a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"flex cursor-pointer items-center justify-between",onClick:()=>{v(!x)},children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(TA,{className:"h-4 w-4"}),a.jsx("span",{className:"text-sm font-medium",children:"Preview"})]}),x?a.jsx(qu,{className:"text-muted-foreground h-4 w-4"}):a.jsx(Bs,{className:"text-muted-foreground h-4 w-4"})]}),x&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"grid gap-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-muted-foreground text-xs",children:"Status:"}),a.jsx(jr,{variant:f?"default":"secondary",className:"text-xs",children:f?"Enabled":"Disabled"})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-muted-foreground text-xs",children:"Cron:"}),a.jsx(jr,{variant:"secondary",className:"font-mono text-xs",children:R})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-muted-foreground text-xs",children:"Timezone:"}),a.jsx(jr,{variant:"outline",className:"text-xs",children:y})]}),a.jsxs("div",{className:"flex items-start justify-between gap-2",children:[a.jsx("span",{className:"text-muted-foreground text-xs",children:"Schedule:"}),a.jsx("span",{className:"flex-1 text-right text-xs",children:_})]})]}),f&&Z&&y!==Op()&&a.jsxs(G2,{className:"border-amber-200 bg-amber-50",children:[a.jsx(gh,{className:"h-4 w-4"}),a.jsx(dI,{children:"Time Zone"}),a.jsxs(q2,{children:["Schedule runs in ",y," (not your local ",Op()," ","time). Execution time may differ from expected."]})]})]})]})]}),c&&a.jsx(Ee,{className:"w-full",disabled:!f,children:"Save Schedule"})]})]})}function sie(){return a.jsx(Cn,{variant:"common",type:"single",collapsible:!0,children:a.jsxs(Kt,{value:"trigger-type-options-description-details",children:[a.jsx(Zt,{children:"How do I choose a type?"}),a.jsxs(Yt,{children:[a.jsxs("p",{className:"mb-2",children:[a.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)."]}),a.jsxs("p",{className:"mb-2",children:[a.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 oie(){return a.jsx(Cn,{variant:"common",type:"single",collapsible:!0,children:a.jsxs(Kt,{value:"trigger-type-change-description-details",children:[a.jsx(Zt,{children:"How do I change the trigger type?"}),a.jsx(Yt,{children:a.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 iie(){return a.jsx(Cn,{variant:"common",type:"single",collapsible:!0,children:a.jsxs(Kt,{value:"report-change-description-details",children:[a.jsx(Zt,{children:"How do I change a report?"}),a.jsx(Yt,{children:a.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 lie(){return a.jsx(Cn,{variant:"common",type:"single",collapsible:!0,children:a.jsxs(Kt,{value:"report-select-description-details",children:[a.jsx(Zt,{children:"How do I choose the report?"}),a.jsxs(Yt,{children:[a.jsx("p",{className:"mb-2",children:"For a Report Run trigger, select one of the available Destinations (e.g., a Google Sheets report)."}),a.jsxs("p",{children:["You can use an existing one or create a new one on the ",a.jsx("strong",{children:"Destinations"})," tab"," ","of this Data Mart."]})]})]})})}function cie({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:r,onCancel:s,onDirtyChange:i}){const[c,u]=h.useState(!1),{form:f,handleTypeChange:m,handleSubmit:y,isDirty:g}=Hoe({initialData:e,preSelectedReportId:t,preSelectedType:n,onSubmit:async E=>{u(!0);try{await r(E)}finally{u(!1)}}});h.useEffect(()=>{i==null||i(g)},[g,i]);const{control:x,watch:v}=f,S=v("type")===Fn.REPORT_RUN;return a.jsx(_l,{...f,children:a.jsxs(gi,{onSubmit:E=>void y(E),noValidate:!1,children:[a.jsxs(Nl,{children:[a.jsx(_t,{control:x,name:"type",render:({field:E})=>a.jsxs(xt,{children:[a.jsx(yt,{tooltip:"Choose what you want this trigger to run - a report or a connector",children:"Trigger Type"}),a.jsxs(ca,{onValueChange:R=>{E.onChange(R),m(R)},defaultValue:E.value,disabled:!!n||!!e||!!v("triggerConfig.reportId"),children:[a.jsx(Ct,{children:a.jsx(da,{className:"w-full",children:a.jsx(ua,{placeholder:"Select trigger type"})})}),a.jsxs(fa,{children:[a.jsx(Gn,{value:Fn.REPORT_RUN,children:"Report Run"}),a.jsx(Gn,{value:Fn.CONNECTOR_RUN,children:"Connector Run"})]})]}),a.jsx(xn,{children:e?a.jsx(oie,{}):a.jsx(sie,{})}),a.jsx(Mt,{})]})}),S&&a.jsx(_t,{control:x,name:"triggerConfig.reportId",render:({field:E})=>a.jsxs(xt,{children:[a.jsx(yt,{tooltip:"Select the report that will be run by this trigger",children:"Report"}),a.jsx(Ct,{children:a.jsx(BS,{children:a.jsx(Voe,{value:E.value,onChange:E.onChange,disabled:!!t||!!e})})}),a.jsx(xn,{children:e!=null&&e.triggerConfig?a.jsx(iie,{}):a.jsx(lie,{})}),a.jsx(Mt,{})]})}),a.jsx(Tb,{showPreview:!1,cron:v("cronExpression"),timezone:v("timeZone"),enabled:v("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"})]}),a.jsxs(Oc,{children:[a.jsx(Ee,{variant:"default",type:"submit",className:"w-full","aria-label":e?"Save changes":"Create trigger",disabled:!g||c,children:c?e?"Saving...":"Creating...":e?"Save changes":"Create trigger"}),s&&a.jsx(Ee,{variant:"outline",type:"button",onClick:s,className:"w-full","aria-label":"Cancel",children:"Cancel"})]})]})})}function uie({cronExpression:e,timeZone:t,isEnabled:n=!0}){const r=h.useMemo(()=>Xoe(e,t,n),[e,t,n]);return a.jsxs("div",{children:[a.jsx("div",{children:r}),n&&a.jsx("code",{className:"text-muted-foreground mt-1 block text-xs",children:t})]})}function die({trigger:e,onEditTrigger:t,onDeleteTrigger:n}){const[r,s]=h.useState(!1),[i,c]=h.useState(!1),u=()=>{c(!1),n(e.id)};return a.jsxs("div",{className:"text-right",onClick:f=>{f.stopPropagation()},children:[a.jsxs(_r,{open:r,onOpenChange:s,children:[a.jsx(Nr,{asChild:!0,children:a.jsx(Ee,{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:a.jsx(Gs,{className:"dm-card-table-body-row-actionbtn-icon"})})}),a.jsxs(Ar,{align:"end",children:[a.jsxs(Nt,{onClick:()=>{t(e.id)},children:[a.jsx(sd,{className:"text-foreground h-4 w-4","aria-hidden":"true"}),"Edit trigger"]}),a.jsx(ja,{}),a.jsxs(Nt,{onClick:()=>{c(!0)},children:[a.jsx(es,{className:"h-4 w-4 text-red-600","aria-hidden":"true"}),a.jsx("span",{className:"text-red-600",children:"Delete trigger"})]})]})]}),a.jsx(br,{open:i,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:u,variant:"destructive"})]})}function fie({connector:e}){const{connectors:t}=Dc(),n=Yee(e,t);return a.jsx(a.Fragment,{children:n})}function wI({connector:e}){return a.jsx(fie,{connector:e})}function hie(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 mie=e=>{const{connectors:t}=Dc();return h.useMemo(()=>t.find(n=>n.name===e),[t,e])},pie=re.memo(function({connector:t,children:n}){const r=mie(t.source.name),{dataMart:s,runs:i,getDataMartRuns:c}=Ss();h.useEffect(()=>{s!=null&&s.id&&c(s.id)},[s==null?void 0:s.id,c]);const u=h.useMemo(()=>r!=null&&r.logoBase64?a.jsx(_c,{base64:r.logoBase64,size:20}):null,[r==null?void 0:r.logoBase64]),f=h.useCallback(()=>{s!=null&&s.storage&&RX(s.storage,t.storage.fullyQualifiedName)},[s==null?void 0:s.storage,t.storage.fullyQualifiedName]),m=h.useMemo(()=>hie(i),[i]),y=h.useMemo(()=>!m.lastRunDate||!m.lastRunStatus?null:{statusType:KQ(m.lastRunStatus),statusText:YQ(m.lastRunStatus),date:m.lastRunDate},[m]),g=h.useMemo(()=>(s==null?void 0:s.storage)&&jX(s.storage),[s]),x=h.useMemo(()=>{const v=t.source.fields.length.toString();return`${t.source.node} • ${v} fields`},[t.source.node,t.source.fields.length]);return a.jsxs(Ny,{children:[a.jsx(Ay,{asChild:!0,children:a.jsx("span",{children:n})}),a.jsxs(Dy,{children:[a.jsxs(ZS,{children:[a.jsx(YS,{children:u}),a.jsxs(WS,{children:[a.jsx(XS,{children:a.jsx(wI,{connector:t})}),a.jsx(QS,{children:x})]})]}),a.jsxs(JS,{children:[a.jsxs(el,{children:[a.jsx(tl,{children:"Last run status:"}),a.jsx(nl,{children:y?a.jsx(Ph,{type:y.statusType,variant:"ghost",children:y.statusText}):"Not run yet"})]}),a.jsxs(el,{children:[a.jsx(tl,{children:"Last run date:"}),a.jsx(nl,{children:y?a.jsx(Hs,{date:y.date}):"Never run"})]}),a.jsxs(el,{children:[a.jsx(tl,{children:"Total runs:"}),a.jsxs(nl,{children:[m.totalRuns," runs",m.firstRunDate&&a.jsxs(a.Fragment,{children:[", since"," ",m.firstRunDate.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})]})]})]})]}),a.jsx(e2,{children:a.jsxs(Ee,{className:"w-full",variant:"default",onClick:f,title:"Open Storage","aria-label":"Open Storage",children:[g,a.jsx(ai,{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 gie(e){const t=e.triggerConfig,n=aa.getInfo(t.report.dataDestination.type).icon;return a.jsxs("div",{className:"group inline-flex items-center gap-2 whitespace-nowrap",children:[a.jsx(n,{className:"h-4 w-4",size:16}),t.report.title,a.jsx(GQ,{report:t.report,children:a.jsx(Fr,{className:"inline-block h-4 w-4 align-text-bottom opacity-0 transition-opacity duration-200 group-hover:opacity-100"})})]})}function yie(e){var s;const t=e.triggerConfig,{connector:n}=t.connector,r=(s=n.info)!=null&&s.logoBase64?a.jsx(_c,{base64:n.info.logoBase64,className:"h-4 w-4",size:16}):a.jsx(lc,{className:"h-4 w-4",size:16});return a.jsxs("div",{className:"group inline-flex items-center gap-2 whitespace-nowrap",children:[r,a.jsx(wI,{connector:n}),a.jsx(pie,{connector:n,children:a.jsx(Fr,{className:"inline-block h-4 w-4 align-text-bottom opacity-0 transition-opacity duration-200 group-hover:opacity-100"})})]})}function xie({trigger:e}){switch(e.type){case Fn.REPORT_RUN:return gie(e);case Fn.CONNECTOR_RUN:return yie(e);default:return a.jsx("div",{className:"text-muted-foreground text-sm",children:"—"})}}function vie({onEditTrigger:e,onDeleteTrigger:t}){return[{accessorKey:"type",size:150,header:"Trigger Type",cell:({row:n})=>{const s=n.getValue("type")===Fn.REPORT_RUN?"Report Run":"Connector Run";return a.jsx(jr,{variant:"outline",children:s})},meta:{title:"Trigger Type"}},{accessorKey:"triggerConfig",size:35,header:"Run Target",cell:({row:n})=>a.jsx(xie,{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,i=n.getValue("isActive");return a.jsx(uie,{cronExpression:String(r),timeZone:s,isEnabled:i})},meta:{title:"Schedule"}},{accessorKey:"nextRun",size:15,header:"Next Run",cell:({row:n})=>{const r=n.original.nextRun;return a.jsx("div",{className:"text-muted-foreground text-sm",children:r?a.jsx(Hs,{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 a.jsx("div",{className:"text-sm",children:r?a.jsx(Hs,{date:new Date(r)}):a.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 a.jsx(Ph,{type:r?Jn.SUCCESS:Jn.NEUTRAL,variant:"ghost",showIcon:!1,children:r?"Enabled":"Disabled"})},meta:{title:"Trigger Status"}},{id:"actions",size:80,header:({table:n})=>a.jsx(gd,{table:n}),cell:({row:n})=>a.jsx(die,{trigger:n.original,onEditTrigger:e,onDeleteTrigger:t}),meta:{title:"Actions"}}]}function bie({table:e,onPreviousClick:t,onNextClick:n}){return a.jsxs("div",{className:"dm-card-pagination",role:"navigation","aria-label":"Table pagination",children:[a.jsx(Ee,{variant:"outline",size:"sm",onClick:t,disabled:!e.getCanPreviousPage(),"aria-label":"Go to previous page",children:"Previous"}),a.jsx(Ee,{variant:"outline",size:"sm",onClick:n,disabled:!e.getCanNextPage(),"aria-label":"Go to next page",children:"Next"})]})}function Y2({isOpen:e,onClose:t,dataMartId:n,preSelectedReportId:r,preSelectedType:s}){const{createScheduledTrigger:i,updateScheduledTrigger:c,selectedTrigger:u}=pI(),{showUnsavedDialog:f,setShowUnsavedDialog:m,handleClose:y,confirmClose:g,handleFormDirtyChange:x,handleFormSubmitSuccess:v}=Ic(t),C=!!u,S=h.useMemo(()=>u?{type:u.type,cronExpression:u.cronExpression,timeZone:u.timeZone,isActive:u.isActive,triggerConfig:u.type===Fn.REPORT_RUN?{type:sl.SCHEDULED_REPORT_RUN,reportId:u.triggerConfig.reportId}:null}:void 0,[u]),E=async j=>{C?await c(n,u.id,j.cronExpression,j.timeZone,j.isActive):await i(n,j.type,j.cronExpression,j.timeZone,j.isActive,j.triggerConfig),v()},R=h.useRef(!1);return h.useEffect(()=>{const j=C?"Edit":"Create",_=(u==null?void 0:u.type)??s;e&&!R.current?(Le({event:"scheduled_trigger_config_open",category:"ScheduledTrigger",action:j,label:_}),R.current=!0):!e&&R.current&&(Le({event:"scheduled_trigger_config_close",category:"ScheduledTrigger",action:j,label:_}),R.current=!1)},[e,C,u,s]),a.jsxs(a.Fragment,{children:[a.jsx(ci,{open:e,onOpenChange:j=>{j||y()},children:a.jsxs(ui,{children:[a.jsxs(di,{children:[a.jsxs(fi,{children:[C?"Edit":"Create"," Scheduled Trigger"]}),a.jsx(yl,{children:"Configure automatic runs for your reports or connectors."})]}),a.jsx(cie,{preSelectedReportId:r,preSelectedType:s,initialData:S,onSubmit:E,onCancel:y,onDirtyChange:x})]})}),a.jsx(br,{open:f,onOpenChange:m,title:"Unsaved Changes",description:"You have unsaved changes. Exit without saving?",confirmLabel:"Yes, leave now",cancelLabel:"No, stay here",onConfirm:g,variant:"destructive"})]})}function Sie({triggers:e,dataMartId:t,onEditTrigger:n,onDeleteTrigger:r}){const[s,i]=h.useState(!1),c=h.useCallback(()=>{i(!1)},[]),u=h.useCallback(R=>{r(R)},[r]),f=h.useMemo(()=>vie({onEditTrigger:n,onDeleteTrigger:u}),[n,u]),{sorting:m,setSorting:y,columnVisibility:g,setColumnVisibility:x}=Ac({columns:f,storageKeyPrefix:"data-mart-scheduled-triggers",defaultSortingColumn:"type"}),v=El({data:e,columns:f,getCoreRowModel:Cl(),getPaginationRowModel:Fh(),onSortingChange:y,getSortedRowModel:Nc(),getFilteredRowModel:pd(),state:{sorting:m,columnVisibility:g},onColumnVisibilityChange:x,enableGlobalFilter:!0,enableColumnResizing:!1}),C=h.useCallback(()=>{v.previousPage()},[v]),S=h.useCallback(()=>{v.nextPage()},[v]);return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"dm-card-table-wrap",children:a.jsxs(wl,{id:"scheduled-triggers-table",className:"dm-card-table",role:"table","aria-label":"Scheduled Triggers",children:[a.jsx(Rl,{className:"dm-card-table-header",children:v.getHeaderGroups().map(R=>a.jsx(Hn,{className:"dm-card-table-header-row",children:R.headers.map(j=>a.jsx(Tl,{className:"[&:has([role=checkbox])]:pl-6 [&>[role=checkbox]]:translate-y-[2px]",scope:"col",style:j.column.id==="type"?{width:150,minWidth:150,maxWidth:150}:j.column.id==="actions"?{width:80,minWidth:80,maxWidth:80}:{width:`${String(j.getSize())}%`},children:j.isPlaceholder?null:typeof j.column.columnDef.header=="function"?j.column.columnDef.header(j.getContext()):j.column.columnDef.header},j.id))},R.id))}),a.jsx(jl,{className:"dm-card-table-body",children:v.getRowModel().rows.length?v.getRowModel().rows.map((R,j)=>a.jsx(Hn,{onClick:()=>{n(R.original.id)},className:"dm-card-table-body-row group",role:"row","aria-rowindex":j+1,children:R.getVisibleCells().map((_,I)=>a.jsx($r,{className:`whitespace-normal ${_.column.id==="actions"?"actions-cell":""}`,role:"cell","aria-colindex":I+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)):a.jsx(Hn,{children:a.jsx($r,{colSpan:f.length,className:"dm-card-table-body-row-empty",role:"cell",children:a.jsx("span",{role:"status","aria-live":"polite",children:"No scheduled triggers found."})})})})]})}),a.jsx(bie,{table:v,onPreviousClick:C,onNextClick:S}),a.jsx(Y2,{isOpen:s,onClose:c,dataMartId:t})]})}function Cie({dataMartId:e}){const{triggers:t,deleteScheduledTrigger:n,selectScheduledTrigger:r,selectedTrigger:s}=Poe(e),[i,c]=h.useState(!1);h.useEffect(()=>{s&&c(!0)},[s]);const u=y=>{const g=t.find(x=>x.id===y);g&&r(g)},f=()=>{c(!1),r(null)},m=async y=>{try{await n(e,y)}catch(g){console.error("Error deleting trigger:",g)}};return a.jsxs(a.Fragment,{children:[a.jsx(Sie,{triggers:t,dataMartId:e,onEditTrigger:u,onDeleteTrigger:y=>void m(y)}),a.jsx(Y2,{isOpen:i,onClose:f,dataMartId:e})]})}function W2(){return a.jsx("div",{className:"dm-card-block !gap-1.5 !py-3",children:a.jsxs("div",{className:"text-foreground flex items-start gap-1.5 text-sm",children:[a.jsx(Xb,{className:"h-5 w-5 shrink-0","aria-hidden":"true"}),a.jsxs("div",{children:[a.jsx("p",{className:"font-medium",children:"Time Triggers"}),a.jsxs("p",{className:"text-muted-foreground",children:["Set up automatic runs in the ",a.jsx("span",{className:"font-medium",children:"Triggers"})," tab once you’ve saved and published this Data Mart."]})]})]})})}function Ip(e){return e.startsWith('"')&&e.endsWith('"')?e:`"${e}"`}function kg(e){return e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function Eie({dataStorageType:e,target:t,destinationName:n,connectorName:r,onTargetChange:s}){const i=n.replace(/[^a-zA-Z0-9_]/g,"_"),c=r.replace(/[^a-zA-Z0-9_]/g,"_").toLowerCase(),[u,f]=h.useState(""),[m,y]=h.useState(""),[g,x]=h.useState(""),[v,C]=h.useState(null),[S,E]=h.useState(null),[R,j]=h.useState(null),_=(D,k=!1)=>D.trim()?k&&D.startsWith('"')&&D.endsWith('"')?D.slice(1,-1)?null:"Quoted identifier cannot be empty":/^[A-Za-z][A-Za-z0-9_]*$/.test(D)?null:"Use letters, numbers, and underscores; start with a letter":"This field is required",I=h.useCallback((D,k,B,G,Y,V)=>{let Z;if(e===Re.SNOWFLAKE&&Y){const M=Ip(Y),$=Ip(k);Z=`${D}.${M}.${$}`}else Z=`${D}.${k}`;const F=e===Re.SNOWFLAKE?!!(D&&Y&&k&&B===null&&V===null&&G===null):!!(D&&k&&B===null&&G===null);s({fullyQualifiedName:Z,isValid:F})},[s,e]);h.useEffect(()=>{let D="",k="",B="";if(t!=null&&t.fullyQualifiedName){const M=t.fullyQualifiedName.match(/(?:[^."]+|"[^"]*")+/g)??[];if(e===Re.SNOWFLAKE&&M.length===3){const $=M[0],H=M[1],oe=M[2];$&&H&&oe&&(D=$,k=kg(H),B=kg(oe))}else if(M.length>=2){const $=M[0],H=M[1];$&&H&&(D=$,B=H)}}else D=`${c}_owox`,e===Re.SNOWFLAKE&&(k="PUBLIC"),B=i;const G=_(D),Y=e===Re.SNOWFLAKE?_(k,!0):null,V=_(B,e===Re.SNOWFLAKE);f(D),y(k),x(B),C(G),E(Y),j(V);const Z=e===Re.SNOWFLAKE&&k?`${D}.${Ip(k)}.${Ip(B)}`:`${D}.${B}`,F=e===Re.SNOWFLAKE?!!(D&&k&&B&&G===null&&Y===null&&V===null):!!(D&&B&&G===null&&V===null);((t==null?void 0:t.fullyQualifiedName)!==Z||t.isValid!==F)&&I(D,B,G,V,k,Y)},[t,i,c,e,I]);const A=D=>{f(D);const k=_(D);C(k),I(D,g,k,R,m,S)},O=D=>{y(D);const k=_(D,!0);E(k),I(u,g,v,R,D,k)},T=D=>{x(D);const k=_(D,e===Re.SNOWFLAKE);j(k),I(u,D,v,k,m,S)};return a.jsxs(ni,{children:[e===Re.GOOGLE_BIGQUERY&&a.jsxs(a.Fragment,{children:[a.jsx(ti,{icon:a.jsx(SD,{}),title:"Google BigQuery",docUrl:"https://docs.owox.com/docs/storages/supported-storages/google-bigquery/",variant:"compact"}),a.jsxs(al,{title:"Choose where to store your data",children:[a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"dataset-name",tooltip:"Enter dataset name for Google BigQuery where the connector data will be stored.",children:"Dataset name"}),a.jsx(It,{type:"text",id:"dataset-name",placeholder:"Enter dataset name",autoComplete:"off",className:"box-border w-full",value:u,"aria-invalid":!!v,"aria-describedby":v?"dataset-name-error":void 0,onChange:D=>{A(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Dataset is auto-created on first run if it doesn’t exist"}),v&&a.jsx("p",{id:"dataset-name-error",className:"text-destructive text-sm",children:v})]}),a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"table-name",tooltip:"Enter table name where the connector data will be stored.",children:"Table name"}),a.jsx(It,{type:"text",id:"table-name",placeholder:"Enter table name",autoComplete:"off",className:"box-border w-full",value:g,"aria-invalid":!!R,"aria-describedby":R?"table-name-error":void 0,onChange:D=>{T(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Table is auto-created on first run if it doesn’t exist"}),R&&a.jsx("p",{id:"table-name-error",className:"text-destructive text-sm",children:R})]})]})]}),e===Re.AWS_ATHENA&&a.jsxs(a.Fragment,{children:[a.jsx(ti,{icon:a.jsx(CD,{}),title:"AWS Athena",docUrl:"https://docs.owox.com/docs/storages/supported-storages/aws-athena/",variant:"compact"}),a.jsxs(al,{title:"Choose where to store your data",children:[a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"database-name",tooltip:"Enter database name for Amazon Athena where the connector data will be stored.",children:"Database name"}),a.jsx(It,{type:"text",id:"database-name",placeholder:"Enter database name",autoComplete:"off",className:"box-border w-full",value:u,"aria-invalid":!!v,"aria-describedby":v?"database-name-error":void 0,onChange:D=>{A(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Database is auto-created on first run if it doesn’t exist"}),v&&a.jsx("p",{id:"database-name-error",className:"text-destructive text-sm",children:v})]}),a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"athena-table-name",tooltip:"Enter table name where the connector data will be stored.",children:"Table name"}),a.jsx(It,{type:"text",id:"athena-table-name",placeholder:"Enter table name",autoComplete:"off",className:"box-border w-full",value:g,"aria-invalid":!!R,"aria-describedby":R?"athena-table-name-error":void 0,onChange:D=>{T(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Table is auto-created on first run if it doesn’t exist"}),R&&a.jsx("p",{id:"athena-table-name-error",className:"text-destructive text-sm",children:R})]})]})]}),e===Re.SNOWFLAKE&&a.jsxs(a.Fragment,{children:[a.jsx(ti,{icon:a.jsx(ED,{}),title:"Snowflake",docUrl:"https://docs.owox.com/docs/storages/supported-storages/snowflake/",variant:"compact"}),a.jsxs(al,{title:"Choose where to store your data",children:[a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"snowflake-database-name",tooltip:"Enter database name for Snowflake where the connector data will be stored.",children:"Database name"}),a.jsx(It,{type:"text",id:"snowflake-database-name",placeholder:"Enter database name",autoComplete:"off",className:"box-border w-full",value:u,"aria-invalid":!!v,"aria-describedby":v?"snowflake-database-name-error":void 0,onChange:D=>{A(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Database is auto-created on first run if it doesn't exist"}),v&&a.jsx("p",{id:"snowflake-database-name-error",className:"text-destructive text-sm",children:v})]}),a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"snowflake-schema-name",tooltip:"Enter schema name for Snowflake where the connector data will be stored. Identifiers will be quoted automatically to preserve case sensitivity.",children:"Schema name"}),a.jsx(It,{type:"text",id:"snowflake-schema-name",placeholder:"PUBLIC",autoComplete:"off",className:"box-border w-full",value:m,"aria-invalid":!!S,"aria-describedby":S?"snowflake-schema-name-error":void 0,onChange:D=>{O(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Schema is auto-created on first run if it doesn't exist"}),S&&a.jsx("p",{id:"snowflake-schema-name-error",className:"text-destructive text-sm",children:S})]}),a.jsxs(Bi,{children:[a.jsx(Ga,{required:!0,htmlFor:"snowflake-table-name",tooltip:"Enter table name where the connector data will be stored. Identifiers will be quoted automatically to preserve case sensitivity.",children:"Table name"}),a.jsx(It,{type:"text",id:"snowflake-table-name",placeholder:"my_table",autoComplete:"off",className:"box-border w-full",value:g,"aria-invalid":!!R,"aria-describedby":R?"snowflake-table-name-error":void 0,onChange:D=>{T(D.target.value)},required:!0}),a.jsx("p",{className:"text-muted-foreground text-sm",children:"Table is auto-created on first run if it doesn't exist"}),R&&a.jsx("p",{id:"snowflake-table-name-error",className:"text-destructive text-sm",children:R})]})]})]}),a.jsx(al,{title:"Schedule updates",children:a.jsx(W2,{})})]})}function wie({onSubmit:e,dataStorageType:t,configurationOnly:n=!1,existingConnector:r=null,mode:s="full",initialStep:i,preselectedConnector:c,onDirtyChange:u}){const[f,m]=h.useState(!1),[y,g]=h.useState(null),[x,v]=h.useState(""),[C,S]=h.useState([]),[E,R]=h.useState(1),[j,_]=h.useState({}),[I,A]=h.useState(!1),[O,T]=h.useState(new Set),[D,k]=h.useState(new Set),{connectors:B,connectorSpecification:G,connectorFields:Y,loading:V,loadingSpecification:Z,loadingFields:F,error:M,fetchAvailableConnectors:$,fetchConnectorSpecification:H,fetchConnectorFields:oe}=Dc();h.useEffect(()=>{u==null||u(f)},[f,u]);const[ge,P]=h.useState(null),U=h.useMemo(()=>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"}],[n,s]),z=U.length,X=h.useCallback(async Me=>{!O.has(Me)&&!Z&&(T(q=>new Set(q).add(Me)),await H(Me))},[O,Z,H]),W=h.useCallback(async Me=>{D.has(Me)||(k(q=>new Set(q).add(Me)),await oe(Me))},[D,oe]);h.useEffect(()=>{if(!c||y||B.length===0)return;const Me=B.find(q=>q.name===c);Me&&(g(Me),R(i??2),X(Me.name),!n&&s!=="fields-only"&&W(Me.name))},[c,B,y,i,n,s,X,W]),h.useEffect(()=>{if(B.length===0&&!V&&$(),r&&B.length>0&&!y){const{source:Me,storage:q}=r;v(Me.node),S(Me.fields),_(Me.configuration[0]||{}),P({fullyQualifiedName:q.fullyQualifiedName,isValid:!0});const ne=B.find(ce=>ce.name===Me.name);ne&&(g(ne),X(ne.name),!n&&s!=="fields-only"&&W(ne.name),s==="fields-only"&&W(ne.name))}if(n&&B.length>0&&!y&&!r){const Me=B[0];g(Me),X(Me.name)}},[s,r,B,n,V,$,X,W,y]);const ae=Me=>{g(Me),_({}),A(!1),m(!0),T(q=>{const ne=new Set(q);return ne.delete(Me.name),ne}),X(Me.name),W(Me.name),Le({event:"connector_setup",category:Me.name,action:"connector_selected",label:Me.displayName})},J=Me=>{v(Me),S([]),m(!0)},le=(Me,q)=>{S(q?ne=>ne.includes(Me)?ne:[...ne,Me]:ne=>ne.filter(ce=>ce!==Me)),m(!0)},ye=(Me,q)=>{S(q?ne=>{const ce=Me.filter(Oe=>!ne.includes(Oe));return[...ne,...ce]}:ne=>ne.filter(ce=>!Me.includes(ce))),m(!0)},Ce=Me=>{P(Me),m(!0)},Ve=h.useCallback(Me=>{_(Me),m(!0)},[]),De=h.useCallback(Me=>{A(Me)},[]);h.useEffect(()=>{G&&(G.some(q=>q.required&&q.name!=="Fields")||A(!0))},[G]),h.useEffect(()=>{var q;const Me=((q=U[E-1])==null?void 0:q.title)??`Step ${String(E)}`;y&&Le({event:"connector_setup",category:y.name,action:"step",label:Me})},[E,y]);const et=()=>{E<z&&R(E+1)},rt=()=>{E>1&&R(E-1)},dn=()=>{if(n)return y!==null&&I;if(s==="fields-only")switch(E){case 1:return C.length>0;default:return!1}switch(E){case 1:return y!==null;case 2:return I;case 3:return x!=="";case 4:return C.length>0;case 5:return ge!==null&&ge.fullyQualifiedName!==""&&ge.isValid;default:return!1}},zt=()=>E>1,On=(Me,q)=>{if(!Me)return q;const ne=Me.find(ce=>ce.name===q);return(ne==null?void 0:ne.destinationName)??q},yn=()=>{if(n&&E===1)return G&&y?a.jsx(Q_,{connector:y,connectorSpecification:G,onConfigurationChange:Ve,onValidationChange:De,initialConfiguration:j,loading:Z,isEditingExisting:!!(r!=null&&r.source.configuration.length)}):null;if(s==="fields-only")switch(E){case 1:return y&&x&&Y?a.jsx(J_,{connector:y,connectorFields:Y,selectedField:x,selectedFields:C,onFieldToggle:le,onSelectAllFields:ye}):null;default:return null}switch(E){case 1:return a.jsx(goe,{connectors:B,selectedConnector:y,loading:V,error:M,onConnectorSelect:ae,onConnectorDoubleClick:()=>{R(Me=>Me<z?Me+1:Me)}});case 2:return y&&G?a.jsx(Q_,{connector:y,connectorSpecification:G,onConfigurationChange:Ve,onValidationChange:De,initialConfiguration:j,loading:Z,isEditingExisting:!1}):null;case 3:return y&&Y?a.jsx(Ooe,{connectorFields:Y,connector:y,selectedField:x,connectorName:y.displayName,loading:F,onFieldSelect:J}):null;case 4:return y&&x&&Y?a.jsx(J_,{connector:y,connectorFields:Y,selectedField:x,selectedFields:C,onFieldToggle:le,onSelectAllFields:ye}):null;case 5:return x&&Y?a.jsx(Eie,{dataStorageType:t,destinationName:On(Y,x),connectorName:(y==null?void 0:y.displayName)??"",target:ge,onTargetChange:Ce}):null;default:return null}};return a.jsxs(rre,{children:[a.jsx(are,{children:yn()}),a.jsx(sre,{variant:"horizontal",children:a.jsx(yoe,{currentStep:E,totalSteps:z,canGoNext:dn(),canGoBack:zt(),isLoading:Z||F,onNext:et,onBack:rt,onFinish:()=>{n&&y?(e({source:{name:y.name,configuration:[j],node:(r==null?void 0:r.source.node)??x,fields:(r==null?void 0:r.source.fields)??C},storage:(r==null?void 0:r.storage)??{fullyQualifiedName:(r==null?void 0:r.storage.fullyQualifiedName)??""}}),Le({event:"connector_setup",category:y.name,action:"created",label:"configuration-only"})):s==="fields-only"&&r?(e({source:{...r.source,fields:C},storage:r.storage}),Le({event:"connector_setup",category:r.source.name,action:"created",label:"fields-only"})):y&&ge&&(e({source:{name:y.name,configuration:[j],node:x,fields:C},storage:{fullyQualifiedName:ge.fullyQualifiedName}}),Le({event:"connector_setup",category:y.name,action:"created",label:"full"})),m(!1)}})})]})}const RI=20,jI=20;function TI({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 _I(e=30,t=0){TI({vertical:jI+e,horizontal:RI+t})}function ah(){TI({vertical:jI,horizontal:RI})}function NI({isOpen:e,onClose:t,dataStorageType:n,onSubmit:r,configurationOnly:s=!1,existingConnector:i=null,mode:c="full",initialStep:u,preselectedConnector:f}){h.useEffect(()=>(e?_I(55):ah(),()=>{ah()}),[e]);const{showUnsavedDialog:m,setShowUnsavedDialog:y,handleClose:g,confirmClose:x,handleFormDirtyChange:v,handleFormSubmitSuccess:C}=Ic(t);return a.jsxs(a.Fragment,{children:[a.jsx(ci,{open:e,onOpenChange:S=>{S||g()},children:a.jsxs(ui,{children:[a.jsxs(di,{children:[a.jsx(fi,{children:c==="fields-only"?"Connector Fields":i!=null&&i.source.name?"Edit Connector":"Set Up Connector"}),a.jsx(yl,{children:c==="fields-only"?"Select fields for your Data Mart":i!=null&&i.source.name?"Update configuration":"Follow these steps to set it up"})]}),a.jsx(wie,{onSubmit:S=>{r(S),C()},dataStorageType:n,configurationOnly:s||c==="configuration-only",existingConnector:i,mode:c,initialStep:u,preselectedConnector:f,onDirtyChange:v})]})}),a.jsx(br,{open:m,onOpenChange:y,title:"Unsaved Changes",description:"You have unsaved changes. Exit without saving?",confirmLabel:"Yes, leave now",cancelLabel:"No, stay here",onConfirm:x,variant:"destructive"})]})}const X2=({dataStorageType:e,onSubmit:t,children:n,configurationOnly:r=!1,existingConnector:s=null,preset:i,isOpen:c,onClose:u})=>{const[f,m]=h.useState(!1),[y,g]=h.useState(1),[x,v]=h.useState();h.useEffect(()=>{c!==void 0&&m(c)},[c]);const C=()=>{v(void 0),g(1),m(!0)},S=()=>{m(!1),u==null||u()};return h.useEffect(()=>{i&&(i==="connector"?(v(void 0),g(1),m(!0)):(v(i),g(2),m(!0)))},[i]),a.jsxs(a.Fragment,{children:[n&&a.jsx("div",{onClick:C,style:{cursor:"pointer"},children:n}),a.jsx(nd,{children:a.jsx(NI,{isOpen:f,onClose:S,dataStorageType:e,onSubmit:t,configurationOnly:r,existingConnector:s,initialStep:y,preselectedConnector:x})})]})};function Rie({storageType:e,onSetupConnector:t,preset:n,isOpen:r,onClose:s}){return a.jsx(X2,{dataStorageType:e,onSubmit:t,configurationOnly:!1,preset:n,isOpen:r,onClose:s,children:a.jsxs(Ee,{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:[a.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:a.jsx(eS,{className:"h-4 w-4",strokeWidth:2.25})}),a.jsx("span",{children:"Setup Connector"}),a.jsx(_a,{className:"h-6 w-6"})]})})}const jie=e=>{switch(e){case Re.GOOGLE_BIGQUERY:return"Google BigQuery";case Re.AWS_ATHENA:return"AWS Athena";case Re.SNOWFLAKE:return"Snowflake";default:return e}},Au=e=>typeof e=="object"&&"connector"in e,jf=e=>{if(!Au(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.split("."),i=s.length===2||s.length===3;return r&&i};function Tie({configIndex:e,connectorDef:t,onRemoveConfiguration:n,onUpdateConfiguration:r,totalConfigurations:s,dataStorage:i}){const c=Sl.getInfo(i.type),{connectors:u,fetchAvailableConnectors:f}=Dc();h.useEffect(()=>{f()},[f]);const m=C=>{const S=u.find(E=>E.name===C);if(S!=null&&S.logoBase64)return()=>a.jsx(_c,{base64:S.logoBase64,size:24})},y=()=>{const C=t.connector.source.node||"No node selected";return a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsx("span",{className:"text-muted-foreground/75",children:"Data:"})," ",a.jsx("span",{className:"text-muted-foreground font-medium",children:C}),a.jsx("span",{className:"text-muted-foreground",children:"•"}),a.jsxs(Et,{children:[a.jsx(wt,{asChild:!0,children:a.jsxs("span",{className:"text-muted-foreground flex items-center gap-1 font-medium",children:[a.jsx("span",{children:"Edit config"}),a.jsx(_a,{className:"h-3 w-3"})]})}),a.jsx(Rt,{children:"Edit connector configuration"})]})]})},g=(C,S,E)=>a.jsxs("span",{children:[a.jsxs("span",{className:"text-muted-foreground/75",children:[C,":"]})," ",a.jsx(gn,{href:E,onClick:R=>{R.stopPropagation()},children:S})]}),x=()=>{switch(i.type){case Re.GOOGLE_BIGQUERY:{const C=i.config.projectId,S=t.connector.storage.fullyQualifiedName,E=S.split(".")[0],R=S.split(".")[1],j=`https://console.cloud.google.com/bigquery?project=${C}&ws=!1m4!1m3!3m2!1s${C}!2s${E}`,_=`https://console.cloud.google.com/bigquery?project=${C}&ws=!1m4!1m3!3m2!1s${C}!2s${E}!3s${R}`;return a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[g("Dataset",E,j),a.jsx("span",{className:"text-muted-foreground",children:"•"}),g("Table",R,_),a.jsxs(Et,{children:[a.jsx(wt,{asChild:!0,children:a.jsx(Fr,{className:"h-4 w-4"})}),a.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 Re.AWS_ATHENA:{const C=i.config.region,S=t.connector.storage.fullyQualifiedName,[E,R]=S.split("."),j=`https://console.aws.amazon.com/athena/home?region=${C}#/query-editor`;return a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[g("Database",E,j),a.jsx("span",{className:"text-muted-foreground",children:"•"}),g("Table",R,j),a.jsxs(Et,{children:[a.jsx(wt,{asChild:!0,children:a.jsx(Fr,{className:"h-4 w-4"})}),a.jsx(Rt,{children:"The database and table are automatically created during the first run of the data mart, if they don't already exist"})]})]})}case Re.SNOWFLAKE:{const C=i.config.account,E=t.connector.storage.fullyQualifiedName.split("."),R=E[0],j=E[1],_=E[2],I=`https://${C}.snowflakecomputing.com`,A=`${I}/#/data/databases/${R}`,O=`${I}/#/data/databases/${R}/schemas/${j}`,T=`${I}/#/data/databases/${R}/schemas/${j}/table/${_}`;return a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[g("Database",R,A),a.jsx("span",{className:"text-muted-foreground",children:"•"}),g("Schema",kg(j),O),a.jsx("span",{className:"text-muted-foreground",children:"•"}),g("Table",kg(_),T),a.jsxs(Et,{children:[a.jsx(wt,{asChild:!0,children:a.jsx(Fr,{className:"h-4 w-4"})}),a.jsx(Rt,{children:"The database, schema 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"}},v=()=>s!==1;return a.jsxs("div",{className:"border-border flex w-full items-center rounded-lg border-1 p-1 dark:bg-white/2",children:[a.jsx("div",{className:"flex-grow",children:a.jsxs("div",{className:"grid grid-cols-2 items-center gap-4",children:[a.jsx(X2,{dataStorageType:i.type,onSubmit:r(e),configurationOnly:!0,existingConnector:{source:{...t.connector.source,configuration:[t.connector.source.configuration[e]]},storage:t.connector.storage},children:a.jsx(vb,{icon:m(t.connector.source.name),title:t.connector.source.name||"Connector",subtitle:y(),className:"bg-background hover:bg-muted min-h-[80px] cursor-pointer border-0 transition-colors hover:shadow-none"})}),a.jsx(vb,{title:jie(i.type),icon:c.icon,subtitle:x(),className:"bg-background min-h-[80px] cursor-default border-0 hover:shadow-none dark:bg-white/2"})]})}),a.jsx("div",{className:"shrink-0 px-4",children:a.jsxs(Et,{children:[a.jsx(wt,{asChild:!0,children:a.jsx("span",{children:a.jsx(Ee,{type:"button",variant:"ghost",onClick:()=>{v()&&n(e)},disabled:!v(),children:a.jsx(es,{className:"h-4 w-4"})})})}),!v()&&a.jsx(Rt,{children:"Remove last configuration only after adding a new one."})]})})]})}function _ie({storageType:e,onAddConfiguration:t,existingConnector:n}){return a.jsx("div",{children:a.jsx(X2,{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:a.jsxs(Ee,{type:"button",variant:"outline",className:"dm-card-table-add-field-btn cursor-pointer",children:[a.jsx(ha,{className:"h-4 w-4"}),a.jsx("span",{children:"Configuration"})]})})})}function Nie({control:e,storageType:t,preset:n,autoOpen:r=!1,saveDataMartDefinition:s}){const{dataMart:i,runDataMart:c}=vs(),{setValue:u,getValues:f,trigger:m}=yd(),[y,g]=h.useState(!1),[x,v]=h.useState(!1);h.useEffect(()=>{r&&v(!0)},[r]);const C=(i==null?void 0:i.status)??zr.DRAFT,S=async Z=>{u("definition",Z,{shouldDirty:!0,shouldTouch:!0}),await m("definition")&&s&&s()},E=async Z=>{const F=Z.source,M=Z.storage;await S({connector:{source:F,storage:M}})},R=async Z=>{if(i){if(i.status.code!==zr.PUBLISHED){Tt.error("Manual run is only available for published data marts");return}await c({id:i.id,payload:Z})}},j=Z=>async F=>{const $=f().definition;if(typeof $=="object"&&Au($)){const H=[...$.connector.source.configuration];H[Z]=F.source.configuration[0]||{};const oe={connector:{...$.connector,source:{...$.connector.source,configuration:H}}};await S(oe)}},_=async Z=>{const M=f().definition;if(typeof M=="object"&&Au(M)){const $={connector:{...M.connector,source:{...M.connector.source,fields:Z.source.fields}}};await S($)}g(!1)},I=Z=>{R({runType:Z.runType,data:Z.data})},A=Z=>{const F=Z.connector.source.fields.length;return a.jsxs(Ee,{type:"button",variant:"outline",onClick:()=>{g(!0)},className:"dm-card-table-add-field-btn cursor-pointer",children:[a.jsx(KU,{className:"h-4 w-4"}),a.jsxs("span",{children:["Edit Fields (",String(F),")"]})]})},[O,T]=h.useState(null),[D,k]=h.useState(!1),B=Z=>{T(Z),k(!0)},G=async()=>{O!==null&&(await Y(O),T(null),k(!1))},Y=async Z=>{const M=f().definition;if(Au(M)&&M.connector.source.configuration.length<=1){const $=B2($e.CONNECTOR);await S($)}if(typeof M=="object"&&Au(M)&&M.connector.source.configuration.length>1){const $={...M.connector.source,configuration:M.connector.source.configuration.filter((oe,ge)=>ge!==Z)},H={connector:{...M.connector,source:$}};await S(H)}},V=async Z=>{const M=f().definition;if(Au(M)){const $={...M.connector.source,configuration:[...M.connector.source.configuration,Z]},H={connector:{...M.connector,source:$}};await S(H)}};return a.jsxs(a.Fragment,{children:[a.jsx(_t,{control:e,name:"definition",render:({field:Z})=>a.jsxs(xt,{className:"dark:bg-white/2",children:[a.jsx(Ct,{children:a.jsx("div",{className:"space-y-3",children:!jf(Z.value)||C===zr.DRAFT?a.jsx(Rie,{storageType:t,onSetupConnector:F=>{E(F),v(!1)},preset:n,isOpen:x,onClose:()=>{v(!1)}}):a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(_ie,{storageType:t,onAddConfiguration:F=>void V(F),existingConnector:jf(Z.value)?{source:Z.value.connector.source,storage:Z.value.connector.storage}:void 0}),jf(Z.value)&&A(Z.value)]}),a.jsx("div",{className:"flex items-center gap-2",children:i&&i.definitionType===$e.CONNECTOR&&a.jsx(O6,{configuration:i.definition,onManualRun:I,children:a.jsxs(Ee,{variant:"outline",children:[a.jsx(Xg,{className:"h-4 w-4"}),a.jsx("span",{children:"Manual Run..."})]})})})]}),a.jsx("div",{className:"space-y-3",children:jf(Z.value)&&(i!=null&&i.storage)?Z.value.connector.source.configuration.map((F,M)=>{const $=Z.value;return a.jsx(nd,{children:a.jsx(Tie,{configIndex:M,connectorDef:$,dataStorage:i.storage,onRemoveConfiguration:H=>{B(H)},onUpdateConfiguration:H=>j(H),dataMartStatus:typeof C=="object"?C.code:C,totalConfigurations:$.connector.source.configuration.length},M)},M)}):null})]})})}),a.jsx(Mt,{})]})}),a.jsx(nd,{children:a.jsx(NI,{isOpen:y,onClose:()=>{g(!1)},onSubmit:Z=>void _(Z),dataStorageType:t,existingConnector:jf(f().definition)?{source:f().definition.connector.source,storage:f().definition.connector.storage}:void 0,mode:"fields-only"})}),a.jsx(br,{open:D,onOpenChange:k,title:"Delete Configuration",description:"Are you sure you want to delete this configuration? This action cannot be undone.",confirmLabel:"Delete",cancelLabel:"Cancel",onConfirm:()=>{G()},onCancel:()=>{T(null)},variant:"destructive"})]})}function Aie({definitionType:e,storageType:t,preset:n,saveDataMartDefinition:r}){const{control:s}=yd(),[i,c]=h.useState(!1);return h.useEffect(()=>{e===$e.CONNECTOR&&!n?c(!0):c(!1)},[e,n]),a.jsxs("div",{className:"space-y-2",children:[e===$e.SQL&&a.jsx(doe,{control:s}),e===$e.TABLE&&a.jsx(foe,{control:s,storageType:t}),e===$e.VIEW&&a.jsx(hoe,{control:s,storageType:t}),e===$e.TABLE_PATTERN&&a.jsx(moe,{control:s,storageType:t}),e===$e.CONNECTOR&&a.jsx(Nie,{control:s,storageType:t,preset:n,autoOpen:i,saveDataMartDefinition:r})]})}function AI(){const[e]=zL(),t=e.get("preset");return h.useMemo(()=>{if(!t)return;const n=t.toLowerCase();return yee(n)},[t])}function Die(e,t){const[n,r]=h.useState(e);return h.useEffect(()=>{const s=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(s)}},[e,t]),n}const Oie=1e3,Iie=[Xa.SUCCESS,Xa.ERROR,Xa.CANCELLED];function Mie(e){const[t,n]=h.useState(!1),[r,s]=h.useState(null),i=h.useRef({triggerId:null,abortController:null}),c=h.useCallback(g=>i.current.triggerId===g,[]),u=h.useCallback(g=>{s({isValid:!1,error:g instanceof Error?g.message:"Validation failed"}),n(!1)},[]),f=h.useCallback(async()=>{const{triggerId:g,abortController:x}=i.current;if(g){x==null||x.abort(),i.current={triggerId:null,abortController:null},s(null),n(!1);try{await Tn.abortSqlDryRunTrigger(e,g)}catch(v){console.error("Failed to cancel trigger:",v)}}},[e]),m=h.useCallback(async(g,x)=>{for(;!x.aborted&&c(g);)try{const v=await Tn.getSqlDryRunTriggerStatus(e,g);if(Iie.includes(v)){const C=await Tn.getSqlDryRunTriggerResponse(e,g);s({isValid:C.isValid,error:C.error??void 0,bytes:C.bytes}),n(!1),i.current={triggerId:null,abortController:null};return}await new Promise(C=>setTimeout(C,Oie))}catch(v){u(v),i.current={triggerId:null,abortController:null};return}},[e,c,u]),y=h.useCallback(async g=>{await f(),n(!0),s(null);try{const{triggerId:x}=await Tn.createSqlDryRunTrigger(e,g),v=new AbortController;i.current={triggerId:x,abortController:v},await m(x,v.signal)}catch(x){u(x)}},[e,f,m,u]);return h.useEffect(()=>()=>{const{triggerId:g,abortController:x}=i.current;x==null||x.abort(),g&&Tn.abortSqlDryRunTrigger(e,g).catch(()=>{})},[e]),{validateSql:y,isLoading:t,result:r,cancel:f}}const kie=300;function Lie({sql:e,dataMartId:t,debounceDelay:n=kie,className:r="",onValidationStateChange:s}){const i=Die(e.trim(),n),{validateSql:c,isLoading:u,result:f,cancel:m}=Mie(t);h.useEffect(()=>{if(!i){m();const g={isLoading:!1,isValid:null,error:null,bytes:null};s==null||s(g);return}c(i)},[i,c,m,s]),h.useEffect(()=>{const g={isLoading:u,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(g)},[u,f,s]);const y=()=>u?a.jsxs("div",{className:"flex h-5 items-center gap-2",children:[a.jsx(Ec,{className:"h-4 w-4 animate-spin"}),a.jsx("span",{className:"text-sm",children:"Validating..."})]}):f?f.isValid?a.jsxs("div",{className:"flex h-5 items-center gap-2",children:[a.jsx(IP,{className:"h-4 w-4 text-green-600"}),a.jsx("span",{className:"text-sm font-medium text-green-600",children:"Valid SQL code"}),f.bytes!==void 0&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"mx-1 text-gray-400",children:"•"}),a.jsxs(Et,{children:[a.jsx(wt,{asChild:!0,children:a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx(lc,{className:"h-3 w-3 text-gray-600"}),a.jsx("span",{className:"text-xs text-gray-600",children:NQ(f.bytes)})]})}),a.jsx(Rt,{children:a.jsx("p",{className:"text-xs",children:"This is an estimated volume and may differ from the actual value"})})]})]})]}):a.jsxs("div",{className:"flex h-9 items-center gap-2",children:[a.jsx(ng,{className:"h-4 w-4 flex-shrink-0 text-red-600"}),f.error&&a.jsx("span",{className:"text-xs text-red-500",children:f.error})]}):a.jsxs("div",{className:"flex h-5 items-center gap-2 text-gray-500",children:[a.jsx(lc,{className:"h-4 w-4"}),a.jsx("span",{className:"text-sm",children:"Type a query to get started"})]});return a.jsx("div",{className:`inline-flex h-9 items-center px-3 py-2 ${r}`,children:y()})}const Pie={isValid:null,isLoading:!1,error:null},Uie=(e,t)=>{if(e!==$e.SQL)return"";const n=t;return(n==null?void 0:n.sqlQuery)??""},zie=e=>B2(e);function Fie({definitionType:e,initialDefinitionType:t,setDefinitionType:n}){const{dataMart:r,updateDataMartDefinition:s,runSchemaActualization:i}=vs(),c=AI();if(!r)throw new Error("Data mart not found");const{definition:u,id:f,storage:{type:m}}=r,[,y]=h.useState(Pie),[g,x]=h.useState(!1),v=h.useCallback(()=>{if(!e)return;const V={definitionType:e,definition:B2(e)};return u?{definitionType:e,definition:u}:V},[e,u]),C=h.useCallback(()=>{if(!e)return;const V=uoe(e,m);return yi(V)},[e,m]),S=Ro({resolver:C(),defaultValues:v(),mode:"onChange"}),{handleSubmit:E,reset:R,watch:j,formState:{isDirty:_,isValid:I}}=S,A=j("definition"),O=Uie(e,A);h.useEffect(()=>{e&&R(v())},[e,R,v]),h.useEffect(()=>{if(!e&&!t&&(c!=null&&c.definitionType)){n(c.definitionType);const V={definitionType:c.definitionType,definition:zie(c.definitionType)};R(V)}},[c,e,t,R,n]);const T=h.useCallback(V=>{y({isLoading:V.isLoading,isValid:V.isValid,error:V.error})},[]),D=h.useCallback(V=>{n(V)},[n]),k=h.useCallback(async V=>{if(e&&f)try{await s(f,V.definitionType,V.definition),x(!0),R(V)}catch(Z){console.error("Failed to update data mart definition:",Z)}},[f,e,s,R]);h.useEffect(()=>{g&&(x(!1),i==null||i())},[g,i]);const B=h.useCallback(V=>{V==null||V.preventDefault(),E(k)(V)},[E,k]),G=h.useCallback(()=>{R(v())},[R,v]),Y=()=>e?a.jsxs("form",{onSubmit:B,className:"space-y-4",children:[a.jsx(Aie,{definitionType:e,storageType:m,preset:c==null?void 0:c.connectorSourceTitle,saveDataMartDefinition:B}),e!==$e.CONNECTOR&&a.jsxs("div",{className:"flex items-center gap-4",children:[a.jsx(Ee,{variant:"default",type:"submit",disabled:!I||!_,children:"Save"}),a.jsx(Ee,{type:"button",variant:"ghost",onClick:G,disabled:!_,children:"Discard"}),e===$e.SQL&&O&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"h-6 w-px bg-gray-300"}),a.jsx(Lie,{sql:O,dataMartId:f,onValidationStateChange:T})]})]})]}):null;return a.jsx(i5,{...S,children:a.jsxs("div",{className:"space-y-4",children:[!t&&a.jsx(aoe,{initialType:e,onTypeSelect:D}),Y()]})})}function Hie(e){switch(e){case Re.GOOGLE_BIGQUERY:return{type:"bigquery-data-mart-schema",fields:[]};case Re.AWS_ATHENA:return{type:"athena-data-mart-schema",fields:[]};case Re.SNOWFLAKE:return{type:"snowflake-data-mart-schema",fields:[]};default:throw new Error(`Unsupported storage type: ${e}`)}}function DI(e){return e.type==="bigquery-data-mart-schema"}function OI(e){return e.type==="athena-data-mart-schema"}function II(e){return e.type==="snowflake-data-mart-schema"}function tN(e){return e!==null&&typeof e=="object"&&"mode"in e}function nN(e){return e!==null&&typeof e=="object"&&"isPrimaryKey"in e}function rN(e){return e!==null&&typeof e=="object"&&"isPrimaryKey"in e&&!("mode"in e)}function $ie(e){return e==null?"":typeof e=="string"||typeof e=="number"||typeof e=="boolean"?String(e):""}function l1(e){return e==null?e:JSON.parse(JSON.stringify(e))}function Vie(e){const t=l1(e),[n,r]=h.useState(t),[s,i]=h.useState(!1);h.useEffect(()=>{const f=l1(e);r(f),i(!1)},[e]);const c=h.useCallback(f=>{n?DI(n)&&f.every(tN)?(r({...n,fields:f}),i(!0)):OI(n)&&f.every(nN)?(r({...n,fields:f}),i(!0)):II(n)&&f.every(rN)&&(r({...n,fields:f}),i(!0)):f.length>0&&(tN(f[0])?(r({type:"bigquery-data-mart-schema",fields:f}),i(!0)):nN(f[0])?(r({type:"athena-data-mart-schema",fields:f}),i(!0)):rN(f[0])&&(r({type:"snowflake-data-mart-schema",fields:f}),i(!0)))},[n]),u=h.useCallback(()=>{const f=l1(e);r(f),i(!1)},[e]);return{schema:n,isDirty:s,updateSchema:c,resetSchema:u,setIsDirty:i}}function Bie(e,t){const n=h.useRef(!1),r=h.useRef(!1),[s,i]=h.useState("idle");return h.useEffect(()=>{e||(n.current||r.current)&&(i(t?"error":"success"),n.current=!1,r.current=!1)},[e,t]),{operationStatus:s,startSaveOperation:()=>{n.current=!0,i("idle")},startActualizeOperation:()=>{r.current=!0,i("idle")},resetOperationStatus:()=>{i("idle")}}}function Gie(e){const t=h.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]=h.useState({});return h.useEffect(()=>{r(t)},[t]),{columnVisibility:n,setColumnVisibility:r,defaultHiddenColumns:t}}function MI(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 i=e;return i.fields&&i.fields.length>0?i.fields.some(c=>MI(c,t)):!1}function kI(e,t,n=""){const r=[];return e.forEach((s,i)=>{const c=n?`${n}.${String(i)}`:String(i),u=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((u||f||m)&&r.push(c),s.fields&&s.fields.length>0){const y=kI(s.fields,t,c);y.length>0&&(r.includes(c)||r.push(c),r.push(...y))}}),r}function qie(e,t,n){const r=e.original;if(!n)return!0;const s=n.toLowerCase();return MI(r,s)}function Kie(e){const[t,n]=h.useState(""),r=h.useCallback(i=>{n(i),e.setGlobalFilter(i)},[e]),s=t.toLowerCase();return{value:t,onChange:r,searchValue:s}}function Zie(e){const[t,n]=h.useState(new Set),[r,s]=h.useState(null),i=h.useRef(""),c=h.useMemo(()=>{const C=S=>S.some(E=>E.type===ar.RECORD||E.type===ar.STRUCT||E.fields&&C(E.fields));return C(e)},[e]),u=h.useCallback(C=>{n(S=>{const E=new Set(S);return E.has(C)?E.delete(C):E.add(C),E})},[]),f=h.useCallback(()=>{const C=[],S=(E,R="")=>{E.forEach((j,_)=>{const I=R?`${R}.${String(_)}`:String(_);(j.type===ar.RECORD||j.type===ar.STRUCT)&&j.fields&&j.fields.length>0&&(C.push(I),S(j.fields,I))})};S(e),n(E=>C.every(j=>E.has(j))?new Set:new Set(C))},[e]),m=h.useMemo(()=>{const C=[],S=(E,R="",j=0)=>{E.forEach((_,I)=>{const A=R?`${R}.${String(I)}`:String(I),O=_.type===ar.RECORD||_.type===ar.STRUCT;C.push({..._,path:A,level:j}),O&&_.fields&&t.has(A)&&S(_.fields,A,j+1)})};return S(e),C},[e,t]),y=h.useCallback(C=>{if(C!==i.current)if(i.current=C,C){r===null&&s(new Set(t));const E=kI(e,C).filter(R=>{const j=R.split(".").map(Number);let _=e,I;for(let A=0;A<j.length;A++){if(I=_[j[A]],!I)return!1;if((I.type===ar.RECORD||I.type===ar.STRUCT)&&I.fields&&I.fields.length>0)return!0;A<j.length-1&&(_=I.fields??[])}return!1});n(R=>{const j=new Set(R);return E.forEach(_=>{j.add(_)}),j})}else r!==null&&(n(r),s(null))},[e,t,r]),g=h.useCallback(C=>{const S=m[C];return S.type===ar.RECORD||S.type===ar.STRUCT},[m]),x=h.useMemo(()=>e.map(C=>({...C,fields:void 0})),[e]),v=h.useMemo(()=>{const C=[],S=(E,R="")=>{E.forEach((j,_)=>{const I=R?`${R}.${String(_)}`:String(_);(j.type===ar.RECORD||j.type===ar.STRUCT)&&j.fields&&j.fields.length>0&&(C.push(I),S(j.fields,I))})};return S(e),C.length===0?!1:C.every(E=>t.has(E))},[e,t]);return{expandedRecords:t,hasRecordFields:c,toggleRecordExpansion:u,toggleAllRecords:f,flattenedFields:m,handleSearchChange:y,isRecordType:g,topLevelFields:x,allExpanded:v}}function Yie(e,t,n,r){const s=h.useCallback((f,m)=>{if(n){const y=[...e],g=t[f].path;if(!g)y[f]={...y[f],...m};else{const x=g.split(".").map(Number);let v=y,C;for(let E=0;E<x.length-1;E++)C=v[x[E]],v=C.fields??[];const S=x[x.length-1];v[S]&&(v[S]={...v[S],...m})}n(y)}},[e,t,n]),i=h.useCallback(()=>{if(n){const f={name:"",type:ar.STRING,mode:th.NULLABLE,isPrimaryKey:!1,status:Qa.DISCONNECTED};n([...e,f])}},[e,n]),c=h.useCallback(f=>{if(n){const m=[...e],y=t[f].path;if(!y)m.splice(f,1);else{const g=y.split(".").map(Number);let x=m,v;for(let S=0;S<g.length-1;S++)v=x[g[S]],x=v.fields??[];const C=g[g.length-1];x.splice(C,1)}n(m)}},[e,t,n]),u=h.useCallback(f=>{var m,y;if(n&&r){const g=[...e],x=t[f].path,v={name:"",type:ar.STRING,mode:th.NULLABLE,isPrimaryKey:!1,status:Qa.DISCONNECTED};if(!x)(m=g[f]).fields??(m.fields=[]),g[f].fields.push(v);else{const C=x.split(".").map(Number);let S=g;for(let E=0;E<C.length;E++){const R=C[E];E===C.length-1?((y=S[R]).fields??(y.fields=[]),S[R].fields.push(v)):S=S[R].fields??[]}}n(g)}},[e,t,n,r]);return{updateField:s,handleAddRow:i,handleDeleteRow:c,handleAddNestedField:u}}function Q2(e,t,n){return{handleDragEnd:h.useCallback(s=>{const{active:i,over:c}=s;if(!c||i.id===c.id||!t)return;if(!n){const x=Number(i.id),v=Number(c.id),C=[...e],[S]=C.splice(x,1);C.splice(v,0,S),t(C);return}const u=n.findIndex((x,v)=>(x.path??String(v))===i.id),f=n.findIndex((x,v)=>(x.path??String(v))===c.id);if(u===-1||f===-1)return;const m=n[u].path,y=n[f].path,g=[...e];if(!m&&!y){const[x]=g.splice(u,1);g.splice(f,0,x),t(g);return}if(m&&y){const x=m.split(".").map(Number),v=y.split(".").map(Number);if(x.length===v.length&&x.slice(0,-1).join(".")===v.slice(0,-1).join(".")){let C=g;for(let j=0;j<x.length-1;j++)C=C[x[j]].fields??[];const S=x[x.length-1],E=v[v.length-1],[R]=C.splice(S,1);C.splice(E,0,R),t(g)}}},[e,n,t])}}function Wie(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return h.useMemo(()=>r=>{t.forEach(s=>s(r))},t)}const Zy=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function bd(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function J2(e){return"nodeType"in e}function Na(e){var t,n;return e?bd(e)?e:J2(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function eC(e){const{Document:t}=Na(e);return e instanceof t}function qh(e){return bd(e)?!1:e instanceof Na(e).HTMLElement}function LI(e){return e instanceof Na(e).SVGElement}function Sd(e){return e?bd(e)?e.document:J2(e)?eC(e)?e:qh(e)||LI(e)?e.ownerDocument:document:document:document}const So=Zy?h.useLayoutEffect:h.useEffect;function tC(e){const t=h.useRef(e);return So(()=>{t.current=e}),h.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 Xie(){const e=h.useRef(null),t=h.useCallback((r,s)=>{e.current=setInterval(r,s)},[]),n=h.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,n]}function sh(e,t){t===void 0&&(t=[e]);const n=h.useRef(e);return So(()=>{n.current!==e&&(n.current=e)},t),n}function Kh(e,t){const n=h.useRef();return h.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function Lg(e){const t=tC(e),n=h.useRef(null),r=h.useCallback(s=>{s!==n.current&&(t==null||t(s,n.current)),n.current=s},[]);return[n,r]}function _b(e){const t=h.useRef();return h.useEffect(()=>{t.current=e},[e]),t.current}let c1={};function Zh(e,t){return h.useMemo(()=>{if(t)return t;const n=c1[e]==null?0:c1[e]+1;return c1[e]=n,e+"-"+n},[e,t])}function PI(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((i,c)=>{const u=Object.entries(c);for(const[f,m]of u){const y=i[f];y!=null&&(i[f]=y+e*m)}return i},{...t})}}const Vu=PI(1),Pg=PI(-1);function Qie(e){return"clientX"in e&&"clientY"in e}function nC(e){if(!e)return!1;const{KeyboardEvent:t}=Na(e.target);return t&&e instanceof t}function Jie(e){if(!e)return!1;const{TouchEvent:t}=Na(e.target);return t&&e instanceof t}function Nb(e){if(Jie(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 Qie(e)?{x:e.clientX,y:e.clientY}:null}const oh=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[oh.Translate.toString(e),oh.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),aN="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function ele(e){return e.matches(aN)?e:e.querySelector(aN)}const tle={display:"none"};function nle(e){let{id:t,value:n}=e;return re.createElement("div",{id:t,style:tle},n)}function rle(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 re.createElement("div",{id:t,style:s,role:"status","aria-live":r,"aria-atomic":!0},n)}function ale(){const[e,t]=h.useState("");return{announce:h.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const UI=h.createContext(null);function sle(e){const t=h.useContext(UI);h.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function ole(){const[e]=h.useState(()=>new Set),t=h.useCallback(r=>(e.add(r),()=>e.delete(r)),[e]);return[h.useCallback(r=>{let{type:s,event:i}=r;e.forEach(c=>{var u;return(u=c[s])==null?void 0:u.call(c,i)})},[e]),t]}const ile={draggable:`
|
|
799
799
|
To pick up a draggable item, press the space bar.
|
|
800
800
|
While dragging, use the arrow keys to move the item.
|
|
801
801
|
Press space again to drop the item in its new position, or press escape to cancel.
|
package/dist/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<link rel="icon" type="image/png" href="/favicon.png" />
|
|
7
7
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
8
8
|
<title>OWOX</title>
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-BGfJfg5u.js"></script>
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/assets/index-DOu38PCs.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.
|
|
3
|
+
"version": "0.16.0-next-20251212073834",
|
|
4
4
|
"description": "Web interface for OWOX Data Marts - an open-source solution for Data Analysts",
|
|
5
5
|
"author": "OWOX",
|
|
6
6
|
"license": "ELv2",
|
|
@@ -11,7 +11,14 @@
|
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=22.16.0"
|
|
13
13
|
},
|
|
14
|
-
"keywords": [
|
|
14
|
+
"keywords": [
|
|
15
|
+
"owox",
|
|
16
|
+
"data-marts",
|
|
17
|
+
"web-app",
|
|
18
|
+
"react",
|
|
19
|
+
"typescript",
|
|
20
|
+
"tailwind"
|
|
21
|
+
],
|
|
15
22
|
"homepage": "https://github.com/OWOX/owox-data-marts",
|
|
16
23
|
"repository": {
|
|
17
24
|
"type": "git",
|
|
@@ -22,7 +29,9 @@
|
|
|
22
29
|
"url": "https://github.com/OWOX/owox-data-marts/issues"
|
|
23
30
|
},
|
|
24
31
|
"main": "./dist/index.html",
|
|
25
|
-
"files": [
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
26
35
|
"scripts": {
|
|
27
36
|
"build": "tsc -b && vite build",
|
|
28
37
|
"dev": "vite --config vite.config.ts",
|