{% extends "base.html" %}
{% block title %}{{ 'Modifier' if unit else 'Nouveau' }} logement — GMAO{% endblock %}
{% block content %}<div class="container" style="max-width:900px"><h1 class="h3 mb-4">{{ 'Modifier le' if unit else 'Nouveau' }} logement</h1><form method="post" class="card"><div class="card-body row g-3">
<div class="col-md-8"><label class="form-label">Nom *</label><input name="name" class="form-control" value="{{ unit.name if unit else '' }}" placeholder="Ex. Logement 1" required></div><div class="col-md-4"><label class="form-label">Code</label><input name="code" class="form-control" value="{{ unit.code if unit and unit.code else '' }}"></div>
<div class="col-md-6"><label class="form-label">Bâtiment *</label><select name="building_id" class="form-select" required><option value="">—</option>{% for building in buildings %}<option value="{{ building.id }}" {% if unit and unit.building_id == building.id %}selected{% endif %}>{{ building.site.name ~ ' · ' if building.site else '' }}{{ building.name }}</option>{% endfor %}</select></div><div class="col-md-3"><label class="form-label">Type</label><select name="housing_type" class="form-select"><option value="fonction">Fonction</option><option value="gardien">Gardien</option><option value="temporaire">Temporaire</option></select></div><div class="col-md-3"><label class="form-label">État</label><select name="occupancy_status" class="form-select">{% for value,label in [('vacant','Vacant'),('occupe','Occupé'),('travaux','En travaux'),('indisponible','Indisponible')] %}<option value="{{ value }}" {% if unit and unit.occupancy_status == value %}selected{% endif %}>{{ label }}</option>{% endfor %}</select></div>
<div class="col-md-6"><label class="form-label">Occupant</label><input name="occupant_name" class="form-control" value="{{ unit.occupant_name if unit and unit.occupant_name else '' }}"></div><div class="col-md-6"><label class="form-label">Contact</label><input name="occupant_contact" class="form-control" value="{{ unit.occupant_contact if unit and unit.occupant_contact else '' }}"></div><div class="col-md-3"><label class="form-label">Début d'occupation</label><input type="date" name="occupancy_start" class="form-control" value="{{ unit.occupancy_start.isoformat() if unit and unit.occupancy_start else '' }}"></div><div class="col-md-3"><label class="form-label">Fin prévue/réelle</label><input type="date" name="occupancy_end" class="form-control" value="{{ unit.occupancy_end.isoformat() if unit and unit.occupancy_end else '' }}"></div><div class="col-md-6"><label class="form-label">Notes techniques</label><textarea name="notes" class="form-control">{{ unit.notes if unit and unit.notes else '' }}</textarea></div>
<div class="col-md-3"><label class="form-label">Nombre de clés remises</label><input type="number" min="0" name="key_count" class="form-control" value="0"></div><div class="col-md-9"><label class="form-label">État des lieux d’entrée</label><textarea name="entry_condition" class="form-control" rows="2"></textarea></div>
{% if unit %}<div class="col-md-12"><label class="form-label">État des lieux de sortie</label><textarea name="exit_condition" class="form-control" rows="2" placeholder="À renseigner lors du départ ou du changement d’occupant"></textarea></div>{% endif %}
</div><div class="card-footer"><button class="btn btn-primary">Enregistrer</button> <a href="{{ url_for('housing.index') }}" class="btn btn-outline-secondary">Annuler</a></div></form></div>{% endblock %}
