@extends('emails.layout')

@section('body')

@if($recipient === 'client')
    {{-- Email to the CLIENT who just paid --}}
    <div class="alert-box alert-success">
        <strong style="color:#15803d;font-size:1rem;">✅ Payment Confirmed!</strong>
        <p style="margin:0.4rem 0 0;color:#166534;">
            Your payment of <strong>₦{{ number_format($invoice->total, 2) }}</strong> has been received successfully.
        </p>
    </div>

    <h2>Thank you for your payment!</h2>
    <p>
        This is your payment receipt for invoice <strong>{{ $invoice->invoice_number }}</strong>
        from <strong>{{ $invoice->user->business_name }}</strong>.
    </p>

@else
    {{-- Email to the BUSINESS OWNER --}}
    <div class="alert-box alert-success">
        <strong style="color:#15803d;font-size:1rem;">💰 Payment Received!</strong>
        <p style="margin:0.4rem 0 0;color:#166534;">
            <strong>{{ $invoice->client->display_name }}</strong> has paid
            <strong>₦{{ number_format($invoice->total, 2) }}</strong> for
            invoice <strong>{{ $invoice->invoice_number }}</strong>.
        </p>
    </div>

    <h2>You've been paid 🎉</h2>
    <p>
        Great news! A payment has been confirmed on your OlaInvoice account.
        Login to view the full payment details.
    </p>
@endif

{{-- Payment details box --}}
<div style="background:#f8fafc;border-radius:8px;padding:1.25rem;margin:1.25rem 0;border:1px solid #e2e8f0;">
    <div class="info-grid">
        <div class="info-item">
            <label>Invoice Number</label>
            <div class="value" style="font-family:monospace;">{{ $invoice->invoice_number }}</div>
        </div>
        <div class="info-item">
            <label>Amount Paid</label>
            <div class="value" style="color:#16a34a;font-size:1.1rem;">₦{{ number_format($invoice->total, 2) }}</div>
        </div>
        <div class="info-item">
            <label>Payment Date</label>
            <div class="value">{{ $invoice->paid_at?->format('d/m/Y H:i') ?? now()->format('d/m/Y H:i') }}</div>
        </div>
        <div class="info-item">
            <label>Payment Method</label>
            <div class="value">Paystack</div>
        </div>
        @if($recipient === 'client')
        <div class="info-item">
            <label>Business</label>
            <div class="value">{{ $invoice->user->business_name }}</div>
        </div>
        @else
        <div class="info-item">
            <label>Client</label>
            <div class="value">{{ $invoice->client->display_name }}</div>
        </div>
        @endif
    </div>
</div>

@if($recipient === 'owner')
    <div style="text-align:center;margin:1.5rem 0;">
        <a href="{{ route('invoices.show', $invoice) }}" class="btn-pay" style="background:#1d4ed8;">
            View Invoice →
        </a>
    </div>
@else
    <p style="font-size:0.875rem;color:#64748b;">
        Please keep this email as your payment receipt.
        If you have any questions, contact <strong>{{ $invoice->user->business_name }}</strong>
        @if($invoice->user->email) at <a href="mailto:{{ $invoice->user->email }}" style="color:#00a651;">{{ $invoice->user->email }}</a> @endif.
    </p>
@endif

@endsection
