import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:flutter/material.dart';

class RadioSelectionDialogModel {
  String title;
  int value;

  RadioSelectionDialogModel(this.title, this.value);
}

class RadioSelectionDialog extends StatefulWidget {
  final Function(int) onValueSelected;
  final List<RadioSelectionDialogModel> listData;
  final int selectedIndex;

  const RadioSelectionDialog({Key key, this.onValueSelected, this.listData, this.selectedIndex}) : super(key: key);

  @override
  State createState() => new RadioSelectionDialogState();
}

class RadioSelectionDialogState extends State<RadioSelectionDialog> {
  int selectedIndex;

  @override
  void initState() {
    selectedIndex = widget.selectedIndex ?? 0;
    super.initState();
  }

  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: Colors.white,
      shape: RoundedRectangleBorder(),
      insetPadding: EdgeInsets.only(left: 21, right: 21),
      child: Padding(
        padding: EdgeInsets.only(left: 20, right: 20, top: 18, bottom: 28),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: [
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(
                  child: Padding(
                    padding: const EdgeInsets.only(top: 16.0),
                    child: Text(
                      TranslationBase.of(context).select,
                      style: TextStyle(fontSize: 24, fontWeight: FontWeight.w600, color: Color(0xff2B353E), height: 35 / 24, letterSpacing: -0.96),
                    ),
                  ),
                ),
                IconButton(
                  padding: EdgeInsets.zero,
                  icon: Icon(Icons.close),
                  color: Color(0xff2B353E),
                  constraints: BoxConstraints(),
                  onPressed: () {
                    Navigator.pop(context);
                  },
                )
              ],
            ),
            SizedBox(height: 21),
            Text(
              TranslationBase.of(context).pleaseSelectFromBelowOptions,
              style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.56),
            ),
            ListView.separated(
                physics: NeverScrollableScrollPhysics(),
                shrinkWrap: true,
                padding: EdgeInsets.only(bottom: 42, top: 10),
                itemBuilder: (context, index) {
                  return Row(
                    children: [
                      SizedBox(
                        width: 22,
                        height: 22,
                        child: Radio(
                          value: widget.listData[index].value,
                          groupValue: selectedIndex,
                          onChanged: (value) {
                            setState(() {
                              selectedIndex = value;
                            });
                          },
                        ),
                      ),
                      SizedBox(width: 8),
                      Text(
                        widget.listData[index].title,
                        style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xff575757), letterSpacing: -0.56),
                      ),
                    ],
                  );
                },
                separatorBuilder: (context, index) => SizedBox(height: 10),
                itemCount: widget.listData.length),
            Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Expanded(
                  child: DefaultButton(
                    TranslationBase.of(context).save,
                    () {
                      Navigator.pop(context);
                      widget.onValueSelected(selectedIndex);
                    },
                    color: Color(0xff349745),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
