'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-cd6fab62.js');
const defaultI18n = require('./default-i18n-072e75d7.js');
require('./index-20b57ec7.js');
require('./_commonjsHelpers-537d719a.js');

const scPaginationCss = ":host{display:block}";

const ScPagination = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.scPrevPage = index.createEvent(this, "scPrevPage", 7);
    this.scNextPage = index.createEvent(this, "scNextPage", 7);
    this.page = 1;
    this.perPage = 0;
    this.total = 0;
    this.totalShowing = 0;
    this.totalPages = 0;
  }
  componentWillLoad() {
    this.handlePaginationChange();
  }
  handlePaginationChange() {
    // do we have a previous or next page?
    this.hasNextPage = this.total > 1 && this.page < this.totalPages;
    this.hasPreviousPage = this.totalPages > 1 && this.page > 1;
    // from->to.
    this.from = this.perPage * (this.page - 1) + 1;
    this.to = Math.min(this.from + this.totalShowing - 1, this.total);
  }
  render() {
    if (!this.hasNextPage && !this.hasPreviousPage)
      return null;
    return (index.h("sc-flex", null, index.h("div", null, defaultI18n.sprintf(defaultI18n.__('Displaying %1d to %2d of %3d items', 'surecart'), this.from, this.to, this.total)), index.h("sc-flex", null, index.h("sc-button", { onClick: () => this.scPrevPage.emit(), disabled: !this.hasPreviousPage, size: "small" }, defaultI18n.__('Previous', 'surecart')), index.h("sc-button", { onClick: () => this.scNextPage.emit(), disabled: !this.hasNextPage, size: "small" }, defaultI18n.__('Next', 'surecart')))));
  }
  static get watchers() { return {
    "total": ["handlePaginationChange"],
    "totalPages": ["handlePaginationChange"],
    "page": ["handlePaginationChange"],
    "perPage": ["handlePaginationChange"],
    "totalShowing": ["handlePaginationChange"]
  }; }
};
ScPagination.style = scPaginationCss;

exports.sc_pagination = ScPagination;
