
<?php
    use Illuminate\Support\Str;
?>

<section class="pfx-sec pfx-bpsec">
    <div class="pfx-sec-h">
        <i class="fas fa-file-invoice-dollar"></i>
        <span>Fatura Muhatabı</span>
        <button type="button" class="pfx-secopy" data-a="copy-sec" title="Seçili muhatabı kopyala">
            <i class="fas fa-copy"></i>
        </button>
    </div>

    <?php if(count($billingProfiles) > 1): ?>
        <div class="pfx-bptabs" role="tablist">
            <?php $__currentLoopData = $billingProfiles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $bp): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <button type="button" class="pfx-bptab <?php echo e($i === 0 ? 'on' : ''); ?>"
                        data-a="bp-tab" data-bp="<?php echo e($i); ?>" role="tab"
                        title="<?php echo e($bp['label']); ?> — <?php echo e($bp['sub']); ?>">
                    <i class="fas <?php echo e($bp['type'] === 'company' ? 'fa-building' : 'fa-id-card'); ?>"></i>
                    <span><?php echo e($bp['type'] === 'company' ? Str::limit($bp['label'], 18) : 'Şahıs'); ?></span>
                    <?php if(! $bp['complete']): ?><b class="pfx-bpdot" title="Vergi / kimlik numarası eksik"></b><?php endif; ?>
                </button>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
    <?php endif; ?>

    <?php $__currentLoopData = $billingProfiles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $bp): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <?php
            $b = $bp['billing'];
            $isCompanyProfile = $bp['type'] === 'company';
            $target = $isCompanyProfile && $bp['company_id']
                ? \App\Models\Customer\Customer::find($bp['company_id'])
                : $customer;
            $targetUrl = $target ? route('agency.customers.update-field', $target) : null;

            // Şahıs profilinde vergi bilgisi yoktur; T.C. kimlik numarası kullanılır.
            $bpRows = $isCompanyProfile
                ? [
                    ['label' => 'Unvan', 'field' => 'company_name', 'value' => $target?->company_name ?: $b['company_name']],
                    ['label' => 'Vergi No', 'field' => 'billing_tax_number', 'value' => $b['tax_number'], 'mono' => true, 'ph' => '10 hane'],
                    ['label' => 'Vergi Dairesi', 'field' => 'billing_tax_office', 'value' => $b['tax_office']],
                    ['label' => 'Adres', 'field' => 'billing_address', 'value' => $b['address'], 'type' => 'textarea'],
                    ['label' => 'E-posta', 'field' => 'billing_email', 'value' => $b['email'], 'type' => 'email'],
                    ['label' => 'Telefon', 'field' => 'phone', 'value' => $b['phone'], 'mono' => true],
                  ]
                : [
                    ['label' => 'Unvan', 'field' => null, 'value' => $b['name']],
                    ['label' => 'T.C. Kimlik No', 'field' => 'national_id', 'value' => $b['tax_number'], 'mono' => true, 'ph' => '11 hane'],
                    ['label' => 'Adres', 'field' => 'billing_address', 'value' => $b['address'], 'type' => 'textarea'],
                    ['label' => 'E-posta', 'field' => 'billing_email', 'value' => $b['email'], 'type' => 'email'],
                    ['label' => 'Telefon', 'field' => 'phone', 'value' => $b['phone'], 'mono' => true],
                  ];

            $block = trim(implode("\n", array_filter(array_map(
                fn ($r) => filled($r['value']) ? $r['label'] . ': ' . $r['value'] : null,
                $bpRows
            ))));
        ?>

        <div class="pfx-bppanel <?php echo e($i === 0 ? 'on' : ''); ?>" data-bp-panel="<?php echo e($i); ?>" role="tabpanel">
            <?php if(! $bp['complete']): ?>
                <div class="pfx-bpwarn">
                    <i class="fas fa-triangle-exclamation"></i>
                    <?php echo e($isCompanyProfile ? 'Vergi numarası girilmeden bu unvana resmi fatura kesilemez.' : 'T.C. kimlik numarası girilmemiş.'); ?>

                </div>
            <?php endif; ?>

            <?php $__currentLoopData = $bpRows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bpRow): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php echo $__env->make('components.quick-view.ledger-row', [
                    'r' => $bpRow + ['url' => $targetUrl, 'text' => trim((string) $bpRow['value'])],
                ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

            <div class="pfx-bpfoot">
                <span><?php echo e($bp['sub']); ?></span>
                <button type="button" class="pfx-chip" data-a="copy-block" data-copy-block="<?php echo e($block); ?>">
                    <i class="fas fa-clone"></i> Fatura bilgisini kopyala
                </button>
            </div>
        </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</section>
<?php /**PATH C:\xampp\htdocs\acente\resources\views/agency/customers/partials/qv-billing.blade.php ENDPATH**/ ?>