add_namespace = eeu


country_event = {
	id = eeu.200

	hidden = yes

	trigger = {
		has_game_rule = {
			rule = eeu_rule_enable_separatism
			option = eeu_rule_enable_separatism_yes
		}
		tag = var:global.eeu_tag
		has_global_flag = form_european_union_flag
		has_global_flag = {
			flag = form_european_union_flag
			days > 180
		}
		NOT = {
			has_global_flag = eeu_flag_global_union
		}
		var:global.eeu_tag = {
			has_power_balance = {
				id = eeu_balance_of_power
			}
			has_stability < 0.45
		}
	}

	mean_time_to_happen = {
		days = 180
	}

	immediate = {
		log = "eeu: eeu_tag is [?global.eeu_tag.GetName]"
		log = "eeu: separatism: === eligable countries ===" 

		clear_temp_array = eeu_separatism_eligable_countries
		for_each_scope_loop = {
			array = global.countries
			if = {
				limit = {
					exists = no
					is_dynamic_country = no
					# if = {
					# 	limit = {
					# 		exists = no
					# 	}
					# 	always = yes
					# }
					# else = {
					# 	log = "[THIS.GetName] : exists"
					# 	always = no
					# }
					# if = {
					# 	limit = {
					# 		is_dynamic_country = no
					# 	}
					# 	always = yes
					# }
					# else = {^^
					# 	log = "[THIS.GetName] : is dynamic"
					# 	always = no
					# }
					any_of_scopes = {
						array = core_states
						is_on_continent = europe
						# if = {
						# 	limit = {
						# 		is_on_continent = europe
						# 	}
						# 	always = yes
						# }
						# else = {
						# 	log = "[PREV.GetName] : [THIS.GetName] not in europe"
						# 	always = no
						# }
						var:global.eeu_tag = {
							owns_state = PREV
						}
						# if = {
						# 	limit = {
						# 		var:global.eeu_tag = {
						# 			owns_state = PREV
						# 		}
						# 	}
						# 	always = yes
						# }
						# else = {
						# 	log = "[PREV.GetName] : [THIS.GetName] not owned by EU"
						# 	always = no
						# }
						any_neighbor_state = {
							var:global.eeu_tag = {
								NOT = { owns_state = PREV }
							}
						}
					}
				}
				log = "eeu: separatism: ELIGABLE [THIS.GetName] with [?THIS.core_states^num] cores"
				add_to_temp_array = { eeu_separatism_eligable_countries = THIS }
			}
			# else = {
			# 	log = "eeu: separatism: NOT eligable [THIS.GetName] with [?THIS.core_states^num] cores"
			# }
		}
			
		log = "eeu: separatism: found [?eeu_separatism_eligable_countries^num] eligable countries"
		random_scope_in_array = {
			array = eeu_separatism_eligable_countries
			log = "eeu: separatism trigger: select [THIS.GetName]"
			set_variable = { global.eeu_seperating_country = THIS }
			log = "eeu: separatism trigger: set [?eeu_seperating_country.GetName]"
			var:global.eeu_tag = {
				country_event = {
					id = eeu.201
				}
			}
		}
	}

	option = {

	}
}


country_event = { # separatism event
	id = eeu.201
	title = eeu.201.t
	desc = eeu.201.d
	picture = GFX_report_event_generic_parliament

	is_triggered_only = yes

	immediate = {
		log = "eeu: separatism event: has seperating countrs [?global.eeu_seperating_country.GetName]"
	}

	option = { 
		name = eeu.201.a
		trigger = {
			has_political_power > 50
		}

		add_political_power = -100
	}
	option = {
		name = eeu.201.b
		trigger = {
			has_country_flag = eeu_flag_bop_allow_repression
		}

		var:global.eeu_seperating_country = {
			for_each_scope_loop = {
				array = core_states
				add_resistance = 0.05
				add_compliance = -0.05
			}
		}
	}
	option = {
		name = eeu.201.c
		trigger = {
			has_political_power > 25
			has_country_flag = eeu_flag_bop_allow_church
		}

		add_political_power = -75
	}
	option = {
		name = eeu.201.e

		add_stability = 0.25
		
		release = var:global.eeu_seperating_country
		var:global.eeu_seperating_country = {
			set_country_flag = eeu_flag_left_eu
			add_timed_idea = {
				idea = eeu_idea_left_eu
				days = 175
			}
		}

		if = {
			limit = {
				OR = {
					has_government = communism
					has_government = neutrality
					has_government = fascism
				}
			}
			create_wargoal = {
				target = var:global.eeu_seperating_country
				type = annex_everything
			}
		}
		# else_if = {
		# 	limit = { 
		# 		has_government = fascism
		# 	}
		# 	declare_war_on = {
		# 		target = var:global:eeu_seperating_country
		# 	}
		# }
	}
	option = {
		name = eeu.201.f
		trigger = {
			has_government = democratic
		}

		add_stability = 0.25

		release_puppet = var:global.eeu_seperating_country
		set_autonomy = {
			target = var:global.eeu_seperating_country
			autonomy_state = eeu_autonomy_prospect
		}
	}
}