import 'package:flutter/material.dart';
import 'package:rasadyar_chicken/presentation/pages/role/view.dart';
import 'package:rasadyar_core/core.dart';

import '../../../widget/app_bar.dart';
import 'logic.dart';

class PoultryActionPage extends GetView<PoultryActionLogic> {
  PoultryActionPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: chickenAppBar(
        hasBack: false,
        hasFilter: false,
        hasSearch: false,
        isBase: false,
      ),
      body: Column(
        children: [
          Assets.images.poultryAction.image(
            height: 212.h,
            width: Get.width.w,
            fit: BoxFit.cover,
          ),
          ObxValue((data) {
            return Expanded(
              child: GridView.builder(
                physics: BouncingScrollPhysics(),
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 2,
                  mainAxisSpacing: 12.h,
                  crossAxisSpacing: 12.w,
                ),
                itemCount: data.length,
                hitTestBehavior: HitTestBehavior.opaque,
                itemBuilder: (BuildContext context, int index) {
                  var item = data[index];
                  return roleCardWithIcon(
                    title: item.title,
                    icon: item.icon,
                    onTap: () async {
                      Get.toNamed(item.route, id: 0);
                    },
                  );
                },
              ),
            );
          }, controller.items),
        ],
      ),
    );
  }
}

Widget roleCardWithIcon({
  required String title,
  required String icon,
  Function()? onTap,
  int? width,
  int? height,
}) {
  return Container(
    width: width?.w ?? 128.w,
    height: height?.h ?? 48.h,
    margin: EdgeInsets.all(8.w),
    decoration: BoxDecoration(
      borderRadius: BorderRadius.circular(8.r),
      border: Border.all(color: AppColor.blueNormal, width: 1.w),
    ),
    child: InkWell(
      onTap: onTap,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        spacing: 8,
        children: [
          SvgGenImage.vec(icon).svg(width: 46.w, height: 46.h,colorFilter: ColorFilter.mode(
            AppColor.blueNormal,
           BlendMode.srcIn
          )),

          Text(
            title,
            style: AppFonts.yekan12Bold.copyWith(color: AppColor.blueNormal),
          ),
        ],
      ),
    ),
  );
}
