'use client';
import { useState } from 'react';
import { RefreshCw } from 'lucide-react';
import { ReviewIQFilterProvider, useReviewIQFilters } from '@/contexts/ReviewIQFilterContext';
import { useReviewIQAnalytics } from '@/hooks/useReviewIQAnalytics';
import { DashboardSkeleton, DashboardError, DashboardEmpty } from './DashboardSkeleton';
import { FilterBar } from './FilterBar';
import { SentimentPie } from './charts/SentimentPie';
import { IntensityHeatmap } from './charts/IntensityHeatmap';
import { TimelineChart } from './charts/TimelineChart';
import { IssuesTable } from './tables/IssuesTable';
import { SpansTable } from './tables/SpansTable';
import { OpportunityMatrix } from './insights/OpportunityMatrix';
import { ExplorerView } from './ExplorerView';
import type { URTDomain, Synthesis, LegacySynthesis } from './types';
import { isSynthesisV2 } from './types';
// Helper to extract legacy fields from either synthesis format
function getLegacyInsight(synthesis: Synthesis | null | undefined, field: keyof LegacySynthesis): string | undefined {
if (!synthesis) return undefined;
if (isSynthesisV2(synthesis)) {
// V2 doesn't have these fields, return undefined
return undefined;
}
return (synthesis as LegacySynthesis)[field] as string | undefined;
}
interface ReviewIQDashboardProps {
jobId?: string | null;
businessId?: string | null;
}
/**
* Inner dashboard component that uses the filter context.
* Shows data exploration view with charts, tables, and trend explorer.
*/
function ReviewIQDashboardInner({ jobId, businessId }: ReviewIQDashboardProps) {
const { filters, setURTDomain } = useReviewIQFilters();
const [issuesPage, setIssuesPage] = useState(1);
const [spansPage, setSpansPage] = useState(1);
const { data, loading, error, refetch } = useReviewIQAnalytics({
jobId,
businessId,
filters,
issuesPage,
issuesPageSize: 10,
spansPage,
spansPageSize: 10,
});
// No job selected
if (!jobId && !businessId) {
return
{data.overview.total_reviews.toLocaleString()} reviews ยท {data.overview.total_spans.toLocaleString()} insights