@extends('admin.layout')

@section('title', $config['title'])

@section('body')
<div class="shell">
    @include('admin.partials.sidebar')
    <main class="main">
        <div class="topbar">
            <div><h1>{{ $config['title'] }}</h1><div class="crumb">List, add, edit and remove records</div></div>
            <div class="actions">
                <a class="btn btn-orange" href="{{ route('admin.module.create', $module) }}">Add New</a>
                @include('admin.partials.logout')
            </div>
        </div>
        @if (session('status')) <div class="status">{{ session('status') }}</div> @endif
        <section class="panel">
            <table>
                <tr>
                    @foreach ($config['columns'] as $column)
                        <th>{{ ucwords(str_replace('_', ' ', $column)) }}</th>
                    @endforeach
                    <th>Action</th>
                </tr>
                @foreach ($rows as $row)
                    <tr>
                        @foreach ($config['columns'] as $column)
                            <td>{{ \Illuminate\Support\Str::limit((string) ($row->{$column} ?? ''), 90) }}</td>
                        @endforeach
                        <td>
                            <div class="actions">
                                <a class="btn btn-gray" href="{{ route('admin.module.edit', [$module, $row->id]) }}">Edit</a>
                                <form method="post" action="{{ route('admin.module.destroy', [$module, $row->id]) }}" onsubmit="return confirm('Delete this record?')">
                                    @csrf @method('DELETE')
                                    <button class="btn-red" type="submit">Remove</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                @endforeach
            </table>
            <div class="pagination">{{ $rows->links() }}</div>
        </section>
    </main>
</div>
@endsection
