{{--
# ────────────── lee_gwena ──────────────
# Code by: ashley_gwena
# Created: 2026-03-12
# Notes: Transfer detail and journal preview
# ───────────────────────────────────────
--}}
@extends('layouts.master')

@section('title', 'Transfer Details')

@section('content')
<div class="container py-4">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <div>
            <h1 class="h3 mb-1">Transfer #{{ $transfer->id }}</h1>
            <p class="text-muted mb-0">Status: {{ ucfirst($transfer->status) }}</p>
        </div>
        <a href="{{ route('transfers.index') }}" class="btn btn-outline-secondary">Back</a>
    </div>

    <div class="card p-4 mb-3">
        <div class="row g-3">
            <div class="col-md-6"><strong>Type:</strong> {{ $transfer->transfer_type }}</div>
            <div class="col-md-6"><strong>Client:</strong> {{ $transfer->client_id }}</div>
            <div class="col-md-6"><strong>Amount:</strong> {{ number_format($transfer->amount, 2) }}</div>
            <div class="col-md-6"><strong>Reference:</strong> {{ $transfer->reference ?? 'N/A' }}</div>
        </div>
    </div>

    <div class="card p-4 mb-3">
        <h2 class="h6">Journal Preview</h2>
        <table class="table table-sm">
            <thead>
                <tr>
                    <th>Account</th>
                    <th>Type</th>
                    <th>Amount</th>
                </tr>
            </thead>
            <tbody>
                @foreach($preview['entries'] as $entry)
                    <tr>
                        <td>{{ $entry['label'] ?? $entry['account_id'] ?? 'Business Ledger' }}</td>
                        <td>{{ ucfirst($entry['type']) }}</td>
                        <td>{{ number_format($entry['amount'], 2) }}</td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    </div>

    <div class="d-flex gap-2">
        <form method="POST" action="{{ route('transfers.approve', $transfer) }}">
            @csrf
            <button class="btn btn-outline-success" type="submit">Approve</button>
        </form>
        <form method="POST" action="{{ route('transfers.post', $transfer) }}">
            @csrf
            <button class="btn btn-outline-primary" type="submit">Post</button>
        </form>
        <form method="POST" action="{{ route('transfers.reverse', $transfer) }}">
            @csrf
            <button class="btn btn-outline-danger" type="submit">Reverse</button>
        </form>
    </div>
</div>
@endsection


