// import 'package:awesome_dialog/awesome_dialog.dart';
// import 'package:cloud_firestore/cloud_firestore.dart';
// import 'package:firebase_auth/firebase_auth.dart';
// import 'package:firebase_storage/firebase_storage.dart';
// import 'package:flutter/material.dart';
// import 'package:image_picker/image_picker.dart';
// import 'dart:io';

// class AddStudentPage extends StatefulWidget {
//   final String classname;

//   const AddStudentPage({required this.classname, Key? key}) : super(key: key);

//   @override
//   State<AddStudentPage> createState() => _AddStudentState();
// }

// class _AddStudentState extends State<AddStudentPage> {
//   final ImagePicker _imagePicker = ImagePicker();
//   XFile? _selectedImage;
//   String? _selectedSex;

//   // Controllers
//   final TextEditingController _firstnameController = TextEditingController();
//   final TextEditingController _lastnameController = TextEditingController();
//   final TextEditingController _birthdayController = TextEditingController();
//   final TextEditingController _doctornameController = TextEditingController();
//   final TextEditingController _doctorphoneController = TextEditingController();
//   final TextEditingController _allergiesController = TextEditingController();
//   final TextEditingController _medicineController = TextEditingController();
//   final TextEditingController _parentnameController = TextEditingController();
//   final TextEditingController _parentphoneController = TextEditingController();
//   final TextEditingController _parentemailController = TextEditingController();
//   final TextEditingController _addressLine1Controller = TextEditingController();
//   final TextEditingController _addressLine2Controller = TextEditingController();
//   final TextEditingController _cityController = TextEditingController();
//   final TextEditingController _zipController = TextEditingController();
//   final TextEditingController _countryController = TextEditingController();
//   final TextEditingController _stateController = TextEditingController();

//   bool _specialNeedsYes = false;
//   bool _specialNeedsNo = false;

//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBar(
//         leading: IconButton(
//           icon: Icon(Icons.arrow_back),
//           onPressed: () => Navigator.pop(context),
//         ),
//         title: Text('Add Kid'),
//         centerTitle: true,
//       ),
//       body: SingleChildScrollView(
//         child: SafeArea(
//           child: Padding(
//             padding: const EdgeInsets.all(16.0),
//             child: Form(
//               child: Column(
//                 children: [
//                   _buildImagePicker(),
//                   _buildSectionTitle('Bio'),
//                   _buildTextField(_firstnameController, 'First Name', Icons.person),
//                   _buildTextField(_lastnameController, 'Last Name', Icons.person),
//                   _buildTextField(_birthdayController, 'Birthday', Icons.cake),
//                   _buildDropdownButton(),
//                   _buildSectionTitle('Medicine'),
//                   _buildTextField(_doctornameController, 'Doctor Name', Icons.person),
//                   _buildTextField(_doctorphoneController, 'Doctor Phone Number', Icons.phone),
//                   _buildTextField(_allergiesController, 'Allergies', Icons.coronavirus_sharp),
//                   _buildTextField(_medicineController, 'Medicine', Icons.medication_outlined),
//                   _buildSpecialNeedsSection(),
//                   _buildSectionTitle('Contact'),
//                   _buildTextField(_parentnameController, 'Parent Name', Icons.person),
//                   _buildTextField(_parentphoneController, 'Parent Phone Number', Icons.phone),
//                   _buildTextField(_parentemailController, 'Parent Email', Icons.email),
//                   _buildSectionTitle('Address'),
//                   _buildTextField(_addressLine1Controller, 'Address Line 1', Icons.location_on_outlined),
//                   _buildTextField(_addressLine2Controller, 'Address Line 2', Icons.location_on_outlined),
//                   _buildTextField(_cityController, 'City', Icons.location_city_sharp),
//                   _buildTextField(_zipController, 'Zip/Postal Code', Icons.location_searching),
//                   _buildTextField(_countryController, 'Country', Icons.location_city_rounded),
//                   _buildTextField(_stateController, 'State/Region', Icons.location_city_sharp),
//                   _buildActionButtons(),
//                 ],
//               ),
//             ),
//           ),
//         ),
//       ),
//     );
//   }

//   Widget _buildImagePicker() {
//     return GestureDetector(
//       onTap: () async {
//         XFile? image = await _imagePicker.pickImage(source: ImageSource.gallery, imageQuality: 50);
//         setState(() => _selectedImage = image);
//       },
//       child: CircleAvatar(
//         radius: 50.0,
//         backgroundImage: _selectedImage != null ? FileImage(File(_selectedImage!.path)) : AssetImage('assets/classlogo.png') as ImageProvider,
//       ),
//     );
//   }

//   Widget _buildTextField(TextEditingController controller, String hintText, IconData icon) {
//     return Padding(
//       padding: const EdgeInsets.only(top: 20),
//       child: TextField(
//         controller: controller,
//         decoration: InputDecoration(
//           hintText: hintText,
//           filled: true,
//           fillColor: Color.fromARGB(107, 196, 196, 196),
//           border: OutlineInputBorder(borderRadius: BorderRadius.circular(10.0), borderSide: BorderSide.none),
//           suffixIcon: Icon(icon, size: 23.0, color: Color.fromARGB(132, 12, 12, 12)),
//         ),
//       ),
//     );
//   }

