import 'package:comwell_key_app/check_out/components/accept_terms_toggle.dart';
import 'package:comwell_key_app/check_out/components/apply_club_points.dart';
import 'package:comwell_key_app/check_out/components/checkout_itemized_bill.dart';
import 'package:comwell_key_app/check_out/components/send_receipt.dart';
import 'package:comwell_key_app/services/models/booking_dto.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:comwell_key_app/utils/l10n_utils.dart';
import 'package:flutter/material.dart';

class PaymentPageTemplate extends StatelessWidget {
  final Iterable<BookingAddonItem> addOnItems;
  final bool applyClubPoints;
  final int totalPriceBeforeDiscount;
  final int totalPriceAfterDiscount;
  final int trimmedBalance;
  final int clubPoints;
  final bool isTermsAccepted;
  final String userEmail;
  final void Function(bool) onAcceptTermsChanged;
  final bool showError;
  final void Function() onShowTermsAndConditions;
  final void Function(bool) onApplyClubPointsChanged;

  const PaymentPageTemplate({
    super.key,
    required this.addOnItems,
    required this.applyClubPoints,
    required this.totalPriceBeforeDiscount,
    required this.totalPriceAfterDiscount,
    required this.trimmedBalance,
    required this.clubPoints,
    required this.isTermsAccepted,
    required this.userEmail,
    required this.onAcceptTermsChanged,
    required this.showError,
    required this.onShowTermsAndConditions,
    required this.onApplyClubPointsChanged,
  });

  @override
  Widget build(BuildContext context) {
    // Calculate dynamic bottom padding to account for bottom sheet
    const bottomSheetHeight = 120.0; // Approximate height of bottom sheet
    final safeAreaBottom = MediaQuery.of(context).padding.bottom;
    final dynamicBottomPadding =
        bottomSheetHeight + safeAreaBottom + 20.0; // Extra 20px for comfort

    return SingleChildScrollView(
      key: PageStorageKey("$runtimeType"),
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const SizedBox(height: 40),
            Text(
              context.strings.checkout_page_payment_title,
              style: Theme.of(context).textTheme.headlineLarge,
            ),
            const SizedBox(height: 26),
            CheckoutItemizedBill(
              addOnItems: addOnItems,
              applyClubPoints: applyClubPoints,
              totalPriceBeforeDiscount: totalPriceBeforeDiscount,
              totalPriceAfterDiscount: totalPriceAfterDiscount,
              trimmedBalance: trimmedBalance,
            ),
            const SizedBox(height: 52),
            ApplyClubPoints(
              applyClubPoints: applyClubPoints,
              clubPoints: clubPoints,
              onApplyClubPointsChanged: onApplyClubPointsChanged,
            ),
            const Divider(color: colorDivider),
            const SizedBox(height: 20),
            SendReceipt(
              sendReceipt: true,
              userEmail: userEmail,
              onSendReceiptChanged: (value) {
                // TODO: Implement send receipt
              },
            ),
            const SizedBox(height: 10),
            AcceptTermsToggle(
              isTermsAccepted: isTermsAccepted,
              onAcceptTermsChanged: onAcceptTermsChanged,
              showError: showError,
              onShowTermsAndConditions: onShowTermsAndConditions,
            ),
            SizedBox(height: dynamicBottomPadding),
          ],
        ),
      ),
    );
  }
}