{{define "profile_edit_content"}}
	{{with .UserProfile}}
		{{ range (index $.FormInfos "infos")}}
			<div class="alert alert-info"><a class="panel-close close" data-dismiss="alert">×</a><i class="glyphicon glyphicon-info-sign"></i> {{ . }}</div>
		{{end}}
		{{ range (index $.FormErrors "errors")}}
			<div class="alert alert-danger"><a class="panel-close close" data-dismiss="alert">×</a><i class="glyphicon glyphicon-exclamation-sign"></i> {{ . }}</div>
		{{end}}
        <h3>{{ call $.T "personal_info"}}</h3>
       <div class="user-edit">
        <form role="form" method="POST">
            <label class="input-label">{{call $.T "api_token" }}:</label>
              <p style="font-family: monospace;">{{.APIToken}}</p>
              <a class="form-input" href="{{ genRoute "user_profile_apireset" "id" (print .ID) "username" .Username }}">Reset Api key</a>
            <label class="input-label">{{ call $.T "email_address" }}:</label> <br>
              <input class="form-input" type="text" name="email" id="email" value="{{.Email}}"> <br>
	 			{{ range (index $.FormErrors "email")}}
					<p class="text-error">{{ . }}</p>
				{{end}}
            <label class="input-label">{{ call $.T "language"}}:</label> <br>
                <select id="language" name="language" class="form-input">
					{{ $userLanguage := .Language }}
					{{ range $tag, $translatedName := $.Languages }}
						<option value="{{ $tag }}" {{ if or (eq $userLanguage $tag) (and (eq $userLanguage "") (eq $tag getDefaultLanguage)) }}selected{{end}}>{{ $translatedName }} {{if eq $tag getDefaultLanguage}}({{ call $.T "default" }}){{end}}</option>
					{{ end }}
                </select> <br>
	 			{{ range (index $.FormErrors "language")}}
					<p class="text-error">{{ . }}</p>
				{{end}}
          {{ if not (HasAdmin $.User)}}
            <label class="input-label">{{ call $.T "current_password"}}:</label> <br>
              <input class="form-input" name="current_password" id="current_password" type="password"> <br>
	 			{{ range (index $.FormErrors "current_password")}}
					<p class="text-error">{{ . }}</p>
				{{end}}
          {{end}}
            <label class="input-label">{{ call $.T "password"}}:</label> <br>
              <input class="form-input" name="password" id="password" type="password"> <br>
	 			{{ range (index $.FormErrors "password")}}
					<p class="text-error">{{ . }}</p>
				{{end}}
            <label class="input-label">{{ call $.T "confirm_password"}}:</label> <br>
              <input class="form-input" name="password_confirmation" id="password_confirmation" type="password"> <br>
	 			{{ range (index $.FormErrors "password_confirmation")}}
					<p class="text-error">{{ . }}</p>
				{{end}}
          <h3>{{ call $.T "preferences"}}</h3>
          {{ with .Settings }}
          {{ if DefaultUserSettings "new_torrent"}}
            <label class="input-label">{{ call $.T "new_torrent_settings" }}:</label> <br>
                <select id="new_torrent" name="new_torrent" class="form-control">
                  <option value="0" {{ if not (.Get "new_torrent") }}selected{{end}}>{{ call $.T "no"}}</option>
                  <option value="1" {{ if .Get "new_torrent" }}selected{{end}}>{{ call $.T "yes"}}</option>
                </select> <br>
              {{ range (index $.FormErrors "new_torrent")}}
          <p class="text-error">{{ . }}</p>
        {{end}}
          {{end}}
          {{ if DefaultUserSettings "new_torrent_email"}}
            <label class="input-label">{{ call $.T "new_torrent_email_settings" }}:</label> <br>
                <select id="new_torrent_email" name="new_torrent_email" class="form-control">
                  <option value="0" {{ if not (.Get "new_torrent_email") }}selected{{end}}>{{ call $.T "no"}}</option>
                  <option value="1" {{ if .Get "new_torrent_email"}}selected{{end}}>{{ call $.T "yes"}}</option>
                </select> <br>
              {{ range (index $.FormErrors "new_torrent_email")}}
          <p class="text-error">{{ . }}</p>
        {{end}}
          {{end}}
          {{ if DefaultUserSettings "new_comment"}}
            <label class="input-label">{{ call $.T "new_comment_settings" }}:</label> <br>
                <select id="new_comment" name="new_comment" class="form-control">
                  <option value="0" {{ if not (.Get "new_comment") }}selected{{end}}>{{ call $.T "no"}}</option>
                  <option value="1" {{ if .Get "new_comment" }}selected{{end}}>{{ call $.T "yes"}}</option>
                </select> <br>
              {{ range (index $.FormErrors "new_comment")}}
          <p class="text-error">{{ . }}</p>
        {{end}}
          {{end}}
          {{ if DefaultUserSettings "new_comment_email"}}
            <label class="input-label">{{ call $.T "new_comment_email_settings" }}:</label> <br>
                <select id="new_comment_email" name="new_comment_email" class="form-control">
                  <option value="0" {{ if not (.Get "new_comment_email") }}selected{{end}}>{{ call $.T "no"}}</option>
                  <option value="1" {{ if .Get "new_comment_email" }}selected{{end}}>{{ call $.T "yes"}}</option>
                </select> <br>
              {{ range (index $.FormErrors "new_comment_email")}}
          <p class="text-error">{{ . }}</p>
        {{end}}
          {{end}}
          {{ if DefaultUserSettings "new_responses"}}
            <label class="input-label">{{ call $.T "new_responses_settings" }}:</label> <br>
                <select id="new_responses" name="new_responses" class="form-control">
                  <option value="0" {{ if not (.Get "new_responses") }}selected{{end}}>{{ call $.T "no"}}</option>
                  <option value="1" {{ if .Get "new_responses" }}selected{{end}}>{{ call $.T "yes"}}</option>
                </select> <br>
              {{ range (index $.FormErrors "new_responses")}}
          <p class="text-error">{{ . }}</p>
        {{end}}
          {{end}}
          {{ if DefaultUserSettings "new_responses_email"}}
            <label class="input-label">{{ call $.T "new_responses_email_settings" }}:</label> <br>
                <select id="new_responses_email" name="new_responses_email" class="form-control">
                  <option value="0" {{ if not (.Get "new_responses_email") }}selected{{end}}>{{ call $.T "no"}}</option>
                  <option value="1" {{ if .Get "new_responses_email" }}selected{{end}}>{{ call $.T "yes"}}</option>
                </select> <br>
              {{ range (index $.FormErrors "new_responses_email")}}
          <p class="text-error">{{ . }}</p>
        {{end}}
          {{end}}
          {{ if DefaultUserSettings "new_follower"}}
            <label class="input-label">{{ call $.T "new_follower_settings" }}:</label> <br>
                <select id="new_follower" name="new_follower" class="form-control">
                  <option value="0" {{ if not (.Get "new_follower") }}selected{{end}}>{{ call $.T "no"}}</option>
                  <option value="1" {{ if .Get "new_follower" }}selected{{end}}>{{ call $.T "yes"}}</option>
                </select> <br>
              {{ range (index $.FormErrors "new_follower")}}
          <p class="text-error">{{ . }}</p>
        {{end}}
          {{end}}
          {{ if DefaultUserSettings "new_follower_email"}}
            <label class="input-label">{{ call $.T "new_follower_email_settings" }}:</label> <br>
                <select id="new_follower_email" name="new_follower_email" class="form-control">
                  <option value="0" {{ if not (.Get "new_follower_email") }}selected{{end}}>{{ call $.T "no"}}</option>
                  <option value="1" {{ if .Get "new_follower_email"}}selected{{end}}>{{ call $.T "yes"}}</option>
                </select> <br>
              {{ range (index $.FormErrors "new_follower_email")}}
          <p class="text-error">{{ . }}</p>
        {{end}}
          {{end}}
          {{ if DefaultUserSettings "followed"}}
            <label class="input-label">{{ call $.T "followed_settings" }}:</label> <br>
                <select id="followed" name="followed" class="form-control">
                  <option value="0" {{ if not (.Get "followed") }}selected{{end}}>{{ call $.T "no"}}</option>
                  <option value="1" {{ if .Get "followed" }}selected{{end}}>{{ call $.T "yes"}}</option>
                </select><br>
              {{ range (index $.FormErrors "followed")}}
          <p class="text-error">{{ . }}</p>
        {{end}}
          {{end}}
          {{ if DefaultUserSettings "followed_email"}}
            <label class="input-label">{{ call $.T "followed_email_settings" }}:</label> <br>
                <select id="followed_email" name="followed_email" class="form-control">
                  <option value="0" {{ if not (.Get "followed_email") }}selected{{end}}>{{ call $.T "no"}}</option>
                  <option value="1" {{ if .Get "followed_email" }}selected{{end}}>{{ call $.T "yes"}}</option>
                </select> <br>
              {{ range (index $.FormErrors "followed_email")}}
          <p class="text-error">{{ . }}</p>
        {{end}}
          {{end}}
          {{end}}
          {{ if HasAdmin $.User}}
          <h3>{{ call $.T "moderation"}}</h3>
            <label class="input-label">{{ call $.T "username"}}:</label> <br>
              <input class="form-control" name="username" id="username" type="text" value="{{.Username}}">
	 			{{ range (index $.FormErrors "username")}}
					<p class="text-error">{{ . }}</p>
				{{end}}
            <label class="input-label">{{ call $.T "role" }}:</label>
                <select id="status" name="status" class="form-control">
                	<option value="-1" {{ if eq .Status -1 }}selected{{end}}>{{ call $.T "banned"}}</option>
                	<option value="0" {{ if eq .Status 0 }}selected{{end}}>{{ call $.T "member"}} ({{ call $.T "default" }})</option>
                	<option value="1" {{ if eq .Status 1 }}selected{{end}}>{{ call $.T "trusted_member"}}</option>
                	{{ if eq .Status 2 }} <!-- just so that it shows correctly -->
                        <option value="2" selected>{{ call $.T "moderator"}}</option>
                	{{end}}
                </select>
	 			{{ range (index $.FormErrors "status")}}
					<p class="text-error">{{ . }}</p>
				{{end}}
		  {{end}}
            <label class="input-label"></label>
              <input type="submit" class="btn btn-primary" name="save" value="{{ call $.T "save_changes"}}">
              <span></span>
              <input type="reset" class="btn btn-default" value="{{ call $.T "cancel"}}">
        </form>
       </div>
        {{ if CurrentOrAdmin $.User .ID }}
        <hr>
        <a href="{{ genRoute "user_profile" }}?delete" onclick="if (!confirm('{{ call $.T "delete_account_confirm" }}')) return false;" class="btn btn-danger btn-lg"><i class="glyphicon glyphicon-trash"></i> {{ call $.T "delete_account"}}</a>
        {{end}}
	{{end}}
{{end}}
