<?php
use yii\web\View;
use \app\models\base\Tags;
use \app\models\Tagsfilter;
if( YII_ENV_DEV )
{
$tmodel = new Tags();
$session = Yii::$app->session;
$x =$session->get('filterx');

$items = Yii::$app->cache->getOrSet("tagsmenu",function () use($tmodel){
	return $tmodel->find()->rightJoin(['m'=>Tagsfilter::find()], 'm.id = tags.id')->orderBy('sort')->All();
});
?>
                <div class="header-bottom__button">
                    <span style="background-color: #eee;padding: 4px;cursor: pointer;border-radius: 7px;fill: #ff8813;" onclick="toggletFiltersModal();return false;">
                                <span class="button__icon"><i class="fa-solid fa-filter"></i>
									<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="width: 17px;height: 14px;" class="icon icon-tg"><title>фильтры материалов</title><path d="M3.9 54.9C10.5 40.9 24.5 32 40 32H472c15.5 0 29.5 8.9 36.1 22.9s4.6 30.5-5.2 42.5L320 320.9V448c0 12.1-6.8 23.2-17.7 28.6s-23.8 4.3-33.5-3l-64-48c-8.1-6-12.8-15.5-12.8-25.6V320.9L9 97.3C-.7 85.4-2.8 68.8 3.9 54.9z"/></svg>
                                </span>
                    </span>
                </div>
<div id="tfilters-modal" class="mymodal hidden shadow p-3 mb-5 bg-white rounded">
	<div class="modal-header">
        <h5 class="modal-title">Читать только</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="$('#tfilters-modal').addClass('hidden');">
          <span aria-hidden="true">&times;</span>
        </button>
    </div>
        <div class="form-group w-100 ml-4">
<?
foreach( $items as $item ){
?>
            <div class="form-check checkbox-lg">
				<input class="form-check-input exttag" type="checkbox" value="<?=$item->id?>" id="flexCheck<?=$item->id?>" name="ExtTag[<?=$item->id?>]"<?=($x && in_array($item->id,$x))?' checked':''?>>
				<label class="form-check-label" for="flexCheck<?=$item->id?>"><?=$item->title?></label><br>
            </div>
<?}?>
        </div>
        <span class="btn btn-gray" onclick="SendTfilter();">Применить фильтр</span>
</div>

<?php
$filterurl = \yii\helpers\Url::base('https')."/setfilters";
$this->registerJs(
<<<JS
    function toggletFiltersModal(){
		$("#tfilters-modal").toggleClass("hidden");
    }
    function SendTfilter(){
		$("#tfilters-modal").toggleClass("hidden");
		var selectElement = document.querySelectorAll('.exttag');
		var a = [];
		selectElement.forEach((el) => {
			if( el.checked ) a.push(el.value);
		});
		if( a.length == 0 ) a.push(0);
			$.getJSON( "$filterurl", { 'filters': a }, function( data ) {
				if( data.status == 'ok' ){
					document.location.reload();
				}
			});
    }
JS
    ,
    View::POS_END,
    'fmodal'
);

}
