<h1 id="<%= jhiPrefixDashed %>-<%= entityFileName %>-heading" jhiTranslate="<%= i18nKeyPrefix %>.home.createOrEditLabel">Create or edit a <%= entityClassHumanized %></h1>
<<%= jhiPrefixDashed %>-alert-error></<%= jhiPrefixDashed %>-alert-error>
<form name="editForm" role="form" novalidate (ngSubmit)="save()" #editForm="ngForm">
    <clr-stack-view>
        <clr-stack-header><span jhiTranslate="<%= i18nKeyPrefix %>.detail.title"><%= entityClassHumanized %></span> {{<%= entityInstance %>.id}}</clr-stack-header>


        <clr-stack-block [clrSbExpanded]="true">
            <clr-stack-label>{{'global.field.id' | translate }}</clr-stack-label>
            <clr-stack-content>{{<%= entityInstance %>.id}}</clr-stack-content>

            <%_ for (idx in fields) {
                    const fieldName = fields[idx].fieldName;
                    const fieldNameCapitalized = fields[idx].fieldNameCapitalized;
                    const fieldNameHumanized = fields[idx].fieldNameHumanized;
                    const fieldType = fields[idx].fieldType;
                    const fieldTypeBlobContent = fields[idx].fieldTypeBlobContent;
                    let fieldInputType = 'text';
                    let ngModelOption = '';
                    const translationKey = `${i18nKeyPrefix}.${fieldName}`;
                    if (['Integer', 'Long', 'Float', 'Double', 'BigDecimal'].includes(fieldType)) {
                    fieldInputType = 'number';
                    } else if (fieldType === 'LocalDate') {
                    fieldInputType = 'date';
                    } else if (['Instant', 'ZonedDateTime'].includes(fieldType)) {
                    fieldInputType = 'datetime-local';
                    } else if (fieldType === 'Boolean') {
                    fieldInputType = 'checkbox';
                    } else if (['byte[]', 'ByteBuffer'].includes(fieldType) && fieldTypeBlobContent !== 'text') {
                    fieldInputType = 'hidden';
                    }
                    _%>
                    <clr-stack-block>
                        <clr-stack-label for="field_<%= fieldName %>">
                            <span jhiTranslate="<%= i18nKeyPrefix %>.<%= fieldName %>"><%= fieldNameHumanized %></span>
                        </clr-stack-label>
                        <clr-stack-content>
                        <%_ if (fields[idx].fieldIsEnum) { _%>
                        <select class="form-control" name="<%= fieldName %>" [(ngModel)]="<%= entityInstance %>.<%= fieldName %>" id="field_<%= fieldName %>" <% if (fields[idx].fieldValidate === true && fields[idx].fieldValidateRules.includes('required')) { %> required<% } %>>
                        <%_ const enumPrefix = angularAppName + '.'+ fieldType;
                        const values = fields[idx].fieldValues.replace(/\s/g, '').split(',');
                        for (key in values) {
                        const value = values[key]; _%>
                        <option value="<%= value %>"><% if (enableTranslation) { %>{{'<%=enumPrefix%>.<%=value%>' | translate}}<% } else { %><%=value%><% } %></option>
                        <%_ } _%>
                        </select>
                        <%_ } else { _%>
                        <%_ if (['byte[]', 'ByteBuffer'].includes(fieldType) && fieldTypeBlobContent !== 'text') { _%>
                        <div>
                            <%_ if (fieldTypeBlobContent === 'image') { _%>
                            <img [src]="'data:' + <%=entityInstance %>.<%=fieldName%>ContentType + ';base64,' + <%=entityInstance %>.<%=fieldName%>" style="max-height: 100px;" *ngIf="<%= entityInstance %>.<%= fieldName %>" alt="<%=entityInstance %> image"/>
                            <%_ } _%>
                            <div *ngIf="<%= entityInstance %>.<%= fieldName %>" class="form-text text-danger clearfix">
                                <%_ if (fieldTypeBlobContent === 'any') { _%>
                                <a class="pull-left" (click)="openFile(<%= entityInstance %>.<%= fieldName %>ContentType, <%= entityInstance %>.<%= fieldName %>)" jhiTranslate="entity.action.open">open</a><br>
                                <span class="pull-left">{{<%= entityInstance %>.<%= fieldName %>ContentType}}, {{byteSize(<%= entityInstance %>.<%= fieldName %>)}}</span>
                                <%_ } else { _%>
                                <span class="pull-left">{{<%= entityInstance %>.<%= fieldName %>ContentType}}, {{byteSize(<%= entityInstance %>.<%= fieldName %>)}}</span>
                                <%_ } _%>
                                <%_ if (fieldTypeBlobContent === 'image') { _%>
                                <button type="button" (click)="clearInputImage('<%= fieldName %>', '<%= fieldName %>ContentType', 'fileImage')" class="btn btn-secondary btn-xs pull-right">
                                    <%_ } else { _%>
                                    <button type="button" (click)="<%= entityInstance %>.<%= fieldName %>=null;<%= entityInstance %>.<%= fieldName %>ContentType=null;"
                                            class="btn btn-secondary btn-xs pull-right">
                                        <%_ } _%>
                                        <span class="fa fa-times"></span>
                                    </button>
                            </div>
                            <input type="file" id="file_<%= fieldName %>" (change)="setFileData($event, <%= entityInstance %>, '<%= fieldName %>', <% if (fieldTypeBlobContent === 'image') { %>true)" accept="image/*" jhiTranslate="entity.action.addimage"<% } else { %>false)" jhiTranslate="entity.action.addblob"<% } %>/>
                        </div>
                        <%_ } _%>
                        <%_ if (fieldType === 'LocalDate') { _%>

                        <%_ } else if (['Instant', 'ZonedDateTime'].includes(fieldType)) { _%>
                        <div class="d-flex">
                            <input id="field_<%= fieldName %>" type="date" class="form-control" name="<%= fieldName %>" [(ngModel)]="<%= fieldName %>"
                            <%- include ng_validators %>/>
                        </div>
                        <%_ } else if (fieldTypeBlobContent === 'text') { _%>
                        <textarea class="form-control" name="<%= fieldName %>" id="field_<%= fieldName %>"
                                  [(ngModel)]="<%= entityInstance %>.<%= fieldName %>" <%- include ng_validators %>></textarea>
                        <%_ } else { _%>
                        <%_ if (fieldInputType === 'checkbox') { _%>
                        <div class="toggle-switch">
                            <input type="checkbox" class="form-control" name="<%= fieldName %>" id="field_<%= fieldName %>"
                               [(ngModel)]="<%= entityInstance %>.<%= fieldName %>"/>
                            <label for="field_<%= fieldName %>"></label>
                        </div>
                        <%_ } else { _%> 
                        <input type="<%= fieldInputType %>" class="form-control" name="<%= fieldName %>" id="field_<%= fieldName %>"
                               [(ngModel)]="<%= entityInstance %>.<%= fieldName %>" <%- include ng_validators %>/>
                        <%_ } _%>
                        <%_ if (['byte[]', 'ByteBuffer'].includes(fieldType) && fieldTypeBlobContent !== 'text') { _%>
                        <input type="hidden" class="form-control" name="<%= fieldName %>ContentType" id="field_<%= fieldName %>ContentType"
                               [(ngModel)]="<%= entityInstance %>.<%= fieldName %>ContentType" />
                        <%_ } _%>
                        <%_ } _%>
                        <%_ } _%>
                        <%_ if (fields[idx].fieldValidate === true) { _%>
                        <div [hidden]="!(editForm.controls.<%= fieldName %>?.dirty && editForm.controls.<%= fieldName %>?.invalid)">
                            <%_ if (fields[idx].fieldValidateRules.includes('required')) { _%>
                            <small class="form-text text-danger"
                                   [hidden]="!editForm.controls.<%= fieldName %>?.errors?.required" jhiTranslate="entity.validation.required">
                                This field is required.
                            </small>
                            <%_ } _%>
                            <%_ if (fields[idx].fieldValidateRules.includes('minlength')) { _%>
                            <small class="form-text text-danger"
                                   [hidden]="!editForm.controls.<%= fieldName %>?.errors?.minlength" jhiTranslate="entity.validation.minlength" translateValues="{ min: <%= fields[idx].fieldValidateRulesMinlength %> }">
                                This field is required to be at least <%= fields[idx].fieldValidateRulesMinlength %> characters.
                            </small>
                            <%_ } _%>
                            <%_ if (fields[idx].fieldValidateRules.includes('maxlength')) { _%>
                            <small class="form-text text-danger"
                                   [hidden]="!editForm.controls.<%= fieldName %>?.errors?.maxlength" jhiTranslate="entity.validation.maxlength" translateValues="{ max: <%= fields[idx].fieldValidateRulesMaxlength %> }">
                                This field cannot be longer than <%= fields[idx].fieldValidateRulesMaxlength %> characters.
                            </small>
                            <%_ } _%>
                            <%_ if (fields[idx].fieldValidateRules.includes('min')) { _%>
                            <small class="form-text text-danger"
                                   [hidden]="!editForm.controls.<%= fieldName %>?.errors?.min" jhiTranslate="entity.validation.min" translateValues="{ min: <%= fields[idx].fieldValidateRulesMin %> }">
                                This field should be at least <%= fields[idx].fieldValidateRulesMin %>.
                            </small>
                            <%_ } _%>
                            <%_ if (fields[idx].fieldValidateRules.includes('max')) { _%>
                            <small class="form-text text-danger"
                                   [hidden]="!editForm.controls.<%= fieldName %>?.errors?.max" jhiTranslate="entity.validation.max" translateValues="{ max: <%= fields[idx].fieldValidateRulesMax %> }">
                                This field cannot be more than <%= fields[idx].fieldValidateRulesMax %>.
                            </small>
                            <%_ } _%>
                            <%_ if (fields[idx].fieldValidateRules.includes('minbytes')) { _%>
                            <small class="form-text text-danger"
                                   [hidden]="!editForm.controls.<%= fieldName %>?.errors?.minbytes" jhiTranslate="entity.validation.minbytes" translateValues="{ min: <%= fields[idx].fieldValidateRulesMinbytes %> }">
                                This field should be at least <%= fields[idx].fieldValidateRulesMinbytes %>.
                            </small>
                            <%_ } _%>
                            <%_ if (fields[idx].fieldValidateRules.includes('maxbytes')) { _%>
                            <small class="form-text text-danger"
                                   [hidden]="!editForm.controls.<%= fieldName %>?.errors?.maxbytes" jhiTranslate="entity.validation.maxbytes" translateValues="{ max: <%= fields[idx].fieldValidateRulesMaxbytes %> }">
                                This field cannot be more than <%= fields[idx].fieldValidateRulesMaxbytes %>.
                            </small>
                            <%_ } _%>
                            <%_ if (fields[idx].fieldValidateRules.includes('pattern')) { _%>
                            <small class="form-text text-danger"
                                   [hidden]="!editForm.controls.<%= fieldName %>?.errors?.pattern" jhiTranslate="entity.validation.pattern" translateValues="{ pattern: '<%= fieldNameHumanized %>' }">
                                This field should follow pattern for "<%= fieldNameHumanized %>".
                            </small>
                            <%_ } _%>
                            <%_ if (['Integer', 'Long', 'Float', 'Double', 'BigDecimal'].includes(fieldType)) { _%>
                            <small class="form-text text-danger"
                                   [hidden]="!editForm.controls.<%= fieldName %>?.errors?.number" jhiTranslate="entity.validation.number">
                                This field should be a number.
                            </small>
                            <%_ } _%>
                            <%_ if (['Instant', 'ZonedDateTime'].includes(fieldType)) { _%>
                            <small class="form-text text-danger"
                                   [hidden]="!editForm.controls.<%= fieldName %>?.errors?.ZonedDateTimelocal" jhiTranslate="entity.validation.ZonedDateTimelocal">
                                This field should be a date and time.
                            </small>
                            <%_ } _%>
                        </div>
                        <%_ } _%>
                        </clr-stack-content>
                    </clr-stack-block>
                    <%_ } _%>

                    <%_ for (idx in relationships) {
                    const relationshipType = relationships[idx].relationshipType;
                    const ownerSide = relationships[idx].ownerSide;
                    const otherEntityName = relationships[idx].otherEntityName;
                    const otherEntityNamePlural = relationships[idx].otherEntityNamePlural;
                    const otherEntityNameCapitalized = relationships[idx].otherEntityNameCapitalized;
                    const relationshipName = relationships[idx].relationshipName;
                    const relationshipNameHumanized = relationships[idx].relationshipNameHumanized;
                    const relationshipFieldName = relationships[idx].relationshipFieldName;
                    const relationshipFieldNamePlural = relationships[idx].relationshipFieldNamePlural;
                    const otherEntityField = relationships[idx].otherEntityField;
                    const otherEntityFieldCapitalized = relationships[idx].otherEntityFieldCapitalized;
                    const relationshipRequired = relationships[idx].relationshipRequired;
                    const translationKey = `${i18nKeyPrefix}.${relationshipName}`; _%>
                    <%_ if (relationshipType === 'many-to-one' || (relationshipType === 'one-to-one' && ownerSide === true && otherEntityName === 'user')) { _%>
                    <clr-stack-block>
                        <clr-stack-label for="field_<%= relationshipName %>">
                            <span jhiTranslate="<%= i18nKeyPrefix %>.<%= relationshipName %>"><%= relationshipNameHumanized %></span>
                        </clr-stack-label>
                        <clr-stack-content>
                        <%_ if (dto === 'no') { _%>
                            {{<%= entityInstance %>.<%= relationshipName %> ? <%= entityInstance %>.<%= relationshipName %>.id : ''}}
                            <button type="button" class="btn btn-sm btn-link" (click)="change<%= relationships[idx].otherEntityAngularName %>()">
                                {{'entity.update.select' | translate}}
                            </button>
                        <%_ } else { _%>
                        <div class="select form-control">
                        <select class="form-control" id="field_<%= relationshipName %>" name="<%= relationshipName %>" [(ngModel)]="<%= entityInstance %>.<%=relationshipFieldName %>Id" <% if (relationshipRequired) { %> required<% } %>>
                        <%_ if (!relationshipRequired) { _%>
                        <option [ngValue]="null"></option>
                        <%_ } else { _%>
                        <option *ngIf="!editForm.value.<%= relationshipName %>" [ngValue]="null" selected></option>
                        <%_ } _%>
                        <option [ngValue]="<%=otherEntityName %>Option.id" *ngFor="let <%=otherEntityName %>Option of <%=otherEntityNamePlural.toLowerCase() %>; trackBy: track<%=otherEntityNameCapitalized %>ById">{{<%=otherEntityName %>Option.<%=otherEntityField %>}}</option>
                        </select>
                        </div>
                        <%_ } _%>
                        </clr-stack-content>
                    </clr-stack-block>
                    <%_ } else if (relationshipType === 'one-to-one' && ownerSide === true) { _%>
                    <clr-stack-block>
                        <clr-stack-label for="field_<%= relationshipName %>">
                            <span jhiTranslate="<%= i18nKeyPrefix %>.<%= relationshipName %>"><%= relationshipNameHumanized %></span>
                        </clr-stack-label>
                        <clr-stack-content>
                        <%_ if (dto === 'no') { _%>
                            {{<%= entityInstance %>.<%= relationshipName %>.id}}
                            <button type="button" class="btn btn-sm btn-link" (click)="change<%= relationships[idx].otherEntityAngularName %>()">
                                {{'entity.update.select' | translate}}
                            </button>
                        <%_ } else { _%>
                        <div class="select form-control">
                        <select class="form-control" id="field_<%= relationshipName %>" name="<%= relationshipName %>" [(ngModel)]="<%= entityInstance %>.<%=relationshipFieldName %>Id"<% if (relationshipRequired) { %> required<% } %>>
                        <%_ if (!relationshipRequired) { _%>
                        <option [ngValue]="null"></option>
                        <%_ } else { _%>
                        <option *ngIf="!editForm.value.<%= relationshipName %>" [ngValue]="null" selected></option>
                        <%_ } _%>
                        <option [ngValue]="<%=otherEntityName %>Option.id" *ngFor="let <%=otherEntityName %>Option of <%=relationshipFieldNamePlural.toLowerCase() %>; trackBy: track<%=otherEntityNameCapitalized %>ById">{{<%=otherEntityName %>Option.<%=otherEntityField %>}}</option>
                        </select>
                        </div>
                        <%_ } _%>
                        </clr-stack-content>
                    </clr-stack-block>
                    <%_ } else if (relationshipType === 'many-to-many' && relationships[idx].ownerSide === true) { _%>
                    <clr-stack-block >
                        <clr-stack-label for="field_<%= relationshipName %>">
                            <span jhiTranslate="<%= i18nKeyPrefix %>.<%= relationshipName %>"><%= relationshipNameHumanized %></span>
                        </clr-stack-label>
                        <clr-stack-content>
                            <span class="label" *ngFor="let item of (<%=entityInstance %>.<%=relationshipFieldNamePlural %> || [])">
                                {{item.id}}
                            </span>
                            <button type="button" class="btn btn-sm btn-link" (click)="change<%= relationships[idx].otherEntityAngularName %>()">
                                {{'entity.update.select' | translate}}
                            </button>
                        </clr-stack-content>
                    </clr-stack-block>
                    <%_ } _%>
                    <%_ if (relationships[idx].relationshipValidate === true) { _%>
                    <clr-stack-block [hidden]="!(editForm.controls.<%= relationshipName %>?.dirty && editForm.controls.<%= relationshipName %>?.invalid)">
                        <%_ if (relationshipRequired) { _%>
                        <small class="form-text text-danger"
                               [hidden]="!editForm.controls.<%= relationshipName %>?.errors?.required" jhiTranslate="entity.validation.required">
                            This field is required.
                        </small>
                        <%_ } _%>
                    </clr-stack-block>
                    <%_ } _%>
                    <%_ } _%>
        </clr-stack-block>
    </clr-stack-view>
    <br/>

    <button type="button" id="cancel-save" class="btn btn-outline" (click)="previousState()">
        <clr-icon shape="times"></clr-icon>&nbsp;<span jhiTranslate="entity.action.cancel">Cancel</span>
    </button>
    <button type="submit" id="save-entity" [disabled]="editForm.form.invalid || isSaving"
            class="btn btn-primary">
        <clr-icon shape="check"></clr-icon>&nbsp;<span jhiTranslate="entity.action.save">Save</span>
    </button>
</form>
