"use client"; import React, { FC, useEffect, useState } from "react"; import { chuni_static_avatar } from "@/prisma/schemas/artemis/generated/artemis"; import { Check, ChevronsUpDown } from "lucide-react"; 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 { getCurrentTrophies } from "./actions"; import { cozynet_chuni_static_trophies } from "@/prisma/schemas/artemis/generated/artemis"; const getAvatarTextureSrc = (id: number | undefined) => { if (id === undefined) return ""; return `avatarAccessory/CHU_UI_Avatar_Tex_0${id}.png`; }; type static_trophies = cozynet_chuni_static_trophies; type AvatarSelectionProps = { playerTrophySelectionData: { statictrophies: static_trophies[]; }; }; export const TrophyCustomization: FC = ({ playerTrophySelectionData, }) => { const FormSchema = z.object({ trophies: z.number({ required_error: "Please select a trophy", }), }); const form = useForm>({ resolver: zodResolver(FormSchema), }); const [trophyID, setTrophyId] = useState(undefined); useEffect(() => { const fetchTrophies = async () => { try { const data = await getCurrentTrophies(); if (data.length > 0) { setTrophyId(data[0].trophyId!); } } catch (error) { console.error("Error fetching avatar parts:", error); } }; fetchTrophies(); }, []); function onSubmit(data: z.infer) { toast({ title: "You submitted the following values:", description: (
          {JSON.stringify(data, null, 2)}
        
), }); } return (
{/* Avatar Customization Section */}
( Select Trophy No avatar part found. {playerTrophySelectionData.statictrophies.map( (part) => ( { form.setValue("trophies", part.id); }} > {part.str} ), )} )} />
); };