import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:hello_wallpaper/common/components/image_network_widget.dart';
import 'package:hello_wallpaper/common/components/navigation_bar/base_appbar.dart';
import 'package:hello_wallpaper/models/wallpaper_model.dart';
import 'package:hello_wallpaper/modules/cls_det/cls_det_controller.dart';

class ClsDetView extends StatelessWidget {
  ClsDetView({super.key});

  final controller = Get.find<ClsDetController>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: BaseAppBar(controller.clsName),
      body: Scrollbar(
        child: MasonryGridView.count(
          crossAxisCount: 2,
          mainAxisSpacing: 10.w,
          crossAxisSpacing: 10.w,
          physics: const BouncingScrollPhysics(),
          padding: const EdgeInsets.symmetric(horizontal: 20).w,
          itemCount: controller.wallpaperDataList.length,
          itemBuilder: (context, index) {
            return _buildDiscoverItem(controller.wallpaperDataList[index], index);
          },
        ),
      ),
    );
  }

  Widget _buildDiscoverItem(WallpaperData item, int index) {
    return GestureDetector(
      onTap: () => controller.onTapItem(index),
      child: ImageNetworkWidget(
        url: item.previewThumb,
        radius: 8.r,
      ),
    );
  }
}
