import { ChangeDetectionStrategy, Component } from '@angular/core';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { GetPromotionListDocument, LogicalOperator, PROMOTION_FRAGMENT, TypedBaseListComponent, } from '@vendure/admin-ui/core';
import { gql } from 'apollo-angular';
import * as i0 from "@angular/core";
import * as i1 from "@clr/angular";
import * as i2 from "@angular/common";
import * as i3 from "@angular/router";
import * as i4 from "@vendure/admin-ui/core";
import * as i5 from "@ngx-translate/core";
export const GET_PROMOTION_LIST = gql `
    query GetPromotionList($options: PromotionListOptions) {
        promotions(options: $options) {
            items {
                ...Promotion
            }
            totalItems
        }
    }
    ${PROMOTION_FRAGMENT}
`;
export class PromotionListComponent extends TypedBaseListComponent {
    constructor() {
        super();
        this.customFields = this.getCustomFieldConfig('Promotion');
        this.filters = this.createFilterCollection()
            .addIdFilter()
            .addDateFilters()
            .addFilters([
            {
                name: 'startsAt',
                type: { kind: 'dateRange' },
                label: _('marketing.starts-at'),
                filterField: 'startsAt',
            },
            {
                name: 'endsAt',
                type: { kind: 'dateRange' },
                label: _('marketing.ends-at'),
                filterField: 'endsAt',
            },
            {
                name: 'enabled',
                type: { kind: 'boolean' },
                label: _('common.enabled'),
                filterField: 'enabled',
            },
            {
                name: 'name',
                type: { kind: 'text' },
                label: _('common.name'),
                filterField: 'name',
            },
            {
                name: 'couponCode',
                type: { kind: 'text' },
                label: _('marketing.coupon-code'),
                filterField: 'couponCode',
            },
            {
                name: 'desc',
                type: { kind: 'text' },
                label: _('common.description'),
                filterField: 'description',
            },
            {
                name: 'perCustomerUsageLimit',
                type: { kind: 'number' },
                label: _('marketing.per-customer-limit'),
                filterField: 'perCustomerUsageLimit',
            },
            {
                name: 'usageLimit',
                type: { kind: 'number' },
                label: _('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: i1.ClrIconCustomTag, selector: "clr-icon" }, { kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i3.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }, { kind: "component", type: i4.ActionBarComponent, selector: "vdr-action-bar" }, { kind: "component", type: i4.ActionBarLeftComponent, selector: "vdr-ab-left", inputs: ["grow"] }, { kind: "component", type: i4.ActionBarRightComponent, selector: "vdr-ab-right", inputs: ["grow"] }, { kind: "component", type: i4.ChipComponent, selector: "vdr-chip", inputs: ["icon", "invert", "colorFrom", "colorType"], outputs: ["iconClick"] }, { kind: "component", type: i4.LanguageSelectorComponent, selector: "vdr-language-selector", inputs: ["currentLanguageCode", "availableLanguageCodes", "disabled"], outputs: ["languageCodeChange"] }, { kind: "directive", type: i4.IfPermissionsDirective, selector: "[vdrIfPermissions]", inputs: ["vdrIfPermissions", "vdrIfPermissionsElse"] }, { kind: "component", type: i4.ActionBarItemsComponent, selector: "vdr-action-bar-items", inputs: ["locationId"] }, { kind: "component", type: i4.BulkActionMenuComponent, selector: "vdr-bulk-action-menu", inputs: ["locationId", "selectionManager", "hostComponent"] }, { kind: "component", type: i4.DataTable2Component, selector: "vdr-data-table-2", inputs: ["id", "items", "itemsPerPage", "currentPage", "totalItems", "emptyStateLabel", "filters", "activeIndex"], outputs: ["pageChange", "itemsPerPageChange"] }, { kind: "component", type: i4.DataTable2ColumnComponent, selector: "vdr-dt2-column", inputs: ["id", "expand", "heading", "align", "sort", "optional", "hiddenByDefault", "orderable"], exportAs: ["row"] }, { kind: "component", type: i4.DataTable2SearchComponent, selector: "vdr-dt2-search", inputs: ["searchTermControl", "searchTermPlaceholder"] }, { kind: "component", type: i4.DataTableCustomFieldColumnComponent, selector: "vdr-dt2-custom-field-column", inputs: ["customField", "sorts"], exportAs: ["row"] }, { kind: "component", type: i4.PageBlockComponent, selector: "vdr-page-block" }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }, { kind: "pipe", type: i5.TranslatePipe, name: "translate" }, { kind: "pipe", type: i4.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 []; } });
//# sourceMappingURL=data:application/json;base64, 