{{ extends "layouts/profile" }}
{{ import "layouts/partials/menu/profile" }}
{{ import "layouts/partials/helpers/csrf" }}
{{block title()}}{{  T("profile_edit_page", UserProfile.Username) }}{{end}}
{{ block profile_navigation()}}{{ yield profile_menu(route="profile_edit") }}{{end}}
{{block profile_content()}}
<h2 style="margin-top: 4px;">{{  T("personal_info")}}</h2>

 <form role="form" method="POST">
 {{ yield csrf_field()}}
<table class="user-edit-table">
	<tbody>
		<tr>
			<td>{{ T("api_token") }}:</td>
			<td><span style="font-family: monospace;">{{if UserProfile.APIToken == ""}}{{T("no_api_token")}}{{else}}{{UserProfile.APIToken}}{{end}}</span></td>
		</tr>
		<tr>
			<td></td>
			<td style="padding-bottom: 6px;"><a href="/apidoc">{{ T("api_documentation")}}</a> / <a class="form-input up-input" href="/user/{{ UserProfile.ID}}/{{UserProfile.Username }}/apireset">Reset API key</a></td>
		</tr>
		<tr>
			<td><label for="email">{{  T("email_address") }}</label></td>
			<td><input class="form-input up-input" placeholder="{{  T("email_placeholder")}}" type="text" name="email" id="email" value="{{UserProfile.Email}}"/></td>
		</tr>
		<tr>
			<td><label for="language">{{  T("language")}}</label></td>
			<td>
				<select id="language" name="language" class="form-input up-input">
				  {{ userLanguage := UserProfile.Language }}
				  {{ range _, language := Languages }}
				  <option value="{{ language.Tag }}" {{ if userLanguage == language.Tag || userLanguage == language.Code || ((userLanguage == "") && (language.Tag == getDefaultLanguage())) }}selected{{end}}>{{ language.Name }} {{if language.Tag == getDefaultLanguage()}}({{  T("default") }}){{end}}</option>
				  {{ end }}
				</select>
			</td>
		</tr>
		{{ if !User.IsModerator()}}
		<tr>
			<td><label for="current_password">{{  T("current_password") }}</label></td>
			<td><input class="form-input up-input up-input" name="current_password" id="current_password" type="password"/></td>
		</tr>
		{{end}}
		<tr>
			<td><label for="password">{{  T("password") }}</label></td>
			<td><input class="form-input up-input up-input" name="password" id="password" type="password"/></td>
		</tr>
		<tr>
			<td><label for="password_confirmation">{{  T("confirm_password") }}</label></td>
			<td><input class="form-input up-input up-input" name="password_confirmation" id="password" type="password"/></td>
		</tr>
	</tbody>
</table>
    {{ yield errors(name="Email")}}
	{{ yield errors(name="Language")}}
    {{ if !User.IsModerator()}}
        {{ yield errors(name="CurrentPassword")}}
    {{end}}
	{{ yield errors(name="Password")}}
    {{ yield errors(name="ConfirmPassword")}}

