<?php

// Admin view of customers who registered accounts via the CurryPot ordering app
// (as opposed to guest/walk-in customers created automatically during order taking).
class AppCustomerController extends Controller
{
    public function index(): void
    {
        Auth::requirePermission('dashboard', 'view');

        $customerModel = new Customer();
        $orderModel = new Order();
        $customers = $customerModel->registeredAppCustomers();

        $ordersByCustomer = [];
        foreach ($customers as $c) {
            $ordersByCustomer[$c['id']] = $orderModel->findByCustomer((int) $c['id'], 10);
        }

        $this->view('app_customers.index', [
            'pageTitle'   => 'App Customers',
            'customers'   => $customers,
            'ordersByCustomer' => $ordersByCustomer,
            'onlineCount' => $customerModel->onlineCount(5),
        ]);
    }
}
