"use client"; import Image from "@/components/ui/resilient-image"; import { DownloadIcon } from "lucide-react"; import { useState, type ReactNode } from "react"; import { GuideExportBranding } from "@/components/public/guide-export-branding"; import { ExportText, } from "@/components/public/export-language"; import { GuideImageExport } from "@/components/public/guide-image-export"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"; import type { PublicGuide } from "@/lib/guides/queries"; export type WeaponExportGuide = Pick & { character: Pick; }; export interface WeaponGroup { name: string | null; note: string | null; rows: Array<{ id: string; refinement: string; overallPercent: string | null; personalPercent: string | null; note: string | null; weapon: { name: string; imageUrl: string; }; }>; } export type DamageMetric = "overallPercent" | "personalPercent"; function formattedPercent(value: string | null): string { if (value === null) return "-%"; const numeric = Number(value); if (numeric === 0) return "-%"; return `${numeric.toLocaleString("en-US", { maximumFractionDigits: 2 })}%`; } export function WeaponComparisonImage({ guide, group, metric, conditionLabel, }: { guide: WeaponExportGuide; group: WeaponGroup; metric: DamageMetric; conditionLabel: ReactNode; }) { const values = group.rows.map((row) => Number(row[metric]) || 0); const maximum = Math.max(100, ...values); return (

{metric === "overallPercent" ? ( ) : ( )}

{conditionLabel ? (

{conditionLabel}

) : null}
{group.rows.map((row) => { const numeric = Number(row[metric]) || 0; const width = row[metric] === null ? 28 : numeric <= 100 ? Math.max(28, Math.max(0, numeric) * 0.5) : Math.min(90, 50 + ((numeric - 100) / Math.max(1, maximum - 100)) * 40); return (
{row.weapon.name} R{row.refinement}
{formattedPercent(row[metric])} {row.note ? {row.note} : null}
); })}
{group.note ? (

{group.note}

) : null}
); } export function WeaponImageExport({ guide, group, conditionIndex, }: { guide: WeaponExportGuide; group: WeaponGroup; conditionIndex: number; }) { const conditionLabel = group.name; const baseName = `${guide.name}-Weapon-${conditionLabel || `Condition ${conditionIndex + 1}`}`; const metricOptions = ([ ["overallPercent", "ดาเมจทั้งทีม"], ["personalPercent", "ดาเมจส่วนตัว"], ] as const).filter(([metric]) => group.rows.some((row) => row[metric] !== null), ); const [metric, setMetric] = useState( metricOptions[0]?.[0] ?? "overallPercent", ); const metricLabel = metric === "overallPercent" ? "Overall Damage" : "Personal Damage"; const metricOptionsControl = (

ประเภทดาเมจ

{ const next = values[0]; if (next === "overallPercent" || next === "personalPercent") setMetric(next); }} > {metricOptions.map(([value]) => ( {value === "overallPercent" ? "ดาเมจทั้งทีม" : "ดาเมจส่วนตัว"} ))}
); return ( }> บันทึกภาพ เลือกประเภทดาเมจ เลือกค่าที่ต้องการใช้สร้างภาพเปรียบเทียบอาวุธ ); }