@extends('layouts.app')

@section('title', 'Account Settings')

@section('content')
<div class="container-fluid px-4 py-4" data-reveal>
    <div class="mb-4">
        <h1 class="display-md mb-1" style="color: var(--arena-text-primary);">Account Settings</h1>
        <p class="text-muted fs-sm">Manage your profile, security, and game accounts.</p>
    </div>

    @if (session('status'))
        <div class="alert alert-success mb-4" role="alert">
            {{ session('status') }}
        </div>
    @endif

    @if ($errors->any())
        <div class="alert alert-danger mb-4" role="alert">
            <ul class="mb-0">
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif

    <div class="row g-4">
        <!-- Settings Nav Side -->
        <div class="col-md-3">
            <div class="card-arena p-3 d-flex flex-column gap-2" style="background: var(--arena-surface-01);">
                <a href="{{ route('settings') }}" class="btn-arena btn-sm {{ $tab === 'account' ? 'btn-primary' : 'btn-secondary' }} text-start">Account Profile</a>
                <a href="{{ route('settings.tab', 'security') }}" class="btn-arena btn-sm {{ $tab === 'security' ? 'btn-primary' : 'btn-secondary' }} text-start">Security Settings</a>
                <a href="{{ route('settings.tab', 'notifications') }}" class="btn-arena btn-sm {{ $tab === 'notifications' ? 'btn-primary' : 'btn-secondary' }} text-start">Notifications</a>
            </div>
        </div>

        <!-- Settings Config Main -->
        <div class="col-md-9">
            <div class="card-arena p-4">
                @if($tab === 'account')
                <span class="card-title">Edit Profile Information</span>
                <form action="{{ route('settings.profile.update') }}" method="POST" class="d-flex flex-column gap-3">
                    @csrf
                    <div>
                        <label for="username" class="text-label mb-2">Display Username</label>
                        <input type="text" id="username" name="username" class="form-control input-arena" value="{{ old('username', $player['username']) }}">
                    </div>
                    <div>
                        <label for="real_name" class="text-label mb-2">Real Name</label>
                        <input type="text" id="real_name" name="real_name" class="form-control input-arena" value="{{ old('real_name', $player['real_name']) }}">
                    </div>
                    <div>
                        <label for="bio" class="text-label mb-2">Short Biography</label>
                        <textarea id="bio" name="bio" class="form-control input-arena" rows="3" style="resize: none;">{{ old('bio', $player['bio']) }}</textarea>
                    </div>
                    <button type="submit" class="btn-arena btn-primary btn-sm align-self-start mt-2">Save Profile Updates</button>
                </form>
                @elseif($tab === 'security')
                <span class="card-title">Security & Password Changes</span>
                <form action="{{ route('settings.password.update') }}" method="POST" class="d-flex flex-column gap-3">
                    @csrf
                    <div>
                        <label for="old_pass" class="text-label mb-2">Current Password</label>
                        <input type="password" id="old_pass" name="current_password" class="form-control input-arena" placeholder="••••••••" autocomplete="current-password">
                    </div>
                    <div>
                        <label for="new_pass" class="text-label mb-2">New Password</label>
                        <input type="password" id="new_pass" name="password" class="form-control input-arena" placeholder="••••••••" autocomplete="new-password">
                    </div>
                    <div>
                        <label for="new_pass_confirmation" class="text-label mb-2">Confirm New Password</label>
                        <input type="password" id="new_pass_confirmation" name="password_confirmation" class="form-control input-arena" placeholder="••••••••" autocomplete="new-password">
                    </div>
                    <button type="submit" class="btn-arena btn-primary btn-sm align-self-start mt-2">Update Password</button>
                </form>
                @elseif($tab === 'notifications')
                <span class="card-title">Notifications Preferences</span>
                <div class="d-flex flex-column gap-3 text-white">
                    <div class="d-flex align-items-center justify-content-between">
                        <div>
                            <div class="fw-700 fs-sm">Email Alerts</div>
                            <div class="fs-xs text-muted">Receive notifications on registered matches</div>
                        </div>
                        <div class="toggle-arena checked" role="switch" aria-checked="true" tabindex="0"></div>
                    </div>
                    <div class="d-flex align-items-center justify-content-between">
                        <div>
                            <div class="fw-700 fs-sm">Sound Signals</div>
                            <div class="fs-xs text-muted">Lobby challenge auditory alert sounds</div>
                        </div>
                        <div class="toggle-arena" role="switch" aria-checked="false" tabindex="0"></div>
                    </div>
                </div>
                @endif
            </div>
        </div>
    </div>
</div>
@endsection
