# By: Riasat Ullah
# This file contains functions that will generate the context of configurations pages.

from constants import label_names as lbl
from context_manager import components_context, incidents_context, resources_context, users_context
from translators import label_translator as lt
from constants import var_names


def get_routine_list_context(lang, allowed_components):
    '''
    Context for routine list page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)

    page_labels = [lbl.det_video_learn_routine,
                   lbl.ins_delete, lbl.ins_edit, lbl.ins_no, lbl.ins_view, lbl.ins_yes, lbl.res_resources,
                   lbl.qqs_are_you_sure_you_want_to_delete_this_routine, lbl.ttl_associated_policies,
                   lbl.ttl_new_routine, lbl.ttl_routines, lbl.ttl_routine_name, lbl.ttl_timezone,]

    res_labels = [lbl.res_creating_on_call_routines, lbl.res_editing_routines, lbl.res_overriding_routines,
                  lbl.res_on_call_schedule_examples, lbl.res_configuring_escalation_policies, lbl.res_creating_services,
                  lbl.res_team_components]
    page_labels += res_labels

    page_descriptions = [lbl.desc_routine, lbl.desc_routine_empty]
    final_context = {**top_bar_context, **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_routine_details_context(lang, allowed_components):
    '''
    Context for routine details page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)
    months_days_context = components_context.get_months_days_context(lang)

    page_labels = [lbl.det_apply_between, lbl.det_choose_your_template, lbl.det_copied, lbl.det_copy,
                   lbl.det_copy_webcal_url, lbl.det_duration, lbl.det_ends_on, lbl.det_history, lbl.det_none,
                   lbl.det_override_other_layers, lbl.det_paste, lbl.det_rotate_every,
                   lbl.det_routine_tmpl_single_shift_daily, lbl.det_routine_tmpl_single_shift_separate_weekend,
                   lbl.det_routine_tmpl_two_shifts_with_vacation,
                   lbl.det_routine_tmpl_two_shifts_rolling_next_day, lbl.det_routine_tmpl_two_shifts_weekly,
                   lbl.det_skip_on, lbl.det_shift_starts_at, lbl.det_start_from_scratch,
                   lbl.det_starts_on, lbl.det_video_learn_routine, lbl.dsm_days, lbl.dsm_hours,
                   lbl.dsm_select_assignees, lbl.dsm_select_days, lbl.err_routine_layer_date_time_frequency_invalid,
                   lbl.err_routine_layer_min, lbl.err_routine_layer_rotation_assignee, lbl.err_routine_name_invalid,
                   lbl.ins_add, lbl.ins_cancel, lbl.ins_download, lbl.ins_no, lbl.ins_save, lbl.ins_yes,
                   lbl.msg_routine_open_slots_explanation, lbl.msg_routine_open_slots_support_hours,
                   lbl.msg_routine_overlap_add_rotation, lbl.msg_routine_overlap_explanation,
                   lbl.qqs_are_you_sure_you_want_to_continue_with_this_routine_setup,
                   lbl.qqs_are_you_sure_you_want_to_delete_this_routine, lbl.res_resources, lbl.ttl_associated_policies,
                   lbl.ttl_calendar_view, lbl.ttl_delete_routine, lbl.ttl_edit_routine, lbl.ttl_final_schedule,
                   lbl.ttl_layer, lbl.ttl_layers, lbl.ttl_redundant_routine_layers, lbl.ttl_routines,
                   lbl.ttl_routine_name, lbl.ttl_timeline_view, lbl.ttl_time_slots_without_assignees, lbl.ttl_timezone,
                   lbl.ttl_use_template, lbl.ttl_view_schedule]

    res_labels = [lbl.res_creating_on_call_routines, lbl.res_editing_routines, lbl.res_overriding_routines,
                  lbl.res_on_call_schedule_examples, lbl.res_configuring_escalation_policies, lbl.res_creating_services,
                  lbl.res_team_components]

    page_labels += res_labels

    page_context = lt.get_context(page_labels, lang)
    final_context = {**top_bar_context, **months_days_context, **page_context}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_escalation_policy_list_context(lang, allowed_components):
    '''
    Context for escalation policy list page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)

    page_labels = [lbl.ttl_escalation_policies, lbl.ttl_policy_name, lbl.ttl_on_call_now,
                   lbl.ttl_associated_services, lbl.ttl_new_escalation_policy, lbl.res_resources,
                   lbl.det_primary, lbl.det_secondary, lbl.det_video_learn_escalation, lbl.ttl_more,
                   lbl.ins_view, lbl.ins_edit, lbl.ins_delete, lbl.ins_yes, lbl.ins_no,
                   lbl.qqs_are_you_sure_you_want_to_delete_this_escalation_policy]

    res_labels = [lbl.res_on_call_schedule_examples, lbl.res_configuring_escalation_policies,
                  lbl.res_creating_on_call_routines, lbl.res_editing_routines, lbl.res_overriding_routines,
                  lbl.res_creating_services, lbl.res_team_components]
    page_labels += res_labels

    page_descriptions = [lbl.desc_escalation_policy, lbl.desc_escalation_policy_empty]
    final_context = {**top_bar_context, **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_escalation_policy_details_context(lang, allowed_components):
    '''
    Context for escalation policy details page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)
    months_days_context = components_context.get_months_days_context(lang)

    page_labels = [lbl.det_escalate_after, lbl.det_level, lbl.det_levels, lbl.det_missing_backup_escalation,
                   lbl.det_none, lbl.det_primary, lbl.det_secondary, lbl.dsm_minutes, lbl.dsm_select_assignees,
                   lbl.err_no_items_were_selected, lbl.err_policy_duplicate_assignee_in_level, lbl.err_policy_level_min,
                   lbl.err_policy_minutes, lbl.err_policy_name_invalid, lbl.err_select_at_least_one_assignee,
                   lbl.ins_add, lbl.ins_cancel, lbl.ins_no, lbl.ins_save, lbl.ins_yes,
                   lbl.qqs_are_you_sure_you_want_to_delete_this_escalation_policy, lbl.qqs_proceed_without_escalation,
                   lbl.res_resources, lbl.ttl_add_remove_tag, lbl.ttl_associated_services, lbl.ttl_calendar_view,
                   lbl.ttl_delete_policy, lbl.ttl_edit_policy, lbl.ttl_escalation_policies, lbl.ttl_more,
                   lbl.ttl_on_call_now, lbl.ttl_policy_name, lbl.ttl_timeline_view, lbl.ttl_view_schedule]

    res_labels = [lbl.res_on_call_schedule_examples, lbl.res_configuring_escalation_policies,
                  lbl.res_creating_on_call_routines, lbl.res_editing_routines, lbl.res_overriding_routines,
                  lbl.res_creating_services, lbl.res_team_components]

    page_labels += res_labels

    page_context = lt.get_context(page_labels, lang)
    final_context = {**top_bar_context, **months_days_context, **page_context}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_service_list_context(lang, allowed_components):
    '''
    Context for the service list page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)
    months_days_context = components_context.get_months_days_context(lang)

    page_labels = [lbl.det_duration, lbl.det_from, lbl.det_keywords, lbl.det_reason, lbl.det_search_by_service_name,
                   lbl.det_service, lbl.det_to, lbl.det_video_learn_service, lbl.dsm_acknowledged, lbl.dsm_last_30_days,
                   lbl.dsm_open, lbl.ins_delete, lbl.ins_edit, lbl.ins_view, lbl.opt_all_business_services,
                   lbl.opt_all_teams, lbl.opt_anytime, lbl.opt_my_teams, lbl.opt_within_24_hours, lbl.opt_within_7_days,
                   lbl.res_resources, lbl.ttl_business_services, lbl.ttl_create_incident, lbl.ttl_health_check,
                   lbl.ttl_last_incident, lbl.ttl_maintenance_windows, lbl.ttl_new_service, lbl.ttl_on_call_now,
                   lbl.ttl_open_incidents, lbl.ttl_services, lbl.ttl_teams, lbl.ttl_timezone]

    res_labels = [lbl.res_creating_services, lbl.res_adding_service_integrations, lbl.res_transfer_integration,
                  lbl.res_disabling_a_service, lbl.res_schedule_service_maintenance, lbl.res_services_list,
                  lbl.res_business_services, lbl.res_slack_integration_guide]

    page_labels += res_labels
    page_descriptions = [lbl.desc_service, lbl.desc_service_empty, lbl.desc_service_no_maintenance]

    final_context = {**top_bar_context, **months_days_context, **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_service_details_context(lang, allowed_components):
    '''
    Context for the service details page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)
    months_days_context = components_context.get_months_days_context(lang)

    common_labels = [lbl.det_copied, lbl.det_description, lbl.det_disabled, lbl.det_enabled, lbl.det_incoming,
                     lbl.det_maintenance, lbl.det_name, lbl.det_none, lbl.det_outgoing, lbl.dsm_minutes, lbl.err_authorization,
                     lbl.err_invalid_request, lbl.err_service_maintenance_invalid, lbl.err_service_name_invalid,
                     lbl.err_service_support_hours_incomplete, lbl.err_subscription_rights, lbl.ins_schedule,
                     lbl.ins_authorize, lbl.ins_cancel, lbl.ins_delete, lbl.ins_edit, lbl.ins_next, lbl.ins_no, 
                     lbl.ins_reauthorize, lbl.ins_save, lbl.ins_transfer, lbl.ins_yes, lbl.msg_service_integration_added,
                     lbl.msg_service_integration_edited, lbl.msg_service_integration_reauthorized,
                     lbl.qqs_are_you_sure_you_want_to_delete_this_service,
                     lbl.qqs_are_you_sure_you_want_to_delete_this_integration, lbl.res_resources, lbl.ttl_activity,
                     lbl.ttl_add_remove_tag, lbl.ttl_delete_service, lbl.ttl_dependencies, lbl.ttl_disable_service,
                     lbl.ttl_edit_service, lbl.ttl_enable_service, lbl.ttl_integrations, lbl.ttl_service_maintenance,
                     lbl.ttl_schedule_maintenance, lbl.ttl_services, lbl.ttl_settings]

    settings_labels = [lbl.day_mon, lbl.day_tue, lbl.day_wed, lbl.day_thu, lbl.day_fri, lbl.day_sat, lbl.day_sun,
                       lbl.det_assign_to_escalation_policy, lbl.det_service_re_trigger_incident_after,
                       lbl.det_service_allow_auto_grouping, lbl.det_support_hours, lbl.det_from, lbl.det_to,
                       lbl.det_duration, lbl.det_reason, lbl.det_starts_on, lbl.det_none, lbl.dsm_minutes,
                       lbl.det_service_de_prioritize_in_off_hours,
                       lbl.det_service_re_prioritize_un_ack_incidents_in_on_hours, lbl.ttl_timezone]

    integration_labels = [lbl.det_change_event_track_branches, lbl.det_select_service_to_transfer_integration_to,
                          lbl.dsm_value, lbl.err_change_event_invalid_branch, lbl.err_integration_authorization_secret,
                          lbl.err_integration_invalid_credentials, lbl.err_integration_name_invalid,
                          lbl.err_integration_type_change, lbl.err_integration_type_invalid, lbl.err_invalid_url,
                          lbl.ttl_add_custom_header, lbl.ttl_custom_action, lbl.ttl_custom_headers,
                          lbl.ttl_custom_integration, lbl.ttl_email, lbl.ttl_github_integration,
                          lbl.ttl_gitlab_integration, lbl.ttl_integration_key, lbl.ttl_integration_name,
                          lbl.ttl_integration_type, lbl.ttl_integration_url, lbl.ttl_new_integration, lbl.ttl_payload,
                          lbl.ttl_transfer_integration, lbl.ttl_url_endpoint]

    activity_labels = [lbl.det_alert, lbl.det_assigned_to, lbl.det_integration, lbl.det_resolved_on, lbl.det_status,
                       lbl.det_urgency, lbl.dsm_by, lbl.dsm_last_30_days, lbl.dsm_source, lbl.dsm_type,
                       lbl.opt_critical, lbl.opt_high, lbl.opt_low, lbl.opt_medium, lbl.opt_minor, lbl.ttl_created_on,
                       lbl.ttl_incident_id, lbl.ttl_incident_title, lbl.ttl_recent_activity, lbl.ttl_recent_changes,
                       lbl.ttl_suppressed_alerts, lbl.ttl_team]

    incident_status_labels = list(incidents_context.incident_alert_status_maps.values())

    autotask_labels = [lbl.det_autotask_api_details, lbl.det_autotask_configure_how_companies_map,
                       lbl.det_autotask_default_company_description, lbl.det_autotask_map_groups,
                       lbl.det_configure_how_taskcall_will_create_autotask_ticket, lbl.det_queue,
                       lbl.det_sync_taskcall_notes_with_autotask, lbl.det_sync_taskcall_status_with_autotask,
                       lbl.det_sync_taskcall_urgency_with_autotask, lbl.det_ticket_category, lbl.det_tracking_id,
                       lbl.dsm_domain, lbl.err_autotask_groups_permission, lbl.err_autotask_integration_fields_invalid,
                       lbl.msg_autotask_credentials_updated, lbl.msg_autotask_use_existing,
                       lbl.ttl_autotask_integration, lbl.ttl_password, lbl.ttl_user]

    custom_integration_labels = [lbl.det_allowed_url_format, lbl.det_attributes_to_group_alerts_by,
                                 lbl.det_define_how_incoming_alerts_map_to_taskcall_fields,
                                 lbl.det_include_incoming_payload_in_description, lbl.dsm_separate_by_comma,
                                 lbl.err_integration_custom_payload]

    freshdesk_labels = [lbl.det_configure_how_taskcall_will_create_freshdesk_ticket, lbl.det_freshdesk_api_key,
                        lbl.det_freshdesk_domain, lbl.det_sync_taskcall_notes_with_freshdesk,
                        lbl.det_sync_taskcall_status_with_freshdesk, lbl.det_sync_taskcall_urgency_with_freshdesk,
                        lbl.err_freshdesk_api_key_invalid, lbl.err_freshdesk_domain_invalid,
                        lbl.ttl_feature_request, lbl.ttl_freshdesk_integration]

    freshservice_labels = [lbl.det_configure_how_taskcall_will_create_freshservice_ticket, lbl.det_freshservice_api_key,
                           lbl.det_freshservice_domain, lbl.det_requester_email,
                           lbl.det_sync_taskcall_notes_with_freshservice,
                           lbl.det_sync_taskcall_status_with_freshservice,
                           lbl.det_sync_taskcall_urgency_with_freshservice, lbl.det_workspace,
                           lbl.err_freshservice_api_key_invalid, lbl.err_freshservice_domain_invalid,
                           lbl.err_requester_email_invalid, lbl.ttl_feature_request, lbl.ttl_freshservice_integration]
    
    halo_itsm_labels = [lbl.det_configure_how_taskcall_will_create_haloitsm_ticket,
                           lbl.det_haloitsm_domain, lbl.det_haloitsm_client_id, lbl.det_haloitsm_client_secret, 
                           lbl.det_requester_email,lbl.det_sync_taskcall_notes_with_haloitsm,
                           lbl.det_sync_taskcall_status_with_haloitsm,lbl.det_sync_taskcall_urgency_with_haloitsm, 
                           lbl.det_workspace,lbl.err_haloitsm_domain_invalid,lbl.err_haloitsm_client_id_invalid,
                           lbl.err_haloitsm_client_secret_invalid,lbl.err_requester_email_invalid, 
                           lbl.ttl_feature_request, lbl.ttl_haloitsm_integration]

    jira_labels = [lbl.det_administrator_password, lbl.det_administrator_user,
                   lbl.det_automatically_create_taskcall_incident_if_jql_matches, lbl.det_configuration_name,
                   lbl.det_configure_how_jira_will_create_incidents_in_taskcall,
                   lbl.det_configure_how_taskcall_will_create_jira_issues, lbl.det_create_issue_mode,
                   lbl.det_jira_issue_type, lbl.det_jira_project_to_integrate_with, lbl.det_jira_server_details,
                   lbl.det_map_taskcall_jira_status, lbl.det_map_taskcall_jira_urgency,
                   lbl.det_server_address, lbl.det_sync_taskcall_notes_with_jira,
                   lbl.err_configuration_name_invalid, lbl.err_jira_server_integration_fields_invalid,
                   lbl.err_jql_invalid, lbl.msg_jira_server_credentials_updated, lbl.msg_jira_server_use_existing,
                   lbl.opt_automatic, lbl.opt_manual, lbl.ttl_jira_cloud_integration, lbl.ttl_jira_server_integration]

    logic_monitor_labels = [lbl.desc_logic_monitor_credentials, lbl.det_logic_monitor_account_name,
                            lbl.det_logic_monitor_api_key, lbl.onb_skip_this, lbl.ttl_logic_monitor_integration]

    monday_labels = [lbl.det_automatically_create_taskcall_incident_from_monday,
                     lbl.det_configure_how_monday_will_create_incidents_in_taskcall,
                     lbl.det_configure_how_taskcall_will_create_monday_items, lbl.det_create_item_mode,
                     lbl.det_group, lbl.det_map_taskcall_monday_fields, lbl.det_monday_board_to_integrate_with,
                     lbl.det_sync_taskcall_notes_with_monday, lbl.det_trigger_incident_when, lbl.dsm_date_arrives,
                     lbl.dsm_new_item_is_created, lbl.dsm_of_column, lbl.dsm_value_changes, lbl.ins_add_condition,
                     lbl.ttl_monday_integration]

    rundeck_labels = [lbl.ttl_authorization, lbl.ttl_rundeck_integration]

    servicenow_labels = [lbl.det_configure_how_taskcall_will_create_servicenow_incidents,
                         lbl.det_servicenow_configure_how_users_and_assignment_groups_map,
                         lbl.det_default_user, lbl.det_impact, lbl.det_instance_url, lbl.det_servicenow_default_service,
                         lbl.det_servicenow_default_user_description, lbl.det_servicenow_instance_details,
                         lbl.det_servicenow_map_services, lbl.det_sync_taskcall_notes_with_servicenow,
                         lbl.det_sync_taskcall_status_with_servicenow, lbl.det_sync_taskcall_urgency_with_servicenow,
                         lbl.err_servicenow_integration_exists, lbl.err_servicenow_integration_fields_invalid,
                         lbl.ins_add, lbl.msg_servicenow_credentials_updated, lbl.opt_closed, lbl.opt_in_progress,
                         lbl.opt_new, lbl.opt_on_hold, lbl.opt_resolved, lbl.ttl_assignment_groups,
                         lbl.ttl_escalation_policies, lbl.ttl_servicenow_integration]

    team_dynamix_labels = [lbl.det_account, lbl.det_application,
                           lbl.det_configure_how_taskcall_will_create_team_dynamix_ticket,
                           lbl.det_sync_taskcall_notes_with_team_dynamix,
                           lbl.det_sync_taskcall_status_with_team_dynamix,
                           lbl.det_sync_taskcall_urgency_with_team_dynamix, lbl.det_team_dynamix_account_details,
                           lbl.det_team_dynamix_domain, lbl.err_team_dynamix_integration_fields_invalid,
                           lbl.msg_team_dynamix_credentials_updated, lbl.msg_team_dynamix_use_existing,
                           lbl.ttl_team_dynamix_integration]

    solarwinds_servicedesk_labels = [
        lbl.det_account, lbl.det_administrator_api_key,
        lbl.det_administrator_user,
        lbl.det_automatically_create_ticket_for_incidents_with_minimum_urgency,
        lbl.det_category, lbl.det_configuration_name,
        lbl.det_configure_how_taskcall_will_create_solarwinds_servicedesk_ticket,
        lbl.det_solarwinds_servicedesk_account_details,
        lbl.det_solarwinds_servicedesk_domain,
        lbl.det_sync_taskcall_notes_with_solarwinds_servicedesk,
        lbl.det_sync_taskcall_status_with_solarwinds_servicedesk,
        lbl.det_sync_taskcall_urgency_with_solarwinds_servicedesk,
        lbl.err_invalid_value,
        lbl.ins_next, lbl.ins_reauthorize,
        lbl.msg_solarwinds_servicedesk_credentials_updated,
        lbl.msg_solarwinds_servicedesk_use_existing, lbl.sts_acknowledged,
        lbl.sts_open, lbl.sts_pending, lbl.sts_resolved,
        lbl.ttl_solarwinds_servicedesk_integration
    ]

    zendesk_labels = [lbl.det_automatically_create_ticket_for_incidents_with_minimum_urgency,
                      lbl.det_configure_how_taskcall_will_create_zendesk_ticket,
                      lbl.det_sync_taskcall_notes_with_zendesk, lbl.det_sync_taskcall_status_with_zendesk,
                      lbl.det_sync_taskcall_urgency_with_zendesk, lbl.det_ticket_type, lbl.det_zendesk_subdomain,
                      lbl.err_zendesk_subdomain_invalid, lbl.msg_zendesk_reauthorized, lbl.opt_normal, lbl.opt_urgent,
                      lbl.sts_closed, lbl.sts_hold, lbl.sts_new, lbl.sts_open, lbl.sts_pending, lbl.sts_solved,
                      lbl.ttl_incident, lbl.ttl_problem, lbl.ttl_question, lbl.ttl_task, lbl.ttl_zendesk_integration]

    page_labels = common_labels + settings_labels + integration_labels + activity_labels +\
        incident_status_labels + autotask_labels + custom_integration_labels + freshdesk_labels + freshservice_labels +\
        halo_itsm_labels + jira_labels + logic_monitor_labels + monday_labels + rundeck_labels + servicenow_labels +\
        solarwinds_servicedesk_labels + team_dynamix_labels + zendesk_labels

    res_labels = [lbl.res_creating_services, lbl.res_adding_service_integrations, lbl.res_transfer_integration,
                  lbl.res_disabling_a_service, lbl.res_schedule_service_maintenance, lbl.res_services_list,
                  lbl.res_business_services, lbl.res_slack_integration_guide]
    page_labels += res_labels

    page_descriptions = [lbl.desc_integration_with_built_in_tool, lbl.desc_integration_with_custom_action,
                         lbl.desc_integration_with_custom_payload, lbl.desc_integration_with_email,
                         lbl.desc_service_no_incidents, lbl.desc_service_no_integration,
                         lbl.desc_service_no_recent_changes, lbl.desc_service_no_suppressed_alerts]

    final_context = {**top_bar_context, **months_days_context, **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_service_new_context(lang, allowed_components):
    '''
    Context for the new service page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)

    page_labels = [lbl.ttl_services, lbl.ttl_new_service, lbl.det_name, lbl.det_description, lbl.ttl_settings,
                   lbl.det_assign_to_escalation_policy, lbl.det_service_re_trigger_incident_after,
                   lbl.det_service_allow_auto_grouping, lbl.det_support_hours, lbl.det_from, lbl.det_to,
                   lbl.dsm_minutes, lbl.ttl_timezone, lbl.det_service_de_prioritize_in_off_hours,
                   lbl.det_service_re_prioritize_un_ack_incidents_in_on_hours, lbl.err_select_at_least_one_assignee,
                   lbl.err_service_support_hours_incomplete, lbl.ins_create, lbl.ins_cancel,
                   lbl.day_mon, lbl.day_tue, lbl.day_wed, lbl.day_thu, lbl.day_fri, lbl.day_sat, lbl.day_sun]

    page_descriptions = [lbl.desc_service, lbl.desc_service_add_integrations_later_note,
                         lbl.err_service_name_invalid]

    final_context = {**top_bar_context, **lt.get_context(page_labels + page_descriptions, lang)}
    return final_context


def get_business_service_list_context(lang, allowed_components):
    '''
    Context for the business service list page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)

    page_labels = [lbl.ttl_business_services, lbl.ttl_business_service, lbl.ttl_min_impact_urgency, lbl.ttl_team,
                   lbl.ttl_supporting_services, lbl.ttl_subscribers, lbl.ttl_new_business_service,
                   lbl.ttl_technical_services, lbl.res_resources, lbl.ins_view, lbl.ins_edit, lbl.ins_delete,
                   lbl.ins_yes, lbl.ins_no, lbl.qqs_are_you_sure_you_want_to_delete_this_business_service]

    option_labels = [lbl.opt_critical, lbl.opt_high, lbl.opt_medium, lbl.opt_low, lbl.opt_minor]
    res_labels = [lbl.res_business_services, lbl.res_business_service_subscriptions, lbl.res_business_impact_visibility,
                  lbl.res_creating_services]

    page_labels = page_labels + option_labels + res_labels
    page_descriptions = [lbl.desc_business_service, lbl.desc_component_empty]

    final_context = {**top_bar_context, **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_business_service_details_context(lang, allowed_components):
    '''
    Context for the business service details page - both new and edit.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)

    page_labels = [lbl.det_description, lbl.det_name, lbl.det_select_services_to_add,
                   lbl.err_business_service_supporting_min, lbl.err_service_name_invalid,
                   lbl.err_service_self_dependency, lbl.ins_add, lbl.ins_cancel, lbl.ins_create, lbl.ins_save,
                   lbl.ttl_business_services, lbl.ttl_details, lbl.ttl_min_impact_urgency, lbl.ttl_new_business_service,
                   lbl.ttl_supporting_services, lbl.ttl_teams, lbl.ttl_technical_services]

    option_labels = [lbl.opt_critical, lbl.opt_high, lbl.opt_medium, lbl.opt_low, lbl.opt_minor]
    page_labels += option_labels

    page_descriptions = [lbl.desc_business_service, lbl.desc_business_service_min_impact_urgency,
                         lbl.desc_business_supporting_services]

    final_context = {**top_bar_context, **lt.get_context(page_labels + page_descriptions, lang)}
    return final_context


def get_dependency_graph_context(lang, allowed_components):
    '''
    Context for the service dependency graph.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)

    page_labels = [lbl.det_create_dependency, lbl.det_depends_on, lbl.det_disabled, lbl.det_healthy, lbl.det_impacted,
                   lbl.det_manage_dependency, lbl.det_none, lbl.det_on_call, lbl.det_remove_dependency, lbl.det_status,
                   lbl.err_service_business_dependency, lbl.msg_no_open_incidents, lbl.ttl_all_services,
                   lbl.ttl_business_service, lbl.ttl_business_services, lbl.ttl_dependency_graph, lbl.ttl_details,
                   lbl.ttl_escalation_policy, lbl.ttl_open_incidents, lbl.ttl_services, lbl.ttl_team,
                   lbl.ttl_technical_service, lbl.ttl_technical_services, lbl.ttl_view_incidents,
                   lbl.ttl_view_service_settings, lbl.ttl_watch_tutorial]

    page_descriptions = [lbl.desc_service_add_dependency, lbl.desc_service_remove_dependency]

    final_context = {**top_bar_context, **lt.get_context(page_labels + page_descriptions, lang)}
    return final_context


