@extends('layouts.app')

@section('title', 'ছাত্র/ছাত্রীর তথ্য পরিবর্তন')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <!-- Progress Bar -->
            <div class="card mb-4">
                <div class="card-body">
                    <div class="progress" style="height: 30px;">
                        <div class="progress-bar bg-warning progress-bar-striped" 
                             role="progressbar" 
                             style="width: 25%;" 
                             aria-valuenow="25" 
                             aria-valuemin="0" 
                             aria-valuemax="100">
                            ধাপ ১/৪: মৌলিক তথ্য
                        </div>
                    </div>
                </div>
            </div>

            <!-- Main Form -->
            <div class="card card-primary card-outline card-tabs">
                <div class="card-header p-0 pt-1 bg-warning">
                    <ul class="nav nav-tabs" id="admission-tab" role="tablist">
                        <li class="nav-item">
                            <a class="nav-link active text-dark" id="basic-tab" data-toggle="pill" href="#basic" role="tab">
                                <i class="fa fa-user"></i> মৌলিক তথ্য
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" id="academic-tab" data-toggle="pill" href="#academic" role="tab">
                                <i class="fa fa-graduation-cap"></i> শিক্ষাগত তথ্য
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" id="contact-tab" data-toggle="pill" href="#contact" role="tab">
                                <i class="fa fa-address-book"></i> যোগাযোগ ও ঠিকানা
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" id="guardian-tab" data-toggle="pill" href="#guardian" role="tab">
                                <i class="fa fa-users"></i> অভিভাবক তথ্য
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" id="health-tab" data-toggle="pill" href="#health" role="tab">
                                <i class="fa fa-heartbeat"></i> স্বাস্থ্য তথ্য
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" id="documents-tab" data-toggle="pill" href="#documents" role="tab">
                                <i class="fa fa-file"></i> ডকুমেন্টস
                            </a>
                        </li>
                    </ul>
                </div>

                <div class="card-body">
                    <form method="POST" action="{{ route('students.update', $student->id) }}" 
                          enctype="multipart/form-data" id="editForm">
                        @csrf
                        @method('PUT')

                        <!-- Tab Content -->
                        <div class="tab-content" id="admission-tabContent">
                            
                            <!-- Tab 1: Basic Information -->
                            <div class="tab-pane fade show active" id="basic" role="tabpanel">
                                <div class="row">
                                    <div class="col-md-12">
                                        <h5 class="bg-warning text-dark p-2 rounded">
                                            <i class="fa fa-id-card"></i> ছাত্র আইডি: 
                                            <strong>{{ $student->student_id }}</strong>
                                            <small class="float-right">পরিবর্তন করা যাবে না</small>
                                        </h5>
                                    </div>
                                </div>

                                <div class="row mt-3">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>নাম (বাংলা) <span class="text-danger">*</span></label>
                                            <input type="text" 
                                                   name="name_bn" 
                                                   class="form-control @error('name_bn') is-invalid @enderror" 
                                                   value="{{ old('name_bn', $student->name_bn) }}"
                                                   placeholder="রাহিম উদ্দিন"
                                                   required>
                                            @error('name_bn')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                            <small class="text-muted">শুধুমাত্র বাংলা অক্ষর</small>
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>নাম (ইংরেজি) <span class="text-danger">*</span></label>
                                            <input type="text" 
                                                   name="name_en" 
                                                   class="form-control @error('name_en') is-invalid @enderror" 
                                                   value="{{ old('name_en', $student->name_en) }}"
                                                   placeholder="Rahim Uddin"
                                                   required>
                                            @error('name_en')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                            <small class="text-muted">শুধুমাত্র ইংরেজি অক্ষর</small>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>পিতার নাম <span class="text-danger">*</span></label>
                                            <input type="text" 
                                                   name="father_name" 
                                                   class="form-control @error('father_name') is-invalid @enderror" 
                                                   value="{{ old('father_name', $student->father_name) }}"
                                                   placeholder="আব্দুল করিম"
                                                   required>
                                            @error('father_name')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>মাতার নাম <span class="text-danger">*</span></label>
                                            <input type="text" 
                                                   name="mother_name" 
                                                   class="form-control @error('mother_name') is-invalid @enderror" 
                                                   value="{{ old('mother_name', $student->mother_name) }}"
                                                   placeholder="আমেনা বেগম"
                                                   required>
                                            @error('mother_name')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>জন্ম তারিখ <span class="text-danger">*</span></label>
                                            <input type="date" 
                                                   name="date_of_birth" 
                                                   class="form-control @error('date_of_birth') is-invalid @enderror" 
                                                   value="{{ old('date_of_birth', $student->date_of_birth ? $student->date_of_birth->format('Y-m-d') : '') }}"
                                                   max="{{ date('Y-m-d', strtotime('-5 years')) }}"
                                                   required>
                                            @error('date_of_birth')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>জন্মস্থান</label>
                                            <input type="text" 
                                                   name="birth_place" 
                                                   class="form-control" 
                                                   value="{{ old('birth_place', $student->birth_place) }}"
                                                   placeholder="ঢাকা">
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>জাতীয়তা <span class="text-danger">*</span></label>
                                            <select name="nationality" class="form-control @error('nationality') is-invalid @enderror" required>
                                                <option value="বাংলাদেশী" {{ old('nationality', $student->nationality) == 'বাংলাদেশী' ? 'selected' : '' }}>বাংলাদেশী</option>
                                                <option value="Other" {{ old('nationality', $student->nationality) == 'Other' ? 'selected' : '' }}>অন্যান্য</option>
                                            </select>
                                            @error('nationality')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>ধর্ম</label>
                                            <select name="religion" class="form-control">
                                                <option value="">নির্বাচন করুন</option>
                                                <option value="ইসলাম" {{ old('religion', $student->religion) == 'ইসলাম' ? 'selected' : '' }}>ইসলাম</option>
                                                <option value="হিন্দু" {{ old('religion', $student->religion) == 'হিন্দু' ? 'selected' : '' }}>হিন্দু</option>
                                                <option value="বৌদ্ধ" {{ old('religion', $student->religion) == 'বৌদ্ধ' ? 'selected' : '' }}>বৌদ্ধ</option>
                                                <option value="খ্রিস্টান" {{ old('religion', $student->religion) == 'খ্রিস্টান' ? 'selected' : '' }}>খ্রিস্টান</option>
                                                <option value="অন্যান্য" {{ old('religion', $student->religion) == 'অন্যান্য' ? 'selected' : '' }}>অন্যান্য</option>
                                            </select>
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>লিঙ্গ <span class="text-danger">*</span></label>
                                            <select name="gender" class="form-control @error('gender') is-invalid @enderror" required>
                                                <option value="">নির্বাচন করুন</option>
                                                <option value="male" {{ old('gender', $student->gender) == 'male' ? 'selected' : '' }}>পুরুষ</option>
                                                <option value="female" {{ old('gender', $student->gender) == 'female' ? 'selected' : '' }}>মহিলা</option>
                                                <option value="other" {{ old('gender', $student->gender) == 'other' ? 'selected' : '' }}>অন্যান্য</option>
                                            </select>
                                            @error('gender')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>রক্তের গ্রুপ</label>
                                            <select name="blood_group" class="form-control">
                                                <option value="">নির্বাচন করুন</option>
                                                @foreach(['A+', 'A-', 'B+', 'B-', 'O+', 'O-', 'AB+', 'AB-'] as $bg)
                                                    <option value="{{ $bg }}" {{ old('blood_group', $student->blood_group) == $bg ? 'selected' : '' }}>
                                                        {{ $bg }}
                                                    </option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-12 text-right">
                                        <button type="button" class="btn btn-warning next-tab" data-next="academic-tab">
                                            পরবর্তী <i class="fa fa-arrow-right"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>

                            <!-- Tab 2: Academic Information -->
                            <div class="tab-pane fade" id="academic" role="tabpanel">
                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>শ্রেণি <span class="text-danger">*</span></label>
                                            <select name="class_id" class="form-control @error('class_id') is-invalid @enderror" required>
                                                <option value="">শ্রেণি নির্বাচন করুন</option>
                                                @foreach($classes as $class)
                                                <option value="{{ $class->id }}" {{ old('class_id', $student->class_id) == $class->id ? 'selected' : '' }}>
                                                    {{ $class->class_name_bn }} @if($class->section)({{ $class->section }})@endif
                                                </option>
                                                @endforeach
                                            </select>
                                            @error('class_id')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <label>শাখা</label>
                                            <input type="text" 
                                                   name="section" 
                                                   class="form-control @error('section') is-invalid @enderror" 
                                                   value="{{ old('section', $student->section) }}" 
                                                   placeholder="A">
                                            @error('section')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <label>রোল নম্বর <span class="text-danger">*</span></label>
                                            <input type="number" 
                                                   name="roll_number" 
                                                   class="form-control @error('roll_number') is-invalid @enderror" 
                                                   value="{{ old('roll_number', $student->roll_number) }}"
                                                   min="1"
                                                   max="999"
                                                   required>
                                            @error('roll_number')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>ভর্তির তারিখ <span class="text-danger">*</span></label>
                                            <input type="date" 
                                                   name="admission_date" 
                                                   class="form-control @error('admission_date') is-invalid @enderror" 
                                                   value="{{ old('admission_date', $student->admission_date ? $student->admission_date->format('Y-m-d') : date('Y-m-d')) }}"
                                                   required>
                                            @error('admission_date')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>ভর্তির ধরন <span class="text-danger">*</span></label>
                                            <select name="admission_type" class="form-control" required>
                                                <option value="regular" {{ old('admission_type', $student->admission_type) == 'regular' ? 'selected' : '' }}>নিয়মিত</option>
                                                <option value="transfer" {{ old('admission_type', $student->admission_type) == 'transfer' ? 'selected' : '' }}>ট্রান্সফার</option>
                                                <option value="special" {{ old('admission_type', $student->admission_type) == 'special' ? 'selected' : '' }}>বিশেষ</option>
                                            </select>
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>পূর্ববর্তী স্কুল</label>
                                            <input type="text" 
                                                   name="previous_school" 
                                                   class="form-control" 
                                                   value="{{ old('previous_school', $student->previous_school) }}"
                                                   placeholder="আগের স্কুলের নাম">
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <label>পূর্ববর্তী শ্রেণি</label>
                                            <input type="text" 
                                                   name="previous_class" 
                                                   class="form-control" 
                                                   value="{{ old('previous_class', $student->previous_class) }}"
                                                   placeholder="ষষ্ঠ">
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <label>পূর্ববর্তী জিপিএ</label>
                                            <input type="number" 
                                                   name="previous_gpa" 
                                                   class="form-control" 
                                                   value="{{ old('previous_gpa', $student->previous_gpa) }}"
                                                   step="0.01"
                                                   min="0"
                                                   max="5">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>ছাড়ের ক্যাটাগরি</label>
                                            <input type="text" 
                                                   name="discount_category" 
                                                   class="form-control" 
                                                   value="{{ old('discount_category', $student->discount_category) }}"
                                                   placeholder="মেধা/অর্থনৈতিক">
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <label>ছাড়ের শতাংশ</label>
                                            <input type="number" 
                                                   name="discount_percentage" 
                                                   class="form-control" 
                                                   value="{{ old('discount_percentage', $student->discount_percentage) }}"
                                                   min="0"
                                                   max="100">
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>মন্তব্য</label>
                                            <textarea name="remarks" class="form-control" rows="2">{{ old('remarks', $student->remarks) }}</textarea>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-12">
                                        <div class="form-check">
                                            <input type="checkbox" 
                                                   name="is_boarder" 
                                                   class="form-check-input" 
                                                   id="is_boarder"
                                                   {{ old('is_boarder', $student->is_boarder) ? 'checked' : '' }}>
                                            <label class="form-check-label" for="is_boarder">হোস্টেলে থাকবে</label>
                                        </div>
                                    </div>
                                </div>

                                <div class="row mt-3">
                                    <div class="col-12">
                                        <div class="form-check">
                                            <input type="checkbox" 
                                                   name="transport_required" 
                                                   class="form-check-input" 
                                                   id="transport_required"
                                                   {{ old('transport_required', $student->transport_required) ? 'checked' : '' }}>
                                            <label class="form-check-label" for="transport_required">পরিবহন প্রয়োজন</label>
                                        </div>
                                    </div>
                                </div>

                                <div class="row mt-3">
                                    <div class="col-12">
                                        <button type="button" class="btn btn-secondary prev-tab" data-prev="basic-tab">
                                            <i class="fa fa-arrow-left"></i> পূর্ববর্তী
                                        </button>
                                        <button type="button" class="btn btn-warning next-tab float-right" data-next="contact-tab">
                                            পরবর্তী <i class="fa fa-arrow-right"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>

                            <!-- Tab 3: Contact & Address -->
                            <div class="tab-pane fade" id="contact" role="tabpanel">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>মোবাইল নম্বর <span class="text-danger">*</span></label>
                                            <div class="input-group">
                                                <div class="input-group-prepend">
                                                    <span class="input-group-text"><i class="fa fa-phone"></i></span>
                                                </div>
                                                <input type="text" 
                                                       name="phone" 
                                                       class="form-control @error('phone') is-invalid @enderror" 
                                                       value="{{ old('phone', $student->phone) }}"
                                                       placeholder="017XXXXXXXX"
                                                       required>
                                            </div>
                                            @error('phone')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                            <small class="text-muted">বাংলাদেশী মোবাইল নম্বর দিন</small>
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>জরুরি যোগাযোগ</label>
                                            <div class="input-group">
                                                <div class="input-group-prepend">
                                                    <span class="input-group-text"><i class="fa fa-phone-alt"></i></span>
                                                </div>
                                                <input type="text" 
                                                       name="emergency_phone" 
                                                       class="form-control" 
                                                       value="{{ old('emergency_phone', $student->emergency_phone) }}"
                                                       placeholder="017XXXXXXXX">
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>ইমেইল</label>
                                            <div class="input-group">
                                                <div class="input-group-prepend">
                                                    <span class="input-group-text"><i class="fa fa-envelope"></i></span>
                                                </div>
                                                <input type="email" 
                                                       name="email" 
                                                       class="form-control @error('email') is-invalid @enderror" 
                                                       value="{{ old('email', $student->email) }}"
                                                       placeholder="example@email.com">
                                            </div>
                                            @error('email')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>শহর/জেলা <span class="text-danger">*</span></label>
                                            <input type="text" 
                                                   name="city" 
                                                   class="form-control @error('city') is-invalid @enderror" 
                                                   value="{{ old('city', $student->city) }}"
                                                   placeholder="ঢাকা"
                                                   required>
                                            @error('city')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>পোস্টাল কোড</label>
                                            <input type="text" 
                                                   name="postal_code" 
                                                   class="form-control" 
                                                   value="{{ old('postal_code', $student->postal_code) }}"
                                                   placeholder="১২১২">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label>বর্তমান ঠিকানা <span class="text-danger">*</span></label>
                                            <textarea name="present_address" 
                                                      class="form-control @error('present_address') is-invalid @enderror" 
                                                      rows="3"
                                                      required>{{ old('present_address', $student->present_address) }}</textarea>
                                            @error('present_address')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label>স্থায়ী ঠিকানা</label>
                                            <textarea name="permanent_address" 
                                                      class="form-control" 
                                                      rows="3">{{ old('permanent_address', $student->permanent_address) }}</textarea>
                                        </div>
                                    </div>
                                </div>

                                <div class="row mt-3">
                                    <div class="col-12">
                                        <button type="button" class="btn btn-secondary prev-tab" data-prev="academic-tab">
                                            <i class="fa fa-arrow-left"></i> পূর্ববর্তী
                                        </button>
                                        <button type="button" class="btn btn-warning next-tab float-right" data-next="guardian-tab">
                                            পরবর্তী <i class="fa fa-arrow-right"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>

                            <!-- Tab 4: Guardian Information -->
                            <div class="tab-pane fade" id="guardian" role="tabpanel">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>অভিভাবকের নাম <span class="text-danger">*</span></label>
                                            <input type="text" 
                                                   name="guardian_name" 
                                                   class="form-control @error('guardian_name') is-invalid @enderror" 
                                                   value="{{ old('guardian_name', $student->guardian_name) }}"
                                                   required>
                                            @error('guardian_name')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>সম্পর্ক <span class="text-danger">*</span></label>
                                            <select name="guardian_relation" class="form-control" required>
                                                <option value="">নির্বাচন করুন</option>
                                                <option value="father" {{ old('guardian_relation', $student->guardian_relation) == 'father' ? 'selected' : '' }}>পিতা</option>
                                                <option value="mother" {{ old('guardian_relation', $student->guardian_relation) == 'mother' ? 'selected' : '' }}>মাতা</option>
                                                <option value="brother" {{ old('guardian_relation', $student->guardian_relation) == 'brother' ? 'selected' : '' }}>ভাই</option>
                                                <option value="sister" {{ old('guardian_relation', $student->guardian_relation) == 'sister' ? 'selected' : '' }}>বোন</option>
                                                <option value="other" {{ old('guardian_relation', $student->guardian_relation) == 'other' ? 'selected' : '' }}>অন্যান্য</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>অভিভাবকের মোবাইল <span class="text-danger">*</span></label>
                                            <input type="text" 
                                                   name="guardian_phone" 
                                                   class="form-control @error('guardian_phone') is-invalid @enderror" 
                                                   value="{{ old('guardian_phone', $student->guardian_phone) }}"
                                                   placeholder="017XXXXXXXX"
                                                   required>
                                            @error('guardian_phone')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>অভিভাবকের পেশা</label>
                                            <input type="text" 
                                                   name="guardian_occupation" 
                                                   class="form-control" 
                                                   value="{{ old('guardian_occupation', $student->guardian_occupation) }}"
                                                   placeholder="চাকরি/ব্যবসা">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>মাসিক আয় (ঐচ্ছিক)</label>
                                            <div class="input-group">
                                                <input type="number" 
                                                       name="monthly_income" 
                                                       class="form-control" 
                                                       value="{{ old('monthly_income', $student->monthly_income) }}"
                                                       min="0">
                                                <div class="input-group-append">
                                                    <span class="input-group-text">টাকা</span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="row mt-3">
                                    <div class="col-12">
                                        <button type="button" class="btn btn-secondary prev-tab" data-prev="contact-tab">
                                            <i class="fa fa-arrow-left"></i> পূর্ববর্তী
                                        </button>
                                        <button type="button" class="btn btn-warning next-tab float-right" data-next="health-tab">
                                            পরবর্তী <i class="fa fa-arrow-right"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>

                            <!-- Tab 5: Health Information -->
                            <div class="tab-pane fade" id="health" role="tabpanel">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-check mb-3">
                                            <input type="checkbox" 
                                                   name="has_disability" 
                                                   class="form-check-input" 
                                                   id="has_disability"
                                                   {{ old('has_disability', $student->has_disability) ? 'checked' : '' }}>
                                            <label class="form-check-label" for="has_disability">
                                                প্রতিবন্ধী (প্রয়োজনে বিস্তারিত দিন)
                                            </label>
                                        </div>
                                        
                                        <div class="form-group" id="disability_details_div" style="display: {{ old('has_disability', $student->has_disability) ? 'block' : 'none' }};">
                                            <label>প্রতিবন্ধতার বিস্তারিত</label>
                                            <textarea name="disability_details" 
                                                      class="form-control" 
                                                      rows="2">{{ old('disability_details', $student->disability_details) }}</textarea>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>ক্রনিক রোগ (যদি থাকে)</label>
                                            <input type="text" 
                                                   name="chronic_disease" 
                                                   class="form-control" 
                                                   value="{{ old('chronic_disease', $student->chronic_disease) }}"
                                                   placeholder="ডায়াবেটিস/অ্যাজমা ইত্যাদি">
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>এলার্জি (যদি থাকে)</label>
                                            <input type="text" 
                                                   name="allergies" 
                                                   class="form-control" 
                                                   value="{{ old('allergies', $student->allergies) }}"
                                                   placeholder="খাবারে এলার্জি">
                                        </div>
                                    </div>
                                </div>

                                <div class="row mt-3">
                                    <div class="col-12">
                                        <button type="button" class="btn btn-secondary prev-tab" data-prev="guardian-tab">
                                            <i class="fa fa-arrow-left"></i> পূর্ববর্তী
                                        </button>
                                        <button type="button" class="btn btn-warning next-tab float-right" data-next="documents-tab">
                                            পরবর্তী <i class="fa fa-arrow-right"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>

                            <!-- Tab 6: Documents -->
                            <div class="tab-pane fade" id="documents" role="tabpanel">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>ছবি পরিবর্তন করুন</label>
                                            <div class="custom-file">
                                                <input type="file" 
                                                       name="photo" 
                                                       class="custom-file-input @error('photo') is-invalid @enderror" 
                                                       id="photo"
                                                       accept="image/*">
                                                <label class="custom-file-label" for="photo">ছবি নির্বাচন করুন</label>
                                            </div>
                                            @error('photo')
                                                <span class="invalid-feedback">{{ $message }}</span>
                                            @enderror
                                            <small class="text-muted">সর্বোচ্চ ২MB, JPG/PNG ফরম্যাট</small>
                                            <div id="photo_preview" class="mt-2">
                                                @if($student->photo)
                                                    <img src="{{ asset($student->photo) }}" style="max-width: 150px; max-height: 150px;" class="img-thumbnail">
                                                @endif
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>জন্ম নিবন্ধন</label>
                                            <div class="custom-file">
                                                <input type="file" 
                                                       name="birth_certificate" 
                                                       class="custom-file-input" 
                                                       id="birth_certificate"
                                                       accept=".pdf,.jpg,.jpeg,.png">
                                                <label class="custom-file-label" for="birth_certificate">ফাইল নির্বাচন করুন</label>
                                            </div>
                                            @if($student->birth_certificate_file)
                                                <small>বর্তমান ফাইল: {{ basename($student->birth_certificate_file) }}</small>
                                            @endif
                                        </div>
                                    </div>
                                </div>

                                <div class="row mt-3">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>ট্রান্সফার সার্টিফিকেট</label>
                                            <div class="custom-file">
                                                <input type="file" 
                                                       name="transfer_certificate" 
                                                       class="custom-file-input" 
                                                       id="transfer_certificate"
                                                       accept=".pdf,.jpg,.jpeg,.png">
                                                <label class="custom-file-label" for="transfer_certificate">ফাইল নির্বাচন করুন</label>
                                            </div>
                                            @if($student->transfer_certificate)
                                                <small>বর্তমান ফাইল: {{ basename($student->transfer_certificate) }}</small>
                                            @endif
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>পিতার NID</label>
                                            <div class="custom-file">
                                                <input type="file" 
                                                       name="father_nid" 
                                                       class="custom-file-input" 
                                                       id="father_nid"
                                                       accept=".pdf,.jpg,.jpeg,.png">
                                                <label class="custom-file-label" for="father_nid">ফাইল নির্বাচন করুন</label>
                                            </div>
                                            @if($student->father_nid)
                                                <small>বর্তমান ফাইল: {{ basename($student->father_nid) }}</small>
                                            @endif
                                        </div>
                                    </div>
                                </div>

                                <div class="row mt-3">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>পরিবহন জোন</label>
                                            <input type="text" 
                                                   name="transport_zone" 
                                                   class="form-control" 
                                                   value="{{ old('transport_zone', $student->transport_zone) }}"
                                                   placeholder="উত্তরা/মিরপুর">
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>স্ট্যাটাস</label>
                                            <select name="status" class="form-control">
                                                <option value="1" {{ old('status', $student->status) == 1 ? 'selected' : '' }}>সক্রিয়</option>
                                                <option value="0" {{ old('status', $student->status) == 0 ? 'selected' : '' }}>নিষ্ক্রিয়</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="row mt-4">
                                    <div class="col-12 text-center">
                                        <button type="button" class="btn btn-secondary prev-tab" data-prev="health-tab">
                                            <i class="fa fa-arrow-left"></i> পূর্ববর্তী
                                        </button>
                                        <button type="submit" class="btn btn-warning btn-lg">
                                            <i class="fa fa-save"></i> আপডেট করুন
                                        </button>
                                        <a href="{{ route('students.index') }}" class="btn btn-secondary btn-lg">
                                            <i class="fa fa-times"></i> বাতিল
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

            <!-- Important Instructions -->
            <div class="card mt-3">
                <div class="card-header bg-warning">
                    <i class="fa fa-info-circle"></i> গুরুত্বপূর্ণ নির্দেশনা
                </div>
                <div class="card-body">
                    <ul class="list-unstyled">
                        <li><i class="fa fa-check-circle text-success"></i> <span class="text-danger">*</span> চিহ্নিত ফিল্ডগুলো অবশ্যই পূরণ করতে হবে</li>
                        <li><i class="fa fa-check-circle text-success"></i> মোবাইল নম্বর সঠিকভাবে দিন (যেমন: 017XXXXXXXX)</li>
                        <li><i class="fa fa-check-circle text-success"></i> নতুন ছবি আপলোড করলে পুরনো ছবি অটো মুছে যাবে</li>
                        <li><i class="fa fa-check-circle text-success"></i> ছবির সাইজ ২MB এর বেশি হতে পারবে না</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('scripts')
