<?php

namespace App\View\Components;

use App\Models\Invoice;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\Component;
use Illuminate\View\View;

class AppLayout extends Component
{
    /**
     * Get the view / contents that represents the component.
     */
    public function render(): View
    {
        $pendingInvoice = null;

        if (Auth::check()) {
            $pendingInvoice = Invoice::where('user_id', Auth::id())
                ->whereNotIn('status', ['paid', 'cancelled', 'refunded'])
                ->whereNotNull('whmcs_invoice_id')
                ->latest()
                ->first();
        }

        return view('layouts.app', [
            'pendingInvoice' => $pendingInvoice,
        ]);
    }
}
