local power, maxPower

WhatsNext:AddConditionalStatement("Minimum Power Percent",{
	category = "Power",
	text = "{unit}'s power is at or above {amount}.",
	test = function(checkTable) 
		power = UnitPower(tostring(checkTable.unit))
		maxPower = UnitPowerMax(tostring(checkTable.unit))
		return power and maxPower and maxPower > 0 and tonumber(checkTable.amount) <= power / maxPower
	end,
	arguments = {
		unit = {label = "Unit", type = "unit", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {label = "Power Percent", type = "percent", default = .5}
	}
})

WhatsNext:AddConditionalStatement("Maximum Power Percent",{
	category = "Power",
	text = "{unit}'s power is at or below {amount}.",
	test = function(checkTable) 
		power = UnitPower(tostring(checkTable.unit))
		maxPower = UnitPowerMax(tostring(checkTable.unit))
		return power and maxPower and maxPower > 0 and tonumber(checkTable.amount) >= power / maxPower
	end,
	arguments = {
		unit = {label = "Unit", type = "unit", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {label = "Power Percent", type = "percent", default = .5}
	}
})

WhatsNext:AddConditionalStatement("Minimum Power",{
	category = "Power",
	text = "{unit}'s power is at or above {amount}.",
	test = function(checkTable) 
		power = UnitPower(tostring(checkTable.unit))
		return power and power >= 0 and tonumber(checkTable.amount) <= power
	end,
	arguments = {
		unit = {label = "Unit", type = "unit", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {label = "Power", type = "integer", default = 0, min = 1, max = 10000000}
	}
})

WhatsNext:AddConditionalStatement("Maximum Power",{
	category = "Power",
	text = "{unit}'s power is at or below {amount}.",
	test = function(checkTable) 
		power = UnitPower(tostring(checkTable.unit))
		return power and power > 0 and tonumber(checkTable.amount) >= power
	end,
	arguments = {
		unit = {label = "Unit", type = "unit", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {label = "Power", type = "integer", default = 0, min = 1, max = 10000000}
	}
})

WhatsNext:AddConditionalStatement("Minimum Missing Power",{
	category = "Power",
	text = "{unit}'s power is at least {amount} below their maximum power.",
	test = function(checkTable) 
		power = UnitPower(tostring(checkTable.unit))
		maxPower = UnitPowerMax(tostring(checkTable.unit))
		return power and maxPower and maxPower - power >= tonumber(checkTable.amount)
	end,
	arguments = {
		unit = {label = "Unit", type = "unit", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {label = "Power", type = "integer", default = 0}
	}
})

WhatsNext:AddConditionalStatement("Maximum Missing Power",{
	category = "Power",
	text = "{unit}'s power is no more than {amount} below their maximum power.",
	test = function(checkTable) 
		power = UnitPower(tostring(checkTable.unit))
		maxPower = UnitPowerMax(tostring(checkTable.unit))
		return power and maxPower and maxPower - power <= tonumber(checkTable.amount)
	end,
	arguments = {
		unit = {label = "Unit", type = "unit", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {label = "Power", type = "integer", default = 0}
	}
})
WhatsNext:AddConditionalStatement("Minimum Maelstrom",{
	category="SHAMAN",
	text = "player has at least {amount} Astral Power.",
	test = function(checkTable)
		return UnitPower("player",11) >= tonumber(checkTable.amount) 
	end,
	arguments = {
		amount = {label = "Maelstrom", type = "integer", default = 50, min = 0, max = 150},
	}
})