import 'package:food_delivery_client/feature/common/presentation/widgets/w_animated_dots_indicator.dart';
import 'package:food_delivery_client/feature/onboarding/presentation/pages/onboarding_page/widgets/w_onbaording_background.dart';
import 'package:food_delivery_client/feature/onboarding/presentation/pages/onboarding_page/widgets/w_onboarding_body.dart';

import '../../../../../food_delivery_client.dart';

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

  @override
  State<OnboardingPage> createState() => _OnboardingPageState();
}

class _OnboardingPageState extends State<OnboardingPage> {
  late PageController _pageController;
  int currentIndex = 0;

  @override
  void initState() {
    _pageController = PageController(initialPage: 0);
    super.initState();
  }

  @override
  void dispose() {
    _pageController.dispose();

    super.dispose();
  }

  void onPressed() {
    setState(() {
      currentIndex++;
    });
    _pageController.animateToPage(
      currentIndex,
      duration: TimeDelayConst.durationMill300,
      curve: Curves.easeIn,
    );
  }

  void onPageChanged(int int) {
    setState(() {
      currentIndex = int;
    });
  }

  @override
  Widget build(BuildContext context) {
    return WLayout(
      bottom: false,
      child: Scaffold(
        body: Stack(
          children: [
            WOnBoardingBackground(),
            WOnBoardingBody(
              pageController: _pageController,
              onPageChanged: onPageChanged,
            ),
            Positioned(
              bottom: 18,
              left: 24,
              right: 24,
              child: SafeArea(
                child: Column(
                  children: [
                    AnimatedDotsIndicator(count: 2, activeIndex: currentIndex),
                    40.verticalSpace,
                    AppButton(
                      name: currentIndex == 0
                          ? context.loc.onboarding_button_next
                          : context.loc.onboarding_button_get_started,
                      onPressed: () {
                        if (currentIndex < 1) {
                          onPressed();
                        } else {
                          context.go(Routes.login);
                        }
                      },
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