def get_recent_changes_context(lang, allowed_components):
    '''
    Context for the recent changes page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)
    months_days_context = components_context.get_months_days_context(lang)

    page_labels = [lbl.det_description, lbl.det_integration, lbl.det_service, lbl.dsm_by, lbl.dsm_page,
                   lbl.dsm_per_page, lbl.dsm_source, lbl.dsm_type, lbl.ins_no, lbl.ins_redact, lbl.ins_yes,
                   lbl.opt_all_integrations, lbl.opt_all_services, lbl.opt_all_teams, lbl.opt_anytime, lbl.opt_my_teams,
                   lbl.opt_within_24_hours, lbl.opt_within_7_days,
                   lbl.qqs_are_you_sure_you_want_to_redact_this_change_event, lbl.res_resources, lbl.ttl_created_on,
                   lbl.ttl_integration_type, lbl.ttl_last_changed, lbl.ttl_recent_changes, lbl.ttl_recent_changes_setup,
                   lbl.ttl_services, lbl.ttl_team, lbl.ttl_teams]

    res_labels = [lbl.res_what_are_change_events, lbl.res_github_change_events, lbl.res_gitlab_change_events,
                  lbl.res_adding_service_integrations]

    page_labels = page_labels + res_labels
    page_descriptions = [lbl.desc_recent_changes, lbl.desc_recent_changes_empty, lbl.desc_recent_changes_setup]

    final_context = {**top_bar_context, **months_days_context, **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_conference_bridges_context(lang, allowed_components):
    '''
    Context for the conference bridges page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)

    page_labels = [lbl.det_conference_bridge_manual, lbl.det_conference_bridge_microsoft_teams,
                   lbl.det_conference_bridge_microsoft_teams_select_integration,
                   lbl.det_conference_bridge_microsoft_teams_select_user,
                   lbl.det_conference_bridge_webex, lbl.det_conference_bridge_zoom, lbl.det_name,
                   lbl.err_conference_bridge_ms_teams_min_requirements, lbl.err_conference_bridge_name,
                   lbl.err_conference_bridge_phone_url_invalid, lbl.ins_cancel, lbl.ins_create, lbl.res_resources,
                   lbl.ttl_additional_details, lbl.ttl_conference_bridges, lbl.ttl_conference_type,
                   lbl.ttl_conference_url, lbl.ttl_details, lbl.ttl_dial_in_number,
                   lbl.ttl_microsoft_teams_conference_bridge, lbl.ttl_new_conference_bridge]

    res_labels = [lbl.res_setting_up_a_conference_bridge, lbl.res_webex_integration_guide,
                  lbl.res_zoom_integration_guide, lbl.res_mobilize_response, lbl.res_incident_status,
                  lbl.res_how_to_trigger_an_incident]

    page_labels += res_labels

    page_descriptions = [lbl.desc_component_empty, lbl.desc_conference_bridge]

    final_context = {**top_bar_context, **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_api_access_context(lang, allowed_components):
    '''
    Context for the API access page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)
    months_days_context = components_context.get_months_days_context(lang)

    page_labels = [lbl.det_disabled, lbl.det_key, lbl.det_name, lbl.det_optional, lbl.dsm_by, lbl.dsm_separate_by_comma,
                   lbl.err_invalid_request, lbl.ins_cancel, lbl.ins_create, lbl.ins_delete, lbl.ins_done,
                   lbl.ins_disable, lbl.ins_edit, lbl.ins_enable, lbl.ins_yes, lbl.ins_no, lbl.res_resources,
                   lbl.qqs_are_you_sure_you_want_to_delete_this_api_key, lbl.ttl_access_level, lbl.ttl_api_access,
                   lbl.ttl_api_key_security, lbl.ttl_api_version, lbl.ttl_created_on, lbl.ttl_ip_restrictions,
                   lbl.ttl_last_used, lbl.ttl_new_api_key]

    res_labels = [lbl.res_api_keys, lbl.res_incidents_api, lbl.res_how_to_trigger_an_incident,
                  lbl.res_notifications_mechanism, lbl.res_actions_you_can_perform]
    page_labels += res_labels

    page_descriptions = [lbl.desc_api_access, lbl.desc_api_access_security, lbl.desc_component_empty,
                         lbl.err_api_key_name_invalid, lbl.msg_api_key_created]
    final_context = {**top_bar_context, **months_days_context, **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_team_list_context(lang, allowed_components):
    '''
    Context for the team list page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)

    page_labels = [lbl.ttl_teams, lbl.ttl_team, lbl.ttl_new_team,
                   lbl.res_resources, lbl.ins_edit, lbl.ins_delete, lbl.ins_yes, lbl.ins_no,
                   lbl.qqs_are_you_sure_you_want_to_delete_this_team]
    res_labels = [lbl.res_creating_teams, lbl.res_editing_team_member_roles, lbl.res_team_components,
                  lbl.res_advanced_permissions, lbl.res_creating_on_call_routines,
                  lbl.res_configuring_escalation_policies, lbl.res_creating_services]
    page_labels += res_labels
    page_descriptions = [lbl.desc_component_empty, lbl.desc_team]

    final_context = {**top_bar_context, **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_team_new_context(lang, allowed_components):
    '''
    Context for the team list page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)

    page_labels = [lbl.det_make_team_private, lbl.det_name, lbl.err_team_member_count, lbl.err_team_name_invalid,
                   lbl.ins_add, lbl.ins_cancel, lbl.ins_create, lbl.ins_save, lbl.res_resources, lbl.ttl_new_team,
                   lbl.ttl_users]
    user_role_labels = [users_context.user_role_maps[role] for role in users_context.team_roles]

    page_labels = page_labels + user_role_labels
    page_descriptions = [lbl.desc_team]

    final_context = {**top_bar_context, **lt.get_context(page_labels + page_descriptions, lang)}
    return final_context


def get_team_details_context(lang, allowed_components):
    '''
    Context for the team details page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)

    page_labels = [lbl.det_make_team_private, lbl.det_name, lbl.det_private, lbl.det_public, lbl.det_role,
                   lbl.det_select_the_user_to_add_to_your_team, lbl.det_title, lbl.err_team_name_invalid, lbl.ins_add,
                   lbl.ins_cancel, lbl.ins_delete, lbl.ins_no, lbl.ins_save, lbl.ins_update, lbl.ins_yes,
                   lbl.qqs_are_you_sure_you_want_to_delete_this_team, lbl.res_resources, lbl.ttl_add_remove_tag,
                   lbl.ttl_add_team_member, lbl.ttl_components, lbl.ttl_delete_team, lbl.ttl_edit_team, lbl.ttl_email,
                   lbl.ttl_new_team, lbl.ttl_preferred_username, lbl.ttl_escalation_policies, lbl.ttl_routines,
                   lbl.ttl_services, lbl.ttl_teams, lbl.ttl_team_role]

    user_role_labels = [users_context.user_role_maps[role] for role in users_context.team_roles]

    res_labels = [lbl.res_creating_teams, lbl.res_editing_team_member_roles, lbl.res_team_components,
                  lbl.res_advanced_permissions, lbl.res_creating_on_call_routines,
                  lbl.res_configuring_escalation_policies, lbl.res_creating_services]

    page_labels = page_labels + user_role_labels + res_labels
    page_descriptions = [lbl.desc_team, lbl.err_ext_already_team_member]

    final_context = {**top_bar_context, **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_tags_context(lang, allowed_components):
    '''
    Context for the tags page
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)

    page_labels = [lbl.det_description, lbl.det_none, lbl.err_tag_invalid, lbl.ins_cancel, lbl.ins_delete, lbl.ins_edit,
                   lbl.ins_no, lbl.ins_save, lbl.ins_yes, lbl.msg_tag_created, lbl.msg_tag_deleted, lbl.msg_tag_edited,
                   lbl.qqs_are_you_sure_you_want_to_delete_this_tag, lbl.res_resources, lbl.ttl_associated_components,
                   lbl.ttl_escalation_policies, lbl.ttl_new_tag, lbl.ttl_services, lbl.ttl_tag, lbl.ttl_tags,
                   lbl.ttl_teams, lbl.ttl_users]

    res_labels = [lbl.res_contextual_search_and_tagging, lbl.res_user_roles, lbl.res_advanced_permissions,
                  lbl.res_creating_teams, lbl.res_team_components]

    page_labels = page_labels + res_labels
    page_descriptions = [lbl.desc_component_empty, lbl.desc_tag]

    final_context = {**top_bar_context, **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_live_call_routing_list_context(lang, allowed_components):
    '''
    Context for the live call routing list page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)

    page_labels = [lbl.det_local, lbl.det_mobile, lbl.det_name, lbl.det_toll_free, lbl.ins_delete, lbl.ins_edit,
                   lbl.ins_no, lbl.ins_view, lbl.ins_yes,
                   lbl.qqs_are_you_sure_you_want_to_delete_this_live_call_routing, lbl.res_resources,
                   lbl.ttl_associated_services, lbl.ttl_live_call_routing, lbl.ttl_new_live_call_routing,
                   lbl.ttl_phone_number]

    res_labels = [lbl.res_setting_up_live_call_routing, lbl.res_live_call_routing_pricing,
                  lbl.res_how_to_trigger_an_incident, lbl.res_notifications_mechanism, lbl.res_actions_you_can_perform]
    page_labels += res_labels

    page_descriptions = [lbl.desc_live_call_routing, lbl.desc_live_call_routing_empty]

    final_context = {**top_bar_context, **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_live_call_routing_details_context(lang, allowed_components):
    '''
    Context for the live call routing details page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)

    page_labels = [lbl.det_add_option_forwarding, lbl.det_audio_file, lbl.det_default_forwarding_service,
                   lbl.det_description, lbl.det_female, lbl.det_incident_title, lbl.det_language, lbl.det_local,
                   lbl.det_male, lbl.det_maximum_number_of_users_to_forward_to, lbl.det_mobile, lbl.det_name,
                   lbl.det_numbers_to_block, lbl.det_prompt_for_call_acceptance, lbl.det_record_call,
                   lbl.det_record_voicemail, lbl.det_resolve_incident_when_answered_calls_end,
                   lbl.det_resolve_incident_when_unanswered_calls_end, lbl.det_search_phone_number,
                   lbl.det_send_alert_notifications_for_unresolved_incidents,
                   lbl.det_show_incoming_caller_id_when_forwarding, lbl.det_text,
                   lbl.det_timeout_of_every_forwarding_attempt, lbl.det_toll_free, lbl.det_urgency_of_created_incident,
                   lbl.det_voice, lbl.dsm_option, lbl.err_file_too_big, lbl.err_live_call_route_block_numbers,
                   lbl.err_live_call_route_ending, lbl.err_live_call_route_greeting,
                   lbl.err_live_call_route_max_users_and_timeout, lbl.err_live_call_route_name,
                   lbl.err_live_call_route_option_number, lbl.err_live_call_route_options_without_greeting,
                   lbl.err_live_call_route_phone_no_results, lbl.err_live_call_route_phone_number,
                   lbl.err_select_at_least_one_service, lbl.ins_cancel,
                   lbl.ins_no, lbl.ins_save, lbl.ins_select, lbl.ins_yes, lbl.opt_critical, lbl.opt_english,
                   lbl.opt_french, lbl.opt_german, lbl.opt_high, lbl.opt_low, lbl.opt_medium, lbl.opt_minor,
                   lbl.opt_spanish, lbl.msg_live_call_route_call_acceptance_prompt_hint,
                   lbl.msg_live_call_route_default_call_acceptance_prompt,
                   lbl.msg_live_call_route_default_incident_title, lbl.msg_live_call_route_incident_title_hint,
                   lbl.qqs_are_you_sure_you_want_to_delete_this_live_call_routing, lbl.res_resources,
                   lbl.ttl_area_code, lbl.ttl_configurations, lbl.ttl_country, lbl.ttl_delete_routing,
                   lbl.ttl_edit_routing, lbl.ttl_ending_note, lbl.ttl_forwarding_services, lbl.ttl_greeting,
                   lbl.ttl_live_call_routing, lbl.ttl_new_live_call_routing, lbl.ttl_phone_number, lbl.ttl_settings]

    res_labels = [lbl.res_setting_up_live_call_routing, lbl.res_live_call_routing_pricing,
                  lbl.res_how_to_trigger_an_incident, lbl.res_notifications_mechanism, lbl.res_actions_you_can_perform]
    page_labels += res_labels

    page_descriptions = [lbl.desc_live_call_routing_ending_note, lbl.desc_live_call_routing_forwarding_services,
                         lbl.desc_live_call_routing_forwarding_services_options, lbl.desc_live_call_routing_greeting,
                         lbl.desc_live_call_routing_phone_number]

    final_context = {**top_bar_context, **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context


def get_organization_info_context(lang, allowed_components):
    '''
    Context for the organization info page.
    '''
    top_bar_context = components_context.get_dashboard_topbar_context(lang, allowed_components)
    months_days_context = components_context.get_months_days_context(lang)
    sector_context = components_context.get_sectors_context(lang)

    page_labels = [lbl.desc_subscription_update_warning, lbl.det_allow_auto_provisioning,
                   lbl.det_allow_login_with_taskcall_credentials, lbl.det_assertion_consumer_service_url,
                   lbl.det_certificate_x509, lbl.det_default_user_role, lbl.det_card, lbl.det_default,
                   lbl.det_enter_azure_ad_account_domain, lbl.det_enter_google_apps_account_domain,
                   lbl.det_enter_okta_account_domain, lbl.det_enter_okta_client_id, lbl.det_enter_okta_client_secret,
                   lbl.det_fee, lbl.det_idp_entity_id, lbl.det_language, lbl.det_login_url, lbl.det_new_card_added,
                   lbl.det_org_invoice_email_notifications_cc, lbl.det_org_show_on_invoice,
                   lbl.det_org_use_different_billing_address, lbl.det_paid, lbl.det_role, lbl.det_set_as_default,
                   lbl.det_status, lbl.det_switch, lbl.det_title, lbl.det_transfer_ownership,
                   lbl.det_update_subscription_plan_to, lbl.det_upgrade, lbl.det_year, lbl.det_your_subscription,
                   lbl.dsm_card_ending_in, lbl.dsm_card_number, lbl.dsm_coupon, lbl.dsm_domain, lbl.dsm_month,
                   lbl.dsm_per_user, lbl.dsm_verification_code, lbl.err_invalid_coupon, lbl.err_invalid_email,
                   lbl.err_org_account_closure_consent, lbl.err_org_address_incomplete,
                   lbl.err_org_card_deletion_default, lbl.err_org_card_details_invalid,
                   lbl.err_org_client_id_and_secret, lbl.err_org_name_invalid, lbl.err_org_subscription_same,
                   lbl.err_sso_invalid_vendor_domain, lbl.err_sso_saml, lbl.err_sso_type_invalid,
                   lbl.err_subdomain_invalid, lbl.err_system_error, lbl.err_unknown_resource,
                   lbl.err_verification_failed, lbl.ins_add, lbl.ins_cancel, lbl.ins_delete, lbl.ins_no, lbl.ins_save,
                   lbl.ins_transfer, lbl.ins_update, lbl.ins_yes, lbl.msg_account_card_added, lbl.msg_account_card_none,
                   lbl.msg_account_subscription_updated, lbl.msg_org_credits_added, lbl.msg_org_no_active_credits,
                   lbl.msg_sso_settings_saved, lbl.opt_business, lbl.opt_digital_operations,
                   lbl.opt_free, lbl.opt_starter, lbl.qqs_are_you_sure_you_want_to_save_sso_settings,
                   lbl.qqs_are_you_sure_you_want_to_transfer_your_ownership_of_the_account,
                   lbl.qqs_are_you_sure_you_want_to_update_your_billing_information,
                   lbl.qqs_are_you_sure_you_want_to_update_your_organization_subscription, lbl.res_resources,
                   lbl.ttl_account_number, lbl.ttl_account_owner, lbl.ttl_active_credits,
                   lbl.ttl_additional_sso_settings, lbl.ttl_address, lbl.ttl_billings, lbl.ttl_billing_currency,
                   lbl.ttl_billing_information, lbl.ttl_billing_period, lbl.ttl_city, lbl.ttl_close_account,
                   lbl.ttl_credit_amount, lbl.ttl_credit_name, lbl.ttl_credit_remaining, lbl.ttl_country,
                   lbl.ttl_credits, lbl.ttl_current_owner_new_role, lbl.ttl_details, lbl.ttl_email,
                   lbl.ttl_expiration_date, lbl.ttl_grant_date, lbl.ttl_invoice, lbl.ttl_invoice_date,
                   lbl.ttl_invoice_amount, lbl.ttl_invoice_email_notifications, lbl.ttl_login_authentication,
                   lbl.ttl_new_owner, lbl.ttl_new_user, lbl.ttl_organization, lbl.ttl_organization_name,
                   lbl.ttl_payment_date, lbl.ttl_payment_instrument, lbl.ttl_payment_methods, lbl.ttl_payment_status,
                   lbl.ttl_redeem_credit, lbl.ttl_requested_users, lbl.ttl_sector, lbl.ttl_single_sign_on,
                   lbl.ttl_state, lbl.ttl_subdomain, lbl.ttl_subscription, lbl.ttl_summary, lbl.ttl_timezone,
                   lbl.ttl_total_amount_remaining, lbl.ttl_total_amount_used, lbl.ttl_update_billing_information,
                   lbl.ttl_update_subscription, lbl.ttl_vat_id, lbl.ttl_warning, lbl.ttl_zip_code]

    user_role_labels = list(users_context.user_role_maps.values())
    res_labels = [lbl.res_adding_a_user, lbl.res_advanced_permissions, lbl.res_transfer_ownership,
                  lbl.res_setting_up_sso, lbl.res_subscription_plans]
    page_labels = page_labels + user_role_labels + res_labels + list(components_context.language_maps.values())

    page_descriptions = [lbl.desc_account_closure_last_warning, lbl.desc_account_closure_no_billings_access,
                         lbl.desc_account_closure_no_data_access, lbl.desc_account_closure_owner_acknowledgement,
                         lbl.desc_account_closure_pending_bills, lbl.desc_account_closure_verification,
                         lbl.desc_sso_directly_with_taskcall, lbl.desc_sso_oidc_authentication_protocol,
                         lbl.desc_sso_saml_authentication_protocol, lbl.desc_sso_users_added_automatically,
                         lbl.desc_sso_with_taskcall_authentication, lbl.desc_subscription_business,
                         lbl.desc_subscription_digital_operations, lbl.desc_subscription_free,
                         lbl.desc_subscription_starter, lbl.msg_org_info_updated, lbl.msg_org_subdomain_updated]

    final_context = {**top_bar_context, **months_days_context, **sector_context,
                     **lt.get_context(page_labels + page_descriptions, lang)}
    final_context[var_names.resource_items] = resources_context.get_resources_content(res_labels, final_context)
    return final_context
