import type { Route } from './+types/route'

import { Suspense } from 'react'
import { Await } from 'react-router'

import { Skeleton } from '@repo/ui/components/skeleton'
import { request as req } from '@repo/util/request'

export function meta({}: Route.MetaArgs) {
  return [{ title: 'Matrículas agendadas' }]
}

export async function loader({ context, request, params }: Route.LoaderArgs) {
  const data = req({
    url: `/orgs/${params.orgid}/enrollments/scheduled`,
    context,
    request
  }).then((r) => r.json())

  return {
    data
  }
}

export default function Route({ loaderData: { data } }: Route.ComponentProps) {
  return (
    <>
      <div className="space-y-0.5 mb-8">
        <h1 className="text-2xl font-bold tracking-tight">
          Matrículas agendadas
        </h1>
        <p className="text-muted-foreground">
          Acompanhe todas as matrículas agendadas, cancele quando quiser ou
          matricule imediatamente.
        </p>
      </div>

      <Suspense fallback={<Skeleton />}>
        <Await resolve={data}>
          {(resolved) => <>...{console.log(resolved)}</>}
        </Await>
      </Suspense>
    </>
  )
}
