{block name='blog-overview'}
    {et_isShopVersionAtLeast value="5.5.0-rc.1" assign='shopIsAtLeast55'}
    {et_isShopVersionAtLeast value="5.6.0-rc.2" assign='shopIsAtLeast56'}
    {$lazyLoadImages=$lazyLoadImages|default:true}
    {block name='blog-overview-include-extension'}
        {include file='snippets/extension.tpl'}
    {/block}

    {block name='blog-overview-link-content'}
        {if $shopIsAtLeast56}
            {if isset($Link) && !empty($Link->getContent())}
                {opcMountPoint id='opc_before_content' inContainer=false}
                {container fluid=$Link->getIsFluid() class="link-content {if $Einstellungen.template.theme.left_sidebar === 'Y' && $boxesLeftActive}container-plus-sidebar{/if}"}
                {$Link->getContent()}
                {/container}
            {/if}
        {/if}
    {/block}

    {opcMountPoint id='opc_before_filter' inContainer=true}

    <div class="blog-overview">
        {* Filter Bar *}
        {block name='filter'}
            <div class="row blog-overview-main">
                <div class="col col-12 col-xl">
                    {get_static_route id='news.php' assign=routeURL}
                    {block name='blog-overview-form'}
                        <form id="frm_filter" method="POST" name="frm_filter" action="{$routeURL}" class="label-slide">
                            {csrf_token}
                            {formgroup}
                                <div class="form-row">
                                    {* Sorting *}
                                    <div class="col col-12 col-sm-4 col-lg-auto">
                                        {block name='blog-overview-form-sort'}
                                            <select name="nSort" class="form-control onchangeSubmit custom-select" aria-label="{lang key='newsSort' section='news'}">
                                                <option value="-1"{if $nSort === -1} selected{/if}>{lang key='newsSort' section='news'}</option>
                                                <option value="1"{if $nSort === 1} selected{/if}>{lang key='newsSortDateDESC' section='news'}</option>
                                                <option value="2"{if $nSort === 2} selected{/if}>{lang key='newsSortDateASC' section='news'}</option>
                                                <option value="3"{if $nSort === 3} selected{/if}>{lang key='newsSortHeadlineASC' section='news'}</option>
                                                <option value="4"{if $nSort === 4} selected{/if}>{lang key='newsSortHeadlineDESC' section='news'}</option>
                                                <option value="5"{if $nSort === 5} selected{/if}>{lang key='newsSortCommentsDESC' section='news'}</option>
                                                <option value="6"{if $nSort === 6} selected{/if}>{lang key='newsSortCommentsASC' section='news'}</option>
                                            </select>
                                        {/block}
                                    </div>

                                    {* Filter by date *}
                                    <div class="col col-12 col-sm-4 col-lg-auto">
                                        {block name='blog-overview-form-date'}
                                            <select name="cDatum" class="form-control onchangeSubmit custom-select" aria-label="{lang key='newsDateFilter' section='news'}">
                                                <option value="-1"{if $cDatum == -1} selected{/if}>{lang key='newsDateFilter' section='news'}</option>
                                                {if !empty($oDatum_arr)}
                                                    {foreach $oDatum_arr as $oDatum}
                                                        <option value="{$oDatum->cWert}"{if $cDatum == $oDatum->cWert} selected{/if}>{$oDatum->cName}</option>
                                                    {/foreach}
                                                {/if}
                                            </select>
                                        {/block}
                                    </div>

                                    {* Filter By Category *}
                                    {lang key='newsCategorie' section='news' assign='cCurrentKategorie'}
                                    {if $oNewsCat->getID() > 0}
                                        {assign var=kNewsKategorie value=$oNewsCat->getID()}
                                    {else}
                                        {assign var=kNewsKategorie value=$kNewsKategorie|default:0}
                                    {/if}
                                    <div class="col col-12 col-sm-4 col-lg-auto">
                                        {block name='blog-overview-form-categories'}
                                            <select name="{if $shopIsAtLeast55}{$smarty.const.QUERY_PARAM_NEWS_CATEGORY}{else}nNewsKat{/if}" class="form-control onchangeSubmit custom-select" aria-label="{lang key='newsCategorie' section='news'}">
                                                <option value="-1"{if $kNewsKategorie === -1} selected{/if}>{lang key='newsCategorie' section='news'}</option>
                                                {if !empty($oNewsKategorie_arr)}
                                                    {assign var=selectedCat value=$kNewsKategorie}
                                                    {block name='blog-overview-include-newscategories-recursive'}
                                                        {include file='snippets/newscategories_recursive.tpl' i=0 selectedCat=$selectedCat}
                                                    {/block}
                                                {/if}
                                            </select>
                                        {/block}
                                    </div>

                                    {* Items per Page *}
                                    <div class="col col-12 col-sm-4 col-lg-auto">
                                        {block name='blog-overview-form-items'}
                                            <select
                                                name="{$oPagination->getId()}_nItemsPerPage"
                                                id="{$oPagination->getId()}_nItemsPerPage"
                                                class="form-control onchangeSubmit custom-select"
                                                aria-label="{lang key='newsPerSite' section='news'}"
                                            >
                                                <option value="-1" {if $oPagination->getItemsPerPage() == 0} selected{/if}>
                                                    {lang key='showAll'}
                                                </option>
                                                {foreach $oPagination->getItemsPerPageOptions() as $nItemsPerPageOption}
                                                    <option value="{$nItemsPerPageOption}"{if $oPagination->getItemsPerPage() == $nItemsPerPageOption} selected{/if}>
                                                        {$nItemsPerPageOption}
                                                    </option>
                                                {/foreach}
                                            </select>
                                        {/block}
                                    </div>
                                </div>
                            {/formgroup}
                        </form>
                    {/block}
                </div>

                {* Pagination *}
                <div class="col col-12 col-sm-auto blog-overview-pagination">
                    {block name='blog-overview-include-pagination-top'}
                        {include file='snippets/pagination.tpl' oPagination=$oPagination cThisUrl='news.php' parts=['pagi'] noWrapper=true}
                    {/block}
                </div>
            </div>

            {* Divider *}
            {block name='blog-overview-hr-top'}
                <hr class="blog-overview-hr">
            {/block}
        {/block}

        {* Overview Content (ie Blog Posts) *}
        {block name='blog-overview-category'}
            {* No Posts *}
            {if $noarchiv === 1}
                {block name='blog-overview-alert-no-archive'}
                    <div role="alert" class="alert alert-info">{lang key='noNewsArchiv' section='news'}</div>
                {/block}
            {elseif !empty($newsItems)}
                <div id="newsContent" itemprop="mainEntity" itemscope itemtype="https://schema.org/Blog">
                    {* Category *}
                    {if $oNewsCat->getID() > 0}
                        {* Category Title *}
                        {block name='blog-overview-subheading'}
                            {opcMountPoint id='opc_before_news_category_heading'}
                            <h2>{$oNewsCat->getName()}</h2>
                        {/block}

                        {* Category Image/Description *}
                        {block name='blog-overview-preview-image'}
                            <div class="row">
                                {if !empty($oNewsCat->getPreviewImage())}
                                    <div class="col col-12 col-sm-8">
                                        {$oNewsCat->getDescription()}
                                    </div>
                                    <div class="col col-12 col-sm-4">
                                        {include file='snippets/image.tpl' item=$oNewsCat square=false center=true lazy=$lazyLoadImages}
                                    </div>
                                {else}
                                    <div class="col col-sm-12">{$oNewsCat->getDescription()}</div>
                                {/if}
                            </div>
                        {/block}
                    {/if}

                    {* Blog Post List *}
                    {opcMountPoint id='opc_before_news_list'}
                    {block name='blog-overview-previews'}
                        <div class="row blog-overview-preview">
                            {foreach $newsItems as $newsItem}
                                <div class="col col-12 col-md-6 col-lg-4 blog-overview-preview-item">
                                    {block name='blog-overview-include-preview'}
                                        {include file='blog/preview.tpl' lazyLoadImages=$lazyLoadImages}
                                    {/block}
                                </div>
                            {/foreach}
                        </div>
                    {/block}
                </div>
                {opcMountPoint id='opc_after_news_list'}

                {* Pagination Bottom *}
                {block name='blog-overview-include-pagination-bottom'}
                    {include file='snippets/pagination.tpl' oPagination=$oPagination cThisUrl='news.php' parts=['pagi']}
                {/block}
            {/if}
        {/block}
    </div>
{/block}
