@extends('layouts.dashboard')

@section('title', 'Settings')
@section('page-title', 'System Settings')

@section('content')
<div class="row">
    <div class="col-lg-8">
        <div class="table-container mb-4">
            <div class="mb-4">
                <h5 class="mb-1">System Configuration</h5>
                <p class="text-muted mb-0">Manage global settings for the AutoReply SMS system</p>
            </div>

            <form action="{{ route('dashboard.settings.update') }}" method="POST">
                @csrf
                @method('PUT')

                <!-- General Settings -->
                <div class="card mb-4">
                    <div class="card-header bg-light">
                        <h6 class="mb-0"><i class="bi bi-gear me-2"></i>General Settings</h6>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label for="app_name" class="form-label fw-semibold">Application Name</label>
                            <input type="text" class="form-control" id="app_name" name="app_name" 
                                   value="AutoReply SMS" placeholder="Application Name">
                        </div>
                        <div class="mb-3">
                            <label for="default_cooldown" class="form-label fw-semibold">Default Cooldown (Hours)</label>
                            <input type="number" class="form-control" id="default_cooldown" name="default_cooldown" 
                                   value="24" min="1" max="168">
                            <div class="form-text">Default cooldown period for new users</div>
                        </div>
                    </div>
                </div>

                <!-- SMS Settings -->
                <div class="card mb-4">
                    <div class="card-header bg-light">
                        <h6 class="mb-0"><i class="bi bi-chat-text me-2"></i>SMS Settings</h6>
                    </div>
                    <div class="card-body">
                        <div class="form-check form-switch mb-3">
                            <input class="form-check-input" type="checkbox" id="sms_enabled_globally" name="sms_enabled_globally" checked>
                            <label class="form-check-label" for="sms_enabled_globally">
                                <strong>Enable SMS Service Globally</strong>
                                <div class="text-muted small">Master switch for all SMS functionality</div>
                            </label>
                        </div>
                        <div class="form-check form-switch mb-3">
                            <input class="form-check-input" type="checkbox" id="promotions_enabled_globally" name="promotions_enabled_globally" checked>
                            <label class="form-check-label" for="promotions_enabled_globally">
                                <strong>Enable Promotions Globally</strong>
                                <div class="text-muted small">Master switch for promotional messages</div>
                            </label>
                        </div>
                    </div>
                </div>

                <!-- Security Settings -->
                <div class="card mb-4">
                    <div class="card-header bg-light">
                        <h6 class="mb-0"><i class="bi bi-shield-lock me-2"></i>Security Settings</h6>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label for="session_timeout" class="form-label fw-semibold">Session Timeout (Minutes)</label>
                            <input type="number" class="form-control" id="session_timeout" name="session_timeout" 
                                   value="120" min="15" max="1440">
                            <div class="form-text">Auto-logout after inactivity</div>
                        </div>
                        <div class="form-check form-switch mb-3">
                            <input class="form-check-input" type="checkbox" id="force_password_change" name="force_password_change">
                            <label class="form-check-label" for="force_password_change">
                                <strong>Force Password Change on First Login</strong>
                            </label>
                        </div>
                        <div class="form-check form-switch mb-3">
                            <input class="form-check-input" type="checkbox" id="enable_audit_logs" name="enable_audit_logs" checked>
                            <label class="form-check-label" for="enable_audit_logs">
                                <strong>Enable Audit Logging</strong>
                                <div class="text-muted small">Track all admin actions</div>
                            </label>
                        </div>
                    </div>
                </div>

                <!-- Admin Default Settings -->
                <div class="card mb-4">
                    <div class="card-header bg-light">
                        <h6 class="mb-0"><i class="bi bi-person-gear me-2"></i>Default Admin Settings</h6>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label for="default_max_users" class="form-label fw-semibold">Default Max Users for New Admins</label>
                            <input type="number" class="form-control" id="default_max_users" name="default_max_users" 
                                   value="10" min="0">
                            <div class="form-text">Maximum users a new admin can create by default</div>
                        </div>
                    </div>
                </div>

                <button type="submit" class="btn btn-primary">
                    <i class="bi bi-check-lg me-2"></i>Save Settings
                </button>
            </form>
        </div>
    </div>

    <div class="col-lg-4">
        <!-- System Info -->
        <div class="table-container mb-4">
            <h6 class="mb-3"><i class="bi bi-info-circle me-2"></i>System Information</h6>
            <dl class="row mb-0">
                <dt class="col-sm-6">Laravel Version</dt>
                <dd class="col-sm-6">{{ app()->version() }}</dd>
                
                <dt class="col-sm-6">PHP Version</dt>
                <dd class="col-sm-6">{{ phpversion() }}</dd>
                
                <dt class="col-sm-6">Total Users</dt>
                <dd class="col-sm-6">{{ App\Models\User::count() }}</dd>
                
                <dt class="col-sm-6">Total Admins</dt>
                <dd class="col-sm-6">{{ App\Models\Admin::count() }}</dd>
                
                <dt class="col-sm-6">Database</dt>
                <dd class="col-sm-6">{{ config('database.default') }}</dd>
            </dl>
        </div>

        <!-- Quick Actions -->
        <div class="table-container mb-4">
            <h6 class="mb-3"><i class="bi bi-lightning me-2"></i>Quick Actions</h6>
            <div class="d-grid gap-2">
                <a href="{{ route('dashboard.admins') }}" class="btn btn-outline-primary">
                    <i class="bi bi-person-gear me-2"></i>Manage Admins
                </a>
                <a href="{{ route('dashboard.audit-logs') }}" class="btn btn-outline-primary">
                    <i class="bi bi-journal-text me-2"></i>View Audit Logs
                </a>
            </div>
        </div>

        <!-- Danger Zone -->
        <div class="table-container border-danger">
            <h6 class="mb-3 text-danger"><i class="bi bi-exclamation-triangle me-2"></i>Danger Zone</h6>
            <p class="text-muted small">These actions are irreversible. Use with caution.</p>
            <div class="d-grid gap-2">
                <button type="button" class="btn btn-outline-danger" disabled>
                    <i class="bi bi-trash me-2"></i>Clear All Logs
                </button>
                <button type="button" class="btn btn-outline-danger" disabled>
                    <i class="bi bi-arrow-counterclockwise me-2"></i>Reset All Settings
                </button>
            </div>
        </div>
    </div>
</div>
@endsection
