"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", "Artifact Tierlist"], ["best-stats", "Best Main Stats & Substats"], ["target-stats", "Target Stats"], ["talents", "Talent Priority"], ] as const; type ArtifactExportSection = (typeof sectionOptions)[number][0]; export function ArtifactImageExport({ children, fileName, targetConditionLabels, }: { children: ReactNode; fileName: string; targetConditionLabels: readonly string[]; }) { const [sections, setSections] = useState>( () => new Set(sectionOptions.map(([value]) => value)), ); const [targetCondition, setTargetCondition] = 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 onlySection = sections.size === 1 ? [...sections][0] : null; const exportWidth = onlySection === "target-stats" || onlySection === "talents" ? 800 : 1200; 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-grid{grid-template-columns:1fr!important}.artifact-export-left{display:grid!important;grid-template-columns:minmax(0,3fr) minmax(0,2fr);align-items:start;gap:1.25rem}.artifact-export-main-stats,.artifact-export-substats{order:initial!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 ( }> ส่งออกภาพ เลือกข้อมูลสำหรับส่งออก เลือกได้หลายส่วน หรือเลือก Entire Section เพื่อส่งออกทั้งหมด setSections( checked ? new Set(sectionOptions.map(([value]) => value)) : new Set(), )} /> Entire Section {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("target-stats") && targetConditionLabels.length > 1 ? (

Target Stats condition

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