<?php
/**
 * Account dashboard template
 *
 * @link       https://yourwebsite.com
 * @since      1.0.0
 *
 * @package    Subscription_System
 * @subpackage Subscription_System/public/partials
 */

// Get user data
$user_id = $current_user->ID;
$first_name = get_user_meta($user_id, 'first_name', true);
$last_name = get_user_meta($user_id, 'last_name', true);
$email = $current_user->user_email;
$username = $current_user->user_login;
$role = implode(', ', $current_user->roles);

// Get avatar
$avatar = get_avatar($user_id, 96, '', $first_name . ' ' . $last_name);
?>

<div class="subscription-system-account-container">
    <div class="account-sidebar">
        <div class="account-header">
            <h2>My Account</h2>
        </div>
        
        <div class="account-profile">
            <div class="profile-avatar">
                <?php echo wp_kses_post($avatar); ?>
                <div class="avatar-upload">
                    <label for="profile-image-upload" class="avatar-edit">
                        <i class="dashicons dashicons-edit"></i>
                    </label>
                    <input type="file" id="profile-image-upload" accept="image/*" style="display: none;">
                </div>
            </div>
            <div class="profile-info">
                <h3><?php echo esc_html($first_name . ' ' . $last_name); ?></h3>
                <p><?php echo esc_html($email); ?></p>
            </div>
        </div>
        
        <div class="account-navigation">
            <a href="?tab=overview" class="nav-item <?php echo $active_tab === 'overview' ? 'active' : ''; ?>">
                <i class="dashicons dashicons-dashboard"></i> Account Overview
            </a>
            <a href="?tab=subscription" class="nav-item <?php echo $active_tab === 'subscription' ? 'active' : ''; ?>">
                <i class="dashicons dashicons-calendar-alt"></i> Subscription
            </a>
            <a href="?tab=history" class="nav-item <?php echo $active_tab === 'history' ? 'active' : ''; ?>">
                <i class="dashicons dashicons-list-view"></i> Subscription History
            </a>
            <a href="?tab=billing" class="nav-item <?php echo $active_tab === 'billing' ? 'active' : ''; ?>">
                <i class="dashicons dashicons-money-alt"></i> Billing Information
            </a>
            <a href="?tab=profile" class="nav-item <?php echo $active_tab === 'profile' ? 'active' : ''; ?>">
                <i class="dashicons dashicons-admin-users"></i> Edit Profile
            </a>
            <a href="?tab=worklog" class="nav-item <?php echo $active_tab === 'worklog' ? 'active' : ''; ?>">
                <i class="dashicons dashicons-clipboard"></i> Work Log
            </a>
            <a href="?tab=orders" class="nav-item <?php echo $active_tab === 'orders' ? 'active' : ''; ?>">
                <i class="dashicons dashicons-cart"></i> My Orders
            </a>
            <a href="?tab=content-subscriptions" class="nav-item <?php echo $active_tab === 'content-subscriptions' ? 'active' : ''; ?>">
                <i class="dashicons dashicons-rss"></i> Content Subscriptions
            </a>
            <a href="<?php echo esc_url(wp_logout_url(home_url())); ?>" class="nav-item">
                <i class="dashicons dashicons-exit"></i> Logout
            </a>
        </div>
    </div>
    
    <div class="account-content">
        <?php
        // Load the appropriate tab content
        switch ($active_tab) {
            case 'overview':
                include plugin_dir_path(dirname(__FILE__)) . 'partials/account-tabs/account-overview.php';
                break;
            case 'subscription':
                include plugin_dir_path(dirname(__FILE__)) . 'partials/account-tabs/account-subscription.php';
                break;
            case 'history':
                include plugin_dir_path(dirname(__FILE__)) . 'partials/account-tabs/account-history.php';
                break;
            case 'billing':
                include plugin_dir_path(dirname(__FILE__)) . 'partials/account-tabs/account-billing.php';
                break;
            case 'profile':
                include plugin_dir_path(dirname(__FILE__)) . 'partials/account-tabs/account-profile.php';
                break;
            case 'worklog':
                include plugin_dir_path(dirname(__FILE__)) . 'partials/account-tabs/account-worklog.php';
                break;
            case 'orders':
                include plugin_dir_path(dirname(__FILE__)) . 'partials/account-tabs/account-orders.php';
                break;
            case 'content-subscriptions':
                include plugin_dir_path(dirname(__FILE__)) . 'partials/account-tabs/account-content-subscriptions.php';
                break;
            default:
                include plugin_dir_path(dirname(__FILE__)) . 'partials/account-tabs/account-overview.php';
                break;
        }
        ?>
    </div>
</div>

<?php
// Only show subscription details in overview tab if needed
if ($active_tab === 'overview') :
    // Get subscription information
    global $wpdb;
    $subscription_table = $wpdb->prefix . 'subscriptions';
    $plans_table = $wpdb->prefix . 'subscription_plans';

    $subscription = $wpdb->get_row($wpdb->prepare(
        "SELECT s.*, p.plan_name, p.duration 
         FROM $subscription_table s 
         LEFT JOIN $plans_table p ON s.plan_id = p.id 
         WHERE s.user_id = %d 
         ORDER BY s.id DESC 
         LIMIT 1",
        $user_id
    ));

    // Get currency from options
    $currency = get_option('subscription_currency', 'USD');
    
    if ($subscription) :
?>
 
<?php
    endif;
endif;
?> 