@extends('layouts.master')

@section('title', 'Transfers')

@section('content')
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;600;700&family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400&display=swap" rel="stylesheet">

<style>
:root{--sky:#0ea5e9;--sky-deep:#0369a1;--sky-light:#38bdf8;--sky-ghost:rgba(14,165,233,.07);--sky-border:rgba(14,165,233,.2);--ink:#0f172a;--ink-mid:#475569;--ink-soft:#94a3b8;--white:#fff;--off:#f7fbff;--surface:#eef6fd;--border:#daeaf8;--amber:#f59e0b;--amber-bg:rgba(245,158,11,.08);--amber-border:rgba(245,158,11,.22);--danger:#ef4444;--danger-bg:rgba(239,68,68,.08);--danger-border:rgba(239,68,68,.2);--fd:'Cormorant Garamond',Georgia,serif;--fb:'DM Sans',system-ui,sans-serif;--fm:'DM Mono',monospace}
.main-content{background:var(--off);font-family:var(--fb)}
.mt-page{max-width:1200px;margin:0 auto;padding:40px 24px 64px}
.mt-hero{background:linear-gradient(135deg,var(--sky-deep),var(--sky));border-radius:22px;padding:28px 34px;color:#fff;box-shadow:0 10px 28px rgba(14,165,233,.2);display:flex;justify-content:space-between;gap:20px;align-items:center}
.mt-hero h1{margin:0;font-family:var(--fd);font-size:36px}
.mt-hero p{margin:6px 0 0;font-size:13px;color:rgba(255,255,255,.85)}
.mt-badge{background:rgba(255,255,255,.18);border:1px solid rgba(255,255,255,.35);border-radius:16px;padding:12px 18px;text-align:center;min-width:140px}
.mt-badge .val{font-family:var(--fd);font-size:28px;font-weight:700;line-height:1}
.mt-badge .lab{font-size:11px;text-transform:uppercase;letter-spacing:.08em}
.mt-toolbar{display:flex;align-items:center;gap:12px;margin:20px 0;flex-wrap:wrap}
.mt-btn{display:inline-flex;align-items:center;gap:7px;padding:10px 18px;border-radius:10px;border:1px solid var(--sky-border);text-decoration:none;font-size:13px;font-weight:600;background:#fff;color:var(--sky-deep)}
.mt-btn.primary{background:linear-gradient(135deg,var(--sky-deep),var(--sky));color:#fff;border-color:var(--sky-deep)}
.mt-search{margin-left:0;position:relative;flex:1;max-width:320px}
.mt-search input{width:280px;max-width:100%;padding:10px 14px 10px 34px;border:1px solid var(--border);border-radius:10px}
.mt-search .ico{position:absolute;left:12px;top:8px;color:var(--ink-soft)}
.mt-actions-right{margin-left:auto;display:flex;gap:10px;align-items:center}
.mt-table{margin-top:18px;background:#fff;border:1px solid var(--border);border-radius:18px;overflow:hidden;box-shadow:0 6px 20px rgba(14,165,233,.08)}
.mt-head,.mt-row{display:grid;grid-template-columns:0.8fr 1.2fr 1.2fr 1fr 1fr 1.2fr;gap:12px;align-items:center;padding:14px 18px}
.mt-head{background:var(--surface);font-size:10px;font-weight:700;color:var(--ink-soft);text-transform:uppercase;letter-spacing:.1em}
.mt-row{border-top:1px solid var(--border);font-size:13px;color:var(--ink-mid)}
.mt-row:hover{background:var(--sky-ghost)}
.mt-title{font-weight:700;color:var(--ink)}
.mt-actions{display:flex;gap:6px;flex-wrap:wrap}
.mt-actions a,.mt-actions button{padding:6px 10px;border-radius:8px;text-decoration:none;font-size:12px;font-weight:600;border:1px solid var(--border);color:var(--ink-mid);background:#fff}
.mt-actions a.view{border-color:var(--sky-border);color:var(--sky-deep);background:var(--sky-ghost)}
.mt-actions a.edit{border-color:var(--amber-border);color:#92400e;background:var(--amber-bg)}
.mt-actions button.delete{border-color:var(--danger-border);color:#991b1b;background:var(--danger-bg)}
.mt-empty{padding:40px;text-align:center;color:var(--ink-soft)}
@media (max-width: 1024px){.mt-head,.mt-row{grid-template-columns:1fr 1fr 1fr;}.mt-head div:nth-child(n+4),.mt-row div:nth-child(n+4){display:none}}
@media (max-width: 768px){.mt-page{padding:24px 14px 40px}.mt-hero{flex-direction:column;align-items:flex-start}.mt-search{margin-left:0;width:100%}.mt-search input{width:100%}}
</style>

<div class="mt-page">
    <nav class="mt-bc" style="font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--ink-soft);margin-bottom:14px;">
        <a href="{{ route('modules.edit') }}" style="color:var(--ink-soft);text-decoration:none;">Edit Menu</a>
        <span>›</span>
        <a href="{{ route('modules.edit.chart-of-accounts') }}" style="color:var(--ink-soft);text-decoration:none;">Chart of Accounts</a>
        <span>›</span>
        <span style="color:var(--sky-deep);">Transfers</span>
    </nav>

    <div class="mt-hero">
        <div>
            <h1>Transfers</h1>
            <p>Trust ↔ business transfer workflow.</p>
        </div>
        <div class="mt-badge">
            <div class="val">{{ isset($transfers) ? count($transfers) : 0 }}</div>
            <div class="lab">Records</div>
        </div>
    </div>

    <div class="mt-toolbar">
        <a href="{{ route('modules.edit.chart-of-accounts') }}" class="mt-btn">← COA Home</a>
        <div class="mt-search">
            <span class="ico">🔍</span>
            <input id="transferSearch" type="search" placeholder="Search transfer ID or client">
        </div>
        <div class="mt-actions-right">
            <a href="{{ route('transfers.create') }}" class="mt-btn primary">+ New Transfer</a>
        </div>
    </div>

    <div class="mt-table">
        <div class="mt-head">
            <div>ID</div>
            <div>Type</div>
            <div>Client</div>
            <div>Amount</div>
            <div>Status</div>
            <div>Actions</div>
        </div>

        @forelse($transfers as $transfer)
        <div class="mt-row" data-search="{{ strtolower('#' . $transfer->id . ' ' . ($transfer->client_id ?? '')) }}">
            <div class="mt-title">#{{ $transfer->id }}</div>
            <div>{{ $transfer->transfer_type }}</div>
            <div>{{ $transfer->client_id }}</div>
            <div>{{ number_format($transfer->amount, 2) }}</div>
            <div>{{ ucfirst($transfer->status) }}</div>
            <div class="mt-actions">
                <a class="view" href="{{ route('transfers.show', $transfer) }}">View</a>
                <a class="edit" href="{{ route('transfers.edit', $transfer) }}">Edit</a>
                <form method="POST" action="{{ route('transfers.destroy', $transfer) }}" onsubmit="return confirm('Delete this transfer?');">
                    @csrf
                    @method('DELETE')
                    <button type="submit" class="delete">Delete</button>
                </form>
            </div>
        </div>
        @empty
        <div class="mt-empty">No transfers recorded.</div>
        @endforelse
    </div>
</div>

<script>
(() => {
    const input = document.getElementById('transferSearch');
    const rows = Array.from(document.querySelectorAll('.mt-row'));

    input.addEventListener('input', function () {
        const q = this.value.trim().toLowerCase();
        rows.forEach((row) => {
            const hit = !q || (row.dataset.search || '').includes(q);
            row.style.display = hit ? '' : 'none';
        });
    });
})();
</script>
@endsection
