@extends('layouts.buyer')

@section('title', 'Quote Requests')

@section('buyer-content')
    <!-- Page Header -->
    <div class="page-header">
        <div>
            <h3 class="page-title">Quote Requests</h3>
            <p class="text-muted mb-0">Review and manage quotes from suppliers</p>
        </div>
        <a href="{{ route('post.requirement.index') }}" class="btn btn-primary-gradient shadow-sm">
            <i class="bi bi-plus-lg me-2"></i> Post Requirement
        </a>
    </div>

    <!-- Stats Cards -->
    <div class="row g-3 mb-4">
        <div class="col-xl-3 col-md-6">
            <div class="card h-100 border-0 shadow-sm rounded-4 overflow-hidden group-hover-lift">
                <div class="card-body p-4 position-relative">
                    <div class="position-absolute top-0 end-0 p-3" style="opacity: 0.1;">
                        <i class="bi bi-inbox display-1 text-primary"></i>
                    </div>
                    <div class="position-relative z-1">
                        <div class="d-flex align-items-center mb-3">
                            <div class="rounded-3 bg-primary bg-opacity-10 p-2 text-primary">
                                <i class="bi bi-inbox fs-4"></i>
                            </div>
                            <h6 class="ms-3 mb-0 text-muted fw-bold small text-uppercase spacing-1">Total Quotes</h6>
                        </div>
                        <h2 class="fw-bold mb-0 text-dark">{{ $stats['total'] }}</h2>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xl-3 col-md-6">
            <div class="card h-100 border-0 shadow-sm rounded-4 overflow-hidden group-hover-lift">
                <div class="card-body p-4 position-relative">
                    <div class="position-absolute top-0 end-0 p-3" style="opacity: 0.1;">
                        <i class="bi bi-hourglass-split display-1 text-warning"></i>
                    </div>
                    <div class="position-relative z-1">
                        <div class="d-flex align-items-center mb-3">
                            <div class="rounded-3 bg-warning bg-opacity-10 p-2 text-warning">
                                <i class="bi bi-hourglass-split fs-4"></i>
                            </div>
                            <h6 class="ms-3 mb-0 text-muted fw-bold small text-uppercase spacing-1">Pending Review</h6>
                        </div>
                        <h2 class="fw-bold mb-0 text-dark">{{ $stats['pending'] }}</h2>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xl-3 col-md-6">
            <div class="card h-100 border-0 shadow-sm rounded-4 overflow-hidden group-hover-lift">
                <div class="card-body p-4 position-relative">
                    <div class="position-absolute top-0 end-0 p-3" style="opacity: 0.1;">
                        <i class="bi bi-check-circle display-1 text-success"></i>
                    </div>
                    <div class="position-relative z-1">
                        <div class="d-flex align-items-center mb-3">
                            <div class="rounded-3 bg-success bg-opacity-10 p-2 text-success">
                                <i class="bi bi-check-circle fs-4"></i>
                            </div>
                            <h6 class="ms-3 mb-0 text-muted fw-bold small text-uppercase spacing-1">Accepted</h6>
                        </div>
                        <h2 class="fw-bold mb-0 text-dark">{{ $stats['accepted'] }}</h2>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xl-3 col-md-6">
            <div class="card h-100 border-0 shadow-sm rounded-4 overflow-hidden group-hover-lift">
                <div class="card-body p-4 position-relative">
                    <div class="position-absolute top-0 end-0 p-3" style="opacity: 0.1;">
                        <i class="bi bi-x-circle display-1 text-danger"></i>
                    </div>
                    <div class="position-relative z-1">
                        <div class="d-flex align-items-center mb-3">
                            <div class="rounded-3 bg-danger bg-opacity-10 p-2 text-danger">
                                <i class="bi bi-x-circle fs-4"></i>
                            </div>
                            <h6 class="ms-3 mb-0 text-muted fw-bold small text-uppercase spacing-1">Rejected</h6>
                        </div>
                        <h2 class="fw-bold mb-0 text-dark">{{ $stats['rejected'] }}</h2>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Quotes List -->
    <div class="card border-0 shadow-sm rounded-4 overflow-hidden">
        <div class="card-header bg-transparent py-3">
            <h6 class="fw-bold mb-0">
                <i class="bi bi-chat-quote me-2 text-primary"></i>All Received Quotes
            </h6>
        </div>
        
        <div class="card-body p-0">
            @forelse($quotes as $quote)
                <div class="p-4 border-bottom {{ $quote->status == 'pending' ? 'bg-warning-subtle bg-opacity-10' : ($quote->status == 'accepted' ? 'bg-success-subtle bg-opacity-10' : '') }}">
                    <div class="row align-items-center">
                        <div class="col-lg-4 mb-3 mb-lg-0">
                            <div class="d-flex align-items-center">
                                @if($quote->seller && $quote->seller->logo)
                                    <img src="{{ asset('storage/' . $quote->seller->logo) }}" class="rounded-circle me-3 shadow-sm" style="width: 50px; height: 50px; object-fit: cover;">
                                @else
                                    <div class="rounded-circle bg-primary bg-opacity-10 text-primary d-flex align-items-center justify-content-center me-3 fw-bold fs-4" style="width: 50px; height: 50px;">
                                        {{ strtoupper(substr($quote->seller->company_name ?? 'S', 0, 1)) }}
                                    </div>
                                @endif
                                <div>
                                    <h6 class="fw-bold mb-0 text-dark">{{ $quote->seller->company_name ?? 'Seller' }}</h6>
                                    <div class="text-muted small mt-1 text-truncate" style="max-width: 200px;">
                                        <i class="bi bi-clipboard me-1"></i>{{ $quote->rfq->title ?? 'N/A' }}
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-2 col-4 text-center">
                            <div class="fw-bold text-success fs-5">₹{{ number_format($quote->revised_price ?? $quote->price, 0) }}</div>
                            <small class="text-muted fw-medium text-uppercase" style="font-size: 0.7rem;">Quoted Price</small>
                        </div>
                        <div class="col-lg-2 col-4 text-center">
                            <div class="fw-medium text-dark">{{ $quote->delivery_timeline }}</div>
                            <small class="text-muted fw-medium text-uppercase" style="font-size: 0.7rem;">Delivery</small>
                        </div>
                        <div class="col-lg-2 col-4 text-center">
                            {!! $quote->status_badge !!}
                            <div class="small text-muted mt-1">{{ $quote->created_at->format('d M') }}</div>
                        </div>
                        <div class="col-lg-2 text-end mt-3 mt-lg-0">
                            <a href="{{ route('buyer.quotes.show', $quote) }}" class="btn btn-primary btn-sm rounded-pill shadow-sm px-3 fw-medium">
                                Review Quote <i class="bi bi-arrow-right ms-1"></i>
                            </a>
                        </div>
                    </div>
                </div>
            @empty
                <div class="text-center py-5">
                    <div class="rounded-circle bg-light d-inline-flex align-items-center justify-content-center mb-4" style="width: 80px; height: 80px;">
                        <i class="bi bi-inbox fs-1 text-muted opacity-50"></i>
                    </div>
                    <h5 class="fw-bold mb-2">No Quotes Received Yet</h5>
                    <p class="text-muted mb-4 opacity-75">Post a buying requirement to start receiving quotes from verified suppliers.</p>
                    <a href="{{ route('post.requirement.index') }}" class="btn btn-primary rounded-pill px-4 shadow-sm hover-lift">
                        <i class="bi bi-plus-lg me-1"></i> Post Your First Requirement
                    </a>
                </div>
            @endforelse

            @if($quotes->hasPages())
                <div class="p-3 bg-light border-top">
                    {{ $quotes->links() }}
                </div>
            @endif
        </div>
    </div>
@endsection
