import 'package:flutter/material.dart';
import 'package:kmobile/data/models/user.dart';
import 'package:kmobile/features/cheque/screens/cheque_enquiry_screen.dart';
import 'package:kmobile/features/cheque/screens/positive_pay_screen.dart';
import 'package:kmobile/features/cheque/screens/revoke_stop_screen.dart';
import 'package:kmobile/features/cheque/screens/stop_cheque_screen.dart';
import 'package:material_symbols_icons/material_symbols_icons.dart';
import '../../../l10n/app_localizations.dart';

class ChequeManagementScreen extends StatefulWidget {
  final List<User> users;
  final int selectedIndex;
  const ChequeManagementScreen({
    super.key,
    required this.users,
    required this.selectedIndex,
  });

  @override
  State<ChequeManagementScreen> createState() => _ChequeManagementScreen();
}

class _ChequeManagementScreen extends State<ChequeManagementScreen> {
  List<User> get users => widget.users;
  int get selectedAccountIndex => widget.selectedIndex;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          AppLocalizations.of(context).chequeManagement,
        ),
        centerTitle: false,
      ),
      body: Stack(
        children: [
          Padding(
            padding: const EdgeInsets.symmetric(vertical: 16.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                Expanded(
                  child: ChequeManagementCardTile(
                    icon: Symbols.payments,
                    label: AppLocalizations.of(context).chequeEnquiryTitle,
                    onTap: () {
                      Navigator.push(
                        context,
                        MaterialPageRoute(
                          builder: (context) => ChequeEnquiryScreen(
                            users: users,
                            selectedIndex: selectedAccountIndex,
                          ),
                        ),
                      );
                    },
                  ),
                ),
                Expanded(
                  child: ChequeManagementCardTile(
                    icon: Symbols.block_sharp,
                    label: AppLocalizations.of(context).stopCheque,
                    onTap: () {
                      Navigator.push(
                        context,
                        MaterialPageRoute(
                          builder: (context) => StopChequeScreen(
                            users: users,
                            selectedIndex: selectedAccountIndex,
                          ),
                        ),
                      );
                    },
                  ),
                ),
                Expanded(
                  child: ChequeManagementCardTile(
                    icon: Symbols.stop_circle,
                    label: AppLocalizations.of(context).revokeStop,
                    onTap: () {
                      Navigator.push(
                        context,
                        MaterialPageRoute(
                          builder: (context) => RevokeStopChequeScreen(
                            users: users,
                            selectedIndex: selectedAccountIndex,
                          ),
                        ),
                      );
                    },
                  ),
                ),
                Expanded(
                  child: ChequeManagementCardTile(
                    icon: Symbols.check_circle, // Using check_circle for Positive Pay
                    label: AppLocalizations.of(context).positivePayTitle,
                    onTap: () {
                      Navigator.push(
                        context,
                        MaterialPageRoute(
                          builder: (context) => PositivePayScreen(
                            users: users,
                            selectedIndex: selectedAccountIndex,
                          ),
                        ),
                      );
                    },
                  ),
                ),
              ],
            ),
          ),
          IgnorePointer(
            child: Center(
              child: Opacity(
                opacity: 0.07, // Reduced opacity
                child: ClipOval(
                  child: Image.asset(
                    'assets/images/logo.png',
                    width: 200, // Adjust size as needed
                    height: 200, // Adjust size as needed
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

class ChequeManagementCardTile extends StatelessWidget {
  final IconData icon;
  final String label;
  final VoidCallback onTap;
  final bool disable;

  const ChequeManagementCardTile({
    super.key,
    required this.icon,
    required this.label,
    required this.onTap,
    this.disable = false,
  });

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    return Card(
      margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      elevation: 4, // Add some elevation for better visual separation
      child: InkWell(
        onTap:
            disable ? null : onTap, // Disable InkWell if the tile is disabled
        borderRadius: BorderRadius.circular(12.0),
        child: Padding(
          padding: const EdgeInsets.symmetric(vertical: 24.0, horizontal: 16.0),
          child: Center(
            child: SingleChildScrollView(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Icon(
                    icon,
                    size: 48, // Make icon larger
                    color: disable
                        ? theme.disabledColor
                        : theme.colorScheme.primary,
                  ),
                  const SizedBox(height: 12),
                  Text(
                    label,
                    textAlign: TextAlign.center,
                    style: theme.textTheme.titleLarge?.copyWith(
                      fontWeight: FontWeight.bold,
                      color: disable
                          ? theme.disabledColor
                          : theme.colorScheme.onSurface,
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}