import { C as S, m as e, n as C, s as D, t as R, w as q, x as y, U as M, W as I, q as j, j as F, B as $, k, l as W } from "./publicApi-fkG2o0UD.js";
import z, { useContext as V, useState as g, useRef as P, useEffect as h, memo as G, useMemo as H, useCallback as Q } from "react";
import { P as Y, B as J, l as K, k as X, T as Z, E as ee, h as ne, j as te, b as v, M as oe, m as se, u as ae, s as re, a as ie, d as le, C as w, e as ce, S as ue, f as de, g as A, i as me } from "./usePlatform-BOsxQh1R.js";
import { L as pe, E as fe } from "./ErrorBoundary-D8xyNCpV.js";
import { P as E } from "./toUpper-ubLyw1wj.js";
import { r as ge } from "./ArrowBroadUnderbarDown-Cu2cQQV9.js";
const xe = ({ tab: n }) => {
  const c = V(S), [o, u] = g(!0), r = P(null), p = () => new Promise((s) => {
    const d = n?.customTab?.src ? c?.[n?.customTab?.src] : void 0;
    if (d?.type === "tab") {
      const i = d.component;
      s(i);
    } else n.customTab?.type === "external" && import(
      /* @vite-ignore */
      `${D()}/custom/${n.customTab.src}.js`
    ).then((i) => {
      const m = i.default;
      s(m);
    });
  });
  return h(() => {
    p().then((s) => {
      r.current && (new s(n, r.current).render(), u(!1));
    });
  }, []), /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
    o && C._("Loading..."),
    /* @__PURE__ */ e.jsx("div", { ref: r, style: { visibility: o ? "hidden" : "visible" } })
  ] });
}, Ce = j.div`
    margin-left: 270px !important;
    width: 150px;
`;
function O({ serviceName: n }) {
  const c = P(), [o, u] = g(null), [r, p] = g(!1), [s, d] = g({});
  h(() => {
    const a = new AbortController();
    return R({
      endpointUrl: q(`settings/${encodeURIComponent(n)}`),
      handleError: !0,
      signal: a.signal,
      callbackOnError: (l) => {
        a.signal.aborted || u(l);
      }
    }).catch((l) => {
      if (a.signal.aborted)
        return null;
      throw l;
    }).then((l) => {
      l && d(l.entry[0].content);
    }), () => {
      a.abort();
    };
  }, [n]);
  const i = (a) => {
    c.current.handleSubmit(a);
  }, m = (a) => {
    p(a);
  };
  if (o)
    throw o;
  return Object.keys(s).length ? /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
    /* @__PURE__ */ e.jsx(S.Consumer, { children: (a) => /* @__PURE__ */ e.jsx(Y.Consumer, { children: (l) => /* @__PURE__ */ e.jsx(
      J,
      {
        ref: c,
        page: y,
        stanzaName: n,
        serviceName: "settings",
        mode: K,
        currentServiceState: s,
        handleFormSubmit: m,
        pageContext: l,
        customComponentContext: a
      }
    ) }) }),
    /* @__PURE__ */ e.jsx(Ce, { children: /* @__PURE__ */ e.jsx(
      M,
      {
        className: "saveBtn",
        label: C._("Save"),
        onClick: i,
        loading: r
      }
    ) })
  ] }) : /* @__PURE__ */ e.jsx(I, { size: "medium" });
}
O.propTypes = {
  serviceName: E.string.isRequired
};
function U({ selectedTab: n, updateIsPageOpen: c }) {
  const [o, u] = g({ open: !1 }), r = n.style === X;
  h(() => {
    r && c(!!o.open);
  }, [c, r, o]);
  const p = () => {
    u({
      ...o,
      open: !0,
      mode: v,
      formLabel: n.formTitle ? `Add ${n.formTitle}` : `Add ${n.title}`
    });
  }, s = () => {
    u({ ...o, open: !1 });
  }, d = () => /* @__PURE__ */ e.jsx(
    te,
    {
      page: y,
      open: o.open,
      handleRequestClose: s,
      returnFocus: () => {
      },
      serviceName: n.name,
      mode: v,
      formLabel: o.formLabel
    }
  ), i = (b, T) => {
    const f = n?.formTitle || n.title;
    u({
      ...o,
      open: !0,
      stanzaName: b.name,
      formLabel: T === oe ? `Clone ${f}` : `Update ${f}`,
      mode: T
    });
  }, m = () => {
    u({ ...o, open: !1 });
  }, a = () => /* @__PURE__ */ e.jsx(
    ee,
    {
      open: o.open,
      handleRequestClose: m,
      serviceName: n.name,
      stanzaName: o.stanzaName,
      mode: o.mode,
      formLabel: o.formLabel,
      page: y
    }
  ), l = () => /* @__PURE__ */ e.jsx(
    "div",
    {
      style: r && o.open ? { display: "none" } : { display: "block" },
      children: /* @__PURE__ */ e.jsx(
        ne,
        {
          page: y,
          serviceName: n.name,
          handleRequestModalOpen: () => p(),
          handleOpenPageStyleDialog: i
        }
      )
    }
  );
  return /* @__PURE__ */ e.jsxs(Z, { value: null, children: [
    r && o.open && a(),
    l(),
    !r && o.open && d()
  ] });
}
U.propTypes = {
  selectedTab: E.object,
  updateIsPageOpen: E.func
};
const he = G(U);
var je = ge();
const be = /* @__PURE__ */ F(je);
function ye(n) {
  return /* @__PURE__ */ e.jsx(
    $,
    {
      target: "_blank",
      to: n.fileUrl,
      download: n.fileNameAfterDownload,
      "data-test": "downloadButton",
      icon: /* @__PURE__ */ e.jsx(be, {}),
      children: n.children
    }
  );
}
const we = D().replace("js/build", "openapi.json");
function Te() {
  return /* @__PURE__ */ e.jsx(ye, { fileUrl: we, fileNameAfterDownload: "openapi.json", children: "OpenAPI.json" });
}
const Ee = j(se.Typography)`
    font-size: 0.8em;
`, Pe = () => {
  const n = k();
  if (n?.meta?.hideUCCVersion)
    return null;
  const c = n?.meta?._uccVersion ?? null;
  return /* @__PURE__ */ e.jsxs(
    Ee,
    {
      as: "span",
      title: "Splunk Add-On UCC framework is a framework to generate UI-based Splunk add-ons. It includes UI, REST handlers, Modular inputs, OAuth and Alert action templates.",
      "data-test": "ucc-credit",
      children: [
        "Made with",
        " ",
        /* @__PURE__ */ e.jsx(pe, { to: "https://splunk.github.io/addonfactory-ucc-generator/", openInNewContext: !0, children: "UCC" }),
        " ",
        c
      ]
    }
  );
}, ve = j.div`
    display: inline-flex;
    align-items: center;
    justify-content: end;
    flex-wrap: wrap;
    gap: 0.4rem;
`, Se = j(w.Row)`
    padding: 5px 0px;

    .dropdown {
        text-align: right;
    }

    .input_button {
        text-align: right;
        margin-right: 0px;
    }
`, De = j(A)`
    flex-wrap: wrap;
`;
function _e() {
  const n = k();
  W(n.pages.configuration, "Configuration page not found in global config");
  const { title: c, description: o, subDescription: u, tabs: r } = n.pages.configuration, p = ae(n, "configuration"), s = r.filter(
    (t) => !re(t.hideForPlatform, p)
  ), d = H(() => s.map((t) => t.name), [s]), i = P(!1), [m, a] = g(s[0].name), [l, b] = g(!1), f = ie()?.get("tab");
  h(() => {
    f && d.includes(f) && f !== m && a(f);
  }, [f, d, m]), h(() => (i.current = !0, () => {
    i.current = !1;
  }), []);
  const B = Q((t, { selectedTabId: x }) => {
    i.current && x && (a(x), b(!1));
  }, []), N = (t) => {
    i.current && b(t);
  }, _ = (t) => z.createElement(xe, { tab: t }), L = (t) => {
    let x;
    return t?.customTab ? x = _(t) : x = t?.table ? /* @__PURE__ */ e.jsx(
      he,
      {
        selectedTab: t,
        updateIsPageOpen: N
      },
      t.name
    ) : /* @__PURE__ */ e.jsx(O, { serviceName: t.name }, t.name), /* @__PURE__ */ e.jsx(
      "div",
      {
        style: t.name !== m ? { display: "none" } : { display: "block" },
        id: `${t.name}Tab`,
        children: x
      },
      t.name
    );
  };
  return /* @__PURE__ */ e.jsx(fe, { children: /* @__PURE__ */ e.jsxs(le, { platform: p, children: [
    /* @__PURE__ */ e.jsxs("div", { style: l ? { display: "none" } : { display: "block" }, children: [
      /* @__PURE__ */ e.jsx(w, { gutter: 8, children: /* @__PURE__ */ e.jsxs(Se, { children: [
        /* @__PURE__ */ e.jsxs(w.Column, { span: 9, children: [
          /* @__PURE__ */ e.jsx(ce, { children: C._(c) }),
          /* @__PURE__ */ e.jsx(ue, { children: C._(o || "") }),
          /* @__PURE__ */ e.jsx(
            de,
            {
              text: u?.text || "",
              links: u?.links
            }
          )
        ] }),
        /* @__PURE__ */ e.jsx(w.Column, { span: 3, style: { textAlignLast: "right" }, children: /* @__PURE__ */ e.jsxs(ve, { children: [
          /* @__PURE__ */ e.jsx(Pe, {}),
          /* @__PURE__ */ e.jsx(Te, {})
        ] }) })
      ] }) }),
      /* @__PURE__ */ e.jsx(De, { activeTabId: m, onChange: B, children: s.map((t) => /* @__PURE__ */ e.jsx(A.Tab, { label: C._(t.title), tabId: t.name }, t.name)) })
    ] }),
    s.map((t) => L(t)),
    /* @__PURE__ */ e.jsx(me, { position: "top-right" })
  ] }) });
}
export {
  _e as default
};
