{% set page = app.request.get('page') %}
{% set query = app.request.get('s') %}
{% set tags = app.request.get('tags') %}
{% set allBlogs = getBlogs({'page': page, 'query': query, 'tags': tags}, app.request) %}
{% set mainBlog = allBlogs["mainBlog"] %}
{% set blogs = allBlogs["blogs"] %}
{% set pageCount = allBlogs["pageCount"] %}
{% set search = app.request.get('s') %}
{% set filterTags = app.request.get('tags') %}
{% set blogTags = getBlogTags(app.request) %}
<div class="blog-content">
    {% if (mainBlog is not defined or not mainBlog) and (blogs|length) == 0 %}
        <span class="blog-not-found not-found">{{"blog_not_found"|trans|capitalize}}</span>
    {% else %}
        {% if mainBlog is defined and mainBlog %}
            {% include 'components/_blog-item.html.twig' with {type: "main", blog: mainBlog} %}
        {% endif %}
        {% for blog in blogs %}
            {% include 'components/_blog-item.html.twig' with {blog: blog} %}
        {% endfor %}
    {% endif %}
</div>
{% if (mainBlog) or (blogs|length > 0) %}
    <div class="blog-page-navigator">
        {% set navCount = 2 %}

        {% if not page %}{% set page = 1 %}{% endif %}
        {% set page = page|number_format %}

        <a{% if page <= 1 %} style="opacity: 0;pointer-events:none;"{% endif %} href="{{path('blog', {'s': search, 'tags': filterTags, 'page': page-1})}}" class="prev-button">{{"back"|trans|title}}</a>

        {% for i in (1..(navCount))|reverse %}
            {% if page > i %}
                <a href="{{path('blog', {'s': search, 'tags': filterTags, 'page':  page-i})}}" class="border-button big-button">0{{page-i}}</a>
            {% endif %}
        {% endfor %}

        <div class="border-button big-button active">0{{page}}</div>
        
        {% for i in ((page + 1)..(page + navCount)) %}
            {% if i - 1 < pageCount %}
                <a href="{{path('blog', {'s': search, 'tags': filterTags, 'page':  i})}}" class="border-button big-button">0{{i}}</a>
            {% endif %}
        {% endfor %}

        <a{% if page >= pageCount %} style="opacity: 0;pointer-events:none;"{% endif %} href="{{path('blog', {'s': search, 'tags': filterTags, 'page': page+1})}}" class="next-button">{{"next"|trans|title}}</a>
    </div>
{% endif %}