<?php
/**
 * Merges all menu groups, tabbed views, and callbacks into one centralized file for the Free version.
 */
defined('ABSPATH') || exit;

class Termin_Kalender_Admin_Menu
{
    public static function init()
    {
        // Use priority 20 so it runs after the main page is registered in class-termin-kalender-admin-page.php
        add_action('admin_menu', [self::class, 'register_menu_with_groups'], 20);
    }

    public static function register_menu_with_groups()
    {
        // If PRO is active, it handles the entire sub-menu structure itself (at priority 99).
        // Free must step aside to prevent duplicates and tab mixing.
        if (defined('TERMIN_KALENDER_PRO_ON')) {
            return;
        }

        $parent_slug = 'termin-kalender';
        $capability = 'termin_kalender_edit';

        // --- SETUP ---
        self::add_free_subpage(esc_html__('Setup & Help', 'termin-kalender') . ' <span class="label label-free">FREE</span>', 'termin_kalender_setup', [self::class, 'render_setup_tabs']);

        // --- INPUT: Tools that feed INTO the calendar ---
        self::add_free_subpage(esc_html__('Team Tools', 'termin-kalender'), 'termin_kalender_team_tools', [self::class, 'render_team_tabs']);
        self::add_free_subpage(esc_html__('Reservation Form', 'termin-kalender'), 'termin_kalender_reservation_form', [self::class, 'render_reservation_tabs']);

        // --- OUTPUT: Views that display FROM the calendar ---
        self::add_free_subpage(esc_html__('Calendar Views', 'termin-kalender') . ' <span class="label label-free">FREE</span>', 'termin_kalender_calendar_views', [self::class, 'render_calendar_tabs']);
        self::add_free_subpage(esc_html__('List Views', 'termin-kalender') . ' <span class="label label-free">FREE</span>', 'termin_kalender_list_views', [self::class, 'render_list_tabs']);
        self::add_free_subpage(esc_html__('WP Event Posts', 'termin-kalender'), 'termin_kalender_event_posts', [self::class, 'render_event_posts_tabs']);

        // --- SYSTEM ---
        self::add_free_subpage(esc_html__('System', 'termin-kalender'), 'termin_kalender_system', [self::class, 'render_system_tabs']);
    }

    private static function add_free_subpage($title, $slug, $callback, $cap = 'termin_kalender_edit')
    {
        // Strip HTML badges for the page <title> tag (plain text only).
        $page_title = wp_strip_all_tags($title);
        $suffix = add_submenu_page(
            'termin-kalender',
            $page_title,
            $title,
            $cap,
            $slug,
            $callback
        );
        // Ensure it's tracked for enqueuing assets
        Termin_Kalender_Plugin::$ter_kal_admin_pages_hook_suffixes[$slug] = $suffix;
        Termin_Kalender_Plugin::$ter_kal_admin_pages_hook_suffixes[] = $suffix; // Safe fallback
    }

    // ==========================================
    // RENDER TAB CONTAINERS
    // ==========================================

    private static function render_tab_nav($current_tab, $tabs, $page_slug)
    {
        echo '<div class="wrap"><h2 class="nav-tab-wrapper">';
        foreach ($tabs as $tab_key => $tab_data) {
            $active = ($current_tab == $tab_key) ? 'nav-tab-active' : '';
            $url = admin_url('admin.php?page=' . $page_slug . '&tab=' . $tab_key);

            $allowed_badge = array( 'span' => array( 'class' => array() ) );
            $badge = isset($tab_data['is_pro']) && $tab_data['is_pro'] ? ' <span class="label label-pro">PRO</span>' : '';
            $badge_beta = isset($tab_data['is_beta']) && $tab_data['is_beta'] ? ' <span class="label label-beta">BETA</span>' : '';
            $badge_legacy = isset($tab_data['is_legacy']) && $tab_data['is_legacy'] ? ' <span class="label label-legacy">LEGACY</span>' : '';
            $badge_free = isset($tab_data['is_free']) && $tab_data['is_free'] ? ' <span class="label label-free">FREE</span>' : '';
            $badge_trial = isset($tab_data['is_trial']) && $tab_data['is_trial'] ? ' <span class="label label-free">TRY FREE</span>' : '';

            echo '<a href="' . esc_url($url) . '" class="nav-tab ' . esc_attr($active) . '">' . esc_html($tab_data['title']) . wp_kses($badge, $allowed_badge) . wp_kses($badge_beta, $allowed_badge) . wp_kses($badge_legacy, $allowed_badge) . wp_kses($badge_free, $allowed_badge) .wp_kses($badge_trial, $allowed_badge) . '</a>';
        }
        echo '</h2></div>';
    }

