
"use strict";

export default ['$route', $route => {

    function found(element, path, args) {
        for (let a in args) {
            path = path.replace(':' + a, args[a]);
        }
        element.attr('href', '#' + path.replace(/^#/, ''));
    };

    return {
        restrict: 'A',
        link: (scope, element, attrs) => {
            if (!(attrs.moPath)) {
                return;
            }
            let path = scope.$eval(attrs.moPath);
            if (!path) {
                return;
            }
            let args = attrs['arguments'] ? scope.$eval(attrs['arguments']) : {};
            if ($route.current && $route.current.params && $route.current.params.language) {
                args.language = args.language || $route.current.params.language;
            } else {
                args.language = args.language || 'en';
            }
            for (let _path in $route.routes) {
                let _pC = ($route.routes[_path].controller || '') + '';
                if (_pC.toLowerCase() == path.toLowerCase()) {
                    return found(element, _path, args);
                }
            }
            return found(element, path, args);
        }
    };
}];


@@ -35,22 +35,72 @@
 route', 
-$route
+'$location', 'languages', ($route, $location, languages)
  =%3E %7B%0A%0A 
@@ -394,117 +394,245 @@
     
-if (!(attrs.moPath)) %7B%0A                return;%0A            %7D%0A            let path = scope.$eval(attrs.moPath)
+let params = $route.current ? $route.current.params : %7B%7D;%0A            let original = $route.current ? $route.current.originalPath : $location.path().replace(/%5E%5C/%5Ba-z%5D%7B2%7D%5C//, '/:language/');%0A            let path = attrs.moPath %7C%7C original
 ;%0A  
@@ -794,66 +794,8 @@
 if (
-$route.current && $route.current.params && $route.current.
 para
@@ -858,31 +858,16 @@
 uage %7C%7C 
-$route.current.
 params.l
@@ -949,12 +949,20 @@
  %7C%7C 
-'en'
+languages%5B0%5D
 ;%0A  

add sensible defaults