<?php
/**
 * WP Multi – Modul: Zentrale Menü-Registrierung
 *
 * Automatisch aus wp-multi.php ausgelagert. Wird über den Loader in
 * wp-multi.php eingebunden (nur wenn das WP Multi Toolkit aktiv ist).
 */

if (!defined('ABSPATH')) { exit; }

/*
 * Zentrale Menü-Registrierung
 *
 * Alle Admin-Seiten von WP Multi hängen als Submenüs am gemeinsamen
 * Top-Level-Menü "WP Multi" (Slug 'wp-multi'), das das Toolkit mit
 * admin_menu-Priorität 9 registriert. Diese Funktion läuft mit
 * Priorität 20 und legt bei fehlendem Toolkit-Menü ein Fallback an.
 */
function wp_multi_register_admin_menus() {
    global $admin_page_hooks;

    $parent = 'wp-multi';

    // Fallback: falls das Toolkit-Top-Level (noch) nicht existiert
    if (empty($admin_page_hooks[$parent])) {
        add_menu_page(
            __('WP Multi', 'wp-multi'),
            __('WP Multi', 'wp-multi'),
            'manage_options',
            $parent,
            'wp_multi_security_settings_page',
            'dashicons-screenoptions',
            59
        );
    }

    $hooks = array();

    // Sicherheit
    $hooks[] = add_submenu_page($parent, __('Sicherheit', 'wp-multi'), __('Sicherheit', 'wp-multi'), 'manage_options', 'wp-multi-security', 'wp_multi_security_settings_page');
    $hooks[] = add_submenu_page($parent, __('WP Multi Statistik', 'wp-multi'), __('Sicherheits-Statistik', 'wp-multi'), 'manage_options', 'wp-multi-statistics', 'wp_multi_statistics_page');
    $hooks[] = add_submenu_page($parent, __('Sicherheitseinstellungen', 'wp-multi'), __('Benutzer-Sicherheit', 'wp-multi'), 'manage_options', 'wp_multi_users_security_settings', 'wp_multi_users_security_settings_page');
    $hooks[] = add_submenu_page($parent, __('Blockierte IPs', 'wp-multi'), __('Blockierte IPs', 'wp-multi'), 'manage_options', 'wp_multi_blocked_ips', 'wp_multi_display_blocked_ips');
    $hooks[] = add_submenu_page($parent, __('Gesperrte Benutzer', 'wp-multi'), __('Gesperrte Benutzer', 'wp-multi'), 'manage_options', 'wp-multi-blocked-users', 'wp_multi_blocked_users_page');
    $hooks[] = add_submenu_page($parent, __('Login-URL', 'wp-multi'), __('Login-URL', 'wp-multi'), 'manage_options', 'wp_multi_login_url', 'wp_multi_login_url_page');
    $hooks[] = add_submenu_page($parent, __('Login-Design', 'wp-multi'), __('Login-Design', 'wp-multi'), 'manage_options', 'wp_multi_login_design', 'wp_multi_login_design_page');

    // Analyse & Inhalte
    $hooks[] = add_submenu_page($parent, __('Benutzer Analytics', 'wp-multi'), __('Benutzer-Analytics', 'wp-multi'), 'manage_options', 'wp_multi_analytics', 'wp_multi_display_user_analytics');
    $hooks[] = add_submenu_page($parent, __('Gast-Autor Übersicht', 'wp-multi'), __('Gast-Autoren', 'wp-multi'), 'manage_options', 'guest_author_overview', 'wp_multi_guest_author_overview_page');
    $hooks[] = add_submenu_page($parent, __('Pinwand', 'wp-multi'), __('Pinwand', 'wp-multi'), 'manage_options', 'message-board', 'wp_multi_add_message_board');
    $hooks[] = add_submenu_page($parent, __('Gemeldete Beiträge', 'wp-multi'), __('Gemeldete Beiträge', 'wp-multi'), 'manage_options', 'reported-posts', 'wp_stat_notice_reported_posts_page');
    $hooks[] = add_submenu_page($parent, __('WP Stat & Notice', 'wp-multi'), __('Statistik & Notice', 'wp-multi'), 'manage_options', 'statistik_manager', 'statistik_manager_options_page');

    // Werkzeuge
    $hooks[] = add_submenu_page($parent, __('Custom Shortcodes', 'wp-multi'), __('Shortcodes', 'wp-multi'), 'manage_options', 'wp_multi_shortcodes', 'wp_multi_shortcode_page');
    $hooks[] = add_submenu_page($parent, __('Automatische Tags', 'wp-multi'), __('Auto-Tags', 'wp-multi'), 'manage_options', 'wp-multi-auto-tags', 'wp_multi_auto_tags_page');
    $hooks[] = add_submenu_page($parent, __('Custom Text Einstellungen', 'wp-multi'), __('Custom Text', 'wp-multi'), 'manage_options', 'wp_multi_custom_text_settings', 'wp_multi_custom_text_settings_page_content');

    // Benachrichtigungen
    $hooks[] = add_submenu_page($parent, __('Notify', 'wp-multi'), __('Notify', 'wp-multi'), 'manage_options', 'wp-multi-notify', 'wp_multi_notify_page');
    $hooks[] = add_submenu_page($parent, __('DC-Notify Einstellungen', 'wp-multi'), __('DC-Notify', 'wp-multi'), 'manage_options', 'wp-multi-dc-notify', 'wp_multi_settings_page');
    $hooks[] = add_submenu_page($parent, __('TG-Notify Einstellungen', 'wp-multi'), __('TG-Notify', 'wp-multi'), 'manage_options', 'tg-notify', 'tg_notify_page');

    // Custom Admin-Links
    $hooks[] = add_submenu_page($parent, __('Admin-Link hinzufügen', 'wp-multi'), __('Admin-Links', 'wp-multi'), 'manage_options', 'wp-stat-notice-custom-page', 'wp_stat_notice_add_custom_page_form');

    // Benutzerdefinierte Admin-Link-Seiten (dynamisch aus Option)
    $custom_pages = get_option('wp_stat_notice_custom_pages', []);
    if (!empty($custom_pages) && is_array($custom_pages)) {
        foreach ($custom_pages as $page) {
            if (!isset($page['title'], $page['slug'])) {
                continue;
            }
            $hooks[] = add_submenu_page($parent, $page['title'], $page['title'], 'manage_options', $page['slug'], 'wp_stat_notice_custom_page');
        }
    }

    // Hooks beim Design-System des Toolkits anmelden (lädt das gemeinsame CSS)
    if (function_exists('wpmt_register_admin_hook')) {
        foreach ($hooks as $hook) {
            wpmt_register_admin_hook($hook);
        }
    }
}
add_action('admin_menu', 'wp_multi_register_admin_menus', 20);


