<?php
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
if (!defined('NICKELBOX')) {
    die("Direct access denied.");
}

$item = new Item($_GET['id']);
?>

<div class="container">
    <div class="row">
        <div class="col-md-4">
            <!-- Item image(s) go here -->
        </div>

        <div class="col-md-8">
            <div class="row mt-4">
                <div class="col-sm-7 jumbotron py-4">
                    <h2><?php echo $item->getName(); ?></h2>
                    <p>in <a href="./?page=browse&cat=<?php echo $item->getCategoryId(); ?>"><?php echo $item->getCategoryName(); ?></a></p>
                    <h3>$<?php echo $item->getPrice(); ?></h3>
                </div>
                <div class="col-sm-5">
                    <form action="./action.php" method="POST">
                        <input type="number" name="qty" class="form-control mb-2" placeholder="Quantity" value="1" />
                        <button type="submit" class="btn btn-block btn-primary"><i class="fas fa-cart-plus"></i> Add to Cart</button>
                        <input type="hidden" name="item" value="<?php echo $item->getId(); ?>" />
                        <input type="hidden" name="action" value="addtocart" />
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="row mt-4 mt-sm-0">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <h5 class="card-title">Description</h5>

                    <p>
                        <?php
                        $desc = $item->getDescription();
                        if (empty($desc)) {
                            echo "No item information found.";
                        } else {
                            echo htmlspecialchars($desc);
                        }
                        ?>
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>