import 'package:flutter/material.dart';
import 'package:aves/model/entry/entry.dart';
import 'package:provider/provider.dart';
import 'package:aves/widgets/cast/cast_controller.dart';

class CastActions {
  static List<AvesEntry> getEntries(BuildContext context) {
    try {
      final selection = context.read<Selection<AvesEntry>>();
      final selected = selection.selectedItems.toList();
      if (selected.isNotEmpty) return selected;
    } catch (_) {}

    try {
      final lens = context.read<CollectionLens>();
      final lensEntries = lens.sortedEntries;
      if (lensEntries != null && lensEntries.isNotEmpty) {
        return List<AvesEntry>.from(lensEntries);
      }
    } catch (_) {}

    try {
      final single = Provider.of<AvesEntry>(context, listen: false);
      return [single];
    } catch (_) {}

    return [];
  }
}
