import 'dart:io';

import 'package:hmg_patient_app/pages/insurance/UpdateInsuranceManually.dart';
import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/app_toast.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/widgets/bottom_options/BottomSheet.dart';
import 'package:hmg_patient_app/widgets/buttons/defaultButton.dart';
import 'package:hmg_patient_app/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class AttachInsuranceCardImageDialog extends StatefulWidget {
  String name;
  String fileNo;
  String? identificationNo;
  String? mobileNo;
  Function(File file, String image) image;
  bool isBirthNotification;

  AttachInsuranceCardImageDialog({Key? key, required this.name, required this.fileNo, this.identificationNo, this.mobileNo, required this.image, this.isBirthNotification = false}) : super(key: key);

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

class _AttachInsuranceCardImageDialogState extends State<AttachInsuranceCardImageDialog> {
  @override
  void initState() {
    super.initState();
  }

  String? image = "";
  late File file;

  @override
  Widget build(BuildContext context) {
    return SimpleDialog(
      children: [
        Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Text(
              widget.isBirthNotification ? TranslationBase.of(context).scanID : TranslationBase.of(context).updateInsurCards,
              style: TextStyle(
                fontSize: 14,
                fontWeight: FontWeight.w600,
                letterSpacing: -0.48,
              ),
            ),
            Divider(),
            Padding(
              padding: const EdgeInsets.only(left: 8, right: 8),
              child: Text(
                widget.name,
                style: TextStyle(
                  fontSize: 14,
                  letterSpacing: -0.48,
                ),
              ),
            ),
            SizedBox(
              height: 3,
            ),
            Text(
              TranslationBase.of(context).fileNo + " " + widget.fileNo,
              style: TextStyle(
                fontSize: 14,
                letterSpacing: -0.48,
              ),
            ),
            SizedBox(
              height: 5.0,
            ),
            InkWell(
              onTap: () {
                ImageOptions.showImageOptions(context, (String image, File file) {
                  setState(() {
                    this.image = image;
                    this.file = file;
                  });
                });
              },
              child: image!.isEmpty
                  ? Padding(
                      padding: const EdgeInsets.all(18.0),
                      child: Container(
                        width: double.maxFinite,
                        height: 200,
                        decoration: BoxDecoration(borderRadius: BorderRadius.circular(2), border: Border.all(color: Colors.grey, width: 1.5)),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          // mainAxisAlignment: MainAxisAlignment.,
                          children: [
                            SizedBox(
                              height: 25,
                            ),
                            Icon(
                              Icons.camera_enhance_rounded,
                              size: 85,
                            ),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Icon(Icons.attach_file),
                                Text(
                                  TranslationBase.of(context).selectAttachment.toUpperCase(),
                                  style: TextStyle(
                                    fontSize: 12,
                                    letterSpacing: -0.48,
                                    fontWeight: FontWeight.w600,
                                  ),
                                )
                              ],
                            ),
                          ],
                        ),
                      ),
                    )
                  : Image.file(
                      file,
                      fit: BoxFit.fill,
                      height: 250,
                    ),
            ),
            if (!widget.isBirthNotification)
              Text(
                "OR",
                style: TextStyle(
                  fontSize: 16,
                  letterSpacing: -0.48,
                  fontWeight: FontWeight.w600,
                ),
              ),
            if (!widget.isBirthNotification)
              Padding(
                padding: const EdgeInsets.all(18.0),
                child: DefaultButton(
                  TranslationBase.of(context).updateInsuranceManually,
                  () {
                    Navigator.pop(context);
                    Navigator.push(
                      context,
                      FadePage(
                        page: UpdateInsuranceManually(
                          patientIdentificationNo: '',
                          patientMobileNumber: '',
                          patientID: 0,
                        ),
                      ),
                    );
                  },
                  textColor: Colors.white,
                  color: CustomColors.accentColor,
                ),
              ),
            Text(
              "OR",
              style: TextStyle(
                fontSize: 16,
                letterSpacing: -0.48,
                fontWeight: FontWeight.w600,
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(18.0),
              child: Text(
                TranslationBase.of(context).habibCallCenter,
                style: TextStyle(
                  fontSize: 16,
                  letterSpacing: -0.48,
                  fontWeight: FontWeight.w600,
                ),
              ),
              // DefaultButton(
              //   TranslationBase.of(context).updateInsuranceManually,
              //   () {
              //     Navigator.pop(context);
              //     Navigator.push(
              //       context,
              //       FadePage(
              //         page: UpdateInsuranceManually(
              //           patientIdentificationNo: widget.identificationNo,
              //           patientMobileNumber: widget.mobileNo,
              //           patientID: num.parse(widget.fileNo),
              //         ),
              //       ),
              //     );
              //   },
              //   textColor: Colors.white,
              //   color: CustomColors.accentColor,
              // ),
            ),
            SizedBox(
              height: 25.0,
            ),
            Divider(),
            Row(
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: InkWell(
                    onTap: () {
                      Navigator.pop(context);
                    },
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Container(
                        child: Center(
                          child: Text(
                            TranslationBase.of(context).cancel.toUpperCase(),
                            style: TextStyle(
                              fontSize: 12,
                              letterSpacing: -0.48,
                              fontWeight: FontWeight.w600,
                              color: Colors.red,
                            ),
                          ),
                        ),
                      ),
                    ),
                  ),
                ),
                Container(
                  width: 1,
                  height: 30,
                  color: Colors.grey[500],
                ),
                Expanded(
                  flex: 1,
                  child: InkWell(
                    onTap: () {
                      if (file != null && image != null) {
                        Navigator.pop(context);
                        widget.image(file, image!);
                      } else {
                        AppToast.showErrorToast(message: TranslationBase.of(context).noInsuranceCardAttached);
                      }
                    },
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Center(
                          child: Text(
                        TranslationBase.of(context).ok.toUpperCase(),
                        style: TextStyle(
                          fontSize: 12,
                          letterSpacing: -0.48,
                          fontWeight: FontWeight.w600,
                        ),
                      )),
                    ),
                  ),
                ),
              ],
            )
          ],
        )
      ],
    );
  }
}
