import 'package:flutter/material.dart';
import 'package:nfc_manager/nfc_manager.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/views/widgets/item_views/info_header_widget.dart';

class NonHmgEmployeeSwipeView extends StatefulWidget {
  NonHmgEmployeeSwipeView({Key? key}) : super(key: key);

  @override
  _NonHmgEmployeeSwipeViewState createState() {
    return _NonHmgEmployeeSwipeViewState();
  }
}

class _NonHmgEmployeeSwipeViewState extends State<NonHmgEmployeeSwipeView> {
  bool isNfcEnabled = false;

  @override
  void initState() {
    super.initState();
    checkForNfcAndLocationPermission();
  }

  void checkForNfcAndLocationPermission() async {
    try {
      isNfcEnabled = await NfcManager.instance.isAvailable();
    } catch (e) {
      isNfcEnabled = false;
    }
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(16),
      margin: const EdgeInsets.only(top: 21),
      decoration: BoxDecoration(borderRadius: BorderRadius.circular(30), color: Colors.white, border: Border.all(color: AppColor.white936.withOpacity(.05), width: 1)),
      width: double.infinity,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          InfoHeader16Widget( "Mark Attendance"),
          Text(
            "Mark Attendance",
            style: AppTextStyles.heading5.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
          ),
          GridView(
            physics: const NeverScrollableScrollPhysics(),
            shrinkWrap: true,
            padding: const EdgeInsets.only(bottom: 0, top: 16),
            gridDelegate:
                SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: (MediaQuery.of(context).size.width < 550) ? 3 : 5, childAspectRatio: 1 / 1, crossAxisSpacing: 16, mainAxisSpacing: 16),
            children: <Widget>[
              gridItem("Nfc", Icons.nfc, isNfcEnabled).onPress(isNfcEnabled ? () {} : null),
              gridItem("Qr Scan", Icons.qr_code, true).onPress(() {}),
            ],
          )
        ],
      ),
    );
  }

  Widget gridItem(String label, IconData iconData, bool enable) {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(borderRadius: BorderRadius.circular(25), color: AppColor.white30, border: Border.all(color: AppColor.white936.withOpacity(.03), width: 1)),
      alignment: Alignment.center,
      child: Column(
        //mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          Icon(iconData, color: enable ? AppColor.black35 : Colors.grey),
          Text(
            label,
            style: AppTextStyles.heading6.copyWith(color: enable ? AppColor.black35 : Colors.grey),
          ),
        ],
      ),
    );
  }
}
