{{-- Subscription Usage Widget --}}
@php
    $stats = Auth::user()->seller->getUsageStats();
@endphp

<div class="card border-0 shadow-sm mb-4">
    <div class="card-header bg-gradient-primary text-white py-3 d-flex justify-content-between align-items-center" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">
        <div>
            <h6 class="mb-0 fw-bold text-white">
                <i class="bi bi-speedometer2 me-2"></i>Plan Usage
            </h6>
            <small class="opacity-75">{{ $stats['plan_name'] }} Plan</small>
        </div>
        @if($stats['is_subscribed'])
            <span class="badge bg-white text-primary fw-bold px-3 py-2">
                <i class="bi bi-clock me-1"></i>{{ $stats['days_remaining'] }} days left
            </span>
        @else
            <a href="{{ route('seller.subscription.index') }}" class="btn btn-sm btn-warning fw-bold">
                <i class="bi bi-arrow-up-circle me-1"></i>Upgrade
            </a>
        @endif
    </div>
    <div class="card-body p-4">
        <div class="row g-4">
            {{-- Products --}}
            <div class="col-md-6 col-lg-3">
                <div class="d-flex align-items-center">
                    <div class="rounded-circle bg-primary bg-opacity-10 p-3 me-3">
                        <i class="bi bi-box-seam text-primary fs-4"></i>
                    </div>
                    <div class="flex-grow-1">
                        <small class="text-muted d-block">Products</small>
                        <span class="fw-bold fs-5">{{ $stats['products']['used'] }}/{{ $stats['products']['limit'] }}</span>
                        @php $productPercent = $stats['products']['limit'] > 0 ? ($stats['products']['used'] / $stats['products']['limit']) * 100 : 0; @endphp
                        <div class="progress mt-1" style="height: 4px;">
                            <div class="progress-bar {{ $productPercent >= 90 ? 'bg-danger' : ($productPercent >= 70 ? 'bg-warning' : 'bg-primary') }}" style="width: {{ min($productPercent, 100) }}%"></div>
                        </div>
                    </div>
                </div>
            </div>

            {{-- Inquiries --}}
            <div class="col-md-6 col-lg-3">
                <div class="d-flex align-items-center">
                    <div class="rounded-circle bg-success bg-opacity-10 p-3 me-3">
                        <i class="bi bi-envelope text-success fs-4"></i>
                    </div>
                    <div class="flex-grow-1">
                        <small class="text-muted d-block">Inquiries (Monthly)</small>
                        <span class="fw-bold fs-5">{{ $stats['inquiries']['sent'] }}/{{ $stats['inquiries']['limit'] }}</span>
                        @php $inquiryPercent = $stats['inquiries']['limit'] > 0 ? ($stats['inquiries']['sent'] / $stats['inquiries']['limit']) * 100 : 0; @endphp
                        <div class="progress mt-1" style="height: 4px;">
                            <div class="progress-bar bg-success {{ $inquiryPercent >= 90 ? 'bg-danger' : '' }}" style="width: {{ min($inquiryPercent, 100) }}%"></div>
                        </div>
                    </div>
                </div>
            </div>

            {{-- Banners --}}
            <div class="col-md-6 col-lg-3">
                <div class="d-flex align-items-center">
                    <div class="rounded-circle bg-info bg-opacity-10 p-3 me-3">
                        <i class="bi bi-image text-info fs-4"></i>
                    </div>
                    <div class="flex-grow-1">
                        <small class="text-muted d-block">Banners</small>
                        @if($stats['banners']['limit'] > 0)
                            <span class="fw-bold fs-5">{{ $stats['banners']['used'] }}/{{ $stats['banners']['limit'] }}</span>
                        @else
                            <span class="text-muted small"><i class="bi bi-lock me-1"></i>Upgrade to unlock</span>
                        @endif
                    </div>
                </div>
            </div>

            {{-- Custom Pages --}}
            <div class="col-md-6 col-lg-3">
                <div class="d-flex align-items-center">
                    <div class="rounded-circle bg-warning bg-opacity-10 p-3 me-3">
                        <i class="bi bi-file-earmark-text text-warning fs-4"></i>
                    </div>
                    <div class="flex-grow-1">
                        <small class="text-muted d-block">Custom Pages</small>
                        @if($stats['pages']['limit'] > 0)
                            <span class="fw-bold fs-5">{{ $stats['pages']['used'] }}/{{ $stats['pages']['limit'] }}</span>
                        @else
                            <span class="text-muted small"><i class="bi bi-lock me-1"></i>Upgrade to unlock</span>
                        @endif
                    </div>
                </div>
            </div>
        </div>

        {{-- Feature Badges --}}
        <div class="mt-4 pt-3 border-top">
            <small class="text-muted d-block mb-2">Active Features:</small>
            <div class="d-flex flex-wrap gap-2">
                @if($stats['features']['show_contact'])
                    <span class="badge bg-success-subtle text-success border border-success px-3 py-2"><i class="bi bi-telephone me-1"></i>Contact Visible</span>
                @endif
                @if($stats['features']['view_buyer_contact'])
                    <span class="badge bg-primary-subtle text-primary border border-primary px-3 py-2"><i class="bi bi-person-lines-fill me-1"></i>View Buyer Contact</span>
                @endif
                @if($stats['features']['has_verified_badge'])
                    <span class="badge bg-info-subtle text-info border border-info px-3 py-2"><i class="bi bi-patch-check-fill me-1"></i>KYC Verified</span>
                @endif
                @if($stats['features']['has_certificates'])
                    <span class="badge bg-warning-subtle text-warning border border-warning px-3 py-2"><i class="bi bi-award me-1"></i>Certificates</span>
                @endif
                @if($stats['features']['allow_microsite'])
                    <span class="badge bg-dark text-white px-3 py-2"><i class="bi bi-globe me-1"></i>Microsite</span>
                @endif
                @if(!$stats['is_subscribed'])
                    <span class="badge bg-secondary px-3 py-2"><i class="bi bi-info-circle me-1"></i>Free Plan - Limited Features</span>
                @endif
            </div>
        </div>
    </div>
</div>
