{% extends 'base.html' %}
{% block content %}
<div class="page-toolbar"><div><h1 class="h3 mb-1">Mensajería</h1><p class="text-muted mb-0">SMTP y plantillas editables para recetas, prácticas, informes y resultados.</p></div><span class="badge text-bg-dark">HTML + CSS permitido</span></div>
<ul class="nav nav-tabs mb-4" role="tablist"><li class="nav-item"><button class="nav-link active" data-bs-toggle="tab" data-bs-target="#tabSmtp" type="button">SMTP</button></li><li class="nav-item"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#tabRecipe" type="button">Recetas</button></li><li class="nav-item"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#tabPractice" type="button">Prácticas</button></li><li class="nav-item"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#tabReport" type="button">Informes</button></li><li class="nav-item"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#tabResult" type="button">Resultados</button></li></ul>
<form method="post"><div class="tab-content form-grid-tabs">
<div class="tab-pane fade show active" id="tabSmtp"><div class="card table-panel"><div class="card-body"><div class="row g-3"><div class="col-md-6"><label class="form-label">Host</label><input class="form-control" name="smtp_host" value="{{ settings.host }}"></div><div class="col-md-2"><label class="form-label">Puerto</label><input class="form-control" name="smtp_port" value="{{ settings.port }}"></div><div class="col-md-4 d-flex align-items-end"><div class="form-check form-switch"><input class="form-check-input" type="checkbox" name="smtp_use_tls" id="smtp_use_tls" {% if settings.use_tls %}checked{% endif %}><label class="form-check-label" for="smtp_use_tls">Usar TLS</label></div></div><div class="col-md-6"><label class="form-label">Usuario</label><input class="form-control" name="smtp_username" value="{{ settings.username }}"></div><div class="col-md-6"><label class="form-label">Contraseña</label><input class="form-control" type="password" name="smtp_password" value="{{ settings.password }}"></div><div class="col-md-6"><label class="form-label">Remitente</label><input class="form-control" name="smtp_from_email" value="{{ settings.from_email }}"></div><div class="col-md-6"><label class="form-label">Nombre remitente</label><input class="form-control" name="smtp_from_name" value="{{ settings.from_name }}"></div></div></div></div></div>
{% for code, label, subject, html in [('recipe','Recetas',settings.recipe_subject,settings.recipe_html),('practice','Prácticas',settings.practice_subject,settings.practice_html),('report','Informes',settings.report_subject,settings.report_html),('result','Resultados',settings.result_subject,settings.result_html)] %}
<div class="tab-pane fade" id="tab{{ code|capitalize }}"><div class="card table-panel"><div class="card-body"><div class="row g-3"><div class="col-12"><h2 class="h5 mb-1">Mensaje para {{ label|lower }}</h2><p class="text-muted mb-0">Se adjunta automáticamente el PDF emitido.</p></div><div class="col-12"><label class="form-label">Asunto</label><input class="form-control" name="message_{{ code }}_subject" value="{{ subject }}"></div><div class="col-12"><label class="form-label">Cuerpo HTML enriquecido</label><textarea class="form-control html-editor font-monospace" name="message_{{ code }}_html" rows="16">{{ html }}</textarea></div><div class="col-12"><div class="alert alert-light border mb-0">Variables disponibles: {{ '{{ patient_name }}' }}, {{ '{{ professional_name }}' }}, {{ '{{ legal_number }}' }}, {{ '{{ cuir }}' }}, {{ '{{ verify_url }}' }}. Podés incluir HTML y CSS inline.</div></div></div></div></div></div>
{% endfor %}
</div><div class="d-grid mt-4"><button class="btn btn-primary btn-lg">Guardar mensajería y plantillas</button></div></form>
{% endblock %}
