scripted_gui = {
	vp_renaming_container = {
		context_type = player_context
		
		window_name = "vp_renaming_container"
		parent_window_token = topbar

		visible = {
			is_ai = no
		}
		
		ai_enabled = {
			always = no
		}

		triggers = {
			vp_name_button_turn_on_en_visible = {
				NOT = {
					has_global_flag = disable_state_renaming
				}
			}
			vp_name_button_turn_on_en_click_enabled = {
				always = no
			}
			vp_name_button_turn_off_en_click_enabled = {
				always = no
			}
			vp_name_button_turn_off_en_visible = {
				has_global_flag = disable_state_renaming
			}
		}
		
		effects = {
			vp_name_button_turn_on_en_click = {
				set_global_flag = disable_state_renaming
				every_state = {
					limit = {
						r56_is_state_rename_exception = no
					}
					meta_effect = {
						text = {
							set_state_name = STATE_[ID]
						}
						ID = "[THIS.GetID]"
					}
				}
				set_variable = { global.province_id = 0 }
				for_each_scope_loop = {
					array = global.province_controllers
					if = {
						limit = {
							check_variable = { global.province_id > 1 }	#the array contains a province 0 that doesn't exist, while province 1 is a lake that has no state
							NOT = {
								#has_idea = TAH_mangos #doesn't exist
								has_cosmetic_tag = BYZ_UNIFIED
								has_country_flag = GRE_GREATER_GREECE_flag
								has_country_flag = GRE_byz_unified_flag
								AND = {
									original_tag = COG
									OR = {
										has_global_flag = COG_renamed_cities
										has_global_flag = COG_renamed_cities_decoster
									}
								}
								is_in_array = {
									array = global.vp_rename_exceptions
									value = global.province_id
								}
							}
						}
						meta_effect = {
							text = {
								set_province_name = {
									id = [ID]
									name = VICTORY_POINTS_[ID]
								}
							}
							ID = "[?global.province_id]"
						}
					}
					add_to_variable = { global.province_id = 1 }
				}
			}
			vp_name_button_turn_off_en_click = {
				clr_global_flag = disable_state_renaming
				every_state = {
					limit = {
						r56_is_state_rename_exception = no
					}
					reset_state_name = yes
				}
				set_variable = { global.province_id = 0 }
				for_each_scope_loop = {
					array = global.province_controllers
					if = {
						limit = {
							check_variable = { global.province_id > 1 }	#the array contains a province 0 that doesn't exist, while province 1 is a lake that has no state
							NOT = {
								#has_idea = TAH_mangos #doesn't exist
								has_cosmetic_tag = BYZ_UNIFIED
								has_country_flag = GRE_GREATER_GREECE_flag
								has_country_flag = GRE_byz_unified_flag
								AND = {
									original_tag = COG
									OR = {
										has_global_flag = COG_renamed_cities
										has_global_flag = COG_renamed_cities_decoster
									}
								}
								is_in_array = {
									array = global.vp_rename_exceptions
									value = global.province_id
								}
							}
						}
						reset_province_name = global.province_id
					}
					add_to_variable = { global.province_id = 1 }
				}
			}
		}
	}
}
