<?php
/**
 * Template for Attendee Profile Page
 *
 * @package HVAC_Community_Events
 * @since 1.0.0
 */

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

// Get data from parent scope
$profile = $attendee_data['profile'];
$stats = $attendee_data['stats'];
$timeline = $attendee_data['timeline'];
?>

<div class="hvac-attendee-profile">
    
    <!-- Page Header -->
    <div class="hvac-profile-header">
        <div class="hvac-profile-title">
            <h1>Attendee Profile</h1>
            <span class="hvac-profile-subtitle"><?php echo esc_html($profile['name']); ?></span>
        </div>
        <div class="hvac-profile-actions">
            <a href="mailto:<?php echo esc_attr($profile['email']); ?>" class="ast-button ast-button-primary">
                <i class="fas fa-envelope"></i> Email Attendee
            </a>
            <button class="ast-button ast-button-secondary" onclick="window.print()">
                <i class="fas fa-print"></i> Print
            </button>
            <a href="<?php echo esc_url(wp_get_referer() ?: home_url('/hvac-dashboard/')); ?>" class="ast-button ast-button-secondary">
                <i class="fas fa-arrow-left"></i> Back
            </a>
        </div>
    </div>

    <!-- Statistics Section -->
    <div class="hvac-stats-row">
        <div class="hvac-stat-col">
            <div class="hvac-stat-card">
                <h3>Total Purchases</h3>
                <div class="stat-value"><?php echo number_format($stats['total_purchases']); ?></div>
            </div>
        </div>
        <div class="hvac-stat-col">
            <div class="hvac-stat-card">
                <h3>Events Registered</h3>
                <div class="stat-value"><?php echo number_format($stats['events_registered']); ?></div>
            </div>
        </div>
        <div class="hvac-stat-col">
            <div class="hvac-stat-card">
                <h3>Events Attended</h3>
                <div class="stat-value"><?php echo number_format($stats['events_checked_in']); ?></div>
            </div>
        </div>
        <div class="hvac-stat-col">
            <div class="hvac-stat-card">
                <h3>Certificates Earned</h3>
                <div class="stat-value"><?php echo number_format($stats['certificates_earned']); ?></div>
            </div>
        </div>
    </div>

    <!-- Profile Information Section -->
    <div class="hvac-content-section">
        <h2>Contact Information</h2>
        <div class="hvac-info-table">
            <table class="hvac-table">
                <tbody>
                    <tr>
                        <td class="hvac-label">Name</td>
                        <td><?php echo esc_html($profile['name']); ?></td>
                    </tr>
                    <tr>
                        <td class="hvac-label">Email</td>
                        <td><a href="mailto:<?php echo esc_attr($profile['email']); ?>"><?php echo esc_html($profile['email']); ?></a></td>
                    </tr>
                    <?php if (!empty($profile['phone'])): ?>
                    <tr>
                        <td class="hvac-label">Phone</td>
                        <td><a href="tel:<?php echo esc_attr($profile['phone']); ?>"><?php echo esc_html($profile['phone']); ?></a></td>
                    </tr>
                    <?php endif; ?>
                    <?php if (!empty($profile['company'])): ?>
                    <tr>
                        <td class="hvac-label">Company</td>
                        <td><?php echo esc_html($profile['company']); ?></td>
                    </tr>
                    <?php endif; ?>
                    <?php if (!empty($profile['state'])): ?>
                    <tr>
                        <td class="hvac-label">State</td>
                        <td><?php echo esc_html($profile['state']); ?></td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>

    <!-- Timeline Section -->
    <div class="hvac-content-section">
        <h2>Activity Timeline</h2>
        
        <?php if (empty($timeline)): ?>
            <p class="hvac-no-activity">No activity recorded for this attendee.</p>
        <?php else: ?>
            <div class="hvac-timeline">
                <?php foreach ($timeline as $index => $event): ?>
                    <div class="hvac-timeline-item" data-type="<?php echo esc_attr($event['type']); ?>">
                        <div class="hvac-timeline-date">
                            <?php echo date('M j, Y', strtotime($event['date'])); ?>
                            <span class="hvac-timeline-time"><?php echo date('g:i A', strtotime($event['date'])); ?></span>
                        </div>
                        <div class="hvac-timeline-marker" style="background-color: <?php echo esc_attr($event['color']); ?>">
                            <i class="<?php echo esc_attr($event['icon']); ?>"></i>
                        </div>
                        <div class="hvac-timeline-content">
                            <h4><?php echo esc_html($event['title']); ?></h4>
                            <?php if ($event['type'] === 'event' && isset($event['checked_in'])): ?>
                                <span class="hvac-checkin-status <?php echo $event['checked_in'] ? 'checked-in' : 'not-checked-in'; ?>">
                                    <?php echo $event['checked_in'] ? 'Checked In' : 'Not Checked In'; ?>
                                </span>
                            <?php endif; ?>
                            <?php if ($event['type'] === 'certificate' && !empty($event['certificate_number'])): ?>
                                <span class="hvac-certificate-number">
                                    Certificate #<?php echo esc_html($event['certificate_number']); ?>
                                </span>
                            <?php endif; ?>
                            <?php if (!empty($event['event_id'])): ?>
                                <a href="<?php echo esc_url(get_permalink($event['event_id'])); ?>" class="hvac-event-link" target="_blank">
                                    View Event <i class="fas fa-external-link-alt"></i>
                                </a>
                            <?php endif; ?>
                        </div>
                        <?php if ($index < count($timeline) - 1): ?>
                            <div class="hvac-timeline-connector"></div>
                        <?php endif; ?>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </div>
</div>