import { Component, Element, Event, h, Prop, State } from "@stencil/core";
import { Contact, Name } from "@payfunc/model";
import * as translation from "./translation";
export class IntergiroCustomerContact {
  constructor() {
    this.types = ["organization", "person"];
  }
  componentWillLoad() {
    this.t = translation.create(this.element);
  }
  async update(property, value) {
    var _a;
    if (!value || Object.keys(value).length == 0)
      (_a = this.customer.contact) === null || _a === void 0 ? true : delete _a[property];
    else {
      const update = { [property]: value };
      if (Contact.is(update))
        this.customer.contact = Object.assign(Object.assign({}, this.customer.contact), update);
    }
    this.updateContact.emit(this.customer.contact);
  }
  render() {
    var _a, _b;
    const contact = this.customer.contact;
    return [
      h("section", null,
        h("label", null, this.t("Name")),
        h("ig-display-edit", { type: "text", name: this.t("Name"), value: (contact === null || contact === void 0 ? void 0 : contact.name) ? Name.get(contact.name) : undefined, onChanged: (e) => this.update("name", e.detail) })),
      h("section", null,
        h("label", null, this.t("Type")),
        h("ig-display-edit", { type: "text", name: this.t("Type"), value: contact === null || contact === void 0 ? void 0 : contact.type, select: this.types, onChanged: (e) => this.update("type", e.detail) })),
      h("section", null,
        h("label", null, this.t("Number")),
        h("smoothly-display", { type: "text", value: contact === null || contact === void 0 ? void 0 : contact.number })),
      h("section", null,
        h("label", null, this.t("Identity number")),
        h("ig-display-edit", { type: "identity-number", name: this.t("Identity number"), value: contact === null || contact === void 0 ? void 0 : contact.identityNumber, onChanged: (e) => this.update("identityNumber", e.detail) })),
      h("section", null,
        h("label", null, this.t("Email")),
        h("ig-email-addresses", { value: (_a = contact === null || contact === void 0 ? void 0 : contact.email) !== null && _a !== void 0 ? _a : "", onChanged: (e) => this.update("email", e.detail) })),
      h("section", null,
        h("label", null, this.t("Phone number")),
        h("ig-phone-numbers", { value: (_b = contact === null || contact === void 0 ? void 0 : contact.phone) !== null && _b !== void 0 ? _b : "", onChanged: (e) => this.update("phone", e.detail) })),
      h("section", null,
        h("label", null, this.t("Address")),
        h("ig-addresses", { value: contact === null || contact === void 0 ? void 0 : contact.address, onChanged: (e) => this.update("address", e.detail) })),
    ];
  }
  static get is() { return "ig-customer-contact"; }
  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": ""
      }
    }
  }; }
  static get states() { return {
    "t": {}
  }; }
  static get events() { return [{
      "method": "updateContact",
      "name": "updateContact",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
  static get elementRef() { return "element"; }
}
