import 'package:flutter/material.dart';

class NewTareaForm extends StatefulWidget {
  const NewTareaForm({super.key});

  @override
  _NewTareaFormState createState() => _NewTareaFormState();
}

class _NewTareaFormState extends State<NewTareaForm> {
  final _formKey = GlobalKey<FormState>();
  String _taskName = '';

  void _submitForm() {
    if (_formKey.currentState!.validate()) {
      _formKey.currentState!.save();
      
      Navigator.of(context).pop();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(16.0),
      child: Form(
        key: _formKey,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Form(
              key: _formKey,
              child: TextFormField(
                decoration: InputDecoration(labelText: 'Ingrese La nueva tarea'),
                validator: (value) {
                  if (value == null || value.isEmpty) {
                    return 'Porfavor ingrese una tarea';
                  }
                  return null;
                },
                onSaved: (value) {
                  _taskName = value!;
                },
              ),
            ),
            SizedBox(height: 16),
            TextFormField(
              decoration: InputDecoration(labelText: 'Ingrese la prioridad'),
              validator: (value) {
                if (value == null || value.isEmpty) {
                  return 'Porfavor ingrese una prioridad';
                }
                return null;
              },
              onSaved: (value) {
                _taskName = value!;
              },
            ),
            SizedBox(height: 16),
            ElevatedButton(
              onPressed: _submitForm,
              child: Text('Nueva Tarea'),
            ),
          ],
        ),
      ),
    );
  }
}
