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;
};
import { MapToComponentField, MapToComponentMethod, VegaSlimmer } from 'vega-slimmer/core';
/**
 * The table pagination of VegaTable
 */
export class VegaTablePaginationController extends VegaSlimmer {
  /**
   * Component lifecycle - componentWillLoad
   */
  componentWillLoad() {
    var _a, _b;
    this.currentPage = ((_a = this.pagination) === null || _a === void 0 ? void 0 : _a.current) || 1;
    this.pageSize = ((_b = this.pagination) === null || _b === void 0 ? void 0 : _b.pageSize) || 10;
  }
  /**
   *
   */
  watchPagination() {
    if (this.pagination) {
      const { pageSize, current } = this.pagination;
      if (pageSize > 0) {
        this.pageSize = pageSize;
      }
      if (current > 0) {
        this.currentPage = current;
      }
    }
  }
  /**
   * Set pageSize value
   *
   * @param {number} pageSize - New value for pageSize
   */
  setPageSize(pageSize) {
    this.pageSize = pageSize;
  }
  /**
   * Set currentPage value
   *
   * @param {number} currentPage - New value for currentPage
   */
  setCurrentPage(currentPage) {
    this.currentPage = currentPage;
  }
  /**
   * Whether the row is visible in current page
   *
   * @param {number} index - The record index of the currentData
   * @returns {boolean} Return true if the row is visible
   */
  isRowVisible(index) {
    if (!this.pagination)
      return true;
    const pageSize = this.pageSize;
    const current = this.currentPage;
    const start = (current - 1) * pageSize;
    const end = current * pageSize;
    return index >= start && index < end;
  }
}
__decorate([
  MapToComponentField()
], VegaTablePaginationController.prototype, "pagination", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaTablePaginationController.prototype, "pageSize", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaTablePaginationController.prototype, "currentPage", void 0);
__decorate([
  MapToComponentMethod('componentWillLoad')
], VegaTablePaginationController.prototype, "componentWillLoad", null);
__decorate([
  MapToComponentMethod('watchPagination')
], VegaTablePaginationController.prototype, "watchPagination", null);
