import{k as F,r as Q,a as L,g as U,i as W,l as i,o as n,R as G,B,U as Y,s as k,aq as I,v as A,m as Z,aH as K,aY as E,ar as X,aZ as q,a_ as ee,a$ as te}from"./entry_page.js";import{r as ae,d as V,E as $,a as z}from"./Dashboard.EnterpriseViewOnlyPreset.DHDF7xhT.js";import{S as se}from"./Search.BUYt---Z.js";import{T as ne}from"./Dashboard.DashboardPage.ktKyY7ut.js";import{m as oe,c as re,a as ie,l as le,g as H,q as ue,f as de,b as ce,d as pe,e as fe}from"./Dashboard.utils.DCnVQca0.js";import{M as O,D as _e}from"./Menu.CCGX78wV.js";import{F as T}from"./Dashboard.consts.BpCQqH5Z.js";import"./toUpper.BNt1QE2_.js";import"./ErrorBoundary.BjiCoH_C.js";import"./ChevronLeft.DxnwXrVH.js";import"./ArrowBroadUnderbarDown.Dr75X1l6.js";var ge=ae();const me=F(ge);var N={exports:{}},R;function he(){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,{default:()=>u});const j=Q();var v=r.n(j);const y=L();var c=r.n(y);const x=U;var f=r.n(x);const _=W();var g=f().p.withConfig({displayName:"ParagraphStyles__Styled",componentId:"sic5zk-0"})(["",";",";",""],_.mixins.reset("block"),_.mixins.typography("body"),(0,_.pick)({enterprise:(0,x.css)(["margin-bottom:calc("," / 2);"],_.variables.lineHeight),prisma:(0,x.css)(["margin-bottom:14px;"])}));function b(){return b=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var d in o)({}).hasOwnProperty.call(o,d)&&(e[d]=o[d])}return e},b.apply(null,arguments)}function w(e,t){if(e==null)return{};var o,d,p=S(e,t);if(Object.getOwnPropertySymbols){var m=Object.getOwnPropertySymbols(e);for(d=0;d<m.length;d++)o=m[d],t.includes(o)||{}.propertyIsEnumerable.call(e,o)&&(p[o]=e[o])}return p}function S(e,t){if(e==null)return{};var o={};for(var d in e)if({}.hasOwnProperty.call(e,d)){if(t.includes(d))continue;o[d]=e[d]}return o}var s={children:c().node,elementRef:c().oneOfType([c().func,c().object])};function a(e){var t=e.children,o=e.elementRef,d=w(e,["children","elementRef"]);return v().createElement(g,b({"data-test":"paragraph",ref:o},d),t)}a.propTypes=s;const u=a;N.exports=l})()),N.exports}var be=he();const ve=F(be),ye=k(I)`
    width: 60vw;
    height: 80vh;
    margin-top: 3vh;
`,xe=k(I.Header)`
    background-color: ${A.neutral200};
`,Se=k(I.Footer)`
    background-color: ${A.neutral200};
`,je=k(I.Body)`
    background-color: ${A.neutral200};
    padding: 15px 30px;
    height: 70vh;
`,we=k("div")`
    display: grid;
    grid-template-columns: 0.35fr 1fr;
    margin: 0px ${A.spacingSmall};

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

    .footerBtn:last-child {
        justify-self: end;
    }
`,Ce=({open:r=!1,handleRequestClose:l,title:j,acceptBtnLabel:v="Done",dataIngestionDropdownValues:y,selectValueForDropdownInModal:c,setSelectValueForDropdownInModal:x,children:f})=>{const _=n.jsx(B,{label:c,style:{minWidth:"160px"},isMenu:!0}),g=[],b=a=>y.filter(u=>u.value===a)[0],w=i.useCallback(a=>y.find(u=>u.label===a),[y]),S=b(c);g.push(n.jsxs(G.Fragment,{children:[n.jsxs(O.Item,{className:"dropdown_menu_item",children:[n.jsx(me,{style:{color:"#00A4FD",marginRight:"2px"}}),S?.label]},`selected-${S?.label}`),n.jsx(O.Divider,{},"divider")]},`selected-${S?.value}`)),y.forEach((a,u)=>{c!==a.value&&g.push(n.jsx(O.Item,{className:"dropdown_menu_item",children:a.label},`${a.label}-${u}`))});const s=i.useCallback(a=>{const u=a.target.textContent||"",e=w(u);e&&x(e.value)},[w,x]);return i.useEffect(()=>{oe()},[r]),n.jsxs(ye,{returnFocus:()=>{},open:r,onRequestClose:l,children:[n.jsx(xe,{onRequestClose:l,title:`Data ingestion details (By ${j})`}),n.jsxs(je,{children:[f,n.jsxs("div",{id:"data_ingestion_modal_dropdown","data-test":"data_ingestion_modal_dropdown",className:"invisible_before_moving",children:[n.jsx(ve,{id:"data_ingestion_dropdown_label","data-test":"data_ingestion_dropdown_label",children:j}),n.jsx(_e,{toggle:_,children:n.jsx(O,{stopScrollPropagation:!0,style:{maxHeight:"40vh",overflow:"auto",padding:"5px 0px",margin:"10px 0px"},onClick:s,children:g})})]})]}),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:v})]})})]})},De=({selectValueForDropdownInModal:r,selectTitleForDropdownInModal:l,setDataIngestionDropdownValues:j})=>{const v=i.useRef(null),y=i.useCallback(s=>{v.current=s},[]),[c,x]=i.useState(null),[f,_]=i.useState([]),g=i.useMemo(()=>Z(),[]),b=(s,a)=>{let u=[];typeof a=="string"?u=[{label:`${a} (disabled)`,value:a}]:Array.isArray(a)&&(u=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,...u]},w=(s,a)=>s.reduce((u,e)=>ue[a]===e.field?JSON.parse(e.values).map(o=>({label:o.value,value:o.value})):u,[]),S=i.useCallback(()=>{if(!c)return null;const s=JSON.parse(JSON.stringify(c));let a=[];if(l==="Input"){const t=f[0]?.results[0]?.Active,o=f[0]?.results[0]?.event_input,d=f[0]?.results[1]?.event_input;t==="yes"?a=b(o,d):t==="no"&&(a=b(d,o))}else l==="Account"?a=w(f[1]?.results||[],l):a=w(f[2]?.results||[],l);j(a);const u=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=u,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,f,l,r,j]);return i.useEffect(()=>{(async()=>{const a=await de(g);_(a)})()},[g]),i.useEffect(()=>{(async()=>{if(v.current&&c){const a=await S();a&&v.current?.updateDefinition(a)}})()},[c,r,S]),i.useEffect(()=>{le("data_ingestion_modal_definition.json",x)},[]),c?n.jsx(V.DashboardContextProvider,{preset:$,featureFlags:T,children:n.jsx(z.DashboardCore,{width:"100%",height:"auto",dashboardCoreApiRef:y,actionMenus:H("data_ingestion")})}):null},ke={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()}),$e=({dashboardDefinition:r})=>{const l=i.useRef(null),[j,v]=i.useState(""),[y,c]=i.useState(""),[x,f]=i.useState(!1),[_,g]=i.useState(null),[b,w]=i.useState(null),[S,s]=i.useState([{}]);i.useEffect(()=>{ce();const p=document.querySelector('[data-input-id="data_ingestion_table_input"] button'),m={attributes:!0},h=P=>{P.forEach(D=>{if(D.attributeName==="data-test-value"){l.current?.updateDefinition(r),v(""),f(!1);const J=D.target?.getAttribute("label");c(J||"")}D.attributeName==="aria-expanded"&&fe(D.target)})},C=new MutationObserver(h);p&&C.observe(p,m);const M=document.querySelector('[data-input-id="data_ingestion_table_input"] button')?.getAttribute("label");return c(M||""),()=>{C&&p&&C.disconnect()}},[r]);const a=i.useCallback(p=>{l.current=p},[]),u=i.useMemo(()=>K.debounce((p,m)=>{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",M=h.inputs.data_ingestion_table_input.options.items.find(D=>D.label===C),P=pe(p,m,M.value,C);h.dataSources.data_ingestion_table_ds.options.query=P,l.current?.updateDefinition(h)}},1e3),[r]),e=(p,{value:m})=>{v(m),u(m,x)},t=ke[y],o=i.useCallback(async p=>{const m=Ee.safeParse(p);if(!m.success)return;const{payload:h}=m.data;if(p.type==="datasource.done"&&p.targetId==="data_ingestion_table_ds"&&h?.data){const C=h.data?.fields[0]?.name;w(C)}p.type==="cell.click"&&p.targetId==="data_ingestion_table_viz"&&h?.cellIndex===0&&h.value&&g(h.value)},[]),d=i.useMemo(()=>({onEventTrigger:o}),[o]);return n.jsx(V.DashboardContextProvider,{preset:$,initialDefinition:r,dashboardPlugin:d,featureFlags:T,children:n.jsxs(n.Fragment,{children:[n.jsx(Ce,{open:!!_,handleRequestClose:()=>g(null),title:b||"",acceptBtnLabel:"Done",dataIngestionDropdownValues:S,selectValueForDropdownInModal:_||"",setSelectValueForDropdownInModal:g,children:n.jsx(ne.Panel,{label:"data_ingestion_modal",panelId:"dataIngestionModalDefTabPanel",children:n.jsx(De,{selectValueForDropdownInModal:_||"",selectTitleForDropdownInModal:b||"",setDataIngestionDropdownValues:s})})}),n.jsx(z.DashboardCore,{width:"100%",height:"auto",dashboardCoreApiRef:a,actionMenus:H("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:j,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(X,{appearance:"fill",type:"info",children:t})})]})})};export{$e as DataIngestionDashboard,$e as default};
