import { Host, h } from "@stencil/core";
/**
 * KlevuUtilSsrProvider component stores the Klevu SSR response as a string
 * that can be hydrated in the client side.
 */
export class KlevuUtilSsrProvider {
  constructor() {
    this.html = undefined;
    this.packed = undefined;
    this.identifier = undefined;
  }
  /**
   * packed parameter returned by KlevuSSRFetch function
   *
   * @param packed
   */
  async setPacked(packed) {
    this.packed = JSON.stringify(packed).replace(/"/g, "'");
  }
  /**
   *
   * @returns packed parameter returned by KlevuSSRFetch function for KlevuSSRHydrate function
   */
  async getPacked() {
    return JSON.parse(this.packed || "{}").replace(/'/g, '"');
  }
  render() {
    if (this.html) {
      return (h(Host, null, h("div", { innerHTML: this.html })));
    }
    return (h(Host, null, h("slot", null)));
  }
  static get is() { return "klevu-util-ssr-provider"; }
  static get encapsulation() { return "shadow"; }
  static get properties() {
    return {
      "html": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "html",
        "reflect": false
      },
      "packed": {
        "type": "string",
        "mutable": true,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "packed",
        "reflect": true
      },
      "identifier": {
        "type": "string",
        "mutable": true,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "identifier",
        "reflect": true
      }
    };
  }
  static get methods() {
    return {
      "setPacked": {
        "complexType": {
          "signature": "(packed: object) => Promise<void>",
          "parameters": [{
              "tags": [{
                  "name": "param",
                  "text": "packed"
                }],
              "text": ""
            }],
          "references": {
            "Promise": {
              "location": "global",
              "id": "global::Promise"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "packed parameter returned by KlevuSSRFetch function",
          "tags": [{
              "name": "param",
              "text": "packed"
            }]
        }
      },
      "getPacked": {
        "complexType": {
          "signature": "() => Promise<any>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global",
              "id": "global::Promise"
            }
          },
          "return": "Promise<any>"
        },
        "docs": {
          "text": "",
          "tags": [{
              "name": "returns",
              "text": "packed parameter returned by KlevuSSRFetch function for KlevuSSRHydrate function"
            }]
        }
      }
    };
  }
}
//# sourceMappingURL=klevu-util-ssr-provider.js.map
