import 'package:flutter/material.dart';
import 'package:cashumit/widgets/store_info_widget.dart';
import 'package:cashumit/widgets/account_settings_widget.dart';
import 'package:cashumit/widgets/receipt_item_list.dart';
import 'package:cashumit/widgets/receipt_total.dart';
import 'package:cashumit/widgets/store_disclaimer.dart';
import 'package:cashumit/widgets/thank_you_pantun.dart';
import 'package:cashumit/widgets/dotted_line.dart';
import 'package:cashumit/widgets/horizontal_divider.dart';
import 'package:cashumit/models/receipt_item.dart';

class ReceiptBody extends StatelessWidget {
  final List<ReceiptItem> items;
  final String? sourceAccountName;
  final String? destinationAccountName;
  final VoidCallback onOpenStoreInfoConfig;
  final VoidCallback onSelectSourceAccount;
  final VoidCallback onSelectDestinationAccount;
  final VoidCallback onOpenCustomTextConfig;
  final double total;
  final Function(int)? onEditItem;
  final Function(int)? onRemoveItem;
  final VoidCallback onAddItem;

  const ReceiptBody({
    Key? key,
    required this.items,
    this.sourceAccountName,
    this.destinationAccountName,
    required this.onOpenStoreInfoConfig,
    required this.onSelectSourceAccount,
    required this.onSelectDestinationAccount,
    required this.onOpenCustomTextConfig,
    required this.total,
    this.onEditItem,
    this.onRemoveItem,
    required this.onAddItem,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 360,
      decoration: const BoxDecoration(
        color: Colors.white,
      ),
      child: Column(
        children: [
          // Informasi toko dengan widget yang dapat diedit
          StoreInfoWidget(
            onTap: onOpenStoreInfoConfig,
          ),
          // Garis pembatas
          const DottedLine(),
          const SizedBox(height: 8),
          // Pengaturan akun sumber dan destinasi
          AccountSettingsWidget(
            sourceAccount: sourceAccountName ?? 'Pilih Sumber',
            destinationAccount: destinationAccountName ?? 'Pilih Tujuan',
            onSelectSource: onSelectSourceAccount,
            onSelectDestination: onSelectDestinationAccount,
          ),
          const SizedBox(height: 8),
          // Garis pemisah
          const HorizontalDivider(),
          // Daftar item
          ReceiptItemList(
            items: items,
            onEditItem: onEditItem,
            onRemoveItem: onRemoveItem,
            onAddItem: onAddItem,
          ),
          // Garis pembatas
          const HorizontalDivider(),
          // Total harga keseluruhan
          ReceiptTotal(total: total),
          const SizedBox(height: 8),
          // Garis pembatas
          const DottedLine(),
          // Disclaimer toko
          StoreDisclaimer(onTap: onOpenCustomTextConfig),
          // Ucapan terima kasih dan pantun
          ThankYouPantun(onTap: onOpenCustomTextConfig),
          const SizedBox(height: 16),
        ],
      ),
    );
  }
}