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

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

<form class="form" [formGroup]="detailForm">
    <vdr-form-field [label]="'common.code' | translate" for="code">
        <input id="code" type="text" formControlName="code" />
    </vdr-form-field>
    <vdr-form-field [label]="'common.description' | translate" for="description">
        <input id="description" type="text" formControlName="description" />
    </vdr-form-field>

    <div class="clr-row">
        <div class="clr-col">
            <label class="clr-control-label">{{ 'settings.shipping-eligibility-checker' | translate }}</label>
            <vdr-configurable-input
                *ngIf="selectedChecker"
                [operation]="selectedChecker"
                [activeChannel]="activeChannel$ | async"
                (remove)="selectedChecker = null"
                formControlName="checker"
            ></vdr-configurable-input>
            <div *ngIf="!selectedChecker">
                <vdr-dropdown>
                    <button class="btn btn-outline" vdrDropdownTrigger>
                        <clr-icon shape="plus"></clr-icon>
                        {{ 'common.select' | translate }}
                    </button>
                    <vdr-dropdown-menu vdrPosition="bottom-left">
                        <button
                            *ngFor="let checker of checkers"
                            type="button"
                            vdrDropdownItem
                            (click)="selectedChecker = checker"
                        >
                            {{ checker.description }}
                        </button>
                    </vdr-dropdown-menu>
                </vdr-dropdown>
            </div>
        </div>
        <div class="clr-col">
            <label class="clr-control-label">{{ 'settings.shipping-calculator' | translate }}</label>
            <vdr-configurable-input
                *ngIf="selectedCalculator"
                [operation]="selectedCalculator"
                [activeChannel]="activeChannel$ | async"
                (remove)="selectedCalculator = null"
                formControlName="calculator"
            ></vdr-configurable-input>
            <div *ngIf="!selectedCalculator">
                <vdr-dropdown>
                    <button class="btn btn-outline" vdrDropdownTrigger>
                        <clr-icon shape="plus"></clr-icon>
                        {{ 'common.select' | translate }}
                    </button>
                    <vdr-dropdown-menu vdrPosition="bottom-left">
                        <button
                            *ngFor="let calculator of calculators"
                            type="button"
                            vdrDropdownItem
                            (click)="selectedCalculator = calculator"
                        >
                            {{ calculator.description }}
                        </button>
                    </vdr-dropdown-menu>
                </vdr-dropdown>
            </div>
        </div>
    </div>
</form>
