:: Basenationalities Controls [nobr]

<<if $nationalities.length < 1>>
	//You cannot be a slave owner without a slave trade. Please add nationalities to continue.//
<<else>>
	<<link "Confirm customization">>
		<<unset $baseControlsFilter>>
		<<if $customWA == 0>>
			<<goto "Intro Summary">>
		<<else>>
			<<goto "Extreme Intro">>
		<</if>>
	<</link>>
<</if>>
<br>

/* Generates cloned array of $nationalities, removing duplicates and then sorting */
<<set $nationalitiescheck = _.uniq($nationalities, false).sort()>>

/* Prints distribution of $nationalities, using $nationalitiescheck to render array */
<<set _percentPerPoint = 100.0 / $nationalities.length>>
<<for _i = 0; _i < $nationalitiescheck.length; _i++>>
	<<set _nation = $nationalitiescheck[_i]>>
	_nation @@.orange;<<= ($nationalities.count(_nation) * _percentPerPoint).toFixed(2)>>%@@
	<<if _i < $nationalitiescheck.length-1>> | <</if>>
<</for>>
<<unset _percentPerPoint>>
<br><br>

/* Fine control tweaking of populations */
Adjust slave populations:
<br style="clear:both" /><hr style="margin:0">

/* Filter controls */
Filter by Race: 
<<for _i = 0; _i < setup.filterRaces.length; _i++>>	
	<<set _race = setup.filterRaces[_i]>>
	<<if $baseControlsFilter == _race.toLowerCase().replace(/[ -]/g, '')>>
		<<print _race>>
	<<else>>
		<<print "
			<<link _race>>
				<<set $baseControlsFilter to setup.filterRaces[" + _i + "].toLowerCase().replace(/[ -]/g, '')>>
				<<replace '#PopControl'>><<include 'Basenationalities Controls'>><</replace>>
			<</link>>
		">>
	<</if>>
	<<if _i < setup.filterRaces.length-1>>
	|
	<</if>>
<</for>>
<br>
Filter by Region:
<<for _i = 0; _i < setup.filterRegions.length; _i++>>	
	<<set _region = setup.filterRegions[_i]>>
	<<if $baseControlsFilter == _region.toLowerCase().replace(/[ -]/g, '')>>
		<<print _region>>
	<<else>>
		<<print "
			<<link _region>>
				<<set $baseControlsFilter to setup.filterRegions[" + _i + "].toLowerCase().replace(/[ -]/g, '')>>
				<<replace '#PopControl'>><<include 'Basenationalities Controls'>><</replace>>
			<</link>>
		">>
	<</if>>
	<<if _i < setup.filterRegions.length-1>>
	|
	<</if>>
<</for>>
<br style="clear:both" /><hr style="margin:0">

<div style="white-space: nowrap">
/* Unfiltered pop controls */
<<if $baseControlsFilter == "all">>
	<<for _i = 0; _i < setup.baseNationalities.length; _i++>>
		<div style="float: left;">
		<<set _nation = setup.baseNationalities[_i]>>
		<<print "
		_nation 
			@@.plusButton;<<link '+'>>
				<<set $nationalities.push(setup.baseNationalities[" + _i + "])>>
				<<replace '#PopControl'>><<include 'Basenationalities Controls'>><</replace>>
			<</link>>@@
		">>
	<<if $nationalitiescheck.includes(_nation) > 0 >>
		<<print "
			@@.minusButton;<<link '–'>>
				<<set $nationalities.deleteAt(($nationalities.indexOf(setup.baseNationalities[" + _i + "])))>>
				<<replace '#PopControl'>><<include 'Basenationalities Controls'>><</replace>>
			<</link>>@@
		">>
		<</if>>
	<<if $nationalities.count(_nation) > 1 >>
		<<print "
			@@.zeroButton;<<link '0'>>
				<<set $nationalities.delete(setup.baseNationalities[" + _i + "])>>
				<<replace '#PopControl'>><<include 'Basenationalities Controls'>><</replace>>
			<</link>>@@
		">>
	<</if>>
	<<if _i < setup.baseNationalities.length-1>>|&nbsp;<</if>>
	</div>
	<</for>>
	<div style="clear: both;">By dominant race/ethnicity (hover over the name to see the nationalities affected):</div>
	<<foreach _race of setup.filterRaces>>
		<<set _racialNationalities = setup.baseNationalities.filter(function(n) {
			var races = setup.raceSelector[n] || setup.raceSelector[''];
			return races.count(_race.toLowerCase()) * 2 > races.length; })>>
		<<if _racialNationalities.length > 0>>
			<<= "<div style='float: left; width: 13em; padding: 0 5px;' title='"
				+ (_racialNationalities.length > 0 ? _racialNationalities.join(", ") : "(none)") 
				+"'>_race @@.plusButton; <<link '+'>>
				<<run Array.prototype.push.apply($nationalities, setup.baseNationalities.filter(function(n) {
						var races = setup.raceSelector[n] || setup.raceSelector[''];
						return races.count('" + _race.toLowerCase() + "') * 2 > races.length; }))>>
				<<replace '#PopControl'>><<include 'Basenationalities Controls'>><</replace>>
			<</link>>@@ @@.zeroButton;<<link '0'>>
				<<run Array.prototype.delete.apply($nationalities, setup.baseNationalities.filter(function(n) {
						var races = setup.raceSelector[n] || setup.raceSelector[''];
						return races.count('" + _race.toLowerCase() + "') * 2 > races.length; }))>>
				<<replace '#PopControl'>><<include 'Basenationalities Controls'>><</replace>>
			<</link>>@@</div>">>
		<</if>>
	<</foreach>>
<<else>>
/* Filtered pop controls */
	<<set _controlsNationality = setup[$baseControlsFilter+'Nationalities']>>
	<<for _i = 0; _i < _controlsNationality.length; _i++>>
		<div style="float: left;">
		<<set _nation = _controlsNationality[_i]>>
		<<print "
		_nation 
			@@.plusButton;<<link '+'>>
				<<set $nationalities.push(_controlsNationality[" + _i + "])>>
				<<replace '#PopControl'>><<include 'Basenationalities Controls'>><</replace>>
			<</link>>@@
		">>
	<<if $nationalitiescheck.includes(_nation) > 0 >>
		<<print "
			@@.minusButton;<<link '–'>>
				<<set $nationalities.deleteAt(($nationalities.indexOf(_controlsNationality[" + _i + "])))>>
				<<replace '#PopControl'>><<include 'Basenationalities Controls'>><</replace>>
			<</link>>@@
		">>
		<</if>>
	<<if $nationalities.count(_nation) > 1 >>
		<<print "
			@@.zeroButton;<<link '0'>>
				<<set $nationalities.delete(_controlsNationality[" + _i + "])>>
				<<replace '#PopControl'>><<include 'Basenationalities Controls'>><</replace>>
			<</link>>@@
		">>
	<</if>>
	<<if _i < _controlsNationality.length-1>>|&nbsp;<</if>>
	</div>
	<</for>>
<</if>>
<div style="clear: both; height: 0;"></div>
</div>