import 'package:flutter/material.dart';

import 'package:pweb/pages/dashboard/buttons/balance/header.dart';
import 'package:pweb/pages/dashboard/buttons/balance/source/layout/amount_with_refresh.dart';
import 'package:pweb/pages/dashboard/buttons/balance/source/layout/copyable_field.dart';


class BalanceSourceBody extends StatelessWidget {
  final String title;
  final String? subtitle;
  final String? badge;
  final Widget amount;
  final Widget refreshButton;
  final Widget actions;
  final String copyLabel;
  final bool canCopy;
  final VoidCallback? onCopy;

  const BalanceSourceBody({
    super.key,
    required this.title,
    required this.subtitle,
    required this.badge,
    required this.amount,
    required this.refreshButton,
    required this.actions,
    required this.copyLabel,
    required this.canCopy,
    required this.onCopy,
  });

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, constraints) {
        final sideMaxWidth = constraints.maxWidth * 0.30;

        return Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Flexible(
              fit: FlexFit.loose,
              child: ConstrainedBox(
                constraints: BoxConstraints(maxWidth: sideMaxWidth),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    BalanceHeader(
                      title: title,
                      subtitle: subtitle,
                      badge: badge,
                    ),
                    SizedBox(height: constraints.maxHeight * 0.06),
                    BalanceCopyableField(
                      label: copyLabel,
                      canCopy: canCopy,
                      onCopy: onCopy,
                    ),
                  ],
                ),
              ),
            ),
            Expanded(
              child: Align(
                alignment: Alignment.center,
                child: FittedBox(
                  fit: BoxFit.scaleDown,
                  child: BalanceAmountWithRefresh(
                    amount: amount,
                    refreshButton: refreshButton,
                  ),
                ),
              ),
            ),
            Flexible(
              fit: FlexFit.loose,
              child: ConstrainedBox(
                constraints: BoxConstraints(maxWidth: sideMaxWidth),
                child: SizedBox(height: constraints.maxHeight, child: actions),
              ),
            ),
          ],
        );
      },
    );
  }
}
