import 'package:diplomaticquarterapp/models/hmg_services.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/all_habib_medical_service_page.dart';
import 'package:diplomaticquarterapp/pages/landing/widgets/pharmacy_view.dart';
import 'package:diplomaticquarterapp/pages/landing/widgets/services_view.dart';
import 'package:diplomaticquarterapp/pages/landing/widgets/slider_view.dart';
import 'package:diplomaticquarterapp/theme/colors.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';

class HomePageFragment extends StatefulWidget {
  Function onPharmacyClick, onLoginClick;

  HomePageFragment({this.onPharmacyClick, this.onLoginClick});

  @override
  _HomePageFragmentState createState() => _HomePageFragmentState();
}

class _HomePageFragmentState extends State<HomePageFragment> {
  List<HmgServices> hmgServices = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    //  getFamilyFiles();
  }

  initialiseHmgServices(bool isLogin) {
    hmgServices.clear();
    hmgServices.add(new HmgServices(0, TranslationBase.of(context).liveCare, TranslationBase.of(context).onlineConsulting, "assets/images/new/Live_Care.svg", isLogin));
    hmgServices.add(new HmgServices(1, TranslationBase.of(context).covidTest, TranslationBase.of(context).driveThru, "assets/images/new/covid_test_drive_thru.svg", isLogin));
    hmgServices.add(new HmgServices(2, TranslationBase.of(context).checkup, TranslationBase.of(context).comprehensive, "assets/images/new/comprehensive_checkup.svg", isLogin));
    hmgServices.add(new HmgServices(3, TranslationBase.of(context).hhcHome, TranslationBase.of(context).healthCare, "assets/images/new/HHC.svg", isLogin));
    hmgServices.add(new HmgServices(4, TranslationBase.of(context).refferal, TranslationBase.of(context).services2, "assets/images/new/E_Refferal.svg", isLogin));
    hmgServices.add(new HmgServices(5, "RRT", TranslationBase.of(context).emergency, "assets/images/new/RRT.svg", isLogin));
  }

  @override
  Widget build(BuildContext context) {
    initialiseHmgServices(false);
    return Container(
      width: double.infinity,
      child: Column(
        children: [
          AspectRatio(
            aspectRatio: 2.3,
            child: Container(
              margin: EdgeInsets.only(left: 14, right: 14, top: 10, bottom: 10),
              child: SliderView(
                onLoginClick: () {
                  widget.onLoginClick();
                },
              ),
              // height: MediaQuery.of(context).size.width / 2.6,
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(left: 20, right: 20),
            child: Image.asset("assets/images/bn_offer.png"),
          ),
          Padding(
            padding: const EdgeInsets.only(
              left: 20,
              right: 20,
              top: 16,
            ),
            child: PharmacyView(
              onPharmacyClick: () {
                widget.onPharmacyClick();
              },
            ),
          ),
          mHeight(16),
          Column(
            children: [
              Padding(
                padding: const EdgeInsets.only(
                  left: 20,
                  right: 8,
                ),
                child: Row(
                  children: [
                    Expanded(
                      child: Text(
                        TranslationBase.of(context).hMGService,
                        style: TextStyle(
                          color: Colors.black,
                          fontSize: 18,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                    FlatButton(
                      onPressed: () {
                        Navigator.push(context, FadePage(page: AllHabibMedicalService()));
                      },
                      child: Text(
                        TranslationBase.of(context).viewAllServices,
                        style: TextStyle(
                          color: CustomColors.accentColor,
                          fontSize: 14,
                          decoration: TextDecoration.underline,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(
                  left: 20,
                  right: 20,
                  top: 4,
                ),
                child: GridView.builder(
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 2 / 2, crossAxisSpacing: 12, mainAxisSpacing: 12),
                    physics: NeverScrollableScrollPhysics(),
                    shrinkWrap: true,
                    itemCount: hmgServices.length,
                    padding: EdgeInsets.zero,
                    itemBuilder: (BuildContext context, int index) {
                      return ServicesView(hmgServices[index], index);
                    }),
              ),
            ],
          ),
          mHeight(140),
        ],
      ),
    );
  }
}
