@extends('dashboard')
@section('title', 'OMS Clients')
@section('page_content')
<div class="container-fluid py-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h4>OMS Clients</h4>
        <a href="{{ route('oms_clients.create') }}" class="btn btn-primary btn-sm">Add New Client</a>
    </div>

    @if(session('success'))
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            {{ session('success') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    @endif

    <div class="card shadow-sm">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover table-striped mb-0 align-middle">
                    <thead class="">
                        <tr>
                            <th>তারিখ</th>
                            <th>ভোক্তার তথ্য</th>
                            <th>NID</th>
                            <th>ডিলার তথ্য</th>
                            <th>পণ্য</th>
                            <th class="text-end">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($clients as $client)
                        <tr>
                            <td>{{ \Carbon\Carbon::parse($client->date)->format('d-m-Y') }}</td>
                            <td>
                                <strong>{{ $client->client_name }}</strong><br>
                                <small >পিতা/স্বামী: {{ $client->guardian_name }}</small><br>
                                <small >ঠিকানা: {{ $client->address ?? 'N/A' }}</small>
                            </td>
                            <td>
                                <span>NID: {{ $client->nid_number }}</span><br>
                                <small class="text-muted">Mob: {{ $client->mobile_number ?? 'N/A' }}</small>
                            </td>
                            <td>
                                <strong>{{ $client->dealer->dealer_name ?? 'N/A' }}</strong><br>
                                <small >বিক্রয় কেন্দ্র: {{ $client->sale_point }} (W-{{ $client->word_no }})</small>
                            </td>
                            <td><span class="badge bg-info text-dark">{{ $client->product_name ?? 'N/A' }}</span></td>
                            <td class="text-end">
                                <a href="{{ route('oms_clients.print', $client->id) }}" target="_blank" class="btn btn-sm btn-dark">Print QR</a>
                                <a href="{{ route('oms_clients.edit', $client->id) }}" class="btn btn-sm btn-warning text-white">Edit</a>
                                <form action="{{ route('oms_clients.destroy', $client->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Are you sure?');">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="btn btn-sm btn-danger">Delete</button>
                                </form>
                            </td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="6" class="text-center text-muted py-4">No clients found.</td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
@endsection