{% set enabledChannels = product.channels|filter(channel => channel.enabled == true) %}

{% if sylius_bundle_loaded_checker('SyliusShopBundle') %}
    {% if not product.enabled or enabledChannels|length < 1 %}
        <a class="ui labeled icon button disabled" href="#" {{ sylius_test_html_attribute('show-product-in-shop-page') }}>
            <i class="angle right icon"></i>
            {{ 'sylius.ui.show_product_in_shop_page'|trans }}
        </a>
    {% elseif enabledChannels|length > 1 %}
        <div class="ui floating dropdown labeled icon button" {{ sylius_test_html_attribute('show-product-in-shop-page') }}>
            <i class="share alternate icon"></i>
            <span class="text">
                {{ 'sylius.ui.show_product_in_shop_page'|trans }}
            </span>
            <div class="menu">
                <div class="scrolling menu">
                    {% for channel in enabledChannels %}
                        {% set product_translation = sylius_product_translation(product, channel) %}
                        {% if product_translation is not null %}
                            {% set url = sylius_channel_url(path('sylius_shop_product_show', {'slug': product_translation.slug, '_locale': product_translation.locale}), channel) %}
                        {% endif %}

                        <a
                            href="{{ (url is not defined) ? '#' : url|raw }}"
                            class="item {% if url is not defined %}disabled{% endif %}"
                            target="_blank"
                        >
                            <i class="angle right icon"></i>
                            {{ 'sylius.ui.show_in'|trans }}
                            {{ channel.name }} ({{ channel.code }})
                        </a>
                    {% endfor %}
                </div>
            </div>
        </div>
    {% else %}
        {% for channel in enabledChannels %}
            {% set product_translation = sylius_product_translation(product, channel) %}
            {% if product_translation is not null %}
                {% set url = sylius_channel_url(path('sylius_shop_product_show', {'slug': product_translation.slug, '_locale': product_translation.locale}), channel) %}
            {% endif %}

            <a
                class="ui labeled icon button {% if url is not defined %}disabled{% endif %}"
                href="{{ (url is not defined) ? '#' : url|raw }}"
                target="_blank"
                {{ sylius_test_html_attribute('show-product-in-shop-page') }}
            >
                <i class="angle right icon"></i>
                {{ 'sylius.ui.show_product_in_shop_page'|trans }}
            </a>
        {% endfor %}
    {% endif %}
{% endif %}
