local power, maxPower

WhatsNext:AddConditionalStatement("Minimum Power Percent",{
	category = "Power",
	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,
	text = function(checkTable) 
		power = tonumber(checkTable.amount)
		return GetUnitDisplayText(checkTable.unit) .. "'s power is at or above " .. tostring(power and power*100 or checkTable.amount) .. "%."
	end,
	arguments = {
		unit = {label = "Unit", type = "dropdown", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {label = "Power", type = "percent", default = .5}
	}
})

WhatsNext:AddConditionalStatement("Maximum Power Percent",{
	category = "Power",
	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,
	text = function(checkTable) 
		power = tonumber(checkTable.amount)
		return GetUnitDisplayText(checkTable.unit) .. "'s power is at or below " .. tostring(power and power*100 or checkTable.amount) .. "%."
	end,
	arguments = {
		unit = {label = "Unit", type = "dropdown", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {label = "Power", type = "percent", default = .5}
	}
})

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

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

WhatsNext:AddConditionalStatement("Minimum Missing Power",{
	category = "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,
	text = function(checkTable) 
		return GetUnitDisplayText(checkTable.unit) .. "'s power is at least " .. tostring(checkTable.amount) .. " below their maximum power."
	end,
	arguments = {
		unit = {label = "Unit", type = "dropdown", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {label = "Power", type = "integer", default = 0}
	}
})

WhatsNext:AddConditionalStatement("Maximum Missing Power",{
	category = "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,
	text = function(checkTable) 
		return GetUnitDisplayText(checkTable.unit) .. "'s power is no more than " .. tostring(checkTable.amount) .. " below their maximum power."
	end,
	arguments = {
		unit = {label = "Unit", type = "dropdown", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {label = "Power", type = "integer", default = 0}
	}
})
