var angular = require('angular');
require('../modules');
var module = angular.module('commons.directives');
module.directive('sinoClosableMeetItemDivider', function($timeout) {
  return {
    require: ['?^$ionicScroll'],
    template: '<div class="item item-divider item-date">' +
        '{{title}}' +
        '<i class="icon" ' +
        ' ng-class="{\'ion-ios-arrow-down\': openStatus, \'ion-ios-arrow-up\': !openStatus}"></i>' +
      '</div>',
    scope: {
      title: '@',
      openStatus: '='
    },

    link: function($scope, $element, $attr, ctrls) {
      var ionicScrollCtrl = ctrls[0];
      $element[0].addEventListener('click', function() {
        $scope.$evalAsync(function() {
          $scope.openStatus = !$scope.openStatus;
          $timeout(function() {
            if (ionicScrollCtrl) {
              var scrollView = ionicScrollCtrl.scrollView;
              scrollView.resize();
            }
          }, 50);
        });
      });
    }
  };
});
