/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { Base, String_$type, markType } from "./type";
import { CodeGeneratingCodeWriter } from "./CodeGeneratingCodeWriter";
import { CodeGeneratingImportManager } from "./CodeGeneratingImportManager";
import { HashSet$1 } from "./HashSet$1";
import { JsonDictionaryParser } from "./JsonDictionaryParser";
import { stringReplace } from "./string";
/**
 * @hidden
 */
export let CodeGeneratingComponentRendererHandlerEmitter = /*@__PURE__*/ (() => {
    class CodeGeneratingComponentRendererHandlerEmitter extends Base {
        constructor(a, b) {
            super();
            this.g = null;
            this.e = null;
            this.a = null;
            this.c = new CodeGeneratingImportManager();
            this.h = new HashSet$1(String_$type, 0);
            this.g = a;
            this.e = b;
            this.a = new CodeGeneratingCodeWriter(this.g);
        }
        get f() {
            return this.e;
        }
        get b() {
            return this.a;
        }
        get d() {
            return this.c;
        }
        j() {
            let a = new HashSet$1(String_$type, 0);
            for (let b = 0; b < this.e.q.count; b++) {
                let c = this.e.q._inner[b];
                if (c.a != null && c.c == null) {
                    if (this.g.library != null && this.g.library.hasItem(c.a.e)) {
                        if (a.contains(c.a.e)) {
                            continue;
                        }
                        a.add_1(c.a.e);
                        let d = this.g.library.getItem(c.a.e);
                        if (d.type == 1) {
                            let e = d.getContentForPlatform(this.e.platform);
                            if (e != null) {
                                if (e.isJson) {
                                    let f = new JsonDictionaryParser();
                                    let g = f.parse(e.content);
                                    if (g.g("imports")) {
                                        let h = g.item("imports").value;
                                        let i = stringReplace(h, "\r\n", "\n").split('\n');
                                        for (let k = 0; k < i.length; k++) {
                                            let j = i[k];
                                            if (j.trim().length == 0) {
                                                continue;
                                            }
                                            if (!this.h.contains(j)) {
                                                this.h.add_1(j);
                                                this.k(this.d, j);
                                            }
                                        }
                                    }
                                    if (g.g("handler")) {
                                        let l = g.item("handler").value;
                                        l = this.i(l);
                                        let m = stringReplace(l, "\r\n", "\n").split('\n');
                                        let n = 0x7FFFFFFF;
                                        let o = "";
                                        for (let p = 0; p < this.g.indentSpaces; p++) {
                                            o += " ";
                                        }
                                        for (let r = 0; r < m.length; r++) {
                                            let q = m[r];
                                            let s = q;
                                            if (s.trim().length == 0) {
                                                continue;
                                            }
                                            s = stringReplace(q, "\t", o);
                                            let t = 0;
                                            for (let u = 0; u < s.length; u++) {
                                                if (s.charAt(u) != ' ' && s.charAt(u) != '\t') {
                                                    break;
                                                }
                                                t++;
                                            }
                                            if (t < n) {
                                                n = t;
                                            }
                                        }
                                        for (let w = 0; w < m.length; w++) {
                                            let v = m[w];
                                            let x = v;
                                            let y = 0;
                                            if (x.trim().length > 0) {
                                                while (x.length > 0 && (x.charAt(0) == ' ' || x.charAt(0) == '\t') && y < n) {
                                                    if (x.charAt(0) == ' ') {
                                                        x = x.substr(1);
                                                        y++;
                                                    }
                                                    if (x.charAt(0) == '\t') {
                                                        x = x.substr(1);
                                                        y += this.g.indentSpaces;
                                                    }
                                                }
                                            }
                                            this.b.k(x);
                                        }
                                    }
                                }
                                else {
                                    let z = e.content;
                                    this.b.k(z);
                                }
                            }
                        }
                    }
                }
            }
            this.e.addContainerResult("eventHandlers", this.b.toString());
            this.e.addImportResult("handlersImports", this.d);
        }
        k(a, b) {
        }
        i(a) {
            return a;
        }
    }
    CodeGeneratingComponentRendererHandlerEmitter.$t = markType(CodeGeneratingComponentRendererHandlerEmitter, 'CodeGeneratingComponentRendererHandlerEmitter');
    return CodeGeneratingComponentRendererHandlerEmitter;
})();
