class styleguideView extends WindozDomContent {
    
    DOMContentLoaded() { 

        // building icon list
        let iconList = this.find('ul.icon-list');
        let sheet = null;

        for(let i = 0; document.styleSheets.length; i++) {
            let rule = document.styleSheets[i];
            if(rule) {
                let rules
                try { rules = rule.cssRules }
                catch(err) { rules = [] }
                for(let r = 0; r < rules.length; r++) {
                    let islocal = rule.href && ( (new URL(rule.href)).host == document.location.host); 
                    if( (rules.item(r).styleSheet) && islocal) {
                        sheet = rules.item(r).styleSheet;
                    }       
                }
            } else {
                break;
            }
        }
        
        if(sheet) {
            let classes = [];
            for(let i = 0; i < sheet.rules.length; i++) {
                let rule = sheet.rules.item(i);
                if(rule.selectorText && rule.selectorText.indexOf('.icon-') == 0) {
                    classes.push(rule.selectorText.replace('.', '').replace('::before', ''))
                }
            } 

            classes.sort();
            for(let i = 0; i < classes.length; i++) {
                let cls = classes[i];
                iconList.appendChild(ui.create(`<li><i medium class="${cls}"></i><label>${cls.replace('icon-', '')}</label></li>`))
            }
        }

        ui.eicfy(this.el);
    }
}

app.registerClass('styleguideView', styleguideView)