<?php
// ajout des recherche par mot clé etc.

echo "<div id='filter-selectors' class='flex flex-gap-2 w-100'>";
foreach($itemdescr->content as $cle=>$value){
    
    if($itemdescr->getParam($cle,"searchable",false)){
        switch($value['type']){
            case "radio":
                display_newoptions($value,$value['type'],$cle, $itemdescr);
                break;
            case "checkbox":
                display_newoptions($value,$value['type'],$cle, $itemdescr);
                break;
            case "select":
                display_newoptions($value, "checkbox",$cle, $itemdescr);
                break;
        }
    }  
}
echo "</div>";
echo "<div id='filter-container' class='flex flex-gap-2'><div id='removefilter' class='py-1 px-2 border-rounded-1' onclick='yc_filter_removeall()' title='Supprimer tout'>X</div></div>";

function display_newoptions($value,$type,$cle, $itemdescr){
    $options=$itemdescr->getOptionarray($cle);
    echo "<div class='filter-item'>";
    echo "<div class='filter-header bg-gray-5 py-1 px-3 ff-bold-secondary' data-filter-key='".$cle."' data-active='false' onclick='yc_filter_activategroup(this)'>";
    echo $value['label'];
    echo "</div>";
    echo "<div class='filter-body bg-gray-5 px-1' data-filter-key='".$cle."'>";
    
    foreach($options as $option => $titre){
            echo "<div data-key='".$cle."' data-value='".$option."' data-check='false' onclick='yc_filter_select(this)' class='py-1 px-2 border-rounded-1'>".$titre."</div>";
        }
    
    echo "</div></div>";
}

function display_options($value,$type,$cle, $itemdescr){
    echo "<div class='my-3 fs-small' data-filtre='".$cle."' data-type='".$type."'><span class='ff-bold-secondary'>".$value['label']."&nbsp;:</span>&nbsp;";

    // ajout d'un bouton rester pour les radio
    if($type=="radio"){
        echo "<span class='pr-1'>";
        echo "<input type='radio' name='".$cle."' value='' id='na' checked><label class='btn-cartouche' for='na' onClick='yc_reset_filter(\"".$cle."\")'>Reset</label>";
        echo "</span>";
    }

    $options=$itemdescr->getOptionarray($cle);
    if(count($options)> 10){
        
        // multiple sélection?
        $addmult="";
        if($type=="checkbox" || ($type="select" && $itemdescr->isTagmultiple($cle))){
            $addmult=" multiple";
        }
        
        echo "<select class='btn-select' name='".$cle."' onchange='yc_filtre_items()'".$addmult.">";
        foreach($options as $option => $titre){
            echo "<option value='".$option."'>".$titre."</option>";
        }
        echo "</select>";
    } else {
        foreach($options as $option => $titre){
            echo "<span class='pr-1'>";
            echo "<input type='".$type."' name='".$cle."' value='".$titre."' ";
            if($type!="radio"){ echo "checked"; }
            echo " id='".makeid($titre)."'><label class='btn-cartouche' for='".makeid($titre)."'>".$titre."</label>";
            echo "</span>";
        }
    }
    echo "</div>";
}
?>
<!-- <div class="btn btn-ok btn-small" onclick="empty_filtre(true)">Réinitialiser</div> <div class="btn btn-ok btn-small" onclick="empty_filtre(false)">Tout déselectionner</div> -->