/*
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 * as tslib_1 from "tslib";
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
 */
var CodeGeneratingComponentRendererHandlerEmitter = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(CodeGeneratingComponentRendererHandlerEmitter, _super);
    function CodeGeneratingComponentRendererHandlerEmitter(a, b) {
        var _this = _super.call(this) || this;
        _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);
        return _this;
    }
    Object.defineProperty(CodeGeneratingComponentRendererHandlerEmitter.prototype, "f", {
        get: function () {
            return this.e;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CodeGeneratingComponentRendererHandlerEmitter.prototype, "b", {
        get: function () {
            return this.a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CodeGeneratingComponentRendererHandlerEmitter.prototype, "d", {
        get: function () {
            return this.c;
        },
        enumerable: true,
        configurable: true
    });
    CodeGeneratingComponentRendererHandlerEmitter.prototype.j = function () {
        var a = new HashSet$1(String_$type, 0);
        for (var b = 0; b < this.e.t.count; b++) {
            var c = this.e.t._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);
                    var d = this.g.library.getItem(c.a.e);
                    if (d.type == 1) {
                        var e = d.getContentForPlatform(this.e.platform);
                        if (e != null) {
                            if (e.isJson) {
                                var f = new JsonDictionaryParser();
                                var g = f.parse(e.content);
                                if (g.g("imports")) {
                                    var h = g.item("imports").value;
                                    var i = stringReplace(h, "\r\n", "\n").split('\n');
                                    for (var k = 0; k < i.length; k++) {
                                        var 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")) {
                                    var l = g.item("handler").value;
                                    l = this.i(l);
                                    var m = stringReplace(l, "\r\n", "\n").split('\n');
                                    var n = 0x7FFFFFFF;
                                    var o = "";
                                    for (var p = 0; p < this.g.indentSpaces; p++) {
                                        o += " ";
                                    }
                                    for (var r = 0; r < m.length; r++) {
                                        var q = m[r];
                                        var s = q;
                                        if (s.trim().length == 0) {
                                            continue;
                                        }
                                        s = stringReplace(q, "\t", o);
                                        var t = 0;
                                        for (var u = 0; u < s.length; u++) {
                                            if (s.charAt(u) != ' ' && s.charAt(u) != '\t') {
                                                break;
                                            }
                                            t++;
                                        }
                                        if (t < n) {
                                            n = t;
                                        }
                                    }
                                    for (var w = 0; w < m.length; w++) {
                                        var v = m[w];
                                        var x = v;
                                        var 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 {
                                var z = e.content;
                                this.b.k(z);
                            }
                        }
                    }
                }
            }
        }
        this.e.addContainerResult("eventHandlers", this.b.toString());
        this.e.addImportResult("handlersImports", this.d);
    };
    CodeGeneratingComponentRendererHandlerEmitter.prototype.k = function (a, b) {
    };
    CodeGeneratingComponentRendererHandlerEmitter.prototype.i = function (a) {
        return a;
    };
    CodeGeneratingComponentRendererHandlerEmitter.$t = markType(CodeGeneratingComponentRendererHandlerEmitter, 'CodeGeneratingComponentRendererHandlerEmitter');
    return CodeGeneratingComponentRendererHandlerEmitter;
}(Base));
export { CodeGeneratingComponentRendererHandlerEmitter };
