import { Component, Element, Event, h, Listen, Prop, State } from "@stencil/core";
import { Error } from "gracely";
import * as gracely from "gracely";
import { Notice } from "smoothly";
import { Handler } from "../Handler";
import * as translation from "./translation";
export class CustomerAddress {
  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 = this.customer.contact
        ? Handler.client.customer.setContact(this.customer.contact, "me")
        : gracely.client.malformedContent("contact", "model.Contact", "Contact information missing");
      if (!Error.is(response))
        result = [true, this.t("Updated contact information.")];
      else
        result = [false, this.t("Failed to update contact information.")];
      return result;
    }));
  }
  render() {
    return [
      h("h2", { color: "light" }, this.t("Contact information")),
      h("ig-customer-contact", { customer: this.customer }),
    ];
  }
  static get is() { return "customer-address"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "customer": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Customer",
        "resolved": "Customer",
        "references": {
          "Customer": {
            "location": "import",
            "path": "@payfunc/model"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "component": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "\"app\" | \"address\"",
        "resolved": "\"address\" | \"app\" | undefined",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "component",
      "reflect": true
    }
  }; }
  static get states() { return {
    "t": {}
  }; }
  static get events() { return [{
      "method": "notice",
      "name": "notice",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "Notice",
        "resolved": "Notice",
        "references": {
          "Notice": {
            "location": "import",
            "path": "smoothly"
          }
        }
      }
    }]; }
  static get elementRef() { return "element"; }
  static get listeners() { return [{
      "name": "updateContact",
      "method": "updateContact",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
