<vdr-action-bar>
    <vdr-ab-left>
        <vdr-entity-info [entity]="entity$ | async"></vdr-entity-info>
    </vdr-ab-left>

    <vdr-ab-right>
        <vdr-action-bar-items locationId="tax-category-detail"></vdr-action-bar-items>
        <button
            class="btn btn-primary"
            *ngIf="isNew$ | async; else updateButton"
            (click)="create()"
            [disabled]="!saveButtonEnabled()"
        >
            {{ 'common.create' | translate }}
        </button>
        <ng-template #updateButton>
            <button
                class="btn btn-primary"
                (click)="save()"
                [disabled]="!saveButtonEnabled()"
                *vdrIfPermissions="updatePermission"
            >
                {{ 'common.update' | translate }}
            </button>
        </ng-template>
    </vdr-ab-right>
</vdr-action-bar>

<form class="form" [formGroup]="detailForm">
    <vdr-form-field [label]="'common.name' | translate" for="name">
        <input
            id="name"
            type="text"
            formControlName="name"
            [readonly]="!(updatePermission | hasPermission)"
        />
    </vdr-form-field>
    <vdr-form-field [label]="'common.default-tax-category' | translate" for="isDefault">
        <clr-toggle-wrapper>
            <input
                type="checkbox"
                clrToggle
                id="isDefault"
                [vdrDisabled]="!(updatePermission | hasPermission)"
                formControlName="isDefault"
            />
        </clr-toggle-wrapper>
    </vdr-form-field>
    <section formGroupName="customFields" *ngIf="customFields.length">
        <label>{{ 'common.custom-fields' | translate }}</label>
        <vdr-tabbed-custom-fields
            entityName="TaxCategory"
            [customFields]="customFields"
            [customFieldsFormGroup]="detailForm.get('customFields')"
            [readonly]="!(updatePermission | hasPermission)"
        ></vdr-tabbed-custom-fields>
    </section>
    <vdr-custom-detail-component-host
        locationId="tax-category-detail"
        [entity$]="entity$"
        [detailForm]="detailForm"
    ></vdr-custom-detail-component-host>
</form>
