<?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__('Forms & Contacts', 'termin-kalender'), 'termin_kalender_forms', [self::class, 'render_forms_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 team coordination:', 'termin-kalender')],
            ['list' => [
                ['label' => __('To-Do List', 'termin-kalender'), 'text' => __('Personal to-do lists and flexible task delegation. Tasks with a due date appear automatically in the calendar. Undated requests from contact forms are collected here.', 'termin-kalender')],
                ['label' => __('Team Messages', 'termin-kalender'), 'text' => __('Internal message board. Messages with a date and location instantly become calendar appointments, such as team meetings or team tasks.', 'termin-kalender')],
                ['label' => __('Teams - Workgroups', 'termin-kalender'), 'text' => __('Create teams with WordPress users or secure login access. Work together on shared boards with tasks and messages.', 'termin-kalender')],
                ['label' => __('Calendar Editors', 'termin-kalender'), 'text' => __('Assign trusted members to manage the calendar. Full editing access, with optional delete control.', 'termin-kalender')],
            ]],
        ]
    ],
    'calendar_views' => [
        'title' => __('Calendar Views', 'termin-kalender'),
        'blocks' => [
            ['text' => __('All ways to display and integrate calendars:', 'termin-kalender')],
            ['list' => [
                ['label' => __('iCal & Google (Display)', 'termin-kalender'), 'text' => __('Subscribe to external feeds (Google, Apple) and display automatically updated external calendars on your website.', 'termin-kalender')],
                ['label' => __('iCal Feed (Export)', 'termin-kalender'), 'text' => __('Provide users with .ics subscription links — your selected calendar data automatically appear on every smartphone.', 'termin-kalender')],
                ['label' => __('Add Your Own', 'termin-kalender'), 'text' => __('Primary users can overlay a private calendar in the backend only — to spot scheduling conflicts at a glance.', 'termin-kalender')],
                ['label' => __('Editable Frontend', 'termin-kalender'), 'text' => __('Calendar editors manage appointments directly on 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 on your website.', 'termin-kalender'),
                     'text' => __('Subscribe to external calendar feeds (Google, Apple, Outlook, etc.) and display their events continuously and automatically updated in your frontend calendar.  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 selected 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 for calendar editors. Manage appointments directly on the website – no WordPress backend required. Team members work on their own team boards.', '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 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 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 or team tools. Team members see it in the frontend 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' => __('Safe calendar backups.', 'termin-kalender'),
                     'text' => __('Save selected parts of the calendar anytime. Restore only what’s needed – for example only appointments or only to-dos – while everything else stays unchanged. Perfect before changes or updates.', '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 runs manually only when opening this tab – lightweight and resource-friendly, never 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' => __('Flexible form builder for appointments and requests.', 'termin-kalender'),
                     'text' => __('Create custom forms for reservations, requests, or simple contact messages. Add fields and adjust the design as needed.', 'termin-kalender')],
                    ['heading' => __('Smart handling:', 'termin-kalender')],
                    ['text' => __('Forms without a date are saved as to-dos for calendar editors. Forms with a date appear directly as appointments in the calendar. Simple and flexible – for requests or bookings.', 'termin-kalender')],
                    ['heading' => __('Soft blocking for resources:', 'termin-kalender')],
                    ['text' => __('Use a “..Booked” category to mark resources like rooms or vehicles. Requested dates are checked against existing appointments. If there’s a conflict, a notice is shown – the request can still be sent.', 'termin-kalender')],
                ]
            ],
            'subscribers' => [
                'title' => __('Newsletter Subscribers', 'termin-kalender'),
                'blocks' => [
                    ['bold' => __('Collect newsletter subscribers directly through your forms.', 'termin-kalender'),
                     'text' => __('Add an optional opt-in checkbox to any contact or reservation form. Visitors can subscribe to your newsletter with one click while submitting the form — no extra plugins required.', 'termin-kalender')],
                    ['heading' => __('Central Subscriber List:', 'termin-kalender')],
                    ['text' => __('Manage all sign-ups in one clear list, including their name, email, date, and the specific form they used.', 'termin-kalender')],
                    ['heading' => __('Universal CSV Export:', 'termin-kalender')],
                    ['text' => __('Export your subscriber list with a single click as a CSV file. It is fully compatible and ready to be imported into any popular newsletter tool like Mailchimp, Brevo, CleverReach, MailerLite, or simply Excel.', 'termin-kalender')],
                    ['heading' => __('Privacy Friendly (GDPR):', 'termin-kalender')],
                    ['text' => __('The explicit opt-in checkbox ensures you collect subscribers with clear consent and stay fully GDPR compliant.', 'termin-kalender')],
                ]
            ],
            // ── Setup: Welcome ─────────────────────────────────────────
    'setup_welcome' => [
        'title' => __('What Termin-Kalender PRO offers', 'termin-kalender'),
        'blocks' => [
            ['bold' => __('The admin calendar becomes an intelligent hub.', 'termin-kalender'),
             'text' => __('Not just manually created appointments flow into the admin calendar — dated form submissions (reservations), scheduled tasks (deadlines) and team meetings all follow automatically.', 'termin-kalender')],
            ['heading' => __('What Termin-Kalender PRO offers:', 'termin-kalender')],
            ['list' => [
                ['label' => __('Recurring Events', 'termin-kalender'), 'text' => __('Create complex, recurring appointment 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 to navigate.', 'termin-kalender')],
                ['label' => __('Event Posts', 'termin-kalender'), 'text' => __('With one click, turn any appointment into a full WordPress post with images, text and content. Calendar changes like dates automatically update the post — and every post is independently indexable 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 individuals. Without a date, a to-do stays as an open task — add a due date and it appears automatically in the calendar.', 'termin-kalender')],
                ['label' => __('Team Messages', 'termin-kalender'), 'text' => __('Internal team communication. Add a date & location to any message and it instantly becomes a meeting or work assignment — automatically shown in the calendar.', 'termin-kalender')],
            ]],
            ['heading' => __('Smart Assistant (AI Panel):', 'termin-kalender')],
            ['list' => [
                ['label' => __('Smart Briefing', 'termin-kalender'), 'text' => __('The digital assistant summarizes upcoming appointments, open tasks and new team messages in a natural-language daily report.', 'termin-kalender')],
                ['label' => __('Smart 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 — built-in onboarding covers all modules step by step.', '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_forms_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],
            'form_builder' => ['title' => __('Form Builder', 'termin-kalender'), 'is_pro' => true],
            'subscribers' => ['title' => __('Subscribers', 'termin-kalender'), 'is_pro' => true]
        ];

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

        if (in_array($current_tab, ['overview', 'form_builder', 'subscribers'], true)) {
            $map = ['overview' => 'reservation_form', 'form_builder' => 'reservation_form', 'subscribers' => 'subscribers'];
            $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_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]);
            }
        }
    }
}
