import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import * as i0 from "@angular/core";
/**
 * Service that serves as communication bus for dnd
 */
export class DndBusService {
    constructor() {
        //######################### protected fields #########################
        /**
         * Used for emitting drop data changes
         */
        this.dropDataChangeSubject = new Subject();
        /**
         * Current value of drop placeholder preview
         */
        this.dropPlaceholderPreview = null;
        /**
         * Used for emitting when new drop placeholder preview should be displayed
         */
        this.newDropPlaceholderPreviewSubject = new Subject();
        /**
         * Used for emitting when old drop placeholder preview should be removed
         */
        this.oldDropPlaceholderPreviewSubject = new Subject();
    }
    //######################### public properties #########################
    /**
     * Occurs when drop data changes
     */
    get dropDataChange() {
        return this.dropDataChangeSubject.asObservable();
    }
    /**
     * Occurs when new drop placeholder preview should be displayed
     */
    get newDropPlaceholderPreviewChange() {
        return this.newDropPlaceholderPreviewSubject
            .asObservable();
    }
    /**
     * Occurs when old drop placeholder preview should be removed
     */
    get oldDropPlaceholderPreviewChange() {
        return this.oldDropPlaceholderPreviewSubject
            .asObservable();
    }
    /**
     * Gets current drop placeholder preview index
     */
    get dropPlaceholderPreviewIndex() {
        return this.dropPlaceholderPreview?.index ?? null;
    }
    //######################### public methods #########################
    /**
     * Sets drop data new value
     * @param data - Value of data that changed
     */
    setDropData(data) {
        this.dropDataChangeSubject.next(data);
    }
    /**
     * Sets drop placeholder preview
     * @param data - Data for new drop placeholder preview
     */
    setDropPlaceholderPreview(data) {
        //nothing has changed
        if (data?.index === this.dropPlaceholderPreview?.index && data?.parentId === this.dropPlaceholderPreview?.parentId) {
            return;
        }
        if (this.dropPlaceholderPreview) {
            this.oldDropPlaceholderPreviewSubject.next(this.dropPlaceholderPreview);
        }
        this.dropPlaceholderPreview = data;
        if (this.dropPlaceholderPreview) {
            this.newDropPlaceholderPreviewSubject.next(this.dropPlaceholderPreview);
        }
    }
}
DndBusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: DndBusService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
DndBusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: DndBusService });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: DndBusService, decorators: [{
            type: Injectable
        }] });
//# sourceMappingURL=dndBus.service.js.map