import 'package:flutter/material.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import '../../../core/local_source/local_source.dart';
import '../../../injector_container.dart';
import '../../../router/name_routes.dart';
import '../../../service/notification_service.dart';

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

  @override
  State<InitialPage> createState() => _InitialPageState();
}

class _InitialPageState extends State<InitialPage> {
  @override
  void initState() {
    _redirect();
    super.initState();
  }

  void _redirect() {
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      if (context.mounted) {
        if (sl<LocalSource>().getHasProfile()) {
          Navigator.of(context).pushReplacementNamed(Routes.main);
        } else {
          Navigator.of(context).pushReplacementNamed(Routes.language);
        }
        await NotificationService.clearNotificationBadge();
        FlutterNativeSplash.remove();
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return const SizedBox();
  }
}
