<?php
	if ($logedin){ 
		$info = api_get("accounts/verify_credentials");
		if($info['error']){
			die();
		}
	}
?>

<?php if ($logedin): ?>
<div class='element'>
	<div class='avatar' style='height:1px;'></div>
	<div class='profile'>
		<form method='post' enctype="multipart/form-data">
		<input type='hidden' name='action' value='account'>
		<?php 
			$profile['mainColor'] = averageColor($info['avatar']);
			$profile['header'] = $info['header_static'];
		?>
		<div id='profileheader' style='width: 100%; height:250px; background-color:#<?php echo $profile['mainColor']; ?>; background-size:cover; background-image:url(<?php echo $profile['header']; ?>); display:inline-block; position:relative;'>
			<span style='width:290; height:30px; display:block; margin-top:15px; margin-right:15px; float:right;'>
			<div class='profileButton cursor' style='width:100%; border-radius:0px; position:relative;'><span class='fontello' style='font-size:inherit;'>&#xe824;</span> Change Cover<input style='position:absolute; left:0px; top:5px; width:150px; opacity:0;' type='file' id='chooseheader' onChange="previewHeader();" accept="image/*" name='header'></div>
			</span>
			<span style='position:absolute; bottom:10px; left:10px;'>
			</span>
		</div>
		<div style='width: 100%; position:relative; text-align:center; padding-bottom:15px;'>
			<div id='profileavatar' class='avatar_header' style='position:relative; background-color:white; background-size: cover; background-image:url(<?php echo $info['avatar']; ?>); text-align:center; float:none; display:inline-block; border:3px solid white; margin-top:-50px; border-radius:5px; width:80px; height:80px;'>
				<span style='position:absolute; bottom:3px; left:3px;'>
					<div class='profileButton' style='width:100%; border-radius:0px; position:relative;'><span class='fontello' style='font-size:inherit;'>&#xe824;</span><input style='position:absolute; left:0px; top:5px; width:30px; opacity:0;' type='file' id='chooseavatar' onChange="previewAvatar();" accept="image/*" name='avatar'></div>
				</span>
			</div>
			<br><span><input style='width:80% !important; font-weight:bold; font-size:30px; text-align:center;' type='text' name='username' value='<?php echo $info['display_name']; ?>'></span>
			<br><span><textarea name='bio' style='width:80%; height:150px; text-align:center;'><?php echo $info['source']['note']; ?></textarea></span>
			<br><span><input style='margin:10px;' type="submit" value="Save Changes" id="send"></span>
			</form>
		</div>
	</div>
</div>
<?php endif; ?>


