import {
  getPartialsConfig,
  makePartials,
} from "$root/defaults/makePartials.tsx";
import { FreshContext } from "$fresh/server.ts";
import { isEmployee, State } from "$root/defaults/interfaces.ts";

// deno-lint-ignore require-await
export async function Index(
  _request: Request,
  context: FreshContext<State>,
) {
  const employeeStatus = isEmployee(
    (context.state as unknown as { session: Record<string, string> }).session,
  );

  return (
    <div class="page-content">
      <h2 class="page-title">Étudiants</h2>
      <p>
        Bienvenue{" "}
        <strong>
          {(context.state as unknown as { session: Record<string, string> })
            .session.displayName}
        </strong>
        .
      </p>
      {employeeStatus && (
        <p>
          Consultez la{" "}
          <a href="/students/consult" f-partial="/students/partials/consult">
            liste des élèves
          </a>{" "}
          ou gérez les{" "}
          <a
            href="/students/promotions"
            f-partial="/students/partials/promotions"
          >
            promotions
          </a>
          .
        </p>
      )}
    </div>
  );
}

export const config = getPartialsConfig();
export default makePartials(Index);
