<?php
function article_list($list = null)
{
    $content = '';
    $filters = '
        <form method="get" action="articles.php">
            <input type="hidden" name="view" value="sort">
            <div class="row_space_between no_margin">
    ';

    if (!isset($_GET['sort']) || $_GET['sort'] == 'newest') {
        $ids = article_ids_by_newest();
        $filters .= '
            <p>Newest - Oldest</p>
            <label for="recency_desc"><i class="nf nf-md-sort_clock_descending_outline"></i>
                <input id="recency_desc" type="radio" name="sort" value="oldest" onclick="this.form.submit()">
            </label>
        ';
    } else if ($_GET['sort'] == 'oldest') {
        $ids = article_ids_by_oldest();
        $filters .= '
            <p>Oldest - Newest</p>
            <label for="recency_asc"><i class="nf nf-md-sort_clock_ascending_outline"></i>
                <input id="recency_asc" type="radio" name="sort" value="newest" onclick="this.form.submit()">
            </label>
        ';
    }

    $filters .= '
            </div>
        </form>
    ';

    $content .= '
    <div class="article_cards_grid">
        <div class="article_filters">
            ' . $filters . '
        </div>
        <div class="article_cards">
    ';

    if (!isset($list))
        foreach ($ids as $id)
            $content .= article_card($id);
    else
        foreach ($list as $id)
            $content .= article_card($id);

    $content .= '
        </div>
    </div>
    ';

    return $content;
}
