scripted_gui = {
	
	pd_offer_peace_deal = {
	
		context_type = diplomatic_action
		
		window_name = "pd_offer_peace_deal"
		
		visible = {
			always = yes
		}
		
		dynamic_lists = {
			pd_state_grid = {
				array = ROOT.pd_state_list
				change_scope = yes
				entry_container = "[pd_offer_peace_deal_loc]" 
			}
		}
		
		effects = {
		
			# Tab selection
			
			pd_tab_take_click = {
				ROOT = { clr_country_flag = pd_root_gives }
				reset_peace_deal_proposal = yes
			}
			
			pd_tab_give_click = {
				ROOT = { set_country_flag = pd_root_gives }
				reset_peace_deal_proposal = yes
			}
		
			# State marking mode
		
			take_click = {
				set_variable = { ROOT.pd_selected = 1 }
			}
		
			puppet_click = {
				set_variable = { ROOT.pd_selected = 2 }
			}
			
			demilitarize_click = {
				set_variable = { ROOT.pd_selected = 3 }
			}
			
			liberate_click = {
				set_variable = { ROOT.pd_selected = 4 }
			}
			
			# War reparations
			
			war_reparations_click = {
				ROOT = { set_country_flag = pd_war_reparations }
				if = {
					limit = { ROOT = { has_country_flag = pd_root_gives } }
					subtract_from_variable = { ROOT.pd_total_cost = ROOT.pd_wr_cost }
				}
				else = {
					add_to_variable = { ROOT.pd_total_cost = ROOT.pd_wr_cost }
				} 
			}
			
			war_reparations_set_click = {
				ROOT = { clr_country_flag = pd_war_reparations }
				if = {
					limit = { ROOT = { has_country_flag = pd_root_gives } }
					add_to_variable = { ROOT.pd_total_cost = ROOT.pd_wr_cost }
				}
				else = {
					subtract_from_variable = { ROOT.pd_total_cost = ROOT.pd_wr_cost }
				} 
			}
			
			# Disarm
			
			disarm_click = {
				ROOT = { set_country_flag = pd_disarm }
				if = {
					limit = { ROOT = { has_country_flag = pd_root_gives } }
					subtract_from_variable = { ROOT.pd_total_cost = ROOT.pd_disarm_cost }
				}
				else = {
					add_to_variable = { ROOT.pd_total_cost = ROOT.pd_disarm_cost }
				} 
			}
			
			disarm_set_click = {
				ROOT = { clr_country_flag = pd_disarm }
				if = {
					limit = { ROOT = { has_country_flag = pd_root_gives } }
					add_to_variable = { ROOT.pd_total_cost = ROOT.pd_disarm_cost }
				}
				else = {
					subtract_from_variable = { ROOT.pd_total_cost = ROOT.pd_disarm_cost }
				} 
			}
			
			# Marking states
			
			pd_mark_click = {
				add_state_to_list = yes
			}
			
			pd_unmark_click = {
				remove_state_from_list = yes
			}
			
			pd_mark_give_click = {
				add_state_to_list = yes
			}
			
			pd_unmark_give_click = {
				remove_state_from_list = yes
			}
		}
		
		triggers = {
		
			# Tab selection
		
			pd_take_state_grid_visible = {
				NOT = { ROOT = { has_country_flag = pd_root_gives } }
			}
			
			pd_tab_take_active_visible = {
				NOT = { ROOT = { has_country_flag = pd_root_gives } }
			}
			
			pd_give_state_grid_visible = {
				ROOT = { has_country_flag = pd_root_gives }
			}
			
			pd_tab_give_active_visible = {
				ROOT = { has_country_flag = pd_root_gives }
			}
			
			pd_mark_give_visible = {
				ROOT = { has_country_flag = pd_root_gives }
			}
			
			pd_unmark_give_visible = {
				ROOT = { has_country_flag = pd_root_gives }
			}
			
			# Waitng response disable
			
			pd_tab_give_click_enabled = {
				ROOT = {
					NOT = { has_country_flag = pd_waiting_response }
				}
			}
		
			pd_mark_click_enabled = {
				ROOT = {
					NOT = { has_country_flag = pd_waiting_response }
				}
			}
			
			pd_unmark_click_enabled = {
				ROOT = {
					NOT = { has_country_flag = pd_waiting_response }
				}
			}
			
			# State marking mode
		
			take_selected_visible = {
				check_variable = { ROOT.pd_selected = 1 }
			}
			
			puppet_selected_visible = {
				check_variable = { ROOT.pd_selected = 2 }
			}
			
			demilitarize_selected_visible = {
				check_variable = { ROOT.pd_selected = 3 }
			}
			
			liberate_selected_visible = {
				check_variable = { ROOT.pd_selected = 4 }
			}
			
			war_reparations_set_visible = {
				ROOT = { has_country_flag = pd_war_reparations }
			}
			
			# War reparations
			
			war_reparations_click_enabled = {
				check_variable = { wr_payments < 2 }
				ROOT = {
					NOT = { has_country_flag = pd_waiting_response }
				}
			}
			
			war_reparations_set_click_enabled = {
				ROOT = {
					NOT = { has_country_flag = pd_waiting_response }
				}
			}
			
			# Disarm
			
			disarm_set_visible = {
				ROOT = { has_country_flag = pd_disarm }
			}
			
			disarm_click_enabled = {
				ROOT = {
					NOT = { has_country_flag = pd_waiting_response }
				}
			}
			
			disarm_set_click_enabled = {
				ROOT = {
					NOT = { has_country_flag = pd_waiting_response }
				}
			}
			
			# Acceptance icon
			
			accept_icon_yes_visible = {
				pd_ai_will_accept = yes
			}
			
			accept_icon_no_visible = {
				NOT = { pd_ai_will_accept = yes }
			}
		}
		
		ai_enabled = {
			always = no # Handled in a different way
        }
        
	}
}

