{% extends "base.html" %}

{% block title %}Inventory Counts - ScanLook{% endblock %}

{% block content %}
<div class="dashboard-container">
    <div class="dashboard-header">
        <div class="header-left">
            <a href="{{ url_for('admin_dashboard') }}" class="btn btn-secondary btn-sm" style="margin-right: var(--space-md);">
                <i class="fa-solid fa-arrow-left"></i> Back to Admin
            </a>
            <div>
                <h1 class="page-title">Inventory Counts</h1>
                <p class="page-subtitle">Manage cycle counts and physical inventory</p>
            </div>
        </div>
        <div class="header-right">
            <label class="filter-toggle" style="margin-right: var(--space-lg);">
                <input type="checkbox" id="showArchived" {% if show_archived %}checked{% endif %} onchange="toggleArchived()">
                <span class="filter-label">Show Archived</span>
            </label>
            <a href="{{ url_for('invcount.create_session') }}" class="btn btn-primary">
                <span class="btn-icon">+</span> New Session
            </a>
        </div>
    </div>

    {% if sessions %}
        <div class="sessions-grid">
            {% for session in sessions %}
            <div class="session-card {% if session.status == 'archived' %}session-archived{% endif %}">
                <div class="session-card-header">
                    <h3 class="session-name">
                        {{ session.session_name }}
                        {% if session.status == 'archived' %}<span class="archived-badge">ARCHIVED</span>{% endif %}
                    </h3>
                    <span class="session-type-badge session-type-{{ session.session_type }}">
                        {{ 'Full Physical' if session.session_type == 'full_physical' else 'Cycle Count' }}
                    </span>
                </div>

                <div class="session-stats">
                    <div class="stat-item">
                        <div class="stat-value">{{ session.total_locations or 0 }}</div>
                        <div class="stat-label">Total Locations</div>
                    </div>
                    <div class="stat-item">
                        <div class="stat-value">{{ session.completed_locations or 0 }}</div>
                        <div class="stat-label">Completed</div>
                    </div>
                    <div class="stat-item">
                        <div class="stat-value">{{ session.in_progress_locations or 0 }}</div>
                        <div class="stat-label">In Progress</div>
                    </div>
                </div>

                <div class="session-meta">
                    <div class="meta-item">
                        <span class="meta-label">Created:</span>
                        <span class="meta-value">{{ session.created_timestamp[:16] }}</span>
                    </div>
                    <div class="meta-item">
                        <span class="meta-label">By:</span>
                        <span class="meta-value">{{ session.created_by_name }}</span>
                    </div>
                </div>

                <div class="session-actions">
                    <a href="{{ url_for('invcount.session_detail', session_id=session.session_id) }}" class="btn btn-secondary btn-block">
                        View Details
                    </a>
                </div>
            </div>
            {% endfor %}
        </div>
    {% else %}
        <div class="empty-state">
            <div class="empty-icon">📋</div>
            <h2 class="empty-title">No Active Sessions</h2>
            <p class="empty-text">Create a new count session to get started</p>
        </div>
    {% endif %}
</div>

<script>
function toggleArchived() {
    const checked = document.getElementById('showArchived').checked;
    window.location.href = '{{ url_for("invcount.admin_dashboard") }}' + (checked ? '?show_archived=1' : '');
}
</script>

<style>
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-xl);
}
.header-left { display: flex; align-items: center; }
.header-right { display: flex; align-items: center; }
</style>
{% endblock %}