import { r as registerInstance, c as createEvent, h } from './index-f1d2a96f.js';
import { _ as __, s as sprintf } from './default-i18n-91ef32a0.js';
import './index-0a61debd.js';
import './_commonjsHelpers-9943807e.js';

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

const ScPagination = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.scPrevPage = createEvent(this, "scPrevPage", 7);
    this.scNextPage = 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 (h("sc-flex", null, h("div", null, sprintf(__('Displaying %1d to %2d of %3d items', 'surecart'), this.from, this.to, this.total)), h("sc-flex", null, h("sc-button", { onClick: () => this.scPrevPage.emit(), disabled: !this.hasPreviousPage, size: "small" }, __('Previous', 'surecart')), h("sc-button", { onClick: () => this.scNextPage.emit(), disabled: !this.hasNextPage, size: "small" }, __('Next', 'surecart')))));
  }
  static get watchers() { return {
    "total": ["handlePaginationChange"],
    "totalPages": ["handlePaginationChange"],
    "page": ["handlePaginationChange"],
    "perPage": ["handlePaginationChange"],
    "totalShowing": ["handlePaginationChange"]
  }; }
};
ScPagination.style = scPaginationCss;

export { ScPagination as sc_pagination };
