(function() {
	'use strict';

	// generic UI For listing files
	angular.module('ti_common').directive('ticViewPanelSticky', ticViewPanel);

	var stickyPanelExpanded = true;
	var viewStickyStateChangedHandler;

	function ticViewPanel() {

		var directive = {
			restrict: 'E',
			templateUrl: 'ti_common/containers/view_panel.html',
			controller: ViewPanelControllerSticky,
			controllerAs: 'vm',
			bindToController : true,
			transclude : {
				'actions' : '?ticViewPanelActions',
				'body' : 'ticViewPanelBody'
 			},
 			scope : {
 				heading : '=',
 				description : '='
 			}
		};

	
		ViewPanelControllerSticky.$inject = ['$scope'];
		function ViewPanelControllerSticky($scope){	
			var vm = this;
			
			vm.show = stickyPanelExpanded;
			vm.otherClasses = 'footer';

			$scope.$watch('vm.show', function(newValue, oldValue){
				if( newValue !== oldValue ){
					stickyPanelExpanded = newValue;
					viewStickyStateChangedHandler();
				}
			});

		}

		return directive;
	}


	angular.module('ti_common').service('ticViewStickyPanel', ticViewStickyPanel);

	function ticViewStickyPanel(){

		function registerViewStickyStateChangedHandler(newHandler){
			viewStickyStateChangedHandler = newHandler;
		}

		return {
			registerViewStickyStateChangedHandler : registerViewStickyStateChangedHandler,
			stickyPanelExpanded : function(){
				return stickyPanelExpanded;
			}
		};

	}

})();