'use client';

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

import { clearTokens } from '@/lib/api';
import { clearKeycloakLogoutInProgress, clearLoginState } from '@/lib/keycloak-oidc';
import { pickAppText } from '@/lib/i18n/core';
import { useAppI18n } from '@/lib/i18n/provider';
import { useChatStore } from '@/lib/store';

export default function LogoutCallbackPage() {
  const { locale } = useAppI18n();
  const router = useRouter();
  const setUser = useChatStore((s) => s.setUser);

  useEffect(() => {
    clearTokens();
    clearLoginState();
    clearKeycloakLogoutInProgress();
    setUser(null);
    router.replace('/login?logged_out=1');
  }, [router, setUser]);

  return (
    <div className="flex min-h-screen items-center justify-center px-4">
      <div className="text-sm text-muted-foreground">
        {pickAppText(locale, '正在退出登录...', 'Signing out...')}
      </div>
    </div>
  );
}
