/*

	Copyright (c) 2020, 2023, The Unified Company.

	This code is part of Unify.

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE,
	as published by the Free Software Foundation.
	See the GNU AFFERO GENERAL PUBLIC LICENSE, for more details.

	https://unifyjs.org 

*/

import tools	 		from './tools.js';

export default class cssManager{

	rules = new Array();
	
	addRule( selector, body ) {
	
		var rule = new Object();
		
		rule.selector	= selector;
		rule.body		= body;
		
		this.rules[ selector ] = body;

	}
	
	composeCss( selector, body ) {
	
		if( body == "") {
		
			return "";
		
		}

		return "\n" + selector + "{ " + "\n" + body + "\n" + " } " + "\n";
	
	}
	
	getRule( selector, body ) {

		selector = tools.cleanRollup( selector );
	
		if( this.rules[ selector ] ) {
		
			return "";
		
		} else {

			this.addRule( selector, body );
			
			return this.composeCss( selector, body );

		}

	}

}
