import 'package:diplomaticquarterapp/models/FamilyFiles/GetAllSharedRecordByStatusResponse.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../../../../Constants.dart';

class SelectPatientFamilyDialog extends StatefulWidget {
  final List<GetAllSharedRecordsByStatusList> getAllSharedRecordsByStatusList;
  final Function(GetAllSharedRecordsByStatusList) onValueSelected;
  GetAllSharedRecordsByStatusList selectedPatientFamily;

  List<GetAllSharedRecordsByStatusList> getAllSharedRecordsByStatusApprovedList = new List();

  SelectPatientFamilyDialog({Key key, this.getAllSharedRecordsByStatusList, this.onValueSelected, this.selectedPatientFamily});

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

class _SelectPatientFamilyDialogState extends State<SelectPatientFamilyDialog> {
  @override
  void initState() {
    super.initState();
    widget.selectedPatientFamily = widget.selectedPatientFamily ?? widget.getAllSharedRecordsByStatusList[0];

    if (widget.getAllSharedRecordsByStatusList.isNotEmpty)
      widget.getAllSharedRecordsByStatusList.forEach((element) {
        if (element.status == 3) widget.getAllSharedRecordsByStatusApprovedList.add(element);
      });
  }

  @override
  Widget build(BuildContext context) {
    return SimpleDialog(
      children: [
        Column(
          children: [
            Divider(),
            ...List.generate(
              widget.getAllSharedRecordsByStatusApprovedList.length,
              (index) => Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  SizedBox(
                    height: 2,
                  ),
                  Row(
                    children: <Widget>[
                      Expanded(
                        flex: 1,
                        child: InkWell(
                          onTap: () {
                            setState(() {
                              widget.selectedPatientFamily = widget.getAllSharedRecordsByStatusApprovedList[index];
                            });
                          },
                          child: ListTile(
                            title: Text(
                              widget.getAllSharedRecordsByStatusApprovedList[index].patientName,
                              style: TextStyle(
                                fontSize: 14,
                                fontWeight: FontWeight.w600,
                                letterSpacing: -0.46,
                              ),
                            ),
                            leading: Radio(
                              value: widget.getAllSharedRecordsByStatusApprovedList[index],
                              groupValue: widget.selectedPatientFamily,
                              activeColor: secondaryColor,
                              onChanged: (value) {
                                setState(() {
                                  widget.selectedPatientFamily = value;
                                });
                              },
                            ),
                          ),
                        ),
                      )
                    ],
                  ),
                  SizedBox(
                    height: 5.0,
                  ),
                ],
              ),
            ),
            SizedBox(
              height: 5.0,
            ),
            Row(
              // mainAxisAlignment: MainAxisAlignment.spaceBetween,
              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: 14,
                              fontWeight: FontWeight.w600,
                              letterSpacing: -0.46,
                              color: Colors.red,
                            ),
                          ),
                        ),
                      ),
                    ),
                  ),
                ),
                Container(
                  width: 1,
                  height: 30,
                  color: Colors.grey[500],
                ),
                Expanded(
                  flex: 1,
                  child: InkWell(
                    onTap: () {
                      widget.onValueSelected(widget.selectedPatientFamily);
                      Navigator.pop(context);
                    },
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Center(
                        child: Text(
                          TranslationBase.of(context).ok,
                          style: TextStyle(
                            fontSize: 14,
                            fontWeight: FontWeight.w600,
                            letterSpacing: -0.46,
                          ),
                        ),
                      ),
                    ),
                  ),
                ),
              ],
            )
          ],
        )
      ],
    );
  }
}
