import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/viewModel/livecare_view_model.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
import 'package:doctor_app_flutter/core/model/livecare/get_pending_res_list.dart';
import 'package:doctor_app_flutter/utils/dr_app_shared_pref.dart';
import 'package:doctor_app_flutter/utils/utils.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/card_with_bgNew_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart';
import 'package:doctor_app_flutter/widgets/shared/rounded_container_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../config/size_config.dart';
import '../../widgets/shared/app_scaffold_widget.dart';

DrAppSharedPreferances sharedPref = DrAppSharedPreferances();

class LiveCarePandingListScreen extends StatefulWidget {
  // In the constructor, require a item id.
  LiveCarePandingListScreen({Key? key}) : super(key: key);

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

class _LiveCarePandingListState extends State<LiveCarePandingListScreen> {
  List<LiveCarePendingListResponse> _data = [];
  Utils helpers = new Utils();
  bool _isInit = true;
  LiveCareViewModel _liveCareProvider = LiveCareViewModel();

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    if (_isInit) {
      _liveCareProvider = Provider.of<LiveCareViewModel>(context);
      pendingList();
    }
    _isInit = false;
  }

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
        appBarTitle: TranslationBase.of(context).livecare,
        body: Container(
          child: ListView(
              scrollDirection: Axis.vertical,

              // physics: const AlwaysScrollableScrollPhysics(),
              children: <Widget>[
                RoundedContainer(
                    child: !_liveCareProvider.isFinished
                        ? Container(height: SizeConfig.screenHeight, width: SizeConfig.screenWidth, child: DrAppCircularProgressIndeicator())
                        : _liveCareProvider.hasError
                            ? Center(
                                child: Text(
                                  _liveCareProvider.errorMsg,
                                  style: TextStyle(color: Colors.red),
                                ),
                              )
                            : Column(
                                children: _liveCareProvider.liveCarePendingList.map<Widget>((item) {
                                  return Container(
                                    decoration: myBoxDecoration(),
                                    child: InkWell(
                                      child: CardWithBgWidgetNew(
                                        //CardWithBgWidget(
                                        widget: Column(
                                          children: <Widget>[
                                            Container(
                                              //  decoration: myBoxDecoration(),
                                              child: Row(
                                                children: <Widget>[
                                                  Expanded(
                                                    flex: 4,
                                                    child: Row(
                                                      children: <Widget>[
                                                        Column(
                                                          children: <Widget>[
                                                            Container(
                                                                decoration: BoxDecoration(
                                                                  gradient: LinearGradient(begin: Alignment(-1, -1), end: Alignment(1, 1), colors: [
                                                                    Colors.grey[100]!,
                                                                    Colors.grey[200]!,
                                                                  ]),
                                                                  boxShadow: [BoxShadow(color: Color.fromRGBO(0, 0, 0, 0.08), offset: Offset(0.0, 5.0), blurRadius: 16.0)],
                                                                  borderRadius: BorderRadius.all(Radius.circular(50.0)),
                                                                ),
                                                                width: 80,
                                                                height: 80,
                                                                child: Icon(
                                                                  item.gender == "1" ? DoctorApp.male : DoctorApp.female_icon,
                                                                  size: 80,
                                                                )),
                                                          ],
                                                        ),
                                                        SizedBox(
                                                          width: 20,
                                                        ),
                                                        Column(
                                                          crossAxisAlignment: CrossAxisAlignment.start,
                                                          children: <Widget>[
                                                            AppText(
                                                              item.patientName!,
                                                              fontSize: 2.0 * SizeConfig.textMultiplier!,
                                                              fontWeight: FontWeight.bold,
                                                            ),
                                                            SizedBox(
                                                              height: 8,
                                                            ),
                                                            AppText(
                                                              TranslationBase.of(context).fileNo + item.patientID.toString(),
                                                              fontSize: 2.0 * SizeConfig.textMultiplier!,
                                                              fontWeight: FontWeight.bold,
                                                            ),
                                                            AppText(
                                                              TranslationBase.of(context).age + ' ' + item.age.toString(),
                                                              fontSize: 2.0 * SizeConfig.textMultiplier!,
                                                              fontWeight: FontWeight.bold,
                                                            ),
                                                            SizedBox(
                                                              height: 8,
                                                            ),
                                                          ],
                                                        ),
                                                      ],
                                                    ),
                                                  ),
                                                  Expanded(
                                                    flex: 1,
                                                    child: IconButton(
                                                      icon: Icon(
                                                        Icons.video_call,
                                                        size: 40,
                                                      ),
                                                      color: Colors.green, //Colors.black,
                                                      onPressed: () => {
                                                        _isInit = true,
                                                        // sharedPref.setObj(
                                                        //     LIVE_CARE_PATIENT,
                                                        //     item),
                                                        // Navigator.of(context)
                                                        //     .pushNamed(
                                                        //         VIDEO_CALL,
                                                        //         item)
                                                        // Navigator.push(
                                                        //     context,
                                                        //     MaterialPageRoute(
                                                        //         builder: (context) =>
                                                        //             VideoCallPage(
                                                        //                 item,
                                                        //                 context)))
                                                      },
                                                    ),
                                                  )
                                                ],
                                              ),
                                            ),
                                            // Divider(color: Colors.grey)
                                          ],
                                        ),
                                      ),
                                      onTap: () {},
                                    ),
                                  );
                                }).toList(),
                              ))
              ]),
        ));
  }

  Future<bool> pendingList() async {
    _liveCareProvider.getpendingList().then((result) {
      this.setState(() {
        _data = _liveCareProvider.liveCarePendingList;
      });
    });
    return true;
  }

  myBoxDecoration() {
    return BoxDecoration(
      border: Border(
        bottom: BorderSide(
          //                    <--- top side
          color: Colors.grey,
          width: 1.0,
        ),
      ),
    );
  }
}

MyGlobals myGlobals = new MyGlobals();

class MyGlobals {
  GlobalKey? _scaffoldKey;

  MyGlobals() {
    _scaffoldKey = GlobalKey();
  }

  GlobalKey get scaffoldKey => _scaffoldKey!;
}
