"use strict";
angular.module('monsart').directive('maMediaStyle', function () {
    return {
        restrict: 'A',
        link: function (scope, elem, attrs) {
            var $elem = angular.element(elem);

            var params = eval('(' + attrs.maMediaStyle + ')');
            var screenWidth = angular.element('#preview-screen').width();
            var shouldDisable = function (screen) {
                if (params.lte && params.lte < screen) {
                    return true;
                }
                if (params.gte && params.gte > screen) {
                    return true;
                }
                return false;
            };
            scope.$on('screen.changed', function (event, data) {
                var width = data === '100%' ? screenWidth : parseInt(data);

                if (shouldDisable(width)) {
                    $elem.context.disabled = true;
                } else {
                    $elem.context.disabled = false;
                }

            });
            if (shouldDisable(screenWidth)) {

                $elem.context.disabled = true;

            }


        }

    }
});