import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:sk_base_mobile/util/media_util.dart';
import 'package:sk_base_mobile/app_theme.dart';

class PhotoPickerUtil {
  showPicker({Function? callback}) async {
    return showCupertinoModalPopup(
        context: Get.context!,
        builder: (BuildContext ctx) {
          return CupertinoActionSheet(
            title: const Text('Change avatar'),
            cancelButton: CupertinoActionSheetAction(
                onPressed: () {
                  Get.back();
                },
                child: const Text(
                  'Cancel',
                  style: TextStyle(color: Color(0xffcdcdcd)),
                )),
            actions: ['Photography', 'Album']
                .map((item) => CupertinoActionSheetAction(
                    onPressed: () async {
                      Get.back();
                      XFile? pickedFile = item == 'Photography'
                          ? await MediaUtil().getImageFromCamera()
                          : await MediaUtil().getImageFromGallery();
                      if (pickedFile != null) {
                        if (callback != null) {
                          callback(pickedFile);
                        }
                      }
                    },
                    child: Text(
                      item,
                      style: const TextStyle(color: AppTheme.primaryColor),
                    )))
                .toList(),
          );
        });
  }
}
