# The display is opt-in through a GUI variable; this cache never enables it.
cmp_b7_refresh_marked_country = {
	scope = country
	is_shown = { is_player = yes }
	effect = {
		# Keep an ordinary country as the fallback, including when no mark exists.
		set_variable = { name = cmp_b7_display_country value = this }
		random_country = {
			limit = { has_variable = sakuya_mark_country_target }
			root = { set_variable = { name = cmp_b7_display_country value = prev } }
		}
		if = {
			limit = { NOT = { any_country = { has_variable = sakuya_mark_country_target } } }
			ordered_decentralized_country = {
				limit = { has_variable = sakuya_mark_country_target }
				order_by = gdp
				position = 0
				check_range_bounds = no
				root = { set_variable = { name = cmp_b7_display_country value = prev } }
			}
		}
	}
}

cmp_b7_display_country_valid = {
	scope = country
	is_shown = {
		is_player = yes
		trigger_if = {
			limit = { has_variable = cmp_b7_display_country }
			trigger_if = {
				limit = { exists = var:cmp_b7_display_country }
				var:cmp_b7_display_country = {
					has_variable = sakuya_mark_country_target
					any_scope_state = { always = yes }
				}
			}
			trigger_else = { always = no }
		}
		trigger_else = { always = no }
	}
}
