namespace BP
{
	namespace Array
	{
		//------------------------------------------------------------------------------------------------------------------------
		// Gets a random element from availIndexs and uses the index to return that index element from aryLookup.
		// Removes the element from availIndexs. If availIndexs length is 0 then it's gets populated with all the indexs of aryLookup
		//------------------------------------------------------------------------------------------------------------------------
		kStr GetUniqueElement(array<kStr>& aryLookup, array<int>& availIndexs)
		{
			if (availIndexs.length() == 0)
			{
				int lookupLength = int(aryLookup.length());
				for (int i = 0; i < lookupLength; i++)
				{
					availIndexs.insertLast(i);
				}					
			}
			int index = BP::Array::RandomIndex(availIndexs);
			int lookupIndex = availIndexs[index];
			availIndexs.removeAt(index);
			return aryLookup[lookupIndex];
		}
		//------------------------------------------------------------------------------------------------------------------------
		// Returns a int number to an array of ints that contain the single digit value by index
		//------------------------------------------------------------------------------------------------------------------------
		array<int> NumberToArray(int num)
		{
			if (num == 0)
			{
				array<int> result = {0};
				return result;
			}
			
			num = Math::Abs(num);
			array<int> nums;
			while (num > 0)
			{
				nums.insertLast(num % 10);
				num /= 10;
			}
			nums.reverse();
			return nums;
		}
		//------------------------------------------------------------------------------------------------------------------------
		bool IndexInRange(uint arrayLength, int index)
		{
			return index >= 0 && index < int(arrayLength);
		}
		//------------------------------------------------------------------------------------------------------------------------
		int RandomIndex(array<int> ary)
		{
			return Math::RandMax(ary.length());
		}
		//------------------------------------------------------------------------------------------------------------------------
		int RandomElement(array<int> ary)
		{
			return ary[Math::RandMax(ary.length())];
		}
		//------------------------------------------------------------------------------------------------------------------------
		kVec3 RandomElement(array<kVec3> ary)
		{
			return ary[Math::RandMax(ary.length())];
		}
		//------------------------------------------------------------------------------------------------------------------------
		kStr RandomElement(array<kStr> ary)
		{
			return ary[Math::RandMax(ary.length())];
		}
		//------------------------------------------------------------------------------------------------------------------------
		// Returns the index of the final weight selection
		//------------------------------------------------------------------------------------------------------------------------
		int Weights(array<int> chances)
		{
			int totalChance = 0;
			for (uint i = 0; i < chances.length(); i++)
			{
				totalChance += chances[i];
			}

			int top = 0;
			int rand = Math::RandMax(totalChance);
			for (uint i = 0; i < chances.length(); i++)
			{
				top += chances[i];
				if (rand < top)
				{
					return i;
				}
			}
			
			return 0;
		}
		//------------------------------------------------------------------------------------------------------------------------
		void Clear(array<kStr> &inout ary, int index, int count)
		{
			for (int i = index; i < count; i++)
			{
				ary[i] = "";
			}
		}
		//------------------------------------------------------------------------------------------------------------------------
		void Clear(array<int> &inout ary, int index, int count)
		{
			for (int i = index; i < count; i++)
			{
				ary[i] = 0;
			}
		}
		//------------------------------------------------------------------------------------------------------------------------
		void Clear(array<array<kActor@>> &inout ary, int index, int count)
		{
			for (int i = index; i < count; i++)
			{
				ary[i].resize(0);
			}
		}
		//------------------------------------------------------------------------------------------------------------------------
		void Copy(array<int> &inout srcAry, array<int> &inout destAry, int count)
		{
			for (int i = 0; i < count; i++)
			{
				destAry[i] = srcAry[i];
			}
		}
		//------------------------------------------------------------------------------------------------------------------------
		void Copy(array<kStr> &inout srcAry, array<kStr> &inout destAry, int count)
		{
			for (int i = 0; i < count; i++)
			{
				destAry[i] = srcAry[i];
			}
		}
		//------------------------------------------------------------------------------------------------------------------------
		void Copy(array<array<kActor@>> &inout srcAry, array<array<kActor@>> &inout destAry, int count)
		{
			for (int i = 0; i < count; i++)
			{
				destAry[i] = srcAry[i];
			}
		}
		//------------------------------------------------------------------------------------------------------------------------
	}
}
