import 'package:flutter/material.dart';

import 'package:pshared/models/payment/type.dart';
import 'package:pshared/models/recipient/recipient.dart';

import 'package:pweb/pages/dashboard/buttons/balance/balance.dart';
import 'package:pweb/pages/dashboard/buttons/buttons.dart';
import 'package:pweb/pages/dashboard/payouts/multiple/title.dart';
import 'package:pweb/pages/dashboard/payouts/multiple/widget.dart';
import 'package:pweb/pages/dashboard/payouts/single/widget.dart';

import 'package:pweb/generated/i18n/app_localizations.dart';


class AppSpacing {
  static const double small = 10;
  static const double medium = 16;
  static const double large = 20;
}

class DashboardPage extends StatefulWidget {
  final ValueChanged<Recipient> onRecipientSelected;
  final void Function(PaymentType type) onGoToPaymentWithoutRecipient;

  const DashboardPage({
    super.key,
    required this.onRecipientSelected,
    required this.onGoToPaymentWithoutRecipient,
  });

  @override
  State<DashboardPage> createState() => _DashboardPageState();
}

class _DashboardPageState extends State<DashboardPage> {
  bool _showContainerSingle = true;
  bool _showContainerMultiple = false;

  void _setActive(bool single) {
    setState(() {
      _showContainerSingle = single;
      _showContainerMultiple = !single;
    });
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Row(
              children: [
                Expanded(
                  flex: 0,
                  child: TransactionRefButton(
                    onTap: () => _setActive(true),
                    isActive: _showContainerSingle,
                    label: AppLocalizations.of(context)!.sendSingle,
                    icon: Icons.person_add,
                  ),
                ),
                const SizedBox(width: AppSpacing.small),
                Expanded(
                  flex: 0,
                  child: TransactionRefButton(
                    onTap: () => _setActive(false),
                    isActive: _showContainerMultiple,
                    label: AppLocalizations.of(context)!.sendMultiple,
                    icon: Icons.group_add,
                  ),
                ),
              ],
            ),
            const SizedBox(height: AppSpacing.medium),
            BalanceWidget(),
            const SizedBox(height: AppSpacing.small),
            if (_showContainerMultiple) TitleMultiplePayout(),
            const SizedBox(height: AppSpacing.medium),
            if (_showContainerSingle)
              SinglePayoutForm(
                onRecipientSelected: widget.onRecipientSelected,
                onGoToPayment: widget.onGoToPaymentWithoutRecipient,
              ),
            if (_showContainerMultiple) MultiplePayoutForm(),
          ],
        ),
      ),
    );
  }
}
