scripted_gui = {

	money_open_scripted_gui = {
		context_type = player_context
		window_name = "money_gui_open_window"

		visible = {
			ROOT = {is_ai = no}
		}

		triggers = {
			money_main_background_button_visible = {
				NOT = {
					has_country_flag = money_not_visible
				}
			}
			money_main_money_amount_visible = {
				AND = {
					has_global_flag = wia_money_gflag
				    NOT = {
				    	has_country_flag = money_not_visible
				    }
				}
			}
			money_main_money_civil_visible = {
				AND = {
					NOT = {
					    has_global_flag = wia_money_gflag
				    }
				    NOT = {
				    	has_country_flag = money_not_visible
				    }
				}
			}

			money_main_not_visible_button_visible = {
				NOT = {
					has_country_flag = money_not_visible
				}
			}

			money_main_visible_button_visible = {
				has_country_flag = money_not_visible
			}
		}

		effects = {
			money_main_background_button_click = {
				ROOT = {set_country_flag = money_open}
			}

			money_main_not_visible_button_click = {
				ROOT = {set_country_flag = money_not_visible}
			}
			money_main_visible_button_click = {
				ROOT = {clr_country_flag = money_not_visible}
			}
		}
	}

	money_main_scripted_gui = {
		context_type = player_context
		window_name = "money_gui_main_window"

		visible = {
			AND = {
				ROOT = {is_ai = no}
				ROOT = {has_country_flag = money_open}
			}
		}

		triggers = {
			money_nat_inv_plus_civ_button_click_enabled = {
				ROOT = {NOT = {has_decision = nat_inv_mission}}
				ROOT = {
					check_variable = {nat_inv_civ_count_var < 25}
				}
			}
			money_nat_inv_plus_civ_button_visible = {
				has_global_flag = wia_money_gflag
			}

			money_nat_inv_minus_civ_button_click_enabled = {
				ROOT = {NOT = {has_decision = nat_inv_mission}}
				ROOT = {
					check_variable = {nat_inv_civ_count_var > 5}
				}
			}
			money_nat_inv_minus_civ_button_visible = {
				has_global_flag = wia_money_gflag
			}

			money_nat_inv_invest_button_click_enabled = {
				ROOT = {NOT = {has_decision = nat_inv_mission}}
				NOT = {
					ROOT = {
						check_variable = {nat_inv_civ_count_var = 0}
					}
				}
				if = {
			    	limit = {check_variable = {nat_inv_civ_count_var = 5}}
    
			    	num_of_civilian_factories_available_for_projects > 5
    
			    	else_if = {
			    		limit = {check_variable = {nat_inv_civ_count_var = 10}}
    
			    		num_of_civilian_factories_available_for_projects > 10
    
			    		else_if = {
			    			limit = {check_variable = {nat_inv_civ_count_var = 15}}
    
			    			num_of_civilian_factories_available_for_projects > 15
    
			    			else_if = {
								limit = {check_variable = {nat_inv_civ_count_var = 20}}

								num_of_civilian_factories_available_for_projects > 20

								else_if = {
									limit = {check_variable = {nat_inv_civ_count_var = 25}}

									num_of_civilian_factories_available_for_projects > 25
								}
							}
			    		}
			    	}
			    }
			}
			money_nat_inv_invest_button_visible = {
				has_global_flag = wia_money_gflag
			}

			money_nat_inv_civ_count_bg_visible = {
				has_global_flag = wia_money_gflag
			}

			money_nat_inv_name_title_visible = {
				has_global_flag = wia_money_gflag
			}
		}

		effects = {	
			money_close_button_click = {
				ROOT = {clr_country_flag = money_open}
			}

			money_nat_inv_plus_civ_button_click = {
				ROOT = {
					add_to_variable = {
						var = nat_inv_civ_count_var
						value = 5
					}
				}
			}

			money_nat_inv_minus_civ_button_click = {
				ROOT = {
					subtract_from_variable = {
						var = nat_inv_civ_count_var
						value = 5
					}
				}
			}

			money_nat_inv_invest_button_click = {
				ROOT = {
					activate_decision = nat_inv_mission
					add_dynamic_modifier = {
						modifier = money_nat_inv_dynamic_mod
						days = 60
					}
				}
			}
		}
	}

	money_send_money_scripted_gui = {
		context_type = selected_country_context
		window_name = "money_gui_send_money_window"
		parent_window_name = money_gui_main_window

		visible = {
			always = yes
		}

		triggers = {
			money_send_money_invest1_button_click_enabled = {
				NOT = {original_tag = ROOT}
				ROOT = {NOT = {has_war_with = PREV}}
				ROOT = {industrial_complex > 1}
				FROM = {
					NOT = {
						OR = {
							check_variable = {
								factory_limit_rank_var = factory_limit_var
							}
							check_variable = {
								factory_limit_rank_var < factory_limit_var
							}
						}
					}
				}
			}

			money_send_money_invest2_button_click_enabled = {
				NOT = {original_tag = ROOT}
				ROOT = {NOT = {has_war_with = PREV}}
				ROOT = {industrial_complex > 2}
				FROM = {
					NOT = {
						OR = {
							check_variable = {
								factory_limit_rank_var = factory_limit_var
							}
							check_variable = {
								factory_limit_rank_var < factory_limit_var
							}
						}
					}
				}
			}

			money_send_money_invest3_button_click_enabled = {
				NOT = {original_tag = ROOT}
				ROOT = {NOT = {has_war_with = PREV}}
				ROOT = {industrial_complex > 3}
				FROM = {
					NOT = {
						OR = {
							check_variable = {
								factory_limit_rank_var = factory_limit_var
							}
							check_variable = {
								factory_limit_rank_var < factory_limit_var
							}
						}
					}
				}
			}
		}

		effects = {
			money_send_money_invest1_button_click = {
				ROOT = {
					set_country_flag = {
						flag = money_investing_flag
						days = 1
						value = 1
					}

					random_owned_controlled_state = {
						limit = {
							industrial_complex > 0
						}
						remove_building = {
							type = industrial_complex
							level = 1
						}
					}
				}

				if = {
					limit = {
						has_global_flag = wia_money_gflag
					}
				    FROM = {
				    	add_to_variable = {
				    		var = money_var
				    		value = 1
				    	}
				    	add_to_variable = {
				    		var = factory_limit_var
				    		value = 1
				    	}
				    	country_event = money.1
				    }

					else = {
						FROM = {
							country_event = money.1
							random_owned_controlled_state = {
					        	limit = {
					        		industrial_complex > 0
					        	}
					        	add_building_construction = {
					        		type = industrial_complex
					        		level = 1
									instant_build = yes
					        	}
					        }
							add_to_variable = {
								var = factory_limit_var
								value = 1
							}
						}
					}
				}
			}

			money_send_money_invest2_button_click = {
				ROOT = {
					set_country_flag = {
						flag = money_investing_flag
						days = 1
						value = 1
					}

					random_owned_controlled_state = {
						limit = {
							industrial_complex > 0
						}
						remove_building = {
							type = industrial_complex
							level = 1
						}
					}
					random_owned_controlled_state = {
						limit = {
							industrial_complex > 0
						}
						remove_building = {
							type = industrial_complex
							level = 1
						}
					}
				}

				if = {
					limit = {
						has_global_flag = wia_money_gflag
					}
				    FROM = {
				    	add_to_variable = {
				    		var = money_var
				    		value = 2
				    	}
				    	add_to_variable = {
				    		var = factory_limit_var
				    		value = 2
				    	}
				    	country_event = money.1
				    }

					else = {
						FROM = {
							country_event = money.1
							random_owned_controlled_state = {
					        	limit = {
					        		industrial_complex > 1	
					        	}
					        	add_building_construction = {
					        		type = industrial_complex
					        		level = 2
									instant_build = yes
					        	}
					        }
							add_to_variable = {
								var = factory_limit_var
								value = 2
							}
						}
					}
				}
			}

			money_send_money_invest3_button_click = {
				ROOT = {
					set_country_flag = {
						flag = money_investing_flag
						days = 1
						value = 1
					}

					random_owned_controlled_state = {
						limit = {
							industrial_complex > 0
						}
						remove_building = {
							type = industrial_complex
							level = 1
						}
					}
					random_owned_controlled_state = {
						limit = {
							industrial_complex > 0
						}
						remove_building = {
							type = industrial_complex
							level = 1
						}
					}
					random_owned_controlled_state = {
						limit = {
							industrial_complex > 0
						}
						remove_building = {
							type = industrial_complex
							level = 1
						}
					}
				}

				if = {
					limit = {
						has_global_flag = wia_money_gflag
					}
				    FROM = {
				    	add_to_variable = {
				    		var = money_var
				    		value = 3
				    	}
				    	add_to_variable = {
				    		var = factory_limit_var
				    		value = 3
				    	}
				    	country_event = money.1
				    }

					else = {
						FROM = {
							country_event = money.1
							random_owned_controlled_state = {
					        	limit = {
					        		industrial_complex > 2
					        	}
					        	add_building_construction = {
					        		type = industrial_complex
					        		level = 3
									instant_build = yes
					        	}
					        }
							add_to_variable = {
								var = factory_limit_var
								value = 3
							}
						}
					}
				}
			}
		}
	}

	money_debt_scripted_gui = {
		context_type = player_context
		window_name = "money_gui_debt_window"
		parent_window_name = money_gui_main_window

		visible = {
			always = yes
		}

		triggers = {
		}

		effects = {
		}
	}

	money_limit_scripted_gui = {
		context_type = selected_country_context
		window_name = "money_gui_limit_window"
		parent_window_name = countrydiplomacyview

		visible = {
			NOT = { tag = ROOT }
		}

		triggers = {
		}

		effects = {
		}
	}
}
