text: var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
      var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
      if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
      else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
      return c > 3 && r && Object.defineProperty(target, key, r), r;
  };
  var __metadata = (this && this.__metadata) || function (k, v) {
      if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  };
  var __param = (this && this.__param) || function (paramIndex, decorator) {
      return function (target, key) { decorator(target, key, paramIndex); }
  };
  import { Directive, ElementRef, Host } from "@angular/core";
  import { CtrCompleter } from "./ctr-completer";
  var CtrRowItem = (function () {
      function CtrRowItem(row, index) {
          this.row = row;
          this.index = index;
      }
      return CtrRowItem;
  }());
  export { CtrRowItem };
  var CtrDropdown = (function () {
      function CtrDropdown(completer, el) {
          this.completer = completer;
          this.el = el;
          this.rows = [];
          this.completer.registerDropdown(this);
      }
      CtrDropdown.prototype.ngOnInit = function () {
          var css = getComputedStyle(this.el.nativeElement);
          this.isScrollOn = css.maxHeight && css.overflowY === "auto";
      };
      CtrDropdown.prototype.ngOnDestroy = function () {
          this.completer.registerDropdown(null);
      };
      CtrDropdown.prototype.registerRow = function (row) {
          this.rows.push(row);
      };
      CtrDropdown.prototype.highlightRow = function (index) {
          var highlited = this.rows.find(function (row) { return row.index === index; });
          if (index < 0) {
              if (this.currHighlited) {
                  this.currHighlited.row.setHighlited(false);
              }
              this.currHighlited = undefined;
              this.completer.onHighlighted(null);
              return;
          }
          if (!highlited) {
              return;
          }
          if (this.currHighlited) {
              this.currHighlited.row.setHighlited(false);
          }
          this.currHighlited = highlited;
          this.currHighlited.row.setHighlited(true);
          this.completer.onHighlighted(this.currHighlited.row.getDataItem());
      };
      CtrDropdown.prototype.clear = function () {
          this.rows = [];
      };
      CtrDropdown.prototype.onSelected = function (item) {
          this.completer.onSelected(item);
      };
      CtrDropdown.prototype.selectCurrent = function () {
          if (this.currHighlited) {
              this.onSelected(this.currHighlited.row.getDataItem());
          }
          else if (this.rows.length > 0) {
              this.onSelected(this.rows[0].row.getDataItem());
          }
      };
      CtrDropdown.prototype.nextRow = function () {
          var nextRowIndex = 0;
          if (this.currHighlited) {
              nextRowIndex = this.currHighlited.index + 1;
          }
          this.highlightRow(nextRowIndex);
          if (this.isScrollOn && this.currHighlited) {
              var row = this.currHighlited.row.getNativeElement();
              if (this.dropdownHeight() < row.getBoundingClientRect().bottom) {
                  this.dropdownScrollTopTo(this.dropdownRowOffsetHeight(row));
              }
          }
      };
      CtrDropdown.prototype.prevRow = function () {
          var nextRowIndex = -1;
          if (this.currHighlited) {
              nextRowIndex = this.currHighlited.index - 1;
          }
          this.highlightRow(nextRowIndex);
          if (this.isScrollOn && this.currHighlited) {
              var rowTop = this.dropdownRowTop();
              if (rowTop < 0) {
                  this.dropdownScrollTopTo(rowTop - 1);
              }
          }
      };
      CtrDropdown.prototype.dropdownScrollTopTo = function (offset) {
          this.el.nativeElement.scrollTop = this.el.nativeElement.scrollTop + offset;
      };
      CtrDropdown.prototype.dropdownRowTop = function () {
          return this.currHighlited.row.getNativeElement().getBoundingClientRect().top -
              (this.el.nativeElement.getBoundingClientRect().top +
                  parseInt(getComputedStyle(this.el.nativeElement).paddingTop, 10));
      };
      CtrDropdown.prototype.dropdownHeight = function () {
          return this.el.nativeElement.getBoundingClientRect().top +
              parseInt(getComputedStyle(this.el.nativeElement).maxHeight, 10);
      };
      CtrDropdown.prototype.dropdownRowOffsetHeight = function (row) {
          var css = getComputedStyle(row);
          return row.offsetHeight +
              parseInt(css.marginTop, 10) + parseInt(css.marginBottom, 10);
      };
      return CtrDropdown;
  }());
  CtrDropdown = __decorate([
      Directive({
          selector: "[ctrDropdown]",
      }),
      __param(0, Host()),
      __metadata("design:paramtypes", [CtrCompleter, ElementRef])
  ], CtrDropdown);
  export { CtrDropdown };
  //# sourceMappingURL=ctr-dropdown.js.map