import * as i0 from '@angular/core';
import { Component, ChangeDetectionStrategy, NgModule } from '@angular/core';
import * as i2 from '@angular/forms';
import { Validators } from '@angular/forms';
import { marker } from '@biesbjerg/ngx-translate-extract-marker';
import * as i1 from '@vendure/admin-ui/core';
import { PROMOTION_FRAGMENT, TypedBaseDetailComponent, getCustomFieldsDefaults, createUpdatedTranslatable, findTranslation, encodeConfigArgValue, getConfigArgValue, getDefaultConfigArgValue, createBulkDeleteAction, Permission, createBulkAssignToChannelAction, AssignPromotionsToChannelDocument, createBulkRemoveFromChannelAction, RemovePromotionsFromChannelDocument, TypedBaseListComponent, GetPromotionListDocument, LogicalOperator, PageComponent, detailBreadcrumb, detailComponentWithResolver, GetPromotionDetailDocument, SharedModule, PageService } from '@vendure/admin-ui/core';
import { gql } from 'apollo-angular';
import { combineLatest } from 'rxjs';
import { take, mergeMap, map } from 'rxjs/operators';
import * as i3 from '@clr/angular';
import * as i4 from '@angular/common';
import { AsyncPipe } from '@angular/common';
import * as i5 from '@ngx-translate/core';
import * as i3$1 from '@angular/router';
import { ROUTES, RouterModule } from '@angular/router';

