<div class="modal-header">
    <button ng-click="cancel()" type="button" aria-label="Close" class="close closebtn">&times;</button>
    <span class="modal-title">{{'Edit field' | translate}}</span>
</div>
<div class="modal-body">
    <form name="typeForm" class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-3 control-label">
                {{'Display name' | translate}}<small class="text-danger">*</small>
            </label>
            <div class="col-sm-9">
                <input ng-model="field.value.label" type="text" class="form-control" required />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">
                {{'Internal name' | translate}}<small class="text-danger">*</small>
            </label>
            <div class="col-sm-9">
                <input ng-model="field.title" ng-disabled="!isNewForm" type="text" class="form-control" wizdom365-unique="reservedKeys" required />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">
                {{'Category' | translate}}<small class="text-danger">*</small>
            </label>
            <div class="col-sm-9">
                <select ng-options="category as category for category in categories" ng-model="field.value.category" class="form-control"></select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">{{'Type' | translate}}</label>
            <div class="col-sm-9">
                <select ng-model="field.value.type" ng-change="typeChanged()" class="form-control">
                    <option value="text">{{'Text' | translate}}</option>
                    <option value="textarea">{{'Richtext' | translate}}</option>
                    <option value="html">{{'HTML' | translate}}</option>
                    <option value="number">{{'Number' | translate}}</option>
                    <option value="date">{{'Date' | translate}}</option>
                    <option value="checkbox">{{'Checkbox' | translate}}</option>
                    <option value="radio">{{'Radio buttons' | translate}}</option>
                    <option value="select">{{'Select' | translate}}</option>
                    <option value="principals">{{'People picker' | translate}}</option>
                </select>
                <div ng-if="field.value.type === 'radio' || field.value.type === 'select'">
                    <small class="text-muted">{{'Each line is a new option' | translate}}</small>
                    <textarea ng-model="field.value.optionsText"
                              ng-change="setFieldOptions()"
                              ng-list="&#10;"
                              ng-trim="false"
                              rows="5"
                              class="form-control"
                              placeholder="{{'Example option' | translate}} 1&#10;{{'Example option' | translate}} 2"
                              required></textarea>
                </div>
                <div ng-if="field.value.type === 'number'" class="row">
                    <div class="col-sm-4">
                        <small class="text-muted">{{'Step' | translate}}</small>
                        <input type="number" name="numberStep" class="form-control input-sm" step="any" min="0" max="{{field.value.max}}" ng-model="field.value.step" />
                    </div>
                    <div class="col-sm-4">
                        <small class="text-muted">{{'Min' | translate}}</small>
                        <input type="number" name="numberMin" class="form-control input-sm" max="{{field.value.max}}" ng-model="field.value.min" />
                    </div>
                    <div class="col-sm-4">
                        <small class="text-muted">{{'Max' | translate}}</small>
                        <input type="number" name="numberMax" class="form-control input-sm" min="{{field.value.min}}" ng-model="field.value.max" />
                    </div>
                </div>
                <div ng-if="field.value.type === 'principals'" class="row">
                    <div class="col-sm-6">
                        <small class="text-muted">{{'Mode' | translate}}</small>
                        <select ng-model="field.value.principalMode" ng-init="field.value.principalMode = 'all'" class="form-control input-sm">
                            <option value="all">{{'Users and groups' | translate}}</option>
                            <option value="users">{{'Users' | translate}}</option>
                            <option value="groups">{{'Groups' | translate}}</option>
                        </select>
                    </div>
                    <div class="col-sm-6">
                        <small class="text-muted">{{'Domain' | translate}}</small>
                        <select ng-model="field.value.principalDomain" ng-init="field.value.principalDomain = 'all'" class="form-control input-sm">
                            <option value="all">{{'Internals and externals' | translate}}</option>
                            <option value="internals">{{'Internals' | translate}}</option>
                            <option value="externals">{{'Externals' | translate}}</option>
                        </select>
                    </div>
                </div>
                <div ng-if="field.value.type === 'select' || field.value.type === 'principals'" class="checkbox">
                    <label>
                        <input type="checkbox" ng-model="field.value.allowMultiple" />{{'Allow multiple' | translate}}
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">{{'Default value' | translate}}</label>
            <div class="col-sm-9" ng-switch="field.value.type">
                <input    ng-switch-when="text" type="text" class="form-control" ng-model="field.value.defaultValue" />
                <textarea ng-switch-when="textarea" ui-tinymce toolbar-configuration="LiveTiles" ng-model="field.value.defaultValue"></textarea>
                <div      ng-switch-when="html" ui-ace="{mode: 'html'}" ng-model="field.value.defaultValue"></div>
                <input    ng-switch-when="number" type="number" class="form-control" step="{{field.value.step}}" min="{{field.value.min}}" max="{{field.value.max}}" ng-model="field.value.defaultValue" />
                <div      ng-switch-when="date" wizdom365-datetime-picker show-date-picker="true" date="field.value.defaultValue"></div>
                <div      ng-switch-when="checkbox" class="checkbox"><label><input type="checkbox" ng-model="field.value.defaultValue" /></label></div>
                <div      ng-switch-when="radio" ng-repeat="option in field.value.options" class="radio"><label><input type="radio" ng-model="field.value.defaultValue" ng-value="option.value" />{{option.name}}</label></div>
                <select   ng-switch-when="select" ng-if="!field.value.allowMultiple" class="form-control" ng-options="option.value as option.name for option in field.value.options" ng-model="field.value.defaultValue"></select>
                <select   ng-switch-when="select" ng-if="field.value.allowMultiple" multiple class="form-control" ng-options="option.value as option.name for option in field.value.options" ng-model="field.value.defaultValue"></select>
                <wizdom365-principalpicker ng-switch-when="principals" principals="field.value.defaultValue" mode="{{field.value.principalMode}}" domain="{{field.value.principalDomain}}" allowmultiple="{{field.value.allowMultiple}}" add-fn="addPrincipal(principal)" remove-fn="removePrincipal(principal)" placeholder=""></wizdom365-principalpicker>
            </div>
        </div>
    </form>
</div>
<div class="modal-footer">
    <button class="btn btn-danger pull-left" ng-if="!isNewForm" ng-click="delete();">{{'Delete' | translate}}</button>
    <button class="btn btn-default" ng-disabled="loading" ng-click="cancel();">{{(hasPendingChanges() ? 'Cancel' : 'Close') | translate}}</button>
    <button class="btn btn-success" ng-if="hasPendingChanges()" ng-click="save();" ng-disabled="typeForm.$invalid">{{'Save' | translate}}</button>
</div>