{% extends "base.html" %}

{% block title %}View Message - Admin - A+ Academy{% endblock %}

{% block extra_css %}
<style>
    .admin-sidebar {
        background: white;
        border-radius: 20px;
        box-shadow: var(--soft-shadow);
        padding: 1.5rem;
        height: calc(100vh - 140px);
        position: sticky;
        top: 100px;
    }
    .admin-nav-link {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 12px 16px;
        color: var(--text-dark);
        text-decoration: none;
        border-radius: 10px;
        margin-bottom: 8px;
        transition: all 0.3s ease;
    }
    .admin-nav-link:hover, .admin-nav-link.active {
        background: rgba(37, 99, 235, 0.1);
        color: var(--primary-blue);
    }
</style>
{% endblock %}

{% block content %}
<section style="padding: 120px 0 40px;">
    <div class="container">
        <div class="row g-4">
            <!-- Sidebar -->
            <div class="col-lg-3">
                <div class="admin-sidebar">
                    <div class="d-flex align-items-center gap-2 mb-4 pb-3 border-bottom">
                        <i class="bi bi-person-circle text-primary fs-4"></i>
                        <div>
                            <div class="fw-bold">{{ current_user.username }}</div>
                            <small class="text-muted">Administrator</small>
                        </div>
                    </div>

                    <nav>
                        <a href="{{ url_for('admin.dashboard') }}" class="admin-nav-link">
                            <i class="bi bi-speedometer2"></i> Dashboard
                        </a>
                        <a href="{{ url_for('admin.messages') }}" class="admin-nav-link active">
                            <i class="bi bi-envelope"></i> Messages
                        </a>
                        <a href="{{ url_for('admin.content') }}" class="admin-nav-link">
                            <i class="bi bi-file-text"></i> Site Content
                        </a>
                        <a href="{{ url_for('admin.admin_subjects') }}" class="admin-nav-link">
                            <i class="bi bi-book"></i> Subjects
                        </a>
                        <div class="border-top my-3"></div>
                        <a href="{{ url_for('admin.logout') }}" class="admin-nav-link text-danger">
                            <i class="bi bi-box-arrow-right"></i> Logout
                        </a>
                    </nav>
                </div>
            </div>

            <!-- Main Content -->
            <div class="col-lg-9">
                <div class="d-flex justify-content-between align-items-center mb-4">
                    <h4 class="mb-0">Message Details</h4>
                    <a href="{{ url_for('admin.messages') }}" class="btn btn-outline-primary btn-sm">
                        <i class="bi bi-arrow-left"></i> Back to Messages
                    </a>
                </div>

                <div class="soft-card p-4 mb-4">
                    <div class="d-flex justify-content-between align-items-start mb-3">
                        <div>
                            <h5 class="mb-1">{{ message.name }}</h5>
                            <div class="text-muted">
                                <i class="bi bi-envelope"></i> {{ message.email }}
                                {% if message.phone %}
                                | <i class="bi bi-telephone"></i> {{ message.phone }}
                                {% endif %}
                            </div>
                        </div>
                        <div class="text-end">
                            <div class="text-muted small">{{ message.created_at.strftime('%d %B %Y at %H:%M') }}</div>
                            <span class="badge bg-{{ 'success' if message.is_replied else 'info' if message.is_read else 'warning' }}">
                                {{ 'Replied' if message.is_replied else 'Read' if message.is_read else 'New' }}
                            </span>
                        </div>
                    </div>

                    <div class="mb-3">
                        <span class="badge bg-primary">{{ message.subject }}</span>
                    </div>

                    <div class="bg-light p-3 rounded-3">
                        <h6 class="text-muted mb-2">Message:</h6>
                        <p class="mb-0" style="white-space: pre-wrap;">{{ message.message }}</p>
                    </div>
                </div>

                {% if message.is_replied %}
                <div class="soft-card p-4 border-success">
                    <div class="d-flex justify-content-between align-items-start mb-3">
                        <h6 class="text-success mb-0">
                            <i class="bi bi-check-circle-fill"></i> Your Reply
                        </h6>
                        <small class="text-muted">{{ message.replied_at.strftime('%d %B %Y at %H:%M') }}</small>
                    </div>
                    <div class="bg-success bg-opacity-10 p-3 rounded-3">
                        <p class="mb-0" style="white-space: pre-wrap;">{{ message.reply_message }}</p>
                    </div>
                </div>
                {% else %}
                <div class="text-center">
                    <a href="{{ url_for('admin.reply_message', message_id=message.id) }}" class="soft-btn">
                        <i class="bi bi-reply"></i> Reply to Message
                    </a>
                </div>
                {% endif %}
            </div>
        </div>
    </div>
</section>
{% endblock %}
