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 'browse_history_controller.dart';

class BrowseHistoryView extends GetView<BrowseHistoryController> {
  const BrowseHistoryView({super.key});

  @override
  Widget build(BuildContext context) {
    Get.put(BrowseHistoryController());
    return GetBuilder<BrowseHistoryController>(
      builder: (logic) {
        return ViewStateWidget(
          viewState: controller.viewState,
          child: MediaQuery.removePadding(
            context: context,
            removeTop: true,
            child: Scrollbar(
              controller: controller.scrollController,
              child: MasonryGridView.count(
                controller: controller.scrollController,
                itemCount: controller.historyList.length,
                crossAxisCount: 2,
                mainAxisSpacing: 15.w,
                crossAxisSpacing: 15.w,
                padding: const EdgeInsets.fromLTRB(15, 20, 15, 0).w,
                physics: const BouncingScrollPhysics(),
                itemBuilder: (context, index) {
                  ImageModel item = controller.historyList[index];
                  return GestureDetector(
                    onTap: () => controller.toImageDetail(index),
                    onLongPress: () => controller.onLongPressImage(index),
                    child: ImageNetworkWidget(
                      url: item.imageUrl,
                      radius: 13.r,
                      aspectRatio: item.width! / item.height!,
                    ),
                  );
                },
              ),
            ),
          ),
        );
      },
    );
  }

}
