<!DOCTYPE html>
<html lang="pt-br">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="icon" href="{{ asset('images/favicon.ico') }}" type="image/x-icon">

    @vite(['resources/sass/app.scss', 'resources/js/app.js'])
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

    <title>Atendimento</title>
</head>
<div class="container">
    <div class="card mt-3 mb-4 border-light shadow">
        <div class="card-header d-flex justify-content-between">
            <span>Pesquisar</span>
        </div>

        <div class="card-body">
            <form action="{{ route('conta.index') }}">
                <div class="row">

                    <div class="col-md-3 col-sm-12">
                        <label class="form-label" for="analista">Analista</label>
                        <input type="text" name="analista" id="analista" class="form-control"
                            placeholder="Nome do Analista" value="{{$analista}}" />
                    </div>

                    <div class="col-md-3 col-sm-12">
                        <label class="form-label" for="data_inicio">Data Início</label>
                        <input type="date" name="data_inicio" id="data_inicio" class="form-control" value="{{ $data_inicio }}" />
                    </div>

                    <div class="col-md-3 col-sm-12">
                        <label class="form-label" for="data_fim">Data Fim</label>
                        <input type="date" name="data_fim" id="data_fim" class="form-control" value="{{ $data_fim }}"/>
                    </div>

                    <div class="col-md-3 col-sm-12 mt-3 pt-4">
                        <button type="submit" class="btn btn-info btn-sm">Pesquisar</button>
                        <a href="{{ route('conta.index') }}" class="btn btn-warning btn-sm">Limpar</a>
                    </div>

                </div>

            </form>

        </div>
        <div class="container">
            <div style="margin: 0%">
                <h1 style="text-align: center"">Visitas</h1>
            </div>
            <div class="container">
                <a href="{{ route('home') }}">
                    <button class="btn btn-primary" type="button">Voltar</button>
                </a>
                <a class="btn btn-success" href="{{ route('conta.create') }}">Cadastrar Visitas</a>
                <a href="{{ url('gerar-pdf-conta?' . request()->getQueryString()) }}" class="btn btn-warning">Gerar PDF</a>
            </div>
            <br>
                 @if (session('sucesso'))
                 <div class="alert alert-danger m-3" role="alert">
                    {{ session('sucesso') }}
                 </div>
            @endif
            <br>
            <br>
            @forelse ($contas as $conta)
                <table class="table table-striped"">
                    <tr>
                        <th>ID</th>
                        <th>Data</th>
                        <th>Empresa</th>
                        <th>Analista</th>
                        <th>Valor</th>
                        <th>Motivo</th>
                        <th>Veiculo</th>

                    </tr>

                    <tr>
                        <td>{{ $conta->id }}</td>
                        <td>{{ \Carbon\Carbon::parse($conta->data)->tz('America/Sao_Paulo')->format('d/m/Y') }}</td>
                        <td>{{ $conta->cliente }}</td>
                        <td> {{ $conta->analista }}</td>
                        <td> {{ 'R$ ' . number_format($conta->valor, 2, ',', '.') }}</td>
                        <td> {{ $conta->motivo }}</td>
                        <td> {{ $conta->veiculo }}</td>



                        <td><a href="{{ route('conta.show', ['conta' => $conta->id]) }}">
                                <button type="button" class="btn btn-secondary">Visualizar</button>
                            </a></td>

                        <td> <a href="{{ route('conta.edit', ['conta' => $conta->id]) }}">
                                <button class="btn btn-warning" type="button">Editar</button>
                            </a> </td>


                        <form id="formExcluir{{$conta->id}}" action="{{ route('conta.destroy', ['conta' => $conta->id]) }}" method='POST'>
                            @csrf
                            @method('delete')

                            <td><button type="submit" onclick="confirmarExclusao(event,{{$conta->id}})('Tem certeza que deseja apagar?')"
                                    class="btn btn-danger">Apagar</button></td>
                        </form>

                    @empty
                        <span style="color:red">Nenhuma visita encontrada!</span>
            @endforelse
            </tr>
            </table>
            {{ $contas->onEachSide(0)->links() }}

        </div>

        </body>
    </div>
</div>
</html>
