import { create } from "zustand";

interface SelectedUser {
    color: string;
    name: string;
    id: string;
    location?: { position: { x: number; y: number; z: number }; rotation: { x: number; y: number; z: number }; target: { x: number; y: number; z: number } };
}

interface SelectedUserStore {
    selectedUser: SelectedUser | null;
    setSelectedUser: (user: SelectedUser) => void;
    clearSelectedUser: () => void;
    updateLocation: (location: { position: { x: number; y: number; z: number }; rotation: { x: number; y: number; z: number }; target: { x: number; y: number; z: number } }) => void;
}

export const useSelectedUserStore = create<SelectedUserStore>((set) => ({
    selectedUser: null,
    setSelectedUser: (user) => set({ selectedUser: user }),
    clearSelectedUser: () => set({ selectedUser: null }),
    updateLocation: (location) =>
        set((state) => {
            if (!state.selectedUser) return state;
            return {
                selectedUser: {
                    ...state.selectedUser,
                    location: location,
                },
            };
        }),
}));
