{{-- Pricing Override Component --}}
<div id="pricing-override-container">
    <div class="row">
        <div class="col-12">
            <ul class="nav nav-pills mb-3" id="pricing-pills" role="tablist">
                <li class="nav-item" role="presentation">
                    <button class="nav-link active" id="products-pricing-tab" data-bs-toggle="pill" data-bs-target="#products-pricing" 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-pricing-tab" data-bs-toggle="pill" data-bs-target="#tlds-pricing" 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="pricing-pills-content">
        {{-- Products Pricing Tab --}}
        <div class="tab-pane fade show active" id="products-pricing" role="tabpanel">
            <div class="alert alert-info mb-3">
                <i class="fas fa-info-circle me-2"></i>
                {{ __('admin/client-groups.pricing_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-pricing-table">
                            <thead class="table-light">
                                <tr>
                                    <th>{{ __('admin/client-groups.pricing_product_name') }}</th>
                                    <th class="text-center" >1{{ __('admin/client-groups.pricing_month_short') }}</th>
                                    <th class="text-center" >3{{ __('admin/client-groups.pricing_month_short') }}</th>
                                    <th class="text-center" >6{{ __('admin/client-groups.pricing_month_short') }}</th>
                                    <th class="text-center" >12{{ __('admin/client-groups.pricing_month_short') }}</th>
                                    <th class="text-center" >24{{ __('admin/client-groups.pricing_month_short') }}</th>
                                    <th class="text-center" >36{{ __('admin/client-groups.pricing_month_short') }}</th>
                                </tr>
                            </thead>
                            <tbody id="products-pricing-body">
                                <tr class="text-center text-muted">
                                    <td colspan="7" 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 Pricing Tab --}}
        <div class="tab-pane fade" id="tlds-pricing" role="tabpanel">
            <div class="alert alert-info mb-3">
                <i class="fas fa-info-circle me-2"></i>
                {{ __('admin/client-groups.pricing_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-pricing-table">
                            <thead class="table-light">
                                <tr>
                                    <th style="width: 8%">{{ __('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-pricing-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 pricing overrides JSON --}}
@php
    $pricingOverridesValue = '{}';
    if (old('pricing_overrides')) {
        $pricingOverridesValue = old('pricing_overrides');
    } elseif (isset($clientGroup) && $clientGroup->pricing_overrides) {
        $overrides = $clientGroup->pricing_overrides;
        // Ensure it's an object, not an array
        if (is_array($overrides) && empty($overrides)) {
            $pricingOverridesValue = '{}';
        } else {
            $pricingOverridesValue = json_encode($overrides);
        }
    }
@endphp
<input type="hidden" id="pricing_overrides_data" name="pricing_overrides" value="{{ $pricingOverridesValue }}">

<style>
/* Product pricing table - period columns */
.period-input-cell {
    max-width: 90px;
    margin: 0 auto;
}

.period-input-cell input {
    font-size: 0.75rem;
    padding: 0.25rem 0.4rem;
    text-align: center;
    width: 50px;
}

.period-input-cell .input-group-text {
    font-size: 0.7rem;
    padding: 0.25rem 0.35rem;
}

/* TLD pricing - inline groups */
.pricing-input-group {
    display: inline-block;
    margin: 3px;
    vertical-align: top;
}

.pricing-input-group .input-group {
    width: auto;
}

.pricing-input-group .input-group-text {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    min-width: 35px;
}

.pricing-input-group input {
    width: 55px;
    font-size: 0.75rem;
    padding: 0.25rem 0.4rem;
    text-align: center;
}

.action-section {
    padding: 8px;
    border-bottom: 1px solid #dee2e6;
}

.action-section:last-child {
    border-bottom: none;
}

/* Products table styling */
#products-pricing-table th {
    font-size: 0.8rem;
    white-space: nowrap;
}

#products-pricing-table td {
    vertical-align: middle;
}
</style>