<div class='element'>
	<div class='avatar' style='height:0px;'></div>
	<div class='post' style='text-align:left;'>
		<div style='padding:15px; width:90%; text-align:left; display:inline-block;' id="settings">
			<h1><span class='fontello' style='font-size:inherit;'>&#xe82e;</span> Settings</h1>
			<form method='post' enctype="multipart/form-data">
			<input type='hidden' name='action' value='settings'>
			<h1 style='font-size:1em;'><span class='fontello' style='font-size:1em;'>&#xe824;</span> Posting</h1>
			<hr>
			<?php if ($logedin): ?>
				<h2>Default post vsibility</h2>
				<div class="setting">
					<select name='defscope' id='scope'>
						<option value="1" <?php echo ($user_settings['defscope'] == '1' ? "selected" : ""); ?>>&#xe83c; Public</option>	
						<option value="2" <?php echo ($user_settings['defscope'] == '2' ? "selected" : ""); ?>>&#xe816; Unlisted</option>
						<option value="3" <?php echo ($user_settings['defscope'] == '3' ? "selected" : ""); ?>>&#xe819; Private</option>
						<option value="4" <?php echo ($user_settings['defscope'] == '4' ? "selected" : ""); ?>>&#xf0e0; Direct</option>
					</select>
				</div>
				<br>
				<h1 style='font-size:1em;'><span class='fontello' style='font-size:1em;'>&#xf0e5;</span> Timeline</h1>
				<hr>
				<h2>Show replies</h2>
				<div class='setting'>
					<select name="replies">
						<option value="on" <?php echo ($user_settings['replies'] == 'on' ? "selected" : ""); ?>>All</option>
						<option value="off" <?php echo ($user_settings['replies'] == 'off' ? "selected" : ""); ?>>Only to people i follow</option>
					</select>
				</div>
			<?php endif; ?>
				<h2>Show text-only posts</h2>
				<div class='setting'>
					<input type='radio' name='text' id='textOn' value='on' style='display:none;' <?php echo ($user_settings['text'] == 'on' ? "checked" : ""); ?>>
					<label for='textOn'>Yes</label>
					<input type='radio' name='text' id='textOff' value='off' style='display:none;' <?php echo ($user_settings['text'] == 'off' ? "checked" : ""); ?>>
					<label for='textOff'>No</label>
				</div>
				<br><br>
				<h2>Show reblogs</h2>
				<div class='setting'>
					<input type='radio' name='reblog' id='reblogOn' value='on' style='display:none;' <?php echo ($user_settings['reblog'] == 'on' ? "checked" : ""); ?>>
					<label for='reblogOn'>Yes</label>
					<input type='radio' name='reblog' id='reblogOff' value='off' style='display:none;' <?php echo ($user_settings['reblog'] == 'off' ? "checked" : ""); ?>>
					<label for='reblogOff'>No</label>
				</div>
				<br><br>
				<h2>Unroll Content Warnings</h2>
				<div class='setting'>
					<input type='radio' name='unrollcw' id='cwshow' value='on' style='display:none;' <?php echo ($user_settings['unrollcw'] == 'on' ? "checked" : ""); ?>>
					<label for='cwshow'>True</label>
					<input type='radio' name='unrollcw' id='cwhide' value='off' style='display:none;' <?php echo ($user_settings['unrollcw'] == 'off' ? "checked" : ""); ?>>
					<label for='cwhide'>False</label>
				</div>
				<br><br>
				<?php if ($logedin): ?>
				<h2>Muted words</h2>
				<span>One per line</span>
				<div class='setting'>
					<textarea name='mtwords' style='width:85%;'><?php
							foreach($user_settings['mtwords'] as $word){
								echo (empty($word) ? "" : trim($word)."\n");
							}
						?></textarea>
				</div>
				<br>
				<h1 style='font-size:1em;'><span class='fontello' style='font-size:1em;'>&#xf0c9;</span> Sidebar</h1>
				<hr>
				<h2>Featured hashtags</h2>
				<span>One per line, without the #</span>
				<div class='setting'>
					<textarea name='fhtags' style='width:85%;'><?php
							foreach($user_settings['fhtags'] as $word){
								echo (empty($word) ? "" : trim($word)."\n");
							}
						?></textarea>
				</div>
				<br>
				<?php endif; ?>
				<h1 style='font-size:1em;'><span class='fontello' style='font-size:1em;'>&#xe81a;</span> Privacy</h1>
				<hr>
				<h2>Embed youtube videos</h2>
				<div class='setting'>
					<input type='radio' name='embyt' id='embYtOn' value='on' style='display:none;' <?php echo ($user_settings['embyt'] == 'on' ? "checked" : ""); ?>>
					<label for='embYtOn'>Yes</label>
					<input type='radio' name='embyt' id='embYtOff' value='off' style='display:none;' <?php echo ($user_settings['embyt'] == 'off' ? "checked" : ""); ?>>
					<label for='embYtOff'>No</label>
				</div>
				
				<br><br>
				<h2>Use Invidious instance</h2>
				<div class='setting''>
					<input type='text' name='invidious' value='<?php echo $user_settings['invidious']; ?>' placeholder='eg. yewtu.be'>(blank to disable)
				</div>
				<h2>Use nitter instance</h2>
				<div class='setting''>
					<input type='text' name='nitter' value='<?php echo $user_settings['nitter']; ?>' placeholder='eg. nitter.net'>(blank to disable)
				</div>
				<h2>Use teddit instance</h2>
				<div class='setting''>
					<input type='text' name='teddit' value='<?php echo $user_settings['teddit']; ?>' placeholder='eg. teddit.net'>(blank to disable)
				</div>
				
			<br><br><br>
			
			<h1><span class='fontello' style='font-size:inherit;'>&#xe818;</span> Attachments</h1>
			<hr>
				<h2>Hide Attachments, show a link instead.</h2>
				<div class='setting'>
					<input type='radio' name='attach' id='a_hide' value='off' style='display:none;' <?php echo ($user_settings['attach'] == 'off' ? "checked" : ""); ?>>
					<label for='a_hide'>Yes</label>
					<input type='radio' name='attach' id='a_show' value='on' style='display:none;' <?php echo ($user_settings['attach'] == 'on' ? "checked" : ""); ?>>
					<label for='a_show'>No</label>
				</div>
				<br><br>
				<h2>Sensitive Media</h2>
				<div class='setting'>
					<input type='radio' name='explicit' id='hide' value='hide' style='display:none;' <?php echo ($user_settings['explicit'] == 'hide' ? "checked" : ""); ?>>
					<label for='hide'>Hide</label>
					<input type='radio' name='explicit' id='blur' value='blur' style='display:none;' <?php echo ($user_settings['explicit'] == 'blur' ? "checked" : ""); ?>>
					<label for='blur'>Blur</label>
					<input type='radio' name='explicit' id='show' value='off' style='display:none;' <?php echo ($user_settings['explicit'] == 'off' ? "checked" : ""); ?>>
					<label for='show'>Show</label>
				</div>
				<br><br>
				<h2>Loop videos</h2>
				<div class='setting'>
					<input type='radio' name='videoloop' id='loopOn' value='on' style='display:none;' <?php echo ($user_settings['videoloop'] == 'on' ? "checked" : ""); ?>>
					<label for='loopOn'>Yes</label>
					<input type='radio' name='videoloop' id='loopOff' value='off' style='display:none;' <?php echo ($user_settings['videoloop'] == 'off' ? "checked" : ""); ?>>
					<label for='loopOff'>No</label>
				</div>
				<br><br>
				<h2>Mute videos</h2>
				<div class='setting'>
					<input type='radio' name='mute' id='muteon' value='on' style='display:none;' <?php echo ($user_settings['mute'] == 'on' ? "checked" : ""); ?>>
					<label for='muteon'>Yes</label>
					<input type='radio' name='mute' id='muteoff' value='off' style='display:none;' <?php echo ($user_settings['mute'] == 'off' ? "checked" : ""); ?>>
					<label for='muteoff'>No</label>
				</div>
			<br><br>
			<br><br>
			<?php if ($logedin): ?>
			<h1><span class='fontello' style='font-size:inherit;'>&#xf0f3;</span> Notifications</h1>
			<hr>
				<div class='setting'>
				<p>Select types of notifications you want to see:</p>
				<input type='checkbox' name='notif[fav]' id='fav' style='display:none;' <?php echo (str_split($user_settings['notif'])[0] == '1' ? "checked" : ""); ?>>
				<label for='fav'>Faves</label>
				<input type='checkbox' name='notif[rt]' id='rt' style='display:none;' <?php echo (str_split($user_settings['notif'])[1] == '1' ? "checked" : ""); ?>>
				<label for='rt'>Reblogs</label>
				<input type='checkbox' name='notif[mnt]' id='mnt' style='display:none;' <?php echo (str_split($user_settings['notif'])[2] == '1' ? "checked" : ""); ?>>
				<label for='mnt'>Mentions</label>
				<input type='checkbox' name='notif[follow]' id='follow' style='display:none;' <?php echo (str_split($user_settings['notif'])[3] == '1' ? "checked" : ""); ?>>
				<label for='follow'>Follow</label>
				</div>
			<br><br>
			<br><br>
			<?php endif; ?>
			<h1><span class='fontello' style='font-size:inherit;'>&#xe809;</span> User Interface</h1>
			<hr>
				<h2>Theme.</h2>
				<select name='theme' onChange='themecheck(this)'>
					<?php
						echo "<option value='default' ".($user_settings['theme'] == "default" ? "selected" : "").">default</option>";
						foreach(themes("list") as $name){
							echo "<option value='$name' ".($user_settings['theme'] == $name ? "selected" : "").">$name</option>";
						}
						echo "<option value='custom' ".($user_settings['theme'] == "custom" ? "selected" : "").">custom</option>";
					?>
				</select>
				
				<div id="customtheme"<?php echo ($user_settings['theme'] == "custom" ? "" : "style='display:none;'");?>>
				<fieldset>
				<legend>Custom Colors</legend>
					Foreground:<br>
					<input type="color" name="fg" value="#<?php echo (!empty($theme) ? $theme['fg'] : "#ffffff");?>"><br><br>
					Background:<br>
					<input type="color" name="bg" value="#<?php echo (!empty($theme) ? $theme['bg'] : "#2b475d");?>"><br><br>
					Text Color:<br>
					<input type="color" name="tx" value="#<?php echo (!empty($theme) ? $theme['tx'] : "#000000");?>"><br><br>
					Link Color:<br>
					<input type="color" name="lc" value="#<?php echo (!empty($theme) ? $theme['lc'] : "#4682b4");?>"><br><br>
					Border Color:<br>
					<input type="color" name="bc" value="#<?php echo (!empty($theme) ? $theme['bc'] : "#ffffff");?>"><br><br>
					Border Width:<br>
					<input type="text" name="bw" value="<?php echo (!empty($theme) ? $theme['bw'] : "0");?>"><br><br>
					Border Radius:<br>
					<input type="text" name="br" value="<?php echo (!empty($theme) ? $theme['br'] : "3");?>"><br><br>
					Drop Shadow Size:<br>
					<input type="text" name="dr" value="<?php echo (!empty($theme) ? $theme['dr'] : "0");?>"><br><br>
				</fieldset>
				</div>
			<br>
			<br><br>
			<input type="submit" value="Save" id="send">
			</form>
		</div>
	</div>
</div>

<?php
if ($logedin){
include ("modules/lists.php");
include ("modules/softmute.php");
}
?>
