import 'package:flutter/material.dart';

class SpurGefunden extends StatefulWidget {
  final TextEditingController spurFund;
  final TextEditingController spurLang;
  final TextEditingController spurTiere;
  final TextEditingController spSicher;
  final TextEditingController welpenSp;
  final TextEditingController welpenAnz;
  final TextEditingController wpSicher;

  const SpurGefunden(
      {super.key,
      required this.spurFund,
      required this.spurLang,
      required this.spurTiere,
      required this.spSicher,
      required this.welpenSp,
      required this.welpenAnz,
      required this.wpSicher});

  @override
  State<SpurGefunden> createState() => _SpurGefundenState();
}

class _SpurGefundenState extends State<SpurGefunden> {
  bool _spurFundChecked = false;
  bool _spSicher = false;
  bool _wpSicher = false;
  bool _welpenSp = false;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Row(
          children: [
            const Text("Spur gefunden"),
            Checkbox(
              value: _spurFundChecked,
              onChanged: (val) {
                setState(() {
                  _spurFundChecked = val ?? false;
                  widget.spurFund.text = val ?? false ? "Spur" : "";
                });
              },
            ),
          ],
        ),
        Visibility(
          visible: _spurFundChecked,
          child: Column(
            children: [
              Align(
                  alignment: Alignment.bottomLeft,
                  child: Text("Gesamtlaenge aller dok. Spuren (m)")),
              TextField(
                keyboardType: TextInputType.number,
                controller: widget.spurLang,
              ),
              const SizedBox(
                height: 30,
              ),
              Align(
                  alignment: Alignment.bottomLeft,
                  child: Text("max. Anzahl zus. gefaerhrterter Tiere")),
              TextField(
                keyboardType: TextInputType.number,
                controller: widget.spurTiere,
              ),
              Row(
                children: [
                  const Text("Sicher"),
                  Checkbox(
                      value: _spSicher,
                      onChanged: (val) {
                        setState(() {
                          _spSicher = val ?? false;
                          widget.spSicher.text = _spSicher ? "sicher" : "unsicher";
                        });
                      }),
                ],
              ),
              const SizedBox(
                height: 10,
              ),
              Row(
                children: [
                  Text("Welpenspur gefunden"),
                  Checkbox(
                    value: _welpenSp,
                    onChanged: (val) {
                      setState(() {
                        _welpenSp = val ?? false;
                      });
                    },
                  ),
                ],
              ),
              Visibility(
                  visible: _welpenSp,
                  child: Column(
                    children: [
                      Align(
                          alignment: Alignment.bottomLeft,
                          child: Text("Gesamtlaenge aller dok. Spuren (m)")),
                      TextField(
                        keyboardType: TextInputType.number,
                        controller: widget.welpenSp,
                      ),
                      const SizedBox(height: 20,),
                      Align(
                          alignment: Alignment.bottomLeft,
                          child: Text("max. Anzahl zus. gefaerhrterter Welpen")),
                      TextField(
                        keyboardType: TextInputType.number,
                        controller: widget.welpenAnz,
                      ),
                      Row(
                        children: [
                          const Text("Sicher"),
                          Checkbox(
                              value: _wpSicher,
                              onChanged: (val) {
                                setState(() {
                                  _wpSicher = val ?? false;
                                  widget.spSicher.text =
                                      _spSicher ? "sicher" : "unsicher";
                                });
                              }),
                        ],
                      ),
                    ],
                  )),
            ],
          ),
        ),
      ],
    );
  }
}
