import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart';
import 'package:diplomaticquarterapp/pages/ToDoList/ToDo.dart';
import 'package:diplomaticquarterapp/pages/medical/balance/advance_payment_page.dart';
import 'package:diplomaticquarterapp/pages/medical/balance/my_balance_page.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/medical/medical_profile_item.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PaymentService extends StatelessWidget {
  ToDoCountProviderModel model;
  ProjectViewModel projectViewModel;

  @override
  Widget build(BuildContext context) {
    projectViewModel = Provider.of(context);
    model = Provider.of<ToDoCountProviderModel>(context);
    List<Widget> paymentServiceList = getPaymentServiceList(context);
    return AppScaffold(
      isShowAppBar: true,
      isShowDecPage: false,
      showNewAppBarTitle: true,
      showNewAppBar: true,
      appBarTitle: TranslationBase.of(context).paymentService,
      body: SingleChildScrollView(
        child: Container(
          margin: EdgeInsets.all(20.0),
          child: Column(
            children: [
              Padding(
                padding: EdgeInsets.only(left: 12, right: 12),
                child: GridView.builder(
                  shrinkWrap: true,
                  primary: false,
                  physics: NeverScrollableScrollPhysics(),
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 2 / 2, crossAxisSpacing: 12, mainAxisSpacing: 12),
                  padding: EdgeInsets.zero,
                  itemCount: paymentServiceList.length,
                  itemBuilder: (BuildContext context, int index) {
                    return paymentServiceList[index];
                  },
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  List<Widget> getPaymentServiceList(BuildContext context) {
    List<Widget> medical = List();

    medical.add(
      InkWell(
        onTap: () {
          projectViewModel.analytics.advancePayments.payment_services(service_type: 'payment service');
          Navigator.push(context, FadePage(page: AdvancePaymentPage()));
        },
        child: MedicalProfileItem(
          title: TranslationBase.of(context).payment,
          imagePath: 'assets/images/new-design/online_payment_icon.png',
          subTitle: TranslationBase.of(context).paymentOnline,
          isPngImage: true,
          width: 65.0,
          height: 55.0,
        ),
      ),
    );

    medical.add(
      InkWell(
        onTap: () {
          projectViewModel.analytics.advancePayments.payment_services(service_type: 'online check-in appointment');
          navigateToToDoPage(context);
        },
        child: MedicalProfileItem(
          title: TranslationBase.of(context).onlineCheckIn,
          imagePath: 'assets/images/device_icon.png',
          subTitle: TranslationBase.of(context).appointment,
          isPngImage: true,
          width: 45.0,
          height: 45.0,
        ),
      ),
    );

    medical.add(
      InkWell(
        onTap: () {
          projectViewModel.analytics.advancePayments.payment_services(service_type: 'alhabib wallet');
          Navigator.push(context, FadePage(page: MyBalancePage()));
        },
        child: MedicalProfileItem(
          title: TranslationBase.of(context).hmg,
          imagePath: 'assets/images/check-in.png',
          subTitle: TranslationBase.of(context).wallet,
          isPngImage: true,
          width: 45.0,
          height: 45.0,
        ),
      ),
    );
    return medical;
  }

  navigateToToDoPage(BuildContext context) {
    if (projectViewModel.isLogin) {
      if (model.count != 0) {
        Navigator.push(context, FadePage(page: ToDo(isShowAppBar: true)));
      } else {
        AppToast.showErrorToast(message: TranslationBase.of(context).upcomingEmpty);
      }
    } else {
      Navigator.push(context, FadePage(page: ToDo(isShowAppBar: true)));
    }
  }
}
