
function onSignIn(googleUser) {
    console.log(googleUser);
    var profile = googleUser.getBasicProfile();
    var $name = profile.getName();
    var $email = profile.getEmail();
    var $id = profile.getId();
    var $status;
    var auth2 = gapi.auth2.getAuthInstance();
    auth2.signOut().then(function () {

    });
    console.log($status);
    mona_ajax_social_data({
        'id': $id,
        'name': $name,
        'email': $email
    }, 'google', $status, jQuery(this));


}

function mona_ajax_social_data($code, $type, $status, $this) {
    // console.log( $code );
    jQuery.ajax({
        url: mona_ajax_url.ajaxURL,
        type: 'post',
        data: {
            action: 'mona_ajax_social_data',
            code: $code,
            type: $type,
        },
        error: function (request) {
            console.log(request);
        },
        beforeSend: function () {

        },
        success: function (response) {
            var $data;
            $data = jQuery.parseJSON(response);
            console.log($data);
            if ($data.status == 'login') {
                window.location.reload();
            } else {
                jQuery.ajax({
                    url: mona_ajax_url.ajaxURL,
                    type: 'post',
                    data: {
                        action: 'mona_ajax_login_social',
                        data: $data.message,
                    },
                    error: function (request) {
                        alert($data.message);
                    },
                    beforeSend: function () {

                    },
                    success: function (response) {
                        window.location.reload();
                    }
                });
            }
        }
    });
}