scripted_gui = {

	#######################################################
	#	GENERAL SETTINGS
	#######################################################
	
	EAI_config_GENERAL = {
		context_type = player_context

		window_name = "EAI_config_GENERAL_window"

		dirty = ROOT.EAI_refresh_gui
		
		visible = { 
			has_country_flag = EAI_config_GENERAL 
			NOT = { has_country_flag = EAI_config_ARMY }
			NOT = { has_country_flag = EAI_config_COUNTRY }
		}

		properties = {

			# EAI_config_GENERAL_2_button = {
			# 	image = "[EAI_GetAntiAggressionSetting]"
			# }

			EAI_config_GENERAL_3_button = {
				image = "[EAI_GetLendLeaseSetting]"
			}

			EAI_config_GENERAL_4_button = {
				image = "[EAI_GetLimitResearchSetting]"
			}

			EAI_config_GENERAL_5_button = {
				image = "[EAI_GetLimitSAProductionSetting]"
			}

			EAI_config_GENERAL_6_button = {
				image = "[EAI_GetNeutralSpainSetting]"
			}

			EAI_config_GENERAL_7_button = {
				image = "[EAI_GetAggressiveGermanySetting]"
			}

			EAI_config_GENERAL_9_button = {
				image = "[EAI_GetRandomIdeologySetting]"
			}

			EAI_config_GENERAL_10_button = {
				image = "[EAI_GetPuppetEgyptSetting]"
			}

			EAI_config_GENERAL_11_button = {
				image = "[EAI_GetDontInvadeNorwaySetting]"
			}

			EAI_config_GENERAL_12_button = {
				image = "[EAI_GetNeutralSouthAmericaSetting]"
			}
		}
		
		effects = {

			EAI_config_GENERAL_1_dropdown_button_click = {

				if = { limit = { has_country_flag = EAI_show_ai_focuses_dropdown }
					clr_country_flag = EAI_show_ai_focuses_dropdown
				}
				else = {
					set_country_flag = EAI_show_ai_focuses_dropdown
				}

				EAI_refresh_gui = yes
			}

			EAI_global_army_config_button_click = {

				if = { limit = { EAI_MODE_historical = yes }
				
					EAI_FOCUS_set_historical = yes
				}

				set_variable = { EAI_configuration_target = Root.id }

				clear_array = EAI_config_country_list_selected_country_array

				set_country_flag = EAI_config_ARMY

				set_country_flag = EAI_config_ARMY_GLOBAL

				EAI_refresh_gui = yes
			}

			# EAI_config_GENERAL_2_button_click = {
			# 	if = { limit = { has_global_flag = EAI_anti_aggression_diplomacy }
			# 		clr_global_flag = EAI_anti_aggression_diplomacy
			# 	}
			# 	else = {
			# 		set_global_flag = EAI_anti_aggression_diplomacy
			# 	}
			# }

			EAI_config_GENERAL_3_button_click = {

				if = { limit = { has_global_flag = EAI_lend_lease }
					clr_global_flag = EAI_lend_lease
				}
				else = {
					set_global_flag = EAI_lend_lease
				}

				EAI_refresh_gui = yes
			}

			EAI_config_GENERAL_4_button_click = {

				if = { limit = { has_global_flag = EAI_limit_research }

					clr_global_flag = EAI_limit_research

					every_country = {
						limit = { has_country_flag = EAI_slots_reduced_3 }
						add_research_slot = 3
						clr_country_flag = EAI_slots_reduced_3
					}
					every_country = {
						limit = { has_country_flag = EAI_slots_reduced_2 }
						add_research_slot = 2
						clr_country_flag = EAI_slots_reduced_2
					}
					every_country = {
						limit = { has_country_flag = EAI_slots_reduced_1 }
						add_research_slot = 1
						clr_country_flag = EAI_slots_reduced_1
					}
				}
				else = {

					set_global_flag = EAI_limit_research 

					every_country = {
						limit = { NOT = { EAI_major_country = yes } original_research_slots > 3 }
						add_research_slot = -3
						set_country_flag = EAI_slots_reduced_3
					}
					every_country = {
						limit = { NOT = { EAI_major_country = yes } original_research_slots > 2 original_research_slots < 4 }
						add_research_slot = -2
						set_country_flag = EAI_slots_reduced_2
					}
					every_country = {
						limit = { NOT = { EAI_major_country = yes } original_research_slots > 1 original_research_slots < 3 }
						add_research_slot = -1
						set_country_flag = EAI_slots_reduced_1
					}
				}

				EAI_refresh_gui = yes
			}

			EAI_config_GENERAL_5_button_click = {

				if = { limit = { has_global_flag = EAI_performance_mode }
					clr_global_flag = EAI_performance_mode
				}
				else = {
					set_global_flag = EAI_performance_mode
				}

				EAI_refresh_gui = yes
			}

			EAI_config_GENERAL_6_button_click = {

				if = { limit = { has_global_flag = EAI_neutral_spr }
				
					clr_global_flag = EAI_neutral_spr

					every_country = { limit = { is_ai = yes original_tag = SPR }

						remove_ideas = EAI_neutrality_idea_SPR
					}

				}
				else = {
					set_global_flag = EAI_neutral_spr
				}

				EAI_refresh_gui = yes
			}

			EAI_config_GENERAL_7_button_click = {

				if = { limit = { has_global_flag = EAI_aggressive_GER }
					clr_global_flag = EAI_aggressive_GER
				}
				else = {
					set_global_flag = EAI_aggressive_GER
				}

				EAI_refresh_gui = yes
			}

			EAI_config_GENERAL_8_dropdown_button_click = {

				if = { limit = { has_country_flag = EAI_show_justification_aggressiveness_dropdown }
					clr_country_flag = EAI_show_justification_aggressiveness_dropdown
				}
				else = {
					set_country_flag = EAI_show_justification_aggressiveness_dropdown
				}

				EAI_refresh_gui = yes
			}

			EAI_config_GENERAL_9_button_click = {

				if = { limit = { has_global_flag = EAI_random_ideology }
					clr_global_flag = EAI_random_ideology
				}
				else = {
					set_global_flag = EAI_random_ideology
				}

				EAI_refresh_gui = yes
			}

			EAI_config_GENERAL_10_button_click = {

				if = { limit = { has_global_flag = EAI_puppet_EGY }
					clr_global_flag = EAI_puppet_EGY

					EGY = { 
						drop_cosmetic_tag = yes
					}
					ENG = { annex_country = { target = EGY transfer_troops = yes } }
				}
				else = {
					set_global_flag = EAI_puppet_EGY

					ENG = { release_puppet = EGY }
					EGY = { set_cosmetic_tag = ENG }
				}

				EAI_refresh_gui = yes
			}

			EAI_config_GENERAL_11_button_click = {

				if = { limit = { has_global_flag = EAI_GER_dont_invade_NOR }
					clr_global_flag = EAI_GER_dont_invade_NOR
				}
				else = {
					set_global_flag = EAI_GER_dont_invade_NOR
				}

				EAI_refresh_gui = yes
			}

			EAI_config_GENERAL_12_button_click = {

				if = { limit = { has_global_flag = EAI_neutral_south_america }
					clr_global_flag = EAI_neutral_south_america
				}
				else = {
					set_global_flag = EAI_neutral_south_america
				}

				EAI_refresh_gui = yes
			}

			EAI_config_GENERAL_13_dropdown_button_click = {

				if = { limit = { has_country_flag = EAI_show_sino_japanese_war_dropdown }
					clr_country_flag = EAI_show_sino_japanese_war_dropdown
				}
				else = {
					set_country_flag = EAI_show_sino_japanese_war_dropdown
				}

				EAI_refresh_gui = yes
			}

			EAI_config_GENERAL_14_dropdown_button_click = {

				if = { limit = { has_country_flag = EAI_show_eastern_front_dropdown }
					clr_country_flag = EAI_show_eastern_front_dropdown
				}
				else = {
					set_country_flag = EAI_show_eastern_front_dropdown
				}

				EAI_refresh_gui = yes
			}

			###########################################
		
			EAI_config_GENERAL_button1_click = {

				clr_country_flag = EAI_config_GENERAL
				set_country_flag = EAI_config_DIFFICULTY

				EAI_refresh_gui = yes
			}

			# EXIT
			EAI_config_exit_click = {

				clr_country_flag = EAI_config_DIFFICULTY
				
				clr_country_flag = EAI_config_GENERAL
				
				clr_country_flag = EAI_show_country_config_decisions

				if = { limit = { EAI_MODE_historical = yes }
					EAI_FOCUS_set_historical = yes
				}
				
				if = { limit = { date > 1936.7.1 }

					every_country = {
						limit = { is_ai = yes NOT = { has_country_flag = EAI_military_focus_config_finished } }
						
						EAI_FOCUS_CONFIG/set_focuses = yes
					}
				}
				
				country_event = EAI.1000 # forces the decision visible triggers to refresh

				EAI_refresh_gui = yes
			}
		}

		triggers = {

			EAI_config_GENERAL_7_button_visible = {
				always = no
			}

			EAI_config_GENERAL_6_button_visible = {
				always = no
			}

			EAI_config_GENERAL_10_button_visible = {
				always = no
			}

			EAI_config_GENERAL_11_button_visible = {
				always = no
			}
		}
	}
	
	# military focus setting
	EAI_config_GENERAL_1 = {
		context_type = player_context

		window_name = "EAI_config_GENERAL_1_window"

		parent_window_name = "EAI_config_GENERAL_window"

		dirty = ROOT.EAI_refresh_gui

		visible = { has_country_flag = EAI_show_ai_focuses_dropdown }

		effects = {

			EAI_config_GENERAL_1a_click = {

				ROOT = { clr_country_flag = EAI_show_ai_focuses_dropdown }
				
				EAI_MODE_clear_challenging = yes
				clr_global_flag = EAI_historical_mode
				clr_global_flag = EAI_random_focuses

				EAI_refresh_gui = yes
			}
			EAI_config_GENERAL_1b_click = {

				ROOT = { clr_country_flag = EAI_show_ai_focuses_dropdown }
				
				EAI_MODE_clear_challenging = yes
				clr_global_flag = EAI_historical_mode
				clr_global_flag = EAI_random_focuses
				
				EAI_MODE_set_challenging = yes

				EAI_refresh_gui = yes
			}
			EAI_config_GENERAL_1c_click = {

				ROOT = { clr_country_flag = EAI_show_ai_focuses_dropdown }
				
				EAI_MODE_clear_challenging = yes
				clr_global_flag = EAI_historical_mode
				clr_global_flag = EAI_random_focuses
				
				set_global_flag = EAI_historical_mode

				EAI_refresh_gui = yes
			}
			EAI_config_GENERAL_1d_click = {

				ROOT = { clr_country_flag = EAI_show_ai_focuses_dropdown }
				
				EAI_MODE_clear_challenging = yes
				clr_global_flag = EAI_historical_mode
				clr_global_flag = EAI_random_focuses
				
				set_global_flag = EAI_random_focuses

				EAI_refresh_gui = yes
			}
		}
	}

	# ai justification aggressiveness
	EAI_config_GENERAL_8 = {
		context_type = player_context

		window_name = "EAI_config_GENERAL_8_window"

		parent_window_name = "EAI_config_GENERAL_window"

		dirty = ROOT.EAI_refresh_gui

		visible = { has_country_flag = EAI_show_justification_aggressiveness_dropdown }

		effects = {

			EAI_config_GENERAL_8a_click = {
				
				ROOT = { clr_country_flag = EAI_show_justification_aggressiveness_dropdown }
				
				clear_variable = global.EAI_justification_aggressiveness

				EAI_refresh_gui = yes
			}
			EAI_config_GENERAL_8b_click = {
				
				ROOT = { clr_country_flag = EAI_show_justification_aggressiveness_dropdown }
				
				set_variable = { global.EAI_justification_aggressiveness = 1 }

				EAI_refresh_gui = yes
			}
			EAI_config_GENERAL_8c_click = {
				
				ROOT = { clr_country_flag = EAI_show_justification_aggressiveness_dropdown }
				
				set_variable = { global.EAI_justification_aggressiveness = 2 }

				EAI_refresh_gui = yes
			}
			EAI_config_GENERAL_8d_click = {
				
				ROOT = { clr_country_flag = EAI_show_justification_aggressiveness_dropdown }
				
				set_variable = { global.EAI_justification_aggressiveness = 3 }

				EAI_refresh_gui = yes
			}
		}
	}

	# sino-japanese war
	EAI_config_GENERAL_13 = {
		context_type = player_context

		window_name = "EAI_config_GENERAL_13_window"

		parent_window_name = "EAI_config_GENERAL_window"

		dirty = ROOT.EAI_refresh_gui

		visible = { has_country_flag = EAI_show_sino_japanese_war_dropdown }

		effects = {

			EAI_config_GENERAL_13a_click = {
				
				ROOT = { clr_country_flag = EAI_show_sino_japanese_war_dropdown }
				
				clear_variable = global.EAI_sino_japanese_war

				EAI_refresh_gui = yes
			}
			EAI_config_GENERAL_13b_click = {
				
				ROOT = { clr_country_flag = EAI_show_sino_japanese_war_dropdown }
				
				set_variable = { global.EAI_sino_japanese_war = 1 }

				EAI_refresh_gui = yes
			}
			EAI_config_GENERAL_13c_click = {
				
				ROOT = { clr_country_flag = EAI_show_sino_japanese_war_dropdown }
				
				set_variable = { global.EAI_sino_japanese_war = 2 }

				EAI_refresh_gui = yes
			}
		}
	}

	# eastern front
	EAI_config_GENERAL_14 = {
		context_type = player_context

		window_name = "EAI_config_GENERAL_14_window"

		parent_window_name = "EAI_config_GENERAL_window"

		dirty = ROOT.EAI_refresh_gui

		visible = { has_country_flag = EAI_show_eastern_front_dropdown }

		effects = {

			EAI_config_GENERAL_14a_click = {
				
				ROOT = { clr_country_flag = EAI_show_eastern_front_dropdown }
				
				clear_variable = global.EAI_eastern_front

				EAI_refresh_gui = yes
			}
			EAI_config_GENERAL_14b_click = {
				
				ROOT = { clr_country_flag = EAI_show_eastern_front_dropdown }
				
				set_variable = { global.EAI_eastern_front = 1 }

				EAI_refresh_gui = yes
			}
			EAI_config_GENERAL_14c_click = {
				
				ROOT = { clr_country_flag = EAI_show_eastern_front_dropdown }
				
				set_variable = { global.EAI_eastern_front = 2 }

				EAI_refresh_gui = yes
			}
		}
	}
}