'use client';

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

import { buildAuthPortalUrl } from '@/lib/auth-portal';
import { pickAppText } from '@/lib/i18n/core';
import { useAppI18n } from '@/lib/i18n/provider';

export default function LoginRedirectPage() {
  const { locale } = useAppI18n();
  const searchParams = useSearchParams();

  useEffect(() => {
    const nextPath = searchParams?.get('next') || '/';
    window.location.replace(buildAuthPortalUrl('/login', nextPath));
  }, [searchParams]);

  return (
    <div className="flex min-h-screen items-center justify-center px-4">
      <div className="text-sm text-muted-foreground">
        {pickAppText(locale, '正在跳转到登录门户...', 'Redirecting to the sign-in portal...')}
      </div>
    </div>
  );
}
