

<?php $__env->startSection('title', $customer->full_name . ' — Düzenle'); ?>
<?php $__env->startSection('page_title', 'Müşteri Düzenle'); ?>

<?php $__env->startPush('styles'); ?>
<style>
.form-page { max-width:880px;margin:0 auto; }
.form-card { background:#fff;border-radius:20px;border:1px solid #f1f5f9;box-shadow:0 2px 12px rgba(0,0,0,.05);overflow:hidden;margin-bottom:1.25rem; }
.form-section-header { display:flex;align-items:center;gap:.75rem;padding:1.1rem 1.5rem;border-bottom:1px solid #f1f5f9;background:#fafbff; }
.form-section-icon { width:36px;height:36px;border-radius:10px;display:flex;align-items:center;justify-content:center;font-size:15px;flex-shrink:0; }
.form-section-title { font-size:.9rem;font-weight:700;color:#0f172a; }
.form-section-body { padding:1.5rem; }
.field-group { margin-bottom:1.25rem; }
.field-label { display:block;font-size:.78rem;font-weight:700;color:#64748b;text-transform:uppercase;letter-spacing:.4px;margin-bottom:.4rem; }
.field-label .req { color:#ef4444;margin-left:2px; }
.field-input { width:100%;border:1.5px solid #e2e8f0;border-radius:10px;padding:.65rem .9rem;font-size:.875rem;color:#0f172a;background:#f8fafc;transition:all .2s;height:44px; }
.field-input:focus { outline:none;border-color:#6366f1;box-shadow:0 0 0 3px rgba(99,102,241,.1);background:#fff; }
textarea.field-input { height:auto;resize:vertical; }
.fg-2 { display:grid;grid-template-columns:1fr 1fr;gap:1rem; }
.fg-3 { display:grid;grid-template-columns:1fr 1fr 1fr;gap:1rem; }
@media(max-width:640px) { .fg-2,.fg-3 { grid-template-columns:1fr; } }
.toggle-row { display:flex;align-items:center;justify-content:space-between;padding:.75rem 1rem;border-radius:10px;background:#f8fafc;border:1px solid #f1f5f9;margin-bottom:.5rem; }
.toggle-info .tl { font-size:.85rem;font-weight:600;color:#0f172a; }
.toggle-info .td { font-size:.75rem;color:#94a3b8; }
.toggle-switch { position:relative;display:inline-block;width:44px;height:24px;flex-shrink:0 }
.toggle-switch input { opacity:0;width:0;height:0 }
.toggle-slider { position:absolute;cursor:pointer;top:0;left:0;right:0;bottom:0;background:#e2e8f0;border-radius:999px;transition:.3s; }
.toggle-slider:before { content:'';position:absolute;width:18px;height:18px;border-radius:50%;left:3px;bottom:3px;background:#fff;transition:.3s;box-shadow:0 1px 4px rgba(0,0,0,.2); }
input:checked+.toggle-slider { background:#6366f1; }
input:checked+.toggle-slider:before { transform:translateX(20px); }
.form-footer { position:sticky;bottom:0;z-index:10;background:#fff;border-top:1px solid #f1f5f9;padding:1rem 1.5rem;display:flex;justify-content:space-between;align-items:center;border-radius:0 0 20px 20px;box-shadow:0 -4px 20px rgba(0,0,0,.05); }
.error-msg { font-size:.75rem;color:#ef4444;margin-top:.25rem; }
.field-error { border-color:#ef4444 !important;background:#fff5f5 !important; }

/* Email dynamic list */
.email-list { display: flex; flex-direction: column; gap: .5rem; }
.email-item { display: flex; gap: .5rem; align-items: center; }
.btn-add-email { 
    background: #eef2ff; color: #6366f1; border: none; 
    width: 38px; height: 38px; border-radius: 8px; 
    cursor: pointer; transition: all .2s;
    display: flex; align-items: center; justify-content: center;
}
.btn-add-email:hover { background: #6366f1; color: #fff; }
.btn-remove-email {
    background: #fff1f2; color: #ef4444; border: none;
    width: 38px; height: 38px; border-radius: 8px;
    cursor: pointer; transition: all .2s;
    display: flex; align-items: center; justify-content: center;
}
.btn-remove-email:hover { background: #ef4444; color: #fff; }

.type-pill { display:block;padding:.45rem 1rem;font-size:.82rem;font-weight:600;color:#64748b;background:transparent;transition:all .2s;cursor:pointer; }
input[type=radio]:checked + .type-pill { background:#6366f1;color:#fff; }
</style>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
<div class="form-page">

<div class="d-flex align-items-center gap-2 mb-3" style="font-size:.83rem;color:#94a3b8">
    <a href="<?php echo e(route('agency.customers.index')); ?>" style="color:#6366f1;text-decoration:none;font-weight:600">
        <i class="fas fa-users me-1"></i>Müşteriler
    </a>
    <i class="fas fa-chevron-right" style="font-size:10px"></i>
    <a href="<?php echo e(route('agency.customers.show', $customer)); ?>" style="color:#6366f1;text-decoration:none;font-weight:600"><?php echo e($customer->full_name); ?></a>
    <i class="fas fa-chevron-right" style="font-size:10px"></i>
    <span style="color:#0f172a;font-weight:600">Düzenle</span>
</div>

<form method="POST" action="<?php echo e(route('agency.customers.update', $customer)); ?>" id="customerForm">
<?php echo csrf_field(); ?> <?php echo method_field('PUT'); ?>

<?php if($errors->any()): ?>
<div class="alert alert-danger mb-4" style="border-radius:12px; font-size:.85rem; border:none; box-shadow:0 4px 12px rgba(239,68,68,0.1)">
    <div style="font-weight:700" class="mb-2 text-danger"><i class="fas fa-exclamation-triangle me-1"></i> Lütfen aşağıdaki hataları düzeltin:</div>
    <ul class="mb-0 ps-3 text-danger">
        <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <li><?php echo e($error); ?></li>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </ul>
</div>
<?php endif; ?>

<div class="form-card">
    <div class="form-section-header">
        <div class="form-section-icon" style="background:#eef2ff;color:#6366f1"><i class="fas fa-user"></i></div>
        <div class="form-section-title">Temel Bilgiler</div>
        <div class="ms-auto d-flex rounded-pill overflow-hidden" style="border:1.5px solid #e2e8f0">
            <label style="cursor:pointer">
                <input type="radio" name="customer_type" value="individual" <?php echo e(old('customer_type',$customer->customer_type) === 'individual' ? 'checked' : ''); ?> class="d-none type-radio">
                <span class="type-pill" data-val="individual">👤 Kişi</span>
            </label>
            <label style="cursor:pointer">
                <input type="radio" name="customer_type" value="corporate"  <?php echo e(old('customer_type',$customer->customer_type) === 'corporate'  ? 'checked' : ''); ?> class="d-none type-radio">
                <span class="type-pill" data-val="corporate">🏢 Şirket</span>
            </label>
        </div>
    </div>
    <div class="form-section-body">
        <div class="fg-2">
            <div class="field-group">
                <label class="field-label">Ad<span class="req">*</span></label>
                <input type="text" name="first_name" value="<?php echo e(old('first_name', $customer->first_name)); ?>"
                       class="field-input <?php echo e($errors->has('first_name') ? 'field-error' : ''); ?>">
                <?php $__errorArgs = ['first_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <div class="error-msg"><?php echo e($message); ?></div> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
            </div>
            <div class="field-group">
                <label class="field-label">Soyad<span class="req">*</span></label>
                <input type="text" name="last_name" value="<?php echo e(old('last_name', $customer->last_name)); ?>"
                       class="field-input <?php echo e($errors->has('last_name') ? 'field-error' : ''); ?>">
                <?php $__errorArgs = ['last_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <div class="error-msg"><?php echo e($message); ?></div> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
            </div>
        </div>
        <div class="fg-2">
            <div class="field-group">
                <label class="field-label">E-posta Adresleri</label>
                <div class="email-list" id="emailList">
                    <?php 
                        $currentEmails = old('emails', is_array($customer->emails) ? $customer->emails : ($customer->emails ? [$customer->emails] : []));
                        if (empty($currentEmails)) $currentEmails = [''];
                    ?>
                    <?php $__currentLoopData = $currentEmails; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $emailVal): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="email-item">
                            <input type="email" name="emails[]" value="<?php echo e($emailVal); ?>" class="field-input" placeholder="ornek@mail.com">
                            <?php if($loop->first): ?>
                                <button type="button" class="btn-add-email" id="btnAddEmail"><i class="fas fa-plus"></i></button>
                            <?php else: ?>
                                <button type="button" class="btn-remove-email remove-email"><i class="fas fa-trash"></i></button>
                            <?php endif; ?>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
                <?php $__errorArgs = ['emails.*'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <div class="error-msg"><?php echo e($message); ?></div> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
            </div>
            <div class="field-group">
                <label class="field-label">Telefon</label>
                <input type="text" name="phone" value="<?php echo e(old('phone', $customer->phone)); ?>" class="field-input">
            </div>
        </div>
        <div class="fg-3">
            <div class="field-group">
                <label class="field-label">Alt Telefon</label>
                <input type="text" name="phone_alt" value="<?php echo e(old('phone_alt', $customer->phone_alt)); ?>" class="field-input">
            </div>
            <div class="field-group">
                <label class="field-label">Doğum Tarihi</label>
                <input type="date" name="birth_date" value="<?php echo e(old('birth_date', $customer->birth_date?->format('Y-m-d'))); ?>" class="field-input">
            </div>
            <div class="field-group">
                <label class="field-label">Cinsiyet</label>
                <select name="gender" class="field-input">
                    <option value="">Seç</option>
                    <option value="male"   <?php echo e(old('gender',$customer->gender) === 'male'   ? 'selected' : ''); ?>>Erkek</option>
                    <option value="female" <?php echo e(old('gender',$customer->gender) === 'female' ? 'selected' : ''); ?>>Kadın</option>
                    <option value="other"  <?php echo e(old('gender',$customer->gender) === 'other'  ? 'selected' : ''); ?>>Diğer</option>
                </select>
            </div>
        </div>

        <div id="corporateFields" style="<?php echo e(old('customer_type',$customer->customer_type) === 'corporate' ? '' : 'display:none'); ?>">
            <hr style="border-color:#f1f5f9;margin:1rem 0">
            <div class="fg-3">
                <div class="field-group">
                    <label class="field-label">Firma Adı</label>
                    <input type="text" name="company_name" value="<?php echo e(old('company_name',$customer->company_name)); ?>" class="field-input">
                </div>
                <div class="field-group">
                    <label class="field-label">Şirket Türü</label>
                    <select name="company_type" class="field-input">
                        <option value="">Seçiniz</option>
                        <?php $__currentLoopData = \App\Models\Customer\Customer::companyTypes(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $val => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($val); ?>" <?php echo e(old('company_type', $customer->company_type) === $val ? 'selected' : ''); ?>><?php echo e($label); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="field-group">
                    <label class="field-label">Pozisyon</label>
                    <input type="text" name="company_position" value="<?php echo e(old('company_position',$customer->company_position)); ?>" class="field-input">
                </div>
            </div>
            <div class="fg-2">
                <div class="field-group">
                    <label class="field-label">Vergi No</label>
                    <input type="text" name="company_tax_number" value="<?php echo e(old('company_tax_number',$customer->company_tax_number)); ?>" class="field-input">
                </div>
                <div class="field-group">
                    <label class="field-label">Vergi Dairesi</label>
                    <input type="text" name="company_tax_office" value="<?php echo e(old('company_tax_office',$customer->company_tax_office)); ?>" class="field-input">
                </div>
            </div>

            <div class="billing-section mt-4">
                <div style="font-size: .85rem; font-weight: 700; color: #475569; text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px dashed #e2e8f0; padding-bottom: .5rem; margin-bottom: 1rem">
                    <i class="fas fa-file-invoice me-1 text-primary"></i> Fatura Bilgileri
                </div>
                
                <div class="field-group mb-3">
                    <label class="field-label">Fatura Adresi</label>
                    <textarea name="billing_address" class="field-input" rows="2" placeholder="Fatura Adresi"><?php echo e(old('billing_address', $customer->billing_address)); ?></textarea>
                </div>

                <div class="fg-3">
                    <div class="field-group">
                        <label class="field-label">Fatura İli</label>
                        <input type="text" name="billing_city" value="<?php echo e(old('billing_city', $customer->billing_city)); ?>" class="field-input">
                    </div>
                    <div class="field-group">
                        <label class="field-label">Fatura İlçe</label>
                        <input type="text" name="billing_district" value="<?php echo e(old('billing_district', $customer->billing_district)); ?>" class="field-input">
                    </div>
                    <div class="field-group">
                        <label class="field-label">Fatura E-posta</label>
                        <input type="email" name="billing_email" value="<?php echo e(old('billing_email', $customer->billing_email)); ?>" class="field-input">
                    </div>
                </div>

                <div class="fg-2 mt-2">
                    <div class="field-group">
                        <label class="field-label">Fatura Vergi No</label>
                        <input type="text" name="billing_tax_number" value="<?php echo e(old('billing_tax_number', $customer->billing_tax_number)); ?>" class="field-input">
                    </div>
                    <div class="field-group">
                        <label class="field-label">Fatura Vergi Dairesi</label>
                        <input type="text" name="billing_tax_office" value="<?php echo e(old('billing_tax_office', $customer->billing_tax_office)); ?>" class="field-input">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="form-card">
    <div class="form-section-header">
        <div class="form-section-icon" style="background:#fef3c7;color:#f59e0b"><i class="fas fa-tag"></i></div>
        <div class="form-section-title">Durum & Sınıflandırma</div>
    </div>
    <div class="form-section-body">
        <div class="fg-3">
            <div class="field-group">
                <label class="field-label">Durum<span class="req">*</span></label>
                <select name="status" class="field-input">
                    <option value="active"    <?php echo e(old('status',$customer->status) === 'active'    ? 'selected' : ''); ?>>✅ Aktif</option>
                    <option value="potential" <?php echo e(old('status',$customer->status) === 'potential' ? 'selected' : ''); ?>>🔔 Potansiyel</option>
                    <option value="inactive"  <?php echo e(old('status',$customer->status) === 'inactive'  ? 'selected' : ''); ?>>⏸ Pasif</option>
                    <option value="blocked"   <?php echo e(old('status',$customer->status) === 'blocked'   ? 'selected' : ''); ?>>🚫 Engellenmiş</option>
                </select>
            </div>
            <div class="field-group">
                <label class="field-label">Öncelik</label>
                <select name="priority" class="field-input">
                    <option value="1" <?php echo e(old('priority', $customer->priority ? '1' : '0') == '1' ? 'selected' : ''); ?>>⭐ Öncelikli</option>
                    <option value="0" <?php echo e(old('priority', $customer->priority ? '1' : '0') == '0' ? 'selected' : ''); ?>>⚪ Normal</option>
                </select>
            </div>
            <div class="field-group">
                <label class="field-label">Temsilci</label>
                <select name="assigned_agent_id" class="field-input">
                    <option value="">Atanmamış</option>
                    <?php $__currentLoopData = $agents; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $agent): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($agent->id); ?>" <?php echo e(old('assigned_agent_id',$customer->assigned_agent_id) == $agent->id ? 'selected' : ''); ?>>
                            <?php echo e($agent->full_name); ?>

                        </option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
        </div>
        <div class="fg-2">
            <div class="field-group">
                <label class="field-label">Referans Kaynağı</label>
                <input type="text" name="referral_source" value="<?php echo e(old('referral_source',$customer->referral_source)); ?>" class="field-input">
            </div>
            <div class="field-group">
                <label class="field-label">Tercih İletişim</label>
                <select name="preferred_contact_method" class="field-input">
                    <option value="">Seç</option>
                    <?php $__currentLoopData = ['phone'=>'📞 Telefon','email'=>'📧 E-posta','sms'=>'💬 SMS']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $v=>$l): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($v); ?>" <?php echo e(old('preferred_contact_method',$customer->preferred_contact_method) === $v ? 'selected' : ''); ?>><?php echo e($l); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
        </div>
        <div class="fg-2">
            <div class="field-group">
                <label class="field-label">Etiketler</label>
                <input type="text" name="tags" value="<?php echo e(old('tags', is_array($customer->tags) ? implode(',', $customer->tags) : '')); ?>" class="field-input" placeholder="virgül ile ayırın">
                <div style="font-size:.7rem;color:#94a3b8;margin-top:2px">Örn: gezi, kültür, macera</div>
            </div>
            <div class="field-group">
                <label class="field-label">İlgi Alanları</label>
                <input type="text" name="interests" value="<?php echo e(old('interests', is_array($customer->interests) ? implode(',', $customer->interests) : '')); ?>" class="field-input" placeholder="virgül ile ayırın">
                <div style="font-size:.7rem;color:#94a3b8;margin-top:2px">Örn: tarih, doğa, gastronomi</div>
            </div>
        </div>
    </div>
</div>

<div class="form-card">
    <div class="form-section-header">
        <div class="form-section-icon" style="background:#d1fae5;color:#10b981"><i class="fas fa-id-card"></i></div>
        <div class="form-section-title">Kimlik & Adres</div>
    </div>
    <div class="form-section-body">
        <div class="fg-3">
            <div class="field-group">
                <label class="field-label">TC / Kimlik</label>
                <input type="text" name="national_id" value="<?php echo e(old('national_id',$customer->national_id)); ?>" class="field-input">
            </div>
            <div class="field-group">
                <label class="field-label">Pasaport No</label>
                <input type="text" name="passport_number" value="<?php echo e(old('passport_number',$customer->passport_number)); ?>" class="field-input">
            </div>
            <div class="field-group">
                <label class="field-label">Pasaport Geçerlilik</label>
                <input type="date" name="passport_expiry" value="<?php echo e(old('passport_expiry',$customer->passport_expiry?->format('Y-m-d'))); ?>" class="field-input">
            </div>
        </div>
        <div class="fg-3">
            <div class="field-group">
                <label class="field-label">Uyruk (ISO)</label>
                <input type="text" name="nationality" value="<?php echo e(old('nationality',$customer->nationality)); ?>" class="field-input" maxlength="2" placeholder="TR, DE...">
            </div>
            <div class="field-group">
                <label class="field-label">Şehir</label>
                <input type="text" name="city" value="<?php echo e(old('city',$customer->city)); ?>" class="field-input">
            </div>
            <div class="field-group">
                <label class="field-label">İlçe</label>
                <input type="text" name="district" value="<?php echo e(old('district',$customer->district)); ?>" class="field-input">
            </div>
        </div>
        <div class="fg-2">
            <div class="field-group">
                <label class="field-label">Adres</label>
                <input type="text" name="address" value="<?php echo e(old('address',$customer->address)); ?>" class="field-input">
            </div>
            <div class="field-group">
                <label class="field-label">Posta Kodu</label>
                <input type="text" name="postal_code" value="<?php echo e(old('postal_code',$customer->postal_code)); ?>" class="field-input" maxlength="10">
            </div>
        </div>
    </div>
</div>

<div class="form-card">
    <div class="form-section-header">
        <div class="form-section-icon" style="background:#ede9fe;color:#8b5cf6"><i class="fas fa-bullhorn"></i></div>
        <div class="form-section-title">İletişim İzinleri</div>
    </div>
    <div class="form-section-body">
        <?php $__currentLoopData = [
            ['email_marketing','E-posta Pazarlama','Kampanya e-postaları'],
            ['sms_marketing','SMS Pazarlama','Promosyon SMS\'leri'],
        ]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$name,$label,$desc]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <div class="toggle-row">
            <div class="toggle-info"><div class="tl"><?php echo e($label); ?></div><div class="td"><?php echo e($desc); ?></div></div>
            <label class="toggle-switch">
                <input type="hidden" name="<?php echo e($name); ?>" value="0">
                <input type="checkbox" name="<?php echo e($name); ?>" value="1"
                       <?php echo e(old($name, $customer->$name) ? 'checked' : ''); ?>>
                <span class="toggle-slider"></span>
            </label>
        </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>
</div>


<?php if($definitions->isNotEmpty()): ?>
<div class="form-card">
    <div class="form-section-header">
        <div class="form-section-icon" style="background:#f1f5f9;color:#475569"><i class="fas fa-plus-square"></i></div>
        <div class="form-section-title">Ek Bilgiler (Özel Alanlar)</div>
    </div>
    <div class="form-section-body">
        <div class="fg-2">
            <?php $__currentLoopData = $definitions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $def): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php
                    $val = old('custom_fields.'.$def->id, $customer->getCustomFieldValue($def->field_key));
                ?>
                <div class="field-group">
                    <label class="field-label">
                        <?php echo e($def->label); ?>

                        <?php if($def->is_required): ?> <span class="req">*</span> <?php endif; ?>
                    </label>

                    <?php if($def->field_type === 'select'): ?>
                        <select name="custom_fields[<?php echo e($def->id); ?>]" class="field-input <?php echo e($errors->has('custom_fields.'.$def->id) ? 'field-error' : ''); ?>">
                            <option value="">Seçiniz</option>
                            <?php $__currentLoopData = $def->options ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $opt): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($opt['value']); ?>" <?php echo e($val == $opt['value'] ? 'selected' : ''); ?>><?php echo e($opt['label']); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    <?php elseif($def->field_type === 'multiselect'): ?>
                        <?php
                            $selectedArr = is_array($val) ? $val : (json_decode($val, true) ?? []);
                        ?>
                        <select name="custom_fields[<?php echo e($def->id); ?>][]" class="field-input <?php echo e($errors->has('custom_fields.'.$def->id) ? 'field-error' : ''); ?>" multiple style="height:auto">
                            <?php $__currentLoopData = $def->options ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $opt): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($opt['value']); ?>" <?php echo e(in_array($opt['value'], $selectedArr) ? 'selected' : ''); ?>><?php echo e($opt['label']); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    <?php elseif($def->field_type === 'boolean'): ?>
                        <select name="custom_fields[<?php echo e($def->id); ?>]" class="field-input <?php echo e($errors->has('custom_fields.'.$def->id) ? 'field-error' : ''); ?>">
                            <option value="">Seçiniz</option>
                            <option value="1" <?php echo e($val == '1' ? 'selected' : ''); ?>>Evet</option>
                            <option value="0" <?php echo e($val == '0' ? 'selected' : ''); ?>>Hayır</option>
                        </select>
                    <?php elseif($def->field_type === 'textarea'): ?>
                        <textarea name="custom_fields[<?php echo e($def->id); ?>]" class="field-input <?php echo e($errors->has('custom_fields.'.$def->id) ? 'field-error' : ''); ?>" rows="3"><?php echo e($val); ?></textarea>
                    <?php elseif($def->field_type === 'date'): ?>
                        <input type="date" name="custom_fields[<?php echo e($def->id); ?>]" value="<?php echo e($val); ?>" class="field-input <?php echo e($errors->has('custom_fields.'.$def->id) ? 'field-error' : ''); ?>">
                    <?php elseif($def->field_type === 'number' || $def->field_type === 'decimal'): ?>
                        <input type="number" step="any" name="custom_fields[<?php echo e($def->id); ?>]" value="<?php echo e($val); ?>" class="field-input <?php echo e($errors->has('custom_fields.'.$def->id) ? 'field-error' : ''); ?>">
                    <?php else: ?>
                        <input type="text" name="custom_fields[<?php echo e($def->id); ?>]" value="<?php echo e($val); ?>" class="field-input <?php echo e($errors->has('custom_fields.'.$def->id) ? 'field-error' : ''); ?>">
                    <?php endif; ?>

                    <?php $__errorArgs = ['custom_fields.'.$def->id];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <div class="error-msg">Bu alan zorunludur.</div>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
    </div>
</div>
<?php endif; ?>

<div class="form-card">
    <div class="form-section-header">
        <div class="form-section-icon" style="background:#fef3c7;color:#f59e0b"><i class="fas fa-sticky-note"></i></div>
        <div class="form-section-title">Dahili Notlar</div>
    </div>
    <div class="form-section-body">
        <textarea name="internal_notes" class="field-input" rows="4"><?php echo e(old('internal_notes', $customer->internal_notes)); ?></textarea>
    </div>
</div>

<div class="form-footer">
    <a href="<?php echo e(route('agency.customers.show', $customer)); ?>" class="btn btn-outline-secondary" style="border-radius:10px">
        <i class="fas fa-times me-1"></i>İptal
    </a>
    <div class="d-flex gap-2">
        <a href="<?php echo e(route('agency.customers.field-values.edit', $customer)); ?>" class="btn btn-outline-secondary" style="border-radius:10px">
            <i class="fas fa-puzzle-piece me-1"></i>Özel Alanlar
        </a>
        <button type="submit" class="btn text-white" style="background:linear-gradient(135deg,#6366f1,#8b5cf6);border-radius:10px;padding:.65rem 2rem;font-weight:600">
            <i class="fas fa-check me-1"></i>Değişiklikleri Kaydet
        </button>
    </div>
</div>

</form>
</div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
document.querySelectorAll('.type-radio').forEach(r => {
    r.addEventListener('change', function() {
        document.getElementById('corporateFields').style.display =
            this.value === 'corporate' ? '' : 'none';
    });
});

// Dynamic Email List
const emailList = document.getElementById('emailList');
const btnAddEmail = document.getElementById('btnAddEmail');

btnAddEmail?.addEventListener('click', function() {
    const newItem = document.createElement('div');
    newItem.className = 'email-item';
    newItem.innerHTML = `
        <input type="email" name="emails[]" class="field-input" placeholder="ikincil@mail.com">
        <button type="button" class="btn-remove-email remove-email"><i class="fas fa-trash"></i></button>
    `;
    emailList.appendChild(newItem);
});

emailList?.addEventListener('click', function(e) {
    if (e.target.closest('.remove-email')) {
        e.target.closest('.email-item').remove();
    }
});

document.getElementById('customerForm').addEventListener('submit', function() {
    const btn = this.querySelector('button[type="submit"]');
    btn.disabled = true;
    btn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Güncelleniyor...';
});
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('agency.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\acente\resources\views/agency/customers/edit.blade.php ENDPATH**/ ?>