@extends('layouts.default')
@section('content')
<div class="container-fluid">
    <div class="row mb-3"><div class="col"><h3>{{ $page_title }}</h3><p class="text-muted mb-0">{{ $page_description }}</p></div></div>
    @include('admin.onboarding._progress')

    <form method="POST" action="{{ route('admin.onboarding.client.save') }}">
        @csrf
        <input type="hidden" name="client_id" value="{{ old('client_id', $client?->id) }}">
        <div class="row">
            <div class="col-xl-8">
                <div class="card"><div class="card-body">
                    <h5 class="mb-3">Müşteri Bilgileri</h5>
                    <div class="row g-3">
                        <div class="col-md-8"><label class="form-label">Firma Adı *</label><input name="company_name" class="form-control" required value="{{ old('company_name', $client?->company_name) }}"></div>
                        <div class="col-md-4"><label class="form-label">Durum</label><select name="status" class="form-control default-select"><option value="active" @selected(old('status', $client?->status ?? 'active')==='active')>Aktif</option><option value="passive" @selected(old('status', $client?->status)==='passive')>Pasif</option></select></div>
                        <div class="col-md-6"><label class="form-label">Yetkili</label><input name="contact_person" class="form-control" value="{{ old('contact_person', $client?->contact_person) }}"></div>
                        <div class="col-md-6"><label class="form-label">E-posta</label><input name="email" type="email" class="form-control" value="{{ old('email', $client?->email) }}"></div>
                        <div class="col-md-6"><label class="form-label">Telefon</label><input name="phone" class="form-control" value="{{ old('phone', $client?->phone) }}"></div>
                        <div class="col-md-6"><label class="form-label">Web Sitesi</label><input name="website" class="form-control" value="{{ old('website', $client?->website) }}"></div>
                        <div class="col-md-4"><label class="form-label">Sektör</label><input name="sector" class="form-control" value="{{ old('sector', $client?->sector) }}"></div>
                        <div class="col-md-3"><label class="form-label">Para Birimi</label><input name="currency_code" maxlength="3" class="form-control" value="{{ old('currency_code', $client?->currency_code ?? 'TRY') }}"></div>
                        <div class="col-md-3"><label class="form-label">Zaman Dilimi</label><input name="timezone" class="form-control" value="{{ old('timezone', $client?->timezone ?? 'Europe/Istanbul') }}"></div>
                        <div class="col-md-2"><label class="form-label">Dil</label><select name="report_language" class="form-control"><option value="tr" @selected(old('report_language', $client?->report_language ?? 'tr')==='tr')>TR</option><option value="en" @selected(old('report_language', $client?->report_language)==='en')>EN</option></select></div>
                        <div class="col-md-4"><label class="form-label">Ana Renk</label><input name="primary_color" type="color" class="form-control form-control-color" value="{{ old('primary_color', $client?->primary_color ?? '#111827') }}"></div>
                        <div class="col-md-8"><label class="form-label">Rapor Alıcıları</label><input name="report_recipients" class="form-control" placeholder="mail1@site.com, mail2@site.com" value="{{ old('report_recipients', implode(', ', $client?->report_recipients ?: [])) }}"></div>
                        <div class="col-md-6"><label class="form-label">Müşteri Notu</label><textarea name="notes" rows="4" class="form-control">{{ old('notes', $client?->notes) }}</textarea></div>
                        <div class="col-md-6"><label class="form-label">Ajans İçi Not</label><textarea name="internal_notes" rows="4" class="form-control">{{ old('internal_notes', $client?->internal_notes) }}</textarea></div>
                    </div>
                </div></div>
            </div>
            <div class="col-xl-4">
                <div class="card"><div class="card-body">
                    <h5>Mevcut müşteriden devam et</h5>
                    <p class="text-muted">Yeni müşteri yerine mevcut bir müşteri için onboarding akışını sürdürebilirsin.</p>
                    <select onchange="if(this.value) window.location='{{ route('admin.onboarding.start') }}?client_id='+this.value" class="form-control default-select">
                        <option value="">Müşteri seç</option>
                        @foreach($clients as $item)<option value="{{ $item->id }}" @selected($client?->id===$item->id)>{{ $item->company_name }}</option>@endforeach
                    </select>
                    <hr>
                    <button class="btn btn-primary w-100">Kaydet ve Bağlantılara Geç</button>
                    <a href="{{ route('admin.onboarding.index') }}" class="btn btn-light w-100 mt-2">Listeye Dön</a>
                </div></div>
            </div>
        </div>
    </form>
</div>
@endsection
