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 AppreciationSearchPage = Loadable(lazy( () => import('pages/lionerAppreciationSearchPage')));
const AppreciationMaintainPage = Loadable(lazy( () => import('pages/lionerMaintainAppreciationPage')));
const AppreciationReportPage = Loadable(lazy( () => import('pages/lionerGenerateReportPage')));

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

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

    return {
        path: '/',
        element: <MainLayout />,
        children: [
            {
                path: 'appreciation',
                element:  (
                    handleRouteAbility(
                        ability.can('VIEW', 'APPRECIATION'),
                        <AppreciationSearchPage />,
                        <Navigate to="/" />
                    )
                ),
            },
            {
                path: 'appreciation/maintain/:id',
                element:  (
                    handleRouteAbility(
                        ability.can('VIEW', 'APPRECIATION'),
                        <AppreciationMaintainPage />,
                        <Navigate to="/" />
                    )
                ),
            },
            {
                path: 'appreciation/report',
                element:  (
                    handleRouteAbility(
                        ability.can('GENERATE', 'REPORTS'),
                        <AppreciationReportPage />,
                        <Navigate to="/" />
                    )
                ),
            },
            // {
            //     path: 'event/maintain/:id',
            //     element:  (
            //         handleRouteAbility(
            //             ability.can('VIEW', 'EVENT'),
            //             <EventMaintainPage />,
            //             <Navigate to="/" />
            //         )
            //     ),
            // },
        ]
    };
};

export default AppreciationRoutes;
