{# this file contains helper macros, not intended for rendering but import, imported as util in main templates. Note the whitespace control #}

{% macro view_url(view_name, context = g.stop_id) -%}
	{{ url_for('view', path = view_name, stopId = context, _external = True) }}
{%- endmacro %}

{% macro static_url(filename) -%}
	{{ url_for('static', filename = filename, _external = True) }}
{%- endmacro %}

{% macro home_url(context = g.stop_id, lang = None) -%}
	{% if not lang -%}
		{{ url_for('view', path = '', stopId = context, _external = True) }}
	{%- else -%}
		{{ url_for('view', path = '', stopId = context, lang = lang, _external = True) }}
	{%- endif %}
{%- endmacro %}

{# For format string documentation, see: http://babel.pocoo.org/en/latest/dates.html#pattern-syntax #}
{% macro time_short(time) -%}
	{{ time | datetimeformat(format = 'HH:mm') }}
{%- endmacro %}

{% macro time_long(time) -%}
	{{ time | timeformat(format = 'HH:mm:ss') }}
{%- endmacro %}

{% macro date(time) -%}
	{{ time | datetimeformat }}
{%- endmacro %}

{% macro stop_name(full_name = True, context = stop_info) -%}
	{% if full_name %}{% if context.stop_code %}{{ context.stop_code }}{% else %}{{ context.stop_id }}{% endif %} - {% endif %}{{ context.stop_name }}
{%- endmacro %}

{# assumes that schedule_row.headsign does not contain the trip/line short_name attribute already, true for Föli data but GTFS does not guarantee this  #}
{% macro line_name(schedule_row, full_name = False) -%}
	{% if not full_name or not schedule_row.route -%}
		{% if schedule_row.route %}{{ schedule_row.route.short_name }} - {% endif %}{{ schedule_row.headsign }}
	{%- else -%}
		{{ schedule_row.route.route_name }}
	{%- endif %}
{%- endmacro %}

{% macro pagination(context) %}
{% if context -%}
<nav>
	<ul class="pagination pagination-lg pagination-foli justify-content-center">
		{% if context.prev_url -%}
			<li class="page-item previous"><a class="page-link" href="{{ context.prev_url }}">{{ _("Previous") }}</a></li>
		{%- else -%}
			<li class="page-item previous disabled"><span class="page-link">{{ _("Previous") }}</span></li>
		{%- endif %}
		<li class="page-item counts disabled"><span class="page-link">{{ context.on_page }} / {{ context.page_count }}</span></li>
		{% if context.next_url -%}
			<li class="page-item next"><a class="page-link" href="{{ context.next_url }}">{{ _("Next") }}</a></li>
		{%- else -%}
			<li class="page-item next disabled"><span class="page-link">{{ _("Next") }}</span></li>
		{%- endif %}
	</ul>
</nav>
{%- endif %}
{% endmacro %}