const GET_PROMOTION_DETAIL = gql `
    query GetPromotionDetail($id: ID!) {
        promotion(id: $id) {
            ...Promotion
        }
    }
    ${PROMOTION_FRAGMENT}
`;
class PromotionDetailComponent extends TypedBaseDetailComponent {
    constructor(changeDetector, dataService, formBuilder, notificationService) {
        super();
        this.changeDetector = changeDetector;
        this.dataService = dataService;
        this.formBuilder = formBuilder;
        this.notificationService = notificationService;
        this.customFields = this.getCustomFieldConfig('Promotion');
        this.detailForm = this.formBuilder.group({
            name: ['', Validators.required],
            description: '',
            enabled: true,
            couponCode: null,
            perCustomerUsageLimit: null,
            usageLimit: null,
            startsAt: null,
            endsAt: null,
            conditions: this.formBuilder.array([]),
            actions: this.formBuilder.array([]),
            customFields: this.formBuilder.group(getCustomFieldsDefaults(this.customFields)),
        });
        this.conditions = [];
        this.actions = [];
        this.allConditions = [];
        this.allActions = [];
        this.customFields = this.getCustomFieldConfig('Promotion');
    }
    ngOnInit() {
        this.init();
        this.dataService.promotion.getPromotionActionsAndConditions().single$.subscribe(data => {
            this.allActions = data.promotionActions;
            this.allConditions = data.promotionConditions;
            this.changeDetector.markForCheck();
        });
    }
    ngOnDestroy() {
        this.destroy();
    }
    getAvailableConditions() {
        return this.allConditions.filter(o => !this.conditions.find(c => c.code === o.code));
    }
    getConditionDefinition(condition) {
        return this.allConditions.find(c => c.code === condition.code);
    }
    getAvailableActions() {
        return this.allActions.filter(o => !this.actions.find(a => a.code === o.code));
    }
    getActionDefinition(action) {
        return this.allActions.find(c => c.code === action.code);
    }
    saveButtonEnabled() {
        return !!(this.detailForm.dirty &&
            this.detailForm.valid &&
            (this.conditions.length !== 0 || this.detailForm.value.couponCode) &&
            this.actions.length !== 0);
    }
    addCondition(condition) {
        this.addOperation('conditions', condition);
        this.detailForm.markAsDirty();
    }
    addAction(action) {
        this.addOperation('actions', action);
        this.detailForm.markAsDirty();
    }
    removeCondition(condition) {
        this.removeOperation('conditions', condition);
        this.detailForm.markAsDirty();
    }
    removeAction(action) {
        this.removeOperation('actions', action);
        this.detailForm.markAsDirty();
    }
    formArrayOf(key) {
        return this.detailForm.get(key);
    }
    create() {
        if (!this.detailForm.dirty) {
            return;
        }
        const input = this.getUpdatedPromotion({
            id: '',
            createdAt: '',
            updatedAt: '',
            startsAt: '',
            endsAt: '',
            name: '',
            description: '',
            couponCode: null,
            perCustomerUsageLimit: null,
            usageLimit: null,
            enabled: false,
            conditions: [],
            actions: [],
            translations: [],
        }, this.detailForm, this.languageCode);
        this.dataService.promotion.createPromotion(input).subscribe(({ createPromotion }) => {
            switch (createPromotion.__typename) {
                case 'Promotion':
                    this.notificationService.success(marker('common.notify-create-success'), {
                        entity: 'Promotion',
                    });
                    this.detailForm.markAsPristine();
                    this.changeDetector.markForCheck();
                    this.router.navigate(['../', createPromotion.id], { relativeTo: this.route });
                    break;
                case 'MissingConditionsError':
                    this.notificationService.error(createPromotion.message);
                    break;
            }
        }, err => {
            this.notificationService.error(marker('common.notify-create-error'), {
                entity: 'Promotion',
            });
        });
    }
    save() {
        if (!this.detailForm.dirty) {
            return;
        }
        combineLatest(this.entity$, this.languageCode$)
            .pipe(take(1), mergeMap(([paymentMethod, languageCode]) => {
            const input = this.getUpdatedPromotion(paymentMethod, this.detailForm, languageCode);
            return this.dataService.promotion.updatePromotion(input);
        }))
            .subscribe(data => {
            this.notificationService.success(marker('common.notify-update-success'), {
                entity: 'Promotion',
            });
            this.detailForm.markAsPristine();
            this.changeDetector.markForCheck();
        }, err => {
            this.notificationService.error(marker('common.notify-update-error'), {
                entity: 'Promotion',
            });
        });
    }
    /**
     * Given a PaymentMethod and the value of the detailForm, this method creates an updated copy of it which
     * can then be persisted to the API.
     */
    getUpdatedPromotion(promotion, formGroup, languageCode) {
        const formValue = formGroup.value;
        const input = createUpdatedTranslatable({
            translatable: promotion,
            updatedFields: formValue,
            customFieldConfig: this.customFields,
            languageCode,
            defaultTranslation: {
                languageCode,
                name: promotion.name || '',
                description: promotion.description || '',
            },
        });
        return {
            ...input,
            conditions: this.mapOperationsToInputs(this.conditions, formValue.conditions),
            actions: this.mapOperationsToInputs(this.actions, formValue.actions),
        };
    }
    /**
     * Update the form values when the entity changes.
     */
    setFormValues(entity, languageCode) {
        const currentTranslation = findTranslation(entity, languageCode);
        this.detailForm.patchValue({
            name: currentTranslation?.name,
            description: currentTranslation?.description,
            enabled: entity.enabled,
            couponCode: entity.couponCode,
            perCustomerUsageLimit: entity.perCustomerUsageLimit,
            usageLimit: entity.usageLimit,
            startsAt: entity.startsAt,
            endsAt: entity.endsAt,
        });
        entity.conditions.forEach(o => {
            this.addOperation('conditions', o);
        });
        entity.actions.forEach(o => this.addOperation('actions', o));
        if (this.customFields.length) {
            this.setCustomFieldFormValues(this.customFields, this.detailForm.get('customFields'), entity, currentTranslation);
        }
    }
    /**
     * Maps an array of conditions or actions to the input format expected by the GraphQL API.
     */
    mapOperationsToInputs(operations, formValueOperations) {
        return operations.map((o, i) => ({
            code: o.code,
            arguments: Object.values(formValueOperations[i].args).map((value, j) => ({
                name: o.args[j].name,
                value: encodeConfigArgValue(value),
            })),
        }));
    }
    /**
     * Adds a new condition or action to the promotion.
     */
    addOperation(key, operation) {
        const operationsArray = this.formArrayOf(key);
        const collection = key === 'conditions' ? this.conditions : this.actions;
        const index = operationsArray.value.findIndex(o => o.code === operation.code);
        if (index === -1) {
            const argsHash = operation.args.reduce((output, arg) => ({
                ...output,
                [arg.name]: getConfigArgValue(arg.value) ?? this.getDefaultArgValue(key, operation, arg.name),
            }), {});
            operationsArray.push(this.formBuilder.control({
                code: operation.code,
                args: argsHash,
            }));
            collection.push({
                code: operation.code,
                args: operation.args.map(a => ({ name: a.name, value: getConfigArgValue(a.value) })),
            });
        }
    }
    getDefaultArgValue(key, operation, argName) {
        const def = key === 'conditions'
            ? this.allConditions.find(c => c.code === operation.code)
            : this.allActions.find(a => a.code === operation.code);
        if (def) {
            const argDef = def.args.find(a => a.name === argName);
            if (argDef) {
                return getDefaultConfigArgValue(argDef);
            }
        }
        throw new Error(`Could not determine default value for "argName"`);
    }
    /**
     * Removes a condition or action from the promotion.
     */
    removeOperation(key, operation) {
        const operationsArray = this.formArrayOf(key);
        const collection = key === 'conditions' ? this.conditions : this.actions;
        const index = operationsArray.value.findIndex(o => o.code === operation.code);
        if (index !== -1) {
            operationsArray.removeAt(index);
            collection.splice(index, 1);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: PromotionDetailComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i1.DataService }, { token: i2.FormBuilder }, { token: i1.NotificationService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.2", type: PromotionDetailComponent, selector: "vdr-promotion-detail", usesInheritance: true, ngImport: i0, template: "<vdr-page-block>\n    <vdr-action-bar>\n        <vdr-ab-left>\n            <div class=\"flex clr-align-items-center\">\n                <vdr-language-selector\n                    [disabled]=\"isNew$ | async\"\n                    [availableLanguageCodes]=\"availableLanguages$ | async\"\n                    [currentLanguageCode]=\"languageCode$ | async\"\n                    (languageCodeChange)=\"setLanguage($event)\"\n                ></vdr-language-selector>\n            </div>\n        </vdr-ab-left>\n\n        <vdr-ab-right>\n            <vdr-action-bar-items locationId=\"promotion-detail\"></vdr-action-bar-items>\n            <button\n                class=\"btn btn-primary\"\n                *ngIf=\"isNew$ | async; else updateButton\"\n                (click)=\"create()\"\n                [disabled]=\"!saveButtonEnabled()\"\n            >\n                {{ 'common.create' | translate }}\n            </button>\n            <ng-template #updateButton>\n                <button\n                    class=\"btn btn-primary\"\n                    (click)=\"save()\"\n                    *vdrIfPermissions=\"'UpdatePromotion'\"\n                    [disabled]=\"!saveButtonEnabled()\"\n                >\n                    {{ 'common.update' | translate }}\n                </button>\n            </ng-template>\n        </vdr-ab-right>\n    </vdr-action-bar>\n</vdr-page-block>\n\n<form class=\"form\" [formGroup]=\"detailForm\">\n    <vdr-page-detail-layout>\n        <vdr-page-detail-sidebar>\n            <vdr-card *vdrIfPermissions=\"'UpdatePromotion'\">\n                <clr-toggle-wrapper>\n                    <input type=\"checkbox\" clrToggle name=\"enabled\" formControlName=\"enabled\" />\n                    <label>{{ 'common.enabled' | translate }}</label>\n                </clr-toggle-wrapper>\n            </vdr-card>\n            <vdr-card *ngIf=\"entity$ | async as entity\">\n                <vdr-page-entity-info [entity]=\"entity\" />\n            </vdr-card>\n        </vdr-page-detail-sidebar>\n        <vdr-page-block>\n            <vdr-card>\n                <div class=\"form-grid\">\n                    <vdr-form-field [label]=\"'common.name' | translate\" for=\"name\">\n                        <input\n                            id=\"name\"\n                            [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                            type=\"text\"\n                            formControlName=\"name\"\n                        />\n                    </vdr-form-field>\n                    <vdr-rich-text-editor\n                        class=\"form-grid-span\"\n                        formControlName=\"description\"\n                        [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                        [label]=\"'common.description' | translate\"\n                    ></vdr-rich-text-editor>\n                    <vdr-form-field [label]=\"'marketing.starts-at' | translate\" for=\"startsAt\">\n                        <vdr-datetime-picker formControlName=\"startsAt\"></vdr-datetime-picker>\n                    </vdr-form-field>\n                    <vdr-form-field [label]=\"'marketing.ends-at' | translate\" for=\"endsAt\">\n                        <vdr-datetime-picker formControlName=\"endsAt\"></vdr-datetime-picker>\n                    </vdr-form-field>\n                    <vdr-form-field [label]=\"'marketing.coupon-code' | translate\" for=\"couponCode\">\n                        <input\n                            id=\"couponCode\"\n                            [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                            type=\"text\"\n                            formControlName=\"couponCode\"\n                        />\n                    </vdr-form-field>\n                    <vdr-form-field\n                        [label]=\"'marketing.per-customer-limit' | translate\"\n                        [tooltip]=\"'marketing.per-customer-limit-tooltip' | translate\"\n                        for=\"perCustomerUsageLimit\"\n                    >\n                        <input\n                            id=\"perCustomerUsageLimit\"\n                            [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                            type=\"number\"\n                            min=\"1\"\n                            max=\"999\"\n                            formControlName=\"perCustomerUsageLimit\"\n                        />\n                    </vdr-form-field>\n                    <vdr-form-field\n                        [label]=\"'marketing.usage-limit' | translate\"\n                        [tooltip]=\"'marketing.usage-limit-tooltip' | translate\"\n                        for=\"usageLimit\"\n                    >\n                        <input\n                            id=\"usageLimit\"\n                            [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                            type=\"number\"\n                            min=\"1\"\n                            max=\"9999999\"\n                            formControlName=\"usageLimit\"\n                        />\n                    </vdr-form-field>\n                </div>\n            </vdr-card>\n            <vdr-card\n                [title]=\"'common.custom-fields' | translate\"\n                formGroupName=\"customFields\"\n                *ngIf=\"customFields.length\"\n            >\n                <vdr-tabbed-custom-fields\n                    entityName=\"Promotion\"\n                    [customFields]=\"customFields\"\n                    [customFieldsFormGroup]=\"detailForm.get('customFields')\"\n                    [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                ></vdr-tabbed-custom-fields>\n            </vdr-card>\n\n            <vdr-custom-detail-component-host\n                locationId=\"promotion-detail\"\n                [entity$]=\"entity$\"\n                [detailForm]=\"detailForm\"\n            ></vdr-custom-detail-component-host>\n\n            <vdr-card [title]=\"'marketing.conditions' | translate\" formArrayName=\"conditions\">\n                <div *ngFor=\"let condition of conditions; index as i\">\n                    <vdr-configurable-input\n                        (remove)=\"removeCondition($event)\"\n                        [position]=\"i\"\n                        [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                        [operation]=\"condition\"\n                        [operationDefinition]=\"getConditionDefinition(condition)\"\n                        [formControlName]=\"i\"\n                    ></vdr-configurable-input>\n                </div>\n                <div>\n                    <vdr-dropdown *vdrIfPermissions=\"'UpdatePromotion'\">\n                        <button class=\"btn btn-outline\" vdrDropdownTrigger>\n                            <clr-icon shape=\"plus\"></clr-icon>\n                            {{ 'marketing.add-condition' | translate }}\n                        </button>\n                        <vdr-dropdown-menu vdrPosition=\"bottom-left\">\n                            <button\n                                *ngFor=\"let condition of getAvailableConditions()\"\n                                type=\"button\"\n                                vdrDropdownItem\n                                class=\"item-wrap\"\n                                (click)=\"addCondition(condition)\"\n                            >\n                                {{ condition.description }}\n                            </button>\n                        </vdr-dropdown-menu>\n                    </vdr-dropdown>\n                </div>\n            </vdr-card>\n            <vdr-card [title]=\"'marketing.actions' | translate\" formArrayName=\"actions\">\n                <div *ngFor=\"let action of actions; index as i\">\n                    <vdr-configurable-input\n                        (remove)=\"removeAction($event)\"\n                        [position]=\"i\"\n                        [operation]=\"action\"\n                        [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                        [operationDefinition]=\"getActionDefinition(action)\"\n                        [formControlName]=\"i\"\n                    ></vdr-configurable-input>\n                </div>\n                <div>\n                    <vdr-dropdown *vdrIfPermissions=\"'UpdatePromotion'\">\n                        <button class=\"btn btn-outline\" vdrDropdownTrigger>\n                            <clr-icon shape=\"plus\"></clr-icon>\n                            {{ 'marketing.add-action' | translate }}\n                        </button>\n                        <vdr-dropdown-menu vdrPosition=\"bottom-left\">\n                            <button\n                                *ngFor=\"let action of getAvailableActions()\"\n                                type=\"button\"\n                                vdrDropdownItem\n                                class=\"item-wrap\"\n                                (click)=\"addAction(action)\"\n                            >\n                                {{ action.description }}\n                            </button>\n                        </vdr-dropdown-menu>\n                    </vdr-dropdown>\n                </div>\n            </vdr-card>\n        </vdr-page-block>\n    </vdr-page-detail-layout>\n</form>\n", styles: [".item-wrap{white-space:normal}\n"], dependencies: [{ kind: "directive", type: i3.ClrIconCustomTag, selector: "clr-icon" }, { kind: "directive", type: i3.ClrLabel, selector: "label", inputs: ["for"] }, { kind: "directive", type: i3.ClrCheckbox, selector: "[clrCheckbox],[clrToggle]" }, { kind: "component", type: i3.ClrCheckboxWrapper, selector: "clr-checkbox-wrapper,clr-toggle-wrapper" }, { kind: "directive", type: i4.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i2.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i2.MinValidator, selector: "input[type=number][min][formControlName],input[type=number][min][formControl],input[type=number][min][ngModel]", inputs: ["min"] }, { kind: "directive", type: i2.MaxValidator, selector: "input[type=number][max][formControlName],input[type=number][max][formControl],input[type=number][max][ngModel]", inputs: ["max"] }, { kind: "directive", type: i2.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i2.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "directive", type: i2.FormGroupName, selector: "[formGroupName]", inputs: ["formGroupName"] }, { kind: "directive", type: i2.FormArrayName, selector: "[formArrayName]", inputs: ["formArrayName"] }, { kind: "component", type: i1.ActionBarComponent, selector: "vdr-action-bar" }, { kind: "component", type: i1.ActionBarLeftComponent, selector: "vdr-ab-left", inputs: ["grow"] }, { kind: "component", type: i1.ActionBarRightComponent, selector: "vdr-ab-right", inputs: ["grow"] }, { kind: "component", type: i1.ConfigurableInputComponent, selector: "vdr-configurable-input", inputs: ["operation", "operationDefinition", "readonly", "removable", "position"], outputs: ["remove"] }, { kind: "component", type: i1.FormFieldComponent, selector: "vdr-form-field", inputs: ["label", "for", "tooltip", "errors", "readOnlyToggle"] }, { kind: "directive", type: i1.FormFieldControlDirective, selector: "input, textarea, select" }, { kind: "component", type: i1.LanguageSelectorComponent, selector: "vdr-language-selector", inputs: ["currentLanguageCode", "availableLanguageCodes", "disabled"], outputs: ["languageCodeChange"] }, { kind: "component", type: i1.RichTextEditorComponent, selector: "vdr-rich-text-editor", inputs: ["label", "readonly"] }, { kind: "component", type: i1.DropdownComponent, selector: "vdr-dropdown", inputs: ["manualToggle"] }, { kind: "component", type: i1.DropdownMenuComponent, selector: "vdr-dropdown-menu", inputs: ["vdrPosition", "customClasses"] }, { kind: "directive", type: i1.DropdownTriggerDirective, selector: "[vdrDropdownTrigger]" }, { kind: "directive", type: i1.DropdownItemDirective, selector: "[vdrDropdownItem]" }, { kind: "directive", type: i1.IfPermissionsDirective, selector: "[vdrIfPermissions]", inputs: ["vdrIfPermissions", "vdrIfPermissionsElse"] }, { kind: "component", type: i1.ActionBarItemsComponent, selector: "vdr-action-bar-items", inputs: ["locationId"] }, { kind: "component", type: i1.DatetimePickerComponent, selector: "vdr-datetime-picker", inputs: ["yearRange", "weekStartDay", "timeGranularityInterval", "min", "max", "readonly"] }, { kind: "component", type: i1.TabbedCustomFieldsComponent, selector: "vdr-tabbed-custom-fields", inputs: ["entityName", "customFields", "customFieldsFormGroup", "readonly", "compact", "showLabel"] }, { kind: "component", type: i1.CustomDetailComponentHostComponent, selector: "vdr-custom-detail-component-host", inputs: ["locationId", "entity$", "detailForm"] }, { kind: "component", type: i1.PageBlockComponent, selector: "vdr-page-block" }, { kind: "component", type: i1.PageEntityInfoComponent, selector: "vdr-page-entity-info", inputs: ["entity"] }, { kind: "component", type: i1.PageDetailLayoutComponent, selector: "vdr-page-detail-layout" }, { kind: "component", type: i1.PageDetailSidebarComponent, selector: "vdr-page-detail-sidebar" }, { kind: "component", type: i1.CardComponent, selector: "vdr-card", inputs: ["title", "paddingX"] }, { kind: "pipe", type: i4.AsyncPipe, name: "async" }, { kind: "pipe", type: i5.TranslatePipe, name: "translate" }, { kind: "pipe", type: i1.HasPermissionPipe, name: "hasPermission" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: PromotionDetailComponent, decorators: [{
            type: Component,
            args: [{ selector: 'vdr-promotion-detail', changeDetection: ChangeDetectionStrategy.OnPush, template: "<vdr-page-block>\n    <vdr-action-bar>\n        <vdr-ab-left>\n            <div class=\"flex clr-align-items-center\">\n                <vdr-language-selector\n                    [disabled]=\"isNew$ | async\"\n                    [availableLanguageCodes]=\"availableLanguages$ | async\"\n                    [currentLanguageCode]=\"languageCode$ | async\"\n                    (languageCodeChange)=\"setLanguage($event)\"\n                ></vdr-language-selector>\n            </div>\n        </vdr-ab-left>\n\n        <vdr-ab-right>\n            <vdr-action-bar-items locationId=\"promotion-detail\"></vdr-action-bar-items>\n            <button\n                class=\"btn btn-primary\"\n                *ngIf=\"isNew$ | async; else updateButton\"\n                (click)=\"create()\"\n                [disabled]=\"!saveButtonEnabled()\"\n            >\n                {{ 'common.create' | translate }}\n            </button>\n            <ng-template #updateButton>\n                <button\n                    class=\"btn btn-primary\"\n                    (click)=\"save()\"\n                    *vdrIfPermissions=\"'UpdatePromotion'\"\n                    [disabled]=\"!saveButtonEnabled()\"\n                >\n                    {{ 'common.update' | translate }}\n                </button>\n            </ng-template>\n        </vdr-ab-right>\n    </vdr-action-bar>\n</vdr-page-block>\n\n<form class=\"form\" [formGroup]=\"detailForm\">\n    <vdr-page-detail-layout>\n        <vdr-page-detail-sidebar>\n            <vdr-card *vdrIfPermissions=\"'UpdatePromotion'\">\n                <clr-toggle-wrapper>\n                    <input type=\"checkbox\" clrToggle name=\"enabled\" formControlName=\"enabled\" />\n                    <label>{{ 'common.enabled' | translate }}</label>\n                </clr-toggle-wrapper>\n            </vdr-card>\n            <vdr-card *ngIf=\"entity$ | async as entity\">\n                <vdr-page-entity-info [entity]=\"entity\" />\n            </vdr-card>\n        </vdr-page-detail-sidebar>\n        <vdr-page-block>\n            <vdr-card>\n                <div class=\"form-grid\">\n                    <vdr-form-field [label]=\"'common.name' | translate\" for=\"name\">\n                        <input\n                            id=\"name\"\n                            [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                            type=\"text\"\n                            formControlName=\"name\"\n                        />\n                    </vdr-form-field>\n                    <vdr-rich-text-editor\n                        class=\"form-grid-span\"\n                        formControlName=\"description\"\n                        [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                        [label]=\"'common.description' | translate\"\n                    ></vdr-rich-text-editor>\n                    <vdr-form-field [label]=\"'marketing.starts-at' | translate\" for=\"startsAt\">\n                        <vdr-datetime-picker formControlName=\"startsAt\"></vdr-datetime-picker>\n                    </vdr-form-field>\n                    <vdr-form-field [label]=\"'marketing.ends-at' | translate\" for=\"endsAt\">\n                        <vdr-datetime-picker formControlName=\"endsAt\"></vdr-datetime-picker>\n                    </vdr-form-field>\n                    <vdr-form-field [label]=\"'marketing.coupon-code' | translate\" for=\"couponCode\">\n                        <input\n                            id=\"couponCode\"\n                            [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                            type=\"text\"\n                            formControlName=\"couponCode\"\n                        />\n                    </vdr-form-field>\n                    <vdr-form-field\n                        [label]=\"'marketing.per-customer-limit' | translate\"\n                        [tooltip]=\"'marketing.per-customer-limit-tooltip' | translate\"\n                        for=\"perCustomerUsageLimit\"\n                    >\n                        <input\n                            id=\"perCustomerUsageLimit\"\n                            [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                            type=\"number\"\n                            min=\"1\"\n                            max=\"999\"\n                            formControlName=\"perCustomerUsageLimit\"\n                        />\n                    </vdr-form-field>\n                    <vdr-form-field\n                        [label]=\"'marketing.usage-limit' | translate\"\n                        [tooltip]=\"'marketing.usage-limit-tooltip' | translate\"\n                        for=\"usageLimit\"\n                    >\n                        <input\n                            id=\"usageLimit\"\n                            [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                            type=\"number\"\n                            min=\"1\"\n                            max=\"9999999\"\n                            formControlName=\"usageLimit\"\n                        />\n                    </vdr-form-field>\n                </div>\n            </vdr-card>\n            <vdr-card\n                [title]=\"'common.custom-fields' | translate\"\n                formGroupName=\"customFields\"\n                *ngIf=\"customFields.length\"\n            >\n                <vdr-tabbed-custom-fields\n                    entityName=\"Promotion\"\n                    [customFields]=\"customFields\"\n                    [customFieldsFormGroup]=\"detailForm.get('customFields')\"\n                    [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                ></vdr-tabbed-custom-fields>\n            </vdr-card>\n\n            <vdr-custom-detail-component-host\n                locationId=\"promotion-detail\"\n                [entity$]=\"entity$\"\n                [detailForm]=\"detailForm\"\n            ></vdr-custom-detail-component-host>\n\n            <vdr-card [title]=\"'marketing.conditions' | translate\" formArrayName=\"conditions\">\n                <div *ngFor=\"let condition of conditions; index as i\">\n                    <vdr-configurable-input\n                        (remove)=\"removeCondition($event)\"\n                        [position]=\"i\"\n                        [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                        [operation]=\"condition\"\n                        [operationDefinition]=\"getConditionDefinition(condition)\"\n                        [formControlName]=\"i\"\n                    ></vdr-configurable-input>\n                </div>\n                <div>\n                    <vdr-dropdown *vdrIfPermissions=\"'UpdatePromotion'\">\n                        <button class=\"btn btn-outline\" vdrDropdownTrigger>\n                            <clr-icon shape=\"plus\"></clr-icon>\n                            {{ 'marketing.add-condition' | translate }}\n                        </button>\n                        <vdr-dropdown-menu vdrPosition=\"bottom-left\">\n                            <button\n                                *ngFor=\"let condition of getAvailableConditions()\"\n                                type=\"button\"\n                                vdrDropdownItem\n                                class=\"item-wrap\"\n                                (click)=\"addCondition(condition)\"\n                            >\n                                {{ condition.description }}\n                            </button>\n                        </vdr-dropdown-menu>\n                    </vdr-dropdown>\n                </div>\n            </vdr-card>\n            <vdr-card [title]=\"'marketing.actions' | translate\" formArrayName=\"actions\">\n                <div *ngFor=\"let action of actions; index as i\">\n                    <vdr-configurable-input\n                        (remove)=\"removeAction($event)\"\n                        [position]=\"i\"\n                        [operation]=\"action\"\n                        [readonly]=\"!('UpdatePromotion' | hasPermission)\"\n                        [operationDefinition]=\"getActionDefinition(action)\"\n                        [formControlName]=\"i\"\n                    ></vdr-configurable-input>\n                </div>\n                <div>\n                    <vdr-dropdown *vdrIfPermissions=\"'UpdatePromotion'\">\n                        <button class=\"btn btn-outline\" vdrDropdownTrigger>\n                            <clr-icon shape=\"plus\"></clr-icon>\n                            {{ 'marketing.add-action' | translate }}\n                        </button>\n                        <vdr-dropdown-menu vdrPosition=\"bottom-left\">\n                            <button\n                                *ngFor=\"let action of getAvailableActions()\"\n                                type=\"button\"\n                                vdrDropdownItem\n                                class=\"item-wrap\"\n                                (click)=\"addAction(action)\"\n                            >\n                                {{ action.description }}\n                            </button>\n                        </vdr-dropdown-menu>\n                    </vdr-dropdown>\n                </div>\n            </vdr-card>\n        </vdr-page-block>\n    </vdr-page-detail-layout>\n</form>\n", styles: [".item-wrap{white-space:normal}\n"] }]
        }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i1.DataService }, { type: i2.FormBuilder }, { type: i1.NotificationService }]; } });

const ASSIGN_PROMOTIONS_TO_CHANNEL = gql `
    mutation AssignPromotionsToChannel($input: AssignPromotionsToChannelInput!) {
        assignPromotionsToChannel(input: $input) {
            id
            name
        }
    }
`;
const REMOVE_PROMOTIONS_FROM_CHANNEL = gql `
    mutation RemovePromotionsFromChannel($input: RemovePromotionsFromChannelInput!) {
        removePromotionsFromChannel(input: $input) {
            id
            name
        }
    }
`;
const deletePromotionsBulkAction = createBulkDeleteAction({
    location: 'promotion-list',
    requiresPermission: Permission.DeletePromotion,
    getItemName: item => item.name,
    bulkDelete: (dataService, ids) => dataService.promotion.deletePromotions(ids).pipe(map(res => res.deletePromotions)),
});
const assignPromotionsToChannelBulkAction = createBulkAssignToChannelAction({
    location: 'promotion-list',
    requiresPermission: Permission.UpdatePromotion,
    getItemName: item => item.name,
    bulkAssignToChannel: (dataService, promotionIds, channelId) => dataService
        .mutate(AssignPromotionsToChannelDocument, {
        input: {
            channelId,
            promotionIds,
        },
    })
        .pipe(map(res => res.assignPromotionsToChannel)),
});
const removePromotionsFromChannelBulkAction = createBulkRemoveFromChannelAction({
    location: 'promotion-list',
    requiresPermission: Permission.DeleteCatalog,
    getItemName: item => item.name,
    bulkRemoveFromChannel: (dataService, promotionIds, channelId) => dataService
        .mutate(RemovePromotionsFromChannelDocument, {
        input: {
            channelId,
            promotionIds,
        },
    })
        .pipe(map(res => res.removePromotionsFromChannel)),
});

const GET_PROMOTION_LIST = gql `
    query GetPromotionList($options: PromotionListOptions) {
        promotions(options: $options) {
            items {
                ...Promotion
            }
            totalItems
        }
    }
    ${PROMOTION_FRAGMENT}
`;
class PromotionListComponent extends TypedBaseListComponent {
    constructor() {
        super();
        this.customFields = this.getCustomFieldConfig('Promotion');
        this.filters = this.createFilterCollection()
            .addIdFilter()
            .addDateFilters()
            .addFilters([
            {
                name: 'startsAt',
                type: { kind: 'dateRange' },
                label: marker('marketing.starts-at'),
                filterField: 'startsAt',
            },
            {
                name: 'endsAt',
                type: { kind: 'dateRange' },
                label: marker('marketing.ends-at'),
                filterField: 'endsAt',
            },
            {
                name: 'enabled',
                type: { kind: 'boolean' },
                label: marker('common.enabled'),
                filterField: 'enabled',
            },
            {
                name: 'name',
                type: { kind: 'text' },
                label: marker('common.name'),
                filterField: 'name',
            },
            {
                name: 'couponCode',
                type: { kind: 'text' },
                label: marker('marketing.coupon-code'),
                filterField: 'couponCode',
            },
            {
                name: 'desc',
                type: { kind: 'text' },
                label: marker('common.description'),
                filterField: 'description',
            },
            {
                name: 'perCustomerUsageLimit',
                type: { kind: 'number' },
                label: marker('marketing.per-customer-limit'),
                filterField: 'perCustomerUsageLimit',
            },
            {
                name: 'usageLimit',
                type: { kind: 'number' },
                label: marker('marketing.usage-limit'),
                filterField: 'usageLimit',
            },
        ])
            .addCustomFieldFilters(this.customFields)
            .connectToRoute(this.route);
        this.sorts = this.createSortCollection()
            .defaultSort('createdAt', 'DESC')
            .addSorts([
            { name: 'createdAt' },
            { name: 'updatedAt' },
            { name: 'startsAt' },
            { name: 'endsAt' },
            { name: 'name' },
            { name: 'couponCode' },
            { name: 'perCustomerUsageLimit' },
            { name: 'usageLimit' },
        ])
            .addCustomFieldSorts(this.customFields)
            .connectToRoute(this.route);
        super.configure({
            document: GetPromotionListDocument,
            getItems: data => data.promotions,
            setVariables: (skip, take) => this.createQueryOptions(skip, take, this.searchTermControl.value),
            refreshListOnChanges: [this.filters.valueChanges, this.sorts.valueChanges],
        });
    }
    createQueryOptions(skip, take, searchTerm) {
        const filter = this.filters.createFilterInput();
        const sort = this.sorts.createSortInput();
        let filterOperator = LogicalOperator.AND;
        if (searchTerm) {
            filter.couponCode = { contains: searchTerm };
            filter.name = { contains: searchTerm };
            filterOperator = LogicalOperator.OR;
        }
        return {
            options: {
                skip,
                take,
                filter,
                filterOperator,
                sort,
            },
        };
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: PromotionListComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.2", type: PromotionListComponent, selector: "vdr-promotion-list", usesInheritance: true, ngImport: i0, template: "<vdr-page-block>\n    <vdr-action-bar>\n        <vdr-ab-left>\n            <vdr-language-selector\n                   [availableLanguageCodes]=\"availableLanguages$ | async\"\n                   [currentLanguageCode]=\"contentLanguage$ | async\"\n                   (languageCodeChange)=\"setLanguage($event)\"\n               ></vdr-language-selector>\n        </vdr-ab-left>\n        <vdr-ab-right>\n            <vdr-action-bar-items locationId=\"promotion-list\"></vdr-action-bar-items>\n            <a class=\"btn btn-primary\" [routerLink]=\"['./create']\" *vdrIfPermissions=\"'CreatePromotion'\">\n                <clr-icon shape=\"plus\"></clr-icon>\n                {{ 'marketing.create-new-promotion' | translate }}\n            </a>\n        </vdr-ab-right>\n    </vdr-action-bar>\n</vdr-page-block>\n\n<vdr-data-table-2\n    id=\"promotion-list\"\n    [items]=\"items$ | async\"\n    [itemsPerPage]=\"itemsPerPage$ | async\"\n    [totalItems]=\"totalItems$ | async\"\n    [currentPage]=\"currentPage$ | async\"\n    [filters]=\"filters\"\n    (pageChange)=\"setPageNumber($event)\"\n    (itemsPerPageChange)=\"setItemsPerPage($event)\"\n>\n    <vdr-bulk-action-menu\n        locationId=\"promotion-list\"\n        [hostComponent]=\"this\"\n        [selectionManager]=\"selectionManager\"\n    />\n    <vdr-dt2-search\n        [searchTermControl]=\"searchTermControl\"\n        [searchTermPlaceholder]=\"'marketing.search-by-name-or-coupon-code' | translate\"\n    />\n    <vdr-dt2-column [heading]=\"'common.id' | translate\" id=\"id\" [hiddenByDefault]=\"true\">\n        <ng-template let-promotion=\"item\">{{ promotion.id }}</ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column\n        [heading]=\"'common.created-at' | translate\" id=\"created-at\"\n        [hiddenByDefault]=\"true\"\n        [sort]=\"sorts.get('createdAt')\"\n    >\n        <ng-template let-promotion=\"item\">\n            {{ promotion.createdAt | localeDate : 'short' }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column\n        [heading]=\"'common.updated-at' | translate\" id=\"updated-at\"\n        [hiddenByDefault]=\"true\"\n        [sort]=\"sorts.get('updatedAt')\"\n    >\n        <ng-template let-promotion=\"item\">\n            {{ promotion.updatedAt | localeDate : 'short' }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'common.name' | translate\" id=\"name\" [optional]=\"false\" [sort]=\"sorts.get('name')\">\n        <ng-template let-promotion=\"item\">\n            <a class=\"button-ghost\" [routerLink]=\"['./', promotion.id]\"\n                ><span> {{ promotion.name }}</span>\n                <clr-icon shape=\"arrow right\"></clr-icon>\n            </a>\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'common.enabled' | translate\" id=\"enabled\">\n        <ng-template let-promotion=\"item\">\n            <vdr-chip *ngIf=\"promotion.enabled\" colorType=\"success\">{{\n                'common.enabled' | translate\n            }}</vdr-chip>\n            <vdr-chip *ngIf=\"!promotion.enabled\" colorType=\"warning\">{{\n                'common.disabled' | translate\n            }}</vdr-chip>\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'marketing.coupon-code' | translate\" id=\"coupon-code\" [sort]=\"sorts.get('couponCode')\">\n        <ng-template let-promotion=\"item\">\n            {{ promotion.couponCode }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'marketing.starts-at' | translate\" id=\"starts-at\" [sort]=\"sorts.get('startsAt')\">\n        <ng-template let-promotion=\"item\">\n            {{ promotion.startsAt | localeDate : 'short' }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'marketing.ends-at' | translate\" id=\"ends-at\" [sort]=\"sorts.get('endsAt')\">\n        <ng-template let-promotion=\"item\">\n            {{ promotion.endsAt | localeDate : 'short' }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column\n        [heading]=\"'marketing.per-customer-limit' | translate\" id=\"per-customer-limit\"\n        [sort]=\"sorts.get('perCustomerUsageLimit')\"\n        [hiddenByDefault]=\"true\"\n    >\n        <ng-template let-promotion=\"item\">\n            {{ promotion.perCustomerUsageLimit }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column\n        [heading]=\"'marketing.per-customer-limit' | translate\" id=\"per-customer-limit\"\n        [sort]=\"sorts.get('usageLimit')\"\n        [hiddenByDefault]=\"true\"\n    >\n        <ng-template let-promotion=\"item\">\n            {{ promotion.usageLimit }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-custom-field-column *ngFor=\"let customField of customFields\" [customField]=\"customField\" [sorts]=\"sorts\" />\n</vdr-data-table-2>\n", styles: [".search-form{padding:0}.search-input{margin:6px 8px 0 0;min-width:200px}\n"], dependencies: [{ kind: "directive", type: i3.ClrIconCustomTag, selector: "clr-icon" }, { kind: "directive", type: i4.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i3$1.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }, { kind: "component", type: i1.ActionBarComponent, selector: "vdr-action-bar" }, { kind: "component", type: i1.ActionBarLeftComponent, selector: "vdr-ab-left", inputs: ["grow"] }, { kind: "component", type: i1.ActionBarRightComponent, selector: "vdr-ab-right", inputs: ["grow"] }, { kind: "component", type: i1.ChipComponent, selector: "vdr-chip", inputs: ["icon", "invert", "colorFrom", "colorType"], outputs: ["iconClick"] }, { kind: "component", type: i1.LanguageSelectorComponent, selector: "vdr-language-selector", inputs: ["currentLanguageCode", "availableLanguageCodes", "disabled"], outputs: ["languageCodeChange"] }, { kind: "directive", type: i1.IfPermissionsDirective, selector: "[vdrIfPermissions]", inputs: ["vdrIfPermissions", "vdrIfPermissionsElse"] }, { kind: "component", type: i1.ActionBarItemsComponent, selector: "vdr-action-bar-items", inputs: ["locationId"] }, { kind: "component", type: i1.BulkActionMenuComponent, selector: "vdr-bulk-action-menu", inputs: ["locationId", "selectionManager", "hostComponent"] }, { kind: "component", type: i1.DataTable2Component, selector: "vdr-data-table-2", inputs: ["id", "items", "itemsPerPage", "currentPage", "totalItems", "emptyStateLabel", "filters", "activeIndex"], outputs: ["pageChange", "itemsPerPageChange"] }, { kind: "component", type: i1.DataTable2ColumnComponent, selector: "vdr-dt2-column", inputs: ["id", "expand", "heading", "align", "sort", "optional", "hiddenByDefault", "orderable"], exportAs: ["row"] }, { kind: "component", type: i1.DataTable2SearchComponent, selector: "vdr-dt2-search", inputs: ["searchTermControl", "searchTermPlaceholder"] }, { kind: "component", type: i1.DataTableCustomFieldColumnComponent, selector: "vdr-dt2-custom-field-column", inputs: ["customField", "sorts"], exportAs: ["row"] }, { kind: "component", type: i1.PageBlockComponent, selector: "vdr-page-block" }, { kind: "pipe", type: i4.AsyncPipe, name: "async" }, { kind: "pipe", type: i5.TranslatePipe, name: "translate" }, { kind: "pipe", type: i1.LocaleDatePipe, name: "localeDate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: PromotionListComponent, decorators: [{
            type: Component,
            args: [{ selector: 'vdr-promotion-list', changeDetection: ChangeDetectionStrategy.OnPush, template: "<vdr-page-block>\n    <vdr-action-bar>\n        <vdr-ab-left>\n            <vdr-language-selector\n                   [availableLanguageCodes]=\"availableLanguages$ | async\"\n                   [currentLanguageCode]=\"contentLanguage$ | async\"\n                   (languageCodeChange)=\"setLanguage($event)\"\n               ></vdr-language-selector>\n        </vdr-ab-left>\n        <vdr-ab-right>\n            <vdr-action-bar-items locationId=\"promotion-list\"></vdr-action-bar-items>\n            <a class=\"btn btn-primary\" [routerLink]=\"['./create']\" *vdrIfPermissions=\"'CreatePromotion'\">\n                <clr-icon shape=\"plus\"></clr-icon>\n                {{ 'marketing.create-new-promotion' | translate }}\n            </a>\n        </vdr-ab-right>\n    </vdr-action-bar>\n</vdr-page-block>\n\n<vdr-data-table-2\n    id=\"promotion-list\"\n    [items]=\"items$ | async\"\n    [itemsPerPage]=\"itemsPerPage$ | async\"\n    [totalItems]=\"totalItems$ | async\"\n    [currentPage]=\"currentPage$ | async\"\n    [filters]=\"filters\"\n    (pageChange)=\"setPageNumber($event)\"\n    (itemsPerPageChange)=\"setItemsPerPage($event)\"\n>\n    <vdr-bulk-action-menu\n        locationId=\"promotion-list\"\n        [hostComponent]=\"this\"\n        [selectionManager]=\"selectionManager\"\n    />\n    <vdr-dt2-search\n        [searchTermControl]=\"searchTermControl\"\n        [searchTermPlaceholder]=\"'marketing.search-by-name-or-coupon-code' | translate\"\n    />\n    <vdr-dt2-column [heading]=\"'common.id' | translate\" id=\"id\" [hiddenByDefault]=\"true\">\n        <ng-template let-promotion=\"item\">{{ promotion.id }}</ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column\n        [heading]=\"'common.created-at' | translate\" id=\"created-at\"\n        [hiddenByDefault]=\"true\"\n        [sort]=\"sorts.get('createdAt')\"\n    >\n        <ng-template let-promotion=\"item\">\n            {{ promotion.createdAt | localeDate : 'short' }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column\n        [heading]=\"'common.updated-at' | translate\" id=\"updated-at\"\n        [hiddenByDefault]=\"true\"\n        [sort]=\"sorts.get('updatedAt')\"\n    >\n        <ng-template let-promotion=\"item\">\n            {{ promotion.updatedAt | localeDate : 'short' }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'common.name' | translate\" id=\"name\" [optional]=\"false\" [sort]=\"sorts.get('name')\">\n        <ng-template let-promotion=\"item\">\n            <a class=\"button-ghost\" [routerLink]=\"['./', promotion.id]\"\n                ><span> {{ promotion.name }}</span>\n                <clr-icon shape=\"arrow right\"></clr-icon>\n            </a>\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'common.enabled' | translate\" id=\"enabled\">\n        <ng-template let-promotion=\"item\">\n            <vdr-chip *ngIf=\"promotion.enabled\" colorType=\"success\">{{\n                'common.enabled' | translate\n            }}</vdr-chip>\n            <vdr-chip *ngIf=\"!promotion.enabled\" colorType=\"warning\">{{\n                'common.disabled' | translate\n            }}</vdr-chip>\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'marketing.coupon-code' | translate\" id=\"coupon-code\" [sort]=\"sorts.get('couponCode')\">\n        <ng-template let-promotion=\"item\">\n            {{ promotion.couponCode }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'marketing.starts-at' | translate\" id=\"starts-at\" [sort]=\"sorts.get('startsAt')\">\n        <ng-template let-promotion=\"item\">\n            {{ promotion.startsAt | localeDate : 'short' }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'marketing.ends-at' | translate\" id=\"ends-at\" [sort]=\"sorts.get('endsAt')\">\n        <ng-template let-promotion=\"item\">\n            {{ promotion.endsAt | localeDate : 'short' }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column\n        [heading]=\"'marketing.per-customer-limit' | translate\" id=\"per-customer-limit\"\n        [sort]=\"sorts.get('perCustomerUsageLimit')\"\n        [hiddenByDefault]=\"true\"\n    >\n        <ng-template let-promotion=\"item\">\n            {{ promotion.perCustomerUsageLimit }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column\n        [heading]=\"'marketing.per-customer-limit' | translate\" id=\"per-customer-limit\"\n        [sort]=\"sorts.get('usageLimit')\"\n        [hiddenByDefault]=\"true\"\n    >\n        <ng-template let-promotion=\"item\">\n            {{ promotion.usageLimit }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-custom-field-column *ngFor=\"let customField of customFields\" [customField]=\"customField\" [sorts]=\"sorts\" />\n</vdr-data-table-2>\n", styles: [".search-form{padding:0}.search-input{margin:6px 8px 0 0;min-width:200px}\n"] }]
        }], ctorParameters: function () { return []; } });

const createRoutes = (pageService) => [
    {
        path: 'promotions',
        component: PageComponent,
        data: {
            locationId: 'promotion-list',
            breadcrumb: marker('breadcrumb.promotions'),
        },
        children: pageService.getPageTabRoutes('promotion-list'),
    },
    {
        path: 'promotions/:id',
        component: PageComponent,
        data: {
            locationId: 'promotion-detail',
            breadcrumb: { label: marker('breadcrumb.promotions'), link: ['../', 'promotions'] },
        },
        children: pageService.getPageTabRoutes('promotion-detail'),
    },
];
function promotionBreadcrumb(data, params) {
    return detailBreadcrumb({
        entity: data.entity,
        id: params.id,
        breadcrumbKey: 'breadcrumb.promotions',
        getName: promotion => promotion.name,
        route: 'promotions',
    });
}

class MarketingModule {
    static { this.hasRegisteredTabsAndBulkActions = false; }
    constructor(bulkActionRegistryService, pageService) {
        if (MarketingModule.hasRegisteredTabsAndBulkActions) {
            return;
        }
        bulkActionRegistryService.registerBulkAction(assignPromotionsToChannelBulkAction);
        bulkActionRegistryService.registerBulkAction(removePromotionsFromChannelBulkAction);
        bulkActionRegistryService.registerBulkAction(deletePromotionsBulkAction);
        pageService.registerPageTab({
            priority: 0,
            location: 'promotion-list',
            tab: marker('breadcrumb.promotions'),
            route: '',
            component: PromotionListComponent,
        });
        pageService.registerPageTab({
            priority: 0,
            location: 'promotion-detail',
            tab: marker('marketing.promotion'),
            route: '',
            component: detailComponentWithResolver({
                component: PromotionDetailComponent,
                query: GetPromotionDetailDocument,
                entityKey: 'promotion',
                getBreadcrumbs: entity => [
                    {
                        label: entity ? entity.name : marker('marketing.create-new-promotion'),
                        link: [entity?.id],
                    },
                ],
            }),
        });
        MarketingModule.hasRegisteredTabsAndBulkActions = true;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: MarketingModule, deps: [{ token: i1.BulkActionRegistryService }, { token: i1.PageService }], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.2", ngImport: i0, type: MarketingModule, declarations: [PromotionListComponent, PromotionDetailComponent], imports: [SharedModule, i3$1.RouterModule, SharedModule, AsyncPipe, SharedModule] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: MarketingModule, providers: [
            {
                provide: ROUTES,
                useFactory: (pageService) => createRoutes(pageService),
                multi: true,
                deps: [PageService],
            },
        ], imports: [SharedModule, RouterModule.forChild([]), SharedModule, SharedModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: MarketingModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [SharedModule, RouterModule.forChild([]), SharedModule, AsyncPipe, SharedModule],
                    providers: [
                        {
                            provide: ROUTES,
                            useFactory: (pageService) => createRoutes(pageService),
                            multi: true,
                            deps: [PageService],
                        },
                    ],
                    declarations: [PromotionListComponent, PromotionDetailComponent],
                }]
        }], ctorParameters: function () { return [{ type: i1.BulkActionRegistryService }, { type: i1.PageService }]; } });

// This file was generated by the build-public-api.ts script

/**
 * Generated bundle index. Do not edit.
 */

export { GET_PROMOTION_DETAIL, GET_PROMOTION_LIST, MarketingModule, PromotionDetailComponent, PromotionListComponent, assignPromotionsToChannelBulkAction, createRoutes, deletePromotionsBulkAction, promotionBreadcrumb, removePromotionsFromChannelBulkAction };
//# sourceMappingURL=vendure-admin-ui-marketing.mjs.map
