@extends('admin.masterAdmin')

@section('content')
    <div class="card">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h5 class="mb-0">Doctors</h5>
            <a href="{{ route('doctor.create') }}" class="btn btn-sm btn-primary">
                <i class="fa fa-plus-circle mr-1"></i> Add Doctor
            </a>
        </div>

        <div class="card-body">
            {{-- Flash Messages --}}
            @include('components.alert')

            {{-- Doctors Table --}}
            <div class="table-responsive">
                <table class="table table-bordered w-100" id="dt-responsive">
                    <thead class="thead-light">
                        <tr>
                            <th>SL</th>
                            <th>Date</th>
                            <th>Name</th>
                            <th>Designation</th>
                            <th>Description</th>
                            <th>Image</th>
                            <th style="width: 110px;">Action</th>
                        </tr>
                    </thead>

                    <tbody>
                        @forelse ($doctors as $doctor)
                            <tr>
                                <td>{{ $loop->iteration }}</td>
                                <td>{{ $doctor->created_at->format('Y-m-d') }}</td>
                                <td>{{ $doctor->name }}</td>
                                <td>{{ $doctor->designation }}</td>
                                <td>{{ Str::limit($doctor->desc, 50) }}</td>
                                <td>
                                    @if ($doctor->image && file_exists(public_path($doctor->image)))
                                        <img src="{{ asset($doctor->image) }}" width="80" alt="Doctor Image">
                                    @else
                                        <img src="{{ asset('images/no-image.png') }}" width="80" alt="No Image">
                                    @endif
                                </td>
                                <td>
                                    <a href="{{ route('doctor.edit', $doctor->id) }}" class="btn btn-sm btn-primary">
                                        <i class="fa fa-edit"></i>
                                    </a>
                                    <form action="{{ route('doctor.destroy', $doctor->id) }}" method="POST"
                                        class="d-inline-block"
                                        onsubmit="return confirm('Are you sure you want to delete this doctor?')">
                                        @csrf
                                        @method('DELETE')
                                        <button class="btn btn-sm btn-danger">
                                            <i class="fa fa-trash"></i>
                                        </button>
                                    </form>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="7" class="text-center">No doctors found.</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection
