@extends('layouts.default')
@section('content')
@php $existing = $client->platformConnections->keyBy('platform'); @endphp
<div class="container-fluid">
    <div class="row mb-3"><div class="col"><h3>{{ $page_title }}</h3><p class="text-muted mb-0">{{ $client->company_name }} için {{ $page_description }}</p></div></div>
    @include('admin.onboarding._progress')

    <form method="POST" action="{{ route('admin.onboarding.integrations.save', $client) }}">
        @csrf
        <div class="row">
            @foreach($platforms as $key => $label)
                @php $connection = $existing->get($key); @endphp
                <div class="col-xl-6">
                    <div class="card"><div class="card-body">
                        <div class="d-flex justify-content-between align-items-center mb-3">
                            <h5 class="mb-0">{{ $label }}</h5>
                            <div class="form-check form-switch"><input type="checkbox" name="platforms[{{ $key }}][enabled]" value="1" class="form-check-input" @checked($connection || in_array($key, ['google_ads','meta_ads']))></div>
                        </div>
                        <div class="mb-3"><label class="form-label">Bağlantı Adı</label><input name="platforms[{{ $key }}][connection_name]" class="form-control" value="{{ old("platforms.$key.connection_name", $connection?->connection_name ?: $client->company_name.' - '.$label) }}"></div>
                        <div class="mb-3"><label class="form-label">Hesap / Mülk ID</label><input name="platforms[{{ $key }}][account_id]" class="form-control" value="{{ old("platforms.$key.account_id", $connection?->account_id) }}" placeholder="Sonradan keşif ekranından da seçilebilir"></div>
                        <div class="mb-3"><label class="form-label">Hesap / Mülk Adı</label><input name="platforms[{{ $key }}][account_name]" class="form-control" value="{{ old("platforms.$key.account_name", $connection?->account_name) }}"></div>
                        <div><label class="form-label">Not</label><textarea name="platforms[{{ $key }}][note]" rows="2" class="form-control">{{ old("platforms.$key.note", $connection?->meta['onboarding_note'] ?? '') }}</textarea></div>
                    </div></div>
                </div>
            @endforeach
        </div>
        <div class="d-flex justify-content-between">
            <a href="{{ route('admin.onboarding.start', ['client_id' => $client->id]) }}" class="btn btn-light">Geri</a>
            <button class="btn btn-primary">Kaydet ve Marka Kitine Geç</button>
        </div>
    </form>
</div>
@endsection
