@extends('layouts.app')
@section('content')
<main class="nxl-container"><div class="nxl-content">
    <div class="page-header"><h5 class="m-b-10">Recycle Bin</h5></div>
    <div class="main-content">
        @if(session('success')) <div class="alert alert-success">{{ session('success') }}</div> @endif
        <div class="card mb-3"><x-server-list-toolbar placeholder="Search deleted records across modules" :filters="['date_from'=>['label'=>'Deleted from','type'=>'date'],'date_to'=>['label'=>'Deleted to','type'=>'date']]" /></div>
        @foreach($records as $module => $items)
            <div class="card mb-3">
                <div class="card-header"><h5 class="mb-0">{{ ucfirst($module) }} <span class="badge bg-secondary">{{ $items->count() }}</span></h5></div>
                <div class="card-body table-responsive">
                    <table class="table"><thead><tr><th>ID</th><th>Name/Title</th><th>Deleted</th><th></th></tr></thead>
                    <tbody>
                    @forelse($items as $item)
                        <tr>
                            <td>{{ $item->id }}</td>
                            <td>{{ $item->name ?? $item->title ?? $item->topic ?? $item->subject ?? $item->document_number ?? $item->case_number ?? $item->account_name ?? $item->campaign_name ?? $item->content ?? trim(($item->first_name ?? '').' '.($item->last_name ?? '')) ?: '#'.$item->id }}</td>
                            <td>{{ optional($item->deleted_at)->format('Y-m-d H:i') }}</td>
                            <td><form method="POST" action="{{ route('recycle-bin.restore', [$module, $item->id]) }}">@csrf<button class="btn btn-sm btn-success">Restore</button></form></td>
                        </tr>
                    @empty <tr><td colspan="4" class="text-center">No deleted records</td></tr>
                    @endforelse
                    </tbody></table>
                </div>
            </div>
        @endforeach
    </div>
</div></main>
@endsection
