import{g as V,h as s,k as a,R as J,B as q,U as Q,q as w,M as k,v as N,i as L,S as T,aH as E,K as U,aI as F,aJ as W,aK as G}from"./entry_page.js";import{r as K,d as O,E as P,a as R}from"./Dashboard.EnterpriseViewOnlyPreset.hOZR46Qg.js";import{S as Y}from"./Search.CUubiSTp.js";import{T as X}from"./Dashboard.DashboardPage.DIXsiGU0.js";import{m as Z,c as ee,a as te,l as ae,g as $,q as se,f as oe,b as ne,d as ie,e as re}from"./Dashboard.utils.0p-tEVNs.js";import{M as I,D as le}from"./Menu.BxkNNSpG.js";import{x as de}from"./Search.BNBTqs0I.js";import{F as z}from"./Dashboard.consts.BpCQqH5Z.js";import"./ErrorBoundary.xJor3Ppq.js";import"./ArrowBroadUnderbarDown.wq6id2ca.js";var ue=de();const ce=V(ue);var pe=K();const _e=V(pe),fe=w(k)`
    width: 60vw;
    height: 80vh;
    margin-top: 3vh;
`,ge=w(k.Header)`
    background-color: ${N.neutral50};
`,he=w(k.Footer)`
    background-color: ${N.neutral50};
    padding: 20px 40px;
`,me=w(k.Body)`
    background-color: ${N.neutral50};
    padding-right: 30px;
    height: 70vh;
`,be=w("div")`
    display: grid;
    grid-template-columns: 0.35fr 1fr;
    width: 100%;

    .footerBtn:first-child {
        justify-self: start;
    }

    .footerBtn:last-child {
        justify-self: end;
        margin-right: 5px;
    }
`,ve=({open:l=!1,handleRequestClose:n,title:y,acceptBtnLabel:g="Done",dataIngestionDropdownValues:h,selectValueForDropdownInModal:d,setSelectValueForDropdownInModal:C,children:p})=>{const x=a.jsx(q,{label:d,style:{minWidth:"160px"},isMenu:!0}),_=[],S=e=>h.filter(o=>o.value===e)[0],j=s.useCallback(e=>h.find(o=>o.label===e),[h]),m=S(d);_.push(a.jsxs(J.Fragment,{children:[a.jsxs(I.Item,{className:"dropdown_menu_item",children:[a.jsx(ce,{style:{color:"#00A4FD",marginRight:"2px"}}),m?.label]},`selected-${m?.label}`),a.jsx(I.Divider,{},"divider")]},`selected-${m?.value}`)),h.forEach((e,o)=>{d!==e.value&&_.push(a.jsx(I.Item,{className:"dropdown_menu_item",children:e.label},`${e.label}-${o}`))});const t=s.useCallback(e=>{const o=e.target.textContent||"",u=j(o);u&&C(u.value)},[j,C]);return s.useEffect(()=>{Z()},[l]),a.jsxs(fe,{returnFocus:()=>{},open:l,onRequestClose:n,children:[a.jsx(ge,{title:`Data ingestion details (By ${y})`}),a.jsxs(me,{children:[p,a.jsxs("div",{id:"data_ingestion_modal_dropdown","data-test":"data_ingestion_modal_dropdown",className:"invisible_before_moving",children:[a.jsx(_e,{id:"data_ingestion_dropdown_label","data-test":"data_ingestion_dropdown_label",children:y}),a.jsx(le,{toggle:x,children:a.jsx(I,{stopScrollPropagation:!0,style:{maxHeight:"40vh",overflow:"auto",padding:"5px 0px",margin:"10px 0px"},onClick:t,children:_})})]})]}),a.jsx(he,{children:a.jsxs(be,{children:[a.jsx(q,{id:"open_search_on_visualization","data-test":"open_search_on_visualization",label:"View ingested events in search",openInNewContext:!0,onClick:()=>{const e=document.querySelector('#data_ingestion_modal_events_count_viz [data-test="open-search-button"]');e?e.click():document.querySelector('#data_ingestion_modal_data_volume_viz [data-test="open-search-button"]')?.click()}}),a.jsx(Q,{id:"done_button_footer","data-test":"done_button_footer",className:"footerBtn",onClick:n,label:g})]})})]})},ye=({selectValueForDropdownInModal:l,selectTitleForDropdownInModal:n,setDataIngestionDropdownValues:y})=>{const g=s.useRef(null),h=s.useCallback(t=>{g.current=t},[]),[d,C]=s.useState(null),[p,x]=s.useState([]),_=s.useMemo(()=>L(),[]),S=(t,e)=>{let o=[];typeof e=="string"?o=[{label:`${e} (disabled)`,value:e}]:Array.isArray(e)&&(o=e.map(i=>({label:`${i} (disabled)`,value:i})));let u=[];return typeof t=="string"?u=[{label:t,value:t}]:Array.isArray(t)&&(u=t.map(i=>({label:i,value:i}))),[...u,...o]},j=(t,e)=>t.reduce((o,u)=>se[e]===u.field?JSON.parse(u.values).map(b=>({label:b.value,value:b.value})):o,[]),m=s.useCallback(()=>{if(!d)return null;const t=JSON.parse(JSON.stringify(d));let e=[];if(n==="Input"){const i=p[0]?.results[0]?.Active,b=p[0]?.results[0]?.event_input,A=p[0]?.results[1]?.event_input;i==="yes"?e=S(b,A):i==="no"&&(e=S(A,b))}else n==="Account"?e=j(p[1]?.results||[],n):e=j(p[2]?.results||[],n);y(e);const o=ee(n,l,t.dataSources.ds_search_1.options.query),u=te(n,l,t.dataSources.data_ingestion_modal_data_volume_ds.options.query);return t.dataSources.data_ingestion_modal_data_volume_ds.options.query=u,t.dataSources.ds_search_1.options.query=o,n==="Input"||n==="Account"?(delete t.visualizations.data_ingestion_modal_data_volume_viz,delete t.dataSources.data_ingestion_modal_data_volume_ds,delete t.layout.structure[2],t.layout.structure=t.layout.structure.filter(i=>i!==null),t.layout.structure[2].position.y=80):n==="Host"&&(delete t.visualizations.data_ingestion_modal_events_count_viz,delete t.dataSources.ds_search_1,delete t.layout.structure[3],t.layout.structure=t.layout.structure.filter(i=>i!==null)),t},[d,p,n,l,y]);return s.useEffect(()=>{(async()=>{const e=await oe(_);x(e)})()},[_]),s.useEffect(()=>{(async()=>{if(g.current&&d){const e=await m();e&&g.current?.updateDefinition(e)}})()},[d,l,m]),s.useEffect(()=>{ae("data_ingestion_modal_definition.json",C)},[]),d?a.jsx(O.DashboardContextProvider,{preset:P,featureFlags:z,children:a.jsx(R.DashboardCore,{width:"100%",height:"auto",dashboardCoreApiRef:h,actionMenus:$("data_ingestion")})}):null},xe={Input:"Volume metrics are not available when the Input view is selected.",Account:"Volume metrics are not available when the Account view is selected.",Host:"Event metrics are not available when the Host view is selected."},Se=E({payload:E({data:E({fields:G(E({name:F()}))}).optional(),cellIndex:W().optional(),value:F().optional()}).optional()}),Ne=({dashboardDefinition:l})=>{const n=s.useRef(null),[y,g]=s.useState(""),[h,d]=s.useState(""),[C,p]=s.useState(!1),[x,_]=s.useState(null),[S,j]=s.useState(null),[m,t]=s.useState([{}]);s.useEffect(()=>{ne();const r=document.querySelector('[data-input-id="data_ingestion_table_input"] button'),f={attributes:!0},c=M=>{M.forEach(D=>{if(D.attributeName==="data-test-value"){n.current?.updateDefinition(l),g(""),p(!1);const H=D.target?.getAttribute("label");d(H||"")}D.attributeName==="aria-expanded"&&re(D.target)})},v=new MutationObserver(c);r&&v.observe(r,f);const B=document.querySelector('[data-input-id="data_ingestion_table_input"] button')?.getAttribute("label");return d(B||""),()=>{v&&r&&v.disconnect()}},[l]);const e=s.useCallback(r=>{n.current=r},[]),o=s.useMemo(()=>T.debounce((r,f)=>{const c=JSON.parse(JSON.stringify(l));if(c?.inputs?.data_ingestion_table_input?.options?.items?.length>0){const v=document?.querySelector('[data-input-id="data_ingestion_table_input"] button')?.getAttribute("label")||"Source type",B=c.inputs.data_ingestion_table_input.options.items.find(D=>D.label===v),M=ie(r,f,B.value,v);c.dataSources.data_ingestion_table_ds.options.query=M,n.current?.updateDefinition(c)}},1e3),[l]),u=(r,{value:f})=>{g(f),o(f,C)},i=xe[h],b=s.useCallback(async r=>{const f=Se.safeParse(r);if(!f.success)return;const{payload:c}=f.data;if(r.type==="datasource.done"&&r.targetId==="data_ingestion_table_ds"&&c?.data){const v=c.data?.fields[0]?.name;j(v)}r.type==="cell.click"&&r.targetId==="data_ingestion_table_viz"&&c?.cellIndex===0&&c.value&&_(c.value)},[]),A=s.useMemo(()=>({onEventTrigger:b}),[b]);return a.jsx(O.DashboardContextProvider,{preset:P,initialDefinition:l,dashboardPlugin:A,featureFlags:z,children:a.jsxs(a.Fragment,{children:[a.jsx(ve,{open:!!x,handleRequestClose:()=>_(null),title:S||"",acceptBtnLabel:"Done",dataIngestionDropdownValues:m,selectValueForDropdownInModal:x||"",setSelectValueForDropdownInModal:_,children:a.jsx(X.Panel,{label:"data_ingestion_modal",panelId:"dataIngestionModalDefTabPanel",children:a.jsx(ye,{selectValueForDropdownInModal:x||"",selectTitleForDropdownInModal:S||"",setDataIngestionDropdownValues:t})})}),a.jsx(R.DashboardCore,{width:"100%",height:"auto",dashboardCoreApiRef:e,actionMenus:$("data_ingestion")}),a.jsxs("div",{id:"data_ingestion_search","data-test":"data_ingestion_search",className:"invisible_before_moving",children:[a.jsx("p",{id:"data_ingestion_search_label","data-test":"data_ingestion_search_label",children:"Search"}),a.jsx(Y,{id:"data_ingestion_search_input",onChange:u,value:y,style:{minWidth:"150px",gridRow:"6",gridColumn:"1"}})]}),a.jsx("div",{id:"info_message_for_data_ingestion","data-test":"info_message_for_data_ingestion",className:"invisible_before_moving",children:i&&a.jsx(U,{appearance:"fill",type:"info",children:i})})]})})};export{Ne as DataIngestionDashboard,Ne as default};
