<?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/.
 */

require_once __DIR__ . "/required.php";

define("NICKELBOX", true);

require_once __DIR__ . "/lib/item.php";

$config = $database->select("config", ['key', 'value']);
$settings = [
    "sitename" => "Shop",
    "theme" => "default",
    "tax" => 8.5,
];
foreach ($config as $c) {
    $settings[$c['key']] = $c['value'];
}

$page = "home";

if (isset($_GET['page'])) {
    switch ($_GET['page']) {
        case "browse":
            if (isset($_GET['cat']) && $binstack->has('categories', ['catid' => $_GET['cat']])) {
                $page = "browse";
            } else {
                $page = "404";
            }
            break;
        case "search":
            $page = "search";
            break;
        case "item":
            if (isset($_GET['id']) && $binstack->has('items', ['itemid' => $_GET['id']])) {
                $page = "item";
            } else {
                $page = "404";
            }
            break;
        case "cart":
            $page = "cart";
            break;
        case "account":
            $page = "account";
            break;
        case "login":
            $page = "login";
            break;
        case "signup":
            $page = "signup";
            break;
        case "home":
        default:
            $page = "home";
    }
}
require __DIR__ . "/parts/head.php";
require __DIR__ . "/parts/nav.php";
require __DIR__ . "/parts/$page.php";
require __DIR__ . "/parts/footer.php";
