<tr>
    <td>
        @include("admin.components.avatar", [
            'imgURL' => $secretaria->managerPhoto,
            'id' => $secretaria->id,
            'title' => $secretaria->name,
        ])
    
    </td>
    <td>
        {{ $secretaria->name }}
    </td>
    <td>
        <small class="font-monospace text-muted">{{ $secretaria->id }}</small>
    </td>
    <td>
        @if($secretaria->structure_id == "")
        ---
        @else
            {{ $secretaria->pertence->name }}
        @endif
    </td>
    <td>{{ $secretaria->email1 }}</td>
    <td>
        @foreach(App\Enums\StructuresPronunciationStatusEnum::cases() as $pronunciation)
            @if($pronunciation->name == $secretaria->pronunciation)
                {{ $pronunciation->value }} {{ $secretaria->manager }}
            @endif
        @endforeach
    </td>
    <td>
        @if (auth()->user()->getPermissaoDetalhes("GERENCIADOR_DE_SECRETARIAS")['editar'])
            @include("admin.components.btnStatus", [
                'route' => "admin.secretarias.status",
                'id' => $secretaria->id,
            ])
        @else
            <span class="text-muted">-</span>
        @endif
    </td>
    <td>
        <div class="d-flex gap-2">
            @php
                // Constrói a URL pública do órgão
                $publicUrl = '';
                if ($secretaria->structure_id) {
                    // Tem parent - busca o parent
                    $parent = $secretaria->pertence;
                    if ($parent) {
                        $tipoPath = match($secretaria->type) {
                            'SECRETARIA_EXECUTIVA' => 'executivas',
                            'DIRETORIA' => 'diretorias',
                            'SUPERINTENDENCIA' => 'superintendencias',
                            default => ''
                        };
                        if ($tipoPath) {
                            $publicUrl = url("secretarias/{$parent->slug}/{$tipoPath}/{$secretaria->slug}");
                        }
                    }
                } else {
                    // Não tem parent - URL direta
                    $publicUrl = url("secretarias/{$secretaria->slug}");
                }
            @endphp

            @if($publicUrl)
                <a class="btn btn-warning btn-sm flex-fill" href="{{ $publicUrl }}" target="_blank" title="{{ __('Visualizar Página Pública') }}">
                    <i class="fa-solid fa-eye"></i>
                </a>
            @endif

            @if (auth()->user()->getPermissaoDetalhes("GERENCIADOR_DE_SECRETARIAS")['editar'])
                @include("admin.components.btnEdit", [
                    'route' => "admin.secretarias.edit",
                    'id' => $secretaria->id,
                    'class' => 'flex-fill'
                ])

                <a class="btn btn-warning btn-sm flex-fill" href="{{ route('admin.telefones.index', $secretaria->id) }}">
                    <i class="fa-solid fa-phone" data-bs-toggle="tooltip" data-bs-placement="top" title="{{ __('Adicionar Ramal') }}"></i>
                </a>

                <a class="btn btn-warning btn-sm flex-fill" href="{{ route('admin.links.index', $secretaria->id) }}">
                    <i class="fa-solid fa-link" data-bs-toggle="tooltip" data-bs-placement="top" title="{{ __('Adicionar Link') }}"></i>
                </a>
            @endif

            @if (auth()->user()->getPermissaoDetalhes("GERENCIADOR_DE_SECRETARIAS")['excluir'])
                @include("admin.components.btnDelete", [
                    'route' => "admin.secretarias.destroy",
                    'id' => $secretaria->id,
                    'text' => "* Este órgão/departamento será excluído e esta ação não poderá ser desfeita, deseja continuar?",
                    'class' => 'flex-fill'
                ])
            @endif
        </div>
    </td>

</tr>