import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:niogu_app/core/constants/app_font_size.dart';
import 'package:niogu_app/core/utils/currency_format.dart';
import 'package:niogu_app/core/utils/time_zone.dart';
import 'package:niogu_app/features/report/transaction/domain/entities/transaction_report.dart';
import 'package:sizer/sizer.dart';

class TransactionItem extends StatelessWidget {
  final TransactionReportItem item;
  final VoidCallback onTap;
  const TransactionItem({super.key, required this.item, required this.onTap});

  @override
  Widget build(BuildContext context) {
    final bool isTablet = 100.w >= 600;
    return GestureDetector(
      onTap: onTap,
      child: Container(
        clipBehavior: Clip.antiAlias,
        margin: EdgeInsets.symmetric(horizontal: 5.w, vertical: 0.8.h),
        padding: EdgeInsets.all(3.w),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(2.5.w),
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.02),
              blurRadius: 5,
              offset: const Offset(0, 2),
            ),
          ],
        ),
        child: Row(
          children: [
            // Icon
            Container(
              padding: EdgeInsets.all(2.5.w),
              decoration: BoxDecoration(
                color: item.isIncome ? Colors.green[50] : Colors.red[50],
                borderRadius: BorderRadius.circular(2.5.w),
              ),
              child: Icon(
                item.isIncome
                    ? Icons.arrow_upward_rounded
                    : Icons.arrow_downward_rounded,
                color: item.isIncome ? Colors.green[700] : Colors.red[700],
                size: 5.w,
              ),
            ),

            SizedBox(width: 3.w),

            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    item.title,
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      fontSize: isTablet
                          ? AppFontSize.medium.sp
                          : AppFontSize.small.sp,
                      color: Colors.black87,
                    ),
                  ),
                  SizedBox(height: 0.75.h),
                  Text(
                    item.subtitle,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      color: Colors.grey,
                      fontSize: isTablet
                          ? (AppFontSize.medium - 1.25).sp
                          : (AppFontSize.small - 1.25).sp,
                    ),
                  ),
                ],
              ),
            ),

            Column(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                Text(
                  "${item.isIncome ? '+' : '-'} ${CurrencyFormat.formatToIdr(item.amount, 0)}",
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: isTablet
                        ? AppFontSize.medium.sp
                        : AppFontSize.small.sp,
                    color: item.isIncome ? Colors.green[700] : Colors.red[700],
                  ),
                ),
                SizedBox(height: 0.75.h),
                Text(
                  "${DateFormat('HH:mm').format(item.date)} ${TimeZone.getCurrentTimeZone()}",
                  style: TextStyle(
                    color: Colors.grey,
                    fontSize: isTablet
                        ? (AppFontSize.medium - 1.25).sp
                        : (AppFontSize.small - 1.25).sp,
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
