"use client";
import { AlertTriangle, Zap, HelpCircle, CheckCircle } from "lucide-react";
import clsx from "clsx";
interface ProcessFlowProps {
data: any;
simulated?: any;
}
import { InfoTooltip } from "@/components/ui/tooltip";
export function ProcessFlow({ data, simulated }: ProcessFlowProps) {
if (!data || !data.intelligence) return
Loading intelligence...
;
const {
waterfall, norm_adequacy, intervention_roi, yield_rate, break_even_tolerance,
blame_breakdown, elasticity, false_yield_warning, safety_recommendation,
po_imbalance, min_charge_distortion, risk_fingerprint
} = data.intelligence;
const hasShortfall = data.metrics['Shortfall'] > 0;
const maxValue = Math.max(...waterfall.map((w: any) => Math.abs(w.value))) * 1.2;
return (
{/* SUCCESS BANNER - Only show when fulfilled */}
{!hasShortfall && (
Order Fulfilled
Surplus: +{Math.round(Math.abs(data.metrics['Shortfall']))}m
)}
{/* FALSE YIELD WARNING BANNER - Only when there's a shortfall */}
{hasShortfall && false_yield_warning && (
False Yield Alert:
High yield ({yield_rate}%) but insufficient delivery ({norm_adequacy}%)
)}
{/* 1. Policy Intelligence Header */}
Norm Score
{norm_adequacy}%
Production Efficiency
{yield_rate}%
Total
{data.metrics?.["Fresh Yield %"] !== undefined && (
{data.metrics["Fresh Yield %"]}%
Fresh Yield
)}
Elasticity
{elasticity.classification}
{elasticity.value}
Intervention ROI
{intervention_roi}
{/* Only show Safety Needed when there's a shortfall */}
{hasShortfall && (
Safety Needed
+{safety_recommendation.value}%
{safety_recommendation.confidence_low}-{safety_recommendation.confidence_high}%
)}
{/* 2. BLAME BREAKDOWN - Only show when there's a shortfall */}
{hasShortfall && (
Shortfall Responsibility Breakdown
{blame_breakdown.policy_pct > 15 && `${blame_breakdown.policy_pct}%`}
{blame_breakdown.execution_pct > 15 && `${blame_breakdown.execution_pct}%`}
{blame_breakdown.process_pct > 15 && `${blame_breakdown.process_pct}%`}
■ Policy {blame_breakdown.policy_pct}%
■ Execution {blame_breakdown.execution_pct}%
■ Process {blame_breakdown.process_pct}%
{blame_breakdown.policy_pct > 70 && (
⚠️ {Math.round(blame_breakdown.policy_pct)}% of shortfall is policy-driven. Operators did NOT cause this loss.
)}
)}
{/* 3. Loss Waterfall Visual */}
{hasShortfall ? "Loss Waterfall" : "Material Flow"}
{waterfall.map((step: any, i: number) => {
const isNegative = step.value < 0;
const maxValue = Math.max(...waterfall.map((w: any) => Math.abs(w.value)));
const width = Math.min(100, (Math.abs(step.value) / maxValue) * 100);
return (
{step.label}
{step.value > 0 && step.type !== 'base' ? '+' : ''}{Math.round(step.value)}m
{step.desc}
)
})}
{/* 5. PO IMBALANCE WARNING */}
{po_imbalance?.detected && (
Uneven PO Norm Allocation Detected
StdDev of Norm Gap: {po_imbalance.stddev}% across {po_imbalance.details?.length || 0} POs
{min_charge_distortion && (
⚠️ Possible Minimum Charge Distortion
)}
)}
);
}