<?php
/**
 * @var News $post
 * @var \yii\web\View $this
 */

use app\models\base\Image;
use app\models\News;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;

$preview = $post->image;

$retina = $preview->getUrl(Image::SIZE_500x282,"webp");
$normal = $preview->getUrl(Image::SIZE_320x180,"webp");
$bad = $preview->getUrl(Image::SIZE_320x180,'jpg');
$bad = $bad?$bad:'/images/default.jpg';

if( $retina === false || $normal === false ){
	$normal = $bad;
	$retina = $bad;
}

$preview = $post->preview;
?>
<div class="inject" id="<?=$post->uid?>">
    <div class="illustration">
        <?php if($preview instanceof \app\models\base\Image):?>
            <div class="picture-cont-16x9">
                <a href="<?=$post->url?>">
                    <picture class="w-100">
                        <source srcset="<?=$normal?>, <?=$retina?> 2x" media="(min-width: 600px)">
                        <img src="<?=$bad?>" alt="<?=$post->photo_title?>" class="w-100" loading="lazy">
                    </picture>
                </a>
            </div>
        <?php else:?>
            <div class="picture-cont-16x9">
                <a href="<?=$post->url?>">

                </a>
            </div>
        <?php endif;?>

    </div>

    <div class="meta">
        <div class="breadcrumbs">
            <?php
            echo Html::a("НОВОСТИ", ["/news"], ['class' => "breadcrumb"]);
            $topic = $post->getTopics()->andWhere(['show'=>"Y","active"=>1])->one();
            if($topic instanceof \app\models\base\NewsTopic) {
                echo Html::a($topic->title, ["/news/{$topic->url}"], ['class' => "breadcrumb"]);
            }
            ?>
        </div>
        <h2 class="title"><a href="<?=$post->url?>"><?=$post->title?></a></h2>
    </div>
</div>
