<?php $__env->startSection('title','Payment Management'); ?>
<?php $__env->startSection('subtitle','Configure client convenience fees and Desxpert platform earnings.'); ?>
<?php $__env->startSection('content'); ?>
<div class="payment-metrics">
    <article>
        <span>
            <i data-lucide="circle-dollar-sign"></i>
        </span>
        <div>
            <small>GROSS CONSULTATION VALUE</small>
            <strong>₱<?php echo e(number_format($stats['gross_consultations'],2)); ?></strong>
            <p><?php echo e(number_format($stats['paid_transactions'])); ?> paid transactions</p>
        </div>
    </article>
    <article>
        <span>
            <i data-lucide="credit-card"></i>
        </span>
        <div>
            <small>CONVENIENCE FEES COLLECTED</small>
            <strong>₱<?php echo e(number_format($stats['convenience_fees'],2)); ?></strong>
            <p>Added to the client's checkout</p>
        </div>
    </article>
    <article class="fee-highlight">
        <span>
            <i data-lucide="landmark"></i>
        </span>
        <div>
            <small>DESXPERT FEES EARNED</small>
            <strong>₱<?php echo e(number_format($stats['platform_fees'],2)); ?></strong>
            <p>Deducted from professional earnings</p>
        </div>
    </article>
    <article>
        <span>
            <i data-lucide="hand-coins"></i>
        </span>
        <div>
            <small>PROFESSIONAL NET VALUE</small>
            <strong>₱<?php echo e(number_format($stats['professional_net'],2)); ?></strong>
            <p>Before payout release</p>
        </div>
    </article>
</div>
<div class="payment-settings-grid">
    <form class="fee-settings-card" method="post" action="<?php echo e(route('payments.settings.update')); ?>"><?php echo csrf_field(); ?> <?php echo method_field('put'); ?> <div class="fee-card-head">
            <div>
                <span>FEE CONFIGURATION</span>
                <h2>Payment Settings</h2>
                <p>These rates apply when a new Maya checkout is created.</p>
            </div>
            <i data-lucide="settings-2"></i>
        </div>
        <label class="fee-status">
            <input type="hidden" name="is_active" value="0">
            <input type="checkbox" name="is_active" value="1" <?php if(old('is_active',$setting->is_active)): echo 'checked'; endif; ?>> <span></span>
            <div>
                <b>Enable payment fees</b>
                <small>Turn off to charge only the professional consultation amount.</small>
            </div>
        </label>
        <div class="fee-field-group">
            <div>
                <label for="convenience-type">Convenience fee type</label>
                <select id="convenience-type" name="convenience_fee_type">
                    <option value="percentage" <?php if(old('convenience_fee_type',$setting->convenience_fee_type)==='percentage'): echo 'selected'; endif; ?>>Percentage</option>
                    <option value="fixed" <?php if(old('convenience_fee_type',$setting->convenience_fee_type)==='fixed'): echo 'selected'; endif; ?>>Fixed amount</option>
                </select>
            </div>
            <div>
                <label for="convenience-value">Convenience fee</label>
                <div class="fee-value-input">
                    <span id="convenience-symbol">%</span>
                    <input id="convenience-value" type="number" name="convenience_fee_value" value="<?php echo e(old('convenience_fee_value',$setting->convenience_fee_value)); ?>" min="0" step="0.01" required>
                </div>
                <small>Paid by the client in addition to the consultation fee.</small>
            </div>
        </div>
        <div class="desxpert-fee-field">
            <label for="platform-fee">Desxpert fee</label>
            <div class="fee-value-input">
                <span>%</span>
                <input id="platform-fee" type="number" name="platform_fee_percentage" value="<?php echo e(old('platform_fee_percentage',$setting->platform_fee_percentage)); ?>" min="0" max="100" step="0.01" required>
            </div>
            <small>Deducted from the professional's consultation fee when calculating their payout.</small>
        </div>
        <div class="fee-policy">
            <i data-lucide="info"></i>
            <p>Changing these rates does not recalculate existing paid bookings. Their original fee snapshot remains unchanged for accurate payout records.</p>
        </div>
        <button class="save-fees">
            <i data-lucide="save"></i>Save Payment Settings </button>
    </form>
    <section class="fee-preview-card">
        <div class="fee-card-head">
            <div>
                <span>LIVE PREVIEW</span>
                <h2>Checkout Breakdown</h2>
                <p>Enter any consultation fee to preview the complete payment split.</p>
            </div>
            <i data-lucide="calculator"></i>
        </div>
        <label class="preview-amount-field" for="preview-consultation">
            <span>Consultation fee</span>
            <div>
                <b>₱</b>
                <input id="preview-consultation" type="number" value="1000" min="0" step="0.01" inputmode="decimal" aria-describedby="preview-amount-help">
            </div>
            <small id="preview-amount-help">Preview only — this does not change professional booking rates.</small>
        </label>
        <div class="preview-base">
            <span>Consultation fee</span>
            <strong id="preview-gross">₱1,000.00</strong>
        </div>
        <div class="preview-lines">
            <div>
                <span>Client convenience fee</span>
                <strong id="preview-convenience">₱0.00</strong>
            </div>
            <div class="preview-total">
                <span>Client pays</span>
                <strong id="preview-client">₱1,000.00</strong>
            </div>
        </div>
        <div class="preview-divider">
            <span>Professional settlement</span>
        </div>
        <div class="preview-lines">
            <div>
                <span>Gross consultation fee</span>
                <strong id="preview-settlement-gross">₱1,000.00</strong>
            </div>
            <div>
                <span>Desxpert fee</span>
                <strong class="deduction" id="preview-platform">−₱0.00</strong>
            </div>
            <div class="preview-net">
                <span>Professional receives</span>
                <strong id="preview-net">₱1,000.00</strong>
            </div>
        </div>
        <div class="revenue-explainer">
            <span>
                <i data-lucide="building-2"></i>
            </span>
            <div>
                <small>DESXPERT REVENUE ON THIS EXAMPLE</small>
                <strong id="preview-revenue">₱0.00</strong>
                <p>Convenience fee + Desxpert fee</p>
            </div>
        </div>
    </section>
