import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../bloc/login_bloc.dart';
import '../model/login_model.dart';


final TextEditingController _userController = TextEditingController();
final TextEditingController _passController = TextEditingController();
LoginModel? loginModels;
class LoginPage extends StatelessWidget {
  const LoginPage({super.key});
  @override
  Widget build(BuildContext context) {
    return
      BlocConsumer<LoginBloc, LoginState>(
      listener: (context, state) async {},
      builder: (context, state) {
        return
          Column(
            children: [
              Padding(
                padding: const EdgeInsets.only(left: 60, right: 60),
                child:
                TextFormField(
                  decoration: const InputDecoration(
                    labelText: 'Product Name',
                  ),
                  controller: _userController,
                ),
              ),

              Padding(
                padding: const EdgeInsets.only(left: 60, right: 60),
                child:
                TextFormField(
                  decoration: const InputDecoration(
                    labelText: 'PassWord',
                  ),
                  controller: _passController,
                ),
              ),

              OutlinedButton(
                  style: OutlinedButton.styleFrom(minimumSize: Size(200, 50)),
                  onPressed: () async {
                    BlocProvider.of<LoginBloc>(context).add(
                        RequestLogin(
                            context: context,
                            username: _userController.text,
                            password: _passController.text));
                  },
                  child: Text("Submit Form".toUpperCase(),
                    style: const TextStyle(
                        fontWeight: FontWeight.bold),)
              ),
              BlocBuilder<LoginBloc, LoginState>(
                  builder: (context, state) {
                    if (state is LoginLoading) {
                      return const CircularProgressIndicator();
                    }
                    if (state is LoginFailed) {
                      return const Text('login false!');
                    }
                    if (state is LoginInitial) {
                      return
                        Text('LoginInitial');
                    }
                    if (state is LoginSuccess) {
                      return
                        Text('Dang Nhap Thanh Cong');
                    }
                    return const CircularProgressIndicator();
                  }),
            ],
          );
      },
    );
  }
}


