<?php
require_once __DIR__ . '/../../api/lib.php';
hw_require_auth(['client']);
$authUser = hw_get_auth_user();

// CHECK MEMBERSHIP
$db = hw_db();
$membershipStmt = $db->prepare("SELECT id, plan_type, expires_at FROM user_memberships WHERE user_id = ? AND status = 'active' AND expires_at > NOW() LIMIT 1");
$membershipStmt->execute([$authUser['id']]);
if (!$membershipStmt->fetch()) {
    header('Location: /files/atasteofafricanmarketplace/dashboard/user/choose-plan.php');
    exit;
}

$page_title = 'Medical Records | Wellness Dashboard';
$page_description = 'View your health records and documents';
$page_content = function () use ($authUser) {
?>
<style>
  nav.fixed { 
    display: none !important; 
    visibility: hidden !important;
    position: absolute !important;
    pointer-events: none !important;
    z-index: -1 !important;
  }
  body > nav { 
    display: none !important; 
    visibility: hidden !important;
  }
  body {
    padding-top: 0 !important;
  }
</style>
<link rel="stylesheet" href="/files/atasteofafricanmarketplace/assets/dashboard.css">

<div class="dashboard-container">
  <!-- Sidebar -->
  <div class="dashboard-sidebar">
    <div class="sidebar-header">
      <div class="sidebar-profile">
        <div class="profile-avatar">
          <?= strtoupper(substr($authUser['first_name'], 0, 1) . substr($authUser['last_name'], 0, 1)) ?>
        </div>
        <div class="profile-info">
          <h3><?= htmlspecialchars($authUser['first_name'] . ' ' . $authUser['last_name']) ?></h3>
          <p>Wellness Member</p>
        </div>
      </div>
    </div>
    <nav class="sidebar-nav">
      <a href="/files/atasteofafricanmarketplace/dashboard/user/index.php"><i class="fas fa-home"></i>Home</a>
      <a href="/files/atasteofafricanmarketplace/dashboard/user/appointments.php"><i class="fas fa-calendar-check"></i>Appointments</a>
      <a href="/files/atasteofafricanmarketplace/dashboard/user/messages.php"><i class="fas fa-comments"></i>Messages</a>
      <a href="/files/atasteofafricanmarketplace/dashboard/user/records.php" class="active"><i class="fas fa-file-medical"></i>Records</a>
      <a href="/files/atasteofafricanmarketplace/dashboard/user/profile.php"><i class="fas fa-user"></i>Profile & Support</a>
      <hr class="sidebar-divider">
      <a href="/files/atasteofafricanmarketplace/store.php"><i class="fas fa-store"></i>Wellness Store</a>
      <a href="/files/atasteofafricanmarketplace/dashboard/user/billing.php"><i class="fas fa-file-invoice-dollar"></i>Billing</a>
      <hr class="sidebar-divider">
      <a href="/files/atasteofafricanmarketplace/index.php"><i class="fas fa-arrow-left"></i>Back to Home</a>
    </nav>
    <div class="sidebar-footer">
      <a href="/files/atasteofafricanmarketplace/api/auth/logout.php" style="display: flex; align-items: center; gap: 12px; color: rgba(255,255,255,0.7); text-decoration: none; font-size: 13px; font-weight: 500; padding: 10px 0; border-top: 1px solid rgba(212, 173, 49, 0.15); transition: all 0.3s;"><i class="fas fa-sign-out-alt"></i>Sign Out</a>
    </div>
  </div>

  <!-- Main Content -->
  <div class="dashboard-content">
    <main>
      <div class="dashboard-header">
        <h1>Medical Records</h1>
        <p>Your health documents and visit summaries</p>
      </div>

      <!-- Visit Summaries -->
      <div style="background: white; padding: 32px; border-radius: 12px; margin-bottom: 24px;">
        <h2 style="font-size: 20px; color: #0b3d2e; margin: 0 0 20px 0; display: flex; align-items: center; gap: 12px;">
          <i class="fas fa-notes-medical" style="color: #0f5240;"></i>
          Past Visit Summaries
        </h2>
        
        <div style="display: flex; flex-direction: column; gap: 16px;">
          <!-- Sample Visit Summary -->
          <div style="padding: 20px; border: 1px solid #e5e7eb; border-radius: 12px; border-left: 4px solid #0f5240;">
            <div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px;">
              <div>
                <h3 style="font-size: 16px; color: #0b3d2e; margin: 0 0 4px 0; font-weight: 600;">Wellness Consultation</h3>
                <div style="font-size: 14px; color: #64748b;">
                  <i class="far fa-calendar"></i> January 15, 2026 • Coach Sarah Williams
                </div>
              </div>
              <button style="background: #f0f9f6; border: 1px solid #0f5240; color: #0f5240; padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer;">
                <i class="fas fa-download"></i> Download
              </button>
            </div>
            
            <div style="background: #f9fafb; padding: 16px; border-radius: 8px; margin-top: 12px;">
              <p style="font-size: 14px; color: #334155; margin: 0; line-height: 1.6;">
                <strong>Visit Summary:</strong> Discussed stress management techniques and sleep quality improvement. 
                Patient reports feeling more energized with the herbal supplements. Recommended continuing current regimen 
                with addition of chamomile tea before bedtime.
              </p>
            </div>
            
            <div style="margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap;">
              <span style="background: #fef9e7; color: #c9a227; padding: 4px 12px; border-radius: 16px; font-size: 12px; font-weight: 600;">
                Follow-up: 2 weeks
              </span>
              <span style="background: #f0f9f6; color: #0f5240; padding: 4px 12px; border-radius: 16px; font-size: 12px; font-weight: 600;">
                Prescriptions: 2
              </span>
            </div>
          </div>
          
          <!-- Empty State if no records -->
          <div style="text-align: center; padding: 40px; color: #94a3b8;">
            <i class="fas fa-file-medical" style="font-size: 48px; margin-bottom: 16px;"></i>
            <p>No additional visit summaries available</p>
          </div>
        </div>
      </div>

      <!-- Uploaded Documents -->
      <div style="background: white; padding: 32px; border-radius: 12px;">
        <h2 style="font-size: 20px; color: #0b3d2e; margin: 0 0 20px 0; display: flex; align-items: center; gap: 12px;">
          <i class="fas fa-file-upload" style="color: #d4ad31;"></i>
          Your Uploaded Documents
        </h2>
        
        <div style="text-align: center; padding: 60px 20px; border: 2px dashed #e5e7eb; border-radius: 12px;">
          <div style="font-size: 48px; margin-bottom: 16px;">📄</div>
          <h3 style="font-size: 18px; color: #334155; margin: 0 0 8px 0;">No documents uploaded yet</h3>
          <p style="color: #64748b; margin: 0 0 20px 0;">Upload lab results, prescriptions, or other medical documents</p>
          <a href="/files/atasteofafricanmarketplace/dashboard/user/index.php#health-data" 
             style="display: inline-flex; align-items: center; gap: 8px; background: #d4ad31; color: white; padding: 12px 24px; border-radius: 8px; font-weight: 600; text-decoration: none;">
            <i class="fas fa-upload"></i>
            Upload Document
          </a>
        </div>
      </div>
    </main>
  </div>
</div>

<?php };
include __DIR__ . '/../../partials/layout.php';
?>
