<?php

namespace RinnovoBooking\Core;

class AdminMenu {

    // Singleton
    private static $instance = null;
    private static $plugin_path;

    // Metodo per ottenere l'istanza della classe
    public static function get_instance() {
        if (self::$instance === null) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    // Costruttore privato
    private function __construct() {
        add_action('admin_menu', [$this, 'register_menu_pages']);
        self::$plugin_path = dirname(__DIR__).'/admin/';
    }

    // Metodo per registrare le pagine del menu admin
    public function register_menu_pages() {
        add_menu_page(
            RINNOVOBOOKINGNOMEPLUGIN . ' - Impostazioni',
            RINNOVOBOOKINGNOMEPLUGIN,
            'manage_options',
            RINNOVOBOOKINGPREFIX . '/' . RINNOVOBOOKINGPREFIX . '.php',
            [$this, 'render_description_page'],
            '' . RINNOVOBOOKINGSTAGING . '/wp-content/plugins/' . RINNOVOBOOKINGPREFIX . '/admin/images/' . RINNOVOBOOKINGPREFIXLOGO,
            20
        );

        $submenus = [
            ['Email', 'email', 'render_email_page'],
            ['Email Form', 'emailform', 'render_email_form_page'],
            ['Fasce Orarie', 'fasceorarie', 'render_fasce_orarie_page'],
            ['Informazioni', 'info', 'render_info_page'],
            ['iPatente Api', 'ipatenteapi', 'render_ipatenteapi_page'],
            ['Log', 'log', 'render_log_page'],
            ['Prenotazioni', 'prenotazioni', 'render_prenotazioni_page'],
            ['Report', 'reportprenotazioni', 'render_report_prenotazioni_page'],
            ['Sedi', 'sedi', 'render_sedi_page'],
            ['Speciali', 'speciali', 'render_speciali_page'],
            ['Utenti', 'utenti', 'render_utenti_page'],
        ];

        foreach ($submenus as [$menu_title, $menu_slug, $callback]) {
            add_submenu_page(
                RINNOVOBOOKINGPREFIX . '/' . RINNOVOBOOKINGPREFIX . '.php',
                RINNOVOBOOKINGNOMEPLUGIN . ' - ' . $menu_title,
                $menu_title,
                'manage_options',
                RINNOVOBOOKINGPREFIX . $menu_slug,
                [$this, $callback]
            );
        }
    }

    // Metodi per il rendering delle pagine
    public function render_description_page() {
        include self::$plugin_path . 'impostazioni.php';
    }

    public function render_fasce_orarie_page() {
        include self::$plugin_path . 'fasceorarie.php';
    }

    public function render_speciali_page() {
        include self::$plugin_path . 'speciali.php';
    }

    public function render_sedi_page() {
        include self::$plugin_path . 'sedi.php';
    }

    public function render_utenti_page() {
        include self::$plugin_path . 'utenti.php';
    }

    public function render_log_page() {
        include self::$plugin_path . 'log.php';
    }

    public function render_prenotazioni_page() {
        include self::$plugin_path . 'prenotazioni.php';
    }

    public function render_info_page() {
        include self::$plugin_path . 'info.php';
    }

    public function render_report_prenotazioni_page() {
        include self::$plugin_path . 'reportprenotazioni.php';
    }

    public function render_email_page() {
        include self::$plugin_path . 'emailinviate.php';
    }

    public function render_email_form_page() {
        include self::$plugin_path . 'emailform.php';
    }
    
    public function render_ipatenteapi_page() {
        include self::$plugin_path . 'ipatenteapi.php';
    }
}

