<%#
 Copyright 2013-2019 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed 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 class="row justify-content-center">
    <div class="col-8">
        <div *ngIf="<%= entityInstance %>">
            <h2><span jhiTranslate="<%= i18nKeyPrefix %>.detail.title"><%= entityClassHumanized %></span> {{<%= entityInstance %>.id}}</h2>
            <hr>
            <<%= jhiPrefixDashed %>-alert-error></<%= jhiPrefixDashed %>-alert-error>
            <dl class="row-md jh-entity-details">
                <%_ for (idx in fields) {
                const fieldName = fields[idx].fieldName;
                const fieldType = fields[idx].fieldType;
                const fieldTypeBlobContent = fields[idx].fieldTypeBlobContent; _%>
                <dt><span jhiTranslate="<%= i18nKeyPrefix %>.<%= fieldName %>"<% if (fields[idx].javadoc) { if (enableTranslation) { %> [ngbTooltip]="'<%= i18nKeyPrefix %>.help.<%= fieldName %>' | translate"<% } else { %> ngbTooltip="<%= fields[idx].javadoc %>"<% } } %>><%= fields[idx].fieldNameHumanized %></span></dt>
                <dd>
                    <%_ if (fields[idx].fieldIsEnum) { _%>
                    <span jhiTranslate="{{'<%= angularAppName %>.<%= fieldType %>.' + <%= entityInstance %>.<%= fieldName %>}}">{{<%= entityInstance %>.<%= fieldName %>}}</span>
                    <%_ } else if (['byte[]', 'ByteBuffer'].includes(fieldType) && fieldTypeBlobContent === 'image') { _%>
                    <div *ngIf="<%= entityInstance %>.<%= fieldName %>">
                        <a (click)="openFile(<%= entityInstance %>.<%= fieldName %>ContentType, <%= entityInstance %>.<%= fieldName %>)">
                            <img [src]="'data:' + <%=entityInstance %>.<%= fieldName %>ContentType + ';base64,' + <%= entityInstance %>.<%= fieldName %>" style="max-width: 100%;" alt="<%=entityInstance %> image"/>
                        </a>
                        {{<%= entityInstance %>.<%= fieldName %>ContentType}}, {{byteSize(<%= entityInstance %>.<%= fieldName %>)}}
                    </div>
                    <%_ } else if (['byte[]', 'ByteBuffer'].includes(fieldType) && fieldTypeBlobContent === 'any') { _%>
                    <div *ngIf="<%= entityInstance %>.<%= fieldName %>">
                        <a (click)="openFile(<%= entityInstance %>.<%= fieldName %>ContentType, <%= entityInstance %>.<%= fieldName %>)" jhiTranslate="entity.action.open">open</a>
                        {{<%= entityInstance %>.<%= fieldName %>ContentType}}, {{byteSize(<%= entityInstance %>.<%= fieldName %>)}}
                    </div>
                    <%_ } else { _%>
                    <span>{{<%= entityInstance %>.<%= fieldName %>}}</span>
                    <%_ } _%>
                </dd>
                <%_ } _%>
                <%_ for (idx in relationships) {
                const relationshipType = relationships[idx].relationshipType;
                const ownerSide = relationships[idx].ownerSide;
                const relationshipName = relationships[idx].relationshipName;
                const relationshipFieldName = relationships[idx].relationshipFieldName;
                const relationshipFieldNamePlural = relationships[idx].relationshipFieldNamePlural;
                const relationshipNameHumanized = relationships[idx].relationshipNameHumanized;
                const otherEntityName = relationships[idx].otherEntityName;
                const otherEntityStateName = relationships[idx].otherEntityStateName;
                const otherEntityField = relationships[idx].otherEntityField;
                const otherEntityFieldCapitalized = relationships[idx].otherEntityFieldCapitalized;
                if (relationshipType === 'many-to-one'
                || (relationshipType === 'one-to-one' && ownerSide === true)
                || (relationshipType === 'many-to-many' && ownerSide === true)) { _%>
                <dt><span jhiTranslate="<%= i18nKeyPrefix %>.<%= relationshipName %>"><%= relationshipNameHumanized %></span></dt>
                <dd>
                    <%_ if (otherEntityName === 'user') { _%>
                    <%_ if (relationshipType === 'many-to-many') { _%>
                    <span *ngFor="let <%= relationshipFieldName %> of <%= entityInstance %>.<%= relationshipFieldNamePlural %>; let last = last">
                        {{<%= relationshipFieldName %>.<%= otherEntityField %>}}{{last ? '' : ', '}}
                    </span>
                    <%_ } else { _%>
                    <%_ if (dto === 'no') { _%>
                    {{<%= entityInstance + "." + relationshipFieldName + "?." + otherEntityField %>}}
                    <%_ } else { _%>
                    {{<%= entityInstance + "." + relationshipFieldName + otherEntityFieldCapitalized %>}}
                    <%_ } _%>
                    <%_ } _%>
                    <%_ } else { _%>
                    <%_ if (relationshipType === 'many-to-many') { _%>
                    <span *ngFor="let <%= relationshipFieldName %> of <%= entityInstance %>.<%= relationshipFieldNamePlural %>; let last = last">
                        <a [routerLink]="['/<%= otherEntityStateName %>', <%= relationshipFieldName %>?.id, 'view' ]">{{<%= relationshipFieldName %>.<%= otherEntityField %>}}</a>{{last ? '' : ', '}}
                    </span>
                    <%_ } else { _%>
                    <%_ if (dto === 'no') { _%>
                    <div *ngIf="<%= entityInstance + '.' + relationshipFieldName %>">
                        <a [routerLink]="['/<%= otherEntityStateName %>', <%= entityInstance + '.' + relationshipFieldName + '?.id' %>, 'view']">{{<%= entityInstance + "." + relationshipFieldName + "?." + otherEntityField %>}}</a>
                    </div>
                    <%_ } else { _%>
                    <div *ngIf="<%= entityInstance + '.' + relationshipFieldName + "Id" %>">
                        <a [routerLink]="['/<%= otherEntityStateName %>', <%= entityInstance + '.' + relationshipFieldName + "Id" %>, 'view']">{{<%= entityInstance + "." + relationshipFieldName + otherEntityFieldCapitalized %>}}</a>
                    </div>
                    <%_ } _%>
                    <%_ } _%>
                    <%_ } _%>
                </dd>
                <%_ } _%>
                <%_ } _%>
            </dl>

            <button type="submit"
                    (click)="previousState()"
                    class="btn btn-info">
                <fa-icon [icon]="'arrow-left'"></fa-icon>&nbsp;<span jhiTranslate="entity.action.back"> Back</span>
            </button>

            <button type="button"
                    [routerLink]="['/<%= entityUrl %>', <%= entityInstance %>.id, 'edit']"
                    class="btn btn-primary">
                <fa-icon [icon]="'pencil-alt'"></fa-icon>&nbsp;<span jhiTranslate="entity.action.edit"> Edit</span>
            </button>
        </div>
    </div>
</div>
