@extends('layouts.app')

@section('title', 'Detalhes do Pescador')

@section('content')
<div class="sinagem-main">
    <div class="s-card">
        <div class="s-card-header">
            <h4 class="s-card-title">
                <i class="fas fa-user-circle"></i>
                {{ $pescador->merchant->full_name ?? $pescador->full_name ?? 'Pescador' }}
            </h4>
            <div class="d-flex gap-2">
                @if($pescador->status === 'pending')
                    <form action="{{ route('mercado.pescadores.approve', $pescador) }}" method="POST" class="d-inline">
                        @csrf
                        <button type="submit" class="btn btn-success btn-sm">
                            <i class="fas fa-check-circle"></i>
                            Aprovar
                        </button>
                    </form>
                @endif

                @if($pescador->status === 'active' || $pescador->status === 'approved')
                    <form action="{{ route('mercado.pescadores.suspend', $pescador) }}" method="POST" class="d-inline">
                        @csrf
                        <button type="submit" class="btn btn-warning btn-sm">
                            <i class="fas fa-ban"></i>
                            Suspender
                        </button>
                    </form>
                @elseif($pescador->status === 'suspended')
                    <form action="{{ route('mercado.pescadores.activate', $pescador) }}" method="POST" class="d-inline">
                        @csrf
                        <button type="submit" class="btn btn-success btn-sm">
                            <i class="fas fa-play-circle"></i>
                            Ativar
                        </button>
                    </form>
                @endif

                <a href="{{ route('mercado.pescadores.edit', $pescador) }}" class="btn btn-outline-secondary btn-sm">
                    <i class="fas fa-edit"></i>
                    Editar
                </a>
                <a href="{{ route('mercado.pescadores.index') }}" class="btn btn-outline-primary btn-sm">
                    <i class="fas fa-arrow-left"></i>
                    Voltar
                </a>
            </div>
        </div>

        <div class="s-card-body">
            <div class="row">
                <div class="col-md-6">
                    <!-- Informações do Comerciante (Merchant) -->
                    <div class="info-section">
                        <h5 class="info-section-title">
                            <i class="fas fa-user"></i>
                            Informações do Comerciante
                        </h5>
                        <table class="info-table">
                            <tr>
                                <th>Nome Completo</th>
                                <td>{{ $pescador->merchant->full_name ?? '-' }}<\/td>
                            </tr>
                            <tr>
                                <th>Nº Identidade</th>
                                <td>{{ $pescador->merchant->identity_number ?? '-' }}<\/td>
                            </tr>
                            <tr>
                                <th>Telefone</th>
                                <td>{{ $pescador->merchant->phone ?? '-' }}<\/td>
                            </tr>
                            <tr>
                                <th>Telefone Alternativo</th>
                                <td>{{ $pescador->merchant->alternate_phone ?? '-' }}<\/td>
                            </tr>
                            <tr>
                                <th>Email</th>
                                <td>{{ $pescador->merchant->email ?? '-' }}<\/td>
                            </tr>
                            <tr>
                                <th>Data de Nascimento</th>
                                <td>{{ $pescador->merchant->birth_date ? \Carbon\Carbon::parse($pescador->merchant->birth_date)->format('d/m/Y') : '-' }}<\/td>
                            </tr>
                            </table>
                    </div>
                </div>

                <div class="col-md-6">
                    <!-- Informações do Pescador -->
                    <div class="info-section">
                        <h5 class="info-section-title">
                            <i class="fas fa-fish"></i>
                            Informações do Pescador
                        </h5>
                        <table class="info-table">
                            <tr>
                                <th>Nº Registro</th>
                                <td>{{ $pescador->registration_number ?? '-' }}<\/td>
                            </tr>
                            <tr>
                                <th>Nº Licença de Pesca</th>
                                <td>{{ $pescador->fishing_license_number ?? '-' }}<\/td>
                            </tr>
                            <tr>
                                <th>Validade da Licença</th>
                                <td>{{ $pescador->license_expiry_date ? \Carbon\Carbon::parse($pescador->license_expiry_date)->format('d/m/Y') : '-' }}<\/td>
                            </tr>
                            <tr>
                                <th>Categoria Profissional</th>
                                <td>
                                    @php
                                        $categories = [
                                            'artisanal' => 'Artesanal',
                                            'semi_industrial' => 'Semi-industrial',
                                            'industrial' => 'Industrial',
                                            'recreational' => 'Recreativo',
                                        ];
                                    @endphp
                                    {{ $categories[$pescador->professional_category] ?? $pescador->professional_category ?? '-' }}
                                <\/td>
                            </tr>
                            <tr>
                                <th>Zona de Pesca</th>
                                <td>{{ $pescador->fishing_zone ?? '-' }}<\/td>
                            </tr>
                            <tr>
                                <th>Dono de Embarcação</th>
                                <td>{{ $pescador->vessel_owner ? 'Sim' : 'Não' }}<\/td>
                            </tr>
                            <tr>
                                <th>Pescadores Dependentes</th>
                                <td>{{ $pescador->dependent_fishermen ?? 0 }}<\/td>
                            </tr>
                            <tr>
                                <th>Status</th>
                                <td>
                                    @php
                                        $statusClasses = [
                                            'active' => 'badge-success',
                                            'approved' => 'badge-info',
                                            'pending' => 'badge-warning',
                                            'suspended' => 'badge-danger',
                                            'expired' => 'badge-dark',
                                            'deceased' => 'badge-dark',
                                            'inactive' => 'badge-secondary',
                                        ];
                                        $statusTexts = [
                                            'active' => 'Ativo',
                                            'approved' => 'Aprovado',
                                            'pending' => 'Pendente',
                                            'suspended' => 'Suspenso',
                                            'expired' => 'Expirado',
                                            'deceased' => 'Falecido',
                                            'inactive' => 'Inativo',
                                        ];
                                        $statusIcons = [
                                            'active' => 'fa-check-circle',
                                            'approved' => 'fa-check-circle',
                                            'pending' => 'fa-clock',
                                            'suspended' => 'fa-ban',
                                            'expired' => 'fa-hourglass-end',
                                            'deceased' => 'fa-skull',
                                            'inactive' => 'fa-stop-circle',
                                        ];
                                    @endphp
                                    <span class="badge {{ $statusClasses[$pescador->status] ?? 'badge-neutral' }}">
                                        <i class="fas {{ $statusIcons[$pescador->status] ?? 'fa-question-circle' }}"></i>
                                        {{ $statusTexts[$pescador->status] ?? $pescador->status }}
                                    </span>
                                <\/td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>

            <!-- Contatos de Emergência -->
            <div class="row mt-3">
                <div class="col-12">
                    <div class="info-section">
                        <h5 class="info-section-title">
                            <i class="fas fa-ambulance"></i>
                            Contatos de Emergência
                        </h5>
                        <div class="row">
                            <div class="col-md-6">
                                <table class="info-table">
                                    <tr>
                                        <th>Nome do Familiar</th>
                                        <td>{{ $pescador->next_of_kin_name ?? '-' }}<\/td>
                                    </tr>
                                    <tr>
                                        <th>Telefone do Familiar</th>
                                        <td>{{ $pescador->next_of_kin_phone ?? '-' }}<\/td>
                                    </tr>
                                    <tr>
                                        <th>Parentesco</th>
                                        <td>{{ $pescador->next_of_kin_relationship ?? '-' }}<\/td>
                                    </tr>
                                    <tr>
                                        <th>Tipo Sanguíneo</th>
                                        <td>{{ $pescador->blood_type ?? '-' }}<\/td>
                                    </tr>
                                </table>
                            </div>
                            <div class="col-md-6">
                                <table class="info-table">
                                    <tr>
                                        <th>Contato de Emergência</th>
                                        <td>{{ $pescador->emergency_contact_phone ?? '-' }}<\/td>
                                    </tr>
                                    <tr>
                                        <th>Nº Seguro Saúde</th>
                                        <td>{{ $pescador->health_insurance_number ?? '-' }}<\/td>
                                    </tr>
                                    <tr>
                                        <th>Validade do Seguro</th>
                                        <td>{{ $pescador->health_insurance_expiry ? \Carbon\Carbon::parse($pescador->health_insurance_expiry)->format('d/m/Y') : '-' }}<\/td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Embarcações -->
            @if($pescador->vessels && $pescador->vessels->count() > 0)
            <div class="row mt-3">
                <div class="col-12">
                    <div class="info-section">
                        <h5 class="info-section-title">
                            <i class="fas fa-ship"></i>
                            Embarcações
                        </h5>
                        <div class="table-responsive">
                            <table class="s-table">
                                <thead>
                                    <tr>
                                        <th>Nome</th>
                                        <th>Registro</th>
                                        <th>Tipo</th>
                                        <th>Capacidade (kg)</th>
                                        <th>Status</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($pescador->vessels as $vessel)
                                    <tr>
                                        <td>{{ $vessel->vessel_name ?? '-' }}<\/td>
                                        <td>{{ $vessel->registration_number ?? '-' }}<\/td>
                                        <td>{{ $vessel->vessel_type ?? '-' }}<\/td>
                                        <td>{{ number_format($vessel->capacity_kg ?? 0, 0, ',', '.') }}<\/td>
                                        <td>
                                            <span class="badge {{ $vessel->status === 'active' ? 'badge-success' : 'badge-warning' }}">
                                                {{ ucfirst($vessel->status ?? 'N/A') }}
                                            </span>
                                        <\/td>
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            @endif

            <!-- Licenças -->
            @if($pescador->licenses && $pescador->licenses->count() > 0)
            <div class="row mt-3">
                <div class="col-12">
                    <div class="info-section">
                        <h5 class="info-section-title">
                            <i class="fas fa-id-card"></i>
                            Licenças de Pesca
                        </h5>
                        <div class="table-responsive">
                            <table class="s-table">
                                <thead>
                                    <tr>
                                        <th>Nº Licença</th>
                                        <th>Data Emissão</th>
                                        <th>Data Validade</th>
                                        <th>Status</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($pescador->licenses as $license)
                                    <tr>
                                        <td>{{ $license->license_number ?? '-' }}<\/td>
                                        <td>{{ $license->issue_date ? \Carbon\Carbon::parse($license->issue_date)->format('d/m/Y') : '-' }}<\/td>
                                        <td>{{ $license->expiry_date ? \Carbon\Carbon::parse($license->expiry_date)->format('d/m/Y') : '-' }}<\/td>
                                        <td>
                                            <span class="badge {{ $license->status === 'active' ? 'badge-success' : 'badge-danger' }}">
                                                {{ ucfirst($license->status ?? 'N/A') }}
                                            </span>
                                        <\/td>
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            @endif

            <!-- Datas de Registro -->
            <div class="row mt-3">
                <div class="col-12">
                    <div class="info-section">
                        <h5 class="info-section-title">
                            <i class="fas fa-calendar-alt"></i>
                            Datas de Registro
                        </h5>
                        <table class="info-table">
                            <tr>
                                <th>Criado em</th>
                                <td>{{ $pescador->created_at ? $pescador->created_at->format('d/m/Y H:i') : '-' }}<\/td>
                            </tr>
                            <tr>
                                <th>Última atualização</th>
                                <td>{{ $pescador->updated_at ? $pescador->updated_at->format('d/m/Y H:i') : '-' }}<\/td>
                            </tr>
                            @if($pescador->approved_at)
                            <tr>
                                <th>Aprovado em</th>
                                <td>{{ $pescador->approved_at ? \Carbon\Carbon::parse($pescador->approved_at)->format('d/m/Y H:i') : '-' }}<\/td>
                            </tr>
                            @endif
                            @if($pescador->suspended_at)
                            <tr>
                                <th>Suspenso em</th>
                                <td>{{ $pescador->suspended_at ? \Carbon\Carbon::parse($pescador->suspended_at)->format('d/m/Y H:i') : '-' }}<\/td>
                            </tr>
                            @endif
                            @if($pescador->suspended_until)
                            <tr>
                                <th>Suspenso até</th>
                                <td>{{ $pescador->suspended_until ? \Carbon\Carbon::parse($pescador->suspended_until)->format('d/m/Y') : '-' }}<\/td>
                            </tr>
                            @endif
                        </table>
                    </div>
                </div>
            </div>

            <!-- Metadados -->
            @if($pescador->metadata)
            <div class="row mt-3">
                <div class="col-12">
                    <div class="info-section">
                        <h5 class="info-section-title">
                            <i class="fas fa-database"></i>
                            Metadados
                        </h5>
                        <pre class="metadata-pre">{{ json_encode($pescador->metadata, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) }}</pre>
                    </div>
                </div>
            </div>
            @endif
        </div>
    </div>
