import 'package:clean/base/base_controller.dart';
import 'package:clean/base/base_photo_controller.dart';
import 'package:clean/data/bean/photos_type.dart';
import 'package:clean/module/image_picker/image_picker_util.dart';
import 'package:clean/module/people_photo/photo_group.dart';
import 'package:clean/module/photo_preview/photo_preview_view.dart';
import 'package:clean/utils/toast_util.dart';
import 'package:get/get.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';

class ScreenShotsController extends BasePhotoController {
  late String titleName;

  @override
  void onInit() {
    print("ScreenShotsController onInit");
    _getArgs();
    super.onInit();
  }

  void _getArgs() {


    print("ScreenShotsController _getArgs");
    final args = Get.arguments;
    if (args != null) {
      titleName = args["titleName"];
    }
    if (titleName.isEmpty) {
      ToastUtil.show("titleName is empty");
      Get.back();
    }

  }


  @override
  void loadPhotos() {
    photoGroups.clear();

    if (titleName == "Screenshots") {
      final photoGroup = ImagePickerUtil.screenshotPhotos;
      if (photoGroup.isNotEmpty) {
        photoGroups.add(PhotoGroup(
          isSelected: false,
          images: photoGroup,
        ));
      }
      selectedPhotosIds.assignAll(ImagePickerUtil.selectedScreenshotPhotosIds);
    } else if (titleName == "Blurry") {
      final photoGroup = ImagePickerUtil.blurryPhotos;
      if (photoGroup.isNotEmpty) {
        photoGroups.add(PhotoGroup(
          isSelected: false,
          images: photoGroup,
        ));
      }
      selectedPhotosIds.assignAll(ImagePickerUtil.selectedBlurryPhotosIds);
    }
  }

  clickBack() {
    print("ScreenShotsController titleName $titleName clickBack ");
    updateSelections(selectedPhotosIds);
    Get.back();
  }

  @override
  PhotosType getPhotosType() => titleName == "Screenshots" ? PhotosType.screenshots : PhotosType.blurryPhotos;
}