import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import '../../app/constant.dart';
import '../../app/route.dart';
import '../../provider/current_user_provider.dart';

class SplashScreen extends HookConsumerWidget {
  const SplashScreen({super.key});
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    // useEffect(() {
    //   WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
    //     final doctorID =
    //         ref.read(currentUserProvider)?.model.M_UserM_DoctorCode ?? "0";
    //     // print(doctorID);

    //     if (doctorID == "0") {
    //       //not login

    //       Navigator.of(context)
    //           .pushNamedAndRemoveUntil(loginRoute, (route) => false);
    //       return;

    //     } else {
    //       Navigator.of(context)
    //           .pushNamedAndRemoveUntil(menuRoute, (route) => false);
    //     }
    //   });
    //   return () {};
    // }, []);

    // setelah 3 detik redirect ke login route
    Timer(const Duration(seconds: 3), () {
      Navigator.of(context).pushNamedAndRemoveUntil(
        loginRoute,
        (route) => false,
      );
    });

    return Scaffold(
      // appBar: AppBar(
      //   backgroundColor: Constant.backgroundColor,
      //   elevation: 0,
      // ),
      backgroundColor: Constant.backgroundColor,
      body: SafeArea(
        child: Container(
          width: Constant.getActualXPhone(context: context, x: 390),
          height: Constant.getActualYPhone(context: context, y: 844),
          child: Image.asset(
            "images/logo_splash_screen.png",
            // fit: BoxFit.width,
            // scale: 1,
          ),
          // color: Colors.green,
        ),
      ),
    );
  }
}
