"use client"; import { Bar, BarChart, CartesianGrid, LabelList, ReferenceLine, XAxis, YAxis } from "recharts"; import Image from "@/components/ui/resilient-image"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, type ChartConfig, } from "@/components/ui/chart"; import type { PublicGuide } from "@/lib/guides/queries"; const chartConfig = { overall: { label: "ดาเมจทั้งทีม", color: "var(--chart-1)" }, personal: { label: "ดาเมจส่วนตัว", color: "var(--chart-2)" }, } satisfies ChartConfig; function percentage(value: string | null) { if (!value?.trim()) return null; const number = Number(value); return Number.isFinite(number) && number !== 0 ? number : null; } export function WeaponChart({ rows }: { rows: PublicGuide["weaponGroups"][number]["rows"] }) { const data = rows.map((row, index) => ({ name: `${index + 1}. ${row.weapon.name} R${row.refinement}`, weapon: row.weapon, refinement: row.refinement, overall: percentage(row.overallPercent), personal: percentage(row.personalPercent), })); const hasOverall = data.some((row) => row.overall !== null); const hasPersonal = data.some((row) => row.personal !== null); const singleMetric = !hasOverall || !hasPersonal; if (!hasOverall && !hasPersonal) return

ไม่มีข้อมูลเปรียบเทียบสำหรับกราฟนี้

; return เปรียบเทียบดาเมจอาวุธ เปอร์เซ็นต์ดาเมจในเงื่อนไขนี้ - เส้น 100% คือค่าฐาน Math.min(0, minimum), (maximum: number) => Math.max(110, maximum)]} tickFormatter={(value) => `${value}%`} /> { const row = data.find((item) => item.name === payload.value); if (!row) return ; const scale = Math.min(1, Math.max(0, Number(width) / data.length - 4) / 56); return
{row.weapon.name} R{row.refinement}
; }} />
{chartConfig[name as keyof typeof chartConfig]?.label ?? name} {value}%
} />} /> } /> {hasPersonal && typeof value === "number" ? `${value.toLocaleString("th-TH", { maximumFractionDigits: 2 })}%` : ""} className="fill-foreground text-xs" /> } {hasOverall && typeof value === "number" ? `${value.toLocaleString("th-TH", { maximumFractionDigits: 2 })}%` : ""} className="fill-foreground text-xs" /> }
; }