import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
import { s as sprintf, _ as __ } from './default-i18n.js';
import './index2.js';
import { d as defineCustomElement$3 } from './sc-button2.js';
import { d as defineCustomElement$2 } from './sc-flex2.js';
import { d as defineCustomElement$1 } from './sc-spinner2.js';

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

const ScPagination = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    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"]
  }; }
  static get style() { return scPaginationCss; }
}, [1, "sc-pagination", {
    "page": [2],
    "perPage": [2, "per-page"],
    "total": [2],
    "totalShowing": [2, "total-showing"],
    "totalPages": [2, "total-pages"],
    "hasNextPage": [32],
    "hasPreviousPage": [32],
    "from": [32],
    "to": [32]
  }]);
function defineCustomElement() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-pagination", "sc-button", "sc-flex", "sc-spinner"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-pagination":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScPagination);
      }
      break;
    case "sc-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "sc-flex":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
    case "sc-spinner":
      if (!customElements.get(tagName)) {
        defineCustomElement$1();
      }
      break;
  } });
}
defineCustomElement();

export { ScPagination as S, defineCustomElement as d };
