{% extends 'base.html' %}
{% block title %}Verificación de receta electrónica{% endblock %}
{% block content %}
<section class="public-section-block public-section-muted">
  <div class="container-xl">
    <div class="row justify-content-center">
      <div class="col-12 col-xl-10">
        <div class="recipe-verify-hero p-4 p-lg-5 mb-4 shadow-sm">
          <div class="top-logo-row">
            <div>
              {% if site_settings.logo_path %}<img src="{{ url_for('static', filename=site_settings.logo_path) }}" alt="logo" class="recipe-logo mb-3">{% endif %}
              <h1 class="h3 mb-2">Verificación de receta electrónica</h1>
              <p class="mb-0 text-muted">La farmacia o el auditor pueden validar una receta cargando el número legal o la CUIR. La consulta expone solo nombre y apellido del paciente y los últimos 4 dígitos del DNI.</p>
            </div>
            <span class="badge text-bg-dark px-3 py-2">Consulta pública</span>
          </div>
          <form method="get" action="{{ url_for('public_verify_recipe') }}" class="row g-3 align-items-end mt-2">
            <div class="col-12 col-lg-9"><label for="q" class="form-label fw-semibold">Número de receta o CUIR</label><input type="text" class="form-control form-control-lg" id="q" name="q" value="{{ query or '' }}" placeholder="Ej.: 202604140001 o 10250042..." autocomplete="off"></div>
            <div class="col-12 col-lg-3 d-grid"><button type="submit" class="btn btn-primary btn-lg">Verificar</button></div>
          </form>
        </div>
        {% if result %}
        <div class="card recipe-verify-result shadow-sm"><div class="card-body p-4 p-lg-5"><div class="top-logo-row mb-3">{% if site_settings.logo_path %}<img src="{{ url_for('static', filename=site_settings.logo_path) }}" alt="logo" class="recipe-logo">{% endif %}<div><span class="recipe-status-pill badge {% if result.status == 'Activa' %}text-bg-success{% elif result.status == 'Vencida' %}text-bg-warning{% elif result.status == 'Suspendida' %}text-bg-secondary{% else %}text-bg-danger{% endif %}">{{ result.status }}</span></div></div><div class="mb-3"><h2 class="h5 mb-1">Resultado de la validación</h2><div class="text-muted">Se visualiza información abreviada para la dispensa segura.</div></div><div class="table-responsive"><table class="table table-bordered align-middle mb-0"><tbody><tr><th style="width: 30%">Paciente</th><td>{{ result.patient_name }}</td></tr><tr><th>DNI (últimos 4)</th><td>{{ result.patient_dni_last4 }}</td></tr><tr><th>Profesional emisor</th><td>{{ result.professional_name }}</td></tr><tr><th>Especialidad</th><td>{{ result.professional_specialty or '—' }}</td></tr><tr><th>Matrícula</th><td>{{ result.professional_matricula or '—' }}</td></tr><tr><th>Fecha de emisión</th><td>{{ result.issued_at }}</td></tr><tr><th>Fecha de vencimiento</th><td>{{ result.expires_at }}</td></tr><tr><th>N° de receta legal</th><td>{{ result.legal_number }}</td></tr><tr><th>CUIR</th><td>{{ result.cuir }}</td></tr><tr><th>Medicamento / DCI</th><td>{{ result.medication_generic_name }}</td></tr><tr><th>Presentación</th><td>{{ result.medication_presentation or '—' }}</td></tr><tr><th>Forma farmacéutica</th><td>{{ result.pharmaceutical_form or '—' }}</td></tr><tr><th>Cantidad</th><td>{{ result.quantity_units or '—' }}</td></tr><tr><th>Posología</th><td>{{ result.dosage_instructions or '—' }}</td></tr><tr><th>Diagnóstico</th><td>{{ result.diagnosis or '—' }}</td></tr></tbody></table></div></div></div>
        {% elif not_found %}
        <div class="alert alert-warning shadow-sm border-0 rounded-4" role="alert">No se encontró una receta con el número ingresado.</div>
        {% endif %}
      </div>
    </div>
  </div>
</section>
{% endblock %}
