<?php 


Route::isJs(function(){
ob_start();
?>
<div>
<style type="text/css">
	md-toast.md-success-toast-theme .md-toast-content {
	    background-color: green;
	}
	md-toast.md-error-toast-theme .md-toast-content {
	    background-color: maroon;
	}
</style>
</div>
<?php
$code=ob_get_clean();
?>
<script>
	app.directive('notification', ['$mdToast',function ($mdToast) {
		return {
			restrict: 'EA',
			template : <?= json_encode($code) ?>,
			controller : function($scope){
			 	var last = {
			      bottom: true,
			      top: false,
			      left: false,
			      right: true
			    };
				$scope.toastPosition = angular.extend({},last);
				function sanitizePosition() {
				  var current = $scope.toastPosition;
				  if ( current.bottom && last.top ) current.top = false;
				  if ( current.top && last.bottom ) current.bottom = false;
				  if ( current.right && last.left ) current.left = false;
				  if ( current.left && last.right ) current.right = false;
				  last = angular.extend({},current);
				}
				$scope.getToastPosition = function() {
				  sanitizePosition();
				  return Object.keys($scope.toastPosition)
				    .filter(function(pos) { 
				    	return $scope.toastPosition[pos]; 
				    })
				    .join(' ');
				};
				$scope.show = function(msg){
				    var pinTo = $scope.getToastPosition();
				    $mdToast.show(
				      $mdToast.simple()
				        .textContent(msg)
				        .position(pinTo )
				        .hideDelay(2000)
				    );
				};
				$scope.error = function(msg){
				    var pinTo = $scope.getToastPosition();
				    $mdToast.show(
				      $mdToast.simple()
				        .textContent(msg)
				        .theme('error-toast')
				        .position(pinTo )
				        .hideDelay(2000)
				    );
				};
				$scope.success = function(msg){
				    var pinTo = $scope.getToastPosition();
				    $mdToast.show(
				      $mdToast.simple()
				        .textContent(msg)
				        .theme('success-toast')
				        .position(pinTo )
				        .hideDelay(2000)
				    );
				};
				window.notification = function(data){
					var msg = data[0];
					var type = data[1];
					if(type == "success"){
						$scope.success(msg);
					}else if(type == "error"){
						$scope.error(msg);
					}else{
						$scope.show(msg);
					}
					$scope.$apply();
				}
			},
			link: function (scope, iElement, iAttrs) {
				
			}
		};
	}]);
</script>
<?php
});