import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { g as getOrder, c as clearOrder } from './checkouts.js';
import { u as uiStore } from './ui.js';

const scCartLoaderCss = ":host{position:relative;z-index:var(--sc-cart-z-index, 999999);font-family:var(--sc-font-sans)}";

const ScCartLoader$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    /** The mode for the form. */
    this.mode = 'live';
  }
  render() {
    var _a, _b, _c, _d;
    /**
     * Search for the sc-checkout component on a page to make sure
     * we don't show the cart on a checkout page.
     */
    if (!!document.querySelector('sc-checkout'))
      return null;
    // clear the order if it's already paid.
    const order = getOrder(this.formId, this.mode);
    if ((order === null || order === void 0 ? void 0 : order.status) === 'paid') {
      clearOrder(this.formId, this.mode);
      return null;
    }
    // return the loader.
    return h("div", { innerHTML: ((_b = (_a = order === null || order === void 0 ? void 0 : order.line_items) === null || _a === void 0 ? void 0 : _a.pagination) === null || _b === void 0 ? void 0 : _b.count) || ((_d = (_c = uiStore === null || uiStore === void 0 ? void 0 : uiStore.state) === null || _c === void 0 ? void 0 : _c.cart) === null || _d === void 0 ? void 0 : _d.open) ? this.template : '' });
  }
  static get style() { return scCartLoaderCss; }
}, [1, "sc-cart-loader", {
    "formId": [513, "form-id"],
    "mode": [1],
    "template": [1]
  }]);
function defineCustomElement$1() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-cart-loader"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-cart-loader":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScCartLoader$1);
      }
      break;
  } });
}
defineCustomElement$1();

const ScCartLoader = ScCartLoader$1;
const defineCustomElement = defineCustomElement$1;

export { ScCartLoader, defineCustomElement };
