"use client"; import Image from "@/components/ui/resilient-image"; import Link from "next/link"; import { useEffect, useMemo, useRef, useState, type ReactNode } from "react"; import { CopyIcon, GripVerticalIcon, PlusIcon, Trash2Icon, UserRoundIcon, } from "lucide-react"; import { closestCenter, DndContext, KeyboardSensor, PointerSensor, useSensor, useSensors, type DragEndEvent, } from "@dnd-kit/core"; import { arrayMove, rectSortingStrategy, SortableContext, sortableKeyboardCoordinates, useSortable, } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import { toast } from "sonner"; import { saveStygianRecommendationsAction } from "@/app/admin/stygian/actions"; import { AutosaveStatus } from "@/components/admin/autosave-status"; import { StygianSyncButton } from "@/components/admin/stygian-sync-button"; import { ArtifactSelect, CatalogDropdown, CharacterSelect, WeaponSelect, } from "@/components/admin/ui/catalog-select"; import { DeleteConfirmationDialog } from "@/components/admin/ui/delete-confirmation-dialog"; import { StygianBossCard, StygianBossTab, type StygianBossDisplay, } from "@/components/stygian/stygian-boss-display"; import { AdminDropdown, ConstellationSelect, ElementSelect, RefinementSelect, } from "@/components/admin/ui/option-select"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Field, FieldGroup, FieldLabel, FieldSet, FieldLegend, } from "@/components/ui/field"; import { Popover, PopoverContent, PopoverDescription, PopoverHeader, PopoverTitle, PopoverTrigger, } from "@/components/ui/popover"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { elementIconFilter } from "@/lib/catalog/element"; import { AutosaveCoordinator, type AutosaveStatus as CoordinatorStatus } from "@/lib/editor/autosave"; import { supportsWeaponType } from "@/lib/catalog/lunaris"; import { stygianBossPositionLabels, stygianBossPositions, stygianLevels } from "@/lib/stygian/constants"; import { stygianElements, type StygianRecommendationItemInput, } from "@/lib/stygian/schema"; import { cn } from "@/lib/utils"; type CatalogItem = { key: string; name: string; aliases: string[]; imageUrl: string; rarity: number | null; weaponType?: string | null; }; type Character = CatalogItem & { element: string | null; elementIconUrl: string | null; }; type ScheduleSummary = { scheduleId: number; challengeName: string }; type Boss = StygianBossDisplay & { level: number; position: number }; type StoredItem = { kind: string; catalogKey: string | null; weaponKey: string | null; artifactKey: string | null; refinement: number | null; constellationLevel: number | null; element: string | null; }; type Recommendation = { id: string; level: number; bossPosition: number; kind: string; items: StoredItem[]; }; const characterPlaceholderIcon =