import 'dart:async';
import 'package:animated_splash_screen/animated_splash_screen.dart';
import 'package:flutter/material.dart';
import 'package:navigation/app_routes.dart';
import 'package:navigation/navigation_contract.dart';
import 'package:page_transition/page_transition.dart';

class SplashScreen extends StatefulWidget {
  const SplashScreen({super.key, required this.navigationContract});
  final NavigationContract navigationContract;

  @override
  State<SplashScreen> createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> {
  @override
  void initState() {
    super.initState();
    unawaited(nextRoute());
  }

  Future<void> nextRoute() async {
    await Future.delayed(const Duration(milliseconds: 3500));
    if (!mounted) return;
    widget.navigationContract.goTo(AppRoutes.onboarding);
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedSplashScreen(
      splash: Image.asset('assets/images/logos/splash.gif'),
      splashIconSize: 2000.0,
      nextScreen: const SizedBox.shrink(),
      disableNavigation: true,
      backgroundColor: Colors.white,
      splashTransition: SplashTransition.fadeTransition,
      pageTransitionType: PageTransitionType.fade,
    );
  }
}
