<?php

namespace App\Controllers\Admin;

use App\Controllers\BaseController;
use App\Models\OrderModel;

class HistoryOrder extends BaseController
{
    /**
     * Menampilkan daftar seluruh riwayat order lengkap dengan filter komprehensif
     */
    public function index()
    {
        $orderModel = new OrderModel();
        
        // Membaca input filter dari UI
        $statusOrder = $this->request->getGet('status_order');
        $paymentStatus = $this->request->getGet('payment_status');
        $productionStatus = $this->request->getGet('production_status');

        $builder = $orderModel->orderBy('created_at', 'DESC');

        if (!empty($statusOrder)) {
            $builder->where('status_order', $statusOrder);
        }
        if (!empty($paymentStatus)) {
            $builder->where('payment_status', $paymentStatus);
        }
        if (!empty($productionStatus)) {
            $builder->where('production_status', $productionStatus);
        }

        // Ambil data riwayat order ter-filter dengan pagination halaman
        $data['orders'] = $builder->paginate(15, 'group_orders');
        $data['pager']  = $orderModel->pager;

        return view('admin/history/index', $data);
    }
}