import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/theme/colors.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:provider/provider.dart';

class LiveCareTypeSelect extends StatefulWidget {
  @override
  _LiveCareTypeSelectState createState() => _LiveCareTypeSelectState();
}

class _LiveCareTypeSelectState extends State<LiveCareTypeSelect> {
  var languageID;
  AppSharedPreferences sharedPref = AppSharedPreferences();

  ProjectViewModel projectViewModel;

  @override
  void initState() {
    getLanguageID();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    projectViewModel = Provider.of<ProjectViewModel>(context);
    return AppScaffold(
      isShowDecPage: true,
      isShowAppBar: true,
      showNewAppBarTitle: true,
      showNewAppBar: true,
      appBarTitle: TranslationBase.of(context).livecare.toUpperCase(),
      body: SingleChildScrollView(
        child: Container(
          margin: EdgeInsets.only(left: 20.0, right: 20.0, top: 20.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(child: Text(TranslationBase.of(context).livecareService, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0, letterSpacing: -0.64, color: CustomColors.darkGrey))),
              Container(
                  margin: EdgeInsets.only(top: 7.0),
                  child: Text(TranslationBase.of(context).livecareServiceDesc, style: TextStyle(fontSize: 14.0, letterSpacing: -0.64, color: CustomColors.textColor, fontWeight: FontWeight.w600))),
              Container(
                  margin: EdgeInsets.only(top: 20.0),
                  child: Text(TranslationBase.of(context).whyLivecare, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0, letterSpacing: -0.64, color: CustomColors.darkGrey))),
              Container(
                child: Row(
                  children: <Widget>[
                    SvgPicture.asset("assets/images/new-design/allow.svg", width: 20),
                    Container(
                      width: MediaQuery.of(context).size.width * 0.72,
                      margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0.0),
                      child: Text(TranslationBase.of(context).livecarePoint1,
                          overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0, letterSpacing: -0.64, color: CustomColors.black, fontWeight: FontWeight.w600)),
                    )
                  ],
                ),
              ),
              Container(
                child: Row(
                  children: <Widget>[
                    SvgPicture.asset("assets/images/new-design/allow.svg", width: 20),
                    Container(
                      width: MediaQuery.of(context).size.width * 0.72,
                      margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0.0),
                      child: Text(TranslationBase.of(context).docVirtualAppoIns4,
                          overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0, letterSpacing: -0.64, color: CustomColors.black, fontWeight: FontWeight.w600)),
                    )
                  ],
                ),
              ),
              Container(
                child: Row(
                  children: <Widget>[
                    SvgPicture.asset("assets/images/new-design/allow.svg", width: 20),
                    Container(
                      width: MediaQuery.of(context).size.width * 0.72,
                      margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0.0),
                      child: Text(TranslationBase.of(context).docVirtualAppoIns5,
                          overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0, letterSpacing: -0.64, color: CustomColors.black, fontWeight: FontWeight.w600)),
                    )
                  ],
                ),
              ),
              Container(
                  margin: EdgeInsets.only(top: 20.0),
                  child: Text(TranslationBase.of(context).livecareSummary, style: TextStyle(fontSize: 14.0, letterSpacing: -0.64, color: CustomColors.textColor, fontWeight: FontWeight.w600))),

              GridView(
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, crossAxisSpacing: 13, mainAxisSpacing: 9),
                physics: NeverScrollableScrollPhysics(),
                padding: EdgeInsets.only(top: 40.0),
                shrinkWrap: true,
                children: [
                  _loginOptionButton(TranslationBase.of(context).livecareOption1, 'assets/images/new/Live_Care.svg', 1),
                  _loginOptionButton(TranslationBase.of(context).livecareOption4, 'assets/images/new/book appointment.svg', 2),
                ],
              ),
              SizedBox(
                height: 40.0,
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _loginOptionButton(String _title, String _icon, int _loginIndex) {
    return InkWell(
      onTap: () {
        if (_loginIndex == 1) {
          projectViewModel.analytics.liveCare.livecare_immediate_consultation();
          Navigator.pop(context, "immediate");
        } else {
          projectViewModel.analytics.liveCare.livecare_schedule_video_call();
          Navigator.pop(context, "schedule");
        }
      },
      child: Container(
        padding: EdgeInsets.only(left: 20, right: 20, bottom: 15, top: 28),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(15),
          color: Colors.white,
          border: Border.all(
            color: Color(0xffefefef),
            width: 1,
          ),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            SvgPicture.asset(
              _icon,
              height: _loginIndex == 1 ? 60 : 50,
              width: _loginIndex == 1 ? 60 : 50,
            ),
            Text(
              _title,
              style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.48, height: 20 / 16),
            ),
          ],
        ),
      ),
    );
  }

  getLanguageID() async {
    var languageID = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    setState(() {
      this.languageID = languageID;
    });
  }
}
