@extends('layouts.admin')

@section('content')

<div class="d-flex justify-content-between align-items-center mb-4">
    <h4 class="brand-font text-uppercase text-secondary mb-0">Customer Quotations</h4>
</div>

<div class="card border-0 shadow-sm rounded-4 bg-white mb-4 p-4">
    <div class="table-responsive">
        <table class="table table-hover align-middle mb-0">
            <thead class="table-light">
                <tr class="text-secondary small text-uppercase" style="font-size: 11px;">
                    <th scope="col">Date</th>
                    <th scope="col">Customer</th>
                    <th scope="col">Product</th>
                    <th scope="col">Notes</th>
                    <th scope="col">Status</th>
                    <th scope="col" class="text-end">Actions</th>
                </tr>
            </thead>
            <tbody>
                @forelse($quotations as $quote)
                    <tr>
                        <td class="small text-muted">{{ $quote->created_at->format('d M Y') }}</td>
                        <td>
                            <div class="fw-bold text-secondary">{{ $quote->name }}</div>
                            <div class="small text-muted">{{ $quote->phone }} | {{ $quote->email }}</div>
                        </td>
                        <td>
                            <a href="{{ route('marketplace.show', $quote->product->slug) }}" target="_blank" class="text-decoration-none fw-bold">
                                {{ $quote->product->name }}
                            </a>
                        </td>
                        <td class="small text-muted" style="max-width: 200px; white-space: normal;">
                            {{ $quote->notes ?? '-' }}
                        </td>
                        <td>
                            @if($quote->status === 'accepted')
                                <span class="badge bg-success bg-opacity-10 text-success rounded-pill px-3 py-1">Accepted</span>
                            @elseif($quote->status === 'rejected')
                                <span class="badge bg-danger bg-opacity-10 text-danger rounded-pill px-3 py-1">Rejected</span>
                            @elseif($quote->status === 'reviewed')
                                <span class="badge bg-info bg-opacity-10 text-info rounded-pill px-3 py-1">Reviewed</span>
                            @else
                                <span class="badge bg-warning bg-opacity-10 text-warning rounded-pill px-3 py-1">Pending</span>
                            @endif
                        </td>
                        <td class="text-end">
                            <div class="d-inline-flex gap-2 align-items-center">
                                <a href="{{ route('admin.quotations.show', $quote->id) }}" class="btn btn-sm btn-outline-primary rounded-circle admin-action-btn" title="View details">
                                    <i class="bi bi-eye"></i>
                                </a>
                                <form action="{{ route('admin.quotations.update_status', $quote->id) }}" method="POST" class="d-inline-flex gap-1">
                                    @csrf
                                    <select name="status" class="form-select form-select-sm rounded-pill" data-swal-status data-swal-title="Update quotation status?">
                                        <option value="pending" {{ $quote->status === 'pending' ? 'selected' : '' }}>Pending</option>
                                        <option value="reviewed" {{ $quote->status === 'reviewed' ? 'selected' : '' }}>Reviewed</option>
                                        <option value="accepted" {{ $quote->status === 'accepted' ? 'selected' : '' }}>Accepted</option>
                                        <option value="rejected" {{ $quote->status === 'rejected' ? 'selected' : '' }}>Rejected</option>
                                    </select>
                                </form>
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="6" class="text-center py-5">
                            <div class="text-muted fs-1 mb-3"><i class="bi bi-chat-left-dots"></i></div>
                            <h6 class="fw-bold text-secondary">No Quotations Found</h6>
                        </td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>

@endsection
