import { Component, Input } from '@angular/core';
import { fuzzySort, getLatestLanguage } from '@aztrix/helpers';
import { of } from 'rxjs';
import { AbstractSelectSearch } from '../abstract-select-search';
import * as i0 from "@angular/core";
import * as i1 from "../select-search/select-search.component";
import * as i2 from "@aztrix/components/row-cell-view";
import * as i3 from "@aztrix/helpers";
import * as i4 from "@aztrix/translate";
export class ProposalSelectSearchComponent extends AbstractSelectSearch {
    constructor() {
        super(...arguments);
        this.searchCallback$ = (options, query) => {
            const searchOptions = options.map((proposal) => ({
                id: proposal.id,
                name: getLatestLanguage(proposal, this.languageCode)?.name,
            }));
            return of(fuzzySort(searchOptions, query, ['name']).map((result) => options.find((option) => option.id === result.id)));
        };
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ProposalSelectSearchComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: ProposalSelectSearchComponent, selector: "ax-proposal-select-search", inputs: { proposals: "proposals", languageCode: "languageCode" }, usesInheritance: true, ngImport: i0, template: "<ng-template #option let-result>\n  <ax-proposal-cell-view [proposal]=\"result\"></ax-proposal-cell-view>\n</ng-template>\n\n<ng-template #selected let-result>\n  <span>\n    {{ result | displayName }}\n  </span>\n</ng-template>\n\n<ax-select-search\n  [form]=\"form\"\n  [options]=\"proposals\"\n  [placeholder]=\"(multiple ? 'label.proposals' : 'label.proposal') | translate\"\n  [optionTemplate]=\"option\"\n  [selectedValueTemplate]=\"selected\"\n  [multiple]=\"multiple\"\n  [searchCallback$]=\"searchCallback$\"\n  [valueCallback]=\"valueCallback\"\n  [label]=\"label ? label : ((multiple ? 'label.proposals' : 'label.proposal') | translate)\"\n></ax-select-search>\n", dependencies: [{ kind: "component", type: i1.SelectSearchComponent, selector: "ax-select-search", inputs: ["form", "options", "placeholder", "optionTemplate", "selectedValueTemplate", "multiple", "label", "keys", "canAddNew", "required", "appearance", "errorsTemplate", "prefixTemplate", "disabled", "valueCallback", "searchCallback$"], outputs: ["addNewValue"] }, { kind: "component", type: i2.ProposalCellViewComponent, selector: "ax-proposal-cell-view", inputs: ["proposal", "languageCode"] }, { kind: "pipe", type: i3.DisplayNamePipe, name: "displayName" }, { kind: "pipe", type: i4.TranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ProposalSelectSearchComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-proposal-select-search', template: "<ng-template #option let-result>\n  <ax-proposal-cell-view [proposal]=\"result\"></ax-proposal-cell-view>\n</ng-template>\n\n<ng-template #selected let-result>\n  <span>\n    {{ result | displayName }}\n  </span>\n</ng-template>\n\n<ax-select-search\n  [form]=\"form\"\n  [options]=\"proposals\"\n  [placeholder]=\"(multiple ? 'label.proposals' : 'label.proposal') | translate\"\n  [optionTemplate]=\"option\"\n  [selectedValueTemplate]=\"selected\"\n  [multiple]=\"multiple\"\n  [searchCallback$]=\"searchCallback$\"\n  [valueCallback]=\"valueCallback\"\n  [label]=\"label ? label : ((multiple ? 'label.proposals' : 'label.proposal') | translate)\"\n></ax-select-search>\n" }]
        }], propDecorators: { proposals: [{
                type: Input
            }], languageCode: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvcG9zYWwtc2VsZWN0LXNlYXJjaC5jb21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9saWJzL2NvbXBvbmVudHMvc2VsZWN0LXNlYXJjaC9wcm9wb3NhbC1zZWxlY3Qtc2VhcmNoL3Byb3Bvc2FsLXNlbGVjdC1zZWFyY2guY29tcG9uZW50LnRzIiwiLi4vLi4vLi4vLi4vLi4vLi4vbGlicy9jb21wb25lbnRzL3NlbGVjdC1zZWFyY2gvcHJvcG9zYWwtc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