{% extends 'base.html.twig' %}

{% block title %}Sous-traitance{% endblock %}

{% block body %}
<div class="row">
    <div class="col-12">
        <div class="page-title-box d-sm-flex align-items-center justify-content-between">
            <h4 class="mb-sm-0 font-size-18">Sous-traitance</h4>
            <div class="page-title-right">
                <ol class="breadcrumb m-0">
                    <li class="breadcrumb-item"><a href="{{ path('app_dashboard') }}">Accueil</a></li>
                    <li class="breadcrumb-item active">Sous-traitance</li>
                </ol>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-center mb-4">
                    <h4 class="card-title mb-0">Entreprises de sous-traitance</h4>
                    <a href="{{ path('app_subcontracting_company_new') }}" class="btn btn-primary">
                        <i class="bi bi-plus-circle me-1"></i> Nouvelle entreprise
                    </a>
                </div>

                <div class="table-responsive">
                    <table class="table table-hover mb-0">
                        <thead class="table-light">
                            <tr>
                                <th>Nom</th>
                                <th>Adresse</th>
                                <th>Ville</th>
                                <th>Téléphone</th>
                                <th>Statut</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for company in companies %}
                            <tr>
                                <td>{{ company.name }}</td>
                                <td>{{ company.address ?? '-' }}</td>
                                <td>{{ company.postalCode ?? '-' }} {{ company.city ?? '' }}</td>
                                <td>{{ company.phone ?? '-' }}</td>
                                <td>
                                    {% if company.active %}
                                        <span class="badge bg-success">Actif</span>
                                    {% else %}
                                        <span class="badge bg-secondary">Inactif</span>
                                    {% endif %}
                                </td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <a href="{{ path('app_subcontracting_company_show', {id: company.id}) }}" class="btn btn-outline-primary" title="Voir">
                                            <i class="bi bi-eye"></i>
                                        </a>
                                        <a href="{{ path('app_subcontracting_company_edit', {id: company.id}) }}" class="btn btn-outline-warning" title="Modifier">
                                            <i class="bi bi-pencil"></i>
                                        </a>
                                        <form method="post" action="{{ path('app_subcontracting_company_delete', {id: company.id}) }}" class="d-inline" onsubmit="return confirm('Supprimer cette entreprise ?');">
                                            <input type="hidden" name="_token" value="{{ csrf_token('delete' ~ company.id) }}">
                                            <button type="submit" class="btn btn-outline-danger" title="Supprimer">
                                                <i class="bi bi-trash"></i>
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                            {% else %}
                            <tr>
                                <td colspan="6" class="text-center text-muted">Aucune entreprise enregistrée</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
