@extends('layouts.admin.theme')
@section('title', env('APP_NAME') . ' :: ' . __('Editais - Parque Tecnológico'))
@section('content')
    @include('errors.messageFlash')

    <div class="container-fluid px-3 px-md-4 py-4">
        <nav aria-label="breadcrumb" class="mb-3">
            <ol class="breadcrumb mb-0 small">
                <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}" class="text-decoration-none">{{ __('Painel') }}</a></li>
                <li class="breadcrumb-item"><a href="{{ route('admin.parqueTecnologico.index') }}" class="text-decoration-none">{{ __('Parque Tecnológico') }}</a></li>
                <li class="breadcrumb-item active" aria-current="page">{{ __('Editais') }}</li>
            </ol>
        </nav>

        <div class="card border-0 shadow-sm rounded-3 mb-4">
        @php $headLine = "<i class='fa-solid fa-file-lines'></i> " . __('Editais'); @endphp
        @include('components.buttons._headLineButtonsBackAdd', [
            'headLine' => $headLine,
            'routeBack' => 'admin.parqueTecnologico.index',
            'nameBack' => __('Voltar'),
            'routeAdd' => 'admin.parqueTecnologico.editais.create',
            'nameAdd' => __('Novo edital'),
            'permission' => 'GERENCIADOR_DE_PARQUE_TECNOLOGICO',
        ])
        <div class="card-body">
            <form id="searchEditais" class="d-flex gap-2 mb-4" method="get">
                <input type="hidden" name="page" value="{{ request()->input('page', 1) }}">
                <input type="text" class="form-control" name="q" placeholder="{{ __('Pesquisar por título ou descrição...') }}"
                    value="{{ request()->input('q') }}">
                <button class="btn btn-primary" type="submit"><i class="fa-solid fa-magnifying-glass me-1"></i> {{ __('Pesquisar') }}</button>
            </form>

            <div class="table-responsive rounded overflow-hidden">
                <table class="table table-hover align-middle text-center mb-0">
                    <thead class="table-light">
                        <tr>
                            <th class="text-start">{{ __('Título') }}</th>
                            <th>{{ __('Data publicação') }}</th>
                            <th>{{ __('Status') }}</th>
                            <th>{{ __('Ações') }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @php $index = 0; @endphp
                        @forelse($editais as $edital)
                            <tr>
                                <td class="text-start">{{ Str::limit($edital->titulo, 80) }}</td>
                                <td>{{ $edital->data_publicacao?->format('d/m/Y') ?? '–' }}</td>
                                <td class="text-center align-middle">
                                    @include('components.buttons._status', [
                                        'index' => $index,
                                        'route' => 'admin.parqueTecnologico.editais.status',
                                        'id' => $edital->id,
                                        'status' => $edital->status,
                                        'permission' => 'GERENCIADOR_DE_PARQUE_TECNOLOGICO',
                                    ])
                                </td>
                                <td class="text-nowrap text-center align-middle">
                                    <div class="btn-group" role="group">
                                        <a href="{{ route('admin.parqueTecnologico.editais.edit', $edital->id) }}" class="btn btn-sm btn-warning" title="{{ __('Editar') }}">
                                            <i class="fa-solid fa-pen-to-square"></i>
                                        </a>
                                        @if (auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_PARQUE_TECNOLOGICO')['excluir'])
                                            <form class="d-inline" action="{{ route('admin.parqueTecnologico.editais.destroy', $edital->id) }}" method="post" onsubmit="return confirmDelete(this)">
                                                @csrf
                                                @method('delete')
                                                @if(request()->filled('q'))
                                                    <input type="hidden" name="q" value="{{ request()->input('q') }}">
                                                @endif
                                                <input type="hidden" name="page" value="{{ request()->input('page', 1) }}">
                                                <input type="hidden" name="confirm" value="{{ __('Este edital será excluído. Deseja continuar?') }}">
                                                <button type="submit" class="btn btn-sm btn-danger" title="{{ __('Excluir') }}">
                                                    <i class="fa-solid fa-trash"></i>
                                                </button>
                                            </form>
                                        @endif
                                    </div>
                                </td>
                            </tr>
                            @php $index++; @endphp
                        @empty
                            <tr>
                                <td colspan="4" class="text-muted fst-italic">{{ __('Nenhum edital encontrado.') }}</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

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