import { Component, h, Host, Prop, State } from '@stencil/core';
export class DevingenProductRootTaban {
  componentWillLoad() {
    this.fetchProductSettings();
  }
  fetchProductSettings() {
    this.apiDevingen.findProductSettingsTaban(this.product._id)
      .then(response => this.productSettings = response)
      .catch((e) => {
      var _a;
      if (((_a = e === null || e === void 0 ? void 0 : e.data) === null || _a === void 0 ? void 0 : _a.error) === 'product-setting-not-found-for-product') {
        this.apiDevingen.createProductSettingsTaban(this.product._id)
          .then((response) => {
          this.productSettings = response;
        })
          .catch(error => this.error = error);
      }
      else {
        this.error = e;
      }
    });
  }
  render() {
    const { error } = this;
    if (error) {
      return (h(Host, null,
        h("div", { class: "d-flex justify-content-center" },
          h("devingen-error-card", { error: error, message: "Unexpected error occurred." }))));
    }
    return (h(Host, { class: "container d-flex flex-grow-1 flex-column" }));
  }
  static get is() { return "devingen-product-root-taban"; }
  static get properties() { return {
    "apiDevingen": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "DevingenApi",
        "resolved": "DevingenApi",
        "references": {
          "DevingenApi": {
            "location": "import",
            "path": "../../api/devingen-api"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "product": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Product",
        "resolved": "Product",
        "references": {
          "Product": {
            "location": "import",
            "path": "../../models/product"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "error": {},
    "productSettings": {},
    "showSettingsForm": {}
  }; }
}
