import 'package:animate_do/animate_do.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../app.dart';
import 'controller.dart';

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetX<HomeController>(
      init: HomeController(),
      builder: (controller) => SafeArea(
        child: Scaffold(
          backgroundColor: ThemeColor.white,
          appBar: CustomAppbarWidget(),
          body: NotificationListener<ScrollNotification>(
            // onNotification: controller.handleScrollNotification,
            child: SingleChildScrollView(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  // Search Widget
                  Padding(
                    padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 30.h),
                    child: FadeInDown(child: DecoratedSearchWidget()),
                  ),

                  AppTheme.appSizeDivider15H,

                  Padding(
                    padding: EdgeInsets.only(left: 16.w, right: 16.w),
                    child: controller.state.isLoading.value
                        ? CarouselShimmer()
                        : CarouselWidget(
                            sliders: controller.state.sliders,
                          ),
                  ),

                  AppTheme.appSizeDivider30H,

                  Padding(
                    padding: EdgeInsets.only(left: 16.w, right: 16.w),
                    child: HorizontalScrollableProducts(
                      param: {
                        'new': 1,
                        'title': 'new_products'.tr,
                        'url': 'new-products',
                      },
                    ),
                  ),

                  controller.state.banners1.isNotEmpty
                      ? Column(
                          children: [
                            AppTheme.appSizeDivider20H,
                            Padding(
                              padding: EdgeInsets.only(left: 16.w, right: 16.w),
                              child: controller.state.isLoading.value
                                  ? CarouselShimmer()
                                  : CarouselWidget(
                                      sliders: controller.state.banners1,
                                    ),
                            ),
                          ],
                        )
                      : SizedBox.shrink(),

                  AppTheme.appSizeDivider30H,

                  Padding(
                    padding: EdgeInsets.only(left: 16.w, right: 16.w),
                    child: HorizontalScrollableProducts(
                      param: {
                        'featured': 1,
                        'title': 'featured_products'.tr,
                        'url': 'featured-products',
                      },
                    ),
                  ),

                  controller.state.banners2.isNotEmpty
                      ? Column(
                          children: [
                            AppTheme.appSizeDivider10H,
                            Padding(
                              padding: EdgeInsets.only(left: 16.w, right: 16.w),
                              child: controller.state.isLoading.value
                                  ? CarouselShimmer()
                                  : CarouselWidget(
                                      sliders: controller.state.banners2,
                                    ),
                            ),
                          ],
                        )
                      : SizedBox.shrink(),

                  AppTheme.appSizeDivider30H,

                  Padding(
                    padding: EdgeInsets.only(left: 16.w, right: 16.w),
                    child: HorizontalScrollableProducts(
                      param: {
                        'discount': 1,
                        'title': 'discounted_price'.tr,
                        'url': 'products-discounted',
                      },
                    ),
                  ),

                  AppTheme.appSizeDivider30H,

                  Padding(
                    padding: EdgeInsets.only(left: 16.w, right: 16.w),
                    child: HorizontalScrollableProducts(
                      param: {
                        'weekly': 1,
                        'title': 'weekly_offers'.tr,
                        'url': 'weeklyOffers',
                      },
                    ),
                  ),

                  AppTheme.appSizeDivider30H,
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
