/* global registerGlobalBackward, TraverseUtility */
registerGlobalBackward('1.12.8',function (theme) {
    'use strict';
    TraverseUtility.traverseControls(theme.controls, changeTransformRotate);
    TraverseUtility.traverseControls(theme.templates, changeTransformRotate);
    TraverseUtility.traverseControls(theme.prototypes, changeTransformRotate);

    function changeTransformRotate(control) {
        if (control.css && control.css['transform-rotate']) {
            var transformRotate = control.css['transform-rotate'];
            if (transformRotate) {
                var rotate = 'rotate(' + transformRotate + ')';
                var transform = control.css.transform;
                if (transform) {
                    if (transform.indexOf('rotate') === -1) {
                        transform += ' ' + rotate;
                    } else {
                        transform = transform.replace(/rotate\([^)]*\)/g, rotate);
                    }
                } else {
                    transform = rotate;
                }
            }
        }
    }
    return theme;
});