<h5 class="mb-4"><i class="fas fa-redo me-2"></i>{{ __('store.clientarea_domains_renew') }}</h5>

<div class="row mb-4">
    <div class="col-md-6">
        <label class="form-label text-muted">{{ __('store.clientarea_domains_current_expiry') }}</label>
        <div class="fw-bold">
            {{ $domain->expire_date->format($dateTimeFormat) }}
            @php
                $daysToExpiry = (int) now()->diffInDays($domain->expire_date, false);
            @endphp
            @if($daysToExpiry > 0 && $daysToExpiry <= 30)
                <br><small class="text-warning">{{ $daysToExpiry }} {{ __('store.clientarea_domains_days_to_expiry') }}</small>
            @elseif($daysToExpiry <= 0)
                <br><small class="text-danger">{{ __('store.clientarea_domains_expired') }}</small>
            @endif
        </div>
    </div>
    <div class="col-md-6">
        <label class="form-label text-muted">{{ __('store.clientarea_domains_auto_renew') }}</label>
        <div>
            @if($domain->auto_renew)
                <span class="badge bg-success">{{ __('store.common_enabled') }}</span>
            @else
                <span class="badge bg-secondary">{{ __('store.common_disabled') }}</span>
            @endif
        </div>
    </div>
</div>

<!-- Period Selection - populated from API -->
<div class="mb-4">
    <label class="form-label">{{ __('store.clientarea_domains_renewal_period') }}</label>
    <div id="periodOptions">
        <div class="text-center py-3">
            <span class="spinner-border spinner-border-sm me-2"></span>
            {{ __('store.common_loading') }}
        </div>
    </div>
</div>

<!-- Renewal Summary -->
<div class="mb-4 d-none" id="renewalSummary">
    <div class="card border-primary">
        <div class="card-body">
            <h6 class="card-title">{{ __('store.clientarea_domains_renewal_summary') }}</h6>
            <div class="row">
                <div class="col-6">
                    <small class="text-muted">{{ __('store.clientarea_domains_new_expiry_date') }}</small>
                    <div class="fw-bold" id="newExpiryDate">-</div>
                </div>
                <div class="col-6">
                    <small class="text-muted">{{ __('store.common_price') }}</small>
                    <div class="fw-bold text-primary" id="renewalPrice">-</div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Action Buttons -->
<div class="d-flex gap-2 justify-content-end">
    <a href="{{ route('store.auth.domains.manage', $domain->id) }}" class="btn btn-outline-secondary">
        {{ __('store.common_cancel') }}
    </a>
    <button type="button" class="btn btn-primary" id="addToCartBtn" disabled>
        <i class="fas fa-shopping-cart me-2"></i>{{ __('store.buttons_add_to_cart') }}
    </button>
</div>

<!-- Success state -->
<div class="d-none" id="successActions">
    <div class="alert alert-success mb-3">
        <i class="fas fa-check-circle me-2"></i>
        {{ __('store.clientarea_domains_renewal_added_to_cart') }}
    </div>
    <div class="d-flex gap-2 justify-content-center">
        <a href="{{ route('store.auth.domains.manage', $domain->id) }}" class="btn btn-outline-primary">
            <i class="fas fa-arrow-left me-2"></i>{{ __('store.clientarea_domains_management_tabs_overview') }}
        </a>
        <a href="{{ lroute('store.basket.index') }}" class="btn btn-primary">
            <i class="fas fa-shopping-cart me-2"></i>{{ __('store.clientarea_domains_go_to_cart') }}
        </a>
    </div>
</div>

<div class="mt-4">
    <div class="alert alert-info mb-0">
        <i class="fas fa-info-circle me-2"></i>
        <strong>{{ __('store.clientarea_domains_renewal_note_title') }}</strong><br>
        {{ __('store.clientarea_domains_renewal_note_text') }}
    </div>
</div>

@push('scripts')
<script>
window.domainRenewalConfig = {
    domainId: {{ $domain->id }},
    domainName: '{{ $domain->domain }}',
    csrfToken: '{{ csrf_token() }}',
    routes: {
        renewalOptions: '{{ route("api.store.domain.renewal-options", $domain->id) }}',
        basketAdd: '{{ route("api.store.basket.add") }}'
    },
    translations: {
        loading: '{{ __("store.common_loading") }}',
        error: '{{ __("store.common_error") }}',
        noOptions: '{{ __("store.clientarea_domains_no_renewal_options") }}',
        newExpiry: '{{ __("store.clientarea_domains_new_expiry") }}'
    }
};
</script>
@vite('resources/js/store/domain-renewal.js')
@endpush
