<!-- ObjItems Table Component -->
<div class="card">
    <div class="card-header bg-success text-white">
        <h5 class="mb-0">Объекты (ObjItems)</h5>
    </div>
    <div class="card-body p-0">
        <div class="table-responsive" style="max-height: 70vh; overflow-y: auto;">
            <table class="table table-striped table-hover table-sm table-bordered mb-0" style="font-size: 0.9rem;">
                <thead class="table-dark sticky-top">
                    <tr>
                        <th>ID</th>
                        <th>Имя</th>
                        <th>Спутник</th>
                        <th>Частота, МГц</th>
                        <th>Полоса, МГц</th>
                        <th>Поляризация</th>
                        <th>Модуляция</th>
                        <th>Сим. v</th>
                        <th>ОСШ</th>
                        <th>Геолокация</th>
                        <th>Дата гео</th>
                        <th>Объект</th>
                        <th>LyngSat</th>
                        {% if show_marks == '1' %}
                        <th>Отметки</th>
                        {% endif %}
                    </tr>
                </thead>
                <tbody>
                    {% for item in processed_objitems %}
                    <tr>
                        <td><a href="{% url 'mainapp:objitem_detail' item.id %}">{{ item.id }}</a></td>
                        <td>{{ item.name }}</td>
                        <td>{{ item.satellite }}</td>
                        <td>{{ item.frequency }}</td>
                        <td>{{ item.freq_range }}</td>
                        <td>{{ item.polarization }}</td>
                        <td>{{ item.modulation }}</td>
                        <td>{{ item.bod_velocity }}</td>
                        <td>{{ item.snr }}</td>
                        <td>{{ item.geo_coords }}</td>
                        <td>{{ item.geo_date }}</td>
                        <td>
                            {% if item.source_id %}
                            <a href="{% url 'mainapp:source_update' item.source_id %}">{{ item.source_id }}</a>
                            {% else %}
                            -
                            {% endif %}
                        </td>
                        <td>
                            {% if item.lyngsat_id %}
                            <a href="{% url 'admin:lyngsatapp_lyngsat_change' item.lyngsat_id %}" target="_blank">
                                <i class="bi bi-link-45deg"></i>
                            </a>
                            {% else %}
                            -
                            {% endif %}
                        </td>
                        {% if show_marks == '1' %}
                        <td>
                            {% if item.marks %}
                            <div style="max-height: 150px; overflow-y: auto;">
                                {% for mark in item.marks %}
                                <div class="mb-1">
                                    <span class="mark-badge {% if mark.mark %}mark-present{% else %}mark-absent{% endif %}">
                                        {% if mark.mark %}✓ Есть{% else %}✗ Нет{% endif %}
                                    </span>
                                    <br>
                                    <small class="text-muted">{{ mark.timestamp|date:"d.m.Y H:i" }}</small>
                                    <br>
                                    <small class="text-muted">{{ mark.created_by }}</small>
                                </div>
                                {% endfor %}
                            </div>
                            {% else %}
                            <span class="text-muted">-</span>
                            {% endif %}
                        </td>
                        {% endif %}
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="{% if show_marks == '1' %}14{% else %}13{% endif %}" class="text-center py-4 text-muted">
                            Нет данных для выбранных фильтров
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
    
    <!-- Pagination -->
    {% if page_obj.paginator.num_pages > 1 %}
    <div class="card-footer">
        <nav>
            <ul class="pagination justify-content-center mb-0">
                {% if page_obj.has_previous %}
                <li class="page-item">
                    <a class="page-link" href="?{% for key, value in request.GET.items %}{% if key != 'page' %}{{ key }}={{ value }}&{% endif %}{% endfor %}page=1">Первая</a>
                </li>
                <li class="page-item">
                    <a class="page-link" href="?{% for key, value in request.GET.items %}{% if key != 'page' %}{{ key }}={{ value }}&{% endif %}{% endfor %}page={{ page_obj.previous_page_number }}">Предыдущая</a>
                </li>
                {% endif %}
                
                <li class="page-item active">
                    <span class="page-link">{{ page_obj.number }} из {{ page_obj.paginator.num_pages }}</span>
                </li>
                
                {% if page_obj.has_next %}
                <li class="page-item">
                    <a class="page-link" href="?{% for key, value in request.GET.items %}{% if key != 'page' %}{{ key }}={{ value }}&{% endif %}{% endfor %}page={{ page_obj.next_page_number }}">Следующая</a>
                </li>
                <li class="page-item">
                    <a class="page-link" href="?{% for key, value in request.GET.items %}{% if key != 'page' %}{{ key }}={{ value }}&{% endif %}{% endfor %}page={{ page_obj.paginator.num_pages }}">Последняя</a>
                </li>
                {% endif %}
            </ul>
        </nav>
        <div class="text-center mt-2">
            <small class="text-muted">Показано {{ page_obj.start_index }}-{{ page_obj.end_index }} из {{ page_obj.paginator.count }} записей</small>
        </div>
    </div>
    {% endif %}
</div>
