import 'package:flutter/material.dart';
import 'package:ongbut_ntmanh/app/module/comment/model/comment_model.dart';
import 'package:ongbut_ntmanh/app/module/coursedetail/widgets/course_detail.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/register/model/school_model.dart';
import '../../module/school/widgets/school_widget.dart';
import '../search_page.dart';

// khoa hoc thu mien phi
// rourse
// https://imes-api.myitsol.com/api/v1/public/search-courses
// https://imes-api.myitsol.com/api/v1/public/course?grade=b9467868-d1d8-4099-9120-d995c41b3402

// 1
// https://imes-api.myitsol.com/api/v1/public/search-courses?gradeId=676f1137-3f22-4260-ac50-f4862d169ecf
// https://imes-api.myitsol.com/api/v1/public/courses/lesson-free?startRecord=0&size=10
// News  https://imes-api.myitsol.com/api/v1/public/blog
// Comment  https://imes-api.myitsol.com/api/v1/public/comment/course?courseId=

// https://imes-api.myitsol.com/api/v1/public/course/5410fd59-ccaa-43ec-8e7f-1c8561a8eee6
// https://imes-api.myitsol.com/api/v1/student/course/part?lessonId=fb228efa-7b32-419e-98b4-a6d5135f4361

class HomePage extends StatefulWidget {

   HomePage({Key? key}) : super(key: key);

  CommentModel? commentModel;
  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  CommentModel? commentModel;



  // final List<String> items = [
  //   '2001',
  //   '2002',
  //   '2003',
  //   '2004',
  //   '2005',
  //   '2006',
  //   '2007',
  //   '2008',
  // ];
  @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,
              // margin: EdgeInsets.fromLTRB(20, 0, 20, 0),
              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(),
            // CourseDetailWidget(),
            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: [
        Image.asset(Images.ongbut_happy,height: 60,width: 60,),
        const Text('ngBụt',style: TextStyle(fontWeight: FontWeight.bold,fontSize: 25,color: AppColors.white),),
        InkWell(
          onTap: (){
            Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (_) => SearchPage(commentModel))).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: 200,
            child: Padding(
              padding: const EdgeInsets.fromLTRB(5, 10, 0, 10),
              child: Text('Tim Kiem',style: TextStyle(fontSize: 15,color: Colors.white),),
            ),
          ),
        ),
        Image.asset(Images.notify,height: 40,width: 40,),
      ],),
    );
  }

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

      child: Container(
          margin: 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),),
                ],
              ),

            ],
          )
      ),
    );
  }

  // Widget _register(){
  //   return
  //     Padding(
  //       padding: const EdgeInsets.fromLTRB(8, 10, 8, 0),
  //       child: SizedBox(
  //         height: checkLandscape(context)?getHeight(context)*0.5:getHeight(context)*0.5,
  //         child:
  //         Column(
  //           children: [
  //             Padding(
  //               padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
  //               child:
  //               Center(
  //                 child: Text('Dang Ky & Tu Van'),
  //               ),
  //             ),
  //             TextField(
  //               //obscureText: true,
  //               decoration: InputDecoration(
  //                 focusColor: AppColors.error,
  //                 hoverColor: AppColors.error,
  //                 border: OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(15.0))),
  //                 labelText: 'Ho ten phu huynh *',
  //               ),
  //             ),
  //             TextField(
  //               //obscureText: true,
  //               decoration: InputDecoration(
  //                 focusColor: AppColors.error,
  //                 hoverColor: AppColors.error,
  //                 border: OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(15.0))),
  //                 labelText: 'Ho ten phu huynh *',
  //               ),
  //             ),
  //             DropdownButton<String>(
  //               disabledHint: const Text('Nam Sinh111111111',
  //                   style: TextStyle(fontSize: 16,color: AppColors.black)),
  //               items: items.map<DropdownMenuItem<String>>((String value) {
  //                 return DropdownMenuItem<String>(
  //                   alignment: Alignment.center,
  //                   value: value,
  //                   child:
  //                   Text(
  //                     value.substring(0),
  //                     style: const TextStyle(fontSize: 20,color: AppColors.black),
  //                   ),
  //                 );
  //               }).toList(),
  //               onChanged: (String? newValue) {},
  //             ),
  //             TextField(
  //               //obscureText: true,
  //               decoration: InputDecoration(
  //                 focusColor: AppColors.error,
  //                 hoverColor: AppColors.error,
  //                 border: OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(15.0))),
  //                 labelText: 'Ho ten phu huynh *',
  //               ),
  //             ),
  //
  //           ],
  //         ),
  //       ),
  //     );
  // }
}




