@extends('layouts.app')
@section('title','Approval Inbox')
@section('crumbs','<b>Approval Inbox</b>')
@section('content')
<div class="card"><div class="card-h"><h2>⏳ Pending approvals</h2></div><div class="card-b">
<div class="twrap"><table class="tbl"><thead><tr><th>Document</th><th>No.</th><th>Requested by</th><th>When</th><th class="no-print">Actions</th></tr></thead>
<tbody>@forelse($pending as $a)<tr>
<td>{{ $types[$a->document_type]['label'] ?? $a->document_type }}</td>
<td><b>{{ $a->document_no }}</b></td><td>{{ $a->requester->name ?? '' }}</td><td class="small">{{ $a->created_at->format('d M Y H:i') }}</td>
<td class="no-print"><div class="row-actions">
<a class="btn btn-sm btn-ghost" href="{{ crud_url($types[$a->document_type]['key'],'show',$a->document_id) }}">Open</a>
<form method="POST" action="{{ route('approvals.decide',$a->id) }}" style="display:inline">@csrf<input type="hidden" name="decision" value="approved"><button class="btn btn-sm btn-ok">Approve</button></form>
<form method="POST" action="{{ route('approvals.decide',$a->id) }}" style="display:inline" data-confirm="Reject this document?">@csrf<input type="hidden" name="decision" value="rejected"><button class="btn btn-sm btn-danger">Reject</button></form>
</div></td></tr>
@empty<tr><td colspan="5" class="muted c">Inbox zero. Nothing awaiting approval. ✓</td></tr>@endforelse</tbody></table></div>
{{ $pending->links() }}
</div></div>
<div class="card"><div class="card-h"><h2>Recent decisions</h2></div><div class="card-b">
<div class="twrap"><table class="tbl"><thead><tr><th>Document</th><th>No.</th><th>Decision</th><th>By</th><th>When</th><th>Remarks</th></tr></thead>
<tbody>@forelse($history as $a)<tr><td>{{ $types[$a->document_type]['label'] ?? $a->document_type }}</td><td>{{ $a->document_no }}</td>
<td><span class="bdg b-{{ $a->status==='approved'?'ok':'bad' }}">{{ $a->status }}</span></td><td>{{ $a->decider->name ?? '' }}</td>
<td class="small">{{ $a->decided_at?->format('d M Y H:i') }}</td><td class="small">{{ $a->remarks }}</td></tr>
@empty<tr><td colspan="6" class="muted c">No history yet.</td></tr>@endforelse</tbody></table></div>
</div></div>
@endsection
