{% capture support_key %}{{ support[0] }}{% endcapture %}
{% capture anysupport %}
    {% for sw in type.software %}
        {% if sw.support contains support_key or sw.partial contains support_key %}
            Y
        {% endif %}
    {% endfor %}
{% endcapture %}

{% if anysupport contains "Y" %}

{% if support[1].note %}{{ support[1].note | markdownify }}{% endif %}

{% assign popup_above_after = type.software | size | minus: 3 %}
{% if popup_above_after < 3 %}
    {% assign popup_above_after = 3 %}
{% endif %}

<div class="support-table {{ include.swtype }}"><table>
    <thead>
        <tr>
            <th>
                <!-- Software -->
            </th>
            {% for ext in support[1].specs %}{% if ext[1].deprecated %}{% else %}
                {% capture ext_name %}{{ ext[0] }}{% endcapture %}

                {% capture should_show_spec %}
                    {% for sw in type.software %}
                        {% if ext[1].hide-on-servers and type.name contains "Servers" %}
                            
                        {% elsif ext[1].hide-if-no-support %}
                            {% if sw.support[support_key] contains ext_name or sw.partial[support_key] contains ext_name %}
                                Y
                            {% endif %}
                        {% elsif ext[1].draft %}
                            {% if sw.support[support_key] contains ext_name or sw.partial[support_key] contains ext_name or sw.na[support_key] contains ext_name %}
                                Y
                            {% endif %}
                        {% else %}
                            Y
                        {% endif %}
                    {% endfor %}
                {% endcapture %}

                {% if should_show_spec contains "Y" %}
                <th class="{% if ext[1].required %}required{% elsif ext[1].draft %}draft{% else %}optional{% endif %}"><a class="spec-name" title="{{ ext[1].description }}" href="{% if ext[1].ext_link %}{{ ext[1].ext_link }}{% else %}{{ site.baseurl }}{{ ext[1].link }}{% endif %}">{{ ext[1].name }}</a></th>
                {% endif %}
            {% endif %}{% endfor %}
        </tr>
    </thead>
    <tbody>
        {% assign sw_index = 0 %}
        {% for sw in type.software %}
        {% assign sw_index = sw_index | plus: 1 %}
        {% if sw_index < popup_above_after %}
            {% assign popup_above = false %}
        {% else %}
            {% assign popup_above = true %}
        {% endif %}

        <tr class="popup-{% if popup_above %}above{% else %}below{% endif %}">
            <td>
                {% if sw.link %}<a{% if sw.ircd-ver || sw.net-address %} class="bold"{% endif %} href="{{ sw.link }}">{{ sw.name }}</a>{% else %}{{ sw.name }}{% endif %}
                {% if sw.ircd-ver %}<span class="ircd-ver">{{ sw.ircd-ver }}</span>{% endif %}
                {% if sw.net-address %}<a class="net-address" href="{{ sw.net-address.link }}">{{ sw.net-address.display }}</a>{% endif %}
                {% if sw.language %}<span class="language">{{ sw.language }}</span>{% endif %}
                {% if sw.dead %}<span class="dead-software">dead</span>{% endif %}
                {% if sw.note %}
                    <div class="sw-note">{{ sw.note | markdownify }}</div>
                {% endif %}
                {% if sw.os %}
                    <div class="os-support">
                    {% for name in sw.os %}
                        {% if site.data.os[name] %}
                            <i title="{{ site.data.os[name]["name"] }}" class="{{ site.data.os[name]["icon"] }} os-support-{{ name | slugify }}"></i>
                        {% endif %}
                    {% endfor %}
                    </div>
                {% endif %}
                {% if sw.sublinks %}
                    <div class="sw-sublinks">
                        {% for sublink in sw.sublinks %}
                            <a href="{{ sublink.link }}">{{ sublink.name }}</a>
                        {% endfor %}
                    </div>
                {% endif %}
            </td>
            {% for ext in support[1].specs %}{% if ext[1].deprecated %}{% else %}
                {% capture ext_name %}{{ ext[0] }}{% endcapture %}

                {% capture should_show_spec %}
                    {% for sw in type.software %}
                        {% if ext[1].hide-on-servers and type.name contains "Servers" %}
                            
                        {% elsif ext[1].hide-if-no-support %}
                            {% if sw.support[support_key] contains ext_name or sw.partial[support_key] contains ext_name %}
                                Y
                            {% endif %}
                        {% elsif ext[1].draft %}
                            {% if sw.support[support_key] contains ext_name or sw.partial[support_key] contains ext_name or sw.na[support_key] contains ext_name %}
                                Y
                            {% endif %}
                        {% else %}
                            Y
                        {% endif %}
                    {% endfor %}
                {% endcapture %}

                {% if should_show_spec contains "Y" %}
                    <td data-capname="{{ support[1].specs[ext_name].name }}" class="{% if ext[1].required %}required{% elsif ext[1].draft %}draft{% else %}optional{% endif %} support {% if sw.support[support_key] contains ext_name %}supported{% elsif sw.partial[support_key] contains ext_name %}partial{% elsif sw.na[support_key] contains ext_name %}na{% else %}unsupported{% endif %}">
                        {% assign show_cap = true %}
                        {% if sw.support[support_key] contains ext_name %}
                            {% assign capab = sw.support[support_key][ext_name] %}
                            {% assign default = 'Yes' %}
                        {% elsif sw.partial[support_key] contains ext_name %}
                            {% assign capab = sw.partial[support_key][ext_name] %}
                            {% assign default = 'Partial' %}
                        {% elsif sw.na[support_key] contains ext_name %}
                            {% assign capab = sw.na[support_key][ext_name] %}
                            {% assign default = 'N/A' %}
                        {% else %}
                            {% assign show_cap = false %}
                        {% endif %}

                        {% if popup_above %}{% else %}
                            {% if show_cap %}
                                {% include show_capability.html %}
                            {% else %}
                                No
                            {% endif %}
                        {% endif %}

                        <div class="hover-popup"><div>
                            <p class="bold">{{ sw.name }}</p>
                            <p>{{ ext[1].name }}</p>
                            {% if info %}
                                <p class="note">{{ info }}</p>
                            {% endif %}
                        </div></div>

                        {% if popup_above %}
                            {% if show_cap %}
                                {% include show_capability.html %}
                            {% else %}
                                No
                            {% endif %}
                        {% endif %}

                        {% assign info = nil %}
                    </td>
                {% endif %}
            {% endif %}{% endfor %}
        </tr>
        {% endfor %}
    </tbody>
</table></div>

{% endif %}
