<vdr-page-block>
    <vdr-action-bar>
        <vdr-ab-left></vdr-ab-left>

        <vdr-ab-right>
            <vdr-action-bar-items locationId="stock-location-detail" />
            <button
                class="btn btn-primary"
                *ngIf="isNew$ | async; else updateButton"
                (click)="create()"
                [disabled]="detailForm.invalid || detailForm.pristine"
            >
                {{ 'common.create' | translate }}
            </button>
            <ng-template #updateButton>
                <button
                    class="btn btn-primary"
                    (click)="save()"
                    [disabled]="detailForm.invalid || detailForm.pristine"
                    *vdrIfPermissions="'UpdateStockLocation'"
                >
                    {{ 'common.update' | translate }}
                </button>
            </ng-template>
            <vdr-action-bar-dropdown-menu locationId="stock-location-detail" />
        </vdr-ab-right>
    </vdr-action-bar>
</vdr-page-block>

<form class="form" [formGroup]="detailForm">
    <vdr-page-detail-layout>
        <vdr-page-detail-sidebar>
            <vdr-card *ngIf="entity$ | async as entity">
                <vdr-page-entity-info [entity]="entity" />
            </vdr-card>
        </vdr-page-detail-sidebar>
        <vdr-page-block>
            <vdr-card>
                <div class="form-grid">
                    <vdr-form-field [label]="'common.name' | translate" for="name">
                        <input
                            id="name"
                            type="text"
                            formControlName="name"
                            [readonly]="!('UpdateStockLocation' | hasPermission)"
                        />
                    </vdr-form-field>
                    <vdr-form-field
                        class="form-grid-span"
                        [label]="'common.description' | translate"
                        for="slug"
                        [errors]="{ pattern: 'catalog.slug-pattern-error' | translate }"
                    >
                        <vdr-rich-text-editor
                            formControlName="description"
                            [readonly]="!('UpdateStockLocation' | hasPermission)"
                        ></vdr-rich-text-editor>
                    </vdr-form-field>
                </div>
            </vdr-card>
            <vdr-card
                formGroupName="customFields"
                *ngIf="customFields.length"
                [title]="'common.custom-fields' | translate"
            >
                <vdr-tabbed-custom-fields
                    entityName="StockLocation"
                    [customFields]="customFields"
                    [customFieldsFormGroup]="detailForm.get('customFields')"
                ></vdr-tabbed-custom-fields>
            </vdr-card>
            <vdr-custom-detail-component-host
                locationId="stock-location-detail"
                [entity$]="entity$"
                [detailForm]="detailForm"
            ></vdr-custom-detail-component-host>
        </vdr-page-block>
    </vdr-page-detail-layout>
</form>
