import 'package:flutter/material.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';

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

class Grid extends StatelessWidget {
  final int crossAsis;
  final double ratio;
  final int ind;
  final controller = Get.put(InventoryInoutController());
  Grid(
      {super.key,
      required this.crossAsis,
      required this.ratio,
      required this.ind});
  @override
  Widget build(BuildContext context) {
    return Obx(() => controller.list[ind].isEmpty
        ? Center(
            child: Text(
              TextEnum.noInventoryInout,
              style: TextStyle(
                  color: AppTheme.black,
                  fontWeight: FontWeight.w600,
                  letterSpacing: ScreenAdaper.width(2),
                  fontSize: ScreenAdaper.sp(30)),
            ),
          )
        : GridView.builder(
            padding: const EdgeInsets.only(top: 40),
            itemCount: controller.list[ind].length,
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: crossAsis, childAspectRatio: ratio),
            itemBuilder: (context, index) {
              return InventoryInoutCard(
                index: index,
                ind: ind,
              );
            },
          ));
  }
}
