import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class SelectionDialog<T> extends StatefulWidget{
  final String title;
  final List<T> items;
  BuildContext context;

  SelectionDialog(this.context,{required this.title, required this.items});

  @override
  State<StatefulWidget> createState() => SelectionDialogState();


  Future<Future<T?>> show() async{
    return showDialog<T>(context: context, builder: (ctx){
      return this;
    });
  }
}

class SelectionDialogState extends State<SelectionDialog>{

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
        body: Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Container(
           margin: EdgeInsets.all(20),
          decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(15)),
          child: Column(
            children: [
              Padding(
                padding: const EdgeInsets.all(15),
                child: Text(widget.title,),
              ),

              Container(height: 0.5, color: Colors.grey,),

              ListView.separated(
                  shrinkWrap: true,
                  padding: EdgeInsets.all(10),
                  itemCount: widget.items.length,
                  itemBuilder: (ctx,idx) => item(idx),
                  separatorBuilder: (ctx,idx) => Container(height: 0.25, color: Colors.grey.withOpacity(0.7),))
            ],
          ),
        )
      ],
    )
    );
  }

  Widget item(int idx){
    var model = widget.items[idx];
    return InkWell(
      onTap: (){
        Navigator.pop(context, model);
      },
      child: Container(
        padding: EdgeInsets.all(20),
        child: Text(model.toString(), style: TextStyle(color: Colors.black)),
      ),
    );
  }

}