import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:flutter/material.dart';
import 'package:doctor/common/settings.dart';
import 'package:doctor/common/zoom_image.dart';

class AllRecordsOnClick extends StatefulWidget {
  var recordDetails;
  var initialIndex;

  AllRecordsOnClick({this.recordDetails,this.initialIndex});

  @override
  State<AllRecordsOnClick> createState() => _AllRecordsOnClickState();
}

class _AllRecordsOnClickState extends State<AllRecordsOnClick>
    with TickerProviderStateMixin {

  final ImagePicker imagePicker = ImagePicker();
  List imageFileList = [];
  final ImagePicker _picker = ImagePicker();

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



  Widget findings(var obj){
    if(obj.findingsImages.length!=0){
      return Container(
        //color: secondaryColor,
          width: double.infinity,
          height: MediaQuery.of(context).size.height * .20,
          child: Row(
            children: [
              Expanded(child:  ListView.builder(
                  scrollDirection: Axis.horizontal,
                  itemCount: obj.findingsImages.length,
                  itemBuilder: (context, index) {
                    return Row(
                      children: [
                        Card(
                          child: GestureDetector(
                            onTap: (){
                              //showPicDialog(obj.prescriptionImages[index]['url']);
                              Navigator.push(
                                  context,
                                  new MaterialPageRoute(
                                      builder: (__) => new ImageZoomPage(imageName:'Findings',imageDetails:obj.findingsImages[index]['url'])));},
                            child: Container(
                              width: MediaQuery.of(context).size.width * .30,
                              height: MediaQuery.of(context).size.height * .15,
                              decoration: BoxDecoration(
                                  shape: BoxShape.rectangle,
                                  image: DecorationImage(
                                      image: NetworkImage(
                                          obj.findingsImages[index]['url'])
                                      as ImageProvider, // picked file
                                      fit: BoxFit.fill)),
                            ),
                          ),
                        )

                      ],
                    );
                  }),),
            ],
          )
      );
    }
    else{
      return GestureDetector(
        child: Row(
          children: [
            Icon(
              Icons.info,
              color: Colors.green,
              size: 40,
            ),
            Text('No Findings found',style: textButtonStyle(),)
          ],
        ),
      );
    }



  }

  Widget reports(var obj){
    if(obj.reportImages.length!=0){
      return Container(
        //color: secondaryColor,
          width: double.infinity,
          height: MediaQuery.of(context).size.height * .20,
          child: Row(
            children: [
              Expanded(child:  ListView.builder(
                  scrollDirection: Axis.horizontal,
                  itemCount: obj.reportImages.length,
                  itemBuilder: (context, index) {
                    return Row(
                      children: [
                        Card(
                          child: GestureDetector(
                            onTap: (){
                              //showPicDialog(obj.prescriptionImages[index]['url']);
                              Navigator.push(
                                  context,
                                  new MaterialPageRoute(
                                      builder: (__) => new ImageZoomPage(imageName:'Findings',imageDetails:obj.reportImages[index]['url'])));},
                            child: Container(
                              width: MediaQuery.of(context).size.width * .30,
                              height: MediaQuery.of(context).size.height * .15,
                              decoration: BoxDecoration(
                                  shape: BoxShape.rectangle,
                                  image: DecorationImage(
                                      image: NetworkImage(
                                          obj.reportImages[index]['url'])
                                      as ImageProvider, // picked file
                                      fit: BoxFit.fill)),
                            ),
                          ),
                        )

                      ],
                    );
                  }),),
            ],
          )
      );
    }
    else{
      return GestureDetector(
        child: Row(
          children: [
            Icon(
              Icons.info,
              color: Colors.green,
              size: 40,
            ),
            Text('No Reports found',style: textButtonStyle(),)
          ],
        ),
      );
    }



  }

  Widget prescriptions(var obj){
    if(obj.prescriptionImages.length!=0){
      return Container(
        //color: secondaryColor,
          width: double.infinity,
          height: MediaQuery.of(context).size.height * .20,
          child: Row(
            children: [
              Expanded(child:  ListView.builder(
                  scrollDirection: Axis.horizontal,
                  itemCount: obj.prescriptionImages.length,
                  itemBuilder: (context, index) {
                    return Row(
                      children: [
                        Card(
                          child: GestureDetector(
                            onTap: (){
                              //showPicDialog(obj.prescriptionImages[index]['url']);
                              Navigator.push(
                                  context,
                                  new MaterialPageRoute(
                                      builder: (__) => new ImageZoomPage(imageName:'Prescriptions',imageDetails:obj.prescriptionImages[index]['url'])));},
                            child: Container(
                              width: MediaQuery.of(context).size.width * .30,
                              height: MediaQuery.of(context).size.height * .15,
                              decoration: BoxDecoration(
                                  shape: BoxShape.rectangle,
                                  image: DecorationImage(
                                      image: NetworkImage(
                                          obj.prescriptionImages[index]['url'])
                                      as ImageProvider, // picked file
                                      fit: BoxFit.fill)),
                            ),
                          ),
                        )

                      ],
                    );
                  }),),
            ],
          )
      );
    }
    else{
      return GestureDetector(
        child: Row(
          children: [
            Icon(
              Icons.info,
              color: Colors.green,
              size: 40,
            ),
            Text('No Prescriptions found',style: textButtonStyle(),)
          ],
        ),
      );
    }



  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppSettings.appBar('Records'),
      body: Padding(
        padding: EdgeInsets.all(10),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              height: MediaQuery.of(context).size.height * .15,
              width: double.infinity,
              child: Padding(
                padding: EdgeInsets.all(0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                        'Problem: ' +
                            widget.recordDetails.problem.toString().toUpperCase(),
                        style: problemTextStyle()),
                    Text(widget.recordDetails.doctorName.toString().toUpperCase(),
                        style: valuesTextStyle()),
                    Text(
                        widget.recordDetails.hospitalName
                            .toString()
                            .toUpperCase(),
                        style: valuesTextStyle()),
                    Text(widget.recordDetails.date.toString().toUpperCase(),
                        style: valuesTextStyle()),
                    Text('Patient details: ', style: problemTextStyle()),
                    Text(
                        widget.recordDetails.patient_name
                            .toString()
                            .toUpperCase(),
                        style: valuesTextStyle()),
                    Row(
                      children: [
                        Text(widget.recordDetails.gender.toString().toUpperCase(),
                            style: valuesTextStyle()),
                        SizedBox(
                          width: MediaQuery.of(context).size.width * .05,
                        ),
                        Text(
                            widget.recordDetails.age.toString().toUpperCase() +
                                " Yrs",
                            style: valuesTextStyle()),
                      ],
                    ),
                  ],
                ),
              ),
            ),
            Text('Findings',style: TextStyle(color: Colors.red,fontSize: 16,fontWeight: FontWeight.bold),),
            findings(widget.recordDetails),
            Text('Reports',style: TextStyle(color: Colors.red,fontSize: 16,fontWeight: FontWeight.bold),),
            reports(widget.recordDetails),
            Text('Prescriptions',style: TextStyle(color: Colors.red,fontSize: 16,fontWeight: FontWeight.bold),),
            prescriptions(widget.recordDetails)
          ],
        ),
      ),
    );
  }
}
