'use strict';
/**
 * Implements directive for FullCalendar component.
 * Component URL: http://arshaw.com/fullcalendar/
 */
angular.module('qusion.ui.scheduler', [])
    .directive('qnScheduler', [
        function() {
            return {
                link: function(scope, element, attr) {
                    var options = scope.$eval(attr.qnScheduler);
                    var dates = scope.$eval(attr.qnDates);
                    // default settings
                    var settings = {
                        theme: true,
                        editable: true,
                        header: {
                            left: 'prev,next today',
                            center: 'title',
                            right: 'month,agendaWeek,agendaDay'
                        }
                    };
                    // ensure options is not undefined
                    options = options || { };
                    // extend settings with user provided options
                    angular.extend(settings, options);
                    // create component
                    element.fullCalendar(settings);

                    scope.$watch(attr.qnDates, function (data) {

                        element.fullCalendar('addEventSource', data);
                        element.fullCalendar('rerenderEvents');
                    });
                }
            };
        }
    ]);