import { Component, h, Prop } from '@stencil/core';
import { clearOrder, getOrder } from '../../../../store/checkouts';
import uiStore from '../../../../store/ui';
export class ScCartLoader {
  constructor() {
    /** 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 is() { return "sc-cart-loader"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["sc-cart-loader.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["sc-cart-loader.css"]
  }; }
  static get properties() { return {
    "formId": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The form id to use for the cart."
      },
      "attribute": "form-id",
      "reflect": true
    },
    "mode": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "'live' | 'test'",
        "resolved": "\"live\" | \"test\"",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The mode for the form."
      },
      "attribute": "mode",
      "reflect": false,
      "defaultValue": "'live'"
    },
    "template": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The cart template to inject when opened."
      },
      "attribute": "template",
      "reflect": false
    }
  }; }
}
