import {lazy, useContext} from 'react';

// project import
import Loadable from 'components/Loadable';
import MainLayout from "../layout/MainLayout";
import {handleRouteAbility} from "../utils/CommonFunction";
import {Navigate} from "react-router";
import AbilityContext from "../components/AbilityProvider";

// render - login
const ApplicationSearchPage = Loadable(lazy( () => import('pages/lionerApplicationSearchPage')));
const ApplicationMaintainPage = Loadable(lazy(() => import('pages/lionerMaintainApplicationPage')));
const EventSearchPage = Loadable(lazy( () => import('pages/lionerEventSearchPage')));
const EventMaintainPage = Loadable(lazy( () => import('pages/lionerMaintainEventPage')));
const AwardSearchPage = Loadable(lazy( () => import('pages/lionerAwardSearchPage')));
const AwardMaintainPage = Loadable(lazy( () => import('pages/lionerMaintainAwardPage')));
const AdvanceSearchPage = Loadable(lazy( () => import('pages/lionerAdvanceSearchPage')));

// ==============================|| AUTH ROUTING ||============================== //

const AwardRoutes =() => {
    const ability = useContext(AbilityContext);

    return {
        path: '/',
        element: <MainLayout />,
        children: [
            {
                path: 'advance/:module/:keyword',
                element: <AdvanceSearchPage />
            },
            {
                path: 'event',
                element:  (
                    handleRouteAbility(
                        ability.can('VIEW', 'EVENT'),
                        <EventSearchPage />,
                        <Navigate to="/" />
                    )
                ),
            },
            {
                path: 'event/maintain/:id',
                element:  (
                    handleRouteAbility(
                        ability.can('VIEW', 'EVENT'),
                        <EventMaintainPage />,
                        <Navigate to="/" />
                    )
                ),
            },
            {
                path: 'application',
                element:  (
                    handleRouteAbility(
                        ability.can('VIEW', 'APPLICATION'),
                        <ApplicationSearchPage />,
                        <Navigate to="/" />
                    )
                ),
            },
            {
                path: 'application/maintain/:id',
                element:  (
                    handleRouteAbility(
                        ability.can('VIEW', 'APPLICATION'),
                        <ApplicationMaintainPage />,
                        <Navigate to="/" />
                    )
                ),
            },
            {
                path: 'application/maintain/:id/:eventId',
                element:  (
                    handleRouteAbility(
                        ability.can('VIEW', 'APPLICATION'),
                        <ApplicationMaintainPage />,
                        <Navigate to="/" />
                    )
                ),
            },
            {
                path: 'award',
                element:  (
                    handleRouteAbility(
                        ability.can('VIEW', 'AWARD'),
                        <AwardSearchPage />,
                        <Navigate to="/" />
                    )
                ),
            },
            {
                path: 'award/maintain/:id',
                element:  (
                    handleRouteAbility(
                        ability.can('VIEW', 'AWARD'),
                        <AwardMaintainPage />,
                        <Navigate to="/" />
                    )
                ),
            },
            {
                path: 'award/maintain/:id/:eventId/:applicationId',
                element:  (
                    handleRouteAbility(
                        ability.can('VIEW', 'AWARD'),
                        <AwardMaintainPage />,
                        <Navigate to="/" />
                    )
                ),
            },
        ]
    };
};

export default AwardRoutes;
