'use strict';

// Declare app level module which depends on views, and components
angular.module('myApp', [
    'ngRoute',
    'myApp.view1',
    'myApp.view2',
    'myApp.version',
    'ngAnimate',
    'ui.bootstrap'
]).
config(['$routeProvider', function ($routeProvider) {
    $routeProvider.otherwise({redirectTo: '/view1'});
}]).
controller('DatePickerCtrl', ['$scope', function ($scope) {
    $scope.format = 'yyyy-MM-dd';
    $scope.alerts = [];

    $scope.open = function ($event) {
        $scope.status.opened = true;
    };
    $scope.dateOptions = {
        startingDay: 1
    };
    $scope.toggleOpenDatePicker = function ($event, datePicker) {
        $event.preventDefault();
        $event.stopPropagation();
        $scope[datePicker] = !$scope[datePicker];
    };
    $scope.changeTime = function () {
        $scope.showTime = !$scope.showTime;
        console.log($scope.showTime)
    }
    $scope.closeAlert = function (index) {
        $scope.alerts.splice(index, 1);
    };

    $scope.submitDates = function (startDate, endDate) {
        if (startDate === undefined || endDate === undefined) 

        var difference = endDate - startDate
        if (difference < 0) {
            $scope.alerts.push({
                msg: "end date must not be less than start date ",
                type: "danger"
            });
            return;
        }

        if (difference > 30 * 1000 * 60 * 60 * 24) {
            $scope.alerts.push({
                msg: "can not calculate more than 30 days",
                type: "danger"
            });
            return;
        }
        $scope.alerts = [];
        $scope.$broadcast("dateChange", startDate, endDate);
    };
}]);

{
            $scope.alerts.push({
                msg: "please input start date and end date",
                type: "danger"

            });
            return;
        }