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

{% block stylesheets %}
<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.title_color or particle.title_fontsize %}
#{{ id }} .tm-title { {% if particle.title_color %}color: {{particle.title_color}}; {% endif %}{% if particle.title_fontsize %}font-size: {{particle.title_fontsize}}px;{% endif %} }
{% endif %}
{% if particle.title_backgroundcolor %}
#{{ id }} .tm-heading { {% if particle.title_backgroundcolor %}background-color: {{particle.title_backgroundcolor}}; {% endif %} }
{% if gantry.page.direction == 'rtl' %}
#{{ id }} .tm-heading {position: relative; margin-left: 20px;}
{% else %}
#{{ id }} .tm-heading {position: relative; margin-right: 20px;}
{% endif %}
#{{ id }} .tm-heading:after {content: '';position: absolute;border: 10px solid transparent;top: 50%;transform: translateY(-50%);}
{% if gantry.page.direction == 'rtl' %}
#{{ id }} .tm-heading:after {left: -20px;border-right-color: {{particle.title_backgroundcolor}};}
{% else %}
#{{ id }} .tm-heading:after {right: -20px;border-left-color: {{particle.title_backgroundcolor}};}
{% endif %}
{% if particle.title_alignment == 'right' %}
{% if gantry.page.direction == 'rtl' %}
#{{ id }} .tm-heading {position: relative; margin-left: 0px;}
{% else %}
#{{ id }} .tm-heading {position: relative; margin-right: 0px;}
{% endif %}
#{{ id }} .tm-heading-right .tm-heading:after {border: 10px solid transparent;transform: translateY(-50%);}
{% if gantry.page.direction == 'rtl' %}
#{{ id }} .tm-heading-right .tm-heading:after {right: -20px;left: 100%;border-left-color: {{particle.title_backgroundcolor}};}
{% else %}
#{{ id }} .tm-heading-right .tm-heading:after {left: -20px;right: 100%;border-right-color: {{particle.title_backgroundcolor}};}
{% endif %}
{% endif %}
{% endif %}
{% if particle.content_backgroundcolor %}
#{{ id }} .tm-content { {% if particle.content_backgroundcolor %}background-color: {{particle.content_backgroundcolor}}; {% endif %} }
{% endif %}
#{{ id }} .tm-content, .tm-heading { padding: {{particle.padding|default('10')|e}}px;}
#{{ id }} .tm-item p { {% if particle.subtitle_color %}color: {{particle.subtitle_color}};{% endif %}{% if particle.subtitle_fontsize %} font-size: {{particle.subtitle_fontsize}}px;{% endif %} }
#{{ id }} .jl-slidenav.jl-icon { width: 30px;}
@media (max-width:960px){
    .g-news-ticker .tm-heading,.g-news-ticker .tm-heading-right{margin:0!important}
    .g-news-ticker .tm-heading-right:after,.g-news-ticker .tm-heading:after{display:none}
}
</style>
{% 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 slider_animation_set = particle.slider_animation_set == 'enabled' ? 'sets: 1;' %}
{% set slider_animation_center = particle.slider_animation_center == 'enabled' ? 'center: 1;' %}
{% set slider_animation_finite = particle.slider_animation_finite == 'enabled' ? 'finite: 1;' %}
{% set slider_animation_autoplay = particle.slider_animation_autoplay == 'enabled' ? 'autoplay: 1;' %}
{% set slider_animation_interval = (particle.slider_animation_autoplay == 'enabled' and particle.slider_animation_interval) ? 'autoplay-interval:' ~ particle.slider_animation_interval * 1000 ~ ';' %}
{% set slider_pause_onhover = particle.slider_pause_onhover == 'disabled' ? 'pauseOnHover: false;' %}
{% set velocity = particle.slider_velocity ? 'velocity:' ~ particle.slider_velocity / 100 ~ ';' %}

