'use client';

import { useEffect } from 'react';
import { useRouter } from 'next/navigation';

export default function RootPage() {
    const router = useRouter();

    useEffect(() => {
        // Detect user's preferred language
        let userLang = 'zh'; // default to simplified Chinese

        if (navigator.language) {
            const browserLang = navigator.language.toLowerCase();
            if (
                browserLang.includes('zh-tw') ||
                browserLang.includes('zh-hk') ||
                browserLang.includes('zh-mo')
            ) {
                userLang = 'tw'; // Traditional Chinese
            } else if (browserLang.startsWith('zh')) {
                userLang = 'zh'; // Simplified Chinese
            } else if (browserLang.startsWith('en')) {
                userLang = 'en'; // English
            }
        }

        router.replace(`/${userLang}`);
    }, [router]);

    return (
        <div className="min-h-screen bg-black text-cyan-400 flex items-center justify-center">
            <div className="text-center">
                <div className="text-2xl font-bold text-cyan-400 mb-4">
                    CYBER
                    <span className="text-pink-500">CLOUD</span>
                </div>
                <div className="text-gray-400">Loading...</div>
            </div>
        </div>
    );
}
