import { Component, Element, Event, h, Listen, Prop, State } from "@stencil/core";
import { Error } from "gracely";
import { Notice } from "smoothly";
import { Connection } from "@payfunc/model";
import * as translation from "./translation";
export class IntergiroCustomerDetails {
  constructor() {
    this.opened = "";
  }
  componentWillLoad() {
    this.t = translation.create(this.element);
  }
  async updateContact(event) {
    this.notice.emit(Notice.execute(this.t("Updating contact information..."), async () => {
      let result;
      this.customer.contact = event.detail;
      const response = await Connection.put(`customer/${this.customer.id}/contact`, this.customer.contact);
      if (Error.is(response))
        result = [false, this.t("Failed to update contact information.")];
      else {
        this.updateCustomers.emit();
        result = [true, this.t("Updated contact information.")];
      }
      return result;
    }));
  }
  render() {
    let result;
    switch (this.opened) {
      case "number":
        result = (h("ig-number-details", { number: this.customer.number, identifier: this.customer.id, name: "customer" }));
        break;
      case "contact":
        result = h("ig-customer-contact", { customer: this.customer });
        break;
      case "order":
        result = h("ig-orders-table", { orders: this.orders, display: true, receipt: this.whitelist });
        break;
      case "subscription":
        result = (h("ig-subscription-table", { subscriptions: this.customer.subscription, customer: this.customer }));
        break;
      case "method":
        result = h("ig-customer-method", { customer: this.customer });
        break;
      case "balance":
        result = h("ig-customer-balance", { customer: this.customer, orders: this.orders });
        break;
      default:
        return "";
    }
    return h("td", { colSpan: 9 }, result);
  }
  static get is() { return "ig-customer-details"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "opened": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "\"\" | \"balance\" | \"contact\" | \"method\" | \"number\" | \"order\" | \"subscription\"",
        "resolved": "\"\" | \"balance\" | \"contact\" | \"method\" | \"number\" | \"order\" | \"subscription\"",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "opened",
      "reflect": false,
      "defaultValue": "\"\""
    },
    "customer": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Customer",
        "resolved": "Customer",
        "references": {
          "Customer": {
            "location": "import",
            "path": "@payfunc/model"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "orders": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Order[] | undefined",
        "resolved": "Order[] | undefined",
        "references": {
          "Order": {
            "location": "import",
            "path": "@payfunc/model"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "whitelist": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean | undefined",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "whitelist",
      "reflect": false
    }
  }; }
  static get states() { return {
    "t": {}
  }; }
  static get events() { return [{
      "method": "notice",
      "name": "notice",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }, {
      "method": "updateCustomers",
      "name": "updateCustomers",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
  static get elementRef() { return "element"; }
  static get listeners() { return [{
      "name": "updateContact",
      "method": "updateContact",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
