import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tone_snap/components/base_scrollbar.dart';
import 'package:tone_snap/components/refresh/base_easyrefresh.dart';
import 'package:tone_snap/components/view_state_widget.dart';
import 'package:tone_snap/data/enum/music_type.dart';
import 'package:tone_snap/modules/sideb/widgets/music_item.dart';

import '../../../data/models/search_result_tabbar_model.dart';
import 'search_result_child_controller.dart';

class SearchResultChildView extends GetView<SearchResultChildController> {
  const SearchResultChildView({super.key, required this.searchResultTabBarModel});

  final SearchResultTabBarModel searchResultTabBarModel;

  @override
  String? get tag => '${searchResultTabBarModel.title}-${searchResultTabBarModel.params}';

  @override
  Widget build(BuildContext context) {
    Get.put(SearchResultChildController(), tag: tag);
    controller.setParams(searchResultTabBarModel.params);

    return Obx(() {
      return ViewStateWidget(
        viewState: controller.viewState.value,
        child: BaseEasyRefresh(
          controller: controller.refreshController,
          onLoad: controller.onLoad,
          child: BaseScrollbar(
            scrollController: controller.scrollController,
            child: Obx(() {
              return ListView.builder(
                controller: controller.scrollController,
                itemCount: controller.musicList.length,
                itemBuilder: (context, index) {
                  return MusicItem(
                    musicModel: controller.musicList[index],
                    showDownload: controller.musicList[index].value.musicType == MusicType.musicVideoTypeAtv.name,
                    showMore: controller.musicList[index].value.musicType == MusicType.musicVideoTypeAtv.name,
                    onTapItem: () => controller.onTapItem(controller.musicList[index].value),
                  );
                },
              );
            }),
          ),
        ),
      );
    });
  }
}
