// Logout — URL `/logout`. On mount it POSTs /auth/sign-out (revokes the session
// row + clears the cookie), then sends the browser to /login regardless of the
// result (a failed sign-out still shouldn't strand the user).
import type { ReactNode } from 'react'
import { useEffect } from 'react'
import type { PageMeta } from '@voltro/web'
import { T } from '@voltro/i18n'
import { AuthShell } from '../../components/AuthShell'
import { postAuth } from '../../lib/auth'
import { getCatalog } from '../../locales'

export const renderMode = 'static' as const

export const meta = ({ locale }: { readonly locale: string }): PageMeta => ({
  title: getCatalog(locale)['meta.logout.title'],
})

export default function Logout(): ReactNode {
  useEffect(() => {
    void postAuth('/auth/sign-out', {}).finally(() => window.location.assign('/login'))
  }, [])

  return (
    <AuthShell titleId="logout.title">
      <p className="muted" role="status"><T id="logout.body" /></p>
    </AuthShell>
  )
}
