{% extends 'base.html' %}

{% block content %}
<section class="grid cols-2 dossier-grid">
  <article class="card evidence-board">
    <div class="case-legend">
      <span class="section-label">Routine field sheet</span>
      <span class="pill">Live training log</span>
    </div>
    <h2>{{ routine.name }}</h2>
    <p class="muted">Fill in today's completed reps and weight for each set. Leave any unfinished exercise blank and it will be skipped.</p>
    {% if routine.notes %}
    <p class="muted">{{ routine.notes }}</p>
    {% endif %}
  </article>

  <article class="card evidence-board">
    <div class="case-legend">
      <span class="section-label">Current prescription</span>
      <span class="pill">Shoulder day</span>
    </div>
    <h2>Loaded exercises</h2>
    <ul class="list case-list">
      {% for exercise in routine_sheet %}
      <li>
        <strong>{{ exercise.exercise_name }}</strong>
        <p class="muted">{{ exercise.target_sets }} sets{% if exercise.target_reps %} · target reps {{ exercise.target_reps }}{% endif %}{% if exercise.notes %} · {{ exercise.notes }}{% endif %}</p>
      </li>
      {% endfor %}
    </ul>
  </article>
</section>

<section class="grid dossier-grid">
  <article class="card evidence-board">
    <div class="case-legend">
      <span class="section-label">Workout report</span>
      <span class="pill">Structured entry</span>
    </div>
    <h2>Log this session</h2>
    <form class="stack-form intake-docket" method="post" action="/workouts/routine-log">
      <input type="hidden" name="user_id" value="{{ routine.user_id }}">
      <input type="hidden" name="routine_id" value="{{ routine.id }}">
      <input type="hidden" name="routine_name" value="{{ routine.name }}">
      <input type="hidden" name="exercise_count" value="{{ routine_sheet|length }}">
      <label>Performed at
        <input type="datetime-local" name="performed_at" value="{{ default_performed_at }}" required>
      </label>
      <label>Session notes
        <textarea name="notes" rows="2" placeholder="Pain, wins, machine availability, energy, anything worth remembering."></textarea>
      </label>

      {% for exercise in routine_sheet %}
      <section class="evidence-slab">
        <input type="hidden" name="exercise_{{ exercise.exercise_index }}_set_count" value="{{ exercise.target_sets }}">
        <input type="hidden" name="exercise_{{ exercise.exercise_index }}_default_reps" value="{{ exercise.default_reps }}">
        <div class="case-legend">
          <span class="section-label">Exercise {{ loop.index }}</span>
          <span class="pill">{{ exercise.target_sets }} sets</span>
        </div>
        <label>Exercise
          <select name="exercise_{{ exercise.exercise_index }}_name">
            {% for option_name in exercise_options %}
            <option value="{{ option_name }}" {% if option_name == exercise.exercise_name %}selected{% endif %}>{{ option_name }}</option>
            {% endfor %}
          </select>
        </label>
        <p class="muted">Target reps: {{ exercise.target_reps or 'enter manually' }}</p>
        <div class="grid cols-2 compact-grid">
          {% for set in exercise.sets %}
          <div class="evidence-slab compact-slab">
            <strong>Set {{ set.index + 1 }}</strong>
            <label>Reps
              <input type="number" name="exercise_{{ set.exercise_index }}_set_{{ set.index }}_reps" min="1" step="1" placeholder="{{ set.default_reps }}">
            </label>
            <label>Weight (lb)
              <input type="number" name="exercise_{{ set.exercise_index }}_set_{{ set.index }}_weight_lbs" min="0" step="0.1">
            </label>
          </div>
          {% endfor %}
        </div>
        <label>Exercise notes
          <textarea name="exercise_{{ exercise.exercise_index }}_notes" rows="2" placeholder="Technique note, pain flag, or machine change."></textarea>
        </label>
      </section>
      {% endfor %}

      <button type="submit">Save {{ routine_action_label }} workout</button>
    </form>
  </article>
</section>
{% endblock %}
