"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { useState } from "react";
import { Check, Copy, ChevronDown, Tag, Zap, TestTube2 } from "lucide-react";
import { cn } from "../../../lib/utils";
import { Button } from "../../ui/button";
import { Badge } from "../../ui/badge";
import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger
} from "../../ui/collapsible";
import { GherkinHighlighter } from "./GherkinHighlighter";
function BDDTestCard({ test, index, isOpen, onToggle, language }) {
  var _a, _b, _c;
  const [copied, setCopied] = useState(false);
  const currentScenario = ((_a = test.scenarios) == null ? void 0 : _a[language]) || ((_b = test.scenarios) == null ? void 0 : _b.en) || ((_c = test.scenarios) == null ? void 0 : _c.es) || test.scenario;
  const copyScenario = async () => {
    await navigator.clipboard.writeText(currentScenario);
    setCopied(true);
    setTimeout(() => setCopied(false), 2e3);
  };
  const getPriorityColor = (priority) => {
    switch (priority) {
      case "high":
        return "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400";
      case "medium":
        return "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400";
      case "low":
        return "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400";
      default:
        return "bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-400";
    }
  };
  const getTypeIcon = (type) => {
    switch (type) {
      case "smoke":
        return /* @__PURE__ */ jsx(Zap, { className: "h-3 w-3" });
      case "regression":
      case "integration":
      case "e2e":
        return /* @__PURE__ */ jsx(TestTube2, { className: "h-3 w-3" });
      default:
        return null;
    }
  };
  return /* @__PURE__ */ jsx(Collapsible, { open: isOpen, onOpenChange: onToggle, children: /* @__PURE__ */ jsxs(
    "div",
    {
      className: cn(
        "border rounded-lg transition-colors",
        isOpen ? "border-violet-300 dark:border-violet-700 bg-violet-50/50 dark:bg-violet-950/20" : "border-border hover:border-violet-200 dark:hover:border-violet-800"
      ),
      "data-cy": `bdd-test-${test.id}`,
      children: [
        /* @__PURE__ */ jsx(CollapsibleTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
          "button",
          {
            className: "w-full px-4 py-3 flex items-center gap-3 text-left",
            "data-cy": `bdd-test-trigger-${test.id}`,
            children: [
              /* @__PURE__ */ jsx("span", { className: "text-xs font-mono text-muted-foreground min-w-[2rem]", children: String(index + 1).padStart(2, "0") }),
              /* @__PURE__ */ jsx(
                ChevronDown,
                {
                  className: cn(
                    "h-4 w-4 text-muted-foreground transition-transform",
                    isOpen && "rotate-180"
                  )
                }
              ),
              /* @__PURE__ */ jsx("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 flex-wrap", children: [
                /* @__PURE__ */ jsx("span", { className: "font-mono text-xs text-violet-600 dark:text-violet-400", children: test.id }),
                /* @__PURE__ */ jsx("span", { className: "font-medium truncate", children: test.title })
              ] }) }),
              /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 shrink-0", children: [
                test.metadata.type && /* @__PURE__ */ jsxs(Badge, { variant: "outline", className: "text-xs gap-1", children: [
                  getTypeIcon(test.metadata.type),
                  test.metadata.type
                ] }),
                test.metadata.priority && /* @__PURE__ */ jsx(Badge, { className: cn("text-xs", getPriorityColor(test.metadata.priority)), children: test.metadata.priority })
              ] })
            ]
          }
        ) }),
        /* @__PURE__ */ jsx(CollapsibleContent, { children: /* @__PURE__ */ jsxs("div", { className: "px-4 pb-4 space-y-4", children: [
          test.metadata.tags && test.metadata.tags.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 flex-wrap", children: [
            /* @__PURE__ */ jsx(Tag, { className: "h-3 w-3 text-muted-foreground" }),
            test.metadata.tags.map((tag) => /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "text-xs", children: tag }, tag))
          ] }),
          /* @__PURE__ */ jsxs("div", { className: "relative", children: [
            /* @__PURE__ */ jsx("div", { className: "absolute top-2 right-2 z-10", children: /* @__PURE__ */ jsx(
              Button,
              {
                variant: "ghost",
                size: "sm",
                onClick: copyScenario,
                className: "h-8 px-2 text-slate-400 hover:text-slate-200",
                "data-cy": `bdd-copy-${test.id}`,
                children: copied ? /* @__PURE__ */ jsx(Check, { className: "h-4 w-4 text-green-400" }) : /* @__PURE__ */ jsx(Copy, { className: "h-4 w-4" })
              }
            ) }),
            /* @__PURE__ */ jsx(GherkinHighlighter, { code: currentScenario })
          ] }),
          test.expectedResults && test.expectedResults.length > 0 && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
            /* @__PURE__ */ jsx("h4", { className: "text-sm font-medium text-muted-foreground", children: "Expected Results" }),
            /* @__PURE__ */ jsx("ul", { className: "space-y-1", children: test.expectedResults.map((result, idx) => /* @__PURE__ */ jsxs(
              "li",
              {
                className: "flex items-start gap-2 text-sm text-muted-foreground",
                children: [
                  /* @__PURE__ */ jsx("span", { className: "text-green-500 mt-0.5", children: "\u2713" }),
                  result
                ]
              },
              idx
            )) })
          ] }),
          test.notes && /* @__PURE__ */ jsx("div", { className: "text-sm text-muted-foreground bg-muted/50 rounded-md p-3", children: test.notes })
        ] }) })
      ]
    }
  ) });
}
export {
  BDDTestCard
};
