<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at
        
  http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->
<div ng-switch="schemaType(schema)" class="schema-type">
  <input ng-switch-when="String" class="form-control" type="text"
         ng-model="user.plainAttrs[schema.key].values[index]"
         ng-required="{{schema.mandatoryCondition}}" validate="true"
         ng-disabled="schema.readonly || customReadonly(schema.key)"
         ng-init="initAttribute(schema, index)"
         name="{{schema.key}}"/>

  <div ng-switch-when="Encrypted" class="input-group input-group-sm">
    <span class="input-group-btn" ng-disabled="schema.readonly || customReadonly(schema.key)">  
      <button type="button" class="btn btn-default btn-sm btn-flat"
              confirm="{{'CONFIRM_REMOVE'| translate}}"
              onclick="var pwd = $(this).parent().next('input');
                  if (pwd.is('[readonly]')) {
                    if (pwd.val() === '') {
                      pwd.removeAttr('readonly');
                      $(this).children().attr('class', 'fa fa-unlock');
                    } else {
                      var response = confirm($(this).attr('confirm'));
                      if (response == true) {
                        pwd.removeAttr('readonly');
                        pwd.val('');
                        $(this).children().attr('class', 'fa fa-unlock');
                      }
                    }
                  }
              ">
        <i class="fa fa-lock"></i>
      </button>
    </span>
    <input class="form-control" type="password" readonly="true"
           ng-model="user.plainAttrs[schema.key].values[index]"
           ng-required="{{schema.mandatoryCondition}}" validate="true"
           ng-disabled="schema.readonly || customReadonly(schema.key)" ng-init="initAttribute(schema, index)" 
           name="{{schema.key}}"/>
    <span class="input-group-btn">  
      <button type="button" class="btn btn-default btn-sm btn-flat"
              onmousedown="var pwd = $(this).parent().prev('input');
                  if (!pwd.is('[readonly]')) {
                    pwd.attr('type', 'text');
                    $(this).children().attr('class', 'fa fa-eye-slash');
                  }"
              onmouseup="var pwd = $(this).parent().prev('input');
                  if (!pwd.is('[readonly]')) {
                    pwd.attr('type', 'password');
                    $(this).children().attr('class', 'fa fa-eye');
                  }"
              >
        <i class="fa fa-eye"></i>
      </button>
    </span>
  </div>

  <div ng-switch-when="Boolean">
    <input type="checkbox" ng-model="user.plainAttrs[schema.key].values[index]" 
           ng-true-value="'true'" 
           ng-false-value="'false'" 
           ng-required="{{schema.mandatoryCondition}}"
           ng-disabled="schema.readonly || customReadonly(schema.key)"
           ng-init="initAttribute(schema, index)" />
  </div>

  <input ng-switch-when="Long" class="form-control"
         type="number"
         ng-model="user.plainAttrs[schema.key].values[index]" 
         ng-required="{{schema.mandatoryCondition}}"
         ng-disabled="schema.readonly || customReadonly(schema.key)"
         validate="true"
         ng-init="initAttribute(schema, index)"
         name="{{schema.key}}"/>

  <input ng-switch-when="Double" class="form-control" type="number" ng-model="user.plainAttrs[schema.key].values[index]"
         ng-required="{{schema.mandatoryCondition}}" validate="true"
         ng-disabled="schema.readonly || customReadonly(schema.key)"
         ng-init="initAttribute(schema, index)" name="{{schema.key}}"/>

  <div ng-switch-when="Date" id="date">
    <input type="text" class="dateTimePicker"
           kendo-date-time-picker
           ng-show="!isDateOnly"
           ng-model="extendedDate"
           ng-required="{{schema.mandatoryCondition}}" close-text="Close"
           ng-init="initAttribute(schema, index)"
           ng-change="bindDateToModel(selectedDate, extendedDate)"
           ng-disabled="schema.readonly || customReadonly(schema.key)"
           k-ng-model="selectedDate"
           data-k-format="languageFormat"
           />
    <input type="text" class="datePicker"
           kendo-date-picker
           ng-show="isDateOnly"
           ng-model="extendedDate"
           ng-required="{{schema.mandatoryCondition}}" close-text="Close"
           ng-init="initAttribute(schema, index)"
           ng-change="bindDateToModel(selectedDate, extendedDate)"
           ng-disabled="schema.readonly || customReadonly(schema.key)"
           k-ng-model="selectedDate"
           data-k-format="languageFormat"
           />
  </div>

  <div ng-switch-when="Enum" ng-init="initAttribute(schema, index)">
    <select class="form-control custom-select"
            ng-model="user.plainAttrs[schema.key].values[index]"
            ng-required="{{schema.mandatoryCondition}}"
            ng-disabled="schema.readonly || customReadonly(schema.key)">
      <option ng-repeat="value in enumerationValues" value="{{value}}">
        {{enumerationKeys[$index]|| value}}
      </option>
    </select>
  </div>

  <div ng-switch-when="Binary"
       ng-disabled="schema.readonly || customReadonly(schema.key)"
       ng-init="initAttribute(schema, index)">
    <input file-input type="file" id="fileInput" name="fileInput"/>
    <button type="button" title="Download file" class="fileButton btn btn-default btn-sm" ng-click="download()">
      <i class="fa fa-arrow-circle-down" ></i>
    </button>
  </div>

  <input ng-switch-default class="form-control" type="text"
         ng-model="user.plainAttrs[schema.key].values[index]"
         ng-required="{{schema.mandatoryCondition}}" 
         ng-disabled="schema.readonly || customReadonly(schema.key)"
         ng-init="initAttribute(schema, index)"/>
</div>
