@extends('layouts.default')
@section('title', 'SMTP / Mail Ayarları')
@section('content')
<div class="container-fluid">
    @include('admin.partials.page-header')

    <form method="POST" action="{{ route('admin.mail.save') }}">
        @csrf
        <div class="row">
            <div class="col-xl-8">
                <div class="card">
                    <div class="card-header border-0 pb-0"><h4 class="card-title mb-0">SMTP Bilgileri</h4></div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-8 mb-3"><label class="form-label">SMTP Host</label><input name="smtp_host" class="form-control" value="{{ old('smtp_host', $settings['smtp_host'] ?? '') }}"></div>
                            <div class="col-md-4 mb-3"><label class="form-label">Port</label><input name="smtp_port" type="number" class="form-control" value="{{ old('smtp_port', $settings['smtp_port'] ?? 587) }}"></div>
                            <div class="col-md-6 mb-3"><label class="form-label">Kullanıcı</label><input name="smtp_username" class="form-control" value="{{ old('smtp_username', $settings['smtp_username'] ?? '') }}"></div>
                            <div class="col-md-6 mb-3"><label class="form-label">Şifre</label><input name="smtp_password" type="password" class="form-control" value="" placeholder="Değiştirmek istemiyorsan boş bırak"></div>
                            <div class="col-md-4 mb-3"><label class="form-label">Şifreleme</label><select name="smtp_encryption" class="form-control default-select"><option value="tls" @selected(($settings['smtp_encryption'] ?? 'tls')==='tls')>TLS</option><option value="ssl" @selected(($settings['smtp_encryption'] ?? '')==='ssl')>SSL</option><option value="none" @selected(($settings['smtp_encryption'] ?? '')==='none')>Yok</option></select></div>
                            <div class="col-md-4 mb-3"><label class="form-label">Gönderen Adı</label><input name="from_name" class="form-control" value="{{ old('from_name', $settings['from_name'] ?? 'DW Ads Reporter') }}"></div>
                            <div class="col-md-4 mb-3"><label class="form-label">Gönderen E-posta</label><input name="from_email" type="email" class="form-control" value="{{ old('from_email', $settings['from_email'] ?? '') }}"></div>
                            <div class="col-md-6 mb-3"><label class="form-label">Reply-To</label><input name="reply_to" type="email" class="form-control" value="{{ old('reply_to', $settings['reply_to'] ?? '') }}"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xl-4">
                <div class="card">
                    <div class="card-header border-0 pb-0"><h4 class="card-title mb-0">İşlem</h4></div>
                    <div class="card-body">
                        <button class="btn btn-primary w-100 mb-3">Kaydet</button>
                        <div class="border rounded p-3">
                            <label class="form-label">Test Maili Alıcısı</label>
                            <input type="email" name="test_email" class="form-control mb-2" value="{{ old('test_email') }}" placeholder="ornek@site.com" form="smtp-test-form">
                            <button type="submit" form="smtp-test-form" class="btn btn-outline-primary w-100">Test Maili Gönder</button>
                        </div>
                        <p class="text-muted mt-3 mb-0">SMTP şifresi artık veritabanında şifreli tutulur. Test maili de mail loglarına düşer.</p>
                    </div>
                </div>
            </div>
        </div>
    </form>

    <form id="smtp-test-form" method="POST" action="{{ route('admin.mail.test') }}">
        @csrf
    </form>
</div>
@endsection
