{% extends 'base.html' %}
{% block title %}Settings - {{ company.name }}{% endblock %}
{% block content %}
<div class="container py-5">
    <h1 class="h2 mb-4">Company Settings</h1>
    
    {% if messages %}
    {% for message in messages %}
    <div class="alert alert-{{ message.tags }} alert-dismissible fade show mb-4" role="alert">
        {{ message }}
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
    {% endfor %}
    {% endif %}

    <div class="row g-4">
        <div class="col-md-6">
            <div class="card h-100">
                <div class="card-body p-4">
                    <div class="d-flex justify-content-between align-items-center mb-4">
                        <h5 class="mb-0">Job Statuses</h5>
                        <a href="{% url 'status_create' %}" class="btn btn-sm btn-primary">Add Status</a>
                    </div>
                    <div class="list-group list-group-flush">
                        {% for status in statuses %}
                        <div class="list-group-item px-0 d-flex justify-content-between align-items-center">
                            <div>
                                <span class="fw-medium">{{ status.name }}</span>
                                {% if status.is_starting_status %}
                                <span class="badge bg-success ms-2">Starting</span>
                                {% endif %}
                            </div>
                            <div class="d-flex align-items-center">
                                <a href="{% url 'status_update' status.pk %}" class="btn btn-link btn-sm text-primary me-2"><i class="bi bi-pencil"></i></a>
                                <a href="{% url 'status_delete' status.pk %}" class="btn btn-link btn-sm text-danger"><i class="bi bi-trash"></i></a>
                            </div>
                        </div>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-6">
            <div class="card h-100">
                <div class="card-body p-4">
                    <div class="d-flex justify-content-between align-items-center mb-4">
                        <h5 class="mb-0">Required Folders</h5>
                        <a href="{% url 'folder_create' %}" class="btn btn-sm btn-primary">Add Folder</a>
                    </div>
                    <div class="list-group list-group-flush">
                        {% for folder in folders %}
                        <div class="list-group-item px-0 d-flex justify-content-between align-items-center">
                            <span class="fw-medium">{{ folder.name }}</span>
                            <a href="{% url 'folder_delete' folder.pk %}" class="btn btn-link btn-sm text-danger"><i class="bi bi-trash"></i></a>
                        </div>
                        {% endfor %}
                    </div>
                    <p class="text-muted small mt-3"><i class="bi bi-info-circle me-1"></i> New folders will appear on all existing and future jobs.</p>
                </div>
            </div>
        </div>

        <div class="col-md-6">
            <div class="card h-100">
                <div class="card-body p-4">
                    <div class="d-flex justify-content-between align-items-center mb-4">
                        <h5 class="mb-0">Client Management</h5>
                        <a href="{% url 'client_list' %}" class="btn btn-sm btn-primary">Manage Clients</a>
                    </div>
                    <div class="list-group list-group-flush">
                        {% for client in clients %}
                        <div class="list-group-item px-0 d-flex justify-content-between align-items-center">
                            <span class="fw-medium">{{ client.name }}</span>
                            <div class="d-flex align-items-center">
                                <a href="{% url 'client_update' client.pk %}" class="btn btn-link btn-sm text-primary me-2"><i class="bi bi-pencil"></i></a>
                                <a href="{% url 'client_delete' client.pk %}" class="btn btn-link btn-sm text-danger"><i class="bi bi-trash"></i></a>
                            </div>
                        </div>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-6">
            <div class="card h-100">
                <div class="card-body p-4">
                    <div class="d-flex justify-content-between align-items-center mb-4">
                        <h5 class="mb-0">User Management</h5>
                        <a href="{% url 'user_list' %}" class="btn btn-sm btn-primary">Manage Users</a>
                    </div>
                    {% if invitations %}
                        <h6 class="mb-3">Pending Invitations:</h6>
                        <ul class="list-group mb-3">
                            {% for invite in invitations %}
                                <li class="list-group-item d-flex justify-content-between align-items-center">
                                    {{ invite.email }}
                                    <span class="badge bg-info rounded-pill">Expires {{ invite.expires_at|date:"M d, Y" }}</span>
                                </li>
                            {% endfor %}
                        </ul>
                    {% else %}
                        <p class="text-muted">No pending invitations.</p>
                    {% endif %}
                    <a href="{% url 'invite_user' %}" class="btn btn-sm btn-outline-primary">Invite New User</a>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}