@extends('admin.layouts.layout')
@section('content')
<div class="row match-height">
    <div class="col-md-12 col-12">
        <div class="card">
            <div class="card-header">
                <h4 class="card-title text-primary">Notícias</h4>
                <p class="text-muted">Cadastro de Notícias no Sistema</p>
                <a class="btn btn-outline-primary btn-block d-grid gap-2" type="button" href="{{ route('noticias.create') }}"
                    role="button">Nova notícia</a>
            </div>
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-sm table-hover">
                            <thead>
                                <tr>
                                    <th scope="col">Código</th>
                                    <th scope="col">Título</th>
                                    <th scope="col">Data</th>
                                    <th scope="col">Covid</th>
                                    <th scope="col">Concurso</th>
                                    <th scope="col">Secretaria</th>
                                    <th scope="col">Ações</th>
                                </tr>
                            </thead>
                            <tbody>

                                @foreach ($noticias as $noticia)
                                    <tr>
                                        <td scope="row">{{ $noticia->id }}</td>
                                        <td scope="row">{{ $noticia->titulo }}</td>
                                        <td scope="row">{{ date('d/m/Y', strtotime($noticia->data)) }}</td>
                                        <td scope="row">{{ $noticia->covid }}</td>
                                        <td scope="row">{{ $noticia->concurso }}</td>
                                        <td scope="row">{{ $noticia->secretaria ? $noticia->secretaria->nome : 'Sem Secretaria' }}</td>
                                        <td>
                                            <a href="{{ route('noticias.edit', $noticia->id) }}"
                                                class="btn btn-sm btn-outline-warning">Editar</a>
                                            <form class="d-inline" method="POST"
                                                action="{{ route('noticias.destroy', $noticia->id) }}"
                                                onSubmit="return confirm('Tem certeza que deseja excluir?')">
                                                @method('DELETE')
                                                @csrf
                                                <button class="btn btn-sm btn-outline-danger">Exluir</button>
                                            </form>
                                        </td>
                                    </tr>
                                @endforeach

                            </tbody>
                        </table>
                    </div>
                    {{ $noticias->links('pagination::bootstrap-4') }}
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
