import 'dart:async';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:SEFER/views/auth/login_page.dart';

import '../../constant/box_name.dart';
import '../../main.dart';
import '../../onbording_page.dart';
import '../../views/auth/captin/login_captin.dart';
import '../../views/home/Captin/home_captain/home_captin.dart';
import '../../views/home/map_page_passenger.dart';

class SplashScreenController extends GetxController
    with SingleGetTickerProviderMixin {
  late AnimationController animationController;
  late Animation<double> zoomInAnimation;
  late Animation<double> zoomOutAnimation;

  @override
  void onInit() {
    super.onInit();

    animationController = AnimationController(
      vsync: this,
      duration: const Duration(seconds: 4),
    );

    zoomInAnimation = Tween<double>(begin: 1.0, end: 1.5).animate(
      CurvedAnimation(
        parent: animationController,
        curve: Curves.easeInOut,
      ),
    );

    zoomOutAnimation = Tween<double>(begin: 1.5, end: 1.0).animate(
      CurvedAnimation(
        parent: animationController,
        curve: Curves.easeInOut,
      ),
    );

    animationController.repeat(reverse: true);
    startTimer();
  }

  void startTimer() {
    Timer(const Duration(seconds: 4), () {
      box.read(BoxName.onBoarding) == null
          ? Get.off(() => OnBoardingPage())
          : box.read(BoxName.email) != null
              ? Get.off(() => const MapPagePassenger())
              : box.read(BoxName.emailDriver) == null
                  ? Get.off(() => LoginPage())
                  : box.read(BoxName.emailDriver) != null
                      ? Get.off(() => HomeCaptain())
                      : Get.off(() => LoginCaptin());
    });
  }

  @override
  void onClose() {
    animationController.dispose();
    super.onClose();
  }
}
