import { redirect } from 'react-router'

import { handleCookie } from '~/libs/cookies'
import { AdminLoginPage } from '~/pages/admin-login'

import type { Route } from './+types/_admin.lg-admin._auth.login'

export const loader = async ({ request }: Route.LoaderArgs) => {
  const { staffToken } = await handleCookie(request)

  if (staffToken) {
    throw redirect('/lg-admin')
  }
}

const AuthLayout = () => <AdminLoginPage />
export default AuthLayout
