<?php
require_once "connection.php";

if (isset($_GET['nama_merk']) && isset($_GET['nama_jenis'])) {
    $namaMerk = $con->real_escape_string($_GET['nama_merk']);
    $namaJenis = $con->real_escape_string($_GET['nama_jenis']);

    $sql = "
        SELECT namaTipe 
        FROM tblTipeKendaraan 
        WHERE idJenis IN (
            SELECT idJenis 
            FROM tblJenisKendaraan 
            WHERE namaJenis = '$namaJenis'
        ) AND idMerk IN (
            SELECT idMerk 
            FROM tblMerkKendaraan 
            WHERE namaMerk = '$namaMerk'
        )
        
    ";

    $result = $con->query($sql);

    if ($result && $result->num_rows > 0) {
        $return_arr['tipe_kendaraan'] = array();
        while ($row = $result->fetch_assoc()) {
            $return_arr['tipe_kendaraan'][] = array(
                'nama_tipe' => $row['namaTipe']
            );
        }
        echo json_encode($return_arr);
    } else {
        echo json_encode(["tipe_kendaraan" => []]); // kosong
    }
} else {
    echo json_encode(["error" => "Parameter tidak lengkap"]);
}
?>
