import PeopleIcon from "@mui/icons-material/People";

import { OpenAPI } from "openapi-types";

import { RouterExtension } from "../../router/Router";
import { NavigationOverrides, PageComponent } from "../../types";

const routes: Record<
  string,
  Record<
    string,
    {
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      page: () => PageComponent<any> | Promise<PageComponent<any>>;
      request?: OpenAPI.Request;
      defaultRequest?: OpenAPI.Request;
      offline?: boolean;
    }
  >
> = {
  staff: {
    list: { page: async () => (await import("./pages/staff/list")).default },
    detail: {
      page: async () => (await import("./pages/staff/detail")).default,
    },
  },
};

export const router: RouterExtension = {
  app: "user",
  pages: (route) => {
    const { page, ...hit } = routes[route.view]?.[route.action] ?? {};

    if (page != null) {
      return {
        page: page(),
        ...hit,
      };
    }

    return undefined;
  },
};

export const navigation: NavigationOverrides = {
  "user.staff:list": {
    icon: PeopleIcon,
    title: "Staff",
    permission: "user.view_user",
  },
} as const;
