'use strict';

var Enum = require('./Enum.cjs');
var Utility = require('./Utility.cjs');

/**
 * @param {object[]} children
 * @param {function} callback
 * @return {string}
 */
function serialize (children, callback) {
	var output = '';
	var length = Utility.sizeof(children);

	for (var i = 0; i < length; i++)
		output += callback(children[i], i, children, callback) || '';

	return output
}

/**
 * @param {object} element
 * @param {number} index
 * @param {object[]} children
 * @param {function} callback
 * @return {string}
 */
function stringify (element, index, children, callback) {
	switch (element.type) {
		case Enum.LAYER: if (element.children.length) break
		case Enum.IMPORT: case Enum.DECLARATION: return element.return = element.return || element.value
		case Enum.COMMENT: return ''
		case Enum.KEYFRAMES: return element.return = element.value + '{' + serialize(element.children, callback) + '}'
		case Enum.RULESET: element.value = element.props.join(',');
	}

	return Utility.strlen(children = serialize(element.children, callback)) ? element.return = element.value + '{' + children + '}' : ''
}

exports.serialize = serialize;
exports.stringify = stringify;
//# sourceMappingURL=Serializer.cjs.map
