{% extends "base.html" %}
{% import "macros.html" as m %}
{% block title %}{{ meta.name }} — feedback — mgf-fed-web{% endblock %}

{% block main %}
{% include "_project_header.html" %}

{% if meta.wired %}
  {% set active_tab = "feedback" %}
  {% include "_project_nav.html" %}

  <div class="fw-view-h">
    <h1 class="fw-view-h__t">Feedback loop</h1>
    <span class="fw-view-h__s mono">{{ thread.rounds|length }} round{{ '' if thread.rounds|length == 1 else 's' }} · the closed loop, both directions</span>
  </div>

  {% if feedback_result %}
  <div class="fw-resultbar {{ 'fw-resultbar--ok' if feedback_result.ok else 'fw-resultbar--warn' }}">
    <span class="fw-resultbar__icon">{{ '✓' if feedback_result.ok else '!' }}</span>
    <span class="mono">{{ feedback_result.text }}</span>
  </div>
  {% endif %}

  {# Compose → produce + DELIVER feedback.json into the project's feedback/ inbox
     (uncommitted; never generated/, never git). Non-operative — actionable text. #}
  <section class="card fw-panel fw-compose">
    <header class="fw-panel__head">
      <h2 class="card__title fw-panel__title">Compose feedback</h2>
      <span class="fw-spacer"></span>
      <span class="fw-panel__note mono">delivers to round v{{ next_round }}</span>
    </header>
    <form class="form fw-compose__form" method="post" action="/p/{{ meta.slug }}/feedback">
      <div class="form-row">
        <div class="field" style="flex: 0 1 12rem;">
          <label class="label" for="fb-kind">Kind</label>
          <select class="select" id="fb-kind" name="kind">
            <option value="direction">direction</option>
            <option value="question">question</option>
            <option value="concern">concern</option>
            <option value="approval">approval</option>
            <option value="priority_change">priority change</option>
          </select>
        </div>
        <div class="field" style="flex: 0 1 10rem;">
          <label class="label" for="fb-priority">Priority</label>
          <select class="select" id="fb-priority" name="priority">
            <option value="high">high</option>
            <option value="medium" selected>medium</option>
            <option value="low">low</option>
          </select>
        </div>
        <div class="field" style="flex: 0 1 12rem;">
          <label class="label" for="fb-by">Authored by</label>
          <input class="input" id="fb-by" name="authored_by" value="founder">
        </div>
      </div>
      <div class="field">
        <label class="label" for="fb-title">Title</label>
        <input class="input" id="fb-title" name="title" required placeholder="A short, actionable headline">
      </div>
      <div class="field">
        <label class="label" for="fb-body">Body</label>
        <textarea class="textarea" id="fb-body" name="body" required placeholder="Detailed, actionable text the project can act on…"></textarea>
      </div>
      <div class="form-row">
        <div class="field" style="flex: 0 1 14rem;">
          <label class="label" for="fb-view">Applies to (view)</label>
          <select class="select" id="fb-view" name="applies_view">
            <option value="">— none —</option>
            <option value="status">status</option>
            <option value="roadmap">roadmap</option>
            <option value="architecture">architecture</option>
            <option value="focus">focus</option>
            <option value="general">general</option>
          </select>
        </div>
        <div class="field">
          <label class="label" for="fb-ref">Applies to (ref)</label>
          <input class="input mono" id="fb-ref" name="applies_ref" placeholder="e.g. stage-2b, T-160 (optional)">
        </div>
      </div>
      <div class="form-row">
        <button class="button button-primary" type="submit">Deliver feedback</button>
        <span class="fw-compose__note">Produces a schema-valid <span class="mono">feedback.json</span> and delivers it into <span class="mono">{{ meta.slug }}/fed-resources/feedback/rounds/v{{ next_round }}/</span> — uncommitted; you act on it project-side.</span>
      </div>
    </form>
  </section>

  <div class="fw-view-h"><h2 class="fw-view-h__t" style="font-size:1.1rem;">Round thread</h2></div>
  {% include "_feedback_thread.html" %}
{% endif %}
{% endblock %}
