@extends('emails.email-template')

@php
    $isProcessed = $withdrawal->status == 'Processed';
@endphp

@section('title', 'Outgoing transaction')
@section('subtitle', $isProcessed ? 'This request has been processed' : 'This request is in progress')
@section('company_name', $settings->site_name ?? config('app.name'))

@section('greeting', 'Hello ' . ($foramin ? 'Admin' : ($user->name ?? 'Customer')))

@section('content')
<div style="text-align: center; margin-bottom: 24px;">
    @if ($isProcessed)
    <div style="display: inline-block; padding: 18px; border-radius: 50%; background-color: #DCFCE7; margin-bottom: 14px;">
        <span style="font-size: 28px;">✅</span>
    </div>
    <div style="font-size: 22px; font-weight: 700; color: #16A34A; margin-bottom: 8px;">Payment processed</div>
    @else
    <div style="display: inline-block; padding: 18px; border-radius: 50%; background-color: #FEF3C7; margin-bottom: 14px;">
        <span style="font-size: 28px;">⏳</span>
    </div>
    <div style="font-size: 22px; font-weight: 700; color: #D97706; margin-bottom: 8px;">Payment in progress</div>
    @endif
</div>

@if ($foramin)
<div style="background: linear-gradient(135deg, #EFF6FF 0%, #DBEAFE 100%); border-radius: 12px; padding: 22px; margin-bottom: 24px;">
    <p style="margin:0; font-weight: 500;">{{ $user->name ?? 'Customer' }} — outgoing transaction of <strong style="color:#4F46E5;">{{ $settings->currency }}{{ number_format((float) $withdrawal->amount, 2) }}</strong>@if(!empty($withdrawal->accountname)) to <strong>{{ $withdrawal->accountname }}</strong>@endif. Please review in the admin dashboard if required.</p>
</div>
@else
    @if ($isProcessed)
    <p style="margin-top:0;">Your withdrawal or transfer of <strong>{{ $settings->currency }}{{ number_format((float) $withdrawal->amount, 2) }}</strong> has been <strong>processed</strong>@if(!empty($withdrawal->accountname)), sent toward <strong>{{ $withdrawal->accountname }}</strong>@if(!empty($withdrawal->bankname)) ({{ $withdrawal->bankname }})@endif @endif.</p>
    @else
    <p style="margin-top:0;">Your withdrawal or transfer of <strong>{{ $settings->currency }}{{ number_format((float) $withdrawal->amount, 2) }}</strong> is confirmed and being completed. Beneficiary accounts are typically credited
        @if(!empty($withdrawal->payment_mode) && $withdrawal->payment_mode == 'International Wire Transfer')
        within <strong>72 hours</strong> (international wire).
        @else
        within about <strong>one hour</strong> for local transfers.
        @endif
    </p>
    @endif
@endif

<div style="text-align:center; margin: 18px 0;">
    <span style="display:inline-block; padding: 8px 18px; border-radius: 999px; font-weight: 700; font-size: 12px; letter-spacing: 0.06em; background: #fff7ed; color: #c2410c; border: 1px solid #fdba74;">DEBIT — WITHDRAWAL / TRANSFER</span>
</div>
@endsection

@section('additional_content')
@include('emails.partials.transaction-account-summary', ['user' => $user, 'settings' => $settings, 'foramin' => $foramin])

@php
    $wRows = [
        ['label' => 'Reference / TXN ID', 'value' => !empty($withdrawal->txn_id) ? (string) $withdrawal->txn_id : '—'],
        ['label' => 'Amount', 'value' => $settings->currency . number_format((float) $withdrawal->amount, 2)],
        ['label' => 'Status', 'value' => $isProcessed ? 'Processed' : 'Pending / In progress'],
        ['label' => 'Date', 'value' => \Carbon\Carbon::parse($withdrawal->created_at)->toDayDateTimeString()],
    ];
    if (!empty($withdrawal->accountnumber)) {
        $wRows[] = ['label' => 'Beneficiary account no.', 'value' => (string) $withdrawal->accountnumber];
    }
    if (!empty($withdrawal->accountname)) {
        $wRows[] = ['label' => 'Beneficiary name', 'value' => (string) $withdrawal->accountname];
    }
    if (!empty($withdrawal->bankname)) {
        $wRows[] = ['label' => 'Bank / rail', 'value' => (string) $withdrawal->bankname];
    }
    if (!empty($withdrawal->Description)) {
        $wRows[] = ['label' => 'Description / memo', 'value' => (string) $withdrawal->Description];
    }
    if (!empty($withdrawal->payment_mode)) {
        $wRows[] = ['label' => 'Payment mode', 'value' => (string) $withdrawal->payment_mode];
    }
    if (!$foramin && isset($withdrawal->bal)) {
        $wRows[] = ['label' => 'Available balance (snapshot)', 'value' => $settings->currency . number_format((float) $withdrawal->bal, 2)];
    }
@endphp
@include('emails.partials.transaction-detail-rows', ['rows' => $wRows, 'panelTitle' => 'Withdrawal / transfer details'])

@if(!$foramin && !empty($withdrawal->payment_mode) && $withdrawal->payment_mode == 'International Wire Transfer')
<div style="border-left: 4px solid #F97316; padding: 16px 18px; margin: 24px 0; background-color: #FFF7ED; border-radius: 8px;">
    <p style="margin:0; color: #7C2D12; font-size: 14px;"><strong>International wire:</strong> Settlement can take 2–3 business days. Intermediary banks may deduct fees.</p>
</div>
@endif

@include('emails.partials.transaction-history-cta', ['foramin' => $foramin])
@endsection

@section('help_text')
<p style="margin:0;">If you did not authorize this transaction, contact <a href="mailto:{{ $settings->contact_email ?? '#' }}" style="color:#4F46E5; font-weight:600;">{{ $settings->contact_email ?? 'support' }}</a> immediately.</p>
@endsection

@section('footer')
© {{ date('Y') }} {{ $settings->site_name ?? config('app.name') }} | Secure banking notifications
@endsection
