@extends('layouts.admin.theme')
@section("title", env("APP_NAME") . " :: Lista de Boletins")
@section('content')
    <div class="card shadow-sm">

        @php $headLine = "<i class='fa-solid fa-newspaper'></i> Lista de Boletins"; @endphp

        @include('components.buttons._headLineButtonsBackAdd', [
            'headLine' => __($headLine),
//            'routeBack' => 'admin.turismoNautico.index',
//            'routeBackParams' => [],
//            'nameBack' => __("Voltar"),
            'routeAdd' => 'admin.boletins.create',
            'routeAddParams' => [],
            'nameAdd' => __('Novo Boletim'),
            "permission" => "GERENCIADOR_DE_BOLETINS",
        ])

        <div class="card-body">
            <div class="mb-3">
                <span class="badge bg-primary fs-6">
                    <i class="fa-solid fa-file-pdf me-1"></i>
                    {{ __('Total de boletins') }}: <strong>{{ number_format($totalBoletins, 0, ',', '.') }}</strong>
                </span>
            </div>
            @include("errors.messageFlash")

            <div class="mb-3 alert alert-light">
                <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 class="d-flex">
                                <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="mobile-btn-atualizar btn btn-success text-secondary fw-bold px-3 py-1 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 class="d-flex">
                                <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 class="d-flex">
                                <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 class="d-flex">
                                <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>
            </div>

            <x-tables._table :thead="['Data de Publicação', 'Mês', 'Número', 'Título', 'Arquivo', 'Tipo de Edição', 'Status', 'Ações']" :pagination="$boletins->links()">
                <x-slot name="body">

                    @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><a class="text-dark text-decoration-none d-inline fs-5" href='{{ asset($boletim->url) }}' target="_blank"><i class="fa-solid fa-file-pdf"></i> <small class="text-info">{{ $boletim->fileSizeKB }} KB</small></a></td>
                            <td>
                                @if($boletim->extraordinaryEdition)
                        Edição Extraordinária
                                @else
                        ---
                                @endif
                            </td>
                            <td>
                                @include('components/buttons/_status', [
                                    "index" => $index,
                                    "route" => "admin.boletins.status",
                                    "id" => [$boletim->id],
                                    "status" => $boletim->status,
                                    "permission" => "GERENCIADOR_DE_BOLETINS",
                                ])
                            </td>
                            <td>

                                <div class="d-flex gap-2 justify-content-center">

                                    @include('components/buttons/_editButton', [
                                        "route" => "admin.boletins.edit",
                                        "id" => [$boletim->id],
                                        "fontawesome" => null,
                                        "title" => "Editar",
                                        "permission" => "GERENCIADOR_DE_BOLETINS",
                                    ])

                                    @include('components/buttons/_deleteButton', [
                                        "message" => __("* Este boletim será excluído e esta ação não poderá ser desfeita, deseja continuar?"),
                                        "route" => "admin.boletins.destroy",
                                        "id" => [$boletim->id],
                                        "fontawesome" => null,
                                        "title" => "Excluir",
                                        "permission" => "GERENCIADOR_DE_BOLETINS",
                                    ])

                                    @if($boletim->indexado)
                                        <button class="text-danger text-decoration-none border-0 bg-transparent fs-5 disabled" type="button" style="cursor: initial">
                                            <span class="material-symbols-outlined"> <i class="text-success fa-solid fa-check d-inline fs-5"></i> </span>
                                        </button>
                                    @else
                                        @include('components/buttons/_btnActionPost',[
                                            "route" => "admin.boletins.indexacao",
                                            "id" => [$boletim->id],
                                            "fontawesome" => null,
                                            "permission" => "GERENCIADOR_DE_BOLETINS",
                                        ])
                                    @endif

                                </div>
                            </td>
                        </tr>
                        @php $index++; @endphp
                    @endforeach

                </x-slot>
            </x-tables._table>

        </div>
    </div>
@endsection
