import 'package:flutter/material.dart';

import 'package:provider/provider.dart';

import 'package:pshared/utils/currency.dart';

import 'package:pweb/controllers/payments/amount_field.dart';
import 'package:pweb/pages/dashboard/payouts/amount/mode/selector.dart';

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


class PaymentAmountField extends StatelessWidget {
  const PaymentAmountField();

  @override
  Widget build(BuildContext context) {
    final ui = context.watch<PaymentAmountFieldController>();
    final loc = AppLocalizations.of(context)!;
    final symbol = currencySymbolFromCode(ui.activeCurrencyCode);

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        if (ui.isReverseModeAvailable) ...[
          PaymentAmountModeSelector(
            selectedMode: ui.mode,
            onModeChanged: ui.handleModeChanged,
          ),
          const SizedBox(height: 6),
        ],
        TextField(
          controller: ui.textController,
          focusNode: ui.focusNode,
          keyboardType: const TextInputType.numberWithOptions(decimal: true),
          decoration: InputDecoration(
            labelText: loc.amount,
            border: const OutlineInputBorder(),
            prefixText: symbol == null ? null : '$symbol ',
          ),
          onChanged: ui.handleChanged,
        ),
      ],
    );
  }
}
