{% extends "base.html" %}

{% block content %}
<div class="container mt-5">
    <h1 class="mb-4">System Dashboard</h1>
    
    <div class="row">
        <div class="col-md-12 mb-4">
            <div class="card shadow-sm">
                <div class="card-body">
                    <h5 class="card-title">Quick Search</h5>
                    <form id="searchForm" class="input-group">
                        <input type="text" id="searchInput" class="form-control" placeholder="Search for a person, email, or username...">
                        <button class="btn btn-primary" type="submit">Search</button>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <div class="card shadow-sm">
                <div class="card-body">
                    <h5 class="card-title">People & Identities</h5>
                    <div id="resultsArea">
                        <p class="text-muted">Enter a search term to find entities.</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row mt-4">
        <div class="col-md-12">
            <a href="{% url 'core:logout' %}" class="btn btn-outline-danger">Logout</a>
        </div>
    </div>
</div>

<script>
document.getElementById('searchForm').addEventListener('submit', function(e) {
    e.preventDefault();
    const query = document.getElementById('searchInput').value;
    const resultsArea = document.getElementById('resultsArea');
    resultsArea.innerHTML = '<p>Searching...</p>';

    // Placeholder: In a real scenario, this would call your Django backend
    fetch(`/api/search/?q=${encodeURIComponent(query)}`)
        .then(response => response.json())
        .then(data => {
            resultsArea.innerHTML = data.map(item => `
                <div class="d-flex align-items-center mb-3 p-3 border rounded">
                    <div class="me-3" style="width: 50px; height: 50px; background: #ddd; border-radius: 50%;"></div>
                    <div>
                        <strong>${item.name}</strong><br>
                        <small class="text-muted">${item.type}</small>
                    </div>
                </div>
            `).join('');
        });
});
</script>
{% endblock %}
