<?php
    /** @var \lim\req $_req */
    $fd = $_view["searchQuery"] ?? [];
?>

<div class="main-container">
    <section>
        <div class="text-center">
            <h1 class="headline dotted d-inline-block d-lg-none space-mb-md"><?= formatNumber($_view["totalCount"], 0); ?> Mittelständler sind schon dabei</h1>
            <h2 class="headline big space-mb-lg d-block d-lg-none">Nachhaltige Unternehmen</h2>
        </div>
        <h1 class="headline big space-mb-lg d-none d-lg-block"><?= formatNumber($_view["totalCount"], 0); ?> Unternehmen.<br>
            Sichtbar nachhaltig und verantwortungsvoll.</h1>
        <div class="row g-c">
            <div class="col-lg-3">
                <div class="sticky-top filter-bar">
                    <div class="accordion accordion-flush d-block" id="filter">
                        <div class="accordion-item">
                            <h2 class="accordion-header">
                                <button class="accordion-button collapsed pb-2 mb-3 mt-4" type="button" data-bs-toggle="collapse" data-bs-target="#flush-collapseOne"
                                    aria-expanded="false" aria-controls="flush-collapseOne"> <b>Filter</b> </button>
                            </h2>
                            <div id="flush-collapseOne" class="accordion-collapse collapse" data-bs-parent="#filter">
                                <form id="interviewSearchForm" class="form" method="GET" action="<?= $_con->getLink(["profile", "index"]); ?>">
                                    <div class="input-group mb-3">
                                        <input type="text" name="name" value="<?= sanitizeFormInput($fd["name"] ?? ""); ?>" class="form-control" 
                                            placeholder="Suche nach Unternehmen" aria-label="Suche nach Unternehmen" aria-describedby="suche-unternehmen">
                                    </div>
                                    <div class="input-group mb-3">
                                        <input type="text" name="location|con" value="<?= sanitizeFormInput($fd["location|con"] ?? ""); ?>" class="form-control" 
                                            placeholder="Suche nach Stadt" aria-label="Suche nach Stadt" aria-describedby="suche-stadt">
                                    </div>
                                    <div class="accordion-body">
                                        <select name="category" class="form-select mb-3">
                                            <?php arrayToOptionsSet($_view["industryCategories"], $fd["category"] ?? "", "Suche nach Kategorie"); ?>
                                        </select>
                                        <select name="industryId" class="form-select mb-3">
                                            <?php arrayToOptionsSet($_view["industries"], $fd["industryId"] ?? "", "Suche nach Branche"); ?>
                                        </select>
                                    </div>
                                    <div class="btn lg btn-primary score w-100 ico right">
                                            <input type="submit" value="Suchen" class="">Suchen<span class="icon"></span>
                                    </div>
                                    <?php if ($_view["searchActive"]) { ?>
                                        <a href="<?= $_con->getLink(["profile", "index"]); ?>" class="btn btn-secondary sm ico left w-100 mt-2">
                                            <span class="icon"></span>Suche Zurücksetzen
                                        </a>
                                    <?php } ?>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-9 border-left-score">
                <div class="row g-c">
                    <div class="col-xl-12 text-center text-lg-start">
                        <h3 class="headline medium mb-4 d-none d-lg-block">
                            <?= $_view["searchActive"] ? $_view["searchCount"] . " Ergebnisse gefunden" : "Gelistete Unternehmen";?>
                        </h3>
                        <?php
                        foreach ($_view["searchQuery"] as $key => $label) {
                            $params = array_filter($_req->getCleanParameters(setOnly: true), fn ($val) => $val != $key, ARRAY_FILTER_USE_KEY);
                            $link = $_con->getLink(["profile", "index"], $params);
                            $label = $key == "industryId" ? $_view["industries"][$label] : $label;
                        ?>
                            <a href="<?= $link; ?>" class="filter txt-small"><span class="icon"></span> <?= $label; ?></a>
                        <?php } ?>
                    </div>
                    <?php foreach ($_view["searchResults"] as $row) { ?>
                    <div class="col-xl-4 col-sm-6">
                        <?= $_con->getRenderedView("profile/company.partial", $row); ?>
                    </div>
                    <?php } ?>
                </div>
                <div class="text-center">
                    <?php
                        if ($_view["searchPageData"] ?? null) {
                            $pgView = [
                                "pageData"      => $_view["searchPageData"],
                                "linkArgs"      => ["profile", "index"],
                                "linkParams"    => $_req->getCleanParameters("get"),
                            ];
                            echo $_con->getRenderedView("_common/pagination.partial", $pgView);
                        }
                    ?>
                </div>
            </div>
        </div>
    </section>
</div>

