import{g as V,r as Q,b as L,d as U,f as W,h as i,k as n,R as G,B,U as Y,q as O,a6 as I,v as N,i as K,an as X,aT as E,a7 as Z,aU as q,aV as ee,aW as te}from"./entry_page.js";import{d as F,E as $,a as T}from"./Dashboard.EnterpriseViewOnlyPreset.BFgKUBeJ.js";import{h as ae,S as se}from"./Search.oqroxkAU.js";import{T as ne}from"./Dashboard.DashboardPage.DDf7Qf5R.js";import{m as oe,c as re,a as ie,l as le,g as z,q as de,f as ue,b as ce,d as pe,e as fe}from"./Dashboard.utils.Bd0vy5_w.js";import{M as k,D as _e}from"./Menu.Co03wIjE.js";import{F as H}from"./Dashboard.consts.BpCQqH5Z.js";import"./toUpper.CSgHQ22Z.js";import"./ErrorBoundary.CMbo_g5V.js";var ge=ae();const he=V(ge);var M={exports:{}},R;function me(){return R||(R=1,(()=>{var r={};r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var l={};r.r(l),r.d(l,{StyledParagraph:()=>f,default:()=>d});const S=Q();var b=r.n(S);const y=L();var c=r.n(y);const w=U;var _=r.n(w);const v=W();var f=_().p.withConfig({displayName:"ParagraphStyles__Styled",componentId:"sic5zk-0"})(["",";",";"],v.mixins.reset("block"),v.mixins.typography("body"));function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var u in o)({}).hasOwnProperty.call(o,u)&&(e[u]=o[u])}return e},m.apply(null,arguments)}function j(e,t){if(e==null)return{};var o,u,p=x(e,t);if(Object.getOwnPropertySymbols){var g=Object.getOwnPropertySymbols(e);for(u=0;u<g.length;u++)o=g[u],t.indexOf(o)===-1&&{}.propertyIsEnumerable.call(e,o)&&(p[o]=e[o])}return p}function x(e,t){if(e==null)return{};var o={};for(var u in e)if({}.hasOwnProperty.call(e,u)){if(t.indexOf(u)!==-1)continue;o[u]=e[u]}return o}var s={children:c().node,elementRef:c().oneOfType([c().func,c().object])};function a(e){var t=e.children,o=e.elementRef,u=j(e,["children","elementRef"]);return b().createElement(f,m({"data-test":"paragraph",ref:o},u),t)}a.propTypes=s;const d=a;M.exports=l})()),M.exports}var be=me();const ye=V(be),ve=O(I)`
    width: 60vw;
    height: 80vh;
    margin-top: 3vh;
`,xe=O(I.Header)`
    background-color: ${N.neutral50};
`,Se=O(I.Footer)`
    background-color: ${N.neutral50};
    padding: 20px 40px;
`,je=O(I.Body)`
    background-color: ${N.neutral50};
    padding-right: 30px;
    height: 70vh;
`,we=O("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;
    }
