"use client"; import { useState, type ReactNode } from "react"; import { DownloadIcon } from "lucide-react"; import { GuideImageExport } from "@/components/public/guide-image-export"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"; import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"; const sectionOptions = [ ["tierlist", "อันดับอาร์ติแฟกต์"], ["best-stats", "ออฟหลักและออฟรองที่ดีที่สุด"], ["target-stats", "ค่าสถานะเป้าหมาย"], ["talents", "ลำดับการอัพพรสวรรค์"], ] as const; type ArtifactExportSection = (typeof sectionOptions)[number][0]; export function ArtifactImageExport({ children, fileName, hasNote, targetConditionLabels, recommendedConditionLabels, tierConditionLabels, }: { children: ReactNode; fileName: string; hasNote: boolean; targetConditionLabels: readonly string[]; recommendedConditionLabels: readonly string[]; tierConditionLabels: readonly string[]; }) { const [sections, setSections] = useState>( () => new Set(sectionOptions.map(([value]) => value)), ); const [recommendedCondition, setRecommendedCondition] = useState("0"); const [targetCondition, setTargetCondition] = useState("0"); const [tierCondition, setTierCondition] = useState("0"); const entireSection = sections.size === sectionOptions.length; const hiddenSections = sectionOptions .filter(([value]) => !sections.has(value)) .map(([value]) => `[data-artifact-export-section="${value}"]{display:none!important}`) .join(""); const targetRule = `[data-target-condition]:not([data-target-condition="${targetCondition}"]){display:none!important}`; const recommendedRule = `[data-recommended-condition]:not([data-recommended-condition="${recommendedCondition}"]){display:none!important}`; const tierRule = `[data-tier-condition]:not([data-tier-condition="${tierCondition}"]){display:none!important}`; const onlySection = sections.size === 1 ? [...sections][0] : null; const exportWidth = onlySection === "best-stats" ? 700 : onlySection === "target-stats" || onlySection === "talents" ? 800 : 1200; const exportHeight = onlySection === "best-stats" ? 700 : undefined; const hideEmptyRightColumn = !hasNote && !sections.has("target-stats") && !sections.has("talents") ? ".artifact-export-right{display:none!important}" : ""; const layoutRules = onlySection === "tierlist" ? ".artifact-export-grid{grid-template-columns:1fr!important}.artifact-export-tierlist{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr));gap:1.25rem}" : onlySection === "best-stats" ? ".artifact-export-root{height:100%!important}.artifact-export-grid{grid-template-columns:1fr!important}.artifact-export-left{display:flex!important;flex-direction:column!important}.artifact-export-main-stats,.artifact-export-substats{width:480px!important;max-width:100%!important;margin-inline:auto!important}.artifact-export-main-stats{order:1!important}.artifact-export-substats{order:2!important}.artifact-export-right{width:100%!important}.guide-export-watermark{top:auto!important;bottom:16px!important}" : onlySection === "target-stats" || onlySection === "talents" ? ".artifact-export-grid{display:block!important}.artifact-export-right{width:560px!important;max-width:100%;margin-left:auto!important;margin-right:auto!important;justify-self:center!important}" : ""; return ( }> ส่งออกภาพ เลือกข้อมูลสำหรับส่งออก เลือกได้หลายส่วน หรือเลือกทั้งหมดเพื่อส่งออกทุกส่วน setSections( checked ? new Set(sectionOptions.map(([value]) => value)) : new Set(), )} /> ทั้งหมด {sectionOptions.map(([value, label]) => ( { setSections((current) => { const next = new Set(current); if (checked) next.add(value); else next.delete(value); return next; }); }} /> {label} ))} {sections.has("best-stats") && recommendedConditionLabels.length > 1 ? (

เงื่อนไขค่าสถานะแนะนำ

{ if (values[0]) setRecommendedCondition(values[0]); }} > {recommendedConditionLabels.map((label, index) => ( {label} ))}
) : null} {sections.has("tierlist") && tierConditionLabels.length > 1 ? (

เงื่อนไขอันดับอาร์ติแฟกต์

{ if (values[0]) setTierCondition(values[0]); }}> {tierConditionLabels.map((label, index) => {label})}
) : null} {sections.has("target-stats") && targetConditionLabels.length > 1 ? (

เงื่อนไขค่าสถานะเป้าหมาย

{ if (values[0]) setTargetCondition(values[0]); }} > {targetConditionLabels.map((label, index) => ( {label} ))}
) : null} {children}
); }