let copyInputValueList = [
    {
        parentSelector: '#register_form',
        sourceSelector: '[name="FullName"]',
        targetSelector: ['[name="BankAccountName"]', '[name="EMoneyAccountName"]']
    },
    {
        parentSelector: '#register_form',
        sourceSelector: '[name="Phone"]',
        targetSelector: ['[name="WhatsApp"]', '[name="EMoneyPhoneNo"]']
    }
]

if (document.readyState !== 'loading') copyInit()
else document.addEventListener('DOMContentLoaded', copyInit);

function waitForElement(selector) {
    return new Promise((resolve) => {
        const observer = new MutationObserver((mutations, observer) => {
            const element = document.querySelector(selector);
            if (element) {
                observer.disconnect();
                resolve(element);
            }
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true,
        });
    });
}

function copyInit() {
    if (copyInputValueList.length) {
        copyInputValueList.map((data) => {
            waitForElement(`${data?.parentSelector} ${data?.sourceSelector}`).then((source) => {
                // Perform actions on the element

                if (source) {
                    source.addEventListener('input', (event) => {
                        const sourceValue = event.target.value

                        if (data?.targetSelector) {
                            data.targetSelector.map((target) => {
                                const targetElm = document.querySelector(`${data?.parentSelector} ${target}`)

                                if (targetElm) {
                                    targetElm.value = sourceValue
                                }
                            })
                        }
                    }, false)
                }
            });
        })
    }
}