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:wallpaperx/common/components/image_network_widget.dart';
import 'package:wallpaperx/common/components/view_state_widget.dart';
import 'package:wallpaperx/entity/image_model.dart';
import 'package:wallpaperx/page/favorite/favorite_controller.dart';

class FavoriteView extends GetView<FavoriteController> {
  const FavoriteView({super.key});

  @override
  Widget build(BuildContext context) {
    Get.put(FavoriteController());
    return Obx(
      () => Column(
        children: [
          Expanded(
            child: ViewStateWidget(
              viewState: controller.viewState,
              child: MediaQuery.removePadding(
                context: context,
                removeTop: true,
                child: Scrollbar(
                  controller: controller.scrollController,
                  child: MasonryGridView.count(
                    controller: controller.scrollController,
                    itemCount: controller.favoriteList.length,
                    crossAxisCount: 2,
                    mainAxisSpacing: 20.w,
                    crossAxisSpacing: 20.w,
                    padding: const EdgeInsets.fromLTRB(16, 20, 16, 0).w,
                    physics: const BouncingScrollPhysics(),
                    itemBuilder: (context, index) {
                      ImageModel item = controller.favoriteList[index];
                      return GestureDetector(
                        onTap: () => controller.onTapItem(index),
                        onLongPress: () => controller.onLongPress(index),
                        child: ImageNetworkWidget(
                          url: item.imageUrl,
                          radius: 14.r,
                          aspectRatio: item.width! / item.height!,
                        ),
                      );
                    },
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
