<?php

class CASS_Dashboard_Menu
{
    public static function execute()
    {

        //Create the dashboard menus
        add_action('admin_menu', 'wpcass_add_menu_page');
        function wpcass_add_menu_page()
        {
            //Options
            global $cass_admin_race_list;
            global $cass_admin_member_list;
            global $cass_admin_race_user_list;
            global $cass_admin_race_user_all_courses_list;
            global $cass_admin_group_list;
            global $cass_admin_material_list;
            global $cass_admin_season_list;
            global $cass_admin_type_list;
            global $cass_admin_level_list;
            global $cass_admin_race_leader_list;
            global $cass_admin_race_leader_all_courses_list;
            global $cass_admin_dashboard;

            add_options_page(
                'Configuration du Club Alpin Suisse de Sion',
                'CASs',
                'cass_rl',
                'cass_plugin_options',
                'cass_plugin_options_page'
            );

            //Create CASs top-level menu
            add_menu_page(
                'Club Alpin Suisse de Sion',
                'CASs',
                'cass_rl',
                'cass-settings',
                'page_callback_function',
                'dashicons-smiley',
                99
            );

            //Create submenus

            $cass_admin_dashboard = add_submenu_page(
                'cass-settings',
                __('Tableau de bord', 'cass-admin-dashboard'),
                'Tableau de bord',
                'cass_admin',
                'cass-admin-dashboard',
                'cass_admin_dashboard'
            );

            $cass_admin_member_list = add_submenu_page(
                'cass-settings',
                __('Liste des membres', 'cass-admin-member-list'),
                'Liste des membres',
                'cass_rl',
                'cass-admin-member-list',
                'view_member_list_initialisation'
            );

            $cass_admin_race_list = add_submenu_page(
                'cass-settings',
                __('Liste des courses', 'cass-admin-race-list'),
                'Liste des courses',
                'cass_rl',
                'cass-admin-race-list',
                'view_race_list_initialisation'
            );

            $cass_admin_type_list = add_submenu_page(
                'cass-settings',
                __('Types de courses', 'cass-admin-type-list'),
                'Types de courses',
                'cass_rl',
                'cass-admin-type-list',
                'view_type_list_initialisation'
            );

            $cass_admin_level_list = add_submenu_page(
                'cass-settings',
                __('Niveaux', 'cass-admin-level-list'),
                'Niveaux',
                'cass_rl',
                'cass-admin-level-list',
                'view_level_list_initialisation'
            );

            $cass_admin_group_list = add_submenu_page(
                'cass-settings',
                __('Groupes', 'cass-admin-group-list'),
                'Groupes',
                'cass_rl',
                'cass-admin-group-list',
                'view_group_list_initialisation'
            );

            $cass_admin_material_list = add_submenu_page(
                'cass-settings',
                __('Matériaux', 'cass-admin-material-list'),
                'Matériaux',
                'cass_rl',
                'cass-admin-material-list',
                'view_material_list_initialisation'
            );

            $cass_admin_season_list = add_submenu_page(
                'cass-settings',
                __('Saisons', 'cass-admin-season-list'),
                'Saisons',
                'cass_admin',
                'cass-admin-season-list',
                'view_season_list_initialisation'
            );

            $cass_admin_race_user_list = add_submenu_page(
                null,
                __('Liste des participants', 'cass-admin-race-user-list'),
                'Liste des participants',
                'cass_rl',
                'cass-admin-race-user-list',
                'view_race_user_list_initialisation'
            );

            $cass_admin_race_user_all_courses_list = add_submenu_page(
                null,
                __('Liste des courses du membre', 'cass-admin-race-user-all-courses-list'),
                'Liste des courses du membre',
                'cass_rl',
                'cass-admin-race-user-all-courses-list',
                'view_race_user_all_courses_list_initialisation'
            );


            $cass_admin_race_leader_all_courses_list = add_submenu_page(
                null,
                __('Liste des courses du chef de course', 'cass-admin-race-leader-all-courses-list'),
                'Liste des courses du chef de course',
                'cass_rl',
                'cass-admin-race-leader-all-courses-list',
                'view_race_leader_all_courses_list_initialisation'
            );

            $cass_admin_setting_edit = add_submenu_page(
                'cass-settings',
                __('Paramètres', 'cass-admin-setting-edit'),
                'Paramètres',
                'cass_admin',
                'cass-admin-setting-edit',
                'cass_admin_setting_edit'
            );


            // This is the hidden page
            add_submenu_page(
                null,
                'Edition des courses',
                'Liste des courses',
                'cass_rl',
                'cass-admin-race-edit',
                'cass_admin_race_edit'
            );

            add_submenu_page(
                null,
                'Edition des types de courses',
                'Type de courses',
                'cass_rl',
                'cass-admin-type-edit',
                'cass_admin_type_edit'
            );

            add_submenu_page(
                null,
                'Edition des niveaux',
                'Niveaux',
                'cass_rl',
                'cass-admin-level-edit',
                'cass_admin_level_edit'
            );


            add_submenu_page(
                null,
                'Edition des groupes',
                'Edition des groupes',
                'cass_rl',
                'cass-admin-group-edit',
                'cass_admin_group_edit'
            );

            add_submenu_page(
                null,
                'Edition des matériaux',
                'Edition des matériaux',
                'cass_rl',
                'cass-admin-material-edit',
                'cass_admin_material_edit'
            );

            add_submenu_page(
                null,
                'Edition des saisons',
                'Edition des saisons',
                'cass_rl',
                'cass-admin-season-edit',
                'cass_admin_season_edit'
            );

            add_submenu_page(
                null,
                'Edition du participant',
                'Edition du participant',
                'cass_rl',
                'cass-admin-race-user-edit',
                'cass_admin_race_user_edit'
            );

            add_submenu_page(
                null,
                'Matériaux de la course',
                'Matériaux de la course',
                'cass_rl',
                'cass-admin-race-editmaterial',
                'cass_admin_race_editmaterial'
            );





            // Adding menu
            add_action("load-$cass_admin_group_list", "cass_admin_group_list");
            add_action("load-$cass_admin_material_list", "cass_admin_material_list");
            add_action("load-$cass_admin_season_list", "cass_admin_season_list");
            add_action("load-$cass_admin_type_list", "cass_admin_type_list");
            
        }


        function cass_admin_type_list()
        {
            global $supporthost_sample_page;
            global $table;

            $screen = get_current_screen();

            // get out of here if we are not on our settings page
            if (!is_object($screen) || $screen->id != $supporthost_sample_page)
                return;

            $args = array(
                'label' => __('Elements per page', 'supporthost-admin-table'),
                'default' => 2,
                'option' => 'elements_per_page'
            );
            add_screen_option('per_page', $args);

            $table = new CASS_View_Type_List();
        }

        function cass_admin_group_list()
        {
            global $supporthost_sample_page;
            global $table;

            $screen = get_current_screen();

            // get out of here if we are not on our settings page
            if (!is_object($screen) || $screen->id != $supporthost_sample_page)
                return;

            $args = array(
                'label' => __('Elements per page', 'supporthost-admin-table'),
                'default' => 2,
                'option' => 'elements_per_page'
            );
            add_screen_option('per_page', $args);

            $table = new CASS_View_Group_List();
        }


        function cass_admin_material_list()
        {
            global $supporthost_sample_page;
            global $table;


            $screen = get_current_screen();

            // get out of here if we are not on our settings page
            if (!is_object($screen) || $screen->id != $supporthost_sample_page)
                return;

            $args = array(
                'label' => __('Elements per page', 'supporthost-admin-table'),
                'default' => 2,
                'option' => 'elements_per_page'
            );
            add_screen_option('per_page', $args);

            $table = new CASS_View_Material_List();
        }

        function cass_admin_season_list()
        {
            global $supporthost_sample_page;
            global $table;


            $screen = get_current_screen();

            // get out of here if we are not on our settings page
            if (!is_object($screen) || $screen->id != $supporthost_sample_page)
                return;

            $args = array(
                'label' => __('Elements per page', 'supporthost-admin-table'),
                'default' => 2,
                'option' => 'elements_per_page'
            );
            add_screen_option('per_page', $args);

            $table = new CASS_View_Season_List();
        }

        function cass_admin_dashboard()
        {
            CASS_View_Dashboard::execute();
        }
        function cass_admin_race_edit()
        {
            CASS_View_Race_Edit::execute();
        }

        function cass_admin_type_edit()
        {
            CASS_View_Type_Edit::execute();
        }

        function cass_admin_level_edit()
        {
            CASS_View_Level_Edit::execute();
        }

        function cass_admin_group_edit()
        {
            CASS_View_Group_Edit::execute();
        }


        function cass_admin_material_edit()
        {
            CASS_View_Material_Edit::execute();

        }

        function cass_admin_season_edit()
        {
            CASS_View_Season_Edit::execute();

        }

        function cass_admin_race_editmaterial()
        {
            CASS_View_Race_Edit_Material::execute();
        }

        function cass_admin_race_user_edit()
        {
            CASS_View_Race_User_Edit::execute();
        }

        function cass_admin_setting_edit()
        {
            CASS_View_Setting_Edit::execute();
        }

    }
}