public static string WrapMediaQuery(this string cssRule, ResponsiveDevice responsiveDevice)
 {
     if (cssRule.Length > 0)
     {
         if (responsiveDevice.WidthThreshold > 0)
         {
             return($"@media(min-width:{responsiveDevice.WidthThreshold}px){{{cssRule}}}");
         }
     }
     return(cssRule);
 }
        public static void GenerateAndAppendCss(StyleMolecule styleMolecule, ResponsiveDevice responsiveDevice, ref string cssPerDevice)
        {
            string cssClassIdentifier       = $".s{styleMolecule.StyleMoleculeId}";
            Dictionary <string, string> css = new Dictionary <string, string>();                                                          // val => prop
            Dictionary <string, Dictionary <string, string> > stateModifiedCss = new Dictionary <string, Dictionary <string, string> >(); // pseudo => val => prop

            foreach (var map in styleMolecule.MappedStyleAtoms.Where(m => m.ResponsiveDeviceId == responsiveDevice.ResponsiveDeviceId))
            {
                Dictionary <string, string> targetDict;
                if (map.StateModifier == null)
                {
                    targetDict = css;
                }
                else
                {
                    if (!stateModifiedCss.ContainsKey(map.StateModifier))
                    {
                        targetDict = new Dictionary <string, string>();
                        stateModifiedCss[map.StateModifier] = targetDict;
                    }
                    else
                    {
                        targetDict = stateModifiedCss[map.StateModifier];
                    }
                }
                foreach (var val in map.StyleAtom.AppliedValues)
                {
                    if (!string.IsNullOrEmpty(val.CssValue))
                    {
                        targetDict[val.CssProperty] = val.CssValue;
                    }
                }
            }
            string cssString = string.Join(";", css.Select(kvp => $"{kvp.Key}:{kvp.Value}").Cast <string>());

            if (cssString.Length > 0)
            {
                cssPerDevice += $"{cssClassIdentifier}{{{cssString}}}";
            }
            foreach (var stateModifierKvp in stateModifiedCss) // TODO handle null / empty css value => auto set to default or something
            {
                var    pseudoDict      = stateModifierKvp.Value;
                string pseudoCssString = string.Join(";", pseudoDict.Select(kvp => $"{kvp.Key}:{kvp.Value}").Cast <string>());
                cssPerDevice += $"{cssClassIdentifier}{stateModifierKvp.Key}{{{pseudoCssString}}}";
            }
        }
        internal static void ApplyStyleAtomRange(this StyleMolecule styleMolecule, IEnumerable <StyleAtom> styleAtoms, ResponsiveDevice responsiveDevice, string stateModifier) // TEST cannot be called from service consumer outside solution or move into internalextensions
        {
            if (stateModifier != null && stateModifier == "")
            {
                throw new InvalidOperationException("Supplied state modifier may not be empty. Use null instead.");
            }

            foreach (var styleAtom in styleAtoms)
            {
                var styleMoleculeMapping = new StyleMoleculeAtomMapping()
                {
                    ResponsiveDevice = responsiveDevice,
                    StateModifier    = stateModifier
                };
                styleMolecule.MappedStyleAtoms.Add(styleMoleculeMapping);
                styleAtom.MappedToMolecule = styleMoleculeMapping;
            }
        }
 internal static void ApplyStyleAtom(this StyleMolecule styleMolecule, StyleAtom styleAtom, ResponsiveDevice responsiveDevice, string stateModifier)
 {
     styleMolecule.ApplyStyleAtomRange(new StyleAtom[] { styleAtom }, responsiveDevice, stateModifier);
 }