<?php
session_start();
if(!isset($_SESSION['autorizovan']))
    header("Location: login.php");
require_once 'db.php';
$db = new Db();

if(isset($_GET['id']) && $_GET['id'] != '' ){
    $automobil = $db->AutomobilById($_GET['id']);
}
else { 
    echo "ID automobila nije definisan";
    return;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Polovni automobili</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>

    <div class="container-fluid p-5 bg-primary text-white text-center" style="padding: 5px !important;">
      <h1>Polovni automobili</h1>
      <p>Najbolja ponuda polovnih automobila u Srbiji</p> 
    </div>

    <div class="container mt-5">
        <div class="row">
            <div class="col-sm-6" onclick="open_modal()" >
                <img src="<?php echo $automobil['slika'] ?>" alt="" width="100%" class="thumbli" />
            </div>
            <div class="col-sm-6">
                <?php   echo "<h2 id='model'>Model: ".$automobil['model']."</h2>"; ?>
                <?php   echo "<h3 style='font-style: italic; color: grey;' >".$automobil['proizvodjac']."</h3>"; ?>

                <?php   echo "<h4>Detalji: </h4>"; ?>
                <?php   echo "<p>".$automobil['opis']."</p>"; ?>

                <?php   echo "<h4>Kilometraza: </h4>"; ?>
                <?php   echo "<p>".$automobil['kilometraza']." km </p>"; ?>

                <?php   echo "<h4>Godina proizvodnje: </h4>"; ?>
                <?php   echo "<p>".$automobil['godina_proizvodnje']."</p>"; ?>

                <?php   echo "<h4>Cena: ".$automobil['cena']." </h4>"; ?>
                <br />
                <a href="index.php"><button  type="button" class="btn btn-primary" > Vrati se na početnu</button></a>
            </div>
            
        </div>
    </div>
<?php

?>


<input id="open_modal_button" type="hidden"  data-bs-toggle="modal" data-bs-target="#myModal" />

<div class="modal" id="myModal">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">

      <div class="modal-header">
        <h4 class="modal-title"><?php echo "Model: ".$automobil['model']; ?> ?></h4>
        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
      </div>

      <div class="modal-body">
          <img src="<?php echo $automobil['slika']; ?>" alt="" width="100%" class="thumbli" />
      </div>

      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button>
      </div>

    </div>
  </div>
</div>

<script>

function open_modal(){
    document.getElementById("open_modal_button").click();
}
</script>