<h2>{{  T("preferences")}}</h2>
<table class="user-edit-table">
	<tbody>
		<tr>
			<td><label for="theme">{{ T("theme") }}:</label></td>
			<td>
				<select id="theme-selector" name="theme" class="form-input up-input" onchange="switchThemes()">
				  <option value="">{{ T("theme_select")}}</option>
				  {{ range theme := getThemeList()}}
					  <option value="{{theme}}"{{ if Theme == theme}} selected{{end}}>{{formatThemeName(theme, T)}}</option>
				  {{end}}
				  <option value=""{{ if Theme == "" }} selected{{end}}>{{ T("theme_none")}}</option>
				</select>
			</td>
		</tr>
		<tr class="hidden">
			<td><label for="anidex_api">Anidex API Token:</label></td>
			<td><input disabled class="form-input up-input" placeholder="Coming soon..." type="text" name="anidex_api" id="anidex_api" value="{{UserProfile.AnidexAPIToken}}"/></td>
		</tr>
		<tr class="hidden">
			<td><label for="nyaasi_api">Nyaa.si API Token:</label></td>
			<td><input disabled class="form-input up-input" placeholder="Coming soon..." type="text" name="nyaasi_api" id="nyaasi_api" value="{{UserProfile.NyaasiAPIToken}}"/></td>
		</tr>
		<tr class="hidden">
			<td><label for="tokyot_api">TokyoTosho API Token:</label></td>
			<td><input disabled class="form-input up-input" placeholder="Coming soon..." type="text" name="tokyot_api" id="tokyot_api" value="{{UserProfile.TokyoTAPIToken }}"/></td>
		</tr>
		{{ if DefaultUserSettings("new_torrent")}}
		<tr><td colspan="2"  style="padding:0"><label for="new_torrent">{{  T("new_torrent_settings") }}</label></td></tr>
		<tr>
			<td  colspan="2">
				<select id="new_torrent" name="new_torrent" class="form-input up-input">
				  <option value="0" {{ if !UserProfile.Settings.Get("new_torrent") }}selected{{end}}>{{  T("no")}}</option>
				  <option value="1" {{ if UserProfile.Settings.Get("new_torrent") }}selected{{end}}>{{  T("yes")}}</option>
				</select>
			</td>
		</tr>
		{{end}}
		{{ if DefaultUserSettings("new_torrent_email")}}
		<tr><td colspan="2" style="padding:0"><label for="new_torrent_email">{{  T("new_torrent_email_settings") }}</label></td></tr>
		<tr>
			<td colspan="2">
				<select id="new_torrent_email" name="new_torrent_email" class="form-input up-input">
				  <option value="0" {{ if !UserProfile.Settings.Get("new_torrent_email") }}selected{{end}}>{{  T("no")}}</option>
				  <option value="1" {{ if UserProfile.Settings.Get("new_torrent_email")}}selected{{end}}>{{  T("yes")}}</option>
				</select> 
			</td>
		</tr>
		{{end}}
		{{ if DefaultUserSettings("new_comment")}}
		<tr><td colspan="2"  style="padding:0"><label for="new_comment">{{  T("new_comment_settings") }}</label></td></tr>
		<tr>
			<td colspan="2">
				<select id="new_comment" name="new_comment" class="form-input up-input">
				  <option value="0" {{ if !UserProfile.Settings.Get("new_comment") }}selected{{end}}>{{  T("no")}}</option>
				  <option value="1" {{ if UserProfile.Settings.Get("new_comment") }}selected{{end}}>{{  T("yes")}}</option>
				</select> 
			</td>
		</tr>
		{{end}}
		{{ if DefaultUserSettings("new_comment_email")}}
		<tr><td colspan="2"  style="padding:0"><label for="new_comment_email">{{  T("new_comment_email_settings") }}</label></td></tr>
		<tr>
			<td colspan="2">
				<select id="new_comment_email" name="new_comment_email" class="form-input up-input">
				  <option value="0" {{ if !UserProfile.Settings.Get("new_comment_email") }}selected{{end}}>{{  T("no")}}</option>
				  <option value="1" {{ if UserProfile.Settings.Get("new_comment_email") }}selected{{end}}>{{  T("yes")}}</option>
				</select>
			</td>
		</tr>
		{{end}}
		{{ if DefaultUserSettings("new_responses")}}
		<tr><td colspan="2"  style="padding:0"><label for="new_responses">{{  T("new_responses_settings") }}</label></td></tr>
		<tr>
			<td colspan="2">
				<select id="new_responses" name="new_responses" class="form-input up-input">
				  <option value="0" {{ if !UserProfile.Settings.Get("new_responses") }}selected{{end}}>{{  T("no")}}</option>
				  <option value="1" {{ if UserProfile.Settings.Get("new_responses")}}selected{{end}}>{{  T("yes")}}</option>
				</select>
			</td>
		</tr>
		{{end}}
		{{ if DefaultUserSettings("new_responses_email")}}
		<tr><td colspan="2"  style="padding:0"><label for="new_responses_email">{{  T("new_responses_email_settings") }}</label></td></tr>
		<tr>
			<td colspan="2">
				<select id="new_responses_email" name="new_responses_email" class="form-input up-input">
				  <option value="0" {{ if UserProfile.Settings.Get("new_responses_email") }}selected{{end}}>{{  T("no")}}</option>
				  <option value="1" {{ if UserProfile.Settings.Get("new_responses_email")}}selected{{end}}>{{  T("yes")}}</option>
				</select>
			</td>
		</tr>
		{{end}}
		{{ if DefaultUserSettings("new_follower")}}
		<tr><td colspan="2"  style="padding:0"><label for="new_follower">{{  T("new_follower_settings") }}</label></td></tr>
		<tr>
			<td colspan="2">
				<select id="new_follower" name="new_follower" class="form-input up-input">
				  <option value="0" {{ if UserProfile.Settings.Get("new_follower") }}selected{{end}}>{{  T("no")}}</option>
				  <option value="1" {{ if UserProfile.Settings.Get("new_follower")}}selected{{end}}>{{  T("yes")}}</option>
				</select>
			</td>
		</tr>
		{{end}}
		{{ if DefaultUserSettings("new_follower_email")}}
		<tr><td colspan="2"  style="padding:0"><label for="new_follower_email">{{  T("new_follower_email_settings") }}</label></td></tr>
		<tr>
			<td colspan="2">
				<select id="new_follower_email" name="new_follower_email" class="form-input up-input">
				  <option value="0" {{ if UserProfile.Settings.Get("new_follower_email") }}selected{{end}}>{{  T("no")}}</option>
				  <option value="1" {{ if UserProfile.Settings.Get("new_follower_email")}}selected{{end}}>{{  T("yes")}}</option>
				</select>
			</td>
		</tr>
		{{end}}
		{{ if DefaultUserSettings("followed")}}
		<tr><td colspan="2"  style="padding:0"><label for="followed">{{  T("followed_settings") }}</label></td></tr>
		<tr>
			<td colspan="2">
				<select id="followed" name="followed" class="form-input up-input">
				  <option value="0" {{ if UserProfile.Settings.Get("followed") }}selected{{end}}>{{  T("no")}}</option>
				  <option value="1" {{ if UserProfile.Settings.Get("followed")}}selected{{end}}>{{  T("yes")}}</option>
				</select>
			</td>
		</tr>
		{{end}}
		{{ if DefaultUserSettings("followed_email")}}
		<tr><td colspan="2"  style="padding:0"><label for="followed_email">{{  T("followed_email_settings") }}</label></td></tr>
		<tr>
			<td colspan="2">
				<select id="followed_email" name="followed_email" class="form-input up-input">
				  <option value="0" {{ if UserProfile.Settings.Get("followed_email") }}selected{{end}}>{{  T("no")}}</option>
				  <option value="1" {{ if UserProfile.Settings.Get("followed_email")}}selected{{end}}>{{  T("yes")}}</option>
				</select>
			</td>
		</tr>
		{{end}}
	</tbody>
