(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "../../core/StringHelper"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.AtomStyle = void 0;
    var StringHelper_1 = require("../../core/StringHelper");
    var emptyPrototype = Object.getPrototypeOf({});
    var AtomStyle = /** @class */ (function () {
        function AtomStyle(styleSheet, name) {
            this.styleSheet = styleSheet;
            this.name = name;
            this.styleText = null;
            this.name = this.name + "-root";
        }
        AtomStyle.prototype.getBaseProperty = function (tc, name) {
            var c = tc;
            do {
                c = Object.getPrototypeOf(c);
                if (!c) {
                    throw new Error("No property descriptor found for " + name);
                }
                var pd = Object.getOwnPropertyDescriptor(c.prototype, name);
                if (!pd) {
                    continue;
                }
                return pd.get.apply(this);
            } while (true);
        };
        AtomStyle.prototype.build = function () {
            if (this.styleText) {
                return;
            }
            this.styleText = this.createStyleText("", [], this.root).join("\n");
        };
        AtomStyle.prototype.toString = function () {
            return this.styleText;
        };
        AtomStyle.prototype.createStyleText = function (name, pairs, styles) {
            var styleList = [];
            for (var key in styles) {
                if (styles.hasOwnProperty(key)) {
                    if (/^(\_\$\_|className$|toString$)/i.test(key)) {
                        continue;
                    }
                    var element = styles[key];
                    if (element === undefined || element === null) {
                        continue;
                    }
                    var keyName = StringHelper_1.StringHelper.fromCamelToHyphen(key);
                    if (key === "subclasses") {
                        var n = name;
                        for (var subclassKey in element) {
                            if (element.hasOwnProperty(subclassKey)) {
                                var ve = element[subclassKey];
                                pairs = this.createStyleText("" + n + subclassKey, pairs, ve);
                            }
                        }
                    }
                    else {
                        if (element.url) {
                            styleList.push(keyName + ": url(" + element + ")");
                        }
                        else {
                            styleList.push(keyName + ": " + element);
                        }
                    }
                }
            }
            var cname = StringHelper_1.StringHelper.fromCamelToHyphen(name);
            var styleClassName = "" + this.name + cname;
            if (styleList.length) {
                pairs.push("." + styleClassName + " { " + styleList.join(";\r\n") + "; }");
            }
            return pairs;
        };
        return AtomStyle;
    }());
    exports.AtomStyle = AtomStyle;
});
//# sourceMappingURL=AtomStyle.js.map