{{-- Durum --}}
<div class="form-card">
    <div class="fsh">
        <div class="fsh-icon" style="background:#f1f5f9;color:#64748b"><i
                class="fas fa-cog"></i></div>
        <div class="fsh-title">Durum & Atama</div>
    </div>
    <div class="fsb">
        <div class="fl mb-3">
            <div class="fl mb-3"><label>Durum <span class="req">*</span></label>
            <select name="status" class="fi">
                @foreach([
                    'potential' => 'Potansiyel',
                    'offer_sent' => 'Teklif Verildi',
                    'revised' => 'Revize Edildi',
                    'confirmed' => 'Satış Tamamlandı',
                    'in_progress' => 'Devam Ediyor',
                    'completed' => 'Kapanan',
                    'cancelled' => 'İptal Edildi',
                    'refunded' => 'İade Edildi'
                ] as $v => $l)
                    <option value="{{ $v }}" {{ old('status', $sale->status) === $v ? 'selected' : '' }}>{{ $l }}
                </option>@endforeach
            </select>
        </div>
        <div class="fl mb-3">
            <label>Ödeme Durumu <span style="color:#ef4444">*</span></label>
            <select name="payment_status" class="field-input">
                @foreach(['unpaid' => 'Ödenmedi', 'partial' => 'Kısmi Ödendi', 'paid' => 'Ödendi', 'refunded' => 'İade'] as $v => $l)
                    <option value="{{ $v }}" {{ old('payment_status', $sale->payment_status) === $v ? 'selected' : '' }}>
                        {{ $l }}</option>
                @endforeach
            </select>
        </div>
        <div class="fl">
            <label>Atanan Temsilci</label>
            <select name="assigned_to" class="field-input">
                <option value="">— Seçin —</option>
                @foreach($agents as $a)
                    <option value="{{ $a->id }}" {{ old('assigned_to', $sale->assigned_to) == $a->id ? 'selected' : '' }}>
                        {{ $a->first_name }} {{ $a->last_name }}</option>
                @endforeach
            </select>
        </div>
    </div>
</div>

{{-- Müşteri Bilgileri --}}
<div class="form-card" id="customerDetailsCard" style="display:none; margin-bottom:1.5rem">
    <div class="fsh">
        <div class="fsh-icon" style="background:#ede9fe;color:#8b5cf6"><i class="fas fa-user-check"></i></div>
        <div class="fsh-title">Müşteri Bilgileri</div>
    </div>
    <div class="fsb" id="customerSummaryHtml" style="font-size: 0.82rem; color: #475569;">
    </div>
</div>

{{-- Fiyatlandırma --}}
<div class="form-card">
    <div class="fsh">
        <div class="fsh-icon" style="background:#d1fae5;color:#10b981"><i
                class="fas fa-lira-sign"></i></div>
        <div class="fsh-title">Fiyatlandırma</div>
    </div>
    <div class="fsb">
        <div class="fl mb-3">
            <label>Yetişkin Birim Fiyat</label>
            <input type="number" step="0.01" name="unit_price"
                value="{{ old('unit_price', $sale->unit_price) }}" class="field-input"
                id="unitPrice" oninput="calcPrice()">
        </div>
        <div class="fg-2 mb-3">
            <div class="fl">
                <label>Çocuk Fiyatı</label>
                <input type="number" step="0.01" name="child_price"
                    value="{{ old('child_price', $sale->child_price) }}"
                    class="field-input" id="childPrice" oninput="calcPrice()">
            </div>
            <div class="fl">
                <label>Bebek Fiyatı</label>
                <input type="number" step="0.01" name="infant_price"
                    value="{{ old('infant_price', $sale->infant_price) }}"
                    class="field-input" id="infantPrice" oninput="calcPrice()">
            </div>
        </div>
        <div class="fg-2 mb-3">
            <div class="fl">
                <label>İndirim (%)</label>
                <input type="number" step="0.01" name="discount_rate"
                    value="{{ old('discount_rate', $sale->discount_rate) }}"
                    class="field-input" id="discountRate" oninput="calcPrice()">
            </div>
            <div class="fl">
                <label>KDV (₺)</label>
                <input type="number" step="0.01" name="tax_amount"
                    value="{{ old('tax_amount', $sale->tax_amount) }}"
                    class="field-input" id="taxAmount" oninput="calcPrice()">
            </div>
        </div>
        <div class="fl mb-3">
            <label>Tahsil Edilen</label>
            <input type="number" step="0.01" name="paid_amount"
                value="{{ old('paid_amount', $sale->paid_amount) }}" class="field-input"
                id="paidAmount" oninput="calcPrice()">
        </div>

        <div class="price-panel">
            <div class="pr-row"><span>Ara Toplam</span><span
                    id="displaySubtotal">{{ number_format($sale->subtotal ?? 0, 2) }}</span>
            </div>
            <div class="pr-row" style="color:#fde68a"><span>İndirim</span><span
                    id="displayDiscount">-
                    {{ number_format($sale->discount_amount, 2) }}</span></div>
            <div class="pr-row"><span>KDV</span><span id="displayTax">+
                    {{ number_format($sale->tax_amount, 2) }}</span></div>
            <hr class="pr-div">
            <div class="pr-row pr-total"><span>Toplam</span><span
                    id="displayTotal">{{ number_format($sale->total_amount ?? 0, 2) }}
                    {{ $sale->currency }}</span></div>
            <div class="pr-row" style="color:#fda4af"><span>Kalan</span><span
                    id="displayRemaining">{{ number_format($sale->remaining_amount ?? 0, 2) }}</span>
            </div>

            <input type="hidden" name="total_amount" id="hiddenTotal"
                value="{{ $sale->total_amount }}">
            <input type="hidden" name="remaining_amount" id="hiddenRemaining"
                value="{{ $sale->remaining_amount }}">
            <input type="hidden" name="subtotal" id="hiddenSubtotal"
                value="{{ $sale->subtotal }}">
            <input type="hidden" name="discount_amount" id="hiddenDiscountAmt"
                value="{{ $sale->discount_amount }}">
        </div>

        <div class="fl mt-3">
            <label>Para Birimi</label>
            <select name="currency" class="field-input">
                <option value="TRY" {{ old('currency', $sale->currency) === 'TRY' ? 'selected' : '' }}>₺ TRY
                </option>
                <option value="USD" {{ old('currency', $sale->currency) === 'USD' ? 'selected' : '' }}>$ USD
                </option>
                <option value="EUR" {{ old('currency', $sale->currency) === 'EUR' ? 'selected' : '' }}>€ EUR
                </option>
            </select>
        </div>
    </div>
</div>
