import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/EReferral/search_criteria_model.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

// ignore: must_be_immutable
class SelectSearchCriteriaDialog extends StatefulWidget {
  List<SearchCriteriaModel> searchCriteria  = [
     SearchCriteriaModel(name: "Identification Number",nameAr:"رقم المحول",value: 1),
     SearchCriteriaModel(name: "Referral Number",nameAr:"رقم المحول",value: 2),
  ];
  final Function(SearchCriteriaModel) onValueSelected;
  SearchCriteriaModel selectedCriteria;

  SelectSearchCriteriaDialog(
      {Key key, this.onValueSelected, this.selectedCriteria});

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

class _SelectSearchCriteriaDialogState extends State<SelectSearchCriteriaDialog> {
  @override
  void initState() {
    super.initState();
    widget.selectedCriteria = widget.selectedCriteria ?? widget.searchCriteria[0];
  }

  @override
  Widget build(BuildContext context) {
    return SimpleDialog(
      children: [
        Column(
          children: [
            Texts(" Select Search Criteria", fontSize: 20,),
            Divider(),
            ...List.generate(
              widget.searchCriteria.length,
              (index) => Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  SizedBox(
                    height: 2,
                  ),
                  Row(
                    children: <Widget>[
                      Expanded(
                        flex: 1,
                        child: InkWell(
                          onTap: () {
                            setState(() {
                              widget.selectedCriteria = widget.searchCriteria[index];
                            });
                          },
                          child: ListTile(
                            title: Text(widget.searchCriteria[index].name),
                            leading: Radio(
                              value: widget.searchCriteria[index],
                              groupValue: widget.selectedCriteria,
                              activeColor: Colors.red[800],
                              onChanged: (value) {
                                setState(() {
                                  widget.selectedCriteria = 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: Texts(
                            TranslationBase.of(context).cancel.toUpperCase(),
                            color: Colors.red,
                          ),
                        ),
                      ),
                    ),
                  ),
                ),
                Container(
                  width: 1,
                  height: 30,
                  color: Colors.grey[500],
                ),
                Expanded(
                  flex: 1,
                  child: InkWell(
                    onTap: () {
                      widget.onValueSelected(widget.selectedCriteria);
                      Navigator.pop(context);
                    },
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Center(
                          child: Texts(
                            TranslationBase.of(context).ok,
                        fontWeight: FontWeight.w400,
                      )),
                    ),
                  ),
                ),
              ],
            )
          ],
        )
      ],
    );
  }
}




