<?php
namespace App\Controllers;

use App\Models\AdminReportModel;
use CodeIgniter\Controller;

class AdminReport extends BaseController
{
    protected $reportModel;

    public function __construct()
    {
        helper(['url', 'form']);
        $this->reportModel = new AdminReportModel();
    }

    // Show all orders report with optional date filter
    public function index()
    {
        $fromDate = $this->request->getGet('from_date');
        $toDate   = $this->request->getGet('to_date');

        if ($fromDate && $toDate) {
            $orders = $this->reportModel->getOrdersByDateRange($fromDate, $toDate);
        } else {
            $orders = $this->reportModel->getAllOrdersWithApartment();
        }

        return view('admin_report', [
            'orders'    => $orders,
            'from_date' => $fromDate,
            'to_date'   => $toDate
        ]);
    }

    // Filter by status
    public function filter($status)
    {
        $orders = $this->reportModel->getOrdersByStatus($status);
        return view('admin_report', ['orders' => $orders, 'from_date' => '', 'to_date' => '']);
    }
}
