"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 { cozynet_chuni_static_systemvoice } from "@/prisma/schemas/artemis/generated/artemis"; import { getCurrentSystemVoice, getSystemVoices } from "./actions"; 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 `systemVoiceThumbnails/CHU_UI_SystemVoice_${paddedId}.png`; }; type systemvoice = cozynet_chuni_static_systemvoice; type SystemVoiceSelectionProps = { playerSystemVoiceSelectionData: { systemVoices: systemvoice[]; }; }; export const SystemVoiceCustomization: FC = ({ playerSystemVoiceSelectionData, }) => { const FormSchema = z.object({ PlayerSystemVoice: z.number({ required_error: "Please select a System Voice.", }), }); const form = useForm>({ resolver: zodResolver(FormSchema), }); const [systemVoiceId, setSytemVoiceId] = useState( undefined ); useEffect(() => { const fetchSystemVoices = async () => { try { const data = await getCurrentSystemVoice(); if (data.length > 0) { setSytemVoiceId(data[0].voiceId!); } } catch (error) { console.error("Error fetching system voices:", error); } }; fetchSystemVoices(); }, []); 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: systemVoiceId ? getTexture( form.watch("PlayerSystemVoice"), `systemVoiceThumbnails/CHU_UI_SystemVoice_${systemVoiceId.toString().padStart(8, "0")}.png` ) : `systemVoiceThumbnails/CHU_UI_SystemVoice_Default.png`, // Provide a default texture or handle the case when systemVoiceId is undefined }, }; return (
( Select System Voice No system voice found. {playerSystemVoiceSelectionData.systemVoices.map( (part) => ( { form.setValue("PlayerSystemVoice", part.id!); }} > {part.str} ) )} )} />
{Object.entries(AvatarTextures).map(([key, { src }]) => (
))}
); };