import { j as z, r as Y, f as K, h as X, m as s, B as V, U as Z, q as A, ai as k, v as B, k as ee, az as te, aQ as P, aj as ae, aR as $, aS as ne, aT as se } from "./publicApi-fkG2o0UD.js";
import T, { useCallback as O, useEffect as I, useRef as H, useState as D, useMemo as F } from "react";
import { r as oe, d as J, E as Q, a as L } from "./EnterpriseViewOnlyPreset-CW0maUhb.js";
import { S as re } from "./Search-DTC0iAz2.js";
import { T as ie } from "./DashboardPage-Biv7wmum.js";
import { m as le, c as de, a as ue, l as ce, g as U, q as pe, f as fe, b as _e, d as ge, e as me } from "./utils-BXswP1HG.js";
import { M as N, D as he } from "./Menu-Cnrbj5kL.js";
import { F as W } from "./consts-C-TYhRis.js";
var be = oe();
const ve = /* @__PURE__ */ z(be);
var q = { exports: {} }, R;
function ye() {
  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 i = {};
    r.r(i), r.d(i, {
      default: () => (
        /* reexport */
        l
      )
    });
    const j = T;
    var b = r.n(j);
    const v = /* @__PURE__ */ Y();
    var u = r.n(v);
    const y = K;
    var p = r.n(y);
    const f = X();
    var _ = p().p.withConfig({
      displayName: "ParagraphStyles__Styled",
      componentId: "sic5zk-0"
    })(["", ";", ";", ""], f.mixins.reset("block"), f.mixins.typography("body"), (0, f.pick)({
      enterprise: (0, y.css)(["margin-bottom:calc(", " / 2);"], f.variables.lineHeight),
      prisma: (0, y.css)(["margin-bottom:14px;"])
    }));
    function h() {
      return h = 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;
      }, h.apply(null, arguments);
    }
    function S(e, t) {
      if (e == null) return {};
      var o, d, c = x(e, t);
      if (Object.getOwnPropertySymbols) {
        var g = Object.getOwnPropertySymbols(e);
        for (d = 0; d < g.length; d++)
          o = g[d], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (c[o] = e[o]);
      }
      return c;
    }
    function x(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 n = {
      children: u().node,
      elementRef: u().oneOfType([u().func, u().object])
    };
    function a(e) {
      var t = e.children, o = e.elementRef, d = S(e, ["children", "elementRef"]);
      return b().createElement(_, h({
        "data-test": "paragraph",
        ref: o
      }, d), t);
    }
    a.propTypes = n;
    const l = a;
    q.exports = i;
  })()), q.exports;
}
var xe = ye();
const je = /* @__PURE__ */ z(xe), Se = A(k)`
    width: 60vw;
    height: 80vh;
    margin-top: 3vh;
`, we = A(k.Header)`
    background-color: ${B.neutral200};
`, De = A(k.Footer)`
    background-color: ${B.neutral200};
`, Ce = A(k.Body)`
    background-color: ${B.neutral200};
    padding: 15px 30px;
    height: 70vh;
`, Oe = A("div")`
    display: grid;
    grid-template-columns: 0.35fr 1fr;
    margin: 0px ${B.spacingSmall};

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

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