//   Widget _buildDropdownButton() {
//     return Padding(
//       padding: const EdgeInsets.only(top: 20),
//       child: DropdownButtonFormField<String>(
//         value: _selectedSex,
//         onChanged: (newValue) => setState(() => _selectedSex = newValue),
//         items: <String>['Select', 'Male', 'Female'].map((String value) {
//           return DropdownMenuItem<String>(
//             value: value,
//             child: Text(value),
//           );
//         }).toList(),
//         decoration: InputDecoration(
//           filled: true,
//           fillColor: Color.fromARGB(107, 196, 196, 196),
//           border: OutlineInputBorder(borderRadius: BorderRadius.circular(10.0), borderSide: BorderSide.none),
//           suffixIcon: Icon(Icons.people, size: 23.0, color: Color.fromARGB(132, 12, 12, 12)),
//           hintText: 'Select Gender',
//         ),
//       ),
//     );
//   }

//   Widget _buildSpecialNeedsSection() {
//     return Padding(
//       padding: const EdgeInsets.only(top: 20),
//       child: Row(
//         mainAxisAlignment: MainAxisAlignment.spaceBetween,
//         children: [
//           Expanded(child: Text('Special Needs Child', style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold))),
//           Text('Yes'),
//           Checkbox(value: _specialNeedsYes, onChanged: (bool? value) => setState(() => _specialNeedsYes = value ?? false)),
//           Text('No'),
//           Checkbox(value: _specialNeedsNo, onChanged: (bool? value) => setState(() => _specialNeedsNo = value ?? false)),
//         ],
//       ),
//     );
//   }

//   Widget _buildSectionTitle(String title) {
//     return Padding(
//       padding: const EdgeInsets.only(top: 30, bottom: 10),
//       child: Row(
//         children: [
//           Expanded(
//             child: Text(
//               title,
//               style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Color(0xFF22215B)),
//             ),
//           ),
//         ],
//       ),
//     );
//   }

//   Widget _buildActionButtons() {
//     return Padding(
//       padding: const EdgeInsets.symmetric(vertical: 30),
//       child: Row(
//         mainAxisAlignment: MainAxisAlignment.center,
//         children: [
//           _buildActionButton('Save', Colors.green, _handleSave),
//           SizedBox(width: 20),
//           _buildActionButton('Cancel', Colors.grey.shade200, () => Navigator.pop(context)),
//         ],
//       ),
//     );
//   }

//   Widget _buildActionButton(String title, Color color, VoidCallback onPressed) {
//     return TextButton(
//       onPressed: onPressed,
//       style: TextButton.styleFrom(backgroundColor: color, padding: EdgeInsets.symmetric(horizontal: 30)),
//       child: Text(
//         title,
//         style: TextStyle(color: Colors.white, fontSize: 14, fontFamily: 'Poppins', fontWeight: FontWeight.w600),
//       ),
//     );
//   }

//   Future<void> _handleSave() async {
//     if (_selectedImage == null) {
//       _showDialog('Error', 'Please select an image for the student');
//       return;
//     }
//     try {
//       // Upload image to Firebase Storage
//       String imageName = DateTime.now().millisecondsSinceEpoch.toString();
//       Reference storageRef = FirebaseStorage.instance.ref().child('student_images/$imageName');
//       UploadTask uploadTask = storageRef.putFile(File(_selectedImage!.path));
//       String imageUrl = await (await uploadTask).ref.getDownloadURL();

//       // Save student details to Firestore
//       FirebaseFirestore.instance.collection('students').add({
//         'Firstname': _firstnameController.text.trim(),
//         'Lastname': _lastnameController.text.trim(),
//         'Sex': _selectedSex,
//         'Birthday': _birthdayController.text.trim(),
//         'Doctorname': _doctornameController.text.trim(),
//         'Doctorphone': _doctorphoneController.text.trim(),
//         'Allergies': _allergiesController.text.trim(),
//         'Medicine': _medicineController.text.trim(),
//         'Parentname': _parentnameController.text.trim(),
//         'Parentphone': _parentphoneController.text.trim(),
//         'Parentemail': _parentemailController.text.trim(),
//         'AddressLine1': _addressLine1Controller.text.trim(),
//         'AddressLine2': _addressLine2Controller.text.trim(),
//         'City': _cityController.text.trim(),
//         'Zip': _zipController.text.trim(),
//         'Country': _countryController.text.trim(),
//         'State': _stateController.text.trim(),
//         'Image': imageUrl,
//         'ClassName': widget.classname,
//         'SpecialNeeds': _specialNeedsYes ? 'Yes' : 'No',
//         'UserId': FirebaseAuth.instance.currentUser?.uid ?? '',
//         'Timestamp': FieldValue.serverTimestamp(),
//       });

//       _showDialog('Success', 'Student details saved successfully', success: true);
//     } catch (e) {
//       _showDialog('Error', 'Failed to save student details');
//     }
//   }

//   void _showDialog(String title, String desc, {bool success = false}) {
//     AwesomeDialog(
//       context: context,
//       dialogType: success ? DialogType.success : DialogType.error,
//       animType: AnimType.rightSlide,
//       title: title,
//       desc: desc,
//       btnOkOnPress: () {},
//     ).show();
//   }
// }
