@php
    use App\Models\RelationShip;
    use App\Models\Representative;
@endphp

<div class="representatives-container">
    <h4 class="mb-4">{{ __('detail-patient.patient_representatives') }}</h4>
    
    @if($relationships && count($relationships) > 0)
        <div class="table-responsive">
            <table class="table table-hover">
                <thead class="bg-light">
                    <tr>
                        <th>{{ __('detail-patient.representative_name') }}</th>
                        <th>{{ __('detail-patient.representative_relationship') }}</th>
                        <th>{{ __('detail-patient.representative_identification') }}</th>
                        <th>{{ __('detail-patient.representative_phone') }}</th>
                        <th>{{ __('detail-patient.representative_email') }}</th>
                        <th>{{ __('detail-patient.representative_address') }}</th>
                        <!--<th>{{ __('detail-patient.actions') }}</th>-->
                    </tr>
                </thead>
                <tbody>
                    @foreach($relationships as $relationship)
                        @foreach($relationship->representative()->get() as $representative)
                            <tr>
                                <td>{{ $representative->firstname }} {{ $representative->lastname }}</td>
                                <td>
                                    <span class="badge bg-info">
                                        {{ strtoupper(config("app.parents")()[$relationship->title]) }}
                                    </span>
                                </td>
                                <td>{{ $representative->identification }}</td>
                                <td>{{ $representative->phone }}</td>
                                <td>{{ $representative->email }}</td>
                                <td>{{ $representative->address }}</td>
                                <!--<td>
                                    <div class="btn-group">
                                        <a href="update-representative?id={{ $representative->id }}&patientId={{ $model->id }}" 
                                           class="btn btn-sm btn-outline-primary">
                                            <i class="bi bi-pencil"></i>
                                        </a>
                                    </div>
                                </td>-->
                            </tr>
                        @endforeach
                    @endforeach
                </tbody>
            </table>
        </div>
        
        <div class="mt-4">
            <a href="create-representative?patientId={{ $model->id }}" class="btn btn-primary">
                <i class="bi bi-person-plus me-1"></i> {{ __('detail-patient.add_new_representative') }}
            </a>
        </div>
    @else
        <div class="alert alert-info">
            <i class="bi bi-info-circle me-2"></i>{{ __('detail-patient.no_representatives') }}
        </div>
        
        <div class="mt-4">
            <a href="create-representative?patientId={{ $model->id }}" class="btn btn-primary">
                <i class="bi bi-person-plus me-1"></i> {{ __('detail-patient.add_representative') }}
            </a>
        </div>
    @endif
</div>
