<?php
/**
 * Admin API — Get Trashed Products
 * Returns only softly deleted products as JSON.
 */

session_start();
header('Content-Type: application/json');

// Guard: Only allow admins
if (empty($_SESSION['admin_logged_in'])) {
    http_response_code(401);
    echo json_encode(['status' => 'error', 'message' => 'Unauthorized']);
    exit;
}

require_once '../../includes/config.php';

try {
    $stmt = $pdo->query("SELECT id, name, category, price, image_url, description, created_at FROM products WHERE is_deleted = 1 ORDER BY category, name");
    $products = $stmt->fetchAll();

    echo json_encode([
        'status' => 'success',
        'count'  => count($products),
        'data'   => $products
    ]);
} catch (PDOException $e) {
    http_response_code(500);
    echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
?>
