@extends('site.layouts.layout_1')
@section('content_header')
    <div class="content-section">
        <div class="content-wrapper w-container">
            <div class="masterbreadcrumb">
                <div class="container">
                    <div class="breadcrumb">
                        <a href="/">
                            <span class="breadcrumb__inner">
                                <span class="breadcrumb__title">Página inicial</span>
                            </span>
                        </a>
                        <a href="{{route('site.diariooficial.index')}}" class="w--current">
                            <span class="breadcrumb__inner">
                                <span class="breadcrumb__title">Diário Oficial</span>
                            </span>
                        </a>
                    </div>
                </div>
            </div>
            <div class="w-col w-col-12">
                <div class="post-content-text">
                    <h5>Último documento inserido</h5>
                    <div class="w-row">
                        <div class="w-col w-col-4">
                            <div class="inforquadro3">
                                <i class="fa-solid fa-list-check fa-2x"></i><br><small>Última publicação</small><br>
                                <span class="card-text text-center">{{ $diariooficial->first()->nome ?? '' }}</span>
                            </div>
                        </div>
                        <div class="w-col w-col-4">
                            <div class="inforquadro3">
                                <i class="fa-regular fa-calendar-days fa-2x"></i><br><small>Última data</small><br>
                                <span class="card-text text-center">{{ $diariooficial->first()->data ?? '' }}</span>
                            </div>
                        </div>
                        <div class="w-col w-col-4">
                            <div class="inforquadro3">
                                <i class="fa-regular fa-folder-open fa-2x"></i><br><small>Total de arquivos</small><br>
                                <span class="card-text text-center">{{ $diariooficial->count() ?? '' }}</span>
                            </div>
                        </div>
                    </div>

                    <div class="entry-content p-4">
                        <h1 class="entry-title">
                            Buscar documentos @if(request('categoria')) - Categoria: {{ $tipos->find(request('categoria'))->tipo_nome }} @endif
                        </h1>
                        <div class="dyn-list">
                            <form action="{{ route('site.diariooficial.buscar') }}" method="POST">
                                @csrf
                                <div class="w-row">
                                    <div class="w-col w-col-6">
                                        <label for="">Palavra chave</label>
                                        <input type="text" class="form-control" name="palavra_chave" placeholder="Palavra chave">
                                    </div>
                                    <div class="w-col w-col-4">
                                        <label for="">Nº da Edição</label>
                                        <input type="text" class="form-control" name="numero_edicao" placeholder="Nº da Edição">
                                    </div>
                                    <div class="w-col w-col-2">
                                        <label for="">Ano</label>
                                        <select class="form-control" name="ano">
                                            <option value="">Ano</option>
                                            @for ($i = 2016; $i <= date('Y'); $i++)
                                                <option value="{{ $i }}">{{ $i }}</option>
                                            @endfor
                                        </select>
                                    </div>
                                </div>
                                <div class="w-row">
                                    <div class="w-col w-col-6">
                                        <label for="">Período</label>
                                        <input type="date" class="form-control" name="inicio">
                                    </div>
                                    <div class="w-col w-col-6">
                                        <label for="">Até</label>
                                        <input type="date" class="form-control" name="fim">
                                    </div>
                                </div>
                                <div class="w-row">
                                    <div class="w-col w-col-6">
                                        <label for="">Categoria</label>
                                        <select class="form-control" name="categoria">
                                            <option value="">Categoria</option>
                                            @foreach ($tipos as $tipo)
                                                <option value="{{ $tipo->id }}" {{ request('categoria') == $tipo->id ? 'selected' : '' }}>
                                                    {{ $tipo->tipo_nome }}
                                                </option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div class="w-col w-col-6">
                                        <label for="">Órgão</label>
                                        <select class="form-control" name="orgao">
                                            <option value="">Órgão</option>
                                            @foreach ($secretarias as $secretaria)
                                                <option value="{{ $secretaria->id }}">{{ $secretaria->nome }}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                                <br>
                                <button type="submit" class="btn btn-sm btn-primary inforquadro3">Buscar</button>
                            </form>
                        </div>
                    </div>

                    <h6>Resultado da busca</h6>
                    <div class="w-row">
                        @foreach ($diariooficial as $arquivo)
                            <div class="w-col w-col-6">
                                <div class="inforquadro3">
                                    <a href="{{ asset('assets/site/uploads/' . $entidade->id_tce . '/dom/diario/' . $arquivo->nome) }}" class="titulo_infor" target="_blank">
                                        <i class="fa-solid fa-list-check fa-2x"></i>
                                        <h6 style="color: #fff">{{ $arquivo->titulo }}</h6>
                                    </a>
                                    <br>
                                    <h6 style="color: #fff">{{ date('d/m/Y', strtotime($arquivo->publicacao)) }}</h6>
                                </div>
                            </div>
                        @endforeach

                    </div>

                    <nav class="basepagina" aria-label="Page navigation">
                        <ul class="pagination justify-content-center">
                            @if ($diariooficial->onFirstPage())
                                <li class="page-item disabled">
                                    <span class="page-link">Anterior</span>
                                </li>
                            @else
                                <li class="page-item">
                                    <a class="page-link" href="{{ $diariooficial->previousPageUrl() }}" aria-label="Previous">
                                        <span aria-hidden="true">&laquo; Anterior</span>
                                    </a>
                                </li>
                            @endif

                            @foreach ($diariooficial->links()->elements as $element)
                                @if (is_string($element))
                                    <li class="page-item disabled"><span class="page-link">{{ $element }}</span>
                                    </li>
                                @endif

                                @if (is_array($element))
                                    @foreach ($element as $page => $url)
                                        <li class="page-item {{ $page == $diariooficial->currentPage() ? 'active' : '' }}">
                                            <a class="page-link" href="{{ $url }}">{{ $page }}</a>
                                        </li>
                                    @endforeach
                                @endif
                            @endforeach

                            @if ($diariooficial->hasMorePages())
                                <li class="page-item">
                                    <a class="page-link" href="{{ $diariooficial->nextPageUrl() }}" aria-label="Next">
                                        <span aria-hidden="true">Próximo &raquo;</span>
                                    </a>
                                </li>
                            @else
                                <li class="page-item disabled">
                                    <span class="page-link">Próximo</span>
                                </li>
                            @endif
                        </ul>
                    </nav>
                    <br>
                </div>
            </div>
        </div>
    </div>
@endsection
