import 'package:flutter/material.dart';
import 'package:environment_monitoring_app/screens/marine/manual/marine_manual_report.dart';

class MarineManualPreSampling extends StatelessWidget {
  const MarineManualPreSampling({super.key});

  // This list includes the pre-sampling items, excluding the NPE report.
  // The routes point to the same screens used by the report module.
  final List<ReportItem> _preSamplingItems = const [
    ReportItem(
      icon: Icons.biotech_rounded,
      label: "Sonde Calibration",
      formCode: "F-MM02",
      route: '/marine/manual/report/calibration',
    ),
    ReportItem(
      icon: Icons.checklist_rtl_rounded,
      label: "Pre-Departure & Safety Checklist",
      formCode: "F-MM03",
      route: '/marine/manual/report/pre-departure',
    ),
    ReportItem(
      icon: Icons.build_circle_outlined,
      label: "Equipment Maintenance",
      formCode: "F-MM01",
      route: '/marine/manual/report/maintenance',
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Marine Pre-Sampling"),
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(24.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              "Select a Pre-Sampling Form",
              style: Theme.of(context).textTheme.headlineSmall?.copyWith(
                fontWeight: FontWeight.bold,
              ),
            ),
            const SizedBox(height: 24),
            GridView.builder(
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 2,
                crossAxisSpacing: 16.0,
                mainAxisSpacing: 16.0,
                childAspectRatio: 1.2, // Adjusted for better text fit
              ),
              itemCount: _preSamplingItems.length,
              itemBuilder: (context, index) {
                final item = _preSamplingItems[index];
                return _buildReportCard(context, item);
              },
            ),
          ],
        ),
      ),
    );
  }

  // This widget is copied from MarineManualReportHomePage for visual consistency.
  Widget _buildReportCard(BuildContext context, ReportItem item) {
    return InkWell(
      onTap: () {
        Navigator.pushNamed(context, item.route);
      },
      borderRadius: BorderRadius.circular(12),
      child: Card(
        elevation: 4,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(12),
          side: const BorderSide(color: Colors.white24, width: 1),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Icon(item.icon, size: 40, color: Theme.of(context).colorScheme.secondary),
            const SizedBox(height: 12),
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 8.0),
              child: Text(
                item.label,
                style: Theme.of(context).textTheme.titleMedium,
                textAlign: TextAlign.center,
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              ),
            ),
            const SizedBox(height: 4),
            Text(
              item.formCode, // Displaying the form code
              style: Theme.of(context).textTheme.bodySmall?.copyWith(color: Colors.grey[400]),
            ),
          ],
        ),
      ),
    );
  }
}