<?php

$pages = [
    "index" => [
        "key" => "index",
        "name" => "Accueil",
        "desc" => 'Retour à l\'accueil du site',
    ],
    "services" => [
        "key" => "services",
        "name" => "Services",
        "desc" => "Services proposés",
    ],
    "cgu" => [
        "key" => "cgu",
        "name" => "C.G.U.",
        "desc" => 'Conditions Générales d\'Utilisation',
    ],
    "cgv" => [
        "key" => "cgv",
        "name" => "C.G.V.",
        "desc" => "Conditions Générales de Vente",
    ],
    "interventions" => [
        "key" => "interventions",
        "name" => "Interventions & Incidents",
        "desc" => "Interventions & incidents passés et à venir",
    ],
    "faq" => [
        "key" => "faq",
        "name" => "F.A.Q.",
        "desc" => "Questions Fréquentes",
    ],
    "aide" => [
        "key" => "aide",
        "name" => "Aide",
        "desc" => 'Obtenir de l\'aide',
    ],
    "contact" => [
        "key" => "contact",
        "name" => "Contact",
        "desc" => "Page de Contact",
    ],
    "mentions" => [
        "key" => "mentionslegales",
        "name" => "Mentions Légales",
        "desc" => "Consulter les mentions légales du site",
    ],
    "transparence" => [
        "key" => "transparence",
        "name" => "Transparence",
        "desc" => "Découvrir mon activité en détails",
    ],
    "tarifs" => [
        "key" => "tarifs",
        "name" => "Tarifs",
        "desc" => "Comment estimer un tarif libre",
    ],
    "finances" => [
        "key" => "finances",
        "name" => "Finances",
        "desc" => "fric = pognon",
    ],
];

$mainMenu = [
    $pages["index"],
    $pages["transparence"],
    $pages["services"],
    $pages["tarifs"],
    $pages["interventions"],
    $pages["faq"],
];

$currentPage = $pages["index"];

/**
 * Generate a link to a specified local page
 *
 * @param array $p details of the page to link to, either referring to $pages or provided
 * @param array $override optional override options, same format as $p
 * @return string HTML <a> element
 */
function pageLink(array $p, array $override = [])
{
    global $currentPage;

    if (!empty($override)) {
        $p = array_replace($p, $override);
    }

    $css = $currentPage == $p ? ["active", "item"] : ["item"];
    $anchor = isset($p["anchor"]) ? "#" . $p["anchor"] : "";
    $key = $p["key"] == "index" ? "index" : $p["key"];
    $url = "/" . $key . $anchor;

    return '<a class="' .
        implode(" ", $css) .
        '" href="http://leto.local/clawd.fr' .
        $url . '.php' .
        '" target="_self" title="' .
        $p["desc"] .
        '">' .
        $p["name"] .
        "</a>";
}