</table>

    {{ if DefaultUserSettings("new_torrent")}}
        {{ yield errors(name="NewTorrent")}}
    {{end}}
    {{ if DefaultUserSettings("new_torrent_email")}}
		{{ yield errors(name="NewTorrentEmail")}}
    {{end}}
    {{ if DefaultUserSettings("new_comment")}}
		{{ yield errors(name="NewComment")}}
    {{end}}
    {{ if DefaultUserSettings("new_comment_email")}}
        {{ yield errors(name="NewCommentEmail")}}
    {{end}}
    {{ if DefaultUserSettings("new_responses")}}
        {{ yield errors(name="NewResponses")}}
    {{end}}
    {{ if DefaultUserSettings("new_responses_email")}}
        {{ yield errors(name="NewResponsesEmail")}}
    {{end}}
    {{ if DefaultUserSettings("new_follower")}}
        {{ yield errors(name="NewFollower")}}
    {{end}}
    {{ if DefaultUserSettings("new_follower_email")}}
        {{ yield errors(name="NewFollowerEmail")}}
    {{end}}
    {{ if DefaultUserSettings("followed")}}
        {{ yield errors(name="Followed")}}
    {{end}}
    {{ if DefaultUserSettings("followed_email")}}
        {{ yield errors(name="FollowedEmail")}}
    {{end}}

{{ if User.IsModerator()}}
<h2>{{  T("moderation")}}</h2>
<table class="user-edit-table">
	<tbody>
		<tr>
			<td><label for="username">{{ T("username") }}:</label></td>
			<td><input class="form-input up-input" name="username" id="username" type="text" value="{{UserProfile.Username}}"></td>
		</tr>
		<tr>
			<td><label for="status">{{ T("role") }}:</label></td>
			<td>
				<select id="status" name="status" class="form-input up-input">
				  <option value="-1" {{ if UserProfile.Status == -1 }}selected{{end}}>{{  T("userstatus_banned")}}</option>
				  <option value="0" {{ if UserProfile.Status == 0 }}selected{{end}}>{{  T("userstatus_member")}} ({{  T("default") }})</option>
				  <option value="1" {{ if UserProfile.Status == 1 }}selected{{end}}>{{  T("userstatus_trusted")}}</option>
				  {{ if User.Status == 2}}
				  <option value="4" {{ if UserProfile.Status == 4 }}selected{{end}}>{{  T("userstatus_janitor")}}</option>
				  <option value="2" {{ if UserProfile.Status == 2 }}selected{{end}}>{{  T("userstatus_moderator")}}</option>
				  {{end}}
				  <option value="3" {{ if UserProfile.Status == 3 }}selected{{end}}>{{  T("userstatus_scraped")}}</option>
				</select>
			</td>
		</tr>
	</tbody>
</table>
	{{ yield errors(name="Username")}}
	{{ yield errors(name="Status")}}
 {{end}}

    <input type="submit" class="form-input btn-green" name="save" value="{{  T("save_changes")}}">
    <input type="reset" class="form-input" value="{{  T("cancel")}}">
  </form>
{{ if User.CurrentOrAdmin(UserProfile.ID) }}
<hr/>
<form method="POST" action="/user/{{UserProfile.ID}}/{{UserProfile.Username}}/delete" >
 {{ yield csrf_field()}}
  <button type="submit" class="form-input btn-red" onclick="if (!confirm('{{  T(" delete_account_confirm ") }}')) return false;" style="float:right">{{  T("delete_account") }}</button>
</form>
{{end}}
{{end}}
