import 'package:flutter/material.dart';
import 'package:niogu_app/core/constants/app_color.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/enums/payment_status.dart';
import 'package:niogu_app/features/report/transaction/domain/entities/transaction_report.dart';
import 'package:niogu_app/features/report/transaction/presentation/widgets/summary_row.dart';
import 'package:sizer/sizer.dart';

class PaymentPurchaseSummary extends StatelessWidget {
  final PurchaseDetail purchaseDetail;
  const PaymentPurchaseSummary({super.key, required this.purchaseDetail});

  @override
  Widget build(BuildContext context) {
    final bool isTablet = 100.w > 600;

    final paymentStatus = purchaseDetail.paymentStatus;

    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 5.w, vertical: 2.h),
      child: Column(
        children: [
          SummaryRow(
            label: "Subtotal",
            value: CurrencyFormat.formatToIdr(purchaseDetail.totalPurchase, 0),
          ),
          if (purchaseDetail.discount > 0)
            SummaryRow(
              label: "Diskon",
              value: CurrencyFormat.formatToIdr(-purchaseDetail.discount, 0),
              color: Colors.red,
            ),
          if (purchaseDetail.tax > 0)
            SummaryRow(
              label: "Pajak",
              value: "+" + CurrencyFormat.formatToIdr(purchaseDetail.tax, 0),
              color: Colors.green,
            ),

          Divider(height: 3.h, color: Colors.grey.shade200),

          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                "TOTAL",
                style: TextStyle(
                  fontSize: isTablet
                      ? AppFontSize.medium.sp
                      : AppFontSize.small.sp,
                  fontWeight: FontWeight.bold,
                ),
              ),
              Text(
                CurrencyFormat.formatToIdr(purchaseDetail.totalAmount, 0),
                style: TextStyle(
                  fontSize: isTablet
                      ? AppFontSize.medium.sp
                      : AppFontSize.small.sp,
                  fontWeight: FontWeight.bold,
                  color: AppColor.primaryColor,
                ),
              ),
            ],
          ),

          SizedBox(height: 2.h),

          if (paymentStatus == PaymentStatus.paid) ...[
            SummaryRow(
              label: "Bayar Tunai",
              value: CurrencyFormat.formatToIdr(purchaseDetail.payAmount, 0),
            ),
            SizedBox(height: 0.5.h),
            SummaryRow(
              label: "Kembali",
              value: CurrencyFormat.formatToIdr(purchaseDetail.changeAmount, 0),
              isBold: true,
            ),
          ] else if (paymentStatus == PaymentStatus.partial) ...[
            SummaryRow(
              label: "Bayar Sebagian",
              value: CurrencyFormat.formatToIdr(purchaseDetail.payAmount, 0),
            ),
            SizedBox(height: 0.5.h),
            SummaryRow(
              label: "Kurang Bayar",
              value: CurrencyFormat.formatToIdr(
                purchaseDetail.underPaymentAmount,
                0,
              ),
              isBold: true,
            ),
          ] else ...[
            SummaryRow(
              label: "Hutang",
              value: CurrencyFormat.formatToIdr(purchaseDetail.debtAmount, 0),
            ),
          ],
        ],
      ),
    );
  }
}
