import numProperties from '../object/numProperties.js';
import iterate from '../loop/iterate.js';
/**
 * Adds the given color to the object bbn.data.colors in order to be able to use
 * the css classes bbn-bg-myColor for the background and bbn-myColor for the text color.
 *
 * @method   addColors
 * @global
 * @example
 * ```javascript
 * //<div class="bbn-bg-maroon">background</div> <span class="bbn-maroon">text color</span>
 * bbn.fn.addColors({maroon: '#800000'});
 * ```
 * @memberof bbn.fn
 * @param    {Object} colors
 * @returns
 */
export default function addColors(colors) {
    if (numProperties(colors)) {
        if (!bbn.data.colors) {
            bbn.data.colors = {};
        }
        let element = document.createElement("style");
        document.head.appendChild(element);
        let sheet = element.sheet;
        // Append style element to head
        let i = 0;
        iterate(colors, (v, n) => {
            bbn.data.colors[n] = v;
            sheet.insertRule(".bbn-" +
                n +
                ", .bbn-color-text-" +
                n +
                " {color: " +
                v +
                " !important;}", i);
            sheet.insertRule("svg.bbn-" +
                n +
                ", .bbn-" +
                n +
                " svg, svg.bbn-color-text-" +
                n +
                ", .bbn-color-text-" +
                n +
                " svg {fill: " +
                v +
                ";}", i);
            sheet.insertRule(".bbn-bg-" +
                n +
                ", .bbn-color-bg-" +
                n +
                ", .bbn-color-background-" +
                n +
                " {background-color: " +
                v +
                " !important;}", i);
            sheet.insertRule(".bbn-border-" +
                n +
                ", .bbn-color-border-" +
                n +
                " {border-color: " +
                v +
                " !important;}", i);
            sheet.insertRule(".bbn-color-" +
                n +
                " {border-color: " +
                v +
                "; background-color: " +
                v +
                "; color: " +
                v +
                ";}", i);
        });
    }
}
;