</div>
<section class="payout-panel payment-history">
    <div class="payout-panel-head">
        <div>
            <h2>Recent Paid Transactions</h2>
            <p>Fee snapshots from successful payment records.</p>
        </div>
        <span><?php echo e(number_format($stats['paid_transactions'])); ?> paid</span>
    </div>
    <div class="table-scroll">
        <table class="payout-table">
            <thead>
                <tr>
                    <th>Reference</th>
                    <th>Client</th>
                    <th>Professional</th>
                    <th>Consultation</th>
                    <th>Convenience</th>
                    <th>Desxpert Fee</th>
                    <th class="amount-column">Client Paid</th>
                </tr>
            </thead>
            <tbody><?php $__empty_1 = true; $__currentLoopData = $payments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><?php ($booking=$payment->booking); ?> <tr>
                    <td>
                        <b><?php echo e($payment->reference_id?Illuminate\Support\Str::limit($payment->reference_id,18):'PAY-'.$payment->id); ?></b>
                        <small><?php echo e($payment->created_at?->format('M d, Y g:i A')); ?></small>
                    </td>
                    <td><?php echo e($booking?->client?->profile?->full_name??'Client'); ?></td>
                    <td><?php echo e($booking?->professional?->user?->profile?->full_name??'Professional'); ?></td>
                    <td>₱<?php echo e(number_format($booking?->amount??0,2)); ?></td>
                    <td>₱<?php echo e(number_format($booking?->convenience_fee_amount??0,2)); ?></td>
                    <td>₱<?php echo e(number_format($booking?->platform_fee_amount??0,2)); ?>

                        <small><?php echo e($booking?->platform_fee_percentage!==null?number_format($booking->platform_fee_percentage,2).'%':'Legacy payment'); ?></small>
                    </td>
                    <td class="amount-column">
                        <b>₱<?php echo e(number_format($payment->amount,2)); ?></b>
                    </td>
                </tr><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?> <tr>
                    <td colspan="7" class="empty">No successful payment transactions are available.</td>
                </tr><?php endif; ?> </tbody>
        </table>
    </div>
    <div class="table-footer">
        <span>Showing <?php echo e($payments->firstItem()??0); ?> to <?php echo e($payments->lastItem()??0); ?> of <?php echo e(number_format($payments->total())); ?> paid transactions</span><?php echo e($payments->onEachSide(1)->links('vendor.pagination.default')); ?>

    </div>
</section>
<script>
    (() => {
        const type = document.getElementById('convenience-type');
        const value = document.getElementById('convenience-value');
        const platform = document.getElementById('platform-fee');
        const active = document.querySelector('.fee-status input[type=checkbox]');
        const consultation = document.getElementById('preview-consultation');
        const money = amount => new Intl.NumberFormat('en-PH', {
            style: 'currency',
            currency: 'PHP'
        }).format(amount);
        const update = () => {
            const enabled = active?.checked;
            const gross = Math.max(0, Number(consultation.value || 0));
            const convenience = enabled ? (type.value === 'fixed' ? Number(value.value || 0) : gross * Number(value.value || 0) / 100) : 0;
            const platformFee = enabled ? gross * Number(platform.value || 0) / 100 : 0;
            document.getElementById('convenience-symbol').textContent = type.value === 'fixed' ? '₱' : '%';
            document.getElementById('preview-gross').textContent = money(gross);
            document.getElementById('preview-settlement-gross').textContent = money(gross);
            document.getElementById('preview-convenience').textContent = money(convenience);
            document.getElementById('preview-client').textContent = money(gross + convenience);
            document.getElementById('preview-platform').textContent = '−' + money(platformFee);
            document.getElementById('preview-net').textContent = money(Math.max(0, gross - platformFee));
            document.getElementById('preview-revenue').textContent = money(convenience + platformFee);
        };
        [type, value, platform, active, consultation].forEach(element => element?.addEventListener('input', update));
        update();
    })();
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/html/dev/desxpert-admin/resources/views/admin/payment-management.blade.php ENDPATH**/ ?>