</div>
@endsection

@push('styles')
<style>
    .info-section {
        margin-bottom: 1.5rem;
    }

    .info-section-title {
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text-primary, #1a1a2e);
        margin-bottom: 1rem;
        padding-bottom: 0.5rem;
        border-bottom: 2px solid var(--sinagem-red, #e03030);
        display: inline-block;
    }

    .info-section-title i {
        color: var(--sinagem-red, #e03030);
        margin-right: 0.5rem;
    }

    .info-table {
        width: 100%;
        border-collapse: collapse;
    }

    .info-table tr {
        border-bottom: 1px solid var(--border-light, #f1f5f9);
    }

    .info-table tr:last-child {
        border-bottom: none;
    }

    .info-table th {
        width: 35%;
        padding: 0.75rem 0;
        font-size: 0.8rem;
        font-weight: 600;
        color: var(--text-secondary, #6b7280);
        text-align: left;
    }

    .info-table td {
        width: 65%;
        padding: 0.75rem 0;
        font-size: 0.85rem;
        color: var(--text-primary, #1a1a2e);
    }

    .metadata-pre {
        background: var(--bg-table-alt, #f8fafc);
        padding: 1rem;
        border-radius: var(--radius-sm, 6px);
        font-size: 0.7rem;
        overflow-x: auto;
    }

    .s-table {
        width: 100%;
        border-collapse: collapse;
    }

    .s-table thead th {
        background: var(--bg-table-alt, #f8fafc);
        padding: 0.75rem 1rem;
        font-size: 0.7rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--text-muted, #9ca3af);
        border-bottom: 1px solid var(--border-color, #e5e7eb);
    }

    .s-table tbody td {
        padding: 0.75rem 1rem;
        color: var(--text-sub, #6b7280);
        border-bottom: 1px solid var(--border-light, #f1f5f9);
    }
</style>
@endpush
