import 'package:bookmywages/consts_widgets/app_assets.dart';
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/routers/consts_router.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';

import 'package:shared_preferences/shared_preferences.dart';

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

  @override
  State<FlashScreen> createState() => _FlashScreenState();
}

class _FlashScreenState extends State<FlashScreen> {
  @override
  void initState() {
    super.initState();
    _navigateUser();
  }

  Future<void> _navigateUser() async {
    await Future.delayed(const Duration(seconds: 2));
    final prefs = await SharedPreferences.getInstance();
    final userId = prefs.getString('userId');
    final isVerified = prefs.getString('is_verified');

    if (!mounted) return;

    if (userId != null && userId.isNotEmpty && isVerified == '1') {
      Get.toNamed(RouterConts.homescreen);
    } else {
      Get.toNamed(RouterConts.welcomepage);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.flashscreen,
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Center(child: Image.asset(AppAssets.flashscreen)),
      ),
    );
  }
}
