import { redirect } from 'next/navigation';
import { createClient } from '@/lib/supabase/server';
import { getProfile } from '@/services/profile-actions';
import SettingsHub from '@/components/SettingsHub';

export const metadata = {
    title: 'Einstellungen | Settings',
};

export default async function SettingsPage() {
    const supabase = await createClient();
    const { data: { user } } = await supabase.auth.getUser();

    if (!user) {
        redirect('/login');
    }

    const profile = await getProfile();

    if (!profile) {
        return <div>Loading...</div>;
    }

    return (
        <SettingsHub
            profile={{
                email: profile.email,
                username: profile.username,
                created_at: profile.created_at
            }}
        />
    );
}
