import 'package:flutter/material.dart';
import 'package:kmobile/l10n/app_localizations.dart';
import 'package:material_symbols_icons/symbols.dart';

class TransactionDetailsScreen extends StatelessWidget {
  final dynamic transaction;

  const TransactionDetailsScreen({super.key, required this.transaction});

  @override
  Widget build(BuildContext context) {
    final bool isCredit = transaction.type?.toUpperCase() == 'CR';

    return Scaffold(
      appBar:
          AppBar(title: Text(AppLocalizations.of(context).transactionDetails)),
      body: Stack(
        children: [
          Padding(
            padding: const EdgeInsets.all(16.0),
            child: Column(
              children: [
                Expanded(
                  flex: 3,
                  child: Center(
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        // Amount + icon + Share Button
                        Row(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Text(
                              "₹ ${transaction.amount}",
                              style: const TextStyle(
                                fontSize: 40,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                            const SizedBox(width: 8),
                            Icon(
                              isCredit
                                  ? Symbols.call_received
                                  : Symbols.call_made,
                              color: isCredit
                                  ? const Color(0xFF10BB10)
                                  : Theme.of(context).colorScheme.error,
                              size: 28,
                            ),
                          ],
                        ),
                        const SizedBox(height: 8),
                        // Date centered
                        Text(
                          transaction.date ?? "",
                          style: TextStyle(
                            fontSize: 16,
                            color: Theme.of(context).textTheme.bodySmall?.color,
                          ),
                          textAlign: TextAlign.center,
                        ),
                      ],
                    ),
                  ),
                ),
                Divider(color: Theme.of(context).dividerColor),
                Expanded(
                  flex: 5,
                  child: ListView(
                    children: [
                      _buildDetailRow(
                          AppLocalizations.of(context).transactionType,
                          transaction.type ?? ""),
                      _buildDetailRow(AppLocalizations.of(context).transferType,
                          transaction.name.split("/").first ?? ""),
                      // if (transaction.name.length > 12) ...[
                      //   _buildDetailRow(AppLocalizations.of(context).utrNo,
                      //       transaction.name.split("= ")[1].split(" ")[0] ?? ""),
                      //   _buildDetailRow(
                      //       AppLocalizations.of(context).beneficiaryAccountNo,
                      //       transaction.name.split("A/C ").last ?? "")
                      // ]
                      _buildDetailRow(AppLocalizations.of(context).details,
                          transaction.name),
                    ],
                  ),
                ),
              ],
            ),
          ),
          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
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildDetailRow(String label, String value) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 8.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "$label: ",
            style: const TextStyle(
              fontWeight: FontWeight.bold,
              fontSize: 17,
            ),
          ),
          const SizedBox(height: 30),
          Expanded(
            child: Text(
              value,
              style: const TextStyle(fontSize: 16),
            ),
          ),
        ],
      ),
    );
  }
}
