'use strict';

import _ from 'lodash/core';

import tpl from './tlp.html';
import './tlp.scss';

export default function(app) {
  app.directive('tlp', tlp);

  function tlp(Tlps) {
    'ngInject';

    return {
      templateUrl: tpl,
      scope: {
        value: '='
      },
      replace: true,
      link: linkFn
    };

    function linkFn(scope) {
      if (scope.value === undefined) {
        scope.tlpClass = 'label-none';
        scope.tlp = 'None';
      } else {
        const temp = (_.find(Tlps, { value: scope.value }) || {}).key;

        scope.tlpClass = `label-${(temp || '').toLowerCase()}`;
        scope.tlp = `TLP:${temp}`;
      }
    }
  }
}

@@ -358,23 +358,50 @@
     
-if (
 scope.
-value
+$watch('value', v =%3E %7B%0A        if (v
  ===
@@ -414,32 +414,34 @@
 ined) %7B%0A        
+  
 scope.tlpClass =
@@ -455,32 +455,34 @@
 -none';%0A        
+  
 scope.tlp = 'Non
@@ -491,16 +491,18 @@
 ;%0A      
+ 
+ 
 %7D else %7B
@@ -502,16 +502,18 @@
  else %7B%0A
+  
         
@@ -552,19 +552,9 @@
 ue: 
-scope.value
+v
  %7D) 
@@ -566,16 +566,18 @@
 ).key;%0A%0A
+  
         
@@ -632,32 +632,34 @@
 se()%7D%60;%0A        
+  
 scope.tlp = %60TLP
@@ -675,17 +675,29 @@
 ;%0A      
-%7D
+  %7D%0A      %7D);
 %0A    %7D%0A 

Make tlp directive watch its value