@extends('layouts.pmar.theme')
@section("title", env("APP_NAME") . " :: Boletim Oficial")
@section('content')

    <section>
        <div class="container">
            <div class="row">
                <hr />
                <div class="col-12">
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                                <a href="{{ route("paginas.home") }}">{{ __("Portal") }}</a>
                            </li>
                            <li class="breadcrumb-item active" aria-current="page">
                                {{ __("Boletim Oficial do Município de Angra dos Reis") }}</li>
                        </ol>
                    </nav>
                </div>
                <div class="col-12 pb-5 text-primary">
                    <h1>{{ __("Boletim Oficial do Município de Angra dos Reis") }}</h1>
                </div>
            </div>
        </div>
    </section>

    <section>
        <div class="container">
            <div class="row">
                <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-9 col-xxl-9">
                    <div class="row">
                        <article class="article-main">
                            <div class="mb-3 bg-gray border-0 rounded-4 shadow-sm p-3">
                                <div class="text-center fs-6">Pesquisar por:</div>
                                <ul class="nav nav-tabs border-bottom-0" id="myTab" role="tablist">
                                    <li class="nav-item" role="presentation">
                                        <button
                                            class="nav-link @if(request()->has('q') || request()->all() == []) active @endif border-0 rounded-5"
                                            id="termos-tab" data-bs-toggle="tab" data-bs-target="#termos" type="button"
                                            role="tab" aria-controls="termos" aria-selected="true">Termos</button>
                                    </li>
                                    <li class="nav-item" role="presentation">
                                        <button
                                            class="nav-link @if(request()->has('dataInicio') && request()->has('dataFim')) active @endif border-0 rounded-5"
                                            id="data-tab" data-bs-toggle="tab" data-bs-target="#data" type="button"
                                            role="tab" aria-controls="data" aria-selected="false">Data</button>
                                    </li>
                                    <li class="nav-item" role="presentation">
                                        <button class="nav-link @if(request()->has('n')) active @endif border-0 rounded-5"
                                            id="number-tab" data-bs-toggle="tab" data-bs-target="#number" type="button"
                                            role="tab" aria-controls="number" aria-selected="false">Número</button>
                                    </li>
                                    <li class="nav-item" role="presentation">
                                        <button class="nav-link @if(request()->has('y')) active @endif border-0 rounded-5"
                                            id="year-tab" data-bs-toggle="tab" data-bs-target="#year" type="button"
                                            role="tab" aria-controls="year" aria-selected="false">Ano</button>
                                    </li>
                                </ul>
                                <div class="tab-content" id="myTabContent">
                                    <div class="tab-pane fade @if(request()->has('q') || request()->all() == []) show active @endif"
                                        id="termos" role="tabpanel" aria-labelledby="termos-tab">
                                        <form action="{{ route("paginas.boletim-oficial-ajax") }}"
                                            class="d-flex pesquisarBoletim" method="post">
                                            @csrf
                                            <input type="hidden" name="page" value="{{ request()->input('page', 1) }}">
                                            <input type="text" class="form-control me-2 border-0" name="q"
                                                placeholder="Buscar na publicação" aria-label="Pesquisar">
                                            <button class="btn btn-success text-secondary fw-bold px-4 py-2 rounded-4"
                                                type="submit">Buscar</button>
                                        </form>
                                    </div>
                                    <div class="tab-pane fade @if(request()->has('dataInicio') && request()->has('dataFim')) show active @endif"
                                        id="data" role="tabpanel" aria-labelledby="data-tab">
                                        <form action="{{ route("paginas.boletim-oficial-ajax") }}"
                                            class="d-flex pesquisarBoletim" method="post">
                                            @csrf
                                            <input type="hidden" name="page" value="{{ request()->input('page', 1) }}">
                                            <input type="date" class="form-control me-2 border-0" name="dataInicio"
                                                placeholder="Data início" aria-label="Pesquisar">
                                            <input type="date" class="form-control me-2 border-0" name="dataFim"
                                                placeholder="Data fim" aria-label="Pesquisar">
                                            <button class="btn btn-success text-secondary fw-bold px-4 py-2 rounded-4"
                                                type="submit">Buscar</button>
                                        </form>
                                    </div>
                                    <div class="tab-pane fade @if(request()->has('n')) show active @endif" id="number"
                                        role="tabpanel" aria-labelledby="number-tab">
                                        <form action="{{ route("paginas.boletim-oficial-ajax") }}"
                                            class="d-flex pesquisarBoletim" method="post">
                                            @csrf
                                            <input type="hidden" name="page" value="{{ request()->input('page', 1) }}">
                                            <input type="number" class="form-control me-2 border-0" name="n"
                                                placeholder="2025" aria-label="Pesquisar">
                                            <button class="btn btn-success text-secondary fw-bold px-4 py-2 rounded-4"
                                                type="submit">Buscar</button>
                                        </form>
                                    </div>
                                    <div class="tab-pane fade @if(request()->has('y')) show active @endif" id="year"
                                        role="tabpanel" aria-labelledby="year-tab">
                                        <form action="{{ route("paginas.boletim-oficial-ajax") }}"
                                            class="d-flex pesquisarBoletim" method="post">
                                            @csrf
                                            <input type="hidden" name="page" value="{{ request()->input('page', 1) }}">
                                            <input type="number" class="form-control me-2 border-0" name="y"
                                                placeholder="1996" aria-label="Pesquisar">
                                            <button class="btn btn-success text-secondary fw-bold px-4 py-2 rounded-4"
                                                type="submit">Buscar</button>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </article>
                    </div>
                    <div id="getResultAjaxHTML" class="row">
                        <article class="article-main">
                            <div class="table-responsive mt-4">
                                <table id="bulletinsTable" class="table">
                                    <tr>
                                        <th>Data de Publicação</th>
                                        <th>Mês</th>
                                        <th>Número</th>
                                        <th>Título</th>
                                        <th>Tipo de Edição</th>
                                        <th></th>
                                    </tr>
                                    @php
                                        $index = 0;
                                    @endphp
                                    @foreach($boletins as $boletim)
                                        <tr>
                                            <td>{{ date("d/m/Y", strtotime($boletim->publicationDate))  }}</td>
                                            <td>
                                                @foreach(App\Enums\StatusMonth::cases() as $status)
                                                    @if($status->name == $boletim->month)
                                                        {{ $status->value }}
                                                    @endif
                                                @endforeach
                                            </td>
                                            <td>{{ $boletim->number }}</td>
                                            <td>{{ $boletim->title }}</td>
                                            <td>
                                                @if($boletim->extraordinaryEdition)
                                                    Edição Extraordinária
                                                @else
                                                    ---
                                                @endif
                                            </td>
                                            <td class="d-flex flex-row justify-content-center align-items-center">

                                                <a data-toggle="tooltip" data-placement="top" title="Ver Boletim"
                                                    class="text-center text-secondary bg-white p-3 py-2 rounded-5 text-decoration-none d-inline fs-6 mx-2"
                                                    href='{{ asset($boletim->url) }}' target="_blank"><i
                                                        class="fa-solid fa-eye"></i>
                                                    <div class="bulletinsButton"> Visualizar </div>
                                                </a>

                                                <a download="Boletim {{ $boletim->number }} de {{ $boletim->publicationDate }}.pdf"
                                                    data-toggle="tooltip" data-placement="top"
                                                    title="Baixar arquivo de {{ $boletim->fileSizeKB }} KB"
                                                    class="text-center text-secondary bg-white p-3 py-2 rounded-5 text-decoration-none d-inline fs-6 mx-2"
                                                    href='{{ asset($boletim->url) }}' target="_blank"><i
                                                        class="text-secondary fa-solid fa-download"></i>
                                                    <div class="bulletinsButton"> Download </div>
                                                </a>

                                            </td>
                                        </tr>
                                        @php
                                            $index++;
                                        @endphp
                                    @endforeach
                                </table>
                            </div>
                            <div id="hiddenPagination" class="row">
                                <div class="col-12 my-3">
                                    <div class="d-flex justify-content-center">{!! $boletins->links() !!} </div>
                                </div>
                            </div>
                        </article>
                    </div>
                </div>
                <div class="col">
                    <div class="card-slug">
                        <h2 class="slug-title">Leia Mais</h2>
                        @foreach($noticias as $noticia)
                            <div class="my-4">
                                <!-- <span class="news-label">{{ $noticia->title }}</span> -->
                                <h5 class="slug-summary mt-3">
                                    <a
                                        href="{{ route('paginas.slug', [date('d-m-Y', strtotime($noticia->created_at)), $noticia->slug]) }}">
                                        {{ Str::limit(html_entity_decode($noticia->summary), 50) }}
                                    </a>
                                </h5>
                            </div>
                            <hr>
                        @endforeach

                        <a href="{{ route("paginas.noticias") }}"
                            class="mt-5 px-4 py-2 btn border-1 bg-blue-gradient text-white text-start text-center rounded-5">{{ __("Ver
                                    Mais") }}
                        </a>
                    </div>
                </div>
            </div>
        </div>

    </section>

@endsection
