﻿lwxxx_close_window_sgui = {
	scope = character

	effect = {
		root = {
			lwxxx_window_close_effect = yes
		}
	}
}

lwxxx_toggle_title_button_sgui = {
	scope = character

	saved_scopes = {
		lwxxx_title_key
	}

	is_shown = {
		exists = scope:lwxxx_title_key
		is_target_in_variable_list = { name = lwxxx_list_variable_selected_titles target = scope:lwxxx_title_key }
	}

	effect = {
		root = {
			lwxxx_selected_title_toggle_effect = { TARGET = scope:lwxxx_title_key }
		}
	}
}

lwxxx_toggle_title_abdication_button_sgui = {
	scope = character

	saved_scopes = {
		lwxxx_title_key
	}

	effect = {
		scope:lwxxx_title_key = {
			if = {
				limit = {
					has_variable = lwxxx_title_abdicator
				}

				if = {
					limit = {
						tier = tier_county
						not = {
							root = {
								any_held_title = {
									tier = tier_county
									not = { this = scope:lwxxx_title_key }
									var:lwxxx_title_abdicator ?= root
								}
							}
						}
					}

					root = {
						every_held_title = {
							limit = {
								tier > tier_county
								var:lwxxx_title_abdicator ?= root
							}

							remove_variable = lwxxx_title_abdicator
							root = {
								if = {
									limit = { has_variable_list = lwxxx_abdicate_titles_list }

									remove_list_variable = { name = lwxxx_abdicate_titles_list target = scope:lwxxx_title_key }
								}
							}
						}
					}
				}

				remove_variable = lwxxx_title_abdicator
				root = {
					if = {
						limit = { has_variable_list = lwxxx_abdicate_titles_list }

						remove_list_variable = { name = lwxxx_abdicate_titles_list target = scope:lwxxx_title_key }
					}

					if = {
						limit = {
							or = {
								not = { has_variable_list = lwxxx_abdicate_titles_list }
								variable_list_size = { name = lwxxx_abdicate_titles_list value < 1 }
							}
						}

						remove_list_variable = { name = lwxxx_abdicate_ruler_list target = this }
					}
				}
			}
			else_if = {
				limit = {
					or = {
						tier = tier_county
						root = {
							any_held_title = {
								tier = tier_county
								var:lwxxx_title_abdicator ?= root
							}
						}
					}
				}

				set_variable = { name = lwxxx_title_abdicator value = root }
				root = {
					add_to_variable_list = { name = lwxxx_abdicate_titles_list target = scope:lwxxx_title_key }

					if = {
						limit = { not = { is_target_in_variable_list = { name = lwxxx_abdicate_ruler_list target = this } } }
				
						add_to_variable_list = { name = lwxxx_abdicate_ruler_list target = this }
					}
				}
			}
		}
	}
}

lwxxx_toggle_title_claim_button_sgui = {
	scope = character

	saved_scopes = {
		lwxxx_holder
		lwxxx_title_key
	}

	effect = {
		root = {
			if = {
				limit = { has_weak_claim_on = scope:lwxxx_title_key }

				if = {
					limit = {
						scope:lwxxx_title_key = { tier = tier_county }
						nor = {
							is_landed = yes
							lwxxx_elected_to_other_county_trigger = { TITLE = scope:lwxxx_title_key HOLDER = scope:lwxxx_holder }
						}
					}

					lwxxx_remove_other_claims_effect = { TITLE = scope:lwxxx_title_key HOLDER = scope:lwxxx_holder }
				}

				remove_claim = scope:lwxxx_title_key
				scope:lwxxx_title_key = { lwxxx_remove_last_will_claimant_effect = yes }
			}
			else_if = {
				limit = {
					or = {
						scope:lwxxx_title_key = { tier = tier_county }
						is_landed = yes
						lwxxx_elected_to_any_county_trigger = { HOLDER = scope:lwxxx_holder }
					}
				}

				add_unpressed_claim = scope:lwxxx_title_key
				scope:lwxxx_title_key = { set_variable = { name = lwxxx_last_will_claimant value = root } }
			}
		}
	}
}

lwxxx_has_pressed_claim_sgui = {
	scope = character

	saved_scopes = {
		lwxxx_title_key
	}

	is_shown = {
		exists = scope:lwxxx_title_key
		root = {
			has_strong_claim_on = scope:lwxxx_title_key
		}
	}
}

lwxxx_has_unpressed_claim_sgui = {
	scope = character

	saved_scopes = {
		lwxxx_title_key
	}

	is_shown = {
		exists = scope:lwxxx_title_key
		root = {
			has_weak_claim_on = scope:lwxxx_title_key
		}
	}
}

lwxxx_has_implicit_claim_sgui = {
	scope = character

	saved_scopes = {
		lwxxx_title_key
	}

	is_shown = {
		exists = scope:lwxxx_title_key
		root = {
			has_claim_on = scope:lwxxx_title_key
			nor = {
				has_strong_claim_on = scope:lwxxx_title_key
				has_weak_claim_on = scope:lwxxx_title_key
			}
		}
	}
}

lwxxx_has_abdication_titles_sgui = {
	scope = character

	is_shown = {
		root = {
			has_variable_list = lwxxx_abdicate_titles_list
			variable_list_size = { name = lwxxx_abdicate_titles_list value > 0 }
		}
	}
}

lwxxx_titles_lost_sgui = {
	scope = character

	saved_scopes  = {
		lwxxx_titles_lost
	}

	effect = {
		root = {
			custom_tooltip = "lwxxx_titles_lost_total_tt"
		}
	}
}

lwxxx_titles_lost_to_succession_sgui = {
	scope = character

	saved_scopes  = {
		lwxxx_titles_lost
	}

	effect = {
		root = {
			custom_tooltip = "lwxxx_titles_lost_to_succession_tt"
		}
	}
}

lwxxx_titles_lost_to_abdication_sgui = {
	scope = character

	effect = {
		root = {
			custom_tooltip = "lwxxx_titles_lost_to_abdication_tt"
		}
	}
}
