"use client"; import React, { FC, useEffect, useState } from "react"; import { Check, ChevronsUpDown } from "lucide-react"; import { getCurrentNameplate } from "./actions"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandItem, CommandList, } from "@/components/ui/command"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { z } from "zod"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { toast } from "../../ui/use-toast"; import { cozynet_chuni_static_nameplate } from "@/prisma/schemas/artemis/generated/artemis"; const getNamePlateTextures = (id: number | undefined) => { if (id === undefined) return ""; // Pad the id to be 8 digits long, using leading zeros const paddedId = id.toString().padStart(8, "0"); return `namePlates/CHU_UI_NamePlate_${paddedId}.png`; }; type player_nameplates = cozynet_chuni_static_nameplate; type AvatarSelectionProps = { playerNamePlateSelectionData: { namePlates: player_nameplates[]; }; }; export const NameplateCustomization: FC = ({ playerNamePlateSelectionData, }) => { const FormSchema = z.object({ PlayerNamePlateId: z.number({ required_error: "Please select an Avatar Head Item.", }), }); const form = useForm>({ resolver: zodResolver(FormSchema), }); const [nameplateId, setNameplateId] = useState(undefined); useEffect(() => { const fetchNamePlates = async () => { try { const data = await getCurrentNameplate(); if (data.length > 0) { setNameplateId(data[0].nameplateId!); } } catch (error) { console.error("Error fetching avatar parts:", error); } }; fetchNamePlates(); }, []); function onSubmit(data: z.infer) { toast({ title: "You submitted the following values:", description: (
          {JSON.stringify(data, null, 2)}
        
), }); } const getTexture = (id: number | undefined, defaultSrc: string) => { return id ? getNamePlateTextures(id) : defaultSrc; }; const AvatarTextures = { AvatarHeadAccessory: { src: nameplateId ? getTexture( form.watch("PlayerNamePlateId"), `namePlates/CHU_UI_NamePlate_${nameplateId.toString().padStart(8, "0")}.png` ) : `systemVoiceThumbnails/CHU_UI_SystemVoice_Default.png`, }, }; return (
{/* Avatar Customization Section */}
{Object.entries(AvatarTextures).map(([key, { src }]) => (
{""}
))}
( Select Nameplate No name plate found. {playerNamePlateSelectionData.namePlates.map( (part) => ( { form.setValue("PlayerNamePlateId", part.id!); }} > {part.str} ) )} )} />
); };