@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">Plan 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', $schedule->client_id) == $client->id)>{{ $client->company_name }}</option>@endforeach</select></div>
                    <div class="col-md-6 mb-3"><label class="form-label">Rapor Şablonu</label><select name="report_template_id" class="form-control default-select"><option value="">Varsayılan görünüm</option>@foreach($templates as $template)<option value="{{ $template->id }}" @selected(old('report_template_id', $schedule->report_template_id) == $template->id)>{{ $template->name }} {{ $template->client ? '· '.$template->client->company_name : '· Genel' }}</option>@endforeach</select><small class="text-muted">Otomatik rapor PDF/Excel tasarımı bu şablona göre hazırlanır.</small></div>
                    <div class="col-md-6 mb-3"><label class="form-label">Frekans *</label><select name="frequency" class="form-control default-select" required><option value="daily" @selected(old('frequency', $schedule->frequency)==='daily')>Günlük</option><option value="weekly" @selected(old('frequency', $schedule->frequency)==='weekly')>Haftalık</option><option value="monthly" @selected(old('frequency', $schedule->frequency)==='monthly')>Aylık</option></select></div>
                    <div class="col-md-3 mb-3"><label class="form-label">Saat</label><input type="time" name="daily_time" class="form-control" value="{{ old('daily_time', $schedule->daily_time ?: '09:00') }}"></div>
                    <div class="col-md-3 mb-3"><label class="form-label">Sonraki Çalışma</label><input type="text" class="form-control" value="{{ $schedule->next_run_at?->format('d.m.Y H:i') ?? 'Kaydedince hesaplanır' }}" disabled></div>
                    <div class="col-md-4 mb-3"><label class="form-label">Haftalık Gün</label><select name="weekly_day" class="form-control default-select"><option value="">Seçiniz</option>@foreach([1=>'Pazartesi',2=>'Salı',3=>'Çarşamba',4=>'Perşembe',5=>'Cuma',6=>'Cumartesi',7=>'Pazar'] as $day => $label)<option value="{{ $day }}" @selected(old('weekly_day', $schedule->weekly_day ?: 1) == $day)>{{ $label }}</option>@endforeach</select></div>
                    <div class="col-md-4 mb-3"><label class="form-label">Aylık Gün</label><input type="number" name="monthly_day" class="form-control" min="1" max="31" value="{{ old('monthly_day', $schedule->monthly_day ?: 1) }}" placeholder="1-31"></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', $schedule->timezone ?: 'Europe/Istanbul') }}" required></div>
                </div>
            </div>
        </div>

        <div class="card">
            <div class="card-header border-0 pb-0"><h4 class="card-title mb-0">Kanallar</h4></div>
            <div class="card-body">
                @php($selectedChannels = old('channels', $schedule->channels ?: ['google_ads', 'meta_ads', 'search_console', 'ga4']))
                <div class="row">
                    @foreach(['google_ads' => 'Google Ads', 'meta_ads' => 'Meta Ads', 'search_console' => 'Search Console', 'ga4' => 'GA4'] as $key => $label)
                        <div class="col-md-3 mb-2"><label class="border rounded p-3 d-block"><input type="checkbox" name="channels[]" value="{{ $key }}" class="form-check-input me-2" @checked(in_array($key, $selectedChannels, true))>{{ $label }}</label></div>
                    @endforeach
                </div>
            </div>
        </div>

        <div class="card">
            <div class="card-header border-0 pb-0"><h4 class="card-title mb-0">Mail Alıcıları</h4></div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6 mb-3"><label class="form-label">Alıcılar</label><textarea name="recipients_raw" class="form-control" rows="4" placeholder="Her satıra veya virgülle ayırarak yaz">{{ old('recipients_raw', implode("\n", $schedule->recipients ?? [])) }}</textarea></div>
                    <div class="col-md-3 mb-3"><label class="form-label">CC</label><textarea name="cc_raw" class="form-control" rows="4">{{ old('cc_raw', implode("\n", $schedule->cc ?? [])) }}</textarea></div>
                    <div class="col-md-3 mb-3"><label class="form-label">BCC</label><textarea name="bcc_raw" class="form-control" rows="4">{{ old('bcc_raw', implode("\n", $schedule->bcc ?? [])) }}</textarea></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">Dosya ve Durum</h4></div>
            <div class="card-body">
                <div class="form-check mb-2"><input class="form-check-input" type="checkbox" name="include_pdf" value="1" id="pdf" @checked(old('include_pdf', $schedule->include_pdf))><label class="form-check-label" for="pdf">PDF ekle</label></div>
                <div class="form-check mb-2"><input class="form-check-input" type="checkbox" name="include_excel" value="1" id="excel" @checked(old('include_excel', $schedule->include_excel))><label class="form-check-label" for="excel">Excel ekle</label></div>
                <div class="form-check mb-2"><input class="form-check-input" type="checkbox" name="include_csv" value="1" id="csv" @checked(old('include_csv', $schedule->include_csv))><label class="form-check-label" for="csv">CSV ekle</label></div>
                <div class="form-check mb-3"><input class="form-check-input" type="checkbox" name="is_active" value="1" id="active" @checked(old('is_active', $schedule->is_active))><label class="form-check-label" for="active">Aktif</label></div>
                <button class="btn btn-primary w-100 mb-2">Kaydet</button><a href="{{ route('admin.report-schedules.index') }}" class="btn btn-light w-100">Vazgeç</a>
                @if($schedule->exists)
                    <hr>
                    <a href="{{ route('admin.report-schedules.show', $schedule) }}" class="btn btn-outline-primary w-100">Plan Detayı</a>
                @endif
            </div>
        </div>
    </div>
</div>
