@extends('layouts.app')

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

@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>
                {{ $comerciante->full_name }}
            </h4>
            <div class="d-flex gap-2">
                @if($comerciante->status === 'pending')
                    <form action="{{ route('mercado.comerciantes.approve', $comerciante) }}" method="POST" class="d-inline">
                        @csrf
                        <input type="hidden" name="approved_by" value="{{ auth()->id() }}">
                        <button type="submit" class="btn btn-success btn-sm">
                            <i class="fas fa-check-circle"></i>
                            Aprovar
                        </button>
                    </form>
                @endif

                @if($comerciante->status === 'active')
                    <form action="{{ route('mercado.comerciantes.block', $comerciante) }}" method="POST" class="d-inline">
                        @csrf
                        <button type="submit" class="btn btn-danger btn-sm">
                            <i class="fas fa-ban"></i>
                            Bloquear
                        </button>
                    </form>
                @elseif($comerciante->status === 'suspended')
                    <form action="{{ route('mercado.comerciantes.unblock', $comerciante) }}" method="POST" class="d-inline">
                        @csrf
                        <button type="submit" class="btn btn-warning btn-sm">
                            <i class="fas fa-unlock-alt"></i>
                            Desbloquear
                        </button>
                    </form>
                @endif

                <a href="{{ route('mercado.comerciantes.edit', $comerciante) }}" class="btn btn-outline-secondary btn-sm">
                    <i class="fas fa-edit"></i>
                    Editar
                </a>
                <a href="{{ route('mercado.comerciantes.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-7">
                    <!-- Informações Pessoais -->
                    <div class="info-section mb-4">
                        <h5 class="info-section-title">
                            <i class="fas fa-user"></i>
                            Informações Pessoais
                        </h5>
                        <table class="info-table">
                            <tr>
                                <th>Nome Completo</th>
                                <td>{{ $comerciante->full_name }}</td>
                            </tr>
                            <tr>
                                <th>Tipo de Negócio</th>
                                <td>{{ $comerciante->businessType->name ?? '-' }}</td>
                            </tr>
                            <tr>
                                <th>Data de Nascimento</th>
                                <td>{{ $comerciante->birth_date ? $comerciante->birth_date->format('d/m/Y') : '-' }}</td>
                            </tr>
                        </table>
                    </div>

                    <!-- Documentos -->
                    <div class="info-section mb-4">
                        <h5 class="info-section-title">
                            <i class="fas fa-id-card"></i>
                            Documentos
                        </h5>
                        <table class="info-table">
                            <tr>
                                <th>Nº Identidade</th>
                                <td>{{ $comerciante->identity_number }}</td>
                            </tr>
                            <tr>
                                <th>Tipo de Identidade</th>
                                <td>{{ $comerciante->identity_type }}</td>
                            </tr>
                            <tr>
                                <th>NIF</th>
                                <td>{{ $comerciante->tax_number }}</td>
                            </tr>
                        </table>
                    </div>

                    <!-- Contactos -->
                    <div class="info-section mb-4">
                        <h5 class="info-section-title">
                            <i class="fas fa-address-card"></i>
                            Contactos
                        </h5>
                        <table class="info-table">
                            <tr>
                                <th>Telefone</th>
                                <td>{{ $comerciante->phone }}</td>
                            </tr>
                            <tr>
                                <th>Telefone Alternativo</th>
                                <td>{{ $comerciante->alternate_phone ?? '-' }}</td>
                            </tr>
                            <tr>
                                <th>Email</th>
                                <td>{{ $comerciante->email ?? '-' }}</td>
                            </tr>
                            <tr>
                                <th>Endereço</th>
                                <td>{{ $comerciante->address }}</td>
                            </tr>
                        </table>
                    </div>

                    <!-- Status e Aprovação -->
                    <div class="info-section mb-4">
                        <h5 class="info-section-title">
                            <i class="fas fa-chart-line"></i>
                            Status e Aprovação
                        </h5>
                        <table class="info-table">
                            <tr>
                                <th>Status</th>
                                <td>
                                    @php
                                        $statusClasses = [
                                            'active' => 'badge-success',
                                            'approved' => 'badge-info',
                                            'pending' => 'badge-warning',
                                            'suspended' => 'badge-danger',
                                        ];
                                        $statusTexts = [
                                            'active' => 'Ativo',
                                            'approved' => 'Aprovado',
                                            'pending' => 'Pendente',
                                            'suspended' => 'Bloqueado',
                                        ];
                                    @endphp
                                    <span class="badge {{ $statusClasses[$comerciante->status] ?? 'badge-neutral' }}">
                                        <i class="fas {{ $comerciante->status === 'active' ? 'fa-check-circle' : ($comerciante->status === 'pending' ? 'fa-clock' : 'fa-ban') }}"></i>
                                        {{ $statusTexts[$comerciante->status] ?? $comerciante->status }}
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <th>Aprovado por</th>
                                <td>{{ $comerciante->approvedBy->name ?? '-' }}</td>
                            </tr>
                            <tr>
                                <th>Aprovado em</th>
                                <td>{{ $comerciante->approved_at ? $comerciante->approved_at->format('d/m/Y H:i') : '-' }}</td>
                            </tr>
                        </table>
                    </div>
                </div>

                <div class="col-md-5">
                    <!-- Foto -->
                    <div class="info-section mb-4">
                        <h5 class="info-section-title">
                            <i class="fas fa-camera"></i>
                            Foto
                        </h5>
                        @if($comerciante->photo_url)
                            <img src="{{ $comerciante->photo_url }}" alt="Foto do Comerciante" class="merchant-photo">
                        @else
                            <div class="empty-photo">
                                <i class="fas fa-user-circle"></i>
                                <p>Sem foto cadastrada</p>
                            </div>
                        @endif
                    </div>

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

@push('styles')
<style>
   
</style>
@endpush