<script>
$(document).ready(function() {
    // Tab navigation
    $('.next-tab').click(function() {
        var nextTab = $(this).data('next');
        $('#' + nextTab).tab('show');
        
        // Update progress bar
        var progress = $(this).closest('.tab-pane').index() + 2;
        $('.progress-bar').css('width', (progress * 25) + '%')
                         .text('ধাপ ' + progress + '/৪: ' + getTabName(nextTab));
    });
    
    $('.prev-tab').click(function() {
        var prevTab = $(this).data('prev');
        $('#' + prevTab).tab('show');
        
        // Update progress bar
        var progress = $(this).closest('.tab-pane').index();
        $('.progress-bar').css('width', (progress * 25) + '%')
                         .text('ধাপ ' + progress + '/৪: ' + getTabName(prevTab));
    });
    
    function getTabName(tabId) {
        var names = {
            'basic-tab': 'মৌলিক তথ্য',
            'academic-tab': 'শিক্ষাগত তথ্য',
            'contact-tab': 'যোগাযোগ ও ঠিকানা',
            'guardian-tab': 'অভিভাবক তথ্য',
            'health-tab': 'স্বাস্থ্য তথ্য',
            'documents-tab': 'ডকুমেন্টস'
        };
        return names[tabId] || '';
    }
    
    // File input preview
    $('.custom-file-input').on('change', function() {
        var fileName = $(this).val().split('\\').pop();
        $(this).next('.custom-file-label').addClass("selected").html(fileName);
    });
    
    // Photo preview
    $('#photo').on('change', function() {
        var file = this.files[0];
        var reader = new FileReader();
        
        reader.onload = function(e) {
            $('#photo_preview').html('<img src="' + e.target.result + '" style="max-width: 150px; max-height: 150px;" class="img-thumbnail">');
        }
        
        if (file) {
            reader.readAsDataURL(file);
        }
    });
    
    // Disability checkbox toggle
    $('#has_disability').change(function() {
        if($(this).is(':checked')) {
            $('#disability_details_div').slideDown();
        } else {
            $('#disability_details_div').slideUp();
        }
    });
    
    // Form validation before submit
    $('#editForm').on('submit', function(e) {
        var isValid = true;
        
        // Check required fields in current tab
        $(this).find('.tab-pane.active input[required], .tab-pane.active select[required]').each(function() {
            if(!$(this).val()) {
                $(this).addClass('is-invalid');
                isValid = false;
            }
        });
        
        if(!isValid) {
            e.preventDefault();
            alert('দয়া করে বর্তমান ট্যাবের সকল আবশ্যক ফিল্ড পূরণ করুন');
        }
    });
    
    // Bengali name validation
    $('input[name="name_bn"]').on('keyup', function() {
        var bengaliRegex = /^[\u0980-\u09FF\s]+$/;
        if($(this).val() && !bengaliRegex.test($(this).val())) {
            $(this).addClass('is-invalid');
            $(this).next('.invalid-feedback').html('শুধুমাত্র বাংলা অক্ষর ব্যবহার করুন');
        } else {
            $(this).removeClass('is-invalid');
        }
    });
    
    // Phone number validation
    $('input[name="phone"], input[name="guardian_phone"]').on('keyup', function() {
        var phoneRegex = /^01[3-9]\d{8}$/;
        if($(this).val() && !phoneRegex.test($(this).val())) {
            $(this).addClass('is-invalid');
        } else {
            $(this).removeClass('is-invalid');
        }
    });
    
    // Check duplicate roll number (AJAX) - only if class or roll changes
    $('input[name="roll_number"], select[name="class_id"]').on('change', function() {
        var classId = $('select[name="class_id"]').val();
        var rollNumber = $('input[name="roll_number"]').val();
        var currentStudentId = {{ $student->id }};
        
        if(classId && rollNumber) {
            $.ajax({
                url: '{{ route("students.check-roll") }}',
                type: 'POST',
                data: {
                    _token: '{{ csrf_token() }}',
                    class_id: classId,
                    roll_number: rollNumber,
                    exclude_id: currentStudentId
                },
                success: function(response) {
                    if(response.exists) {
                        $('input[name="roll_number"]').addClass('is-invalid');
                        $('input[name="roll_number"]').next('.invalid-feedback')
                            .html('এই রোল নম্বরটি ইতিমধ্যে ব্যবহার হচ্ছে');
                    } else {
                        $('input[name="roll_number"]').removeClass('is-invalid');
                    }
                }
            });
        }
    });
});
</script>
@endsection