import { useI18n } from "../i18n"; import type { ReactNode } from "react"; import { Card, CardContent, CardHeader } from "../components/ui/card"; import { Badge } from "../components/ui/badge"; import type { CtePlanCte, CtePlanFilter, CtePlanV2 } from "./artifactV2"; const CHIP = "min-w-0 max-w-full whitespace-pre-wrap [overflow-wrap:anywhere] rounded-md bg-muted px-1.5 py-0.5 font-mono text-xs text-foreground/90"; const FIELD_LABEL = "text-xs font-semibold text-muted-foreground"; function Chip({ children }: { children: ReactNode }) { return {children}; } function FilterRow({ filter, index }: { filter: CtePlanFilter; index: number }) { const { t } = useI18n(); return (

{t("Column")}

{filter.column}

{t("Operator")}

{filter.op}

{t("Value")}

{filter.value}
{(filter.description || filter.rationale) && (
{filter.description && ( <> {t("Description")}

{filter.description}

)} {filter.rationale && ( <> {t("Rationale")}

{filter.rationale}

)}
)}
); } function CteCard({ cte, total }: { cte: CtePlanCte; total: number }) { const { t } = useI18n(); const dependsOn = cte.depends_on ?? []; return (
CTE {cte.index}/{total}

{cte.name}

{cte.purpose && (

{cte.purpose}

)}

{t("Depends on")}

{dependsOn.length ? (
{dependsOn.map((dependency) => ( {dependency} ))}
) : (

{t("No dependencies")}

)}
{cte.keys && cte.keys.length > 0 && (

{t("Keys")}

{cte.keys.map((key) => ( {key} ))}
)}
{cte.tables && cte.tables.length > 0 && (

{t("Tables")}

{cte.tables.map((table) => (
{table.name} {table.description && (

{table.description}

)}
))}
)} {cte.filters && cte.filters.length > 0 && (

{t("Filters")}

{cte.filters.map((f, i) => ( ))}
)} {cte.output_columns && cte.output_columns.length > 0 && (

{t("Output columns")}

{cte.output_columns.map((column) => ( {column} ))}
)} {cte.rationale && (

{t("Rationale")}

{cte.rationale}

)}
); } export function CtePlanViewer({ plan }: { plan: CtePlanV2 }) { const { t } = useI18n(); return (
{plan.question && (

{t("Question")}

{plan.question}

)} {plan.strategy && (

{t("Strategy")}

{plan.strategy}

)}

{t("Execution order")}

{plan.ctes.map((c, i) => ( {i > 0 && } {c.name} ))}
    {plan.ctes.map((cte) => (
  1. ))}
); }