import Cache from './Cache';

const media = decl => decl.hasOwnProperty('media') ? decl.media : 'all';

export default function createGetClassName({ calculateRule, mediaOrder, cache }) {
  cache = new Cache(cache);
  const sortMedia = (d1, d2) => mediaOrder.indexOf(media(d1)) - mediaOrder.indexOf(media(d2));

  return sheet => function getClassName(decls) {
    const result = cache.get(decls);

    if (result.hasOwnProperty('newDecls')) {
      for (const decl of (mediaOrder ? result.newDecls.sort(sortMedia) : result.newDecls)) {
        const rule = calculateRule(decl.prop, decl.val);
        sheet.insert(
          media(decl),
          `.${decl.className}${decl.sel || ''}`,
          rule
        );
      }
    }

    return result.className;
  }
}

@@ -583,16 +583,18 @@
 decl.val
+ue
 );%0A     
@@ -673,14 +673,42 @@
 ecl.
-sel %7C%7C
+hasOwnProperty('sel') ? decl.sel :
  ''%7D

Support new css declaration