<commit_before>package bisq.desktop.components.paymentmethods;

import bisq.desktop.components.InputTextField;
import bisq.desktop.util.validation.AccountNrValidator;
import bisq.desktop.util.validation.BankIdValidator;
import bisq.desktop.util.validation.BranchIdValidator;
import bisq.desktop.util.validation.NationalAccountIdValidator;

import bisq.core.locale.BankUtil;
import bisq.core.locale.Res;
import bisq.core.payment.AccountAgeWitnessService;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.payload.CountryBasedPaymentAccountPayload;
import bisq.core.util.BSFormatter;
import bisq.core.util.validation.InputValidator;

import org.apache.commons.lang3.StringUtils;

import javafx.scene.layout.GridPane;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class GeneralBankForm extends PaymentMethodForm {
    private static final Logger log = LoggerFactory.getLogger(GeneralBankForm.class);

    static boolean accountNrAccountTypeCombined = false;
    static boolean nationalAccountIdAccountNrCombined = false;
    static boolean bankNameBankIdCombined = false;
    static boolean bankIdBranchIdCombined = false;
    static boolean bankNameBranchIdCombined = false;
    static boolean branchIdAccountNrCombined = false;

    boolean validatorsApplied;
    boolean useHolderID;
    InputTextField bankNameInputTextField, bankIdInputTextField, branchIdInputTextField, accountNrInputTextField,
            holderIdInputTextField, nationalAccountIdInputTextField;

    boolean accountNrInputTextFieldEdited;

    public GeneralBankForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, InputValidator inputValidator, GridPane gridPane, int gridRow, BSFormatter formatter) {
        super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter);
    }

    static int getIndexOfColumn(int colIndex) {
        return colIndex % 2;
    }

    static void prepareFormLayoutFlags(String countryCode, int currentNumberOfRows) {
        int nrRows = currentNumberOfRows;

        if (nrRows > 2) {
            // Try combine AccountNr + AccountType
            accountNrAccountTypeCombined = BankUtil.isAccountNrRequired(countryCode) && BankUtil.isAccountTypeRequired(countryCode);
            if (accountNrAccountTypeCombined)
                nrRows--;

            if (nrRows > 2) {

                nationalAccountIdAccountNrCombined = BankUtil.isAccountNrRequired(countryCode) &&
                        BankUtil.isNationalAccountIdRequired(countryCode);

                if (nationalAccountIdAccountNrCombined)
                    nrRows--;

                if (nrRows > 2) {
                    // Next we try BankName + BankId
                    bankNameBankIdCombined = BankUtil.isBankNameRequired(countryCode) && BankUtil.isBankIdRequired(countryCode);
                    if (bankNameBankIdCombined)
                        nrRows--;

                    if (nrRows > 2) {
                        // Next we try BankId + BranchId
                        bankIdBranchIdCombined = !bankNameBankIdCombined && BankUtil.isBankIdRequired(countryCode) &&
                                BankUtil.isBranchIdRequired(countryCode);
                        if (bankIdBranchIdCombined)
                            nrRows--;

                        if (nrRows > 2) {
                            // Next we try BankId + BranchId
                            bankNameBranchIdCombined = !bankNameBankIdCombined && !bankIdBranchIdCombined &&
                                    BankUtil.isBankNameRequired(countryCode) && BankUtil.isBranchIdRequired(countryCode);
                            if (bankNameBranchIdCombined)
                                nrRows--;

                            if (nrRows > 2) {
                                branchIdAccountNrCombined = !bankNameBranchIdCombined && !bankIdBranchIdCombined &&
                                        !accountNrAccountTypeCombined &&
                                        BankUtil.isBranchIdRequired(countryCode) && BankUtil.isAccountNrRequired(countryCode);
                                if (branchIdAccountNrCombined)
                                    nrRows--;

                                if (nrRows > 2)
                                    log.warn("We still have too many rows....");
                            }
                        }
                    }
                }
            }
        }
    }

    void validateInput(String countryCode) {
        if (BankUtil.useValidation(countryCode) && !validatorsApplied) {
            validatorsApplied = true;<commit_msg>Enable validation when switching between countries<commit_after>package bisq.desktop.components.paymentmethods;

import bisq.desktop.components.InputTextField;
import bisq.desktop.util.validation.AccountNrValidator;
import bisq.desktop.util.validation.BankIdValidator;
import bisq.desktop.util.validation.BranchIdValidator;
import bisq.desktop.util.validation.NationalAccountIdValidator;

import bisq.core.locale.BankUtil;
import bisq.core.locale.Res;
import bisq.core.payment.AccountAgeWitnessService;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.payload.CountryBasedPaymentAccountPayload;
import bisq.core.util.BSFormatter;
import bisq.core.util.validation.InputValidator;

import org.apache.commons.lang3.StringUtils;

import javafx.scene.layout.GridPane;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class GeneralBankForm extends PaymentMethodForm {
    private static final Logger log = LoggerFactory.getLogger(GeneralBankForm.class);

    static boolean accountNrAccountTypeCombined = false;
    static boolean nationalAccountIdAccountNrCombined = false;
    static boolean bankNameBankIdCombined = false;
    static boolean bankIdBranchIdCombined = false;
    static boolean bankNameBranchIdCombined = false;
    static boolean branchIdAccountNrCombined = false;

    boolean validatorsApplied;
    boolean useHolderID;
    InputTextField bankNameInputTextField, bankIdInputTextField, branchIdInputTextField, accountNrInputTextField,
            holderIdInputTextField, nationalAccountIdInputTextField;

    boolean accountNrInputTextFieldEdited;

    public GeneralBankForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, InputValidator inputValidator, GridPane gridPane, int gridRow, BSFormatter formatter) {
        super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter);
    }

    static int getIndexOfColumn(int colIndex) {
        return colIndex % 2;
    }

    static void prepareFormLayoutFlags(String countryCode, int currentNumberOfRows) {
        int nrRows = currentNumberOfRows;

        if (nrRows > 2) {
            // Try combine AccountNr + AccountType
            accountNrAccountTypeCombined = BankUtil.isAccountNrRequired(countryCode) && BankUtil.isAccountTypeRequired(countryCode);
            if (accountNrAccountTypeCombined)
                nrRows--;

            if (nrRows > 2) {

                nationalAccountIdAccountNrCombined = BankUtil.isAccountNrRequired(countryCode) &&
                        BankUtil.isNationalAccountIdRequired(countryCode);

                if (nationalAccountIdAccountNrCombined)
                    nrRows--;

                if (nrRows > 2) {
                    // Next we try BankName + BankId
                    bankNameBankIdCombined = BankUtil.isBankNameRequired(countryCode) && BankUtil.isBankIdRequired(countryCode);
                    if (bankNameBankIdCombined)
                        nrRows--;

                    if (nrRows > 2) {
                        // Next we try BankId + BranchId
                        bankIdBranchIdCombined = !bankNameBankIdCombined && BankUtil.isBankIdRequired(countryCode) &&
                                BankUtil.isBranchIdRequired(countryCode);
                        if (bankIdBranchIdCombined)
                            nrRows--;

                        if (nrRows > 2) {
                            // Next we try BankId + BranchId
                            bankNameBranchIdCombined = !bankNameBankIdCombined && !bankIdBranchIdCombined &&
                                    BankUtil.isBankNameRequired(countryCode) && BankUtil.isBranchIdRequired(countryCode);
                            if (bankNameBranchIdCombined)
                                nrRows--;

                            if (nrRows > 2) {
                                branchIdAccountNrCombined = !bankNameBranchIdCombined && !bankIdBranchIdCombined &&
                                        !accountNrAccountTypeCombined &&
                                        BankUtil.isBranchIdRequired(countryCode) && BankUtil.isAccountNrRequired(countryCode);
                                if (branchIdAccountNrCombined)
                                    nrRows--;

                                if (nrRows > 2)
                                    log.warn("We still have too many rows....");
                            }
                        }
                    }
                }
            }
        }
    }

    void validateInput(String countryCode) {
        if (BankUtil.useValidation(countryCode)) {
            validatorsApplied = true;
{'fraction_non_alphanumeric': 0.06632379727847423, 'fraction_numerical': 0.0023572270438229938, 'mean_word_length': 2.1406460296096905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4673433', 'n_tokens_mistral': 2333, 'n_tokens_neox': 2230, 'n_words': 431}