{% load pi_fyad_tags %}

<div class="mb-3">
    <div class="d-flex align-items-center mb-2 cursor-pointer"
         data-bs-toggle="collapse"
         data-bs-target="#factory-tier-{{ tier }}"
         aria-expanded="{% if tier >= 3 %}true{% else %}false{% endif %}">
        <h6 class="mb-0">
            {{ tier|factory_tier_badge }}
            <span class="ms-2">{{ factories|length }} factor{{ factories|length|pluralize:"y,ies" }}</span>
        </h6>
        <i class="fas fa-chevron-down ms-auto"></i>
    </div>

    <div class="collapse {% if tier >= 3 %}show{% endif %}" id="factory-tier-{{ tier }}">
        <table class="table table-sm table-striped mb-0">
            <thead>
                <tr>
                    <th>Type</th>
                    <th>Output</th>
                    <th>Schematic</th>
                </tr>
            </thead>
            <tbody>
                {% for factory in factories %}
                <tr>
                    <td>
                        {% eve_type_icon factory.type_id 20 %}
                        <span class="ms-1">{{ factory.type_name }}</span>
                    </td>
                    <td>
                        {% if factory.factory_output_type_id %}
                        {% eve_type_icon factory.factory_output_type_id 20 %}
                        <span class="ms-1">{{ factory.factory_output_name|default:"—" }}</span>
                        {% else %}
                        <span class="text-muted">—</span>
                        {% endif %}
                    </td>
                    <td>{{ factory.schematic_id|default:"—" }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
