{#
/* -------------------------------------------------------------------------- */
/* Обычный лайтбокс выбора метро в паблике */
/* -------------------------------------------------------------------------- */
#}
{% apply spaceless %}
{# <ul class="select-metro buttons">
{% for stationItem in item.children|slice(1) %}
{% set labelParts = stationItem.label|split('(', 2) %}
{% set labelCounts = labelParts[1] %}
{# <li><button type="button" onclick="location='{{ stationItem.uri }}'" class="nonstd-hover-link">{{ labelParts[0]|trim }}</button><span>{{ labelCounts|slice(0, labelCounts|length - 1) }}</span></li> #!}
<li><a href="{{ stationItem.uri }}" class="nonstd-hover-link">{{ labelParts[0]|trim }}</a><span>{{ labelCounts|slice(0, labelCounts|length - 1) }}</span></li>
{% else %}
{% set defaultCity = default_city() %}
{% for station in defaultCity.stations %}
{% set labelParts = station.name|split('(', 2) %}
{% set labelCounts = labelParts[1] %}
{# <li><button type="button" onclick="location='{{ path('profile_list.list_by_station', {'city': defaultCity.uriIdentity, 'station': station.uriIdentity}) }}'" class="nonstd-hover-link">{{ labelParts[0]|trim }}</button><span>{{ labelCounts|slice(0, labelCounts|length - 1) }}</span></li> #!}
<li><a href="{{ path('profile_list.list_by_station', {'city': defaultCity.uriIdentity, 'station': station.uriIdentity}) }}" class="nonstd-hover-link">{{ labelParts[0]|trim }}</a><span>{{ labelCounts|slice(0, labelCounts|length - 1) }}</span></li>
{% endfor %}
{% endfor %}
</ul> #}
<div class="catalog-metro-container" dialog-content>
{% set firstLetter = null %}
{% set sorted_stations = item.children|slice(1)|sort((a, b) => a.name|upper <=> b.name|upper) %}
{% for station in sorted_stations %}
{# {% if loop.index < 5 %}
{{dump(station.extras)}}
{% endif %} #}
{# В stationItem.label Приходит строка формата "Станция Новоизмайловская (24)" - название станции и кол-во элементов найденных по этой станции в скобочках
Напиши оптимальный метод получения количества и названия станции для использования в twig #}
{# {% set [name, count] = station.label|split('(', 2) %} #}
{% set data = station.label|split('(', 2) %}
{% set name = data[0]|trim %}
{% set count = data[1]|slice(0, -1)|trim %}
{% set firstChar = station.label|slice(0, 1)|upper %}
{% if firstLetter != firstChar %}
{% if loop.index != 1 %}</div>{% endif %}
{% set firstLetter = firstChar %}
<div class="catalog catalog-metro mb-4">
<div class="first-letter mb-2 fw-700 d-flex-c">
{{- firstLetter -}}
</div>
{% endif %}
<div class="catalog-item">
<a class="metro-link d-flex-c" href="{{ station.uri }}">
{% include 'components/metro/icon_generate.partial.twig' with {data: station.extras.lines} %}
<span class="metro-name mr-1">{{ name }}</span>
<span class="metro-count d-flex-c clr-main-text fw-600">{{ count }}</span>
</a>
</div>
{% endfor %}
</div>
{% endapply %}