@extends('admin.masterAdmin')

@section('content')
<div class="row">
    <div class="col-lg-12">
        <div class="card card-fullheight">
            <div class="card-header">
                <h5 class="box-title">{{ isset($doctor) ? 'Edit Doctor' : 'Add Doctor' }}</h5>
            </div>

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


                <form action="{{ isset($doctor) ? route('doctor.update', $doctor->id) : route('doctor.store') }}"
                    method="POST" enctype="multipart/form-data">
                    @csrf
                    @if (isset($doctor))
                    @method('PUT')
                    @endif

                    <div class="mb-3">
                        <label>Name</label>
                        <input type="text" name="name" class="form-control"
                            value="{{ old('name', $doctor->name ?? '') }}" required>
                    </div>

                    <div class="mb-3">
                        <label>Slug</label>
                        <input type="text" name="slug" class="form-control"
                            value="{{ old('slug', $doctor->slug ?? '') }}" required>
                    </div>

                    <div class="mb-3">
                        <label>Specialty</label>
                        <select name="specialty_id" class="form-control" required>
                            <option value="">Select Specialty</option>
                            @foreach ($specialties as $specialty)
                            <option value="{{ $specialty->id }}" {{ old('specialty_id', $doctor->specialty_id ?? '') ==
                                $specialty->id ? 'selected' : '' }}>
                                {{ $specialty->name }}
                            </option>
                            @endforeach
                        </select>
                    </div>

                    <div class="mb-3">
                        <label>Department</label>
                        <select name="department_id" class="form-control" required>
                            <option value="">Select Department</option>
                            @foreach ($departments as $department)
                            <option value="{{ $department->id }}" {{ old('department_id', $doctor->department_id ?? '')
                                == $department->id ? 'selected' : '' }}>
                                {{ $department->name }}
                            </option>
                            @endforeach
                        </select>
                    </div>

                    <div class="mb-3">
                        <label>Experience</label>
                        <input type="text" name="experience" class="form-control"
                            value="{{ old('experience', $doctor->experience ?? '') }}">
                    </div>

                    <div class="mb-3">
                        <label>Degree</label>
                        <input type="text" name="degree" class="form-control"
                            value="{{ old('degree', $doctor->degree ?? '') }}">
                    </div>

                    <div class="mb-3">
                        <label>Designation</label>
                        <input type="text" name="designation" class="form-control"
                            value="{{ old('designation', $doctor->designation ?? '') }}">
                    </div>

                    <div class="mb-3">
                        <label>Description</label>
                        <textarea name="desc" class="form-control"
                            rows="4">{{ old('desc', $doctor->desc ?? '') }}</textarea>
                    </div>

                    <div class="mb-3">
                        <label>Image</label>
                        <input type="file" name="image" class="form-control" accept="image/*">
                        @if (isset($doctor) && $doctor->image)
                        <div class="mt-2">
                            <img src="{{ asset('public/'  . $doctor->image) }}" alt="Doctor Image" width="120">
                        </div>
                        @endif
                    </div>

                    <div class="mb-3 form-check">
                        <input type="checkbox" name="show_home" id="show_home" class="form-check-input" {{
                            old('show_home', $doctor->show_home ?? false) ? 'checked' : '' }}>
                        <label class="form-check-label" for="show_home">Show on Home Page</label>
                    </div>


                    <button class="btn btn-success mt-3">{{ isset($doctor) ? 'Update' : 'Save' }}</button>
                    <a href="{{ route('doctor.index') }}" class="btn btn-secondary mt-3">Cancel</a>
                </form>

            </div>
        </div>
    </div>
</div>
@endsection