@extends('layouts.app')

@section('content')
<div class="container app-content pt-3">
    <h1 class="h3 mb-4">Pages</h1>
    <div class="py-3">
        <a href="{{ route('admin.page.create') }}" class="btn btn-success"><i class="mr-2 fa fa-plus"></i>Add Page</a>
    </div>
    <div class="card">
        <div class="table-responsive">
            <table class="table card-table table-vcenter">
                <thead class="thead-light">
                    <tr>
                        <th>Title</th>
                        <th>Slug</th>
                        <th>Created At</th>
                        <th>Updated At</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($pages as $page)
                        <tr>
                            <td>{{ $page->title }}</td>
                            <td>{{ $page->slug }}</td>
                            <td class="text-muted">{{ $page->created_at }}</td>
                            <td class="text-muted">{{ $page->updated_at }}</td>
                            <td>
                                {{-- <a href="{{ route('page', $page) }}" target="_blank" class="btn btn-success btn-sm" type="button">Show</a> --}}
                                <a href="{{ route('admin.page.edit', $page) }}" class="btn btn-warning btn-sm" type="button">Edit</a>
                                <a href="{{ route('admin.page.destroy', $page) }}" class="btn btn-danger btn-sm"
                                    onclick="event.preventDefault();document.getElementById('delete-{{ $page->id }}').submit();">Delete</a>

                                <form id="delete-{{ $page->id }}" action="{{ route('admin.page.destroy', $page) }}" method="POST" style="display: none;">
                                    @csrf
                                    @method('DELETE')
                                </form>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>

        @if ($pages->hasPages())
            <div class="card-footer">
                {{ $pages->links() }}
            </div>
        @endif

    </div>
</div>
@endsection
