<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]="!saveButtonEnabled()"
        >
            {{ 'common.create' | translate }}
        </button>
        <ng-template #updateButton>
            <button class="btn btn-primary" (click)="save()" [disabled]="!saveButtonEnabled()">
                {{ '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" />
    </vdr-form-field>

    <div class="clr-row">
        <div class="clr-col" formArrayName="conditions">
            <label class="clr-control-label">{{ 'marketing.conditions' | translate }}</label>
            <ng-container *ngFor="let condition of conditions; index as i">
                <vdr-configurable-input
                    (remove)="removeCondition($event)"
                    [facets]="facets$ | async"
                    [operation]="condition"
                    [formControlName]="i"
                    [activeChannel]="activeChannel$ | async"
                ></vdr-configurable-input>
            </ng-container>

            <div>
                <vdr-dropdown>
                    <button class="btn btn-outline" vdrDropdownTrigger>
                        <clr-icon shape="plus"></clr-icon>
                        {{ 'marketing.add-condition' | translate }}
                    </button>
                    <vdr-dropdown-menu vdrPosition="bottom-left">
                        <button
                            *ngFor="let condition of getAvailableConditions()"
                            type="button"
                            vdrDropdownItem
                            (click)="addCondition(condition)"
                        >
                            {{ condition.code }}
                        </button>
                    </vdr-dropdown-menu>
                </vdr-dropdown>
            </div>
        </div>
        <div class="clr-col" formArrayName="actions">
            <label class="clr-control-label">{{ 'marketing.actions' | translate }}</label>
            <vdr-configurable-input
                *ngFor="let action of actions; index as i"
                (remove)="removeAction($event)"
                [facets]="facets$ | async"
                [operation]="action"
                [formControlName]="i"
                [activeChannel]="activeChannel$ | async"
            ></vdr-configurable-input>
            <div>
                <vdr-dropdown>
                    <button class="btn btn-outline" vdrDropdownTrigger>
                        <clr-icon shape="plus"></clr-icon>
                        {{ 'marketing.add-action' | translate }}
                    </button>
                    <vdr-dropdown-menu vdrPosition="bottom-left">
                        <button
                            *ngFor="let action of getAvailableActions()"
                            type="button"
                            vdrDropdownItem
                            (click)="addAction(action)"
                        >
                            {{ action.code }}
                        </button>
                    </vdr-dropdown-menu>
                </vdr-dropdown>
            </div>
        </div>
    </div>
</form>
