<!DOCTYPE html>
<html lang="pt-BR">

<head>
    <meta charset="UTF-8">
    <title>Ficha do Usuário - {{ $usuario->name }}</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            font-size: 11pt;
            margin: 0;
            padding: 10pt;
            position: relative;
            min-height: 100vh;
        }

        .header {
            text-align: center;
            margin-bottom: 15pt;
        }

        .header h1 {
            font-size: 14pt;
            margin: 0 0 5pt 0;
            padding-bottom: 3pt;
            border-bottom: 1pt solid #000;
        }

        .user-container {
            width: 100%;
            margin-bottom: 15pt;
        }

        .user-photo-container {
            width: 30%;
            float: left;
        }

        .user-photo {
            width: 120pt;
            height: 150pt;
            object-fit: cover;
        }

        .user-details {
            width: 70%;
            float: right;
        }

        .detail-row {
            margin-bottom: 8pt;
        }

        .detail-label {
            font-weight: bold;
            display: inline-block;
            width: 80pt;
        }

        .section-title {
            font-size: 12pt;
            font-weight: bold;
            margin: 15pt 0 10pt 0;
            padding-bottom: 3pt;
            padding-top: 50px;
            border-bottom: 1pt solid #000;
            clear: both;
        }

        .occurrences-container {
            margin-top: 15px;
        }

        .occurrence {
            border: 1px solid #e0e0e0;
            border-radius: 5px;
            padding: 12px;
            margin-bottom: 15px;
            background: #ffffff;
        }

        .occurrence-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 8px;
        }

        .occurrence-id {
            font-weight: bold;
            color: #333;
        }

        .occurrence-date {
            color: #666;
            font-size: 0.9em;
        }

        .status-container {
            float: right;
            margin-top: -16px;
            font-size: 0.85em;
            font-weight: bold;
        }

        .status-badge {
            padding: 3px 8px;
            border-radius: 3px;
        }

        .status-aberto {
            background-color: #f0ad4e;
            color: #000;
        }

        .status-concluido {
            background-color: #5cb85c;
            color: #fff;
        }

        .status-reprovado {
            background-color: #d9534f;
            color: #fff;
        }

        .status-avaliando {
            background-color: #0275d8;
            color: #fff;
        }

        .status-padrao {
            background-color: #f8f9fa;
            color: #000;
            border: 1px solid #ccc;
        }

        .orgao-label {
            font-weight: bold;
        }

        .orgao-badge {
            margin-top: 10px;
            color: #555;
            font-size: 1em;
        }

        .occurrence-description {
            background: #f8f9fa;
            padding: 10px;
            margin-top: 10px;
            border-radius: 4px;
            border-left: 3px solid #0275d8;
        }

        .description-title {
            font-weight: bold;
            margin-bottom: 5px;
            color: #333;
        }

        .description-content {
            color: #444;
            line-height: 1.4;
        }

        .footer {
            position: absolute;
            bottom: 10pt;
            left: 0;
            right: 0;
            text-align: center;
            font-size: 9pt;
            color: #555;
        }
    </style>
</head>

<body>
    <div class="header">
        <h1>{{ __('FICHA DO USUÁRIO') }}</h1>
    </div>

    <div class="user-container">
        <div class="user-photo-container">
            @php
                $userImagePath = public_path('pmar/assets/img/profile.jpg');
                if ($fotoUser) {
                    $userImage = $fotoUser->user_image ?? null;
                    if (!empty($userImage) && !filter_var($userImage, FILTER_VALIDATE_URL)) {
                        $userImagePath = public_path($userImage);
                    }
                }
            @endphp
            <img class="user-photo" src="{{ $userImagePath }}" alt="{{ __('Foto do usuário') }}">
        </div>

        <div class="user-details">
            <div class="detail-row">
                <span class="detail-label">{{ __('Nome') }}:</span>
                <span class="detail-value">{{ $usuario->name }}</span>
            </div>
            <div class="detail-row">
                <span class="detail-label">{{ __('CPF') }}:</span>
                <span class="detail-value">{{ $usuario->document }}</span>
            </div>
            <div class="detail-row">
                <span class="detail-label">{{ __('E-mail') }}:</span>
                <span class="detail-value">{{ $usuario->email }}</span>
            </div>
            <div class="detail-row">
                <span class="detail-label">{{ __('Telefone') }}:</span>
                <span class="detail-value">{{ $usuario->phone ?? __('Não informado') }}</span>
            </div>
            <div class="detail-row">
                <span class="detail-label">{{ __('Cadastro') }}:</span>
                <span class="detail-value">{{ $usuario->created_at }}</span>
            </div>
        </div>
    </div>

    <div class="section-title">{{ __('OCORRÊNCIAS REGISTRADAS') }}</div>

    @if ($chamados->isEmpty())
        <div class="no-occurrences">{{ __('Nenhuma ocorrência registrada.') }}</div>
    @else
        <div class="occurrences-container">
            @foreach ($chamados as $chamado)
                <div class="occurrence">
                    <div class="occurrence-header">
                        <div class="occurrence-meta">
                            <span class="occurrence-id">OCORRÊNCIA #{{ $chamado->id }}</span>
                            <span class="occurrence-date">Registrada em:
                                {{ date('d/m/Y H:i', strtotime($chamado->created_at)) }}</span>
                        </div>

                        <div class="occurrence-status-container">
                            @php
                                $status = strtoupper(
                                    data_get($ultimoStatusPorChamado, $chamado->id . '.status', 'SEM STATUS'),
                                );
                            @endphp

                            <div class="status-container">
                                <span class="occurrence-id">{{ __('STATUS') }}:</span>
                                <span
                                    class="status-badge {{ [
                                        'ABERTO' => 'status-aberto',
                                        'CONCLUÍDO' => 'status-concluido',
                                        'REPROVADO' => 'status-reprovado',
                                        'SENDO AVALIADO' => 'status-avaliando',
                                        'SEM ÓRGÃO' => 'status-sem-orgao',
                                    ][$status] ?? 'status-padrao' }}">
                                    {{ $status }}
                                </span>
                            </div>
                        </div>
                    </div>

                    <div class="occurrence-organ">
                        <span class="orgao-label">{{ __('Órgão Responsável') }}:</span>
                        @php
                            $orgao = $ultimoStatusPorChamado[$chamado->id]->organ_name ?? null;
                        @endphp

                        @if ($orgao)
                            <span class="orgao-badge">
                                {{ $orgao }}
                            </span>
                        @else
                            <span class="orgao-badge orgao-vazio">
                                {{ __('Sem órgão definido') }}
                            </span>
                        @endif
                    </div>

                    <div class="occurrence-description">
                        <div class="description-title">{{ __('Descrição') }}:</div>
                        <div class="description-content">
                            {{ $chamado->description ?? __('Nenhuma descrição fornecida.') }}
                        </div>
                    </div>
                </div>
            @endforeach
        </div>
    @endif

    <div class="footer">
        {{ __('Gerado em') }}: {{ now()->format('d/m/Y H:i') }} - {{ __('Sistema') }} {{ env('APP_NAME') }}
    </div>
</body>

</html>
