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/offline_box.dart';
import 'package:tone_snap/routes/app_routes.dart';

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

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

  void getOfflineList() {
    offlineList.value = OfflineBox().getReversedList().map((e) => e.obs).toList();
    viewState.value = offlineList.isNotEmpty ? ViewState.normal : ViewState.empty;
  }

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