How to pass conditional array to wp_localize_script

Ended up with this as the function:

// set up the settings for the theme.js
function mb_scripts_settings() {

    // blanks
    $mb_ajax_form_type = $mb_get_page_slug = $mb_redirect = $mb_redirect_time = $mb_form_disable = $mb_array = '';

    // get the form type
    $mb_ajax_form_type      = ( is_front_page() ? 'change'  : 'submit'  );

    // get the page slug from ID
    $mb_get_page_slug       = get_post_field( 'post_name', get_the_ID() );

    // if the page is admin or password
    if( is_page( array('admin', 'pw') ) ) {
        $mb_redirect        = true;
        $mb_redirect_time   = 3000;
        $mb_form_disable    = true;

        if( is_page('admin') ) {
            // generate the url for redirection
            $mb_form_area           = ( ( is_page('admin') && isset($_GET['mbtab']) )   ? $_GET['mbtab']    : null      );
            $mb_form_area_url       = ( empty($mb_form_area)    ? "https://wordpress.stackexchange.com/" : '/admin/?mbtab=' . $mb_form_area . '&mbform=1'  );
            $mb_form_area_url       = get_home_url( $mb_form_area_url );
        }
    }

    // if the page is front
    if( is_front_page() ) {
        $mb_redirect        = false;
        $mb_redirect_time   = 0;
        $mb_form_disable    = false;
        $mb_get_page_slug   = 'front_page';
        $mb_form_area = $mb_form_area_url = null;
    }

    // build the array
    $mb_array = array(
                $mb_ajax_form_type,
                $mb_get_page_slug,
                $mb_redirect,
                $mb_redirect_time,
                $mb_form_disable
            );

    return $mb_array;
}

And when enqueuing the script:

    // enqueue the theme js
    wp_enqueue_script( 'mb_mbtheme_js', mbWebOS_js . 'scripts.' . $mbTheme . '.js' );

    // localise the theme js
    // only for selected pages
    if( is_page('admin') || is_front_page() ) {
        wp_localize_script( 'mb_mbtheme_js', 'mb_mbtheme_js', mb_scripts_settings() );
    }