import 'dart:io';

import 'package:clean/base/base_controller.dart';
import 'package:clean/data/consts/constants.dart';
import 'package:clean/dialog/privacy_dialog.dart';
import 'package:clean/main.dart';
import 'package:clean/module/main/main_view.dart';
import 'package:clean/module/splash/intro/intro_view.dart';
import 'package:flutter/Material.dart';
import 'package:get/get.dart';

class SplashController extends BaseController {
  Animation<double>? animation;

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

  @override
  void onReady() {
    print('SplashController onReady');
    super.onReady();
    final isAgreePrivacy = isAgreePrivacyPolicy();
    if (isAgreePrivacy) {
      onAgreePrivacy();
    } else {
      Future.delayed(const Duration(seconds: 2), () {
        privacyDialog(
          onAgree: () {
            setPrivacyPolicy(true);
            onAgreePrivacy();
          },
          onDisagree: () {
            setPrivacyPolicy(false);
            exit(0);
          },
        );
      });
    }
  }

  // 已经同意隐私
  void onAgreePrivacy() async {
    await initAfterGrant();
    Future.delayed(const Duration(seconds: 2), () {
      if (isFirstIntro()) {
        IntroPage.start();
      } else {
        MainTabPage.start();
      }
    });
  }

  @override
  void onClose() {
    print('SplashController onClose');
    super.onClose();
  }
}
