<?php

// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Bidda Admin Class
 * 
 * This class defines all code necessary to run during the admin area of the site
 */
class Bidda_Admin {
    
    /**
     * Add admin menu for the plugin
     */
    public function add_admin_menu() {
        // Add main menu
        add_menu_page(
            'Bidda School Management',           // Page title
            'Bidda School',                      // Menu title
            'manage_options',                    // Capability
            'bidda-school-management',           // Menu slug
            array($this, 'admin_dashboard'),     // Function
            'dashicons-welcome-learn-more',      // Icon
            6                                    // Position
        );
        
        // Add submenu items
        add_submenu_page(
            'bidda-school-management',
            'Dashboard',
            'Dashboard',
            'manage_options',
            'bidda-school-management',
            array($this, 'admin_dashboard')
        );
        
        add_submenu_page(
            'bidda-school-management',
            'Settings',
            'Settings',
            'manage_options',
            'bidda-settings',
            array($this, 'admin_settings')
        );
    }
    
    /**
     * Add settings link to plugin page
     */
    public function add_settings_link($links) {
        $settings_link = '<a href="admin.php?page=bidda-settings">Settings</a>';
        array_push($links, $settings_link);
        return $links;
    }
    
    /**
     * Display admin dashboard
     */
    public function admin_dashboard() {
        echo '<div class="wrap">';
        echo '<h1>Bidda School Management Dashboard</h1>';
        echo '<p>Welcome to the Bidda School Management System.</p>';
        echo '<p>This system integrates your existing Bidda application with WordPress.</p>';
        echo '<h2>Getting Started</h2>';
        echo '<ol>';
        echo '<li>Configure your database settings in the Settings page</li>';
        echo '<li>Use shortcodes to embed Bidda pages in your WordPress posts/pages</li>';
        echo '<li>Access your Bidda application through the WordPress admin menu</li>';
        echo '</ol>';
        echo '</div>';
    }
    
    /**
     * Display admin settings
     */
    public function admin_settings() {
        echo '<div class="wrap">';
        echo '<h1>Bidda School Management Settings</h1>';
        echo '<form method="post" action="options.php">';
        echo '<table class="form-table">';
        echo '<tr>';
        echo '<th scope="row">Database Host</th>';
        echo '<td><input type="text" name="bidda_db_host" value="localhost" class="regular-text" /></td>';
        echo '</tr>';
        echo '<tr>';
        echo '<th scope="row">Database Name</th>';
        echo '<td><input type="text" name="bidda_db_name" value="school_management" class="regular-text" /></td>';
        echo '</tr>';
        echo '<tr>';
        echo '<th scope="row">Database Username</th>';
        echo '<td><input type="text" name="bidda_db_user" value="root" class="regular-text" /></td>';
        echo '</tr>';
        echo '<tr>';
        echo '<th scope="row">Database Password</th>';
        echo '<td><input type="password" name="bidda_db_pass" value="" class="regular-text" /></td>';
        echo '</tr>';
        echo '<tr>';
        echo '<th scope="row">Bidda Installation Path</th>';
        echo '<td><input type="text" name="bidda_install_path" value="' . ABSPATH . 'bidda/" class="regular-text" /></td>';
        echo '</tr>';
        echo '</table>';
        echo '<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes"></p>';
        echo '</form>';
        echo '</div>';
    }
}