    private static function render_pro_teaser($title, $content_blocks = [], $tab_id = '')
    {
        // Automatically build the filename based on the internal tab ID (e.g. 'messages' -> 'messages.webp')
        $image_url = $tab_id ? 'https://ps.w.org/termin-kalender/assets/tabs/' . esc_attr(str_replace('_', '-', $tab_id)) . '.webp?ver='.Termin_Kalender_Plugin::TER_KAL_TK_VERSION : '';
        ?>
        <div class="wrap termin-kalender-admin-container">
            <div class="termin-kalender-admin-box-white termin-kalender-pro-teaser-box">
                <h2 class="termin-kalender-pro-teaser-title"><span class="dashicons dashicons-lock termin-kalender-pro-teaser-icon"></span><?php echo esc_html($title); ?>
                </h2>
                <div class="termin-kalender-pro-teaser-content">
                    <?php
                    foreach ($content_blocks as $block) {
                        if (isset($block['bold'])) {
                            echo '<p><strong>' . esc_html($block['bold']) . '</strong>';
                            if (isset($block['text'])) {
                                echo ' ' . esc_html($block['text']);
                            }
                            echo '</p>';
                        } elseif (isset($block['text'])) {
                            echo '<p>' . esc_html($block['text']) . '</p>';
                        } elseif (isset($block['heading'])) {
                            echo '<p><strong>' . esc_html($block['heading']) . '</strong></p>';
                        } elseif (isset($block['list'])) {
                            echo '<ul class="termin-kalender-pro-teaser-list">';
                            foreach ($block['list'] as $item) {
                                echo '<li><strong>' . esc_html($item['label']) . ':</strong> ' . esc_html($item['text']) . '</li>';
                            }
                            echo '</ul>';
                        } elseif (isset($block['numbered'])) {
                            echo '<ol class="termin-kalender-pro-teaser-list">';
                            foreach ($block['numbered'] as $item) {
                                echo '<li><strong>' . esc_html($item['label']) . ':</strong> ' . esc_html($item['text']) . '</li>';
                            }
                            echo '</ol>';
                        } elseif (isset($block['note'])) {
                            echo '<p><em>' . esc_html($block['note']) . '</em></p>';
                        }
                    }
                    ?>
                </div>
                
                <div style="margin-bottom: 20px;">
                    <a href="<?php echo esc_url(admin_url('admin.php?page=termin_kalender_setup&tab=pro_info')); ?>"
                        class="button button-primary button-hero"><?php esc_html_e('Upgrade to Termin-Kalender PRO', 'termin-kalender'); ?></a>
                </div>

                <?php if ($image_url): ?>
                <div class="termin-kalender-pro-teaser-image-wrapper" style="text-align: center; margin-top: 15px; padding-top: 20px; border-top: 1px solid #eee;">
                    <img src="<?php echo esc_url($image_url); ?>" 
                         alt="<?php echo esc_attr($title); ?> Preview"
                         class="termin-kalender-pro-tab-image"
                         style="max-width: 90%; height: auto; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);"
                         onerror="this.style.display='none'; this.parentElement.style.display='none';">
                </div>
                <?php endif; ?>
            </div>
        </div>
        <?php
    }

