import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:sk_base_mobile/app_theme.dart';
import 'package:sk_base_mobile/constants/constants.dart';
import 'package:sk_base_mobile/screens/inventory_inout/components/responsive.dart';
import 'package:sk_base_mobile/screens/inventory_inout/components/inventory_inout_card.dart';
import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout_controller.dart';
import 'package:sk_base_mobile/util/util.dart';
import 'package:sk_base_mobile/widgets/loading_indicator.dart';

class InventoryInoutViewItem extends StatelessWidget {
  const InventoryInoutViewItem({super.key, required this.index});
  final int index;
  @override
  Widget build(BuildContext context) {
    return Responsive(
        tablet: Grid(
          columnNum: 2,
          ind: index,
        ),
        largeTablet: Grid(
          columnNum: 3,
          ind: index,
        ),
        mobile: Grid(
          columnNum: 1,
          ind: index,
        ));
  }
}

class Grid extends StatelessWidget {
  final int columnNum;
  int ind;
  final controller = Get.find<InventoryInoutController>();
  Grid({super.key, required this.columnNum, required this.ind});
  @override
  Widget build(BuildContext context) {
    if (controller.currentIndex.value != ind) {
      ind = controller.currentIndex.value;
    }
    return Obx(
      () => controller.loading.value
          ? const LoadingIndicator(common: true)
          : controller.list[ind].isEmpty
              ? Center(
                  child: Text(
                    TextEnum.noInventoryInout,
                    style: TextStyle(
                        color: AppTheme.black,
                        fontWeight: FontWeight.w600,
                        letterSpacing: ScreenAdaper.width(2),
                        fontSize: ScreenAdaper.height(30)),
                  ),
                )
              : MasonryGridView.count(
                  padding: EdgeInsets.only(top: ScreenAdaper.height(60)),
                  crossAxisCount: columnNum,
                  itemCount: controller.list[ind].length,
                  itemBuilder: (context, index) {
                    return InventoryInoutCard(
                      index: index,
                      ind: ind,
                    );
                  },
                ),
    );
    // : GridView.count(
    //     padding: const EdgeInsets.only(top: 40),
    //     crossAxisCount: columnNum,
    //     children: List.generate(controller.list[ind].length, (index) {
    //       return InventoryInoutCard(
    //         index: index,
    //         ind: ind,
    //       );
    //     }),
    //   ));
  }
}