`,Ce=({open:r=!1,handleRequestClose:l,title:S,acceptBtnLabel:b="Done",dataIngestionDropdownValues:y,selectValueForDropdownInModal:c,setSelectValueForDropdownInModal:w,children:_})=>{const v=n.jsx(B,{label:c,style:{minWidth:"160px"},isMenu:!0}),f=[],m=a=>y.filter(d=>d.value===a)[0],j=i.useCallback(a=>y.find(d=>d.label===a),[y]),x=m(c);f.push(n.jsxs(G.Fragment,{children:[n.jsxs(k.Item,{className:"dropdown_menu_item",children:[n.jsx(he,{style:{color:"#00A4FD",marginRight:"2px"}}),x?.label]},`selected-${x?.label}`),n.jsx(k.Divider,{},"divider")]},`selected-${x?.value}`)),y.forEach((a,d)=>{c!==a.value&&f.push(n.jsx(k.Item,{className:"dropdown_menu_item",children:a.label},`${a.label}-${d}`))});const s=i.useCallback(a=>{const d=a.target.textContent||"",e=j(d);e&&w(e.value)},[j,w]);return i.useEffect(()=>{oe()},[r]),n.jsxs(ve,{returnFocus:()=>{},open:r,onRequestClose:l,children:[n.jsx(xe,{title:`Data ingestion details (By ${S})`}),n.jsxs(je,{children:[_,n.jsxs("div",{id:"data_ingestion_modal_dropdown","data-test":"data_ingestion_modal_dropdown",className:"invisible_before_moving",children:[n.jsx(ye,{id:"data_ingestion_dropdown_label","data-test":"data_ingestion_dropdown_label",children:S}),n.jsx(_e,{toggle:v,children:n.jsx(k,{stopScrollPropagation:!0,style:{maxHeight:"40vh",overflow:"auto",padding:"5px 0px",margin:"10px 0px"},onClick:s,children:f})})]})]}),n.jsx(Se,{children:n.jsxs(we,{children:[n.jsx(B,{id:"open_search_on_visualization","data-test":"open_search_on_visualization",label:"View ingested events in search",openInNewContext:!0,onClick:()=>{const a=document.querySelector('#data_ingestion_modal_events_count_viz [data-test="open-search-button"]');a?a.click():document.querySelector('#data_ingestion_modal_data_volume_viz [data-test="open-search-button"]')?.click()}}),n.jsx(Y,{id:"done_button_footer","data-test":"done_button_footer",className:"footerBtn",onClick:l,label:b})]})})]})},De=({selectValueForDropdownInModal:r,selectTitleForDropdownInModal:l,setDataIngestionDropdownValues:S})=>{const b=i.useRef(null),y=i.useCallback(s=>{b.current=s},[]),[c,w]=i.useState(null),[_,v]=i.useState([]),f=i.useMemo(()=>K(),[]),m=(s,a)=>{let d=[];typeof a=="string"?d=[{label:`${a} (disabled)`,value:a}]:Array.isArray(a)&&(d=a.map(t=>({label:`${t} (disabled)`,value:t})));let e=[];return typeof s=="string"?e=[{label:s,value:s}]:Array.isArray(s)&&(e=s.map(t=>({label:t,value:t}))),[...e,...d]},j=(s,a)=>s.reduce((d,e)=>de[a]===e.field?JSON.parse(e.values).map(o=>({label:o.value,value:o.value})):d,[]),x=i.useCallback(()=>{if(!c)return null;const s=JSON.parse(JSON.stringify(c));let a=[];if(l==="Input"){const t=_[0]?.results[0]?.Active,o=_[0]?.results[0]?.event_input,u=_[0]?.results[1]?.event_input;t==="yes"?a=m(o,u):t==="no"&&(a=m(u,o))}else l==="Account"?a=j(_[1]?.results||[],l):a=j(_[2]?.results||[],l);S(a);const d=re(l,r,s.dataSources.ds_search_1.options.query),e=ie(l,r,s.dataSources.data_ingestion_modal_data_volume_ds.options.query);return s.dataSources.data_ingestion_modal_data_volume_ds.options.query=e,s.dataSources.ds_search_1.options.query=d,l==="Input"||l==="Account"?(delete s.visualizations.data_ingestion_modal_data_volume_viz,delete s.dataSources.data_ingestion_modal_data_volume_ds,delete s.layout.structure[2],s.layout.structure=s.layout.structure.filter(t=>t!==null),s.layout.structure[2].position.y=80):l==="Host"&&(delete s.visualizations.data_ingestion_modal_events_count_viz,delete s.dataSources.ds_search_1,delete s.layout.structure[3],s.layout.structure=s.layout.structure.filter(t=>t!==null)),s},[c,_,l,r,S]);return i.useEffect(()=>{(async()=>{const a=await ue(f);v(a)})()},[f]),i.useEffect(()=>{(async()=>{if(b.current&&c){const a=await x();a&&b.current?.updateDefinition(a)}})()},[c,r,x]),i.useEffect(()=>{le("data_ingestion_modal_definition.json",w)},[]),c?n.jsx(F.DashboardContextProvider,{preset:$,featureFlags:H,children:n.jsx(T.DashboardCore,{width:"100%",height:"auto",dashboardCoreApiRef:y,actionMenus:z("data_ingestion")})}):null},Oe={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."},Ee=E({payload:E({data:E({fields:te(E({name:q()}))}).optional(),cellIndex:ee().optional(),value:q().optional()}).optional()}),Ve=({dashboardDefinition:r})=>{const l=i.useRef(null),[S,b]=i.useState(""),[y,c]=i.useState(""),[w,_]=i.useState(!1),[v,f]=i.useState(null),[m,j]=i.useState(null),[x,s]=i.useState([{}]);i.useEffect(()=>{ce();const p=document.querySelector('[data-input-id="data_ingestion_table_input"] button'),g={attributes:!0},h=P=>{P.forEach(D=>{if(D.attributeName==="data-test-value"){l.current?.updateDefinition(r),b(""),_(!1);const J=D.target?.getAttribute("label");c(J||"")}D.attributeName==="aria-expanded"&&fe(D.target)})},C=new MutationObserver(h);p&&C.observe(p,g);const A=document.querySelector('[data-input-id="data_ingestion_table_input"] button')?.getAttribute("label");return c(A||""),()=>{C&&p&&C.disconnect()}},[r]);const a=i.useCallback(p=>{l.current=p},[]),d=i.useMemo(()=>X.debounce((p,g)=>{const h=JSON.parse(JSON.stringify(r));if(h?.inputs?.data_ingestion_table_input?.options?.items?.length>0){const C=document?.querySelector('[data-input-id="data_ingestion_table_input"] button')?.getAttribute("label")||"Source type",A=h.inputs.data_ingestion_table_input.options.items.find(D=>D.label===C),P=pe(p,g,A.value,C);h.dataSources.data_ingestion_table_ds.options.query=P,l.current?.updateDefinition(h)}},1e3),[r]),e=(p,{value:g})=>{b(g),d(g,w)},t=Oe[y],o=i.useCallback(async p=>{const g=Ee.safeParse(p);if(!g.success)return;const{payload:h}=g.data;if(p.type==="datasource.done"&&p.targetId==="data_ingestion_table_ds"&&h?.data){const C=h.data?.fields[0]?.name;j(C)}p.type==="cell.click"&&p.targetId==="data_ingestion_table_viz"&&h?.cellIndex===0&&h.value&&f(h.value)},[]),u=i.useMemo(()=>({onEventTrigger:o}),[o]);return n.jsx(F.DashboardContextProvider,{preset:$,initialDefinition:r,dashboardPlugin:u,featureFlags:H,children:n.jsxs(n.Fragment,{children:[n.jsx(Ce,{open:!!v,handleRequestClose:()=>f(null),title:m||"",acceptBtnLabel:"Done",dataIngestionDropdownValues:x,selectValueForDropdownInModal:v||"",setSelectValueForDropdownInModal:f,children:n.jsx(ne.Panel,{label:"data_ingestion_modal",panelId:"dataIngestionModalDefTabPanel",children:n.jsx(De,{selectValueForDropdownInModal:v||"",selectTitleForDropdownInModal:m||"",setDataIngestionDropdownValues:s})})}),n.jsx(T.DashboardCore,{width:"100%",height:"auto",dashboardCoreApiRef:a,actionMenus:z("data_ingestion")}),n.jsxs("div",{id:"data_ingestion_search","data-test":"data_ingestion_search",className:"invisible_before_moving",children:[n.jsx("p",{id:"data_ingestion_search_label","data-test":"data_ingestion_search_label",children:"Search"}),n.jsx(se,{id:"data_ingestion_search_input",onChange:e,value:S,style:{minWidth:"150px",gridRow:"6",gridColumn:"1"}})]}),n.jsx("div",{id:"info_message_for_data_ingestion","data-test":"info_message_for_data_ingestion",className:"invisible_before_moving",children:t&&n.jsx(Z,{appearance:"fill",type:"info",children:t})})]})})};export{Ve as DataIngestionDashboard,Ve as default};
