import 'package:comwell_key_app/.generated/assets/assets.gen.dart';
import 'package:comwell_key_app/presentation/screens/login/bloc/login_cubit.dart';
import 'package:comwell_key_app/presentation/screens/login/components/forced_logout_banner.dart';
import 'package:comwell_key_app/presentation/screens/login/components/login_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'bloc/login_state.dart';

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

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<LoginCubit, LoginState>(
      builder: (context, state) {
        final cubit = context.read<LoginCubit>();
        return Scaffold(
          body: Container(
            constraints: const BoxConstraints.expand(),
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage(Assets.images.loginScreenBackground.path),
                fit: BoxFit.cover,
              ),
            ),
            child: SafeArea(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  if (cubit.forced) const ForcedLogoutBanner(),
                  // Logo
                  Expanded(
                    flex: 3,
                    child: Assets.images.logo.image(width: 175, height: 50),
                  ),
                  const SizedBox(height: 32),
                  LoginButton(
                    onPressed: () {
                      cubit.login(context);
                    },
                  ),
                  const SizedBox(height: 20),
                ],
              ),
            ),
          ),
        );
      },
    );
  }
}