@extends('layouts.admin.theme')
@section('title', env('APP_NAME') . ' :: ' . __('Arquivos do ') . $conselho->nome)
@section('content')

    @include('errors.messageFlash')

    <div class="card shadow-sm">
        @php $headLine = "<i class='fa-solid fa-paperclip'></i>" . __('Arquivos do ') . "<i class='fa-solid fa-people-group'></i> " . $conselho->nome; @endphp
        @include('components.buttons._headLineButtonsBackAdd', [
            'headLine' => $headLine,
            'routeBack' => 'admin.conselhosMunicipais.conselhos.index',
            'nameBack' => __('Voltar'),
            'routeAdd' => 'admin.conselhosMunicipais.arquivos.create',
            'routeAddParams' => [$conselho->id],
            'nameAdd' => __('Novo arquivo'),
            'permission' => 'GERENCIADOR_DE_CONSELHOS'
        ])
        <div class="card-body">
            <form id="searchAccounts" class="d-flex mb-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 arquivo...') }}"
                    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' => [
                        '#', __('Tipo'), __('Data'), __('Pertence a'), __('Nome'), __('Status'), __('Ações'), __('Indexar')
                    ]])
                    <tbody>
                        @php $index = 0; @endphp
                        @forelse($arquivos as $arquivo)
                            <tr>
                                <td>
                                    <a href="{{ asset($arquivo->link) }}" target="_blank" class="text-dark">
                                        <i class="fa-solid fa-cloud-arrow-up"></i>
                                    </a>
                                </td>
                                <td>{{ $arquivo->tipo }}</td>
                                <td>{{ $arquivo->evento_at ? date('d/m/Y', strtotime($arquivo->evento_at)) : '' }}</td>
                                <td>
                                    <a href="{{ route('admin.conselhosMunicipais.conselhos.edit', $conselho->id) }}" class="text-dark">
                                        {{ $conselho->nome }}
                                    </a>
                                </td>
                                <td class="text-start">{{ $arquivo->nome }}</td>
                                <td>
                                    <form id="{{ 'checkStatus_'.$index }}" action="{{ route('admin.conselhosMunicipais.arquivos.status', [$conselho->id, $arquivo->id]) }}" method="post" class="d-inline">
                                        @csrf
                                        <input type="hidden" name="page" value="{{ request()->input('page', 1) }}">
                                        @if($arquivo->status === 'ATIVADO')
                                            <input type="hidden" name="checkStatus" value="DESATIVADO">
                                            <div class="form-check form-switch d-flex justify-content-center">
                                                <input class="form-check-input" type="checkbox" checked onclick="document.getElementById('{{ 'checkStatus_'.$index }}').submit()">
                                            </div>
                                        @else
                                            <input type="hidden" name="checkStatus" value="ATIVADO">
                                            <div class="form-check form-switch d-flex justify-content-center">
                                                <input class="form-check-input" type="checkbox" onclick="document.getElementById('{{ 'checkStatus_'.$index }}').submit()">
                                            </div>
                                        @endif
                                    </form>
                                </td>
                                <td>
                                    <div class="btn-group" role="group">
                                        <a href="{{ route('admin.conselhosMunicipais.arquivos.edit', [$conselho->id, $arquivo->id]) }}" class="btn btn-sm btn-warning" title="{{ __('Editar') }}">
                                            <i class="fa-solid fa-pen-to-square"></i>
                                        </a>
                                        <form class="d-inline" action="{{ route('admin.conselhosMunicipais.arquivos.destroy', [$conselho->id, $arquivo->id]) }}" method="post" onsubmit="return confirmDelete(this)">
                                            @csrf
                                            @method('delete')
                                            <input type="hidden" name="page" value="{{ request()->input('page', 1) }}">
                                            <input type="hidden" name="confirm" value="{{ __('* Este arquivo será excluído e esta ação não poderá ser desfeita, deseja continuar?') }}">
                                            <button type="submit" class="btn btn-sm btn-danger" title="{{ __('Excluir') }}">
                                                <i class="fa-solid fa-trash"></i>
                                            </button>
                                        </form>
                                    </div>
                                </td>
                                <td>
                                    @if($arquivo->indexado)
                                        <i class="text-success fa-solid fa-check d-inline fs-5"></i>
                                    @else
                                        <form class="d-inline" action="{{ route('admin.conselhosMunicipais.arquivos.indexacao', [$conselho->id, $arquivo->id]) }}" method="post">
                                            @csrf
                                            <button class="text-danger text-decoration-none border-0 fs-5" type="submit" title="{{ __('Indexar') }}">
                                                <i class="text-danger fa-solid fa-rotate-left d-inline fs-5"></i>
                                            </button>
                                        </form>
                                    @endif
                                </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">
                {!! $arquivos->links() !!}
            </div>
        </div>
    </div>
@endsection
