import * as i0 from '@angular/core';
import { ViewChild, Component } from '@angular/core';
import { W as WtoolboxService, M as MetadataProviderService } from './wuic-framework-lib-wuic-framework-lib-DJZAYFw8.mjs';
import * as i3 from 'stimulsoft-designer-angular';
import { StimulsoftDesignerModule, StimulsoftDesignerComponent } from 'stimulsoft-designer-angular';
import * as i1 from '@angular/router';
import { NavigationEnd } from '@angular/router';
import { e as ensureWuicStimulsoftLicenseRegistered } from './wuic-framework-lib-stimulsoft-license.service-BIyxB4pO.mjs';

class ReportDesignerComponent {
    router;
    aRoute;
    metaSrv;
    /**
     * Vedi commento equivalente in `report-viewer.component.ts`: registra la
     * Stimulsoft license al primo mount del designer (lazy-load del chunk
     * `stimulsoft-reports-js` che pesa ~5.4 MB / 12.7 MB raw).
     */
    ngOnInit() {
        void ensureWuicStimulsoftLicenseRegistered();
    }
    /**
     * Riferimento a elementi o componenti figli usato dalla logica UI per designer.
     */
    designer;
    /**
     * Proprieta di stato del componente per request url, usata dalla logica interna e dal template.
     */
    requestUrl;
    /**
     * Proprieta di stato del componente per base request url, usata dalla logica interna e dal template.
     */
    baseRequestUrl;
    /**
     * Proprieta di stato del componente per route, usata dalla logica interna e dal template.
     */
    route;
    /**
     * Valore corrente selezionato per current report, usato dai flussi interattivi del componente.
     */
    currentReport;
    /**
     * Proprieta di stato del componente per router events subscription, usata dalla logica interna e dal template.
     */
    routerEventsSubscription;
    /**
     * Proprieta di stato del componente per designer bootstrap interval, usata dalla logica interna e dal template.
     */
    designerBootstrapInterval;
    reportCacheInvalidationTimer;
    /**
   * function Object() { [native code] }
   * @param router Informazioni di routing usate per comporre o risolvere la navigazione.
   * @param aRoute Informazioni di routing usate per comporre o risolvere la navigazione.
   */
    constructor(router, aRoute, metaSrv) {
        this.router = router;
        this.aRoute = aRoute;
        this.metaSrv = metaSrv;
        this.baseRequestUrl = WtoolboxService.appSettings.api_url + 'ReportDesigner';
        this.requestUrl = WtoolboxService.appSettings.api_url + 'ReportDesigner';
        this.syncRequestUrl();
        this.routerEventsSubscription = this.router.events.subscribe((val) => {
            if (val instanceof NavigationEnd) {
                this.syncRequestUrl();
            }
        });
    }
    /**
* Esegue operazioni di persistenza/sincronizzazione in `syncRequestUrl` allineando lo stato con parametri route/query.
*/
    syncRequestUrl() {
        this.route = this.aRoute.snapshot.paramMap.get('route');
        const reportName = this.aRoute.snapshot.queryParamMap.get('reportName');
        this.currentReport = reportName || '';
        this.requestUrl = this.baseRequestUrl + '?route=' + this.route
            + (reportName ? '&reportName=' + encodeURIComponent(reportName) : '');
    }
    /**
* Gestisce la logica di `fix` con il flusso specifico definito dalla sua implementazione.
*/
    fix() {
        let designer = this.designer;
        debugger;
    }
    /**
     * Completa inizializzazione dopo il rendering della view e collega riferimenti UI.
     *
     * NOTE: <stimulsoft-designer-angular> is now wrapped in @defer (on immediate)
     * in the template — so the @ViewChild reference (`this.designer`) may not be
     * resolved yet when ngAfterViewInit first fires. The bootstrap interval below
     * already polls for readiness, but we guard the initial access too.
     */
    ngAfterViewInit() {
        let self = this;
        this.designerBootstrapInterval = setInterval(() => {
            if (!this.designer) {
                return; // @defer block hasn't rendered yet
            }
            if (this.designer.designerEl?.nativeElement && this.designer.designerEl.nativeElement.style.height !== "100%") {
                this.designer.designerEl.nativeElement.style.height = "100%";
            }
            if (this.designer.designer) {
                if (this.designer.designerEl.nativeElement.getElementsByClassName("stiChildWorkPanel stiWorkPanelScrollContainer").length > 0) {
                    if (this.designer.designerEl.nativeElement.getElementsByClassName("stiChildWorkPanel stiWorkPanelScrollContainer")[0].getElementsByTagName("table").length > 0) {
                        if (this.designerBootstrapInterval) {
                            clearInterval(this.designerBootstrapInterval);
                            this.designerBootstrapInterval = undefined;
                        }
                        let tr = this.designer.designerEl.nativeElement.getElementsByClassName("stiChildWorkPanel stiWorkPanelScrollContainer")[0].getElementsByTagName("table")[0].getElementsByTagName("tr")[0];
                        let saveBtn = tr.children[0];
                        saveBtn.addEventListener("click", () => {
                            if (this.reportCacheInvalidationTimer) {
                                clearTimeout(this.reportCacheInvalidationTimer);
                            }
                            // Delay breve per lasciare al designer il tempo di completare la save lato backend.
                            this.reportCacheInvalidationTimer = setTimeout(() => {
                                this.metaSrv.invalidateReportListCache(this.route);
                            }, 400);
                        });
                        let cloned = saveBtn.cloneNode(true);
                        cloned.id = "saveAsBtn";
                        saveBtn.parentElement.prepend(cloned);
                        cloned.getElementsByTagName("table")[0].getElementsByTagName("tr")[2].getElementsByTagName("td")[0].innerText = "Save As";
                        setTimeout(() => {
                            cloned.className = "stiDesignerStandartBigButton stiDesignerStandartBigButton_Mouse stiDesignerStandartBigButtonDefault";
                        }, 200);
                        cloned.onclick = () => {
                            debugger;
                            //ask name -> save copy of current
                            //change requestUrl and reload
                        };
                        let td = document.createElement("td");
                        td.className = "stiDesignerClearAllStyles";
                        let div = document.createElement("div");
                        div.className = "stiDesignerGroupBlock";
                        let div2 = document.createElement("div");
                        div2.className = "stiDesignerGroupBlockContainer";
                        let formElement = document.createElement("select");
                        formElement.className = "stiDesignerTextBox stiDesignerTextBoxDefault";
                        let optionElement = document.createElement("option");
                        optionElement.value = "foo";
                        optionElement.text = "foo";
                        optionElement.selected = true;
                        formElement.appendChild(optionElement);
                        optionElement = document.createElement("option");
                        optionElement.value = "foo2";
                        optionElement.text = "foo2";
                        optionElement.selected = false;
                        formElement.appendChild(optionElement);
                        formElement.id = "bar";
                        td.appendChild(div);
                        div.appendChild(div2);
                        div2.appendChild(formElement);
                        formElement.onchange = () => {
                            debugger;
                            //set current report
                            self.currentReport = formElement.value;
                            //change requestUrl and reload
                            this.requestUrl = this.baseRequestUrl + '?route=' + this.route + '&reportName=' + self.currentReport;
                        };
                        tr.prepend(td);
                    }
                }
            }
        }, 500);
    }
    /**
     * Rilascia risorse e sottoscrizioni per evitare leak e stati pendenti.
     */
    ngOnDestroy() {
        this.routerEventsSubscription?.unsubscribe();
        if (this.designerBootstrapInterval) {
            clearInterval(this.designerBootstrapInterval);
            this.designerBootstrapInterval = undefined;
        }
        if (this.reportCacheInvalidationTimer) {
            clearTimeout(this.reportCacheInvalidationTimer);
            this.reportCacheInvalidationTimer = undefined;
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ReportDesignerComponent, deps: [{ token: i1.Router }, { token: i1.ActivatedRoute }, { token: MetadataProviderService }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.9", type: ReportDesignerComponent, isStandalone: true, selector: "wuic-report-designer", viewQueries: [{ propertyName: "designer", first: true, predicate: StimulsoftDesignerComponent, descendants: true }], ngImport: i0, template: "<!-- <button (click)=\"fix()\">Fix</button> -->\r\n@defer (on immediate) {\r\n  <stimulsoft-designer-angular #designer [requestUrl]=\"requestUrl\" [width]=\"'100%'\"\r\n      [height]=\"'100%'\"></stimulsoft-designer-angular>\r\n} @placeholder {\r\n  <div class=\"stimulsoft-loading-placeholder\">\r\n    <i class=\"pi pi-spin pi-spinner\"></i>\r\n    <span>Caricamento Report Designer\u2026</span>\r\n    <small>Il SDK Stimulsoft \u00E8 in download (~16 MB). Operazione una tantum.</small>\r\n  </div>\r\n} @loading (minimum 300ms) {\r\n  <div class=\"stimulsoft-loading-placeholder\">\r\n    <i class=\"pi pi-spin pi-spinner\"></i>\r\n    <span>Inizializzazione editor\u2026</span>\r\n  </div>\r\n} @error {\r\n  <div class=\"stimulsoft-error-placeholder\">\r\n    <i class=\"pi pi-exclamation-triangle\"></i>\r\n    <span>Errore nel caricamento del Report Designer. Verifica connessione e ricarica la pagina.</span>\r\n  </div>\r\n}", styles: [":host{display:flex;width:100%;height:100%;min-height:0;flex:1 1 auto}:host ::ng-deep stimulsoft-designer-angular{display:block;width:100%;height:100%;min-height:0;flex:1 1 auto}:host ::ng-deep .stiDesignerMainPanel,:host ::ng-deep .stiDesignerMainPanel *{box-sizing:border-box}:host ::ng-deep .stiDesignerMainPanel{height:100%!important;min-height:0!important}.stimulsoft-loading-placeholder,.stimulsoft-error-placeholder{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;width:100%;height:100%;min-height:400px;color:#64748b;font-size:1rem;background:#f8fafc;border:1px dashed #cbd5e1;border-radius:8px}.stimulsoft-loading-placeholder .pi-spinner{font-size:2rem;color:#6366f1}.stimulsoft-loading-placeholder small{font-size:.8rem;color:#94a3b8;max-width:400px;text-align:center}.stimulsoft-error-placeholder{color:#b91c1c;background:#fef2f2;border-color:#fecaca}.stimulsoft-error-placeholder .pi-exclamation-triangle{font-size:2rem}\n"], dependencies: [{ kind: "ngmodule", type: StimulsoftDesignerModule }], deferBlockDependencies: [() => [i3.StimulsoftDesignerComponent]] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ReportDesignerComponent, decorators: [{
            type: Component,
            args: [{ selector: 'wuic-report-designer', imports: [StimulsoftDesignerModule], template: "<!-- <button (click)=\"fix()\">Fix</button> -->\r\n@defer (on immediate) {\r\n  <stimulsoft-designer-angular #designer [requestUrl]=\"requestUrl\" [width]=\"'100%'\"\r\n      [height]=\"'100%'\"></stimulsoft-designer-angular>\r\n} @placeholder {\r\n  <div class=\"stimulsoft-loading-placeholder\">\r\n    <i class=\"pi pi-spin pi-spinner\"></i>\r\n    <span>Caricamento Report Designer\u2026</span>\r\n    <small>Il SDK Stimulsoft \u00E8 in download (~16 MB). Operazione una tantum.</small>\r\n  </div>\r\n} @loading (minimum 300ms) {\r\n  <div class=\"stimulsoft-loading-placeholder\">\r\n    <i class=\"pi pi-spin pi-spinner\"></i>\r\n    <span>Inizializzazione editor\u2026</span>\r\n  </div>\r\n} @error {\r\n  <div class=\"stimulsoft-error-placeholder\">\r\n    <i class=\"pi pi-exclamation-triangle\"></i>\r\n    <span>Errore nel caricamento del Report Designer. Verifica connessione e ricarica la pagina.</span>\r\n  </div>\r\n}", styles: [":host{display:flex;width:100%;height:100%;min-height:0;flex:1 1 auto}:host ::ng-deep stimulsoft-designer-angular{display:block;width:100%;height:100%;min-height:0;flex:1 1 auto}:host ::ng-deep .stiDesignerMainPanel,:host ::ng-deep .stiDesignerMainPanel *{box-sizing:border-box}:host ::ng-deep .stiDesignerMainPanel{height:100%!important;min-height:0!important}.stimulsoft-loading-placeholder,.stimulsoft-error-placeholder{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;width:100%;height:100%;min-height:400px;color:#64748b;font-size:1rem;background:#f8fafc;border:1px dashed #cbd5e1;border-radius:8px}.stimulsoft-loading-placeholder .pi-spinner{font-size:2rem;color:#6366f1}.stimulsoft-loading-placeholder small{font-size:.8rem;color:#94a3b8;max-width:400px;text-align:center}.stimulsoft-error-placeholder{color:#b91c1c;background:#fef2f2;border-color:#fecaca}.stimulsoft-error-placeholder .pi-exclamation-triangle{font-size:2rem}\n"] }]
        }], ctorParameters: () => [{ type: i1.Router }, { type: i1.ActivatedRoute }, { type: MetadataProviderService }], propDecorators: { designer: [{
                type: ViewChild,
                args: [StimulsoftDesignerComponent]
            }] } });

export { ReportDesignerComponent };
//# sourceMappingURL=wuic-framework-lib-report-designer.component-3-hUYft8.mjs.map
