import { LoaderCircle } from 'lucide-react';
import type { ReactNode } from 'react';

export type AuthenticationStatus = 'checking' | 'authenticated' | 'unauthenticated';

export function initialAuthenticationStatus(storedAccessToken: string): AuthenticationStatus {
  return storedAccessToken ? 'authenticated' : 'checking';
}

export function AuthGate(props: {
  authenticated: ReactNode;
  status: AuthenticationStatus;
  unauthenticated: ReactNode;
}) {
  if (props.status === 'authenticated') return props.authenticated;
  if (props.status === 'unauthenticated') return props.unauthenticated;

  return (
    <div className="authSessionChecking" role="status" aria-busy="true" aria-live="polite">
      <LoaderCircle aria-hidden="true" size={20} />
      <span>正在确认登录状态</span>
    </div>
  );
}
