"use client"; import { useMemo, useState } from "react"; import { BookOpenIcon, CheckIcon, ChevronsUpDownIcon } from "lucide-react"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; import { Field, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { importGuideTeam, type TeamGuide, type TeamGuideTeam } from "@/lib/team-guides"; import { rarityGradientClass } from "@/lib/catalog-rarity"; import { cn } from "@/lib/utils"; import type { Catalog, Team } from "@/lib/translator/types"; function GuideCharacter({ guide, catalog }: { guide: TeamGuide; catalog: Catalog }) { const character = catalog.characters.find((item) => item.id === guide.characterId); return {character?.name.slice(0, 1) ?? guide.name.slice(0, 1)}; } function GuidePicker({ guides, catalog, value, onChange }: { guides: TeamGuide[]; catalog: Catalog; value: string; onChange: (id: string) => void }) { const [open, setOpen] = useState(false); const selected = guides.find((guide) => guide.id === value); return }> {selected && }{selected?.name ?? "Choose guide"} No matching guide.{guides.map((guide) => { onChange(guide.id); setOpen(false); }}>{guide.name}{guide.teams.length})} ; } function TeamCharacters({ team, catalog }: { team: TeamGuideTeam; catalog: Catalog }) { return
{team.members.map((member) => { const character = catalog.characters.find((item) => item.id === member.characterId); return {character?.name.slice(0, 1) ?? "?"}; })}
; } function TeamPicker({ groups, team, catalog, onChange }: { groups: [string, TeamGuideTeam[]][]; team: TeamGuideTeam | undefined; catalog: Catalog; onChange: (id: string) => void }) { const [open, setOpen] = useState(false); return }> {team ? <>{team.title} : Choose team} No matching team.{groups.map(([label, teams]) => {teams.map((item) => { const characterNames = item.members.map((member) => catalog.characters.find((character) => character.id === member.characterId)?.name).filter(Boolean).join(" "); return { onChange(item.id); setOpen(false); }}>{item.title}; })})} ; } export function ImportTeamGuideDialog({ catalog, guides, disabled, onImport }: { catalog: Catalog; guides: TeamGuide[]; disabled: boolean; onImport: (team: Team) => void }) { const [open, setOpen] = useState(false); const [guideId, setGuideId] = useState(guides[0]?.id ?? ""); const guide = guides.find((item) => item.id === guideId) ?? guides[0]; const [teamId, setTeamId] = useState(guide?.teams[0]?.id ?? ""); const team = guide?.teams.find((item) => item.id === teamId) ?? guide?.teams[0]; const preview = useMemo(() => team ? importGuideTeam(team, catalog) : undefined, [team, catalog]); const groups = useMemo(() => { const result = new Map["teams"]>(); for (const item of guide?.teams ?? []) { const label = item.conditionName?.trim() || "Teams"; result.set(label, [...(result.get(label) ?? []), item]); } return [...result.entries()]; }, [guide]); const chooseGuide = (id: string) => { const next = guides.find((item) => item.id === id); setGuideId(id); setTeamId(next?.teams[0]?.id ?? ""); }; return }>IMPORT FROM BUZZ GUIDE Import from Buzz GuideChoose a public guide team to import its characters, weapons, artifacts, constellations, refinements, and combo. Guide{guide?.teams.length ?? 0} teams available. Team {preview?.error && Cannot import this team{preview.error}} {preview?.team && <> Loadout preview
{preview.team.builds.map((build) =>
{build.characterName.slice(0, 1)}

{build.characterName} C{build.constellation}

{build.weaponName} R{build.refinement}

{build.artifactOneName}{build.artifactTwoName ? ` + ${build.artifactTwoName}` : " ยท 4pc"}

)}
{team?.combo.trim() && team.combo.trim() !== "-" && {preview.team.rotation?.enabled ? "Combo will be included" : "Combo saved as reference"}{preview.team.rotation?.enabled ? "The guide combo is valid shorthand and will be enabled." : "The combo uses unsupported guide notation, so it will be preserved with rotation disabled."}} }
}>Cancel
; }