    /**
     * Returns structured content blocks for any tab.
     * Public so PRO can consume the same descriptions in its onboarding cards.
     *
     * @param string $section Section key (e.g. 'team_tools', 'todo', 'ical_display').
     * @return array|null Array with 'title' and 'blocks' keys, or null if unknown section.
     */
    public static function get_content_blocks($section)
    {
        $sections = [
            // ── Overview Sections ──────────────────────────────────────
            'team_tools' => [
                'title' => __('Team Tools', 'termin-kalender'),
                'blocks' => [
                    ['text' => __('The lightweight command center for all team coordination:', 'termin-kalender')],
                    ['list' => [
                        ['label' => __('To-Do List', 'termin-kalender'), 'text' => __('Delegate tasks to teams or individuals. When a date is added, they intelligently appear as events in the calendar. Contact forms land here automatically.', 'termin-kalender')],
                        ['label' => __('Team Messages', 'termin-kalender'), 'text' => __('Internal message board. Messages with a date and location instantly become calendar meetings.', 'termin-kalender')],
                        ['label' => __('Teams - Workgroups', 'termin-kalender'), 'text' => __('User teams or password boards for secure exchange in the frontend.', 'termin-kalender')],
                        ['label' => __('Calendar Editors', 'termin-kalender'), 'text' => __('5-level permission system from admin to simple team member in the frontend.', 'termin-kalender')],
                    ]],
                ]
            ],
            'calendar_views' => [
                'title' => __('Calendar Views', 'termin-kalender'),
                'blocks' => [
                    ['text' => __('All ways to display and connect calendars:', 'termin-kalender')],
                    ['list' => [
                        ['label' => __('iCal & Google (Display)', 'termin-kalender'), 'text' => __('Subscribe to external feeds (Google, Apple) and display external events automatically updated in the frontend calendar.', 'termin-kalender')],
                        ['label' => __('iCal Feed (Export)', 'termin-kalender'), 'text' => __('Provide your users with .ics subscription links – your events land automatically on every smartphone.', 'termin-kalender')],
                        ['label' => __('Add Your Own', 'termin-kalender'), 'text' => __('Primary users overlay their private calendar exclusively in the backend to identify scheduling conflicts.', 'termin-kalender')],
                        ['label' => __('Editable Frontend', 'termin-kalender'), 'text' => __('Calendar editors manage events directly via the website, without entering the backend.', 'termin-kalender')],
                    ]],
                ]
            ],
            'list_views' => [
                'title' => __('Lists & Widgets', 'termin-kalender'),
                'blocks' => [
                    ['text' => __('Turn events into impressive lists for your website:', 'termin-kalender')],
                    ['list' => [
                        ['label' => __('Category List', 'termin-kalender'), 'text' => __('Scalable premium layouts (cards, accordions) as impressive main elements on pages or compact as sidebar widgets.', 'termin-kalender')],
                        ['label' => __('iCal List', 'termin-kalender'), 'text' => __('Display external .ics feeds (holidays, schedules) as structured lists using the same premium layouts.', 'termin-kalender')],
                    ]],
                ]
            ],
            'system' => [
                'title' => __('System & Maintenance', 'termin-kalender'),
                'blocks' => [
                    ['text' => __('The central hub for the technical maintenance of your application:', 'termin-kalender')],
                    ['list' => [
                        ['label' => __('Backup', 'termin-kalender'), 'text' => __('Selective snapshots – safely restore only specific parts (e.g. only to-dos).', 'termin-kalender')],
                        ['label' => __('System & Info', 'termin-kalender'), 'text' => __('Crash protection automatically deactivates faulty internal modules.', 'termin-kalender')],
                        ['label' => __('Calendar Data Check', 'termin-kalender'), 'text' => __('Scans and repairs orphaned entries, faulty recurrence rules and inconsistencies.', 'termin-kalender')],
                    ]],
                ]
            ],
            // ── Calendar Views: Individual Tabs ────────────────────────
            'ical_display' => [
                'title' => __('iCal & Google (Display)', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('Display external calendars in the frontend.', 'termin-kalender'),
                     'text' => __('Subscribe to external calendar feeds (Google, Apple, Outlook, etc.) and display their events continuously and automatically updated in your frontend calendar. Imported events are assigned to a category of your choice and are therefore immediately color-coded and visually integrated. Ideal for holidays, school breaks, league schedules or external team calendars.', 'termin-kalender')],
                ]
            ],
            'ical_feed' => [
                'title' => __('iCal Feed (Export)', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('Your events on every smartphone.', 'termin-kalender'),
                     'text' => __('Generate .ics subscription links for individual categories or the entire calendar. Customers, club members or parents subscribe to this link once and from then on always have all events from your website automatically and up-to-date in their private calendar app (Apple Calendar, Google Calendar, Outlook). Changes on the website are synchronized automatically.', 'termin-kalender')],
                ]
            ],
            'connect' => [
                'title' => __('Add Your Own (Connect)', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('Prevent private and business scheduling conflicts.', 'termin-kalender'),
                     'text' => __('Primary users can exclusively overlay their private or business Apple/Google calendar into the backend calendar view. These events are invisible to visitors but help you immediately identify overlaps between e.g. private and organization events during planning, without having to switch between different apps.', 'termin-kalender')],
                ]
            ],
            'calendar_editable' => [
                'title' => __('Editable Frontend Calendar', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('The editable calendar for your editors.', 'termin-kalender'),
                     'text' => __('An interactive frontend calendar designed strictly for calendar editors. They can create, edit and manage events directly on the website – without ever having to enter the technical WordPress backend. Simple team members receive calendar views or lists in the frontend instead (via Category List or Shortcode).', 'termin-kalender')],
                ]
            ],
            // ── List Views: Individual Tabs ────────────────────────────
            'category_list' => [
                'title' => __('Category List', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('Premium categorized lists & cards.', 'termin-kalender'),
                     'text' => __('Scalable premium layouts such as cards, detail views or compact accordions, filtered by categories. These responsive designs work equally well as an impressive main element on your pages (e.g. "All Courses Overview") or as a compact sidebar widget (e.g. "Next 5 Training Sessions"). Just as professional on smartphones as on desktop.', 'termin-kalender')],
                ]
            ],
            'ical_list' => [
                'title' => __('iCal List', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('External feeds as structured lists.', 'termin-kalender'),
                     'text' => __('Present external calendar feeds (.ics) as a list on your website. Use the same scalable premium layouts (cards, accordions) as for your own events. Perfect for displaying external game schedules, holidays or school breaks seamlessly and automatically updated on your site.', 'termin-kalender')],
                ]
            ],
            // ── Team Tools: Individual Tabs ────────────────────────────
            'todo' => [
                'title' => __('To-Do List', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('Process and delegate tasks in a structured way.', 'termin-kalender'),
                     'text' => __('Use the to-do list as a personal priority list or assign tasks directly to specific teams or individual members. Incoming contact forms without a date automatically land here for processing.', 'termin-kalender')],
                    ['heading' => __('The intelligent automation:', 'termin-kalender')],
                    ['text' => __('A to-do without a date remains as an open task in the list. However, as soon as you assign a date to it (e.g. as a deadline), it immediately appears automatically as an event in the central admin calendar – the hub for all scheduled activities.', 'termin-kalender')],
                ]
            ],
            'messages' => [
                'title' => __('Team Messages', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('The digital message board for internal coordination.', 'termin-kalender'),
                     'text' => __('Team members or editors exchange information, announcements and agreements centrally.', 'termin-kalender')],
                    ['heading' => __('The intelligent automation:', 'termin-kalender')],
                    ['text' => __('A simple text message remains pure information. However, if team members or editors add a date and location to the message, it immediately transforms into a meeting, team event or work assignment.', 'termin-kalender')],
                    ['heading' => __('Visibility:', 'termin-kalender')],
                    ['text' => __('Authorized editors see this assignment in the backend admin calendar. Simple team members see it securely separated in the frontend (via Category List or Team Board).', 'termin-kalender')],
                ]
            ],
            'teams' => [
                'title' => __('Teams - Workgroups', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('Create logical groups for your members.', 'termin-kalender'),
                     'text' => __('You can set up user teams (WordPress accounts) or password boards (for groups without a WordPress account). In both cases, team members exchange tasks and messages within their board in the frontend. They never see the technical backend and require zero training.', 'termin-kalender')],
                ]
            ],
            'editors' => [
                'title' => __('Calendar Editors', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('Precise 5-level permission system:', 'termin-kalender')],
                    ['numbered' => [
                        ['label' => __('Admins & Calendar Creators', 'termin-kalender'), 'text' => __('Absolute full access to the entire system.', 'termin-kalender')],
                        ['label' => __('Calendar Editors (with delete rights)', 'termin-kalender'), 'text' => __('Nearly all rights, including deleting events.', 'termin-kalender')],
                        ['label' => __('Calendar Editors (edit only)', 'termin-kalender'), 'text' => __('Can edit events but have no delete rights.', 'termin-kalender')],
                        ['label' => __('Team Members', 'termin-kalender'), 'text' => __('WordPress users with access to their frontend team board (to-dos & messages).', 'termin-kalender')],
                        ['label' => __('Password Boards', 'termin-kalender'), 'text' => __('Exchange for groups without a WordPress account, protected by page password.', 'termin-kalender')],
                    ]],
                ]
            ],
            // ── System: Individual Tabs ────────────────────────────────
            'backup' => [
                'title' => __('Backup', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('Selective, plugin-specific backups.', 'termin-kalender'),
                     'text' => __('Create targeted snapshots of your event data directly within the plugin. You can restore only specific parts extremely safely and precisely (e.g. only to-dos or only events) without overwriting other newer data. Ideal after major changes or before migrations.', 'termin-kalender')],
                ]
            ],
            'status' => [
                'title' => __('System & Info / Status', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('Automatic crash protection.', 'termin-kalender'),
                     'text' => __('An intelligent system that automatically deactivates and isolates faulty internal modules when problems occur, preventing a crash of the plugin or the entire WordPress website.', 'termin-kalender')],
                ]
            ],
            'auditor' => [
                'title' => __('Calendar Data Check', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('Proactive data maintenance.', 'termin-kalender'),
                     'text' => __('The auditor scans for orphaned entries, faulty recurrence rules or database inconsistencies. With the "Repair" function you keep your database automatically clean for maximum stability. The scan deliberately runs only manually when opening this tab, not in the background.', 'termin-kalender')],
                ]
            ],
            // ── Standalone Tabs ────────────────────────────────────────
            'event_posts' => [
                'title' => __('Event Posts (SEO & Marketing)', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('The ultimate SEO tool for your events.', 'termin-kalender'),
                     'text' => __('Automatically convert selected events into native WordPress posts. Each event gets its own full landing page with extensive content, images and text. Crucially: native posts are created – not Custom Post Types – meaning you can use any page builder (Gutenberg, Elementor, etc.) and are not tied to a plugin format. As a massive automatic side effect, your website receives a strong SEO boost in Google, since each event exists as an independent, indexable post. The system synchronizes changes fully automatically.', 'termin-kalender')],
                ]
            ],
            'reservation_form' => [
                'title' => __('Reservation Form (Smart Forms)', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('Your industry-specific form builder.', 'termin-kalender'),
                     'text' => __('A highly flexible configurator with industry-specific templates (e.g. car rental, table reservation, medical practice). Create any number of custom fields and customize the design.', 'termin-kalender')],
                    ['heading' => __('The intelligent automation:', 'termin-kalender')],
                    ['text' => __('If the form requires no date, it acts as a contact form – the inquiry lands as a to-do for your team to process. If it requires a date, it becomes a booking system – the submission immediately appears as a reservation in the central admin calendar.', 'termin-kalender')],
                    ['heading' => __('Soft Blocking:', 'termin-kalender')],
                    ['text' => __('Using a "Booked" category, specific resources (e.g. a room, a vehicle) can be intelligently protected against date overlaps. The user receives a notification about the conflict and can decide whether to submit a request anyway.', 'termin-kalender')],
                ]
            ],
            // ── Setup: Welcome ─────────────────────────────────────────
            'setup_welcome' => [
                'title' => __('What does Termin-Kalender PRO offer?', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('Your admin calendar becomes an intelligent hub.', 'termin-kalender'),
                     'text' => __('Through cross-module automation, not only manually created events flow in, but also dated form submissions (reservations), scheduled tasks (deadlines) and team meetings – all automatically and without any manual effort in one central place.', 'termin-kalender')],
                    ['heading' => __('Major Calendar Upgrades:', 'termin-kalender')],
                    ['list' => [
                        ['label' => __('Recurring Events', 'termin-kalender'), 'text' => __('Create complex, recurring event series (weekly, monthly, etc.) with just a few clicks.', 'termin-kalender')],
                        ['label' => __('Google Maps Links', 'termin-kalender'), 'text' => __('Venue locations are directly linked for attendees – one click is all it takes to navigate.', 'termin-kalender')],
                        ['label' => __('Event Posts', 'termin-kalender'), 'text' => __('Create full WordPress posts directly from the calendar entry form for maximum SEO reach.', 'termin-kalender')],
                    ]],
                    ['heading' => __('Lightweight Team Coordination:', 'termin-kalender')],
                    ['list' => [
                        ['label' => __('To-Dos & Delegation', 'termin-kalender'), 'text' => __('Assign tasks to teams or individual members.', 'termin-kalender')],
                        ['label' => __('Team Messages', 'termin-kalender'), 'text' => __('Internal communication that instantly turns into calendar meetings when needed.', 'termin-kalender')],
                        ['label' => __('5-Level Permission System', 'termin-kalender'), 'text' => __('From admin through calendar editors (with/without delete rights) to simple team members in the frontend.', 'termin-kalender')],
                    ]],
                    ['heading' => __('Intelligent Assistant (AI Panel):', 'termin-kalender')],
                    ['list' => [
                        ['label' => __('Smart Briefing', 'termin-kalender'), 'text' => __('Your digital assistant summarizes upcoming events, open tasks and new team messages in a natural-language daily report.', 'termin-kalender')],
                        ['label' => __('Magic Search', 'termin-kalender'), 'text' => __('Ultra-fast live search across all calendar entries, to-dos and messages.', 'termin-kalender')],
                    ]],
                    ['note' => __('Get started in minutes, not hours: The built-in onboarding guides you through all modules.', 'termin-kalender')],
                ]
            ],
        ];

        return isset($sections[$section]) ? $sections[$section] : null;
    }

    public static function render_setup_tabs()
    {
        $current_tab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'categories'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only tab navigation
        $tabs = [
            'welcome' => ['title' => __('Info & Start', 'termin-kalender'), 'is_pro' => true],
            'categories' => ['title' => __('Categories Setup', 'termin-kalender'), 'is_free' => true],
            'pro_info' => ['title' => __('PRO Info', 'termin-kalender'), 'is_trial' => true]
        ];

        self::render_tab_nav($current_tab, $tabs, 'termin_kalender_setup');

        if ($current_tab === 'categories' && function_exists('termin_kalender_render_initial_setup_admin_menu_page')) {
            termin_kalender_render_initial_setup_admin_menu_page();
        } elseif ($current_tab === 'welcome') {
            $content = self::get_content_blocks('setup_welcome');
            if ($content) {
                self::render_pro_teaser($content['title'], $content['blocks'], 'setup_welcome');
            }
        } elseif ($current_tab === 'pro_info' && function_exists('termin_kalender_render_block_pro_info_admin_menu_page')) {
            termin_kalender_render_block_pro_info_admin_menu_page();
        }
    }

    public static function render_calendar_tabs()
    {
        $current_tab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'calendar'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only tab navigation
        $tabs = [
            'overview' => ['title' => __('Overview', 'termin-kalender'), 'is_pro' => true],
            'calendar' => ['title' => __('Calendar', 'termin-kalender'), 'is_free' => true],
            'display' => ['title' => __('iCal & Google', 'termin-kalender'), 'is_pro' => true],
            'feed' => ['title' => __('iCal Feed', 'termin-kalender'), 'is_pro' => true],
            'connect' => ['title' => __('Add Your', 'termin-kalender'), 'is_pro' => true],
            'calendar_editable' => ['title' => __('Editable Frontend', 'termin-kalender'), 'is_pro' => true]
        ];

        self::render_tab_nav($current_tab, $tabs, 'termin_kalender_calendar_views');

        if ($current_tab === 'calendar' && function_exists('termin_kalender_render_block_calendar_admin_menu_page')) {
            termin_kalender_render_block_calendar_admin_menu_page();
        } elseif (in_array($current_tab, ['display', 'feed', 'connect', 'calendar_editable', 'overview'], true)) {
            $map = ['display' => 'ical_display', 'feed' => 'ical_feed', 'connect' => 'connect', 'calendar_editable' => 'calendar_editable', 'overview' => 'calendar_views'];
            $content = self::get_content_blocks($map[$current_tab]);
            if ($content) {
                self::render_pro_teaser($content['title'], $content['blocks'], $map[$current_tab]);
            }
        }
    }

    public static function render_list_tabs()
    {
        $current_tab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'lists'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only tab navigation
        $tabs = [
            'overview' => ['title' => __('Overview', 'termin-kalender'), 'is_pro' => true],
            'lists' => ['title' => __('Simple List', 'termin-kalender'), 'is_free' => true],
            'category_list' => ['title' => __('Category List', 'termin-kalender'), 'is_pro' => true],
            'ical_list' => ['title' => __('iCal List', 'termin-kalender'), 'is_pro' => true]
        ];

        self::render_tab_nav($current_tab, $tabs, 'termin_kalender_list_views');

        if ($current_tab === 'lists' && function_exists('termin_kalender_render_block_simple_list_admin_menu_page')) {
            termin_kalender_render_block_simple_list_admin_menu_page();
        } elseif (in_array($current_tab, ['category_list', 'ical_list', 'overview'], true)) {
            $map = ['category_list' => 'category_list', 'ical_list' => 'ical_list', 'overview' => 'list_views'];
            $content = self::get_content_blocks($map[$current_tab]);
            if ($content) {
                self::render_pro_teaser($content['title'], $content['blocks'], $map[$current_tab]);
            }
        }
    }

    public static function render_event_posts_tabs()
    {
        $current_tab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'event_posts'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only tab navigation
        $tabs = [
            'event_posts' => ['title' => __('Event Posts', 'termin-kalender'), 'is_pro' => true]
        ];

        self::render_tab_nav($current_tab, $tabs, 'termin_kalender_event_posts');

        if ($current_tab === 'event_posts') {
            $content = self::get_content_blocks('event_posts');
            if ($content) {
                self::render_pro_teaser($content['title'], $content['blocks'], 'event_posts');
            }
        }
    }

    public static function render_reservation_tabs()
    {
        $current_tab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'reservation_form'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only tab navigation
        $tabs = [
            'reservation_form' => ['title' => __('Reservation Form', 'termin-kalender'), 'is_pro' => true]
        ];

        self::render_tab_nav($current_tab, $tabs, 'termin_kalender_reservation_form');

        if ($current_tab === 'reservation_form') {
            $content = self::get_content_blocks('reservation_form');
            if ($content) {
                self::render_pro_teaser($content['title'], $content['blocks'], 'reservation_form');
            }
        }
    }

    public static function render_team_tabs()
    {
        $current_tab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'overview'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only tab navigation
        $tabs = [
            'overview' => ['title' => __('Overview', 'termin-kalender'), 'is_pro' => true],
            'todo' => ['title' => __('To-Do List', 'termin-kalender'), 'is_pro' => true],
            'messages' => ['title' => __('Team Messages', 'termin-kalender'), 'is_pro' => true],
            'teams' => ['title' => __('Teams - Workgroups', 'termin-kalender'), 'is_pro' => true],
            'editors' => ['title' => __('Calendar Editors', 'termin-kalender'), 'is_pro' => true]
        ];

        self::render_tab_nav($current_tab, $tabs, 'termin_kalender_team_tools');

        if (in_array($current_tab, ['todo', 'messages', 'teams', 'editors', 'overview'], true)) {
            $map = ['todo' => 'todo', 'messages' => 'messages', 'teams' => 'teams', 'editors' => 'editors', 'overview' => 'team_tools'];
            $content = self::get_content_blocks($map[$current_tab]);
            if ($content) {
                self::render_pro_teaser($content['title'], $content['blocks'], $map[$current_tab]);
            }
        }
    }

    public static function render_system_tabs()
    {
        $current_tab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'overview'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only tab navigation
        $tabs = [
            'overview' => ['title' => __('Overview', 'termin-kalender'), 'is_pro' => true],
            'backup' => ['title' => __('Backup', 'termin-kalender'), 'is_pro' => true],
            'status' => ['title' => __('System & Info', 'termin-kalender'), 'is_pro' => true],
            'auditor' => ['title' => __('Calendar Data Check', 'termin-kalender'), 'is_pro' => true]
        ];

        self::render_tab_nav($current_tab, $tabs, 'termin_kalender_system');

        if (in_array($current_tab, ['backup', 'status', 'auditor', 'overview'], true)) {
            $map = ['backup' => 'backup', 'status' => 'status', 'auditor' => 'auditor', 'overview' => 'system'];
            $content = self::get_content_blocks($map[$current_tab]);
            if ($content) {
                self::render_pro_teaser($content['title'], $content['blocks'], $map[$current_tab]);
            }
        }
    }
}
