import 'package:get/get.dart';
import 'package:tone_snap/components/view_state_widget.dart';
import 'package:tone_snap/data/models/music_model.dart';
import 'package:tone_snap/data/storage/love_songs_box.dart';
import 'package:tone_snap/routes/app_routes.dart';

class LoveSongsController extends GetxController {
  static LoveSongsController get to => Get.find<LoveSongsController>();
  var viewState = ViewState.loading.obs;
  var loveList = <Rx<MusicModel>>[].obs;

  @override
  void onReady() {
    super.onReady();
    getLoveList();
  }

  void getLoveList() {
    loveList.value = LoveSongsBox().getReversedList().map((e) => e.obs).toList();
    viewState.value = loveList.isNotEmpty ? ViewState.normal : ViewState.empty;
  }

  void onTapItem(MusicModel musicModel) {
    Get.toNamed(AppRoutes.playPage, arguments: {
      'videoId': musicModel.videoId,
      'playList': LoveSongsBox().getReversedList(),
    });
  }
}
