@extends('layouts.admin.theme')
@section('title', env('APP_NAME') . ' :: Lista de Processos')
@section('content')

    @include("errors.messageFlash")


    <div class="card shadow-sm">
        <div class="card-header bg-primary text-white d-flex justify-content-between align-items-center mb-3">
            <h5 class="mb-0">Meus Processos SEI</h5>
            
        </div>
        <div class="card-body">
            <div class="d-flex">
                @include('components.buttons._newButton', ['url' => 'admin.processos.create', 'text' => 'Novo processo'])
            </div>
            <form id="searchAccounts" class="d-flex mb-4 pt-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 processo..."
                   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' => ['Número SEI', 'Data', 'Pertence a', 'Assunto', 'Andamento', 'Status', 'Ações']])
                    <tbody>
                        @php $index = 0 @endphp
                        @forelse($processos as $processo)
                            <tr>
                                <td style="white-space: nowrap;">{{ $processo->numero }}</td>
                                <td>{{ date("d/m/Y H:m:s", strtotime($processo->created_at)) }}</td>
                                <td>{{ $processo->user->firstName }} {{ $processo->user->lastName }}</td>
                                <td>{!!  Str::limit($processo->descricao, 120) !!}</td>
                                <td>{{ $processo->andamento_descricao }}</td>
                                <td>
                                    <form id="{{ "checkStatus_" . $index }}" class="fix"
                            action="{{ route("admin.processos.status", $processo->id)}}" method="post">
                                        @csrf
                                        <input type="hidden" name="page" value="{{ request()->input('page', 1) }}">
                                        @if($processo->status == "ATIVADO")
                                            <div class="form-check form-switch d-flex justify-content-center">
                                                <input type="hidden" name="checkStatus" value="DESATIVADO">
                                                <input class="form-check-input" type="checkbox" checked
                                       onclick="javascript:$('#{{ "checkStatus_" . $index }}').submit()">
                                            </div>
                                        @else
                                            <div class="form-check form-switch d-flex justify-content-center">
                                                <input type="hidden" name="checkStatus" value="ATIVADO">
                                                <input class="form-check-input" type="checkbox"
                                       onclick="javascript:$('#{{ "checkStatus_" . $index }}').submit()">
                                            </div>
                                        @endif
                                    </form>
                                </td>
                                <td class="text-nowrap text-center align-middle">
                                    <div class="d-flex justify-content-center flex-wrap gap-1">
                                        <a href="{{ route('admin.processos.edit', $processo->id) }}"
                                            class="btn btn-sm btn-warning" title="Editar"><i
                                            class="fa-solid fa-pen-to-square"></i>
                                        </a>

                                        <a href="{{ route("admin.processos.acompanhamento", $processo->id) }}" class="btn btn-sm btn-warning">
                                            <i class="fa-solid fa-eye"></i>
                                        </a>

                                        <form class="d-inline" action="{{ route('admin.processos.destroy', $processo->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 processo 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>
                            </tr>
                            @php $index++ @endphp
                        @empty
                            <tr>
                                <td colspan="7" class="text-muted fst-italic">* Nenhum registro encontrado!</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

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