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 employeeCheck = isEmployee(
    (context.state as unknown as { session: Record<string, string> }).session,
  );

  return (
    <div class="page-content">
      <h2 class="page-title">PolyNotes</h2>
      <p>
        Bienvenue{" "}
        <strong>
          {(context.state as unknown as { session: Record<string, string> })
            .session.displayName}
        </strong>
        .
      </p>
      {employeeCheck
        ? (
          <p>
            Consultez les{" "}
            <a href="/notes/courses" f-partial="/notes/partials/courses">
              notes des élèves
            </a>{" "}
            ou gérez les{" "}
            <a href="/notes/ues" f-partial="/notes/partials/ues">
              UEs
            </a>
            .
          </p>
        )
        : (
          <p>
            Consultez vos{" "}
            <a href="/notes/notes" f-partial="/notes/partials/notes">
              notes
            </a>
            .
          </p>
        )}
    </div>
  );
}

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