import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hmg_nurses/generated/locale_keys.g.dart';
import 'package:sizer/sizer.dart';

class CustomCupertinoPicker {
  static TextStyle textStyle(context) => TextStyle(color: Theme.of(context).primaryColor);

  static int cupertinoPickerIndex = 0;

  static buildPickerItems(context, List items, onSelectFun) {
    return CupertinoPicker(
      magnification: 1.5,
      scrollController: FixedExtentScrollController(initialItem: cupertinoPickerIndex),
      itemExtent: 25,
      looping: false,
      onSelectedItemChanged: (int index) {
        cupertinoPickerIndex = index;
      },
      children: items.map((item) {
        return Text(
          '${item.facilityName}',
          style: TextStyle(fontSize: 12.sp),
        );
      }).toList(),
    );
  }

  static showCupertinoPicker(context, List items, onSelectFun) {
    showModalBottomSheet(
        isDismissible: false,
        context: context,
        builder: (BuildContext builder) {
          return Container(
            height: 40.h,
            color: const Color(0xfff7f7f7),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.end,
              children: <Widget>[
                Container(
                  color: const Color(0xfff7f7f7),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: <Widget>[
                      CupertinoButton(
                        child: Text(LocaleKeys.userID.tr(), style: textStyle(context)),
                        onPressed: () {
                          Navigator.pop(context);
                        },
                      ),
                      CupertinoButton(
                        child: Text(
                          LocaleKeys.userID.tr(),
                          style: textStyle(context),
                        ),
                        onPressed: () {
                          Navigator.pop(context);
                          onSelectFun(cupertinoPickerIndex);
                        },
                      )
                    ],
                  ),
                ),
                Container(height: 3.h, color: const Color(0xfff7f7f7), child: buildPickerItems(context, items, onSelectFun))
              ],
            ),
          );
        });
  }
}
