@page
@model RR3CommunityServer.Pages.SettingsModel
@{
    ViewData["Title"] = "Server Settings";
}

<div class="container-fluid mt-4">
    <div class="row mb-4">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <h1>⚙️ Server Settings</h1>
                    <p class="text-muted">Configure server behavior and options</p>
                </div>
                <a href="/admin" class="btn btn-outline-secondary">← Back to Dashboard</a>
            </div>
        </div>
    </div>

    <!-- Server Configuration -->
    <div class="row">
        <div class="col-lg-8">
            <div class="card mb-4">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">🌐 Server Configuration</h5>
                </div>
                <div class="card-body">
                    <dl class="row">
                        <dt class="col-sm-4">Server URL:</dt>
                        <dd class="col-sm-8">
                            <code>@Model.ServerUrl</code>
                            <button class="btn btn-sm btn-outline-secondary ms-2" onclick="copyToClipboard('@Model.ServerUrl')">
                                <i class="bi bi-clipboard"></i> Copy
                            </button>
                        </dd>
                        
                        <dt class="col-sm-4">Director Endpoint:</dt>
                        <dd class="col-sm-8"><code>@Model.ServerUrl/synergy/director</code></dd>
                        
                        <dt class="col-sm-4">Database:</dt>
                        <dd class="col-sm-8">SQLite (rr3community.db)</dd>
                        
                        <dt class="col-sm-4">Session Timeout:</dt>
                        <dd class="col-sm-8">24 hours</dd>
                        
                        <dt class="col-sm-4">Auto-Approve Purchases:</dt>
                        <dd class="col-sm-8">
                            <span class="badge bg-success">✓ Enabled</span>
                            <small class="text-muted d-block">All purchases auto-approved for community servers</small>
                        </dd>
                    </dl>
                </div>
            </div>

            <!-- APK Configuration -->
            <div class="card mb-4">
                <div class="card-header bg-info text-white">
                    <h5 class="mb-0">📱 APK Configuration</h5>
                </div>
                <div class="card-body">
                    <h6 class="mb-3">To connect game clients to this server:</h6>
                    
                    <div class="alert alert-info">
                        <strong>Method 1: Use the automated script</strong>
                        <pre class="mb-2 mt-2"><code>.\RR3-Community-Mod.ps1 -ServerUrl "@Model.ServerUrl"</code></pre>
                        <small>Located in: <code>E:\rr3\RR3-Community-Mod.ps1</code></small>
                    </div>

                    <div class="alert alert-secondary">
                        <strong>Method 2: Manual AndroidManifest.xml modification</strong>
                        <ol class="small mb-0 mt-2">
                            <li>Decompile APK with APKTool</li>
                            <li>Edit AndroidManifest.xml:
                                <ul>
                                    <li>Change <code>com.ea.nimble.configuration</code> from "live" to "custom"</li>
                                    <li>Add metadata: <code>NimbleCustomizedSynergyServerEndpointUrl</code> = <code>@Model.ServerUrl</code></li>
                                </ul>
                            </li>
                            <li>Recompile and sign APK</li>
                        </ol>
                    </div>

                    <p class="mb-0">
                        <a href="file:///E:/rr3/APK_MODIFICATION_GUIDE.md" class="btn btn-sm btn-primary">
                            <i class="bi bi-book"></i> View Full Guide
                        </a>
                    </p>
                </div>
            </div>
        </div>

        <!-- System Information -->
        <div class="col-lg-4">
            <div class="card mb-4">
                <div class="card-header bg-dark text-white">
                    <h5 class="mb-0">💻 System Info</h5>
                </div>
                <div class="card-body">
                    <dl class="mb-0">
                        <dt>Operating System</dt>
                        <dd><code>@Model.Platform</code></dd>
                        
                        <dt>.NET Version</dt>
                        <dd><code>@Model.DotNetVersion</code></dd>
                        
                        <dt>ASP.NET Core</dt>
                        <dd><code>@Model.AspNetVersion</code></dd>
                        
                        <dt>Server Uptime</dt>
                        <dd><strong>@Model.Uptime</strong></dd>
                        
                        <dt>Process ID</dt>
                        <dd><code>@Model.ProcessId</code></dd>
                        
                        <dt>Working Memory</dt>
                        <dd><code>@Model.MemoryUsage MB</code></dd>
                    </dl>
                </div>
            </div>

            <!-- Quick Links -->
            <div class="card">
                <div class="card-header bg-secondary text-white">
                    <h5 class="mb-0">🔗 Quick Links</h5>
                </div>
                <div class="card-body">
                    <div class="d-grid gap-2">
                        <a href="/swagger" target="_blank" class="btn btn-outline-primary">
                            <i class="bi bi-code-slash"></i> Swagger API Docs
                        </a>
                        <a href="file:///E:/rr3/NETWORK_COMMUNICATION_ANALYSIS.md" class="btn btn-outline-info">
                            <i class="bi bi-file-text"></i> Protocol Documentation
                        </a>
                        <a href="file:///E:/rr3/RR3CommunityServer/README.md" class="btn btn-outline-success">
                            <i class="bi bi-journal"></i> Server README
                        </a>
                        <a href="file:///E:/rr3/PROJECT_INDEX.md" class="btn btn-outline-warning">
                            <i class="bi bi-folder"></i> Project Index
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Database Management -->
    <div class="row mt-4">
        <div class="col-12">
            <div class="card">
                <div class="card-header bg-warning text-dark">
                    <h5 class="mb-0">🗄️ Database Management</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-3">
                            <div class="card border-primary">
                                <div class="card-body text-center">
                                    <h3 class="text-primary">@Model.DbStats.Users</h3>
                                    <p class="mb-0 text-muted">Users</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="card border-success">
                                <div class="card-body text-center">
                                    <h3 class="text-success">@Model.DbStats.Devices</h3>
                                    <p class="mb-0 text-muted">Devices</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="card border-info">
                                <div class="card-body text-center">
                                    <h3 class="text-info">@Model.DbStats.Sessions</h3>
                                    <p class="mb-0 text-muted">Sessions</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="card border-warning">
                                <div class="card-body text-center">
                                    <h3 class="text-warning">@Model.DbStats.Purchases</h3>
                                    <p class="mb-0 text-muted">Purchases</p>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="mt-4">
                        <h6>⚠️ Danger Zone</h6>
                        <div class="alert alert-danger">
                            <form method="post" asp-page-handler="ResetDatabase" onsubmit="return confirm('This will DELETE ALL DATA and reset the database. Are you sure?')">
                                <button type="submit" class="btn btn-danger">
                                    <i class="bi bi-exclamation-triangle"></i> Reset Database (Delete All Data)
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section Scripts {
    <script>
        function copyToClipboard(text) {
            navigator.clipboard.writeText(text).then(() => {
                alert('Copied to clipboard: ' + text);
            });
        }
    </script>
}
