import { Route } from "@/routing";
import { isManagerMiddleware } from "@/management/middleware";
import { EditionsManagement } from "@/management/edition/list";
import React from "react";
import { ManagementIndex } from "@/management/main";
import StaticPageManagement from "@/management/page/list";
import { InternshipTypeManagement } from "@/management/type/list";
import { EditionRouter, EditionManagement } from "@/management/edition/manage";
import { EditionSettings } from "@/management/edition/settings";
import { ProposalManagement } from "@/management/edition/proposal/list";
import { PlanManagement } from "@/management/edition/ipp/list";
import { ReportFields } from "@/management/report/fields/list";
import { ReportManagement } from "@/management/edition/report/list";
import { InternshipManagement } from "@/management/edition/internship/list";
import { EditionReportSchema } from "@/management/edition/report-schema";

export const managementRoutes: Route[] = ([
    { name: "index", path: "/", content: ManagementIndex, exact: true },

    { name: "edition_router", path: "/editions/:edition", content: EditionRouter },
    { name: "edition_settings", path: "/editions/:edition/settings", content: EditionSettings, tags: ["edition"] },
    { name: "edition_manage", path: "/editions/:edition", content: EditionManagement, tags: ["edition"], exact: true },
    { name: "edition_internships", path: "/editions/:edition/internships", content: InternshipManagement, tags: ["edition"] },
    { name: "edition_proposals", path: "/editions/:edition/proposals", content: ProposalManagement, tags: ["edition"] },
    { name: "edition_reports", path: "/editions/:edition/reports", content: ReportManagement, tags: ["edition"] },
    { name: "edition_schema", path: "/editions/:edition/schema", content: EditionReportSchema, tags: ["edition"] },
    { name: "edition_ipp_index", path: "/editions/:edition/ipp", content: PlanManagement, tags: ["edition"] },
    { name: "editions", path: "/editions", content: EditionsManagement },

    { name: "report_fields", path: "/fields", content: ReportFields },
    { name: "types", path: "/types", content: InternshipTypeManagement },
    { name: "static_pages", path: "/static-pages", content: StaticPageManagement }
] as Route[]).map(
    ({ name, path, middlewares = [], ...route }): Route => ({
        name: `management:${ name }`,
        path: `/management${ path }`,
        middlewares: [ isManagerMiddleware, ...middlewares ],
        ...route
    })
);
