var jQueryWeb357LoginAsUserMembershipPro = jQuery.noConflict();
jQueryWeb357LoginAsUserMembershipPro(function ($) {
    /**
    Membership pro Orders' page
    */
    // Login as user button
    $(
        "form[action='index.php?option=com_osmembership&view=subscriptions'] table.adminlist tbody"
    )
        .find('tr')
        .each(function () {
            var last_name_col = $(this).find('td').eq(3).text();
            var last_name_col_clean = last_name_col.trim();
            var username = last_name_col_clean.substring(
                last_name_col_clean.indexOf('(') + 1,
                last_name_col_clean.indexOf(')')
            );

            var build_login_as_user_url =
                login_as_user_with_username_url.replace(
                    '{{osm_username}}',
                    username.trim()
                );

            if (username.length === 0) {
                $(this).find('td').eq(3).after('<td>---</td>');
            } else {
                $(this)
                    .find('td')
                    .eq(3)
                    .after(
                        '<td><a target="_blank" class="btn" href="' +
                            build_login_as_user_url +
                            '">Login as <span class="loginasuser-username" style="font-weight:bold">' +
                            username +
                            '</span></td>'
                    );
            }
        });

    // Column
    $(
        "form[action='index.php?option=com_osmembership&view=subscriptions'] table.adminlist thead"
    )
        .find('th')
        .eq(3)
        .after('<th>Login as User</th>');

    /**
    Membership pro Subscribers' page
    */
    // Login as user button
    $(
        "form[action='index.php?option=com_osmembership&view=subscribers'] table.adminlist tbody"
    )
        .find('tr')
        .each(function () {
            var email = $(this).find('td').eq(3).text();

            var build_login_as_user_url = login_as_user_with_email_url.replace(
                '{{email}}',
                email.trim()
            );

            $(this)
                .find('td')
                .eq(3)
                .after(
                    '<td><a target="_blank" class="btn" href="' +
                        build_login_as_user_url +
                        '">Login as <span class="loginasuser-username" style="font-weight:bold">' +
                        email +
                        '</span></td>'
                );
        });

    // Column
    $(
        "form[action='index.php?option=com_osmembership&view=subscribers'] table.adminlist thead"
    )
        .find('th')
        .eq(3)
        .after('<th>Login as User</th>');
});
