import { useDashboards } from "@/src/hooks/useDashboard"; import { useResultDetails } from "@/src/hooks/useResultDetails"; import { ResultProps } from "@/src/types"; import { getHighlights, toTitleCase } from "@/src/utils/datas"; import { AlertCircle, ChevronLeft, ChevronRight, ExternalLink, Trophy, } from "lucide-react"; import AspectScoreInfo from "./AspectScoreInfo"; export default function ResultDetails({ result }: ResultProps) { const { activeProductIndex = 0, totalProducts = 0, nextProduct, prevProduct, } = useResultDetails({ result }) || {}; const { darkMode } = useDashboards(); if (!result || !result.details || result.details.length === 0) return null; return (
{activeProductIndex > 0 && ( )} {[...result.details] .sort((a, b) => { if (a.name === result.winning_product) return -1; if (b.name === result.winning_product) return 1; return 0; }) .map((item: any, index: number) => { if (index !== activeProductIndex) return null; const { strongest, weakest } = getHighlights(item.aspect_scores); const isPositive = item.general_score > 70; const isNegative = item.general_score < 40; let bgClass = isPositive ? "bg-sentiment-positive-light text-sentiment-positive border-sentiment-positive/20" : isNegative ? "bg-sentiment-negative-light text-sentiment-negative border-sentiment-negative/20" : "bg-sentiment-neutral-light text-sentiment-neutral border-sentiment-neutral/20"; return (
Produk {index + 1} dari {totalProducts}

{toTitleCase(item.name)}

Buka di Tokopedia
{item.verdict}

Kekuatan Utama

{strongest[0]}: {strongest[1]}%

Perlu Diperhatikan

{weakest[0]}: {weakest[1]}%

{(() => { const sortedDetails = [...result.details].sort((a, b) => { if (a.name === result.winning_product) return -1; if (b.name === result.winning_product) return 1; return 0; }); const activeItem = sortedDetails[activeProductIndex]; if (!activeItem) return null; return ( } totalReviews={activeItem.total_reviews} positiveCount={activeItem.positive_count} negativeCount={activeItem.negative_count} /> ); })()} {/*
“{item.description}”
*/}
); })} {activeProductIndex < totalProducts - 1 && ( )}
); }