'use client';

import React, { createContext, use } from 'react';

type User = {
    id: string;
    avatar?: string;
    // Чёто там ещё
};

interface AuthContext {
    user: User | null;
}

const AuthContext = createContext<AuthContext | null>(null);

export const AuthContextProvider = ({ children }: React.PropsWithChildren) => {
    // TODO: подключить бэк
    const user = null;
    return (
        <AuthContext.Provider value={{ user }}>{children}</AuthContext.Provider>
    );
};

export const useAuthContext = () => {
    const context = use(AuthContext);

    if (!context) {
        throw new Error(
            'useAuthContext must be used within AuthContextProvider',
        );
    }

    return context;
};

export const useUser = () => useAuthContext().user;
