import { Component } from '@angular/core';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { FACET_WITH_VALUE_LIST_FRAGMENT, GetFacetListDocument, TypedBaseListComponent, } from '@vendure/admin-ui/core';
import { gql } from 'apollo-angular';
import * as i0 from "@angular/core";
import * as i1 from "@vendure/admin-ui/core";
import * as i2 from "@clr/angular";
import * as i3 from "@angular/common";
import * as i4 from "@angular/router";
import * as i5 from "@ngx-translate/core";
export const FACET_LIST_QUERY = gql `
    query GetFacetList($options: FacetListOptions) {
        facets(options: $options) {
            items {
                ...FacetWithValueList
            }
            totalItems
        }
    }
    ${FACET_WITH_VALUE_LIST_FRAGMENT}
`;
export class FacetListComponent extends TypedBaseListComponent {
    constructor(dataService) {
        super();
        this.dataService = dataService;
        this.initialLimit = 3;
        this.displayLimit = {};
        this.customFields = this.getCustomFieldConfig('Facet');
        this.filters = this.createFilterCollection()
            .addIdFilter()
            .addDateFilters()
            .addFilter({
            name: 'visibility',
            type: { kind: 'boolean' },
            label: _('common.visibility'),
            toFilterInput: value => ({
                isPrivate: { eq: !value },
            }),
        })
            .addCustomFieldFilters(this.customFields)
            .connectToRoute(this.route);
        this.sorts = this.createSortCollection()
            .defaultSort('createdAt', 'DESC')
            .addSort({ name: 'id' })
            .addSort({ name: 'createdAt' })
            .addSort({ name: 'updatedAt' })
            .addSort({ name: 'name' })
            .addSort({ name: 'code' })
            .addCustomFieldSorts(this.customFields)
            .connectToRoute(this.route);
        super.configure({
            document: GetFacetListDocument,
            getItems: data => data.facets,
            setVariables: (skip, take) => ({
                options: {
                    skip,
                    take,
                    filter: {
                        name: {
                            contains: this.searchTermControl.value,
                        },
                        ...this.filters.createFilterInput(),
                    },
                    sort: this.sorts.createSortInput(),
                },
            }),
            refreshListOnChanges: [this.filters.valueChanges, this.sorts.valueChanges],
        });
    }
    toggleDisplayLimit(facet) {
        if (this.displayLimit[facet.id] === facet.valueList.items.length) {
            this.displayLimit[facet.id] = this.initialLimit;
        }
        else {
            this.displayLimit[facet.id] = facet.valueList.items.length;
        }
    }
    setLanguage(code) {
        this.dataService.client.setContentLanguage(code).subscribe();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: FacetListComponent, deps: [{ token: i1.DataService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.2", type: FacetListComponent, selector: "vdr-facet-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=\"facet-list\"></vdr-action-bar-items>\n            <a\n                class=\"btn btn-primary\"\n                [routerLink]=\"['./create']\"\n                *vdrIfPermissions=\"['CreateCatalog', 'CreateFacet']\"\n            >\n                <clr-icon shape=\"plus\"></clr-icon>\n                {{ 'catalog.create-new-facet' | translate }}\n            </a>\n        </vdr-ab-right>\n    </vdr-action-bar>\n</vdr-page-block>\n<vdr-data-table-2\n    class=\"mt-2\"\n    id=\"facet-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=\"facet-list\"\n        [hostComponent]=\"this\"\n        [selectionManager]=\"selectionManager\"\n    ></vdr-bulk-action-menu>\n    <vdr-dt2-search\n        [searchTermControl]=\"searchTermControl\"\n        [searchTermPlaceholder]=\"'catalog.filter-by-name' | translate\"\n    ></vdr-dt2-search>\n    <vdr-dt2-column [heading]=\"'common.id' | translate\" id=\"id\" [hiddenByDefault]=\"true\" [sort]=\"sorts.get('id')\">\n        <ng-template let-facet=\"item\">\n            {{ facet.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-facet=\"item\">\n            {{ facet.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-facet=\"item\">\n            {{ facet.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-facet=\"item\">\n            <a class=\"button-ghost\" [routerLink]=\"['./', facet.id]\"\n                ><span>{{ facet.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.code' | translate\" id=\"code\">\n        <ng-template let-facet=\"item\">\n            {{ facet.code }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'common.visibility' | translate\" id=\"visibility\">\n        <ng-template let-facet=\"item\">\n            <vdr-chip *ngIf=\"facet.isPrivate\" colorType=\"warning\">{{\n                'common.private' | translate\n            }}</vdr-chip>\n            <vdr-chip *ngIf=\"!facet.isPrivate\" colorType=\"success\">{{\n                'common.public' | translate\n            }}</vdr-chip>\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'catalog.values' | translate\" id=\"values\">\n        <ng-template let-facet=\"item\">\n            <div class=\"facet-values-list\">\n                <vdr-facet-value-chip\n                    *ngFor=\"let value of facet.valueList.items | slice : 0 : displayLimit[facet.id] || 3\"\n                    [facetValue]=\"value\"\n                    [removable]=\"false\"\n                    [displayFacetName]=\"false\"\n                ></vdr-facet-value-chip>\n                <vdr-chip *ngIf=\"displayLimit[facet.id] < facet.valueList.totalItems && (displayLimit[facet.id] || 0) === facet.valueList.items.length\">\n                    ... + {{ facet.valueList.totalItems - facet.valueList.items.length }}\n                </vdr-chip>\n                <button\n                    class=\"button-small\"\n                    *ngIf=\"facet.valueList.items.length > initialLimit\"\n                    (click)=\"toggleDisplayLimit(facet)\"\n                >\n                    <ng-container *ngIf=\"(displayLimit[facet.id] || 0) < facet.valueList.items.length; else collapse\">\n                        <clr-icon shape=\"plus\"></clr-icon>\n                        {{ facet.valueList.totalItems - initialLimit }}\n                    </ng-container>\n                    <ng-template #collapse>\n                        <clr-icon shape=\"minus\"></clr-icon>\n                    </ng-template>\n                </button>\n            </div>\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: [".facet-values-list{max-width:500px;display:flex;flex-wrap:wrap;align-items:center;gap:4px}\n"], dependencies: [{ kind: "directive", type: i2.ClrIconCustomTag, selector: "clr-icon" }, { kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i4.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.FacetValueChipComponent, selector: "vdr-facet-value-chip", inputs: ["facetValue", "removable", "displayFacetName"], outputs: ["remove"] }, { 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: i3.AsyncPipe, name: "async" }, { kind: "pipe", type: i3.SlicePipe, name: "slice" }, { kind: "pipe", type: i5.TranslatePipe, name: "translate" }, { kind: "pipe", type: i1.LocaleDatePipe, name: "localeDate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: FacetListComponent, decorators: [{
            type: Component,
            args: [{ selector: 'vdr-facet-list', 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=\"facet-list\"></vdr-action-bar-items>\n            <a\n                class=\"btn btn-primary\"\n                [routerLink]=\"['./create']\"\n                *vdrIfPermissions=\"['CreateCatalog', 'CreateFacet']\"\n            >\n                <clr-icon shape=\"plus\"></clr-icon>\n                {{ 'catalog.create-new-facet' | translate }}\n            </a>\n        </vdr-ab-right>\n    </vdr-action-bar>\n</vdr-page-block>\n<vdr-data-table-2\n    class=\"mt-2\"\n    id=\"facet-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=\"facet-list\"\n        [hostComponent]=\"this\"\n        [selectionManager]=\"selectionManager\"\n    ></vdr-bulk-action-menu>\n    <vdr-dt2-search\n        [searchTermControl]=\"searchTermControl\"\n        [searchTermPlaceholder]=\"'catalog.filter-by-name' | translate\"\n    ></vdr-dt2-search>\n    <vdr-dt2-column [heading]=\"'common.id' | translate\" id=\"id\" [hiddenByDefault]=\"true\" [sort]=\"sorts.get('id')\">\n        <ng-template let-facet=\"item\">\n            {{ facet.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-facet=\"item\">\n            {{ facet.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-facet=\"item\">\n            {{ facet.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-facet=\"item\">\n            <a class=\"button-ghost\" [routerLink]=\"['./', facet.id]\"\n                ><span>{{ facet.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.code' | translate\" id=\"code\">\n        <ng-template let-facet=\"item\">\n            {{ facet.code }}\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'common.visibility' | translate\" id=\"visibility\">\n        <ng-template let-facet=\"item\">\n            <vdr-chip *ngIf=\"facet.isPrivate\" colorType=\"warning\">{{\n                'common.private' | translate\n            }}</vdr-chip>\n            <vdr-chip *ngIf=\"!facet.isPrivate\" colorType=\"success\">{{\n                'common.public' | translate\n            }}</vdr-chip>\n        </ng-template>\n    </vdr-dt2-column>\n    <vdr-dt2-column [heading]=\"'catalog.values' | translate\" id=\"values\">\n        <ng-template let-facet=\"item\">\n            <div class=\"facet-values-list\">\n                <vdr-facet-value-chip\n                    *ngFor=\"let value of facet.valueList.items | slice : 0 : displayLimit[facet.id] || 3\"\n                    [facetValue]=\"value\"\n                    [removable]=\"false\"\n                    [displayFacetName]=\"false\"\n                ></vdr-facet-value-chip>\n                <vdr-chip *ngIf=\"displayLimit[facet.id] < facet.valueList.totalItems && (displayLimit[facet.id] || 0) === facet.valueList.items.length\">\n                    ... + {{ facet.valueList.totalItems - facet.valueList.items.length }}\n                </vdr-chip>\n                <button\n                    class=\"button-small\"\n                    *ngIf=\"facet.valueList.items.length > initialLimit\"\n                    (click)=\"toggleDisplayLimit(facet)\"\n                >\n                    <ng-container *ngIf=\"(displayLimit[facet.id] || 0) < facet.valueList.items.length; else collapse\">\n                        <clr-icon shape=\"plus\"></clr-icon>\n                        {{ facet.valueList.totalItems - initialLimit }}\n                    </ng-container>\n                    <ng-template #collapse>\n                        <clr-icon shape=\"minus\"></clr-icon>\n                    </ng-template>\n                </button>\n            </div>\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: [".facet-values-list{max-width:500px;display:flex;flex-wrap:wrap;align-items:center;gap:4px}\n"] }]
        }], ctorParameters: function () { return [{ type: i1.DataService }]; } });
//# sourceMappingURL=data:application/json;base64, 