import { Component, EventEmitter, Input, Output } from '@angular/core';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "@angular/material/tooltip";
export class SingleCattaxCategoryComponent {
    constructor() {
        this.selectedItems = [];
        this.changeSelected = new EventEmitter();
        this.categoryExtended = new EventEmitter();
        this.cantSelectList = [];
    }
    ngOnChanges(changes) {
        if (changes.selectedItems) {
            this.updateSelectedItems();
        }
    }
    calculatePadding(node) {
        const basePadding = node.level * 24;
        return basePadding + (node.expandable ? 0 : 32);
    }
    toggleVisibility(category) {
        category.hidden = !category.hidden;
        if (category.children && category.children.length) {
            category.children.forEach((item) => this.toggleChildrenRecursive(item, category.hidden));
        }
    }
    includeExcludeItem(category, include) {
        if (this.isIncludeExcludeNotAvailable(category)) {
            return;
        }
        category.include = include;
        this.toggleVisibility(category);
        this.addToSelected(category);
    }
    addToSelected(category) {
        this.changeSelected.emit(category);
        this.updateSelectedItems();
    }
    extendedCategory(category) {
        this.categoryExtended.emit(category);
    }
    extendItems(category) {
        category.isExpand = !category.isExpand;
        this.extendedCategory(category);
    }
    updateSelectedItems() {
        if (this.selectedItems && this.selectedItems.length) {
            this.cantSelectList = [];
            this.selectedItems.forEach((item) => {
                this.cantSelectList.push(...item.path);
            });
        }
        else {
            this.cantSelectList = [];
        }
    }
    isIncludeExcludeNotAvailable(category) {
        return !!this.cantSelectList.find((item) => item.value === category.value);
    }
    toggleChildrenRecursive(item, hidden) {
        item.hidden = hidden;
        if (item.children && item.children.length) {
            item.children.forEach((child) => this.toggleChildrenRecursive(child, hidden));
        }
    }
}
SingleCattaxCategoryComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SingleCattaxCategoryComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
SingleCattaxCategoryComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: SingleCattaxCategoryComponent, selector: "single-cattax-category", inputs: { category: "category", selectedItems: "selectedItems" }, outputs: { changeSelected: "changeSelected", categoryExtended: "categoryExtended" }, usesOnChanges: true, ngImport: i0, template: "<div\n  *ngIf=\"!category.hidden\"\n  class=\"tree\"\n  [style.marginLeft.px]=\"calculatePadding(category)\"\n  [attr.data-qa]=\"'tree-item'\"\n>\n  <div class=\"tree-name\" (click)=\"extendItems(category)\">\n    <span\n      *ngIf=\"category.expandable\"\n      class=\"material-icons material-icons-outlined button-icon button-icon-outline button-icon-large\"\n    >\n      {{ category.isExpand ? 'arrow_drop_down' : 'arrow_right' }}</span\n    >\n    <div class=\"tree-item\" [attr.data-qa-name]=\"category.description\">\n      {{ category.description }}\n    </div>\n  </div>\n  <div class=\"select-item\">\n    <div\n      class=\"button button-exclude\"\n      [attr.data-qa]=\"'exclude'\"\n      [ngClass]=\"{disabled: isIncludeExcludeNotAvailable(category)}\"\n      matTooltip=\"Some categories are selected\"\n      matTooltipDisabled=\"{{ !isIncludeExcludeNotAvailable(category) }}\"\n      [matTooltipPosition]=\"'above'\"\n      (click)=\"includeExcludeItem(category, false)\"\n    >\n      <span class=\"material-icons material-icons-outlined\">remove_circle_outline</span>Exclude\n    </div>\n    <div\n      class=\"button button-include\"\n      [attr.data-qa]=\"'include'\"\n      [ngClass]=\"{disabled: isIncludeExcludeNotAvailable(category)}\"\n      matTooltip=\"Some categories are selected\"\n      matTooltipDisabled=\"{{ !isIncludeExcludeNotAvailable(category) }}\"\n      [matTooltipPosition]=\"'above'\"\n      (click)=\"includeExcludeItem(category, true)\"\n    >\n      <span class=\"material-icons material-icons-outlined\">add_circle_outline</span>Include\n    </div>\n  </div>\n</div>\n<div *ngIf=\"category.isExpand\">\n  <single-cattax-category\n    *ngFor=\"let child of category.children\"\n    [category]=\"child\"\n    [selectedItems]=\"selectedItems\"\n    (changeSelected)=\"addToSelected($event)\"\n    (categoryExtended)=\"extendedCategory($event)\"\n  ></single-cattax-category>\n</div>\n", styles: ["mat-icon{font-size:var(--font-body-1);line-height:22px;cursor:pointer;height:16px;width:16px}.tree-item>span{padding-right:8px;padding-bottom:6px}.mat-checkbox{margin:0 8px}.tree{display:flex;min-height:21px;line-height:21px}.select-item{font-size:var(--font-medium-button);font-weight:var(--font-weight-semibold);line-height:18px;display:flex;margin-left:auto;border-bottom:1px solid var(--neutral-outline-variant-color);min-height:32px;margin-bottom:10px;gap:4px;padding-bottom:10px}.select-item>div{cursor:pointer}.select-item .include{display:inherit;line-height:21px;color:var(--light-success);height:30px}.select-item .exclude{display:inherit;line-height:21px;margin-right:24px;color:var(--error-default-color);height:30px}.select-item div.disabled{background-color:transparent;cursor:not-allowed;color:var(--neutral-on-disable-color)}.select-item div.disabled span.material-icons:hover{cursor:not-allowed}.tree-item{font-size:var(--font-body-2);font-weight:var(--font-weight-regular);line-height:21px;width:100%;display:flex;border-bottom:1px solid var(--neutral-outline-variant-color);margin-left:8px;padding:5px 0 16.5px;color:var(--neutral-on-main-neutral-color)}.tree-name{display:flex;margin-bottom:10px;width:100%;cursor:pointer;align-items:center}.tree-name span{margin-bottom:10.5px}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { kind: "component", type: SingleCattaxCategoryComponent, selector: "single-cattax-category", inputs: ["category", "selectedItems"], outputs: ["changeSelected", "categoryExtended"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SingleCattaxCategoryComponent, decorators: [{
            type: Component,
            args: [{ selector: 'single-cattax-category', template: "<div\n  *ngIf=\"!category.hidden\"\n  class=\"tree\"\n  [style.marginLeft.px]=\"calculatePadding(category)\"\n  [attr.data-qa]=\"'tree-item'\"\n>\n  <div class=\"tree-name\" (click)=\"extendItems(category)\">\n    <span\n      *ngIf=\"category.expandable\"\n      class=\"material-icons material-icons-outlined button-icon button-icon-outline button-icon-large\"\n    >\n      {{ category.isExpand ? 'arrow_drop_down' : 'arrow_right' }}</span\n    >\n    <div class=\"tree-item\" [attr.data-qa-name]=\"category.description\">\n      {{ category.description }}\n    </div>\n  </div>\n  <div class=\"select-item\">\n    <div\n      class=\"button button-exclude\"\n      [attr.data-qa]=\"'exclude'\"\n      [ngClass]=\"{disabled: isIncludeExcludeNotAvailable(category)}\"\n      matTooltip=\"Some categories are selected\"\n      matTooltipDisabled=\"{{ !isIncludeExcludeNotAvailable(category) }}\"\n      [matTooltipPosition]=\"'above'\"\n      (click)=\"includeExcludeItem(category, false)\"\n    >\n      <span class=\"material-icons material-icons-outlined\">remove_circle_outline</span>Exclude\n    </div>\n    <div\n      class=\"button button-include\"\n      [attr.data-qa]=\"'include'\"\n      [ngClass]=\"{disabled: isIncludeExcludeNotAvailable(category)}\"\n      matTooltip=\"Some categories are selected\"\n      matTooltipDisabled=\"{{ !isIncludeExcludeNotAvailable(category) }}\"\n      [matTooltipPosition]=\"'above'\"\n      (click)=\"includeExcludeItem(category, true)\"\n    >\n      <span class=\"material-icons material-icons-outlined\">add_circle_outline</span>Include\n    </div>\n  </div>\n</div>\n<div *ngIf=\"category.isExpand\">\n  <single-cattax-category\n    *ngFor=\"let child of category.children\"\n    [category]=\"child\"\n    [selectedItems]=\"selectedItems\"\n    (changeSelected)=\"addToSelected($event)\"\n    (categoryExtended)=\"extendedCategory($event)\"\n  ></single-cattax-category>\n</div>\n", styles: ["mat-icon{font-size:var(--font-body-1);line-height:22px;cursor:pointer;height:16px;width:16px}.tree-item>span{padding-right:8px;padding-bottom:6px}.mat-checkbox{margin:0 8px}.tree{display:flex;min-height:21px;line-height:21px}.select-item{font-size:var(--font-medium-button);font-weight:var(--font-weight-semibold);line-height:18px;display:flex;margin-left:auto;border-bottom:1px solid var(--neutral-outline-variant-color);min-height:32px;margin-bottom:10px;gap:4px;padding-bottom:10px}.select-item>div{cursor:pointer}.select-item .include{display:inherit;line-height:21px;color:var(--light-success);height:30px}.select-item .exclude{display:inherit;line-height:21px;margin-right:24px;color:var(--error-default-color);height:30px}.select-item div.disabled{background-color:transparent;cursor:not-allowed;color:var(--neutral-on-disable-color)}.select-item div.disabled span.material-icons:hover{cursor:not-allowed}.tree-item{font-size:var(--font-body-2);font-weight:var(--font-weight-regular);line-height:21px;width:100%;display:flex;border-bottom:1px solid var(--neutral-outline-variant-color);margin-left:8px;padding:5px 0 16.5px;color:var(--neutral-on-main-neutral-color)}.tree-name{display:flex;margin-bottom:10px;width:100%;cursor:pointer;align-items:center}.tree-name span{margin-bottom:10.5px}\n"] }]
        }], propDecorators: { category: [{
                type: Input
            }], selectedItems: [{
                type: Input
            }], changeSelected: [{
                type: Output,
                args: ['changeSelected']
            }], categoryExtended: [{
                type: Output,
                args: ['categoryExtended']
            }] } });
//# sourceMappingURL=data:application/json;base64, 