{% extends "base.html" %}

{% block title %}Consumption Sheets - Admin - ScanLook{% endblock %}

{% block content %}
<div class="dashboard-container">
    <div class="dashboard-header" style="margin-top: var(--space-lg);">
        <div class="header-left" style="display: flex; align-items: center; gap: var(--space-md);">
            <a href="{{ url_for('admin_dashboard') }}" class="btn btn-secondary btn-sm">
                <i class="fa-solid fa-arrow-left"></i> Back to Admin
            </a>
            
            <div>
                <h1 class="page-title" style="margin-bottom: 0;{% if showing_archived %} color: var(--color-danger);{% endif %}">
                    {{ 'Archived Processes' if showing_archived else 'Consumption Sheets' }}
                </h1>
                
                <p class="page-subtitle" style="margin-bottom: var(--space-xs);">Manage process types and templates</p>
                
                {% if showing_archived %}
                    <a href="{{ url_for('conssheets.admin_processes') }}" style="font-size: 0.85rem; color: var(--color-primary); display: inline-flex; align-items: center; gap: 6px;">
                        <i class="fa-solid fa-eye"></i> Return to Active List
                    </a>
                {% else %}
                    <a href="{{ url_for('conssheets.admin_processes', archived=1) }}" style="font-size: 0.85rem; color: var(--color-text-muted); display: inline-flex; align-items: center; gap: 6px;">
                        <i class="fa-solid fa-box-archive"></i> View Archived Processes
                    </a>
                {% endif %}
            </div>
        </div>
        
        <a href="{{ url_for('conssheets.create_process') }}" class="btn btn-primary">
            <span class="btn-icon">+</span> New Process
        </a>
    </div>

    {% if processes %}
        <div class="sessions-grid">
            {% for process in processes %}
            <div class="session-card">
                <div class="session-card-header" style="display: flex; justify-content: space-between; align-items: flex-start;">
                    <div>
                        <h3 class="session-name">{{ process.process_name }}</h3>
                        <span class="session-type-badge">
                            {{ process.field_count or 0 }} fields
                        </span>
                    </div>

                    {% if showing_archived %}
                        <form method="POST" 
                              action="{{ url_for('conssheets.restore_process', process_id=process.id) }}"
                              style="margin: 0;">
                            <button type="submit" class="btn-icon-only" title="Restore Process" style="color: var(--color-success);">
                                <i class="fa-solid fa-trash-arrow-up"></i>
                            </button>
                        </form>
                    {% else %}
                        <form method="POST" 
                              action="{{ url_for('conssheets.delete_process', process_id=process.id) }}" 
                              onsubmit="return confirm('Are you sure you want to delete {{ process.process_name }}?');"
                              style="margin: 0;">
                            <button type="submit" class="btn-icon-only" title="Delete Process">
                                <i class="fa-solid fa-trash"></i>
                            </button>
                        </form>
                    {% endif %}
                </div>

                <div class="session-meta">
                    <div class="meta-item">
                        <span class="meta-label">Key:</span>
                        <span class="meta-value" style="font-family: var(--font-mono);">{{ process.process_key }}</span>
                    </div>
                    <div class="meta-item">
                        <span class="meta-label">Created:</span>
                        <span class="meta-value">{{ process.created_at[:16] if process.created_at else 'N/A' }}</span>
                    </div>
                    <div class="meta-item">
                        <span class="meta-label">By:</span>
                        <span class="meta-value">{{ process.created_by_name or 'Unknown' }}</span>
                    </div>
                    <div class="meta-item">
                        <span class="meta-label">Template:</span>
                        <span class="meta-value">{{ '✅ Uploaded' if process.template_file else '❌ None' }}</span>
                    </div>
                </div>

                <div class="session-actions">
                    <a href="{{ url_for('conssheets.process_detail', process_id=process.id) }}" class="btn btn-secondary btn-block">
                        Configure
                    </a>
                </div>
            </div>

               
            {% endfor %}
        </div>
    {% else %}
        <div class="empty-state">
            <div class="empty-icon">📝</div>
            <h2 class="empty-title">No Processes Defined</h2>
            <p class="empty-text">Create a process type to get started (e.g., "AD WIP")</p>
            <a href="{{ url_for('conssheets.create_process') }}" class="btn btn-primary">
                Create First Process
            </a>
        </div>
    {% endif %}
</div>
{% endblock %}
