import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/pages/ErService/rapid-response-team/rrt-main-screen.dart';
import 'package:hmg_patient_app/uitl/location_util.dart';
import 'package:hmg_patient_app/widgets/data_display/medical/medical_profile_item.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:hmg_patient_app/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../uitl/translations_delegate_base.dart';
import 'AmbulanceReq.dart';
import 'EdOnline/DdServicesPage.dart';
import 'NearestEr.dart';

class ErOptions extends StatefulWidget {
  final bool isAppbar;

  const ErOptions({Key? key, required this.isAppbar}) : super(key: key);

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

class _ErOptionsState extends State<ErOptions> {
  late LocationUtils locationUtils;
  late ProjectViewModel projectViewModel;

  @override
  void initState() {
    locationUtils = new LocationUtils(isShowConfirmDialog: true, context: context);
    WidgetsBinding.instance.addPostFrameCallback((_) => locationUtils.getCurrentLocation());

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    projectViewModel = Provider.of<ProjectViewModel>(context);
    final rrtLocked = projectViewModel.havePrivilege(68);

    return AppScaffold(
      isShowAppBar: widget.isAppbar,
      appBarTitle: TranslationBase.of(context).emergencyServices,
      isShowDecPage: false,
      showNewAppBar: true,
      showNewAppBarTitle: true,
      backgroundColor: Color(0xffF8F8F8),
      body: GridView(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 2 / 2, crossAxisSpacing: 12, mainAxisSpacing: 12),
        physics: NeverScrollableScrollPhysics(),
        padding: EdgeInsets.all(21),
        shrinkWrap: true,
        children: [
          InkWell(
            onTap: () {
              if (projectViewModel.havePrivilege(63)) Navigator.push(context, FadePage(page: AmbulanceReq()));
            },
            child: MedicalProfileItem(
              title: TranslationBase.of(context).ambulancerequest,
              imagePath: 'assets/images/new-design/AM.PNG',
              subTitle: TranslationBase.of(context).requestA,
              isPngImage: true,
              isEnable: projectViewModel.havePrivilege(63),
            ),
          ),
          InkWell(
            onTap: () {
              Navigator.push(context, FadePage(page: NearestEr()));
            },
            child: MedicalProfileItem(
              title: TranslationBase.of(context).nearester,
              imagePath: 'assets/images/new-design/emergency_icon.png',
              subTitle: TranslationBase.of(context).locationa,
              isPngImage: true,
            ),
          ),
          InkWell(
            onTap: () {
              if (rrtLocked) Navigator.push(context, FadePage(page: RRTMainScreen()));
            },
            child: MedicalProfileItem(
              title: TranslationBase.of(context).RRTTitle,
              imagePath: 'assets/images/new-design/AM.PNG',
              subTitle: TranslationBase.of(context).RRTSubTitle,
              isPngImage: true,
              isEnable: rrtLocked,
            ),
          ),
          InkWell(
            onTap: () {
              if (projectViewModel.havePrivilege(81)) Navigator.push(context, FadePage(page: DdServicesPage()));
              // Navigator.push(context, FadePage(page: DdServicesPage()));
            },
            child: MedicalProfileItem(
              title: "ED",
              imagePath: 'assets/images/new-design/AM.PNG',
              subTitle: TranslationBase.of(context).service,
              isPngImage: true,
              isEnable: projectViewModel.havePrivilege(81),
            ),
          ),
        ],
      ),
    );
  }
}
