<?php
/**
 * CONTEXTUAL BACK BUTTON HELPER
 * 
 * Generates appropriate back button based on user type
 * - Full admins: Back to admin_dashboard.php
 * - Sub-admins: Back to subadmin_dashboard.php
 * 
 * Usage in admin pages:
 *   require_once __DIR__ . '/get_back_button.php';
 *   echo getBackButton('← Back');
 */

/**
 * Get contextual back button HTML
 * 
 * @param string $label Button label (default: "← Back")
 * @param string $cssClass CSS class for styling (default: "btn")
 * @return string HTML for back button
 */
function getBackButton($label = '← Back', $cssClass = 'btn') {
    $href = 'admin_dashboard.php'; // Default for full admins
    
    // Check if sub-admin
    if (isset($_SESSION['is_subadmin']) && $_SESSION['is_subadmin'] === true) {
        $href = 'subadmin_dashboard.php';
    }
    
    return '<a href="' . htmlspecialchars($href) . '" class="' . htmlspecialchars($cssClass) . '" style="background:#F07E2D; color:#fff; text-decoration:none; padding:8px 12px; border-radius:6px; display:inline-block;">' . htmlspecialchars($label) . '</a>';
}

/**
 * Get back button URL only (without HTML)
 * 
 * @return string Back URL
 */
function getBackUrl() {
    if (isset($_SESSION['is_subadmin']) && $_SESSION['is_subadmin'] === true) {
        return 'subadmin_dashboard.php';
    }
    return 'admin_dashboard.php';
}

/**
 * Check if current user is sub-admin
 * 
 * @return bool
 */
function isCurrentUserSubadmin() {
    return isset($_SESSION['is_subadmin']) && $_SESSION['is_subadmin'] === true;
}

?>
