<?php
// error_reporting(E_ALL);
// ini_set('display_errors', 1);
header("Content-Type: application/json");
require './config/db.php';
require './config/function/function.php';
// header("Content-Type: application/json");


// Get tracking number from request
$trackNo = $_GET['trackNo'] ?? '';

// Validate input
if (empty($trackNo)) {
    echo json_encode(["success" => false, "error" => "Tracking number is required"]);
    exit();
}

// Query to fetch tracking details
$sql = "SELECT * FROM packages WHERE trackNo = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $trackNo);
$stmt->execute();
$result = $stmt->get_result();

// Check if data exists
if ($row = $result->fetch_assoc()) {
    echo json_encode(["success" => true] + $row);
} else {
    echo json_encode(["success" => false, "error" => "Tracking number not found"]);
}

// Close connection
$stmt->close();
$conn->close();
