<?php

namespace App\Controllers;

use App\Core\Controller;
use App\Core\Database;

class OrderTrackingController extends Controller
{
    public function track($code)
    {
        $db = Database::getInstance()->getConnection();
        
        if ($code === 'ultimo') {
             // Pega o ultimo pedido (demo)
             $stmt = $db->query("SELECT * FROM orders ORDER BY id DESC LIMIT 1");
             $order = $stmt->fetch();
        } else {
            $stmt = $db->prepare("SELECT * FROM orders WHERE id = ?");
            $stmt->execute([$code]);
            $order = $stmt->fetch();
        }

        if (!$order) {
            die("Pedido não encontrado.");
        }

        $this->view('client.tracking', ['order' => $order]);
    }
}
