/*
 * Copyright 2015-2024 Ritense BV, the Netherlands.
 *
 * Licensed under EUPL, Version 1.2 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import { BehaviorSubject, combineLatest, map } from 'rxjs';
import { InternalCaseStatusUtils } from '@valtimo/document';
import { CheckboxModule, DropdownModule, InputModule, TagModule, } from 'carbon-components-angular';
import { CARBON_THEME } from '../../models';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { distinctUntilChanged, filter, take } from 'rxjs/operators';
import { isEqual } from 'lodash';
import { CASES_WITHOUT_STATUS_KEY } from '../../constants';
import * as i0 from "@angular/core";
import * as i1 from "@ngx-translate/core";
import * as i2 from "@angular/common";
import * as i3 from "carbon-components-angular";
export class StatusSelectorComponent {
    set statuses(value) {
        this._statuses$.next((value || []).map(status => ({
            ...status,
            tagType: InternalCaseStatusUtils.getTagTypeFromInternalCaseStatusColor(status.color),
        })));
    }
    set selectedStatuses(value) {
        this._selectedStatuses$.next(value);
    }
    constructor(translateService) {
        this.translateService = translateService;
        this.carbonTheme = CARBON_THEME.WHITE;
        this.selectedStatusesChangeEvent = new EventEmitter();
        this._statuses$ = new BehaviorSubject([]);
        this._selectedStatuses$ = new BehaviorSubject([]);
        this.CASES_WITHOUT_STATUS_KEY = CASES_WITHOUT_STATUS_KEY;
        this.listItems$ = combineLatest([
            this._statuses$,
            this._selectedStatuses$,
            this.translateService.stream('key'),
        ]).pipe(filter(([statuses, selectedStatuses]) => !!statuses && !!selectedStatuses), map(([statuses, selectedStatuses]) => statuses.map(status => ({
            content: status.key === this.CASES_WITHOUT_STATUS_KEY
                ? this.translateService.instant('dossierManagement.statuses.withoutStatus')
                : status.title,
            selected: !!selectedStatuses.find(selectedStatus => selectedStatus.key === status.key),
            key: status.key,
            tagType: status.tagType,
        }))), distinctUntilChanged((previous, current) => isEqual(previous, current)));
    }
    itemSelected(event) {
        const newSelectedItems = event?.filter(item => item?.selected) || [];
        this._statuses$.pipe(take(1)).subscribe(statuses => {
            const newSelectedStatuses = newSelectedItems
                .map(item => statuses.find(status => status.key === item.key))
                .filter(status => !!status);
            this.selectedStatusesChangeEvent.emit(newSelectedStatuses);
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: StatusSelectorComponent, deps: [{ token: i1.TranslateService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: StatusSelectorComponent, isStandalone: true, selector: "valtimo-status-selector", inputs: { statuses: "statuses", selectedStatuses: "selectedStatuses", carbonTheme: "carbonTheme", disabled: "disabled" }, outputs: { selectedStatusesChangeEvent: "selectedStatusesChangeEvent" }, ngImport: i0, template: "<!--\n  ~ Copyright 2015-2024 Ritense BV, the Netherlands.\n  ~\n  ~ Licensed under EUPL, Version 1.2 (the \"License\");\n  ~ you may not use this file except in compliance with the License.\n  ~ You may obtain a copy of the License at\n  ~\n  ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n  ~\n  ~ Unless required by applicable law or agreed to in writing, software\n  ~ distributed under the License is distributed on an \"AS IS\" basis,\n  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  ~ See the License for the specific language governing permissions and\n  ~ limitations under the License.\n  -->\n\n<cds-label class=\"status-selector\" *ngIf=\"listItems$ | async as listItems\">\n  {{ 'dossierManagement.statuses.searchFieldTitle' | translate }}\n\n  <cds-dropdown\n    [appendInline]=\"false\"\n    type=\"multi\"\n    [disabled]=\"disabled\"\n    selectionFeedback=\"fixed\"\n    (selected)=\"itemSelected($event)\"\n  >\n    <cds-dropdown-list\n      [items]=\"listItems\"\n      [listTpl]=\"colorDropdownItemTemplate\"\n    ></cds-dropdown-list>\n  </cds-dropdown>\n</cds-label>\n\n<ng-template #colorDropdownItemTemplate let-item=\"item\">\n  <div class=\"status-selector-dropdown-template\">\n    <cds-checkbox [checked]=\"item.selected\"></cds-checkbox>\n\n    <span *ngIf=\"item.key === CASES_WITHOUT_STATUS_KEY\" class=\"generic-span\">{{\n      item?.content\n    }}</span>\n\n    <cds-tag\n      *ngIf=\"item.key !== CASES_WITHOUT_STATUS_KEY\"\n      class=\"cds-tag--no-margin\"\n      [type]=\"item?.tagType\"\n      [title]=\"item?.content\"\n    >\n      {{ item?.content }}\n    </cds-tag>\n  </div>\n</ng-template>\n", styles: ["::ng-deep .status-selector .cds--label{width:100%;margin-bottom:0!important}::ng-deep .status-selector .cds--multiselect{margin-top:8px}::ng-deep .status-selector-dropdown-template{display:flex;margin-top:-4px}::ng-deep .status-selector-dropdown-template .cds--tag{margin:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;display:inline-block;line-height:24px;max-width:100%}::ng-deep .status-selector-dropdown-template .generic-span{display:flex;align-items:center}\n/*!\n * Copyright 2015-2024 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }, { kind: "ngmodule", type: DropdownModule }, { kind: "component", type: i3.Dropdown, selector: "cds-dropdown, ibm-dropdown", inputs: ["id", "label", "hideLabel", "helperText", "placeholder", "displayValue", "clearText", "size", "type", "theme", "disabled", "skeleton", "inline", "disableArrowKeys", "invalid", "invalidText", "warn", "warnText", "appendInline", "scrollableContainer", "itemValueKey", "selectionFeedback", "menuButtonLabel", "selectedLabel", "dropUp"], outputs: ["selected", "onClose", "close"] }, { kind: "component", type: i3.DropdownList, selector: "cds-dropdown-list, ibm-dropdown-list", inputs: ["ariaLabel", "items", "listTpl", "type", "showTitles"], outputs: ["select", "scroll", "blurIntent"] }, { kind: "ngmodule", type: CheckboxModule }, { kind: "component", type: i3.Checkbox, selector: "cds-checkbox, ibm-checkbox", inputs: ["disabled", "skeleton", "hideLabel", "name", "id", "required", "value", "ariaLabel", "ariaLabelledby", "indeterminate", "checked"], outputs: ["click", "checkedChange", "indeterminateChange"] }, { kind: "ngmodule", type: InputModule }, { kind: "component", type: i3.Label, selector: "cds-label, ibm-label", inputs: ["labelInputID", "disabled", "skeleton", "helperText", "invalidText", "invalid", "warn", "warnText", "ariaLabel"] }, { kind: "ngmodule", type: TranslateModule }, { kind: "pipe", type: i1.TranslatePipe, name: "translate" }, { kind: "ngmodule", type: TagModule }, { kind: "component", type: i3.Tag, selector: "cds-tag, ibm-tag", inputs: ["type", "size", "class"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: StatusSelectorComponent, decorators: [{
            type: Component,
            args: [{ selector: 'valtimo-status-selector', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, imports: [CommonModule, DropdownModule, CheckboxModule, InputModule, TranslateModule, TagModule], template: "<!--\n  ~ Copyright 2015-2024 Ritense BV, the Netherlands.\n  ~\n  ~ Licensed under EUPL, Version 1.2 (the \"License\");\n  ~ you may not use this file except in compliance with the License.\n  ~ You may obtain a copy of the License at\n  ~\n  ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n  ~\n  ~ Unless required by applicable law or agreed to in writing, software\n  ~ distributed under the License is distributed on an \"AS IS\" basis,\n  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  ~ See the License for the specific language governing permissions and\n  ~ limitations under the License.\n  -->\n\n<cds-label class=\"status-selector\" *ngIf=\"listItems$ | async as listItems\">\n  {{ 'dossierManagement.statuses.searchFieldTitle' | translate }}\n\n  <cds-dropdown\n    [appendInline]=\"false\"\n    type=\"multi\"\n    [disabled]=\"disabled\"\n    selectionFeedback=\"fixed\"\n    (selected)=\"itemSelected($event)\"\n  >\n    <cds-dropdown-list\n      [items]=\"listItems\"\n      [listTpl]=\"colorDropdownItemTemplate\"\n    ></cds-dropdown-list>\n  </cds-dropdown>\n</cds-label>\n\n<ng-template #colorDropdownItemTemplate let-item=\"item\">\n  <div class=\"status-selector-dropdown-template\">\n    <cds-checkbox [checked]=\"item.selected\"></cds-checkbox>\n\n    <span *ngIf=\"item.key === CASES_WITHOUT_STATUS_KEY\" class=\"generic-span\">{{\n      item?.content\n    }}</span>\n\n    <cds-tag\n      *ngIf=\"item.key !== CASES_WITHOUT_STATUS_KEY\"\n      class=\"cds-tag--no-margin\"\n      [type]=\"item?.tagType\"\n      [title]=\"item?.content\"\n    >\n      {{ item?.content }}\n    </cds-tag>\n  </div>\n</ng-template>\n", styles: ["::ng-deep .status-selector .cds--label{width:100%;margin-bottom:0!important}::ng-deep .status-selector .cds--multiselect{margin-top:8px}::ng-deep .status-selector-dropdown-template{display:flex;margin-top:-4px}::ng-deep .status-selector-dropdown-template .cds--tag{margin:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;display:inline-block;line-height:24px;max-width:100%}::ng-deep .status-selector-dropdown-template .generic-span{display:flex;align-items:center}\n/*!\n * Copyright 2015-2024 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n"] }]
        }], ctorParameters: () => [{ type: i1.TranslateService }], propDecorators: { statuses: [{
                type: Input
            }], selectedStatuses: [{
                type: Input
            }], carbonTheme: [{
                type: Input
            }], disabled: [{
                type: Input
            }], selectedStatusesChangeEvent: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 