import * as i3$2 from '@angular/cdk/drag-drop';
import { moveItemInArray, transferArrayItem, DragDropModule } from '@angular/cdk/drag-drop';
import * as i0 from '@angular/core';
import { EventEmitter, Injectable, Component, Input, Output, ContentChildren, NgModule } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { TemplateDirective, TemplateModule } from '@seniorsistemas/angular-components/template';
import * as i2 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i3 from '@angular/forms';
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import * as i4 from '@seniorsistemas/angular-components/tiered-menu';
import { TieredMenuModule } from '@seniorsistemas/angular-components/tiered-menu';
import * as i4$1 from '@seniorsistemas/angular-components/button';
import { ButtonModule } from '@seniorsistemas/angular-components/button';
import * as i2$1 from '@seniorsistemas/angular-components/badge';
import { BadgeModule } from '@seniorsistemas/angular-components/badge';
import * as i3$1 from '@ngx-translate/core';
import { TranslateModule } from '@ngx-translate/core';

class KanbanEventService {
    selectAllColumnItemsEvent = new EventEmitter();
    unselectAllColumnItemsEvent = new EventEmitter();
    selectItemEvent = new EventEmitter();
    unselectItemEvent = new EventEmitter();
    emitSelectAllColumnItemsEvent(column) {
        this.selectAllColumnItemsEvent.emit(column);
    }
    emitUnselectAllColumnItemsEvent(column) {
        this.unselectAllColumnItemsEvent.emit(column);
    }
    emitSelectItemEvent(item) {
        this.selectItemEvent.emit(item);
    }
    emitUnselectItemEvent(item) {
        this.unselectItemEvent.emit(item);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanEventService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanEventService });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanEventService, decorators: [{
            type: Injectable
        }] });

