import 'package:flutter/material.dart';

class AddStudentPage extends StatefulWidget {
  @override
  _AddStudentPageState createState() => _AddStudentPageState();
}

class _AddStudentPageState extends State<AddStudentPage> {
  String _selectedSex = 'Male';
  bool _isSpecialNeedsChild = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Add Student'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              CircleAvatar(
                radius: 50,
                // Add logic to handle profile image selection
                // backgroundImage: AssetImage('path_to_profile_image'),
              ),
              SizedBox(height: 16),
              buildTextFormField('First Name', 'Enter first name'),
              buildTextFormField('Last Name', 'Enter last name'),
              buildDateOfBirthField(),
              buildSexDropdown(),
              buildMedicineFields(),
              buildSpecialNeedsFields(),
              SizedBox(height: 16),
              ElevatedButton(
                onPressed: () {
                  // Add logic to save student data
                  // Navigator.pop(context); // Navigate back after saving
                },
                child: Text('Save Student'),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget buildTextFormField(String label, String hint) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 8.0),
      child: TextFormField(
        decoration: InputDecoration(
          labelText: label,
          hintText: hint,
        ),
      ),
    );
  }

  Widget buildDateOfBirthField() {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 8.0),
      child: TextFormField(
        readOnly: true,
        onTap: () async {
          // Add logic to show date picker
          // final DateTime picked = await showDatePicker(
          //   context: context,
          //   initialDate: DateTime.now(),
          //   firstDate: DateTime(2000),
          //   lastDate: DateTime(2101),
          // );
          // if (picked != null && picked != DateTime.now()) {
          //   // Handle the selected date
          // }
        },
        decoration: InputDecoration(
          labelText: 'Date of Birth',
          hintText: 'Select date of birth',
        ),
      ),
    );
  }

  Widget buildSexDropdown() {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 8.0),
      child: DropdownButtonFormField<String>(
        value: _selectedSex,
        onChanged: (value) {
          setState(() {
            _selectedSex = value!;
          });
        },
        items: ['Male', 'Female'].map((sex) {
          return DropdownMenuItem<String>(
            value: sex,
            child: Text(sex),
          );
        }).toList(),
        decoration: InputDecoration(
          labelText: 'Sex',
        ),
      ),
    );
  }

  Widget buildMedicineFields() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        buildTextFormField('Doctor Name', 'Enter doctor name'),
        buildTextFormField('Doctor Phone', 'Enter doctor phone'),
        buildTextFormField('Allergies', 'Enter allergies'),
        buildTextFormField('Medicine', 'Enter medicine'),
      ],
    );
  }

  Widget buildSpecialNeedsFields() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            Text('Special Needs Child: '),
            Checkbox(
              value: _isSpecialNeedsChild,
              onChanged: (value) {
                setState(() {
                  _isSpecialNeedsChild = value!;
                });
              },
            ),
          ],
        ),
        if (_isSpecialNeedsChild)
          buildTextFormField('Special Note', 'Enter special note'),
      ],
    );
  }
}

void main() {
  runApp(MaterialApp(
    home: AddStudentPage(),
  ));
}
