{% extends '@nucleus/partials/particle.html.twig' %}

{% block stylesheets %}
{% if particle.particle_title_color or particle.particle_title_fontsize or particle.title_color or particle.title_fontsize or particle.meta_styles == 'list' %}
<style>
{% if particle.particle_title_color or particle.particle_title_fontsize %}
#{{ id }}.g5-particle-title { {% if particle.particle_title_color %}color: {{ particle.particle_title_color }};{% endif %}{% if particle.particle_title_fontsize %}font-size: {{particle.particle_title_fontsize}}px;{% endif %} }
{% endif %}
{% if particle.custom_content_color or particle.custom_content_fontsize %}
#{{ id }} .tm-content a, #{{ id }} .tm-content { {% if particle.custom_content_color %}color: {{particle.custom_content_color}} !important; {% endif %}{% if particle.custom_content_fontsize %}font-size: {{particle.custom_content_fontsize}}px;{% endif %} }
{% endif %}
{% if particle.meta_styles == 'list' %}
#{{ id }} ul.jl-subnav { padding-left: 0px; margin-left: -20px; }
{% endif %}
</style>
{% endif %}
{% endblock %}

{% set attr_extra = particle.extra|attribute_array %}
{% set article_settings = particle.article %}
{% set filter = article_settings.filter %}
{% set sort = article_settings.sort %}
{% set limit = article_settings.limit %}
{% set display = article_settings.display %}

