<?php
require_once '../../config/database.php';

$query = "SELECT 
            SUM(CASE WHEN kondisi = 'Baik' THEN 1 ELSE 0 END) as baik,
            SUM(CASE WHEN kondisi = 'Rusak Ringan' THEN 1 ELSE 0 END) as rusak_ringan,
            SUM(CASE WHEN kondisi = 'Rusak Berat' THEN 1 ELSE 0 END) as rusak_berat
          FROM pdta_inventaris_barang";

$result = mysqli_query($conn, $query);
$data = mysqli_fetch_assoc($result);

header('Content-Type: application/json');
echo json_encode([
    'baik' => (int)$data['baik'],
    'rusak_ringan' => (int)$data['rusak_ringan'],
    'rusak_berat' => (int)$data['rusak_berat']
]);