import 'package:flutter/material.dart';
import 'package:ongbut_ntmanh/app/module/comment/model/comment_model.dart';
import 'package:ongbut_ntmanh/const/colors.dart';
import 'package:ongbut_ntmanh/widgets/widgets_util.dart';
import '../../../res/images/images.dart';
import '../../module/comment/widgets/comment_widget.dart';
import '../../module/course/widgets/course_widget.dart';
import '../../module/login/widget/login_widget.dart';
import '../../module/new/widgets/new_widget.dart';
import '../../module/school/widgets/school_widget.dart';
import '../search_page.dart';

class HomePage extends StatefulWidget {

   HomePage({Key? key}) : super(key: key);
  CommentModel? commentModel;
  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  CommentModel? commentModel;
  @override
  Widget build(BuildContext context) {

    return
      SingleChildScrollView(
        child: Column(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              alignment: Alignment.center,
              transformAlignment: Alignment.center,
              height: checkLandscape(context)?getHeight(context)*0.6:getHeight(context)*0.22,
              width: checkLandscape(context)?getWidth(context)*1:getWidth(context)*1,
              decoration: BoxDecoration(
                color: AppColors.background,
                image: const DecorationImage(
                  image: AssetImage(Images.homeBanner),
                  fit: BoxFit.cover,
                ),
                borderRadius: const BorderRadius.only(bottomLeft:Radius.circular(25),bottomRight:Radius.circular(25)),
                boxShadow: [
                  BoxShadow(
                    color: AppColors.lightGrey.withOpacity(1),
                    spreadRadius: 1,
                    offset: const Offset(0, 0), // changes position of shadow
                  ),
                ],
              ),
              child:
              Column(children: [
                buildAppBar(),
                buildBanner(context)
              ],),
            ),
            CourseWidget(),
            SchoolWidget((listData) {
              print(listData.length);
            }),
            NewWidget(),
            // _register(),
            const LoginPage(),
            CommentWidget((commentModel) {
              print(commentModel.data!.length);
            }),
          ],
        ),
      );

  }
  Container buildAppBar() {
    return Container(
      height: checkLandscape(context)?getHeight(context)*0.25:getHeight(context)*0.07,
      width: checkLandscape(context)?getWidth(context)*1:getWidth(context)*1,
      decoration: const BoxDecoration(boxShadow: [
        BoxShadow(
          color: AppColors.primary,
          spreadRadius: 1,
          offset: Offset(0, 0), // changes position of shadow
        ),
      ],),
      child: Row(children: [
        Padding(
          padding: const EdgeInsets.fromLTRB(10, 0, 0, 0),
          child: Image.asset(Images.logoWhite,height: checkLandscape(context)?getHeight(context)*0.25:getHeight(context)*0.07,
              width:checkLandscape(context)?getWidth(context)*0.2:getWidth(context)*0.25),
        ),
        InkWell(
          onTap: (){
            Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (_) => SearchWidget(),

                )).then((value) {
              if (value != null && value is bool && value) {}
            });
          },
          child: Container(
            margin: const EdgeInsets.fromLTRB(10, 0, 10, 0),
            decoration: const BoxDecoration(
              color: AppColors.primary_light,
              borderRadius: BorderRadius.all(Radius.circular(30)),
              boxShadow: [
                BoxShadow(
                  color: AppColors.primary_light,
                  spreadRadius: 1,
                  offset: Offset(0, 0), // changes position of shadow
                ),
              ],
            ),
            height: 40,
            width: checkLandscape(context)?getWidth(context)*0.7:getWidth(context)*0.55,
            child: const Padding(
              padding: EdgeInsets.fromLTRB(5, 10, 0, 10),
              child: Text('Tim Kiem',style: TextStyle(fontSize: 15,color: Colors.white),),
            ),
          ),
        ),
        Image.asset(Images.notify,height: 25,width: 25,),
      ],),
    );
  }

  Padding buildBanner(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),

      child: Container(
          margin: const EdgeInsets.fromLTRB(10, 0, 10, 0),
          decoration: BoxDecoration(
            color: AppColors.white,
            borderRadius: const BorderRadius.all(Radius.circular(10)),
            boxShadow: [
              BoxShadow(
                color: AppColors.lightGrey.withOpacity(1),
                spreadRadius: 1,
                offset: const Offset(0, 0), // changes position of shadow
              ),
            ],
          ),
          alignment: Alignment.center,
          transformAlignment: Alignment.center,
          height: checkLandscape(context)?getHeight(context)*0.25:getHeight(context)*0.12,
          child:
          ListView(
            padding: EdgeInsets.fromLTRB(checkLandscape(context)?200:0, 0, 0, 0),
            scrollDirection: Axis.horizontal,
            children: [
              Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.fromLTRB(10, 20, 10, 10),
                    child: Stack(
                      clipBehavior: Clip.none,
                      alignment: Alignment.center,
                      children: [
                        Container(
                          height: 50,
                          width: 50,
                          child: Image.asset(Images.icItem),
                        ),
                        Container(
                            height: 40,
                            width: 40,
                            child:
                            Image.asset(Images.acc_ongbut)
                        )
                      ],
                    ),
                  ),
                  const Text('Hoi But',style: TextStyle(fontSize: 12,fontWeight: FontWeight.bold),),
                ],
              ),
              Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.fromLTRB(10, 20, 10, 10),
                    child: Stack(
                      clipBehavior: Clip.none,
                      alignment: Alignment.center,
                      children: [
                        Container(
                          height: 50,
                          width: 50,
                          child: Image.asset(Images.icItem),
                        ),
                        Container(
                            height: 40,
                            width: 40,
                            child:
                            Image.asset(Images.acc_ongbut)
                        )
                      ],
                    ),
                  ),
                  const Text('Hoi But',style: TextStyle(fontSize: 12,fontWeight: FontWeight.bold),),
                ],
              ),
              Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.fromLTRB(10, 20, 10, 10),
                    child: Stack(
                      clipBehavior: Clip.none,
                      alignment: Alignment.center,
                      children: [
                        Container(
                          height: 50,
                          width: 50,
                          child: Image.asset(Images.icItem),
                        ),
                        Container(
                            height: 40,
                            width: 40,
                            child:
                            Image.asset(Images.acc_ongbut)
                        )
                      ],
                    ),
                  ),
                  const Text('Hoi But',style: TextStyle(fontSize: 12,fontWeight: FontWeight.bold),),
                ],
              ),
              Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.fromLTRB(10, 20, 10, 10),
                    child: Stack(
                      clipBehavior: Clip.none,
                      alignment: Alignment.center,
                      children: [
                        Container(
                          height: 50,
                          width: 50,
                          child: Image.asset(Images.icItem),
                        ),
                        Container(
                            height: 40,
                            width: 40,
                            child:
                            Image.asset(Images.acc_ongbut)
                        )
                      ],
                    ),
                  ),
                  const Text('Hoi But',style: TextStyle(fontSize: 12,fontWeight: FontWeight.bold),),
                ],
              ),
              Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.fromLTRB(10, 20, 10, 10),
                    child: Stack(
                      clipBehavior: Clip.none,
                      alignment: Alignment.center,
                      children: [
                        Container(
                          height: 50,
                          width: 50,
                          child: Image.asset(Images.icItem),
                        ),
                        Container(
                            height: 40,
                            width: 40,
                            child:
                            Image.asset(Images.acc_ongbut)
                        )
                      ],
                    ),
                  ),
                  const Text('Hoi But',style: TextStyle(fontSize: 12,fontWeight: FontWeight.bold),),
                ],
              ),
            ],
          )
      ),
    );
  }
}




