import 'package:flutter/material.dart';

import 'package:provider/provider.dart';

import 'package:pshared/controllers/payment/source.dart';

import 'package:pweb/pages/payout_page/wallet/edit/buttons/buttons.dart';
import 'package:pweb/pages/payout_page/wallet/edit/fields.dart';
import 'package:pweb/pages/payout_page/wallet/edit/header.dart';
import 'package:pweb/utils/dimensions.dart';

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

//TODO make this page more generic and reusable
class WalletEditPage extends StatelessWidget {
  final VoidCallback onBack;

  const WalletEditPage({super.key, required this.onBack});

  @override
  Widget build(BuildContext context) {
    final dimensions = AppDimensions();
    final loc = AppLocalizations.of(context)!;

    return Consumer<PaymentSourceController>(
      builder: (context, controller, child) {
        final sourceType = controller.selectedType;

        if (sourceType == null) {
          return Center(child: Text(loc.noWalletSelected));
        }

        return Align(
          alignment: Alignment.topCenter,
          child: Column(
            children: [
              ConstrainedBox(
                constraints: BoxConstraints(
                  maxWidth: dimensions.maxContentWidth,
                ),
                child: Material(
                  elevation: dimensions.elevationSmall,
                  color: Theme.of(context).colorScheme.onSecondary,
                  borderRadius: BorderRadius.circular(
                    dimensions.borderRadiusMedium,
                  ),
                  child: Padding(
                    padding: EdgeInsets.all(dimensions.paddingLarge),
                    child: SingleChildScrollView(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          IconButton(
                            icon: const Icon(Icons.arrow_back),
                            onPressed: onBack,
                          ),
                          WalletEditHeader(),
                          WalletEditFields(),
                          const SizedBox(height: 24),
                          ButtonsWalletWidget(),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
