{{-- Commission Override Component --}}
<div id="commission-override-container">
    <div class="row">
        <div class="col-12">
            <ul class="nav nav-pills mb-3" id="commission-pills" role="tablist">
                <li class="nav-item" role="presentation">
                    <button class="nav-link active" id="products-commission-tab" data-bs-toggle="pill" data-bs-target="#products-commission" type="button" role="tab">
                        <i class="fas fa-box me-1"></i>{{ __('admin/client-groups.pricing_tab_products') }}
                    </button>
                </li>
                <li class="nav-item" role="presentation">
                    <button class="nav-link" id="tlds-commission-tab" data-bs-toggle="pill" data-bs-target="#tlds-commission" type="button" role="tab">
                        <i class="fas fa-globe me-1"></i>{{ __('admin/client-groups.pricing_tab_tlds') }}
                    </button>
                </li>
            </ul>
        </div>
    </div>

    <div class="tab-content" id="commission-pills-content">
        {{-- Products Commission Tab --}}
        <div class="tab-pane fade show active" id="products-commission" role="tabpanel">
            <div class="alert alert-info mb-3">
                <i class="fas fa-info-circle me-2"></i>
                {{ __('admin/client-groups.commission_override_help_products') }}
            </div>

            <div class="card border-0 shadow-sm">
                <div class="card-body p-0">
                    <div class="table-responsive">
                        <table class="table table-sm table-hover mb-0" id="products-commission-table">
                            <thead class="table-light">
                                <tr>
                                    <th>{{ __('admin/client-groups.pricing_product_name') }}</th>
                                    <th class="text-center">{{ __('admin/client-groups.field_commission_rate') }} (%)</th>
                                </tr>
                            </thead>
                            <tbody id="products-commission-body">
                                <tr class="text-center text-muted">
                                    <td colspan="2" class="py-4">
                                        <i class="fas fa-spinner fa-spin fa-2x mb-2"></i>
                                        <p class="mb-0">{{ __('admin/common.loading') }}</p>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        {{-- TLDs Commission Tab --}}
        <div class="tab-pane fade" id="tlds-commission" role="tabpanel">
            <div class="alert alert-info mb-3">
                <i class="fas fa-info-circle me-2"></i>
                {{ __('admin/client-groups.commission_override_help_tlds') }}
            </div>

            <div class="card border-0 shadow-sm">
                <div class="card-body p-0">
                    <div class="table-responsive">
                        <table class="table table-sm table-hover mb-0" id="tlds-commission-table">
                            <thead class="table-light">
                                <tr>
                                    <th>{{ __('admin/client-groups.pricing_tld') }}</th>
                                    <th class="text-center">{{ __('admin/client-groups.pricing_register') }} (%)</th>
                                    <th class="text-center">{{ __('admin/client-groups.pricing_transfer') }} (%)</th>
                                    <th class="text-center">{{ __('admin/client-groups.pricing_renewal') }} (%)</th>
                                </tr>
                            </thead>
                            <tbody id="tlds-commission-body">
                                <tr class="text-center text-muted">
                                    <td colspan="4" class="py-4">
                                        <i class="fas fa-spinner fa-spin fa-2x mb-2"></i>
                                        <p class="mb-0">{{ __('admin/common.loading') }}</p>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{{-- Hidden input to store commission rules JSON --}}
@php
    $commissionRulesValue = '{}';
    if (old('commission_rules')) {
        $commissionRulesValue = is_string(old('commission_rules')) ? old('commission_rules') : json_encode(old('commission_rules'));
    } elseif (isset($clientGroup) && $clientGroup->commission_rules) {
        $rules = $clientGroup->commission_rules;
        if (is_array($rules) && empty($rules)) {
            $commissionRulesValue = '{}';
        } else {
            $commissionRulesValue = json_encode($rules);
        }
    }
@endphp
<input type="hidden" id="commission_rules_data" name="commission_rules" value="{{ $commissionRulesValue }}">

<style>
#products-commission-table .commission-input {
    width: 80px;
    font-size: 0.75rem;
    padding: 0.25rem 0.4rem;
    text-align: center;
    display: inline-block;
}

#tlds-commission-table .commission-input {
    width: 70px;
    font-size: 0.75rem;
    padding: 0.25rem 0.4rem;
    text-align: center;
    display: inline-block;
}
</style>
