{% extends 'base.html' %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
<div class="container-fluid py-3" style="max-width:1100px">
<h1 class="h3">{{ title }}</h1><p class="text-muted">Un profil propose des équipements et ouvrages. Rien n’est créé avant validation.</p>
<form method="post" class="card mb-4"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><div class="card-body row g-3"><div class="col-md-6"><label class="form-label">Nom</label><input class="form-control" name="name" value="{{ profile.name if profile else '' }}" required></div><div class="col-md-6"><label class="form-label">Type structurel</label><select class="form-select" name="room_type_id"><option value="">Aucun</option>{% for rt in room_types %}<option value="{{ rt.id }}" {% if profile and profile.room_type_id == rt.id %}selected{% endif %}>{{ rt.name }}</option>{% endfor %}</select></div><div class="col-12"><label class="form-label">Description</label><textarea class="form-control" name="description">{{ profile.description if profile else '' }}</textarea></div></div><div class="card-footer"><button class="btn btn-primary">Enregistrer</button></div></form>
{% if profile %}
<div class="row g-4"><div class="col-lg-8"><div class="card"><div class="card-header"><strong>Équipements proposés</strong></div><div class="card-body"><form method="post" action="{{ url_for('room_profiles.add_item', id=profile.id) }}" class="row g-2 align-items-end mb-3"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><div class="col-md-4"><label class="form-label">Équipement</label><input class="form-control" name="label" required></div><div class="col-md-2"><label class="form-label">Qté</label><input class="form-control" type="number" min="1" name="quantity" value="1" required></div><div class="col-md-3"><label class="form-label">Catégorie</label><select class="form-select" name="category_id"><option value="">À choisir</option>{% for c in categories %}<option value="{{ c.id }}">{{ c.name }}</option>{% endfor %}</select></div><div class="col-md-3"><label class="form-label">Lot suggéré</label><select class="form-select" name="lot_id"><option value="">Aucun</option>{% for lot in lots %}<option value="{{ lot.id }}">{{ lot.name }}</option>{% endfor %}</select></div><div class="col-md-3"><label class="form-label">Mode</label><select class="form-select" name="is_group"><option value="0">Individuel</option><option value="1">Groupe</option></select></div><div class="col-md-3"><label class="form-label">Par défaut</label><select class="form-select" name="enabled_by_default"><option value="1">Oui</option><option value="0">Non</option></select></div><div class="col-md-3"><button class="btn btn-outline-primary w-100">Ajouter</button></div></form>
<div class="table-responsive"><table class="table table-sm"><thead><tr><th>Proposition</th><th>Quantité</th><th>Mode</th><th>Actions</th></tr></thead><tbody>{% for item in profile.items %}<tr><td>{{ item.label }}{% if item.category %}<small class="text-muted"> · {{ item.category.name }}</small>{% endif %}</td><td><form method="post" action="{{ url_for('room_profiles.edit_item', profile_id=profile.id, item_id=item.id) }}" class="d-flex gap-1"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input class="form-control form-control-sm" style="width:5rem" type="number" min="1" name="quantity" value="{{ item.quantity }}" aria-label="Quantité"><input type="hidden" name="label" value="{{ item.label }}"><input type="hidden" name="is_group" value="{{ '1' if item.is_group else '0' }}"><input type="hidden" name="enabled_by_default" value="{{ '1' if item.enabled_by_default else '0' }}"><button class="btn btn-sm btn-outline-primary">Modifier</button></form></td><td>{{ 'Groupe' if item.is_group else 'Individuel' }}</td><td><form method="post" action="{{ url_for('room_profiles.delete_item', profile_id=profile.id, item_id=item.id) }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><button class="btn btn-sm btn-outline-danger">Retirer</button></form></td></tr>{% else %}<tr><td colspan="4" class="text-muted">Aucune proposition.</td></tr>{% endfor %}</tbody></table></div></div></div>
<div class="col-lg-4"><div class="card"><div class="card-header"><strong>Composition facultative</strong></div><div class="card-body"><form method="post" action="{{ url_for('room_profiles.add_surface', id=profile.id) }}" class="row g-2"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><div class="col-6"><label class="form-label">Type</label><select class="form-select" name="surface_type"><option value="mur">Mur</option><option value="sol">Sol</option><option value="plafond">Plafond</option><option value="autre">Autre</option></select></div><div class="col-6"><label class="form-label">Matériau</label><input class="form-control" name="material" required></div><div class="col-6"><label class="form-label">Finition</label><input class="form-control" name="finish"></div><div class="col-6"><label class="form-label">Repère</label><input class="form-control" name="label"></div><div class="col-12"><button class="btn btn-outline-secondary">Ajouter</button></div></form>{% for surface in profile.surfaces %}<div class="small mt-2">{{ surface.label or surface.surface_type }} — {{ surface.material }}{% if surface.finish %} + {{ surface.finish }}{% endif %}</div>{% endfor %}</div></div><div class="card mt-3"><div class="card-body"><a class="btn btn-primary" href="{{ url_for('room_profiles.preview', id=profile.id) }}">Prévisualiser l’application</a></div></div></div></div>
{% endif %}</div>
{% endblock %}
