/**
 * FileBarValidationDialog — Built-in dialog for displaying validation details.
 *
 * Shows pipeline steps (3-step response flow), rule results, and failure reasons.
 */
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import { HazoUiDialog } from 'hazo_ui';
import { HiCheckCircle, HiExclamationCircle, HiMinusCircle } from 'react-icons/hi';
import { RuleResultCard } from '../rule_result_card.js';
function StatusBadge({ status }) {
    switch (status) {
        case 'passed':
            return _jsx("span", { className: "text-sm font-medium text-green-600", children: "Passed" });
        case 'failed':
            return _jsx("span", { className: "text-sm font-medium text-red-600", children: "Failed" });
        case 'validating':
            return _jsx("span", { className: "text-sm font-medium text-blue-600", children: "Validating\u2026" });
        case 'skipped':
            return _jsx("span", { className: "text-sm font-medium text-muted-foreground", children: "Skipped" });
    }
}
function StepIcon({ status }) {
    switch (status) {
        case 'passed':
            return _jsx(HiCheckCircle, { className: "h-4 w-4 text-green-500 flex-shrink-0" });
        case 'failed':
            return _jsx(HiExclamationCircle, { className: "h-4 w-4 text-red-500 flex-shrink-0" });
        case 'running':
            return (_jsxs("svg", { className: "h-4 w-4 text-blue-500 animate-spin flex-shrink-0", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [_jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), _jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }));
        case 'skipped':
            return _jsx(HiMinusCircle, { className: "h-4 w-4 text-muted-foreground/40 flex-shrink-0" });
        case 'pending':
            return _jsx("div", { className: "h-4 w-4 rounded-full border-2 border-muted-foreground/30 flex-shrink-0" });
    }
}
function PipelineStepsSection({ steps }) {
    return (_jsxs("div", { children: [_jsxs("div", { className: "text-[10px] font-semibold uppercase tracking-wide text-muted-foreground mb-2", children: ["Pipeline Steps (", steps.length, ")"] }), _jsx("div", { className: "space-y-2", children: steps.map((step) => (_jsxs("div", { className: "rounded-md border px-3 py-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(StepIcon, { status: step.status }), _jsx("span", { className: "text-sm font-medium", children: step.label }), step.status === 'running' && (_jsx("span", { className: "text-[10px] text-blue-500 italic ml-auto", children: "Running\u2026" }))] }), step.error
                            ? _jsx("p", { className: "mt-1 ml-6 text-xs text-red-600 leading-relaxed", children: step.error })
                            : step.details
                                ? _jsx("p", { className: "mt-1 ml-6 text-xs text-muted-foreground leading-relaxed", children: step.details })
                                : null] }, step.id))) })] }));
}
function RuleResultsSection({ results, responded_map, on_send_back, on_accept, file_info, on_view_file }) {
    const failed = results.filter(rr => rr.issues.length > 0 && !rr.user_resolved);
    const resolved = results.filter(rr => {
        if (rr.user_resolved)
            return true;
        if (rr.issues.length === 0)
            return false;
        return responded_map ? [...responded_map.values()].some(c => c.rule_id === rr.rule_id && (c.status === 'responded' || c.status === 'resolved')) : false;
    });
    const passed = results.filter(rr => rr.issues.length === 0 && !rr.user_resolved);
    return (_jsxs("div", { className: "space-y-4", children: [failed.length > 0 && (_jsxs("div", { children: [_jsxs("div", { className: "text-[10px] font-semibold uppercase tracking-wide text-red-600 mb-2", children: ["Checks Executed: Failed (", failed.length, ")"] }), _jsx("div", { className: "space-y-2", children: failed.map((rr, i) => (_jsx(RuleResultCard, { rr: rr, responded_map: responded_map }, rr.rule_id + '-' + i))) })] })), resolved.length > 0 && (_jsxs("div", { children: [_jsxs("div", { className: "text-[10px] font-semibold uppercase tracking-wide text-amber-600 mb-2", children: ["Checks Executed: Resolved (", resolved.length, ")"] }), _jsx("div", { className: "space-y-2", children: resolved.map((rr, i) => (_jsx(RuleResultCard, { rr: rr, responded_map: responded_map, on_send_back: on_send_back, on_accept: on_accept, file_info: file_info, on_view_file: on_view_file }, rr.rule_id + '-' + i))) })] })), passed.length > 0 && (_jsxs("div", { children: [_jsxs("div", { className: "text-[10px] font-semibold uppercase tracking-wide text-green-600 mb-2", children: ["Checks Executed: Passed (", passed.length, ")"] }), _jsx("div", { className: "space-y-2", children: passed.map((rr, i) => (_jsx(RuleResultCard, { rr: rr, responded_map: responded_map }, rr.rule_id + '-' + i))) })] }))] }));
}
export function FileBarValidationDialog({ open, on_open_change, details, responded_map, on_send_back_clarification, file_info, on_view_file, on_accept_rule, on_accept_all_rules }) {
    const [show_accept_all_confirm, set_show_accept_all_confirm] = useState(false);
    return (_jsx(HazoUiDialog, { open: open, onOpenChange: on_open_change, title: "Validation Details", description: details.file_name, cancelButtonText: "OK", sizeWidth: "64rem", children: _jsxs("div", { className: "space-y-4 text-sm", children: [details.failure_reason && (_jsx("div", { className: "rounded-md border border-red-200 bg-red-50 px-3 py-2", children: _jsx("p", { className: "text-xs text-red-700", children: details.failure_reason }) })), details.pipeline_steps && details.pipeline_steps.length > 0 && (_jsx(PipelineStepsSection, { steps: details.pipeline_steps })), details.rule_results && details.rule_results.length > 0 && (() => {
                    const pipeline_labels = new Set(details.pipeline_steps?.map(s => s.label) ?? []);
                    const filtered = details.rule_results.filter(rr => !pipeline_labels.has(rr.rule_name ?? ''));
                    return filtered.length > 0 ? _jsx(RuleResultsSection, { results: filtered, responded_map: responded_map, on_send_back: on_send_back_clarification, on_accept: on_accept_rule, file_info: file_info, on_view_file: on_view_file }) : null;
                })(), details.rule_results && on_accept_all_rules && (() => {
                    const unreviewed_resolved = details.rule_results.filter(rr => {
                        if (rr.issues.length === 0 || rr.accepted || rr.sent_back)
                            return false;
                        if (rr.user_resolved)
                            return true;
                        return responded_map ? [...responded_map.values()].some(c => c.rule_id === rr.rule_id && (c.status === 'responded' || c.status === 'resolved')) : false;
                    });
                    if (unreviewed_resolved.length < 1)
                        return null;
                    return (_jsx("div", { className: "pt-2 border-t border-border/40", children: !show_accept_all_confirm ? (_jsxs("button", { type: "button", onClick: () => set_show_accept_all_confirm(true), className: "w-full py-2 text-sm font-medium rounded-md bg-green-600 text-white hover:bg-green-700 transition-colors", children: ["Accept All (", unreviewed_resolved.length, " rule", unreviewed_resolved.length !== 1 ? 's' : '', ")"] })) : (_jsxs("div", { className: "rounded-md border border-green-200 bg-green-50 p-3 space-y-2", children: [_jsxs("p", { className: "text-sm font-medium text-green-800", children: ["Accept ", unreviewed_resolved.length, " resolved rule", unreviewed_resolved.length !== 1 ? 's' : '', "?"] }), _jsx("ul", { className: "text-xs text-green-700 space-y-0.5 pl-4 list-disc", children: unreviewed_resolved.map((rr) => (_jsx("li", { children: rr.rule_name ?? rr.rule_id }, rr.rule_id))) }), _jsxs("div", { className: "flex gap-2 justify-end pt-1", children: [_jsx("button", { type: "button", onClick: () => set_show_accept_all_confirm(false), className: "px-3 py-1.5 text-xs rounded-md border border-green-200 text-green-700 hover:bg-green-100 transition-colors", children: "Cancel" }), _jsx("button", { type: "button", onClick: () => {
                                                on_accept_all_rules(unreviewed_resolved);
                                                set_show_accept_all_confirm(false);
                                            }, className: "px-3 py-1.5 text-xs font-semibold rounded-md bg-green-600 text-white hover:bg-green-700 transition-colors", children: "Confirm" })] })] })) }));
                })(), !details.failure_reason && !details.pipeline_steps?.length && !details.rule_results?.length && details.overall_status === 'validating' && (_jsx("p", { className: "text-xs text-muted-foreground italic", children: "Validation in progress\u2026" }))] }) }));
}
//# sourceMappingURL=file_bar_validation_dialog.js.map