<%- include('partials/header') %>

<main class="app-shell">
  <div class="container">
    <div class="page-grid">
      <aside class="sidebar">
        <nav class="sidebar-nav">
          <a class="sidebar-link active" href="/dashboard">Overview</a>
          <a class="sidebar-link" href="/planner">Sleep Planner</a>
          <a class="sidebar-link" href="/commitments">Commitments</a>
          <a class="sidebar-link" href="/history">Sleep History</a>
          <a class="sidebar-link" href="/profile">Profile & Settings</a>
        </nav>
      </aside>

      <div class="content-panel">
        <div class="eyebrow">Dashboard</div>
        <h2>Today’s Sleep Recommendation</h2>

        <% if (recommendation) { %>
          <div class="result-box">
            <h3>Your RestRight Recommendation</h3>
            <div class="result-line"><strong>🌙 Bedtime:</strong> <%= recommendation.recommended_bedtime %></div>
            <div class="result-line"><strong>☀️ Wake-up:</strong> <%= recommendation.recommended_wake_time %></div>
            <div class="result-line"><strong>😴 Sleep:</strong> <%= recommendation.total_sleep_duration %> hours</div>
            <div class="result-line"><strong>📊 Compatibility Score:</strong> <%= recommendation.compatibility_score %>%</div>
            <div class="result-line"><strong>✅ Reason:</strong> <%= recommendation.reason %></div>
          </div>
        <% } else { %>
          <div class="empty-state">No recommendation has been generated yet. Head to the planner to calculate a sleep schedule.</div>
        <% } %>

        <div class="summary-grid" style="margin-top: 24px;">
          <div class="card">
            <h3>Next commitment</h3>
            <% if (commitments && commitments.length) { %>
              <% const nextCommitment = commitments[0]; %>
              <p><strong><%= nextCommitment.name %></strong></p>
              <p><%= nextCommitment.start_time %> - <%= nextCommitment.end_time %></p>
            <% } else { %>
              <p>No commitments scheduled.</p>
            <% } %>
          </div>

          <div class="card">
            <h3>Total scheduled commitments</h3>
            <p style="font-size: 2rem; margin: 10px 0 0; font-weight: 700;"><%= commitments ? commitments.length : 0 %></p>
          </div>

          <div class="card">
            <h3>Target sleep duration</h3>
            <p style="font-size: 2rem; margin: 10px 0 0; font-weight: 700;"><%= preferences && preferences.preferred_sleep_duration ? preferences.preferred_sleep_duration : 8 %>h</p>
          </div>

          <div class="card">
            <h3>Sleep compatibility score</h3>
            <p style="font-size: 2rem; margin: 10px 0 0; font-weight: 700;"><%= recommendation ? recommendation.compatibility_score : 0 %>%</p>
          </div>
        </div>

        <div class="card" style="margin-top: 28px;">
          <h3>24-hour timeline</h3>
          <div class="timeline">
            <div class="timeline-row">
              <div class="timeline-label">Sleep</div>
              <div class="timeline-bar"><span class="timeline-fill sleep" style="width: 33%;"></span></div>
            </div>
            <div class="timeline-row">
              <div class="timeline-label">Classes / work</div>
              <div class="timeline-bar"><span class="timeline-fill commitment" style="width: 27%;"></span></div>
            </div>
            <div class="timeline-row">
              <div class="timeline-label">Free time</div>
              <div class="timeline-bar"><span class="timeline-fill free" style="width: 40%;"></span></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</main>

<%- include('partials/footer') %>