{# Category Finder #}
{% set category_options = filter.categories ? {id: [filter.categories|split(','), 0]} : {} %}
{% set categories = joomla.finder('category', category_options).published(1).language().limit(0).find() %}

{# Content Finder #}
{% if filter.articles %}
    {% set article_options = filter.articles ? {id: [filter.articles|replace({' ': ''})|split(',')]} : {} %}
    {% set article_finder = joomla.finder('content', article_options).published(1).language() %}
{% else %}
    {% set article_finder = joomla.finder('content').category(categories).published(1).language() %}
{% endif %}

{% set featured = filter.featured|default('include') %}
{% if featured == 'exclude' %}
    {% do article_finder.featured(false) %}
{% elseif featured == 'only' %}
    {% do article_finder.featured(true) %}
{% endif %}

{% set start = limit.start + max(0, ajax.start|int) %}
{% do article_finder.order(sort.orderby, sort.ordering).limit(limit.total).start(start) %}
{% set total = article_finder.count() %}
{% set articles = article_finder.find() %}

{# Set Title/Meta/Content Text Transform #}
{% set title_text_transform = particle.title_text_transform ? ' jl-text-' ~ particle.title_text_transform|e ~ '' %}
{% set meta_text_transform = particle.meta_text_transform ? ' jl-text-' ~ particle.meta_text_transform|e ~ '' %}

{# Set Scrollspy Animation #}
{% set scrollspy_cls = particle.animation != 'inherit' ? ' jl-scrollspy-class' %}

{# Set Animation #}
{% set animation %}
{% if particle.animation != 'inherit' %} jl-scrollspy="target: [jl-scrollspy-class]; cls: jl-animation-{{particle.animation|e}};{% if particle.animation_repeat == 'enabled' %} repeat: true;{% endif %} delay:{% if particle.delay_element_animations %}{{particle.animation_delay|default('200')|e}};{% else %}false;{% endif %}"{% endif %}
{% endset %}

{# Set Max-Width Content #}
{% set content_maxwidth %}
{% if particle.g_maxwidth != 'inherit' %} jl-width-{{particle.g_maxwidth}}{% if particle.g_maxwidth_breakpoint != 'always' %}@{{particle.g_maxwidth_breakpoint}}{% endif %}{% if particle.g_maxwidth_alignment == 'left' %}{% elseif particle.g_maxwidth_alignment == 'center' %} jl-margin-auto{% else %} jl-margin-auto-left{% endif %}{% endif %}
{% endset %}

{# Set Particle Alignment #}
{% set particle_alignment %}
{% if particle.align != 'inherit' %} jl-text-{{particle.align|e}}{% if particle.breakpoint != 'always' %}@{{particle.breakpoint|e}}{% endif %}{% endif %}{% if particle.align != 'inherit' and particle.breakpoint != 'always' %}{% if particle.fallback != 'inherit' %} jl-text-{{particle.fallback|e}}{% endif %}{% endif %}
{% endset %}

{# Set Particle Alignment for Subnav style #}
{% set subnav_alignment %}
{% if particle.align != 'inherit' %} jl-flex-{{particle.align|e}}{% if particle.breakpoint != 'always' %}@{{particle.breakpoint|e}}{% endif %}{% endif %}{% if particle.align != 'inherit' and particle.breakpoint != 'always' %}{% if particle.fallback != 'inherit' %} jl-flex-{{particle.fallback|e}}{% endif %}{% endif %}
{% endset %}

{# set Particle Title Style #}
{% set particle_title_style %}
{% if particle.particle_title %}
<{{particle.particle_title_element|e}} id="{{ id }}" class="g5-particle-title{% if particle.particle_title_align != 'inherit' %} jl-text-{{particle.particle_title_align|e}}{% endif %}{% if particle.particle_predefined_color != 'default' %} jl-text-{{particle.particle_predefined_color|e}}{% endif %}{% if particle.particle_title_style != 'default' %} jl-{{particle.particle_title_style|e}}{% endif %}{% if particle.particle_title_decoration != 'none' %} jl-heading-{{particle.particle_title_decoration|e}}{% endif %}">
{% if particle.particle_title_decoration == 'line' %} <span>{{particle.particle_title|raw}}</span>
{% else %} {{particle.particle_title|raw}}
{% endif %}
</{{particle.particle_title_element|e}}>
{% endif %}
{% endset %}

{# Set Image Width/Height #}
{% set imagewidth = particle.image_width ? ' width="' ~ particle.image_width ~ '"' %}
{% set imageheight = particle.image_height ? ' height="' ~ particle.image_height ~ '"' %}
{# Image Box Shadow #}
{% set image_boxshadow = particle.box_shadow != 'none' ? ' jl-box-shadow-' ~ particle.box_shadow|e ~ '' %}
{% set image_boxshadow_hover = particle.box_shadow_hover != 'none' ? ' jl-box-shadow-hover-' ~ particle.box_shadow_hover|e ~ '' %}

{# Set Image Border Class #}
{% set image_border_cls = particle.image_border != 'none' ? ' jl-border-' ~ particle.image_border|e ~ '' %}

{% set image_transition = particle.image_transition != 'none' ? ' jl-transition-' ~ particle.image_transition|e ~ ' jl-transition-opaque' %}
{# Set Title hover #}
{% set title_hover = (particle.title_hover ? ' class="jl-link-'~ particle.title_hover ~'"') %}
{% set link_transition = particle.link_card and particle.image_transition != 'none' ? ' jl-transition-toggle' %}
{# Set Item Content #}
{% set item_content %}
{% for article in articles %}

{# Set Meta Content #}
{% set item_meta %}
{% if display.date.enabled or display.author.enabled or display.category.enabled or display.hits.enabled %}
{% if particle.meta_styles == 'list' %}
<ul class="tm-meta{{meta_text_transform}}{{subnav_alignment}} jl-subnav{% if particle.meta_subnav_style != 'default' %} jl-subnav-{{particle.meta_subnav_style|e}}{% endif %}{% if particle.meta_margin_top == 'default' %} jl-margin-top{% else %} jl-margin-{{ particle.meta_margin_top|e }}-top{% endif %}">
{% if display.date.enabled %}
<li class="g-array-item-date">
  <span>
  {% if display.date.enabled == 'published' %}
  {{ article.publish_up|date(display.date.format) }}
{% elseif display.date.enabled == 'modified' %}
{{ article.modified|date(display.date.format) }}
{% else %}
  {{ article.created|date(display.date.format) }}
{% endif %}
</span>
</li>
{% endif %}

{% if display.author.enabled %}
<li class="g-array-item-author">
  <span>{{ article.author.name }}</span>
</li>
{% endif %}

{% if display.category.enabled %}
{% set category_link = display.category.enabled == 'link' %}
<li class="g-array-item-category">
{% set cat = article.categories|last %}
{% if category_link and particle.link_card == false %}
<a href="{{ cat.route }}">
{{ cat.title }}
</a>
{% else %}
<span class="g-array-item-category">{{ cat.title }}</span>
{% endif %}
</li>
{% endif %}

{% if display.hits.enabled %}
<li class="g-array-item-hits">
  <span><i class="fa fa-eye" aria-hidden="true"></i> {{ article.hits }}</span>
</li>
{% endif %}
</ul>
{% else %}
<p class="{% if particle.meta_margin_top == 'default' %} jl-margin-top{% else %} jl-margin-{{ particle.meta_margin_top|e }}-top{% endif %} jl-margin-remove-bottom jl-article-meta">

{% if display.author.enabled %}
    {{ particle.author_meta|default('Written by')|raw}} {{ article.author.name }}
{% endif %}

{% if display.author.enabled and display.date.enabled %}
{% set meta_date = particle.date_meta|default('on')|raw %}
{% else %}
{% set meta_date = particle.date_meta|default('Written on')|raw %}
{% endif %}

{% if display.date.enabled %}
    {% if display.date.enabled == 'published' %}
        {{ meta_date }} {{ article.publish_up|date(display.date.format) }}{{ '.'|trim }}
    {% elseif display.date.enabled == 'modified' %}
        {{ meta_date }} {{ article.modified|date(display.date.format) }}{{ '.'|trim }}
    {% else %}
        {{ meta_date }} {{ article.created|date(display.date.format) }}{{ '.'|trim }}
    {% endif %}
{% endif %}

{% if display.category.enabled %}
    {% set category_link = display.category.enabled == 'link' %}
    {% set cat = article.categories|last %}
    {% if category_link and particle.link_card == false %}
        {{ particle.category_meta|default('Posted in')|raw}} <a href="{{ cat.route }}">{{ cat.title }}</a>
    {% else %}
        {{ particle.category_meta|default('Posted in')|raw}} {{ cat.title }}
    {% endif %}
{% endif %}

{% if display.hits.enabled %}
    <span class="g-array-item-hits">
        <i class="fa fa-eye" aria-hidden="true"></i> {{ article.hits }}
    </span>
{% endif %}

</p>
{% endif %}
{% endif %}
{% endset %}

<li class="tm-item"{{scrollspy_cls}}>

{% if display.edit and article.edit %}
    <a class="g-array-item-edit" href="{{ article.edit }}"><i class="fa fa-pencil" aria-hidden="true"></i> {{ 'JGLOBAL_EDIT'|trans }}</a>
{% endif %}

{% if particle.link_card %}
    <a class="jl-panel jl-margin-remove-first-child jl-display-block jl-link-toggle{{link_transition}}" href="{{ article.route }}" target="{{ particle.link_target|default('_self')|e }}">
{% endif %}

{% if display.image.enabled and article.images.image_intro or article.images.image_fulltext %}

<div class="jl-grid-small jl-child-width-expand jl-flex-nowrap{% if particle.img_vertical_alignment == '1' %} jl-flex-middle{% endif %}" jl-grid>
<div class="jl-width-{{ particle.image_grid_width }}{% if particle.image_grid_breakpoint != 'default' %}@{{ particle.image_grid_breakpoint|e }}{% endif %}{% if particle.image_alignment == 'right' %} jl-flex-last{% endif %}">

{% if particle.link_image and particle.link_card == false %}<a class="jl-display-block" href="{{ article.route }}" target="{{ particle.link_target|default('_self')|e }}">{% if particle.image_transition != 'none' %}<div class="jl-inline-clip jl-transition-toggle">{% endif %}{% endif %}
{% if particle.link_card and particle.image_transition != 'none' %}<div class="jl-inline-clip">{% endif %}

{% if article.images.image_intro and display.image.enabled == 'intro' or display.image.enabled == 'show' %}
 
  <img{{imagewidth|raw}}{{imageheight|raw}} class="tm-image{{image_border_cls}}{{image_boxshadow}}{{image_boxshadow_hover}}{{image_transition}}" src="{{ url(article.images.image_intro) }}"{% if article.images.image_intro_alt %} alt="{{article.images.image_intro_alt}}"{% else %} alt="{{ display.title.limit ? article.title|truncate_text(display.title.limit) : article.title }}"{% endif %}>

{% elseif article.images.image_fulltext and display.image.enabled == 'full' %}
 
  <img{{imagewidth|raw}}{{imageheight|raw}} class="tm-image{{image_border_cls}}{{image_boxshadow}}{{image_boxshadow_hover}}{{image_transition}}" src="{{ url(article.images.image_fulltext) }}"{% if article.images.image_fulltext_alt %} alt="{{article.images.image_fulltext_alt}}"{% else %} alt="{{ display.title.limit ? article.title|truncate_text(display.title.limit) : article.title }}"{% endif %}>

{% endif %}

  {% if particle.link_card and particle.image_transition != 'none' %}</div>{% endif %}
  {% if particle.link_image and particle.link_card == false %}{% if particle.image_transition != 'none' %}</div>{% endif %}</a>{% endif %}

</div>
<div>

<div class="jl-panel jl-margin-remove-first-child">

{% endif %}

{% if particle.meta_alignment == 'top' %}
    {{item_meta}}
{% endif %}

{% if display.title.enabled %}
<{{particle.title_element|e}} class="tm-title jl-margin-remove-bottom{{title_text_transform}}{% if particle.title_margin_top == 'default' %} jl-margin-top{% else %} jl-margin-{{ particle.title_margin_top|e }}-top{% endif %}{% if particle.title_color != 'default' %} jl-text-{{particle.title_color|e}}{% endif %}{% if particle.title_style != 'default' %} jl-{{particle.title_style|e}}{% endif %}{% if particle.title_decoration != 'none' %} jl-heading-{{particle.title_decoration|e}}{% endif %}">
{% if particle.title_decoration == 'line' %}
<span>
{% endif %}
{% if particle.link_title and particle.link_card == false %}
<a{{ title_hover|raw }} href="{{ article.route }}" target="{{ particle.link_target|default('_self')|e }}" title="{{ display.title.limit ? article.title|truncate_text(display.title.limit) : article.title }}">
{{ display.title.limit ? article.title|truncate_text(display.title.limit) : article.title }}
</a>
{% else %}
{{ display.title.limit ? article.title|truncate_text(display.title.limit) : article.title }}
{% endif %}
{% if particle.title_decoration == 'line' %}
</span>
{% endif %}
</{{particle.title_element|e}}>
{% endif %}

{% if particle.meta_alignment == 'bottom' %}
{{item_meta}}
{% endif %}

{% if display.text.type %}
    {% set article_text = display.text.type == 'intro' ? display.text.prepare ? article.preparedIntroText : article.introtext : display.text.prepare ? article.preparedText : article.text %}
    <div class="tm-content jl-panel{% if particle.content_style != 'default' %} jl-{{ particle.content_style|e }}{% endif %}{% if particle.content_margin_top == 'default' %} jl-margin-top{% else %} jl-margin-{{ particle.content_margin_top|e }}-top{% endif %}{% if particle.content_visibility != 'always' %} jl-visible@{{ particle.content_visibility }}{% endif %}">
        {% if display.text.formatting == 'text' %}
            {{ article_text|truncate_text(display.text.limit)|raw }}
        {% else %}
            {{ article_text|truncate_html(display.text.limit)|raw }}
        {% endif %}
    </div>
{% endif %}

{% if particle.meta_alignment == 'content' %}
    {{item_meta}}
{% endif %}

{% if display.image.enabled and article.images.image_intro or article.images.image_fulltext %}

</div>

</div>

</div>

{% endif %}

{% if particle.link_card %}
    </a>
{% endif %}

</li>
{% endfor %}
{% endset %}

{% block particle %}
{% if particle.enabled %}
{{particle_title_style}}
<div id="{{ id }}" class="tm-content-wrapper{{content_maxwidth}}{% if particle.class %} {{ particle.class }}{% endif %}{{particle_alignment}}{% if particle.margin == 'inherit' %}{% elseif particle.margin == 'default' %} jl-margin{% else %} jl-margin-{{particle.margin|e}}{% endif %}{% if particle.visibility != 'inherit' %} jl-visible@{{particle.visibility|e}}{% endif %}"{{animation}} {{- attr_extra|raw }}>
<ul class="jl-list{% if particle.list_style != 'default' %} jl-list-{{particle.list_style|e}}{% endif %}{% if particle.large_padding == '1' %} jl-list-large{% endif %}">
    {{item_content}}
</ul>
</div>
{% endif %}
{% endblock %}