'use client';

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

import { startKeycloakLogin } from '@/lib/keycloak-oidc';
import { pickAppText } from '@/lib/i18n/core';
import { useAppI18n } from '@/lib/i18n/provider';

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

  useEffect(() => {
    const nextPath = searchParams?.get('next') || '/mcp';
    void startKeycloakLogin(nextPath);
  }, [searchParams]);

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