"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { memo, useCallback } from "react";
import { cn } from "@stigmer/theme";
import { usePendingApprovals } from "../workflow/usePendingApprovals";
import { PendingApprovalsWidget } from "../workflow/PendingApprovalsWidget";
import { useDashboardSummary } from "./useDashboardSummary";
import { useDashboardFailedRuns } from "./useDashboardFailedRuns";
import { DashboardKPICards } from "./DashboardKPICards";
import { DashboardFailedRuns } from "./DashboardFailedRuns";
/**
 * Composed dashboard widget that aggregates operational metrics from both
 * agent and workflow domains into a unified platform view.
 *
 * Layout:
 * - Row 1: KPI stat cards (Active | Completed | Failed | Total Cost)
 * - Row 2: Pending Approvals | Recent Failures (2-column grid)
 *
 * Cost comes from the billing source of truth (`getOrgUsageReport`),
 * not from summing agent + workflow costs. See AD-DASH-005.
 *
 * @example
 * ```tsx
 * <OperationalDashboard
 *   org="acme"
 *   orgId={activeOrg?.metadata?.id}
 *   onApprovalClick={(id) => navigate(`/executions/${id}`)}
 *   onFailedRunClick={(id, type) => navigate(`/executions/${id}`)}
 * />
 * ```
 *
 * @since Unified Platform Dashboard
 */
export const OperationalDashboard = memo(function OperationalDashboard({ org, orgId, onApprovalClick, onFailedRunClick, className, }) {
    const summaryOptions = {
        org,
        orgId,
        refetchInterval: 60_000,
    };
    const { summary, isLoading: summaryLoading } = useDashboardSummary(summaryOptions);
    const { approvals, totalCount: approvalCount, isLoading: approvalsLoading } = usePendingApprovals({ org, refetchInterval: 30_000 });
    const { failedRuns, isLoading: failedLoading } = useDashboardFailedRuns(org);
    const handleFailedRunClick = useCallback((id, type) => {
        onFailedRunClick?.(id, type);
    }, [onFailedRunClick]);
    return (_jsxs("section", { "aria-label": "Platform dashboard", className: cn("space-y-6", className), children: [_jsx(DashboardKPICards, { summary: summary, isLoading: summaryLoading }), _jsxs("div", { className: "grid gap-6 lg:grid-cols-2", children: [_jsx(PendingApprovalsWidget, { approvals: approvals, totalCount: approvalCount, isLoading: approvalsLoading, onReviewClick: onApprovalClick }), _jsx(DashboardFailedRuns, { failedRuns: failedRuns, isLoading: failedLoading, onViewClick: handleFailedRunClick })] })] }));
});
//# sourceMappingURL=OperationalDashboard.js.map