@extends('layouts.app')
@section('title','Review Statement Import')
@section('crumbs','<a href="'.route('bank-transactions.index').'">Bank Transactions</a> · <b>Review import</b>')
@section('content')
<div class="card"><div class="card-h"><h2>Review — {{ $bank->display_name }} ({{ count($rows) }} rows)</h2></div>
<div class="card-b">
<form method="POST" action="{{ route('bank-import.confirm') }}">@csrf
<div class="twrap"><table class="tbl">
<thead><tr><th>Date</th><th>Statement narration</th><th>Dr</th><th>Cr</th><th>Suggested match</th><th>Action</th></tr></thead>
<tbody>
@foreach($rows as $i => $row)
@php $m = $row['match']; $dup = $m && $m['reconciled']; @endphp
<tr>
<td style="white-space:nowrap">{{ fdate($row['date']) }}</td>
<td>{{ $row['narration'] }}@if($row['reference']) <small class="muted">{{ $row['reference'] }}</small>@endif</td>
<td>{{ $row['direction']==='Dr' ? money($row['amount']) : '' }}</td>
<td>{{ $row['direction']==='Cr' ? money($row['amount']) : '' }}</td>
<td>@if($m)<b>{{ $m['txn_no'] }}</b> <small class="muted">{{ $m['txn_date'] }} · {{ Str::limit($m['narration'] ?? '', 40) }}</small>
@if($dup)<span class="bdg b-warn">already reconciled</span>@endif
@else<span class="muted">— new —</span>@endif</td>
<td style="white-space:nowrap">
@if($m && !$dup)
<label><input type="radio" name="rows[{{ $i }}][action]" value="match" checked> Match</label>
<input type="hidden" name="rows[{{ $i }}][txn_id]" value="{{ $m['id'] }}">
@endif
<label><input type="radio" name="rows[{{ $i }}][action]" value="new" {{ (!$m || $dup) ? 'checked' : '' }}> New</label>
<select name="rows[{{ $i }}][txn_type]">
@foreach(($row['direction']==='Cr' ? ['deposit'=>'Deposit','transfer-in'=>'Transfer in','interest'=>'Interest'] : ['withdrawal'=>'Withdrawal','transfer-out'=>'Transfer out','bank-charges'=>'Bank charges']) as $v=>$l)<option value="{{ $v }}">{{ $l }}</option>@endforeach
</select>
<label><input type="radio" name="rows[{{ $i }}][action]" value="skip"> Skip</label>
</td>
</tr>
@endforeach
</tbody></table></div>
<div style="margin-top:12px;display:flex;gap:8px">
<button class="btn">Confirm import</button>
<a class="btn btn-ghost" href="{{ route('bank-import.create') }}">Back</a>
</div>
</form>
</div></div>
@endsection
