var recaptcha = (function () {
    'use strict';
    const RECAPTCHA_KEY = '6LcRAX4UAAAAAFsc5RD62tSraWJV24dVRLztAwDW';
    let publicMethods = [];
    let formTarget = null;
    let actionForm = null;

    const load = function(){
        setRecaptcha();
    };

    const setRecaptcha = function() {
        grecaptcha.ready(function() {
            grecaptcha.execute(RECAPTCHA_KEY, {action: actionForm}).then(function(token) {
                let inputRecaptcha = document.createElement("input");
                inputRecaptcha.setAttribute("name", "g-recaptcha-response");
                inputRecaptcha.setAttribute("type", "hidden");
                inputRecaptcha.setAttribute("value", token);
                formTarget.appendChild(inputRecaptcha);
            });
        });
    };

    publicMethods.load = function () {
        console.log('recaptcha load');
        load();
        return this;
    };

    publicMethods.setFormTarget = function (form) {
        formTarget = form;
        return this;
    };

    publicMethods.setActionForm = function (action) {
        actionForm = action;
        return this;
    };

    publicMethods.onDOMContentLoaded = function () {
        return this;
    };

    return publicMethods;
})();