@extends('backoffice.layouts.app')

@section('title', 'Iki Adimli Dogrulama')

@section('content')
<div class="container-fluid">
    <div class="row mb-4">
        <div class="col-12">
            <h2 class="mb-1"><i class="bi bi-shield-lock me-2"></i>Iki Adimli Dogrulama</h2>
            <p class="text-muted">Google Authenticator ile 2FA ayarlari</p>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-8">
            <div class="card border-0 shadow-sm">
                <div class="card-body">
                    @if (session('status'))
                        <div class="alert alert-success">{{ session('status') }}</div>
                    @endif
                    @if ($errors->any())
                        <div class="alert alert-danger">{{ $errors->first() }}</div>
                    @endif

                    @if (!$user->twofa_enabled)
                        <div class="mb-3">
                            <div class="fw-semibold mb-2">Durum: Kapali</div>
                            <p class="text-muted">Google Authenticator uygulamasina asagidaki bilgileri girin.</p>
                        </div>
                        <div class="mb-3 text-center">
                            <img src="https://api.qrserver.com/v1/create-qr-code/?size=200x200&data={{ urlencode($otpAuthUrl) }}" alt="2FA QR" />
                        </div>
                        <div class="mb-3">
                            <label class="form-label">Secret</label>
                            <div class="p-2 bg-light border rounded">{{ $user->twofa_secret }}</div>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">OTP Auth URI</label>
                            <div class="p-2 bg-light border rounded" style="word-break: break-all;">{{ $otpAuthUrl }}</div>
                        </div>

                        <form method="POST" action="{{ route('backoffice.2fa.enable') }}" class="mt-3">
                            @csrf
                            <div class="mb-3">
                                <label class="form-label">6 haneli kod</label>
                                <input type="text" name="code" class="form-control" required placeholder="123456">
                            </div>
                            <button type="submit" class="btn btn-primary">Etkinlestir</button>
                        </form>
                    @else
                        <div class="mb-3">
                            <div class="fw-semibold">Durum: Acik</div>
                            <p class="text-muted mb-0">2FA etkin. Kapatmak icin kod girin.</p>
                        </div>

                        <form method="POST" action="{{ route('backoffice.2fa.disable') }}" class="mt-3">
                            @csrf
                            <div class="mb-3">
                                <label class="form-label">6 haneli kod</label>
                                <input type="text" name="code" class="form-control" required placeholder="123456">
                            </div>
                            <button type="submit" class="btn btn-outline-danger">Devre Disi Birak</button>
                        </form>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
