import { Component } from '@angular/core';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { CustomerListQueryDocument, LogicalOperator, 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 "../customer-status-label/customer-status-label.component";
import * as i6 from "@ngx-translate/core";
export const CUSTOMER_LIST_QUERY = gql `
    query CustomerListQuery($options: CustomerListOptions) {
        customers(options: $options) {
            items {
                ...CustomerListItem
            }
            totalItems
        }
    }

    fragment CustomerListItem on Customer {
        id
        createdAt
        updatedAt
        title
        firstName
        lastName
        emailAddress
        user {
            id
            verified
        }
    }
`;
export class CustomerListComponent extends TypedBaseListComponent {
    constructor() {
        super();
        this.customFields = this.getCustomFieldConfig('Customer');
        this.filters = this.createFilterCollection()
            .addIdFilter()
            .addDateFilters()
            .addFilter({
            name: 'firstName',
            type: { kind: 'text' },
            label: _('customer.first-name'),
            filterField: 'firstName',
        })
            .addFilter({
            name: 'lastName',
            type: { kind: 'text' },
            label: _('customer.last-name'),
            filterField: 'lastName',
        })
            .addFilter({
            name: 'emailAddress',
            type: { kind: 'text' },
            label: _('customer.email-address'),
            filterField: 'emailAddress',
        })
            .addCustomFieldFilters(this.customFields)
            .connectToRoute(this.route);
        this.sorts = this.createSortCollection()
            .defaultSort('createdAt', 'DESC')
            .addSort({ name: 'createdAt' })
            .addSort({ name: 'updatedAt' })
            .addSort({ name: 'lastName' })
            .addSort({ name: 'emailAddress' })
            .addCustomFieldSorts(this.customFields)
            .connectToRoute(this.route);
        this.configure({
            document: CustomerListQueryDocument,
            getItems: data => data.customers,
            setVariables: (skip, take) => ({
                options: {
                    skip,
                    take,
                    filter: {
                        ...(this.searchTermControl.value
                            ? {
                                emailAddress: {
                                    contains: this.searchTermControl.value,
                                },
                                lastName: {
                                    contains: this.searchTermControl.value,
                                },
                                postalCode: {
                                    contains: this.searchTermControl.value,
                                },
                            }
                            : {}),
                        ...this.filters.createFilterInput(),
                    },
                    filterOperator: this.searchTermControl.value ? LogicalOperator.OR : LogicalOperator.AND,
                    sort: this.sorts.createSortInput(),
                },
            }),
            refreshListOnChanges: [this.sorts.valueChanges, this.filters.valueChanges],
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: CustomerListComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.2", type: CustomerListComponent, selector: "vdr-customer-list", usesInheritance: true, ngImport: i0, template: "<vdr-page-block>\n    <vdr-action-bar>\n        <vdr-ab-left> </vdr-ab-left>\n        <vdr-ab-right>\n            <vdr-action-bar-items locationId=\"customer-list\"></vdr-action-bar-items>\n            <a class=\"btn btn-primary\" [routerLink]=\"['./create']\" *vdrIfPermissions=\"'CreateCustomer'\">\n                <clr-icon shape=\"plus\"></clr-icon>\n                {{ 'customer.create-new-customer' | translate }}\n            </a>\n        </vdr-ab-right>\n    </vdr-action-bar>\n</vdr-page-block>\n\n<vdr-data-table-2\n    class=\"mt-2\"\n    id=\"customer-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=\"customer-list\"\n        [hostComponent]=\"this\"\n        [selectionManager]=\"selectionManager\"\n    ></vdr-bulk-action-menu>\n    <vdr-dt2-search\n        [searchTermControl]=\"searchTermControl\"\n        [searchTermPlaceholder]=\"'customer.search-customers-by-email-last-name-postal-code' | translate\"\n    ></vdr-dt2-search>\n    <vdr-dt2-column [heading]=\"'common.id' | translate\" id=\"id\" [hiddenByDefault]=\"true\">\n        <ng-template let-customer=\"item\">\n            {{ customer.id }}\n        </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-customer=\"item\">\n            {{ customer.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-customer=\"item\">\n            {{ customer.updatedAt | localeDate : 'short' }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'customer.name' | translate\" id=\"name\" [optional]=\"false\" [sort]=\"sorts.get('lastName')\">\n        <ng-template let-customer=\"item\">\n            <a class=\"button-ghost\" [routerLink]=\"['./', customer.id]\"\n                ><span> {{ customer.title }} {{ customer.firstName }} {{ customer.lastName }} </span>\n                <clr-icon shape=\"arrow right\"></clr-icon>\n            </a>\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'common.status' | translate\" id=\"status\">\n        <ng-template let-customer=\"item\">\n            <vdr-customer-status-label [customer]=\"customer\" />\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'customer.email-address' | translate\" id=\"email-address\" [sort]=\"sorts.get('emailAddress')\">\n        <ng-template let-customer=\"item\">\n            {{ customer.emailAddress }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-custom-field-column *ngFor=\"let field of customFields\" [customField]=\"field\" [sorts]=\"sorts\" />\n</vdr-data-table-2>\n", styles: [".search-input{margin-top:6px;min-width:300px}\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: 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: "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: "component", type: i5.CustomerStatusLabelComponent, selector: "vdr-customer-status-label", inputs: ["customer"] }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }, { kind: "pipe", type: i6.TranslatePipe, name: "translate" }, { kind: "pipe", type: i4.LocaleDatePipe, name: "localeDate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: CustomerListComponent, decorators: [{
            type: Component,
            args: [{ selector: 'vdr-customer-list', template: "<vdr-page-block>\n    <vdr-action-bar>\n        <vdr-ab-left> </vdr-ab-left>\n        <vdr-ab-right>\n            <vdr-action-bar-items locationId=\"customer-list\"></vdr-action-bar-items>\n            <a class=\"btn btn-primary\" [routerLink]=\"['./create']\" *vdrIfPermissions=\"'CreateCustomer'\">\n                <clr-icon shape=\"plus\"></clr-icon>\n                {{ 'customer.create-new-customer' | translate }}\n            </a>\n        </vdr-ab-right>\n    </vdr-action-bar>\n</vdr-page-block>\n\n<vdr-data-table-2\n    class=\"mt-2\"\n    id=\"customer-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=\"customer-list\"\n        [hostComponent]=\"this\"\n        [selectionManager]=\"selectionManager\"\n    ></vdr-bulk-action-menu>\n    <vdr-dt2-search\n        [searchTermControl]=\"searchTermControl\"\n        [searchTermPlaceholder]=\"'customer.search-customers-by-email-last-name-postal-code' | translate\"\n    ></vdr-dt2-search>\n    <vdr-dt2-column [heading]=\"'common.id' | translate\" id=\"id\" [hiddenByDefault]=\"true\">\n        <ng-template let-customer=\"item\">\n            {{ customer.id }}\n        </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-customer=\"item\">\n            {{ customer.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-customer=\"item\">\n            {{ customer.updatedAt | localeDate : 'short' }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'customer.name' | translate\" id=\"name\" [optional]=\"false\" [sort]=\"sorts.get('lastName')\">\n        <ng-template let-customer=\"item\">\n            <a class=\"button-ghost\" [routerLink]=\"['./', customer.id]\"\n                ><span> {{ customer.title }} {{ customer.firstName }} {{ customer.lastName }} </span>\n                <clr-icon shape=\"arrow right\"></clr-icon>\n            </a>\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'common.status' | translate\" id=\"status\">\n        <ng-template let-customer=\"item\">\n            <vdr-customer-status-label [customer]=\"customer\" />\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'customer.email-address' | translate\" id=\"email-address\" [sort]=\"sorts.get('emailAddress')\">\n        <ng-template let-customer=\"item\">\n            {{ customer.emailAddress }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-custom-field-column *ngFor=\"let field of customFields\" [customField]=\"field\" [sorts]=\"sorts\" />\n</vdr-data-table-2>\n", styles: [".search-input{margin-top:6px;min-width:300px}\n"] }]
        }], ctorParameters: function () { return []; } });
//# sourceMappingURL=data:application/json;base64, 