(function() {
  'use strict';
  angular
    .module('app')
    .controller('AlertCtrl', AlertCtrl)
    .controller('AsideCtrl', AsideCtrl)
    .controller('ButtonCtrl', ButtonCtrl)
    .controller('DropdownCtrl', DropdownCtrl)
    .controller('CollapseCtrl', CollapseCtrl)
    .controller('DatepickerCtrl', DatepickerCtrl)
    .controller('TimepickerCtrl', TimepickerCtrl)
    .controller('ModalCtrl', ModalCtrl)
    .controller('SelectCtrl', SelectCtrl)
    .controller('TabCtrl', TabCtrl)
    .controller('TooltipCtrl', TooltipCtrl)
    .controller('PopoverCtrl', PopoverCtrl)
    .controller('TypeaheadCtrl', TypeaheadCtrl);

    AlertCtrl.$inject = ['$scope', '$alert'];
    function AlertCtrl($scope, $alert) {
      $scope.alert = {title: 'Holy guacamole!', content: 'Best check yo self, you\'re not looking too good.', type: 'info'};

      // Service usage
      var myAlert = $alert({title: 'Holy guacamole!', content: 'Best check yo self, you\'re not looking too good.', placement: 'top', type: 'info', keyboard: true, show: false});
      $scope.showAlert = function() {
        myAlert.show(); // or myAlert.$promise.then(myAlert.show) if you use an external html template
      };
    }

    function AsideCtrl($scope) {
      $scope.aside = {title: 'Title', content: 'Hello Aside<br />This is a multiline message!'};
    }

    function ButtonCtrl($scope) {
      $scope.button = {
        toggle: false,
        checkbox: {left: false, middle: true, right: false},
        radio: 0
      };
    }

    DropdownCtrl.$inject = ['$scope', '$alert'];
    function DropdownCtrl($scope, $alert) {
      $scope.dropdown = [
        {text: '<i class="fa fa-fw m-r-sm fa-download"></i>Another action', href: '#anotherAction'},
        {text: '<i class="fa fa-fw m-r-sm fa-globe"></i>Display an alert', click: '$alert("Holy guacamole!")'},
        {text: '<i class="fa fa-fw m-r-sm fa-external-link"></i>External link', href: '/auth/facebook', target: '_self'},
        {divider: true},
        {text: 'Separated link', href: '#separatedLink'}
      ];

      $scope.$alert = function(title) {
        $alert({title: title, content: 'Best check yo self, you\'re not looking too good.', placement: 'top', type: 'info', keyboard: true, show: true});
      };
    }

    CollapseCtrl.$inject = ['$scope', '$templateCache'];
    function CollapseCtrl($scope, $templateCache) {
      $scope.panels = [
        {title:'Collapsible Group Item #1', body: 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch.'},
        {title:'Collapsible Group Item #2', body: 'Food truck fixie locavore, accusamus mcsweeney\'s marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee.'},
        {title:'Collapsible Group Item #3', body: 'Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney\'s organic lomo retro fanny pack lo-fi farm-to-table readymade.'}
      ];

      $scope.panels.activePanel = 1;

      $scope.pushPanel = function() {
        $scope.panels.push({title: 'Collapsible Group Item #4', body: 'Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid.'});
      };
    }

    function DatepickerCtrl($scope) {
      $scope.selectedDate = new Date();
      $scope.selectedDateAsNumber = Date.UTC(1986, 1, 22);
      // $scope.fromDate = new Date();
      // $scope.untilDate = new Date();
      $scope.getType = function(key) {
        return Object.prototype.toString.call($scope[key]);
      };

      $scope.clearDates = function() {
        $scope.selectedDate = null;
      };
    }

    function TimepickerCtrl($scope) {
      $scope.time = new Date(1970, 0, 1, 10, 30);
      $scope.selectedTimeAsNumber = 10 * 36e5;
      $scope.selectedTimeAsString = '10:00';
      $scope.sharedDate = new Date(new Date().setMinutes(0));
    }

    ModalCtrl.$inject = ['$scope', '$modal'];
    function ModalCtrl($scope, $modal) {
      $scope.modal = {title: 'Title', content: 'Hello Modal<br />This is a multiline message!'};

      // Controller usage example
      //
      // var myModal = $modal({title: 'Title', content: 'Hello Modal<br />This is a multiline message!', show: false});
      // $scope.showModal = function() {
      //   myModal.$promise.then(myModal.show);
      // };
      // $scope.hideModal = function() {
      //   myModal.$promise.then(myModal.hide);
      // };
    }

    function SelectCtrl($scope) {
      $scope.selectedIcon = '';
      $scope.selectedIcons = ['Globe', 'Heart'];
      $scope.icons = [
        {value: 'Gear', label: '<i class="fa fa-gear m-r-sm"></i> Gear'},
        {value: 'Globe', label: '<i class="fa fa-globe m-r-sm"></i> Globe'},
        {value: 'Heart', label: '<i class="fa fa-heart m-r-sm"></i> Heart'},
        {value: 'Camera', label: '<i class="fa fa-camera m-r-sm"></i> Camera'}
      ];

      $scope.selectedMonth = 0;
      $scope.months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    }

    function TabCtrl($scope) {
      $scope.tabs = [
        {title:'Home', content: 'Raw denim you probably haven\'t heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica.'},
        {title:'Profile', content: 'Food truck fixie locavore, accusamus mcsweeney\'s marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee.'},
        {title:'About', content: 'Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney\'s organic lomo retro fanny pack lo-fi farm-to-table readymade.'}
      ];

      $scope.tabs.activeTab = 1;

      $scope.pushTab = function() {
        $scope.tabs.push({title: 'Contact', content: 'Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid.'});
      };
    }

    function TooltipCtrl($scope) {
      $scope.tooltip = {title: 'Hello Tooltip!', checked: false};
    }

    function PopoverCtrl($scope) {
      $scope.popover = {title: 'Title', content: 'Hello Popover<br />This is a multiline message!'};
    }

    TypeaheadCtrl.$inject = ['$scope', '$http'];
    function TypeaheadCtrl($scope, $http) {

      $scope.selectedState = '';
      $scope.states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'];

      $scope.selectedIcon = '';
      $scope.icons = [
        {value: 'Gear', label: '<i class="fa fa-gear"></i> Gear'},
        {value: 'Globe', label: '<i class="fa fa-globe"></i> Globe'},
        {value: 'Heart', label: '<i class="fa fa-heart"></i> Heart'},
        {value: 'Camera', label: '<i class="fa fa-camera"></i> Camera'}
      ];

      $scope.selectedAddress = '';
      $scope.getAddress = function(viewValue) {
        var params = {address: viewValue, sensor: false};
        return $http.get('http://maps.googleapis.com/maps/api/geocode/json', {params: params})
        .then(function(res) {
          return res.data.results;
        });
      };
    }
})();