{# Set Animation #}
{% set animation %}
{% if particle.animation != 'inherit' %} jl-scrollspy="cls: jl-animation-{{particle.animation|e}};{% if particle.animation_repeat == 'enabled' %} repeat: true;{% endif %}{% if particle.animation_delay %} delay: {{particle.animation_delay|e}};{% 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 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 title_hover = (particle.title_hover ? ' class="jl-link-'~ particle.title_hover ~'"') %}

{% block particle %}
{% if particle.enabled %}

{{particle_title_style}}
<div id="{{ id }}" class="g-news-ticker{{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 %}{% if particle.extra_shadow == '1' %} jl-box-shadow-bottom jl-width-1-1{% endif %}"{{animation}} {{- attr_extra|raw }}>

<div class="jl-child-width-expand{% if particle.title_grid_gutter != 'default' %} jl-grid-{{ particle.title_grid_gutter|e }}{% endif %}{% if particle.title_vertical_alignment == '1' %} jl-flex-middle{% endif %}{% if particle.box_shadow != 'none' %} jl-box-shadow-{{particle.box_shadow|e}}{% endif %}{% if particle.box_shadow_hover != 'none' %} jl-box-shadow-hover-{{particle.box_shadow_hover|e}}{% endif %}{% if particle.card_style != 'blank' %} jl-card jl-card-{{ particle.card_style }}{% if particle.cardsize != 'default' %} jl-card-{{ particle.cardsize }}{% endif %}{% endif %}" jl-grid>

{% if particle.title_text is not empty %}
<div class="jl-width-{{ particle.title_grid_width }}{% if particle.title_grid_breakpoint != 'default' %}@{{ particle.title_grid_breakpoint|e }}{% endif %}{% if particle.title_alignment == 'right' %} tm-heading-right jl-flex-last{% if particle.title_grid_breakpoint != 'default' %}@{{ particle.title_grid_breakpoint|e }}{% endif %}{% endif %}">
<div class="jl-card tm-heading">
<div class="tm-title{{title_text_transform}}">
{{ particle.title_text|raw }}
</div>
</div>
</div>
{% endif %}

<div jl-slider="{{slider_animation_set}}{{slider_animation_center}}{{slider_animation_finite}}{{velocity}}{{slider_animation_autoplay}}{{slider_animation_interval}}{{slider_pause_onhover}}">

<div class="tm-content jl-panel">

<div class="jl-position-relative{% if particle.slidenav_hover == 'enabled' %} jl-visible-toggle{% endif %}">
<ul class="jl-slider-items jl-grid{% if particle.slider_divider == 'enabled' %} jl-grid-divider{% endif %}{% if particle.slider_gutter != 'default' %} jl-grid-column-{{ particle.slider_gutter|e }}{% endif %}">

{% for article in articles %}
<li class="tm-item{% if particle.phone_portrait %} jl-width-{{ particle.phone_portrait|e }}{% endif %}{% if particle.phone_landscape != 'inherit' %} jl-width-{{ particle.phone_landscape|e }}@s{% endif %}{% if particle.tablet_landscape != 'inherit' %} jl-width-{{ particle.tablet_landscape|e }}@m{% endif %}{% if particle.desktop != 'inherit' %} jl-width-{{ particle.desktop|e }}@l{% endif %}{% if particle.large_desktop != 'inherit' %} jl-width-{{ particle.large_desktop|e }}@xl{% endif %}" tabindex="-1">

{% if display.title.enabled %}
{% if particle.link_title %}
<a{{ title_hover|raw }} href="{{ article.route }}" target="{{ particle.linktarget|default('_self')|e }}">
{{ 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 %}
{% endif %}

{% if display.date.enabled %}
    <span class="jl-label g-array-item-date">
        {% if display.date.enabled == 'published' %}
            <i class="fa fa-clock-o" aria-hidden="true"></i> {{ article.publish_up|date(display.date.format) }}
        {% elseif display.date.enabled == 'modified' %}
            <i class="fa fa-clock-o" aria-hidden="true"></i> {{ article.modified|date(display.date.format) }}
        {% else %}
            <i class="fa fa-clock-o" aria-hidden="true"></i> {{ article.created|date(display.date.format) }}
        {% endif %}
    </span>
{% 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 %}
    {% if display.title.enabled and display.text.type %}
    <p class="g-array-item-text jl-margin-small-top">
    {% else %}
    <p class="g-array-item-text">
    {% endif %}
    {% if particle.link_content %}
    <a{{ title_hover|raw }} href="{{ article.route }}" target="{{ particle.linktarget|default('_self')|e }}">
    {% endif %}
        {% if display.text.formatting == 'text' %}
            {{ article_text|truncate_text(display.text.limit)|raw }}
        {% else %}
            {{ article_text|truncate_html(display.text.limit)|raw }}
        {% endif %}
    {% if particle.link_content %}
    </a>
    {% endif %}        
    </p>
{% endif %}
{% 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 %}
</li>
{% endfor %}

</ul>

{% if particle.slidenav_icon_left and particle.slidenav_icon_right %}
{% set slidenav_icon_left = '<i class="' ~ particle.slidenav_icon_left ~ '" aria-hidden="true"></i>' %}
{% set slidenav_icon_right = '<i class="' ~ particle.slidenav_icon_right ~ '" aria-hidden="true"></i>' %}
{% else %}
{% set slidenav_next = 'jl-slidenav-next' %}
{% set slidenav_prev = 'jl-slidenav-previous' %}
{% endif %}

{% set slidenav_text_color = particle.slidenav_color != 'default' ? ' jl-' ~ particle.slidenav_color ~ '' %}

{# Set Slidenav #}
{% if particle.slidenav_position != 'none' %}
{% if particle.slidenav_position == 'default' %}
<div class="{% if particle.slidenav_breakpoint != 'always' %}jl-visible@{{particle.slidenav_breakpoint|e}}{% endif %}{{ particle.slidenav_hover == 'enabled' ? ' jl-hidden-hover jl-hidden-touch' : '' }}{{slidenav_text_color}}">
<a class="tm-slidenav{% if particle.slidenav_margin != 'none' %} jl-position-{{ particle.slidenav_margin|e }}{% endif %} jl-position-center-left" href="#" {{slidenav_prev}} jl-slider-item="previous">{{slidenav_icon_left|raw}}</a>
<a class="tm-slidenav{% if particle.slidenav_margin != 'none' %} jl-position-{{ particle.slidenav_margin|e }}{% endif %} jl-position-center-right" href="#" {{slidenav_next}} jl-slider-item="next">{{slidenav_icon_right|raw}}</a>
</div>
{% else %}
<div class="jl-slidenav-container{% if particle.slidenav_margin != 'none' %} jl-position-{{ particle.slidenav_margin|e }}{% endif %} jl-position-{{ particle.slidenav_position|e }}{% if particle.slidenav_breakpoint != 'always' %} jl-visible@{{particle.slidenav_breakpoint|e}}{% endif %}{{ particle.slidenav_hover == 'enabled' ? ' jl-hidden-hover jl-hidden-touch' : '' }}{{slidenav_text_color}}">
<a class="tm-slidenav" href="#" {{slidenav_prev}} jl-slider-item="previous">{{slidenav_icon_left|raw}}</a>
<a class="tm-slidenav" href="#" {{slidenav_next}} jl-slider-item="next">{{slidenav_icon_right|raw}}</a>
</div>
{% endif %}
{% endif %}

{# End Slidenav #}

</div>

</div>

</div>

</div>

</div>
{% endif %}
{% endblock %}
