import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:im_stepper/stepper.dart';
import 'package:unit2/screens/offline/passo/land/edit/land_appraisal_edit_offline.dart';
import 'package:unit2/screens/offline/passo/land/edit/land_property_assessement_edit.dart';
import 'package:unit2/screens/offline/passo/land/edit/land_property_owner_offline_edit.dart';
import 'package:unit2/screens/offline/passo/land/edit/land_signatories_edit.dart';
import 'package:unit2/screens/offline/passo/land/edit/location_and_boundaries_edit_offline.dart';
import 'package:unit2/screens/offline/passo/land/edit/other_improvements_edit.dart';
import 'package:unit2/screens/offline/passo/land/edit/value_adjustment_edit.dart';

import '../../../../../model/passo/land_property_owner.dart';
import '../../../../../theme-data.dart/colors.dart';

GlobalKey<FormBuilderState> landOfflineKeyEdit = GlobalKey<FormBuilderState>();

class EditLandOffline extends StatefulWidget {
  final int index;
  final LandPropertyOwner faas;
  final String title;

  const EditLandOffline(
      {super.key,
      required this.title,
      required this.index,
      required this.faas});
  @override
  _EditLandOffline createState() => _EditLandOffline();
}

class _EditLandOffline extends State<EditLandOffline> {
  // THE FOLLOWING TWO VARIABLES ARE REQUIRED TO CONTROL THE STEPPER.
  int activeStep = 0; // Initial step set to 5.

  int upperBound = 6; // upperBound MUST BE total number of icons minus 1.

  void PrevBtn() {
    setState(() {
      activeStep--;
    });
  }

  void NextBtn() {
    setState(() {
      activeStep++;
    });
  }

  void onSAveAll() {
    return Navigator.of(context).pop();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: primary,
        title: Text('Land FAAS'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          children: [
            NumberStepper(
              numbers: [1, 2, 3, 4, 5, 6, 7],
              activeStepColor: primary,
              numberStyle: TextStyle(color: Colors.white),
              lineColor: primary,
              // activeStep property set to activeStep variable defined above.
              activeStep: activeStep,
              activeStepBorderColor: Colors.white,
              activeStepBorderWidth: 1,
              // This ensures step-tapping updates the activeStep.
              onStepReached: (index) {
                setState(() {
                  activeStep = index;
                });
              },
            ),
            Expanded(
              child: Container(
                child: content(PrevBtn, NextBtn, onSAveAll),
              ),
            ),
          ],
        ),
      ),
    );
  }

  /// Returns the next button.

  // Returns the content widget based on the activeStep.
  Widget content(PrevBtn, NextBtn, onSAveAll) {
    switch (activeStep) {
      case 0:
        return LandPropertyOwnerInfoOfflineEdit(NextBtn, widget.faas);
      case 1:
        return LandLocationAndBoundariesOfflineEdit(
            PrevBtn, NextBtn, widget.faas!);
      case 2:
        return LandAppraisalEditOffline(PrevBtn, NextBtn, widget.faas.id!);
      case 3:
        return OtherImprovementEditPageOffline(
            PrevBtn, NextBtn, widget.faas.id!);
      case 4:
        return ValueAdjustmentEditPageOffline(
            PrevBtn, NextBtn, widget.faas.id!);
      case 5:
        return LandPropertyAssessmentEditPageOffline(
            PrevBtn, NextBtn, widget.faas.id!);
      case 6:
        return LandSignatoriesEditOffline(onSAveAll, widget.faas.id!);

      default:
        return SizedBox.shrink();
    }
  }
}
