import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tone_snap/generated/assets.dart';
import 'package:tone_snap/modules/musicoo/home/home_view.dart';
import 'package:tone_snap/modules/musicoo/me/me_view.dart';
import 'package:tone_snap/modules/musicoo/search_music/search_music_view.dart';

class InitialController extends GetxController {
  static InitialController get to => Get.find<InitialController>();
  late PageController pageController;
  final pages = [
    PageItem([Assets.musicooBnb1Unselected, Assets.musicooBnb1Selected], const HomeView()),
    PageItem([Assets.musicooBnb2Unselected, Assets.musicooBnb2Selected], const SearchMusicView()),
    PageItem([Assets.musicooBnb3Unselected, Assets.musicooBnb3Selected], const MeView()),
  ];
  var currentIndex = 0.obs;

  @override
  void onInit() {
    super.onInit();
    pageController = PageController(initialPage: currentIndex.value);
  }

  @override
  void onClose() {
    pageController.dispose();
    super.onClose();
  }

  Future<void> onBottomAppBarItemChanged(int index) async {
    // if (index == 1) {
    //   await PlayerController.to.stopPlay();
    //   Get.toNamed(AppRoutes.uploadMethod);
    // } else {
    //   if (index == 2) _refreshMe();
    //   currentIndex.value = index;
    //   pageController.jumpToPage(index);
    // }
    currentIndex.value = index;
    pageController.jumpToPage(index);
  }
}

class PageItem {
  late final List<String> icons;
  late final StatelessWidget widget;

  PageItem(this.icons, this.widget);
}

