var css = require('css')
    _   = require('lodash');

var tcss = {};

tcss.extractSelectorNames = function(content) {
  var selectors = tcss.extractSelectors(content),
      classes = [],
      ids = [];

  selectors.forEach(function(selector) {
    var selectorName = selector.substring(1);
    if(selector.match(/\./) && !_.includes(classes, selectorName))
      classes.push(selectorName);
    if(selector.match(/#/) && !_.includes(ids, selectorName))
      ids.push(selectorName);
  });

  return { classes: classes, ids: ids };
}

tcss.extractSelectors = function(content) {
  var stylesheet = css.parse(content).stylesheet;
  return tcss.extractSelectorsFromRuleset(stylesheet.rules);
}

tcss.extractSelectorsFromRuleset = function(ruleset) {
  return ruleset.reduce(function(selectors, rule) {
    if(rule.type === 'media') {
      return selectors.concat(tcss.extractSelectorsFromRuleset(rule.rules));
    }
    else if(rule.type !== 'rule') return selectors;

    return selectors.concat(rule.selectors.reduce(function(prev, selector) {
      var matches = selector.match(/[.#]{1}[-_a-z0-9]+/gi);
      if(!matches) return prev;
      return prev.concat(matches);
    }, []));
  }, []);
}

tcss.createAliases = function(identifiers) {
  var aliases = {classes: {}, ids: {}};
  var incr = 0;

  identifiers.classes.forEach(function(klass) {
    aliases.classes[klass] = "t" + incr;
    incr++;
  });

  identifiers.ids.forEach(function(id) {
    aliases.ids[id] = "t" + incr;
    incr++;
  });

  return aliases;
}

module.exports = tcss;

@@ -1293,16 +1293,33 @@
 ncr = 0;
+%0A  var radix = 36
 %0A%0A  iden
@@ -1391,32 +1391,48 @@
 ss%5D = %22t%22 + incr
+.toString(radix)
 ;%0A    incr++;%0A  
@@ -1473,24 +1473,24 @@
 ction(id) %7B%0A
-
     aliases.
@@ -1509,16 +1509,32 @@
 %22 + incr
+.toString(radix)
 ;%0A    in

Use base36 for identifiers