"use client";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { useMemo } from "react";
import { cn } from "../../../lib/utils";
function GherkinHighlighter({ code, className }) {
  const tokenizedLines = useMemo(() => {
    return code.split("\n").map((line) => {
      const trimmed = line.trim();
      const keywordPatterns = [
        { pattern: /^(Given)\s+/i, type: "given" },
        { pattern: /^(When)\s+/i, type: "when" },
        { pattern: /^(Then)\s+/i, type: "then" },
        { pattern: /^(And)\s+/i, type: "and" },
        { pattern: /^(But)\s+/i, type: "but" },
        { pattern: /^(Scenario(?:\s+Outline)?:?)\s*/i, type: "scenario" },
        { pattern: /^(Feature:)\s*/i, type: "feature" },
        { pattern: /^(Background:)\s*/i, type: "background" }
      ];
      for (const { pattern, type } of keywordPatterns) {
        const match = trimmed.match(pattern);
        if (match) {
          return {
            keyword: match[1],
            keywordType: type,
            content: trimmed.slice(match[0].length)
          };
        }
      }
      return { content: line };
    });
  }, [code]);
  const getKeywordColor = (type) => {
    switch (type) {
      case "given":
        return "text-blue-500 dark:text-blue-400";
      case "when":
        return "text-green-500 dark:text-green-400";
      case "then":
        return "text-purple-500 dark:text-purple-400";
      case "and":
      case "but":
        return "text-slate-500 dark:text-slate-400";
      case "scenario":
      case "feature":
      case "background":
        return "text-orange-500 dark:text-orange-400";
      default:
        return "";
    }
  };
  return /* @__PURE__ */ jsx(
    "pre",
    {
      className: cn(
        "bg-slate-900 dark:bg-slate-950 rounded-lg p-4 overflow-x-auto text-sm font-mono",
        className
      ),
      children: /* @__PURE__ */ jsx("code", { children: tokenizedLines.map((line, index) => /* @__PURE__ */ jsx("div", { className: "leading-relaxed", children: line.keyword ? /* @__PURE__ */ jsxs(Fragment, { children: [
        /* @__PURE__ */ jsx("span", { className: cn("font-semibold", getKeywordColor(line.keywordType)), children: line.keyword }),
        /* @__PURE__ */ jsxs("span", { className: "text-slate-300 dark:text-slate-200", children: [
          " ",
          highlightParameters(line.content)
        ] })
      ] }) : /* @__PURE__ */ jsx("span", { className: "text-slate-400 dark:text-slate-500", children: line.content || "\xA0" }) }, index)) })
    }
  );
}
function highlightParameters(text) {
  const parts = text.split(/(".*?"|<\w+>)/g);
  return parts.map((part, index) => {
    if (part.startsWith('"') && part.endsWith('"')) {
      return /* @__PURE__ */ jsx("span", { className: "text-amber-400 dark:text-amber-300", children: part }, index);
    }
    if (part.startsWith("<") && part.endsWith(">")) {
      return /* @__PURE__ */ jsx("span", { className: "text-cyan-400 dark:text-cyan-300 italic", children: part }, index);
    }
    return part;
  });
}
export {
  GherkinHighlighter
};
