import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

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


class BalanceCopyState {
  final String label;
  final String payload;

  const BalanceCopyState({required this.label, required this.payload});

  bool get canCopy => payload.trim().isNotEmpty;
}

class BalanceSourceCopyController {
  const BalanceSourceCopyController();

  BalanceCopyState wallet(BuildContext context, String? depositAddress) =>
      _buildCopyAddressState(context, depositAddress);

  BalanceCopyState ledger(BuildContext context, String? accountCode) =>
      _buildCopyAddressState(context, accountCode);

  Future<bool> copy(BalanceCopyState state) async {
    if (!state.canCopy) return false;
    await Clipboard.setData(ClipboardData(text: state.payload));
    return true;
  }

  BalanceCopyState _buildCopyAddressState(
    BuildContext context,
    String? payload,
  ) {
    final l10n = AppLocalizations.of(context)!;
    return BalanceCopyState(
      label: l10n.copyAddress,
      payload: payload?.trim() ?? '',
    );
  }
}
