import { jsx, jsxs } from "react/jsx-runtime";
import { useEffect } from "react";
import { Box, Text } from "ink";
import { Spinner } from "@inkjs/ui";
import { useVerify } from "../hooks/useVerify.js";
import { semantic } from "../theme/palette.js";
function VerifyLine({ item }) {
  const name = item.name.padEnd(14);
  switch (item.status) {
    case "pending":
      return /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
        "  ",
        "\u25CB",
        " ",
        name
      ] });
    case "checking":
      return /* @__PURE__ */ jsxs(Box, { children: [
        /* @__PURE__ */ jsx(Text, { children: "  " }),
        /* @__PURE__ */ jsx(Spinner, { label: name })
      ] });
    case "pass":
      return /* @__PURE__ */ jsxs(Text, { children: [
        "  ",
        /* @__PURE__ */ jsx(Text, { color: semantic.ok, children: "\u2713" }),
        " ",
        name,
        /* @__PURE__ */ jsx(Text, { dimColor: true, children: item.detail })
      ] });
    case "fail":
      return /* @__PURE__ */ jsxs(Text, { children: [
        "  ",
        /* @__PURE__ */ jsx(Text, { color: semantic.warn, children: "!" }),
        " ",
        name,
        /* @__PURE__ */ jsx(Text, { color: semantic.warn, children: item.detail })
      ] });
    case "warn":
      return /* @__PURE__ */ jsxs(Text, { children: [
        "  ",
        /* @__PURE__ */ jsx(Text, { color: semantic.warn, children: "~" }),
        " ",
        name,
        /* @__PURE__ */ jsx(Text, { dimColor: true, children: item.detail })
      ] });
  }
}
function CapabilityLine({ cap }) {
  const label = cap.capability.padEnd(12);
  switch (cap.status) {
    case "pass":
      return /* @__PURE__ */ jsxs(Text, { children: [
        "  ",
        /* @__PURE__ */ jsx(Text, { color: semantic.ok, children: "\u2713" }),
        " ",
        label,
        /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
          " ",
          cap.detail
        ] })
      ] });
    case "fail":
      return /* @__PURE__ */ jsxs(Text, { children: [
        "  ",
        /* @__PURE__ */ jsx(Text, { color: semantic.err, children: "\u2717" }),
        " ",
        label,
        /* @__PURE__ */ jsxs(Text, { color: semantic.err, children: [
          " ",
          cap.detail
        ] })
      ] });
    case "skipped":
      return /* @__PURE__ */ jsxs(Text, { children: [
        "  ",
        /* @__PURE__ */ jsx(Text, { dimColor: true, children: "\u2013" }),
        " ",
        label,
        /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
          " ",
          cap.detail
        ] })
      ] });
  }
}
function McpWiringLine({ w }) {
  const label = w.agentName.padEnd(16);
  if (w.status === "pass") {
    return /* @__PURE__ */ jsxs(Text, { children: [
      "    ",
      /* @__PURE__ */ jsx(Text, { color: semantic.ok, children: "\u2713" }),
      " ",
      label,
      /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
        " ",
        w.detail
      ] })
    ] });
  }
  if (w.status === "skipped") {
    return /* @__PURE__ */ jsxs(Text, { children: [
      "    ",
      /* @__PURE__ */ jsx(Text, { dimColor: true, children: "\u2013" }),
      " ",
      label,
      /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
        " ",
        w.detail
      ] })
    ] });
  }
  return /* @__PURE__ */ jsxs(Text, { children: [
    "    ",
    /* @__PURE__ */ jsx(Text, { color: semantic.warn, children: "!" }),
    " ",
    label,
    /* @__PURE__ */ jsxs(Text, { color: semantic.warn, children: [
      " ",
      w.detail
    ] })
  ] });
}
function E2EReport({ result }) {
  return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginTop: 1, children: [
    /* @__PURE__ */ jsx(Text, { bold: true, children: "End-to-end capability check:" }),
    /* @__PURE__ */ jsx(Box, { flexDirection: "column", marginTop: 0, children: result.capabilities.map((cap) => /* @__PURE__ */ jsx(CapabilityLine, { cap }, cap.capability)) }),
    result.mcpWiringResults.length > 0 && /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginTop: 1, children: [
      /* @__PURE__ */ jsx(Text, { bold: true, dimColor: true, children: "  MCP wiring:" }),
      result.mcpWiringResults.map((w) => /* @__PURE__ */ jsx(McpWiringLine, { w }, w.agentId))
    ] }),
    /* @__PURE__ */ jsx(Box, { marginTop: 1, children: result.allPassed ? /* @__PURE__ */ jsx(Text, { color: semantic.ok, bold: true, children: "  \u2713 All capabilities confirmed" }) : /* @__PURE__ */ jsxs(Text, { color: semantic.warn, bold: true, children: [
      "  ! ",
      result.hardFailureCount,
      " capability failure(s) \u2014 see details above"
    ] }) })
  ] });
}
function Verification({ dataDir, onComplete, e2eResult }) {
  const { items, done } = useVerify(dataDir);
  useEffect(() => {
    if (done) {
      const timer = setTimeout(() => onComplete(items), 400);
      return () => clearTimeout(timer);
    }
  }, [done, items, onComplete]);
  return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", paddingX: 2, children: [
    /* @__PURE__ */ jsx(Text, { bold: true, children: "Verifying setup..." }),
    /* @__PURE__ */ jsx(Box, { flexDirection: "column", marginTop: 1, children: items.filter((i) => i.status !== "pending").map((item) => /* @__PURE__ */ jsx(VerifyLine, { item }, item.id)) }),
    done && e2eResult && /* @__PURE__ */ jsx(E2EReport, { result: e2eResult })
  ] });
}
export {
  Verification
};
//# sourceMappingURL=Verification.js.map