<?php
/**
 * Admin Menu and Plugin Page functionality
 */

// Prevent direct access to this file
if (!defined('ABSPATH')) {
    exit;
}

// Include menu configuration
require_once plugin_dir_path(__FILE__) . '../includes/menu-config.php';

// Add admin menu and plugin page
function smartpress_admin_menu() {
    $menu_items = smartpress_get_menu_config();
    $first_item = reset($menu_items);

    // Add main menu page
    add_menu_page(
        esc_html__('SmartPress', 'smartpress-pro'), // Page title
        esc_html__('SmartPress', 'smartpress-pro'),  // Menu title
        'manage_options', // Capability
        SMARTPRESS_MENU_SLUG,     // Menu slug
        'smartpress_page', // Callback function
        plugins_url('../assets/smart-press-logo-150.png', __FILE__), // Icon URL
        4 // Position
    );

    // Add submenu pages
    foreach ($menu_items as $item) {
        $slug = SMARTPRESS_MENU_SLUG . $item['slug'];
        
        // Skip the main page as it's already added
        if ($slug !== SMARTPRESS_MENU_SLUG) {
            add_submenu_page(
                SMARTPRESS_MENU_SLUG,    // Parent slug
                esc_html($item['title']),        // Page title
                esc_html($item['title']),        // Menu title
                'manage_options',       // Capability
                $slug,                 // Menu slug
                'smartpress_page'      // Callback function
            );
        }
    }
}
add_action('admin_menu', 'smartpress_admin_menu');

// Callback function to display the plugin page
function smartpress_page() {
    ?>
    <div class="wrap">
        <!-- <h1>SmartPress Settings</h1> -->
        <div id="vue-wp-app-container">
            <!-- Vue app will mount here -->
            <div id="vue-wp-app"></div>
        </div>
    </div>
    <?php
} 