{{-- admin/pages/enquiries/index.blade.php --}}
@extends('admin.layouts.app')
@section('title','Enquiries')
@section('page-title','Enquiries')
@section('content')

<div class="d-flex justify-content-between align-items-center mb-3">
    <div style="font-size:.82rem;color:#64748b">{{ $enquiries->total() }} total enquiries</div>
    <div class="d-flex gap-2">
        <select class="form-select form-select-sm" onchange="location='?status='+this.value" style="width:auto">
            <option value="">All Status</option>
            <option value="new" {{ request('status')=='new'?'selected':'' }}>New</option>
            <option value="read" {{ request('status')=='read'?'selected':'' }}>Read</option>
            <option value="replied" {{ request('status')=='replied'?'selected':'' }}>Replied</option>
        </select>
    </div>
</div>

<div class="card-admin">
    <table class="table table-hover mb-0">
        <thead>
            <tr>
                <th>#</th>
                <th>Name / Email</th>
                <th>Type</th>
                <th>Product</th>
                <th>Date</th>
                <th>Status</th>
                <th style="width:100px">Actions</th>
            </tr>
        </thead>
        <tbody>
            @forelse($enquiries as $enq)
            <tr class="{{ $enq->status == 'new' ? 'fw-600' : '' }}">
                <td class="text-muted">{{ $enq->id }}</td>
                <td>
                    <div style="color:#0f172a">{{ $enq->name }}</div>
                    <div style="font-size:.74rem;color:#94a3b8">{{ $enq->email }}</div>
                    @if($enq->company)<div style="font-size:.74rem;color:#94a3b8">{{ $enq->company }}</div>@endif
                </td>
                <td><span class="badge" style="background:#eff6ff;color:#1e40af;font-size:.7rem">{{ ucfirst(str_replace('_',' ',$enq->enquiry_type)) }}</span></td>
                <td style="font-size:.78rem;color:#64748b">{{ $enq->product->name ?? '—' }}</td>
                <td style="font-size:.78rem;color:#64748b">{{ $enq->created_at->format('d M Y') }}</td>
                <td>
                    <span class="badge" style="font-size:.7rem;
                        background: {{ $enq->status=='new' ? '#fef9c3' : ($enq->status=='replied' ? '#f0fdf4' : '#f1f5f9') }};
                        color: {{ $enq->status=='new' ? '#854d0e' : ($enq->status=='replied' ? '#166534' : '#374151') }}">
                        {{ ucfirst($enq->status) }}
                    </span>
                </td>
                <td>
                    <div class="d-flex gap-1">
                        <a href="{{ route('admin.enquiries.show', $enq->id) }}" class="btn btn-sm" style="background:#eff6ff;color:#1d4ed8;border:none" title="View"><i class="bi bi-eye"></i></a>
                        <form method="POST" action="{{ route('admin.enquiries.destroy', $enq->id) }}" onsubmit="return confirm('Delete?')">@csrf @method('DELETE')
                            <button class="btn btn-sm" style="background:#fee2e2;color:#991b1b;border:none"><i class="bi bi-trash"></i></button>
                        </form>
                    </div>
                </td>
            </tr>
            @empty
            <tr><td colspan="7" class="text-center py-4 text-muted">No enquiries yet.</td></tr>
            @endforelse
        </tbody>
    </table>
    @if($enquiries->hasPages())
    <div class="p-3 border-top">{{ $enquiries->links() }}</div>
    @endif
</div>
@endsection
