import 'package:food_delivery_client/feature/onboarding/presentation/blocs/splash_bloc/splash_bloc.dart';

import '../../../../../food_delivery_client.dart';

class SplashPage extends StatelessWidget {
  const SplashPage({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) => sl<SplashBloc>()..add(SplashEvent.started()),
      child: BlocListener<SplashBloc, SplashState>(
        listener: (context, state) {
          if (state.status.isError()) {
            context.go(Routes.onBoarding);
          }

          if (state.status.isLoaded()) {
            context.go(Routes.main);
          }
        },
        child: WLayout(
          bottom: false,
          top: false,
          child: Scaffold(
            body: Stack(
              children: [
                Positioned.fill(
                  child: SvgPicture.asset(context.appThemeIcons.icSplash),
                ),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Center(child: SvgPicture.asset(AppIcons.icLogo)),
                    ShaderMask(
                      shaderCallback: (bounds) =>
                          AppUtils.kGradient.createShader(
                            Rect.fromLTWH(0, 0, bounds.width, bounds.height),
                          ),
                      child: Text(
                        AppLocaleKeys.appName,
                        style: context.appThemeTextStyles.size64Black,
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
