@extends('layouts.admin.theme')
@section('title', env('APP_NAME') . ' :: '.__('Lista de Conselhos Municipais'))
@section('content')

    @include('errors.messageFlash')

    <div class="card shadow-sm">
        @php $headLine = "<i class='fa-solid fa-people-group'></i> " . __('Lista de Conselhos Municipais'); @endphp
        @include('components.buttons._headLineButtonsBackAdd', [
            'headLine' => $headLine,
            'routeBack' => 'admin.dashboard',
            'nameBack' => __('Voltar'),
            'routeAdd' => 'admin.conselhosMunicipais.conselhos.create',
            'nameAdd' => __('Novo conselho'),
            'permission' => 'GERENCIADOR_DE_CONSELHOS'])
        <div class="card-body">
            @if(isset($isAdmin) && $isAdmin)
                <form method="get" class="d-flex mb-3">
                    <select name="structure_id" class="form-select me-2">
                        <option value="all" {{ ($structureId ?? null) === null ? 'selected' : '' }}>{{ __('Todos') }}</option>
                        @foreach($structures as $s)
                            <option value="{{ $s->id }}" {{ ($structureId ?? null) === $s->id ? 'selected' : '' }}>{{ $s->name }}</option>
                        @endforeach
                    </select>
                    <button class="btn btn-primary" type="submit">{{ __('Filtrar') }}</button>
                </form>
            @else
                <div class="mb-3 text-start">
                    <label class="form-label text-bold">{{ __('Secretaria') }}</label>
                    <input type="text" class="form-control" value="{{ ($structures->first()->name ?? '') }}" readonly>
                </div>
            @endif
            <form id="searchConselhos" class="d-flex mb-4 pt-4" method="get">
                <input type="hidden" name="page" value="{{ request()->input('page', 1) }}">
                <input type="text" class="form-control me-2" name="q" placeholder="{{ __('Pesquisar conselho municipal...') }}"
                    value="{{ request()->input('q') }}">
                <button class="btn btn-outline-success" type="submit"><i class="fa-solid fa-magnifying-glass"></i></button>
            </form>

            <div class="table-responsive">
                <table class="table table-bordered table-hover table-striped align-middle text-center">
                    @include('components.tables._thead', ['thead' => [__('Foto'), __('Nome'), __('Pertence a'), __('Bairro'), __('Email'), __('Telefone'), __('Status'), __('Ações')]])
                    <tbody>
                        @php $index = 0 @endphp
                        @forelse($conselhos as $conselho)
                            <tr>
                                <td>
                                    <img src="{{ asset($conselho->foto) }}" alt="{{ $conselho->nome }}" class="rounded-circle"
                                        style="width: 90px; height: 90px; object-fit: cover; cursor: pointer;"
                                        data-bs-toggle="modal" data-bs-target="#modalFotoConselho{{ $conselho->id }}" />

                                    <div class="modal fade" id="modalFotoConselho{{ $conselho->id }}" tabindex="-1" aria-hidden="true">
                                        <div class="modal-dialog modal-fullscreen">
                                            <div class="modal-content bg-dark">
                                                <div class="modal-header border-0">
                                                    <button type="button" class="btn-close btn-close-white ms-auto" data-bs-dismiss="modal" aria-label="{{ __('Fechar') }}"></button>
                                                </div>
                                                <div class="modal-body d-flex justify-content-center align-items-center">
                                                    <img src="{{ asset($conselho->foto) }}" alt="{{ $conselho->nome }}" class="img-fluid rounded" style="max-height: 90vh;" />
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </td>
                                <td>{{ $conselho->nome }}</td>
                                <td>{{ $conselho->pertence->name ?? '' }}</td>
                                <td>{{ $conselho->endereco->bairro ?? '' }}</td>
                                <td>{{ $conselho->email }}</td>
                                <td>{{ $conselho->telefone }}</td>
                                <td class="text-center align-middle">
                                    @include('components/buttons/_status', [
                                        'index' => $index,
                                        'route' => 'admin.conselhosMunicipais.conselhos.status',
                                        'id' => $conselho->id,
                                        'status' => $conselho->status,
                                        'permission' => 'GERENCIADOR_DE_CONSELHOS',
                                    ])
                                </td>
                                <td class="text-nowrap text-center align-middle">
                                    <div class="btn-group" role="group">
                                        <a href="{{ route('admin.conselhosMunicipais.conselhos.edit', $conselho->id) }}" class="btn btn-sm btn-warning" title="{{ __('Editar') }}">
                                            <i class="fa-solid fa-pen-to-square"></i>
                                        </a>
                                        <a href="{{ route('admin.conselhosMunicipais.arquivos.index', $conselho->id) }}" class="btn btn-sm btn-warning" title="{{ __('Arquivos') }}">
                                            <i class="fa-solid fa-cloud-arrow-up"></i>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                            @php $index++ @endphp
                        @empty
                            <tr>
                                <td colspan="8" class="text-muted fst-italic">{{ __('* Nenhum registro encontrado!') }}</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

            <div class="d-flex justify-content-center mt-4">
                {!! $conselhos->links() !!}
            </div>
        </div>
    </div>
@endsection
