/**
 * Set guide index to theme data unless already exists.
 * @param {object[]} data - Theme data.
 * @returns {object[]} - Theme data with guide index.
 */
module.exports = function (data) {
    var keys = Object.keys(data),
        guideIndices = keys.map(function (key) {
            return data[key].guideIndex;
        }).filter(function (guideIndex) {
                return !!guideIndex;
            });

    function nextGuideIndex() {
        var index = 4;
        while (~guideIndices.indexOf(index)) {
            index++;
        }
        guideIndices.push(index);
        return index;
    }

    keys.forEach(function (key) {
        data[key].guideIndex = data[key].guideIndex || nextGuideIndex();
    });

    return data;
};