@csrf
<div class="row">
    <div class="col-xl-8">
        <div class="card">
            <div class="card-header"><h4 class="card-title mb-0">Bağlantı Bilgileri</h4></div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Müşteri *</label>
                        <select name="client_id" class="form-control default-select" required>
                            <option value="">Seçiniz</option>
                            @foreach($clients as $client)
                                <option value="{{ $client->id }}" @selected(old('client_id', $connection->client_id) == $client->id)>{{ $client->company_name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Bağlantı Adı *</label>
                        <input type="text" name="connection_name" class="form-control" value="{{ old('connection_name', $connection->connection_name) }}" placeholder="Örn: Ana Google Ads Hesabı" required>
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Hesap ID</label>
                        <input type="text" name="account_id" class="form-control" value="{{ old('account_id', $connection->account_id) }}" placeholder="Platformdaki ana hesap/mülk ID">
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Hesap Adı</label>
                        <input type="text" name="account_name" class="form-control" value="{{ old('account_name', $connection->account_name) }}">
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label">Durum *</label>
                        <select name="status" class="form-control default-select" required>
                            @foreach(['draft' => 'Taslak', 'active' => 'Aktif', 'paused' => 'Beklemede', 'error' => 'Hatalı'] as $value => $label)
                                <option value="{{ $value }}" @selected(old('status', $connection->status) === $value)>{{ $label }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label">Para Birimi</label>
                        <input type="text" name="currency_code" class="form-control" value="{{ old('currency_code', $connection->currency_code) }}" maxlength="3" placeholder="TRY">
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label">Zaman Dilimi</label>
                        <input type="text" name="timezone" class="form-control" value="{{ old('timezone', $connection->timezone) }}" placeholder="Europe/Istanbul">
                    </div>
                </div>
            </div>
        </div>

        @includeIf('admin.accounts.partials.credentials-'.$platform, ['connection' => $connection, 'maskedPayload' => $maskedPayload ?? []])

        <div class="card">
            <div class="card-header"><h4 class="card-title mb-0">Son Hata / İç Not</h4></div>
            <div class="card-body">
                <textarea name="last_error" class="form-control" rows="4" placeholder="Manuel not veya son hata bilgisi">{{ old('last_error', $connection->last_error) }}</textarea>
            </div>
        </div>
    </div>
    <div class="col-xl-4">
        <div class="card">
            <div class="card-header"><h4 class="card-title mb-0">Platform</h4></div>
            <div class="card-body">
                <p class="mb-2"><strong>{{ strtoupper(str_replace('_', ' ', $platform)) }}</strong></p>
                <p class="text-muted mb-3">Faz 2 ile tokenlar şifreli kasaya kaydedilir. Boş bırakılan gizli alanlar düzenleme sırasında korunur.</p>
                @if(!empty($maskedPayload))
                    <div class="alert alert-light border mb-3">
                        <strong>Kayıtlı gizli bilgiler:</strong>
                        <ul class="mb-0 ps-3 mt-2">
                            @foreach($maskedPayload as $key => $value)
                                <li><small>{{ $key }}: {{ $value }}</small></li>
                            @endforeach
                        </ul>
                    </div>
                @endif
                <button type="submit" class="btn btn-primary w-100 mb-2">Kaydet</button>
                <a href="{{ url()->previous() }}" class="btn btn-light w-100">Vazgeç</a>
            </div>
        </div>
    </div>
</div>
