// import 'dart:math' as math;
import '../../routes/app_routes.dart';
import 'package:flutter/material.dart';
import '../../widgets/color.dart';

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

  @override
  State<SplashMain> createState() => _SplashMainState();
}

class _SplashMainState extends State<SplashMain>
    with SingleTickerProviderStateMixin {
  late final AnimationController _controller;

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

    // 1. Inisialisasi controller untuk durasi satu putaran (misal 2 detik per putar)
    _controller = AnimationController(
      vsync: this,
      duration: const Duration(seconds: 2),
    )..repeat(); // Membuat logo berputar terus-menerus

    // 2. Timer 3 detik untuk pindah halaman
    Future.delayed(const Duration(seconds: 5), () {
      if (mounted) {
        Navigator.pushReplacementNamed(context, AppRoutes.splash2);
      }
    });
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.background,
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            // 3. Gunakan RotationTransition untuk animasi berputar
            RotationTransition(
              turns: _controller,
              child: Image.asset(
                'assets/images/Logo_Coffee_Scan.png',
                width: 140,
              ),
            ),
            const SizedBox(height: 15),
            // Teks CoffeeScan tetap diam (tidak ikut berputar)
            RichText(
              text: TextSpan(
                style: const TextStyle(
                  fontFamily: 'Montserrat',
                  fontSize: 36,
                  fontWeight: FontWeight.w900,
                ),
                children: const [
                  TextSpan(
                    text: 'Coffee',
                    style: TextStyle(color: AppColors.brownMain),
                  ),
                  TextSpan(
                    text: 'Scan',
                    style: TextStyle(color: AppColors.greenMain),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
