/**
 * Password Fields
 */
import IGDATAPOOLFE from '@dp/ig_datapool_fe.js';

const passwordFieldPlugin = {
    initFields(form) {
        this.init(form);
    },
    init(form) {
        form.querySelectorAll('input[type="password"]').forEach((input) => {
            // Clear value on focus
            input.addEventListener('focus', () => {
                input.value = '';
            });

            // Remove "dummy-" from name on keydown
            input.addEventListener('keydown', () => {
                if (!input.name) return;
                input.name = input.name.replace('dummy-', '');
            });
        });
    }
};

IGDATAPOOLFE.addPlugin('passwordField', passwordFieldPlugin);

export default passwordFieldPlugin;
