<uib-alert ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)">{{alert.msg}}</uib-alert>

<input name="_method" type="hidden" ng-value="method">
<input name="user[profile_attributes][id]" type="hidden" ng-value="user.profile.id">

<div class="row m-t">
    <div class="col-sm-3 col-sm-offset-1">
      <div class="form-group m-t-lg">
          <div class="fileinput text-center" data-provides="fileinput" ng-class="fileinputClass(user.profile.user_avatar.attachment_url)">
            <div class="fileinput-new thumbnail rounded thumb-128-wrapper" style="width: 140px; height: 140px;">
              <img src="<%= image_path("no_avatar.png") %>" class="img-circle">
            </div>
            <div class="fileinput-preview fileinput-exists thumbnail rounded thumb-128-wrapper" data-trigger="fileinput" style="width: 140px; height: 140px; line-height: 140px;">
              <img ng-src="{{ user.profile.user_avatar.attachment_url }}" />
            </div>
            <div class="m-t-sm">
              <input type="hidden" name="user[profile_attributes][user_avatar_attributes][id]" ng-value="user.profile.user_avatar.id">
              <input type="hidden" name="user[profile_attributes][user_avatar_attributes][_destroy]" ng-value="true" ng-if="user.profile.user_avatar._destory">
              <span class="btn btn-default btn-file"
                    ng-click="user.profile.user_avatar._destory = false"
                    ng-hide="preventField['profile.avatar'] && user.profile.user_avatar.attachment_url && !userForm['user[profile_attributes][user_avatar_attributes]'].$dirty">
                  <span class="fileinput-new" translate>{{ 'add_an_avatar' }}</span>
                  <span class="fileinput-exists" translate>{{ 'change' }}</span>
                  <input type="file" name="user[profile_attributes][user_avatar_attributes][attachment]">
              </span>

              <button class="btn btn-danger fileinput-exists"
                      data-dismiss="fileinput"
                      ng-click="user.profile.user_avatar._destory = true"
                      ng-hide="preventField['profile.avatar'] && user.profile.user_avatar.attachment_url && !userForm['user[profile_attributes][user_avatar_attributes]'].$dirty">
                  <i class="fa fa-trash-o"></i>
              </button>
            </div>
          </div>
      </div>

    </div>
    <div class="col-sm-offset-1 col-sm-6">

      <div class="form-group" ng-class="{'has-error': userForm['user[profile_attributes][gender]'].$dirty && userForm['user[profile_attributes][gender]'].$invalid}">
          <label class="checkbox-inline btn btn-default">
            <input type="radio"
                   name="user[profile_attributes][gender]"
                   ng-model="user.profile.gender"
                   value="true"
                   ng-disabled="preventField['profile.gender'] && user.profile.gender && !userForm['user[profile_attributes][gender]'].$dirty"
                   required/>
              <i class="fa fa-male m-l-sm"></i> {{ 'man' | translate }}
          </label>
          <label class="checkbox-inline btn btn-default">
            <input type="radio"
                   name="user[profile_attributes][gender]"
                   ng-model="user.profile.gender"
                   value="false"
                   ng-disabled="preventField['profile.gender'] && user.profile.gender && !userForm['user[profile_attributes][gender]'].$dirty"/>
              <i class="fa fa-female m-l-sm"></i> {{ 'woman' | translate }}
          </label>
          <span class="help-block" ng-show="userForm['user[profile_attributes][gender]'].$dirty && userForm['user[profile_attributes][gender]'].$error.required" translate>{{ 'gender_is_required' }}</span>
      </div>


      <div class="form-group" ng-class="{'has-error': userForm['user[username]'].$dirty && userForm['user[username]'].$invalid}">
        <div class="input-group">
          <span class="input-group-addon"><i class="fa fa-user"></i></span>
          <input type="text"
                 name="user[username]"
                 ng-model="user.username"
                 class="form-control"
                 id="user_username"
                 placeholder="{{ 'pseudonym' | translate }}"
                 ng-disabled="preventField['user.username'] && user.username  && !userForm['user[username]'].$dirty"
                 required/>
        </div>
        <span class="help-block" ng-show="userForm['user[username]'].$dirty && userForm['user[username]'].$error.required" translate>{{ 'pseudonym_is_required' }}</span>
      </div>



      <div class="form-group" ng-class="{'has-error': userForm['user[profile_attributes][last_name]'].$dirty && userForm['user[profile_attributes][last_name]'].$invalid}">
        <div class="input-group">
          <span class="input-group-addon"><i class="fa fa-user"></i></span>
          <input type="text"
                 name="user[profile_attributes][last_name]"
                 ng-model="user.profile.last_name"
                 class="form-control"
                 id="user_last_name"
                 placeholder="{{ 'surname' | translate }}"
                 ng-disabled="preventField['profile.last_name'] && user.profile.last_name && !userForm['user[profile_attributes][last_name]'].$dirty"
                 required/>
        </div>
        <span class="help-block" ng-show="userForm['user[profile_attributes][last_name]'].$dirty && userForm['user[profile_attributes][last_name]'].$error.required" translate>{{ 'surname_is_required' }}</span>
      </div>

      <div class="form-group" ng-class="{'has-error': userForm['user[profile_attributes][first_name]'].$dirty && userForm['user[profile_attributes][first_name]'].$invalid}">
        <div class="input-group">
          <span class="input-group-addon"><i class="fa fa-user"></i></span>
          <input type="text"
                 name="user[profile_attributes][first_name]"
                 ng-model="user.profile.first_name"
                 class="form-control"
                 id="user_first_name"
                 placeholder="{{ 'first_name' | translate }}"
                 ng-disabled="preventField['profile.first_name'] && user.profile.first_name && !userForm['user[profile_attributes][first_name]'].$dirty"
                 required/>
        </div>
        <span class="help-block" ng-show="userForm['user[profile_attributes][first_name]'].$dirty && userForm['user[profile_attributes][first_name]'].$error.required" translate>{{ 'first_name_is_required' }}</span>
      </div>

      <div class="form-group" ng-class="{'has-error': userForm['user[email]'].$dirty && userForm['user[email]'].$invalid}">
        <div class="input-group">
          <span class="input-group-addon"><i class="fa fa-envelope"></i> </span>
          <input type="email"
                 name="user[email]"
                 ng-model="user.email"
                 class="form-control"
                 id="user_email"
                 placeholder="{{ 'email_address' | translate }}"
                 ng-disabled="preventField['user.email'] && user.email && !userForm['user[email]'].$dirty"
                 required/>
        </div>
        <span class="help-block" ng-show="userForm['user[email]'].$dirty && userForm['user[email]'].$error.required" translate>{{ 'email_address_is_required' }}</span>
      </div>

      <div class="form-group" ng-hide="preventPassword">
        <button class="btn btn-warning btn-block"
                ng-click="password.change = !password.change; $event.stopPropagation(); $event.preventDefault()"
                translate>{{ 'change_password' }}</button>
      </div>


      <div class="form-group" ng-class="{'has-error': userForm['user[password]'].$dirty && userForm['user[password]'].$invalid}" ng-if="password.change">
        <div class="input-group">
          <span class="input-group-addon"><i class="fa fa-key"></i> </span>
          <input type="password"
                 name="user[password]"
                 ng-model="user.password"
                 class="form-control"
                 id="user_password"
                 placeholder="{{ 'new_password' | translate }}"
                 ng-minlength="8"
                 required/>
        </div>
        <span class="help-block" ng-show="userForm['user[password]'].$dirty && userForm['user[password]'].$error.required" translate>{{ 'password_is_required' }}</span>
        <span class="help-block" ng-show="userForm['user[password]'].$dirty && userForm['user[password]'].$error.minlength" translate>{{ 'password_is_too_short_(minimum_8_characters)' }}</span>
      </div>

      <div class="form-group" ng-class="{'has-error': userForm['user[password_confirmation]'].$dirty && userForm['user[password_confirmation]'].$invalid}" ng-if="password.change">
        <div class="input-group">
          <span class="input-group-addon"><i class="fa fa-key"></i> </span>
          <input type="password"
                 name="user[password_confirmation]"
                 ng-model="user.password_confirmation"
                 class="form-control"
                 id="user_password_confirmation"
                 placeholder="{{ 'confirmation_of_new_password' | translate }}"
                 ng-minlength="8"
                 required
                 match="user.password"/>
        </div>
        <span class="help-block" ng-show="userForm['user[password_confirmation]'].$dirty && userForm['user[password_confirmation]'].$error.required" translate>{{ 'confirmation_of_password_is_required' }}</span>
        <span class="help-block" ng-show="userForm['user[password_confirmation]'].$dirty && userForm['user[password_confirmation]'].$error.minlength" translate>{{ 'confirmation_of_password_is_too_short_(minimum_8_characters)' }}</span>
        <span class="help-block" ng-show="userForm['user[password_confirmation]'].$error.match" translate>{{ 'confirmation_mismatch_with_password' }}</span>
      </div>

      <div class="form-group" ng-class="{'has-error': userForm['user[profile_attributes][birthday]'].$dirty && userForm['user[profile_attributes][birthday]'].$invalid}">
        <div class="input-group">
          <span class="input-group-addon"><i class="fa fa-calendar-o"></i> </span>
          <input type="text"
                 id="user_birthday"
                 class="form-control"
                 ng-model="user.profile.birthday"
                 uib-datepicker-popup="{{datePicker.format}}"
                 datepicker-options="datePicker.options"
                 is-open="datePicker.opened"
                 placeholder="{{ 'date_of_birth' | translate }}"
                 ng-click="openDatePicker($event)"
                 ng-disabled="preventField['profile.birthday'] && user.profile.birthday && !userForm['user[profile_attributes][birthday]'].$dirty"
                 required/>
          <input type="hidden"
                 name="user[profile_attributes][birthday]"
                 value="{{user.profile.birthday | toIsoDate}}" />
        </div>
        <span class="help-block" ng-show="userForm['user[profile_attributes][birthday]'].$dirty && userForm['user[profile_attributes][birthday]'].$error.required" translate>{{ 'date_of_birth_is_required' }}</span>
      </div>

      <div class="form-group">
        <div class="input-group">
          <span class="input-group-addon"><i class="fa fa-map-marker"></i> </span>
          <input type="hidden"
                 name="user[profile_attributes][address_attributes][id]"
                 ng-value="user.profile.address.id" />
          <input type="text"
                 name="user[profile_attributes][address_attributes][address]"
                 ng-model="user.profile.address.address"
                 class="form-control"
                 id="user_address"
                 ng-disabled="preventField['profile.address'] && user.profile.address.address && !userForm['user[profile_attributes][address_attributes][address]'].$dirty"
                 placeholder="{{ 'address' | translate }}"/>
        </div>
      </div>

      <div class="form-group" ng-class="{'has-error': userForm['user[profile_attributes][phone]'].$dirty && userForm['user[profile_attributes][phone]'].$invalid}">
        <div class="input-group">
          <span class="input-group-addon"><i class="fa fa-phone"></i> </span>
          <input type="text"
                 name="user[profile_attributes][phone]"
                 ng-model="user.profile.phone"
                 class="form-control"
                 id="user_phone"
                 placeholder="{{ 'phone_number' | translate }}"
                 ng-disabled="preventField['profile.phone'] && user.profile.phone && !userForm['user[profile_attributes][phone]'].$dirty"
                 required/>
        </div>
        <span class="help-block" ng-show="userForm['user[profile_attributes][phone]'].$dirty && userForm['user[profile_attributes][phone]'].$error.required" translate>{{ 'phone_number_is_required' }}</span>
      </div>

      <div class="form-group">
        <label for="user_interest" translate>{{ 'interests' }}</label>
        <textarea name="user[profile_attributes][interest]"
                  ng-model="user.profile.interest"
                  rows="5"
                  class="form-control"
                  id="user_interest"
                  placeholder=""
                  ng-disabled="preventField['profile.interest'] && user.profile.interest && !userForm['user[profile_attributes][interest]'].$dirty"></textarea>
      </div>

      <div class="form-group">
        <label for="user_software_mastered" translate>{{ 'CAD_softwares_mastered' }}</label>
        <textarea name="user[profile_attributes][software_mastered]"
                  ng-model="user.profile.software_mastered"
                  rows="5"
                  class="form-control"
                  id="user_software_mastered"
                  placeholder=""
                  ng-disabled="preventField['profile.software_mastered'] && user.profile.software_mastered && !userForm['user[profile_attributes][software_mastered]'].$dirty"></textarea>
      </div>

    </div>

</div>