class KanbanItemComponent {
    _kanbanEventService;
    item;
    selected = false;
    showCheckbox = true;
    headerTemplate = null;
    bodyTemplate = null;
    footerTemplate = null;
    kanbanItemOptions = [];
    constructor(_kanbanEventService) {
        this._kanbanEventService = _kanbanEventService;
    }
    ngOnInit() {
        this._convertToTieredMenuItemData();
    }
    onSelectedChange(value) {
        if (value) {
            this._kanbanEventService.emitSelectItemEvent(this.item);
        }
        else {
            this._kanbanEventService.emitUnselectItemEvent(this.item);
        }
    }
    _convertToTieredMenuItemData() {
        if (!this.item.options)
            return;
        const options = [];
        this.item.options.forEach((option) => {
            options.push({
                ...option,
                command: () => option.command(this.item),
            });
        });
        this.kanbanItemOptions = options;
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanItemComponent, deps: [{ token: KanbanEventService }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.14", type: KanbanItemComponent, selector: "s-kanban-item", inputs: { item: "item", selected: "selected", showCheckbox: "showCheckbox", headerTemplate: "headerTemplate", bodyTemplate: "bodyTemplate", footerTemplate: "footerTemplate" }, ngImport: i0, template: "<div\n    class=\"kanban-item\"\n    [ngClass]=\"{\n        'kanban-item--selected': selected && !item.disabled,\n        'kanban-item--disabled': item.disabled,\n        'kanban-item--frozen': !item.disabled && item.frozen\n    }\">\n    <div class=\"kanban-item__header\">\n        <div class=\"content\">\n            <form>\n                <input\n                    *ngIf=\"showCheckbox && !item.disabled && !item.frozen\"\n                    type=\"checkbox\"\n                    name=\"checkbox\"\n                    [(ngModel)]=\"selected\"\n                    (ngModelChange)=\"onSelectedChange($event)\"\n                    (click)=\"$event.stopPropagation()\">\n            </form>\n            <ng-container *ngTemplateOutlet=\"headerTemplate; context: { $implicit: item }\"></ng-container>\n        </div>\n        <button\n            *ngIf=\"item.options && !item.disabled\"\n            class=\"options-button\"\n            (click)=\"$event.stopPropagation();\"\n            sTieredMenu\n            [items]=\"kanbanItemOptions\">\n            <i class=\"fas fa-ellipsis-v\"></i>\n        </button>\n    </div>\n    <div class=\"kanban-item__body\">\n        <ng-container *ngTemplateOutlet=\"bodyTemplate; context: { $implicit: item }\"></ng-container>\n    </div>\n    <div *ngIf=\"footerTemplate\" class=\"kanban-item__footer\">\n        <ng-container *ngTemplateOutlet=\"footerTemplate; context: { $implicit: item }\"></ng-container>     \n    </div>\n</div>\n", styles: [".kanban-item{background-color:#fff;border-radius:4px;box-shadow:0 1px 5px #00000040;cursor:pointer;display:flex;flex-direction:column;margin:16px;min-width:260px;padding:16px;-webkit-user-select:none;user-select:none}.kanban-item .kanban-item__header{display:flex;justify-content:space-between}.kanban-item .kanban-item__header .content{display:flex;gap:16px}.kanban-item .kanban-item__header .options-button{background-color:transparent;border:none;cursor:pointer;margin-right:-8px;padding:0 8px}.kanban-item .kanban-item__body{margin:16px 0}.kanban-item .kanban-item__footer{border-top:1px solid #dedce5;display:flex;justify-content:space-between}.kanban-item .kanban-item__footer .date-info{align-items:center;color:#6e7280;display:flex;font-family:\"Open Sans\" sans-serif;font-size:12px;gap:4px;line-height:150%}.kanban-item--selected{border:1px solid #428BCA}.kanban-item--disabled{opacity:50%}.kanban-item--frozen{box-shadow:none}\n"], dependencies: [{ kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i3.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i3.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i3.NgForm, selector: "form:not([ngNoForm]):not([formGroup]),ng-form,[ngForm]", inputs: ["ngFormOptions"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i4.TieredMenuDirective, selector: "[sTieredMenu]", inputs: ["items", "focusedItem", "triggerEvent"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanItemComponent, decorators: [{
            type: Component,
            args: [{ selector: "s-kanban-item", template: "<div\n    class=\"kanban-item\"\n    [ngClass]=\"{\n        'kanban-item--selected': selected && !item.disabled,\n        'kanban-item--disabled': item.disabled,\n        'kanban-item--frozen': !item.disabled && item.frozen\n    }\">\n    <div class=\"kanban-item__header\">\n        <div class=\"content\">\n            <form>\n                <input\n                    *ngIf=\"showCheckbox && !item.disabled && !item.frozen\"\n                    type=\"checkbox\"\n                    name=\"checkbox\"\n                    [(ngModel)]=\"selected\"\n                    (ngModelChange)=\"onSelectedChange($event)\"\n                    (click)=\"$event.stopPropagation()\">\n            </form>\n            <ng-container *ngTemplateOutlet=\"headerTemplate; context: { $implicit: item }\"></ng-container>\n        </div>\n        <button\n            *ngIf=\"item.options && !item.disabled\"\n            class=\"options-button\"\n            (click)=\"$event.stopPropagation();\"\n            sTieredMenu\n            [items]=\"kanbanItemOptions\">\n            <i class=\"fas fa-ellipsis-v\"></i>\n        </button>\n    </div>\n    <div class=\"kanban-item__body\">\n        <ng-container *ngTemplateOutlet=\"bodyTemplate; context: { $implicit: item }\"></ng-container>\n    </div>\n    <div *ngIf=\"footerTemplate\" class=\"kanban-item__footer\">\n        <ng-container *ngTemplateOutlet=\"footerTemplate; context: { $implicit: item }\"></ng-container>     \n    </div>\n</div>\n", styles: [".kanban-item{background-color:#fff;border-radius:4px;box-shadow:0 1px 5px #00000040;cursor:pointer;display:flex;flex-direction:column;margin:16px;min-width:260px;padding:16px;-webkit-user-select:none;user-select:none}.kanban-item .kanban-item__header{display:flex;justify-content:space-between}.kanban-item .kanban-item__header .content{display:flex;gap:16px}.kanban-item .kanban-item__header .options-button{background-color:transparent;border:none;cursor:pointer;margin-right:-8px;padding:0 8px}.kanban-item .kanban-item__body{margin:16px 0}.kanban-item .kanban-item__footer{border-top:1px solid #dedce5;display:flex;justify-content:space-between}.kanban-item .kanban-item__footer .date-info{align-items:center;color:#6e7280;display:flex;font-family:\"Open Sans\" sans-serif;font-size:12px;gap:4px;line-height:150%}.kanban-item--selected{border:1px solid #428BCA}.kanban-item--disabled{opacity:50%}.kanban-item--frozen{box-shadow:none}\n"] }]
        }], ctorParameters: () => [{ type: KanbanEventService }], propDecorators: { item: [{
                type: Input,
                args: [{ required: true }]
            }], selected: [{
                type: Input
            }], showCheckbox: [{
                type: Input
            }], headerTemplate: [{
                type: Input
            }], bodyTemplate: [{
                type: Input
            }], footerTemplate: [{
                type: Input
            }] } });

class KanbanColumnComponent {
    kanbanEventService;
    data;
    showCheckbox = true;
    headerTemplate = null;
    selectionControl = new FormControl(false);
    tieredMenuOptions;
    _unsubscribe$ = new Subject();
    constructor(kanbanEventService) {
        this.kanbanEventService = kanbanEventService;
    }
    ngOnInit() {
        this._validateInputs();
        this._subscriveEvents();
        this._createTieredOptions();
        this.tieredMenuOptions = this.data.options ? this.data.options : [];
    }
    ngOnDestroy() {
        this._unsubscribe$.next();
        this._unsubscribe$.complete();
    }
    _createTieredOptions() {
        if (!this.data.options)
            return;
        const options = [];
        this.data.options.forEach((option) => {
            options.push({
                ...option,
                command: () => { option.command(this.data); },
            });
        });
        this.data.options = options;
    }
    _subscriveEvents() {
        this.selectionControl.valueChanges
            .pipe(takeUntil(this._unsubscribe$))
            .subscribe((value) => {
            if (value) {
                this.kanbanEventService.emitSelectAllColumnItemsEvent(this.data);
            }
            else {
                this.kanbanEventService.emitUnselectAllColumnItemsEvent(this.data);
            }
        });
        this.kanbanEventService.unselectItemEvent
            .pipe(takeUntil(this._unsubscribe$))
            .subscribe((_) => {
            this.selectionControl.setValue(false, { emitEvent: false });
        });
        this.kanbanEventService.selectItemEvent
            .pipe(takeUntil(this._unsubscribe$))
            .subscribe((item) => {
            if (!this.data.items.includes(item)) {
                this.selectionControl.setValue(false, { emitEvent: false });
            }
        });
        this.kanbanEventService.selectAllColumnItemsEvent
            .pipe(takeUntil(this._unsubscribe$))
            .subscribe((column) => {
            if (this.data !== column) {
                this.selectionControl.setValue(false, { emitEvent: false });
            }
        });
        this.kanbanEventService.unselectAllColumnItemsEvent
            .pipe(takeUntil(this._unsubscribe$))
            .subscribe((column) => {
            if (this.data !== column) {
                this.selectionControl.setValue(false, { emitEvent: false });
            }
        });
    }
    _validateInputs() {
        if (!this.data) {
            throw new Error("data parameter is required");
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanColumnComponent, deps: [{ token: KanbanEventService }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: KanbanColumnComponent, selector: "s-kanban-column", inputs: { data: "data", showCheckbox: "showCheckbox", headerTemplate: "headerTemplate" }, ngImport: i0, template: "<div class=\"kanban-column\">\n    <div class=\"kanban-column__header\">\n        <div class=\"content\">\n            <form>\n                @if (showCheckbox) {\n                    <input\n                        type=\"checkbox\"\n                        name=\"checkbox\"\n                        [formControl]=\"selectionControl\"\n                    />\n                }\n            </form>\n\n            @if (!headerTemplate) {\n                <div class=\"header\">\n                    <span class=\"title\">{{ data.title }} ({{ data.items.length }})</span>\n                </div>\n            } @else {\n                <ng-container *ngTemplateOutlet=\"headerTemplate; context: { $implicit: data }\"></ng-container>\n            }\n        </div>\n        @if (data.options) {\n            <s-button\n                priority=\"default\"\n                [disabled]=\"false\"\n                [auxiliary]=\"true\"\n                size=\"small\"\n                [menuOptions]=\"tieredMenuOptions\"\n            >\n            </s-button>\n        }\n    </div>\n    <div class=\"kanban-column__body\">\n        <ng-content></ng-content>\n    </div>\n</div>\n", styles: [".kanban-column{align-items:center;background-color:#fbfafc;border:1px solid #dedce5;display:flex;flex-direction:column;height:100%;min-height:120px;-webkit-user-select:none;user-select:none;width:100%}.kanban-column .kanban-column__header{align-items:center;border-bottom:1px solid #dedce5;display:flex;justify-content:space-between;padding:16px 16px 8px;width:100%}.kanban-column .kanban-column__header .content{display:flex;gap:16px}.kanban-column .kanban-column__header .content .teste{display:flex;flex-direction:column;font-family:\"Open Sans\" sans-serif}.kanban-column .kanban-column__header .content .teste .title{font-size:14px;font-weight:800}.kanban-column .kanban-column__header .content .teste .description{font-size:12px}.kanban-column .kanban-column__body{display:flex;height:100%;justify-content:center;width:100%}\n"], dependencies: [{ kind: "directive", type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i3.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i3.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i3.NgForm, selector: "form:not([ngNoForm]):not([formGroup]),ng-form,[ngForm]", inputs: ["ngFormOptions"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i3.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: i4$1.ButtonComponent, selector: "s-button", inputs: ["id", "label", "tooltip", "tooltipPosition", "iconClass", "rightIconClass", "caret", "styleClass", "baseZIndex", "disabled", "auxiliary", "type", "priority", "menuOptions", "size", "slide", "animation", "badge", "iconColor"], outputs: ["clicked"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanColumnComponent, decorators: [{
            type: Component,
            args: [{ selector: "s-kanban-column", template: "<div class=\"kanban-column\">\n    <div class=\"kanban-column__header\">\n        <div class=\"content\">\n            <form>\n                @if (showCheckbox) {\n                    <input\n                        type=\"checkbox\"\n                        name=\"checkbox\"\n                        [formControl]=\"selectionControl\"\n                    />\n                }\n            </form>\n\n            @if (!headerTemplate) {\n                <div class=\"header\">\n                    <span class=\"title\">{{ data.title }} ({{ data.items.length }})</span>\n                </div>\n            } @else {\n                <ng-container *ngTemplateOutlet=\"headerTemplate; context: { $implicit: data }\"></ng-container>\n            }\n        </div>\n        @if (data.options) {\n            <s-button\n                priority=\"default\"\n                [disabled]=\"false\"\n                [auxiliary]=\"true\"\n                size=\"small\"\n                [menuOptions]=\"tieredMenuOptions\"\n            >\n            </s-button>\n        }\n    </div>\n    <div class=\"kanban-column__body\">\n        <ng-content></ng-content>\n    </div>\n</div>\n", styles: [".kanban-column{align-items:center;background-color:#fbfafc;border:1px solid #dedce5;display:flex;flex-direction:column;height:100%;min-height:120px;-webkit-user-select:none;user-select:none;width:100%}.kanban-column .kanban-column__header{align-items:center;border-bottom:1px solid #dedce5;display:flex;justify-content:space-between;padding:16px 16px 8px;width:100%}.kanban-column .kanban-column__header .content{display:flex;gap:16px}.kanban-column .kanban-column__header .content .teste{display:flex;flex-direction:column;font-family:\"Open Sans\" sans-serif}.kanban-column .kanban-column__header .content .teste .title{font-size:14px;font-weight:800}.kanban-column .kanban-column__header .content .teste .description{font-size:12px}.kanban-column .kanban-column__body{display:flex;height:100%;justify-content:center;width:100%}\n"] }]
        }], ctorParameters: () => [{ type: KanbanEventService }], propDecorators: { data: [{
                type: Input,
                args: [{ required: true }]
            }], showCheckbox: [{
                type: Input
            }], headerTemplate: [{
                type: Input
            }] } });

class KanbanItemDraggingComponent {
    quantityItems = 0;
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanItemDraggingComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.14", type: KanbanItemDraggingComponent, selector: "s-kanban-item-dragging", inputs: { quantityItems: "quantityItems" }, ngImport: i0, template: "<div class=\"kanban-item-dragging-container\">\n    <div\n        *ngIf=\"quantityItems\"\n        class=\"kanban-item-dragging\">\n    </div>\n\n    <div\n        class=\"kanban-item-dragging\"\n        [ngClass]=\"{ 'kanban-item-dragging--over': quantityItems }\">\n        <div class=\"content\">\n            <input type=\"checkbox\" checked />\n            <s-badge\n                [text]=\"'platform.angular_components.count_items_selected' | translate:{ count: quantityItems }\"\n                color=\"blue\">\n            </s-badge>\n        </div>\n    </div>\n\n</div>\n", styles: [".kanban-item-dragging-container:has(.kanban-item-dragging--over){padding-top:12px}.kanban-item-dragging{background-color:#fff;border:1px solid #428bca;border-radius:4px;box-shadow:0 1px 5px #00000040;height:52px;padding:16px;width:260px}.kanban-item-dragging .content{display:flex;gap:16px}.kanban-item-dragging--over{left:12px;position:relative;top:-64px}\n"], dependencies: [{ kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2$1.BadgeComponent, selector: "s-badge", inputs: ["type", "color", "title", "text", "selectable", "iconClass", "iconPosition", "infoSign", "enableTruncateText"], outputs: ["selected"] }, { kind: "pipe", type: i3$1.TranslatePipe, name: "translate" }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanItemDraggingComponent, decorators: [{
            type: Component,
            args: [{ selector: 's-kanban-item-dragging', template: "<div class=\"kanban-item-dragging-container\">\n    <div\n        *ngIf=\"quantityItems\"\n        class=\"kanban-item-dragging\">\n    </div>\n\n    <div\n        class=\"kanban-item-dragging\"\n        [ngClass]=\"{ 'kanban-item-dragging--over': quantityItems }\">\n        <div class=\"content\">\n            <input type=\"checkbox\" checked />\n            <s-badge\n                [text]=\"'platform.angular_components.count_items_selected' | translate:{ count: quantityItems }\"\n                color=\"blue\">\n            </s-badge>\n        </div>\n    </div>\n\n</div>\n", styles: [".kanban-item-dragging-container:has(.kanban-item-dragging--over){padding-top:12px}.kanban-item-dragging{background-color:#fff;border:1px solid #428bca;border-radius:4px;box-shadow:0 1px 5px #00000040;height:52px;padding:16px;width:260px}.kanban-item-dragging .content{display:flex;gap:16px}.kanban-item-dragging--over{left:12px;position:relative;top:-64px}\n"] }]
        }], propDecorators: { quantityItems: [{
                type: Input
            }] } });

class KanbanComponent {
    kanbanEventService;
    data;
    showItemCheckboxes = true;
    showColumnCheckboxes = true;
    itemsMoved = new EventEmitter();
    dataUpdated = new EventEmitter();
    itemsSelected = new EventEmitter();
    selectedColumn = null;
    selectedItems = new Set();
    draggingItems = new Set();
    columnHeaderTemplate = null;
    columnEmptyMessageTemplate = null;
    itemHeaderTemplate = null;
    itemBodyTemplate = null;
    itemFooterTemplate = null;
    _unsubscribe$ = new Subject();
    templates = null;
    constructor(kanbanEventService) {
        this.kanbanEventService = kanbanEventService;
    }
    ngOnInit() {
        this._subscribeEvents();
        this._normalizeData();
        this._validateInputs();
    }
    ngAfterContentInit() {
        this._getTemplates();
    }
    ngOnDestroy() {
        this._unsubscribe$.next();
        this._unsubscribe$.complete();
    }
    drop(event) {
        const previousColumn = this.data.columns.find((column) => column.id === event.previousContainer.id);
        const targetColumn = this.data.columns.find((column) => column.id === event.container.id);
        if (!previousColumn || !targetColumn) {
            throw new Error("Unable to obtain information about columns when performing drag and drop");
        }
        if (event.previousContainer === event.container) {
            moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
        }
        else {
            transferArrayItem(event.previousContainer.data, event.container.data, event.previousIndex, event.currentIndex);
        }
        this.selectedItems.forEach((item) => {
            const previousIndex = event.previousContainer.data.indexOf(item);
            if (previousIndex !== -1 && item !== event.item.data) {
                if (event.previousContainer === event.container) {
                    moveItemInArray(event.container.data, previousIndex, event.currentIndex);
                }
                else {
                    transferArrayItem(event.previousContainer.data, event.container.data, previousIndex, event.currentIndex);
                }
            }
        });
        this.selectedItems.add(event.item.data);
        this.itemsMoved.emit({
            items: [...this.selectedItems],
            previousColumn,
            targetColumn,
        });
        if (this.dataUpdated.observers?.length) {
            this.dataUpdated.emit({ ...this.data });
        }
        this.data.columns.forEach((column) => {
            this.kanbanEventService.emitUnselectAllColumnItemsEvent(column);
        });
        this.selectedItems.clear();
    }
    selectItem(event, item, column) {
        if (item.disabled || item.frozen)
            return;
        if (event.ctrlKey) {
            if (this.selectedItems.delete(item)) {
                this.kanbanEventService.emitUnselectItemEvent(item);
            }
            else {
                if (this.selectedColumn && !this.selectedColumn.items.includes(item)) {
                    this.selectedItems.clear();
                }
                this.selectedItems.add(item);
                this.selectedColumn = column;
                this.kanbanEventService.emitSelectItemEvent(item);
            }
        }
        else {
            if (this.selectedItems.delete(item))
                return;
            this.selectedItems.clear();
            this.selectedItems.add(item);
            this.selectedColumn = column;
            this.kanbanEventService.emitSelectItemEvent(item);
        }
    }
    dragStarted() {
        this.selectedItems.forEach((item) => {
            this.draggingItems.add(item);
        });
    }
    dragReleased() {
        this.draggingItems.clear();
    }
    getLinkedColumns(currentColumn) {
        return this.data.columns.filter((column) => column != currentColumn).map((column) => column.id ?? '');
    }
    getColumnHeaderTemplate() {
        return this._getCustomTemplate('column-header') ?? null;
    }
    getColumnEmptyMessageTemplate() {
        return this._getCustomTemplate('column-empty-message') ?? null;
    }
    getItemHeaderTemplate() {
        return this._getCustomTemplate('item-header') ?? null;
    }
    getItemBodyTemplate() {
        return this._getCustomTemplate('item-body') ?? null;
    }
    getItemFooterTemplate() {
        return this._getCustomTemplate('item-footer') ?? null;
    }
    _getCustomTemplate(type) {
        return this.templates?.find((template) => template.type === type)?.template ?? null;
    }
    _subscribeEvents() {
        this.kanbanEventService.selectAllColumnItemsEvent
            .pipe(takeUntil(this._unsubscribe$))
            .subscribe((column) => {
            column.items
                .filter((item) => !item.disabled && !item.frozen)
                .forEach((item) => {
                this.selectedItems.add(item);
            });
            this.selectedColumn = column;
            this.itemsSelected.emit([...this.selectedItems]);
        });
        this.kanbanEventService.unselectAllColumnItemsEvent
            .pipe(takeUntil(this._unsubscribe$))
            .subscribe((_) => {
            this.selectedItems.clear();
        });
        this.kanbanEventService.selectItemEvent
            .pipe(takeUntil(this._unsubscribe$))
            .subscribe((item) => {
            if (this.selectedColumn && !this.selectedColumn.items.includes(item)) {
                this.selectedItems.clear();
            }
            this.selectedItems.add(item);
            this.itemsSelected.emit([...this.selectedItems]);
            // Finding the item column and setting selectedColumn.
            this.data.columns.forEach((column) => {
                column.items.forEach((currentItem) => {
                    if (currentItem === item) {
                        this.selectedColumn = column;
                        return;
                    }
                });
            });
        });
        this.kanbanEventService.unselectItemEvent.pipe(takeUntil(this._unsubscribe$)).subscribe((item) => {
            this.selectedItems.delete(item);
        });
    }
    _normalizeData() {
        this.data.columns.forEach((column) => {
            column.id = column.id || `id-${Math.random().toString(36).substring(2, 9)}-${Date.now().toString(36)}`;
        });
    }
    _validateInputs() {
        const columns = this.data.columns;
        const columnIds = this.data.columns.map((column) => column.id);
        if (new Set(columnIds).size !== columns.length) {
            throw new Error("Repeated IDs are not accepted.");
        }
    }
    _getTemplates() {
        this.columnHeaderTemplate = this.getColumnHeaderTemplate();
        this.columnEmptyMessageTemplate = this.getColumnEmptyMessageTemplate();
        this.itemHeaderTemplate = this.getItemHeaderTemplate();
        this.itemBodyTemplate = this.getItemBodyTemplate();
        this.itemFooterTemplate = this.getItemFooterTemplate();
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanComponent, deps: [{ token: KanbanEventService }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: KanbanComponent, selector: "s-kanban", inputs: { data: "data", showItemCheckboxes: "showItemCheckboxes", showColumnCheckboxes: "showColumnCheckboxes" }, outputs: { itemsMoved: "itemsMoved", dataUpdated: "dataUpdated", itemsSelected: "itemsSelected" }, queries: [{ propertyName: "templates", predicate: TemplateDirective }], ngImport: i0, template: "<div class=\"kanban\">\n  <s-kanban-column\n    *ngFor=\"let column of data.columns\"\n    [data]=\"column\"\n    [showCheckbox]=\"showColumnCheckboxes\"\n    [headerTemplate]=\"columnHeaderTemplate\">\n    <div\n      [id]=\"column.id + ''\"\n      style=\"height: 100%; width: 100%;\"\n      cdkDropList\n      #dynamicList=\"cdkDropList\"\n      [cdkDropListData]=\"column.items\"\n      [cdkDropListConnectedTo]=\"getLinkedColumns(column)\"\n      (cdkDropListDropped)=\"drop($event)\">\n\n      @if (!columnEmptyMessageTemplate) {\n          <div *ngIf=\"!column.items.length\" class=\"empty-message\">\n            <p class=\"text\">\n              <span class=\"fas fa-clock\"></span>&nbsp;\n              <span>{{ \"platform.angular_components.count_items_in_target\" | translate:{ count: column.items.length, target: column.title } }}</span>\n            </p>\n          </div>\n      } @else {\n          <ng-container *ngTemplateOutlet=\"columnEmptyMessageTemplate; context: { $implicit: column }\"></ng-container>\n      }\n\n      <div\n        *ngFor=\"let item of column.items\"\n        cdkDrag\n        [cdkDragData]=\"item\"\n        [cdkDragDisabled]=\"item.disabled || item.frozen\"\n        (cdkDragStarted)=\"dragStarted()\"\n        (cdkDragReleased)=\"dragReleased()\"\n        (click)=\"selectItem($event, item, column)\">\n        \n        <ng-container *ngTemplateOutlet=\"itemTemplate\"></ng-container>\n\n        <ng-container *cdkDragPreview>\n          @if (selectedItems.size > 1) {\n              <s-kanban-item-dragging [quantityItems]=\"selectedItems.size\"></s-kanban-item-dragging>\n          } @else {\n            <ng-container *ngTemplateOutlet=\"itemTemplate\"></ng-container>\n          }\n\n        </ng-container>\n\n        <ng-template #itemTemplate>\n          <s-kanban-item\n              [item]=\"item\"\n              [selected]=\"selectedItems.has(item)\"\n              [showCheckbox]=\"showItemCheckboxes\"\n              [headerTemplate]=\"itemHeaderTemplate\"\n              [bodyTemplate]=\"itemBodyTemplate\"\n              [footerTemplate]=\"itemFooterTemplate\">\n            </s-kanban-item>\n        </ng-template>\n\n        <div *cdkDragPlaceholder>\n          <div class=\"placeholder\">\n            <div class=\"placeholder-line\"></div>\n          </div>\n        </div>\n      </div>\n    </div>\n  </s-kanban-column>\n</div>\n\n", styles: [".kanban{display:flex;gap:16px;overflow:auto;width:100%}.kanban .empty-message{display:flex;justify-content:center;margin:16px}.kanban .empty-message .text{overflow:hidden;text-align:center;text-overflow:ellipsis;width:100%;white-space:nowrap}@media screen and (max-width: 600px){.kanban{flex-direction:column}}s-kanban-column{display:flex;flex-grow:1;min-width:292px}.placeholder{display:flex;justify-content:center}.placeholder .placeholder-line{background-color:#a5a5b2;height:1px;margin:6px 0;width:50%}\n"], dependencies: [{ kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i3$2.CdkDropList, selector: "[cdkDropList], cdk-drop-list", inputs: ["cdkDropListConnectedTo", "cdkDropListData", "cdkDropListOrientation", "id", "cdkDropListLockAxis", "cdkDropListDisabled", "cdkDropListSortingDisabled", "cdkDropListEnterPredicate", "cdkDropListSortPredicate", "cdkDropListAutoScrollDisabled", "cdkDropListAutoScrollStep", "cdkDropListElementContainer"], outputs: ["cdkDropListDropped", "cdkDropListEntered", "cdkDropListExited", "cdkDropListSorted"], exportAs: ["cdkDropList"] }, { kind: "directive", type: i3$2.CdkDrag, selector: "[cdkDrag]", inputs: ["cdkDragData", "cdkDragLockAxis", "cdkDragRootElement", "cdkDragBoundary", "cdkDragStartDelay", "cdkDragFreeDragPosition", "cdkDragDisabled", "cdkDragConstrainPosition", "cdkDragPreviewClass", "cdkDragPreviewContainer", "cdkDragScale"], outputs: ["cdkDragStarted", "cdkDragReleased", "cdkDragEnded", "cdkDragEntered", "cdkDragExited", "cdkDragDropped", "cdkDragMoved"], exportAs: ["cdkDrag"] }, { kind: "directive", type: i3$2.CdkDragPreview, selector: "ng-template[cdkDragPreview]", inputs: ["data", "matchSize"] }, { kind: "directive", type: i3$2.CdkDragPlaceholder, selector: "ng-template[cdkDragPlaceholder]", inputs: ["data"] }, { kind: "component", type: KanbanItemComponent, selector: "s-kanban-item", inputs: ["item", "selected", "showCheckbox", "headerTemplate", "bodyTemplate", "footerTemplate"] }, { kind: "component", type: KanbanColumnComponent, selector: "s-kanban-column", inputs: ["data", "showCheckbox", "headerTemplate"] }, { kind: "component", type: KanbanItemDraggingComponent, selector: "s-kanban-item-dragging", inputs: ["quantityItems"] }, { kind: "pipe", type: i3$1.TranslatePipe, name: "translate" }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanComponent, decorators: [{
            type: Component,
            args: [{ selector: "s-kanban", template: "<div class=\"kanban\">\n  <s-kanban-column\n    *ngFor=\"let column of data.columns\"\n    [data]=\"column\"\n    [showCheckbox]=\"showColumnCheckboxes\"\n    [headerTemplate]=\"columnHeaderTemplate\">\n    <div\n      [id]=\"column.id + ''\"\n      style=\"height: 100%; width: 100%;\"\n      cdkDropList\n      #dynamicList=\"cdkDropList\"\n      [cdkDropListData]=\"column.items\"\n      [cdkDropListConnectedTo]=\"getLinkedColumns(column)\"\n      (cdkDropListDropped)=\"drop($event)\">\n\n      @if (!columnEmptyMessageTemplate) {\n          <div *ngIf=\"!column.items.length\" class=\"empty-message\">\n            <p class=\"text\">\n              <span class=\"fas fa-clock\"></span>&nbsp;\n              <span>{{ \"platform.angular_components.count_items_in_target\" | translate:{ count: column.items.length, target: column.title } }}</span>\n            </p>\n          </div>\n      } @else {\n          <ng-container *ngTemplateOutlet=\"columnEmptyMessageTemplate; context: { $implicit: column }\"></ng-container>\n      }\n\n      <div\n        *ngFor=\"let item of column.items\"\n        cdkDrag\n        [cdkDragData]=\"item\"\n        [cdkDragDisabled]=\"item.disabled || item.frozen\"\n        (cdkDragStarted)=\"dragStarted()\"\n        (cdkDragReleased)=\"dragReleased()\"\n        (click)=\"selectItem($event, item, column)\">\n        \n        <ng-container *ngTemplateOutlet=\"itemTemplate\"></ng-container>\n\n        <ng-container *cdkDragPreview>\n          @if (selectedItems.size > 1) {\n              <s-kanban-item-dragging [quantityItems]=\"selectedItems.size\"></s-kanban-item-dragging>\n          } @else {\n            <ng-container *ngTemplateOutlet=\"itemTemplate\"></ng-container>\n          }\n\n        </ng-container>\n\n        <ng-template #itemTemplate>\n          <s-kanban-item\n              [item]=\"item\"\n              [selected]=\"selectedItems.has(item)\"\n              [showCheckbox]=\"showItemCheckboxes\"\n              [headerTemplate]=\"itemHeaderTemplate\"\n              [bodyTemplate]=\"itemBodyTemplate\"\n              [footerTemplate]=\"itemFooterTemplate\">\n            </s-kanban-item>\n        </ng-template>\n\n        <div *cdkDragPlaceholder>\n          <div class=\"placeholder\">\n            <div class=\"placeholder-line\"></div>\n          </div>\n        </div>\n      </div>\n    </div>\n  </s-kanban-column>\n</div>\n\n", styles: [".kanban{display:flex;gap:16px;overflow:auto;width:100%}.kanban .empty-message{display:flex;justify-content:center;margin:16px}.kanban .empty-message .text{overflow:hidden;text-align:center;text-overflow:ellipsis;width:100%;white-space:nowrap}@media screen and (max-width: 600px){.kanban{flex-direction:column}}s-kanban-column{display:flex;flex-grow:1;min-width:292px}.placeholder{display:flex;justify-content:center}.placeholder .placeholder-line{background-color:#a5a5b2;height:1px;margin:6px 0;width:50%}\n"] }]
        }], ctorParameters: () => [{ type: KanbanEventService }], propDecorators: { data: [{
                type: Input,
                args: [{ required: true }]
            }], showItemCheckboxes: [{
                type: Input
            }], showColumnCheckboxes: [{
                type: Input
            }], itemsMoved: [{
                type: Output
            }], dataUpdated: [{
                type: Output
            }], itemsSelected: [{
                type: Output
            }], templates: [{
                type: ContentChildren,
                args: [TemplateDirective]
            }] } });

class KanbanModule {
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
    static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.14", ngImport: i0, type: KanbanModule, declarations: [KanbanComponent, KanbanItemComponent, KanbanColumnComponent, KanbanItemDraggingComponent], imports: [CommonModule,
            FormsModule,
            ReactiveFormsModule,
            TranslateModule,
            DragDropModule,
            BadgeModule,
            ButtonModule,
            TieredMenuModule,
            TemplateModule], exports: [KanbanComponent, TemplateModule] });
    static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanModule, providers: [KanbanEventService], imports: [CommonModule,
            FormsModule,
            ReactiveFormsModule,
            TranslateModule,
            DragDropModule,
            BadgeModule,
            ButtonModule,
            TieredMenuModule,
            TemplateModule, TemplateModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KanbanModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [
                        CommonModule,
                        FormsModule,
                        ReactiveFormsModule,
                        TranslateModule,
                        DragDropModule,
                        BadgeModule,
                        ButtonModule,
                        TieredMenuModule,
                        TemplateModule,
                    ],
                    declarations: [KanbanComponent, KanbanItemComponent, KanbanColumnComponent, KanbanItemDraggingComponent],
                    exports: [KanbanComponent, TemplateModule],
                    providers: [KanbanEventService],
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { KanbanComponent, KanbanModule };
//# sourceMappingURL=seniorsistemas-angular-components-kanban.mjs.map
