<?php
// admin/index.php

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

add_action('admin_menu', 'trfx_add_upgrade_menu');

function trfx_add_upgrade_menu() {
    if (function_exists('tlr_fs') && !tlr_fs()->is_paying()) {

        // Ensure top-level menu exists
        add_menu_page(
            'Trifuxion Tools',
            'Trifuxion Tools',
            'manage_options',
            'trifuxion-tools-repeater',
            'trfx_main_page_callback',
            'dashicons-screenoptions',
            65
        );

        // Add Upgrade submenu
        add_submenu_page(
            'trifuxion-tools-repeater',
            'Upgrade to Pro',
            'Upgrade to Pro',
            'manage_options',
            'trfx-upgrade',
            'trfx_render_upgrade_page'
        );
    }
}

function trfx_main_page_callback() {
    echo '<div class="wrap"><h1>Trifuxion Tools</h1><p>Use this page to manage your ACF repeater displays.</p></div>';
}

function trfx_render_upgrade_page() {
    echo '<div class="wrap"><h1>Upgrade to Pro</h1>';
    
    if ( function_exists('tlr_fs') ) {
        echo '<p>Thank you for using Trifuxion Tools - Repeater! To unlock Pro features like Carousel and Card Grid, please upgrade below.</p>';
        tlr_fs()->get_upgrade_link_html('Upgrade Now');
    } else {
        echo '<p>Freemius is not initialized.</p>';
    }

    echo '</div>';
}
