{% extends 'base.html' %}
{% block content %}
<div class="row g-4">
  <div class="col-lg-4">
    <div class="card shadow-sm">
      <div class="card-body">
        <h2 class="h5">Disponibilidad de {{ profile.display_name }}</h2>
        <p class="small text-muted">Definí bloques de trabajo semanales. El sistema generará slots con base en los servicios asociados.</p>
        <form method="post" class="row g-3">
          <div class="col-12"><label class="form-label">Día</label>
            <select class="form-select" name="weekday">
              {% for k, v in weekday_labels.items() %}<option value="{{ k }}">{{ v }}</option>{% endfor %}
            </select>
          </div>
          <div class="col-6"><label class="form-label">Desde</label><input class="form-control" name="start_time" type="time" required></div>
          <div class="col-6"><label class="form-label">Hasta</label><input class="form-control" name="end_time" type="time" required></div>
          <div class="col-12 d-grid"><button class="btn btn-primary">Agregar bloque</button></div>
        </form>
      </div>
    </div>
  </div>
  <div class="col-lg-8">
    <div class="card shadow-sm mb-4">
      <div class="card-header fw-bold">Bloques horarios</div>
      <div class="table-responsive">
        <table class="table align-middle mb-0">
          <thead><tr><th>Día</th><th>Desde</th><th>Hasta</th><th></th></tr></thead>
          <tbody>
          {% for item in blocks %}
            <tr>
              <td>{{ weekday_labels[item.weekday] }}</td>
              <td>{{ item.start_time.strftime('%H:%M') }}</td>
              <td>{{ item.end_time.strftime('%H:%M') }}</td>
              <td class="text-end">
                <form method="post" action="{{ url_for('admin_schedule_delete', block_id=item.id) }}" onsubmit="return confirm('¿Eliminar?')">
                  <button class="btn btn-sm btn-outline-danger">Eliminar</button>
                </form>
              </td>
            </tr>
          {% else %}
            <tr><td colspan="4" class="text-center text-muted py-4">No hay bloques cargados.</td></tr>
          {% endfor %}
          </tbody>
        </table>
      </div>
    </div>
    <div class="card shadow-sm">
      <div class="card-header fw-bold">Vista previa de slots de esta semana{% if preview_service %} · {{ preview_service.name }}{% endif %}</div>
      <div class="card-body">
        {% if preview_service %}
          <div class="week-strip compact">
            {% for day in week_dates %}
              <div class="week-day-card">
                <div class="week-day-header">{{ weekday_labels[day.weekday()] }}<span>{{ day.strftime('%d/%m') }}</span></div>
                <div class="week-day-body">
                  {% for slot in preview_slots.get(day.isoformat(), []) %}
                    <div class="slot-pill">{{ slot.label }}</div>
                  {% else %}
                    <div class="text-muted small">Sin disponibilidad</div>
                  {% endfor %}
                </div>
              </div>
            {% endfor %}
          </div>
        {% else %}
          <p class="text-muted mb-0">Asociá al menos un servicio a este profesional para ver la simulación de slots.</p>
        {% endif %}
      </div>
    </div>
  </div>
</div>
{% endblock %}
