import { Component, Element, h, Prop, State } from "@stencil/core";
import { DateTime } from "isoly";
import "smoothly";
import { EmailAddresses, Item, PhoneNumbers } from "../model";
import * as translation from "./translation";
export class IntergiroDisplayOrder {
  componentWillLoad() {
    if (typeof this.order == "string")
      this.order = JSON.parse(this.order);
    this.t = translation.create(this.element);
  }
  render() {
    const t = this.t;
    this.order = this.order;
    return [
      h("header", null,
        h("h1", null, t("Order complete"))),
      h("main", null,
        h("dl", null,
          h("dt", null, t("Order number")),
          h("dd", null, this.order.number ? this.order.number : t("Not available")),
          h("dt", null, t("Amount")),
          h("dd", null,
            this.order.currency,
            " ",
            Item.amount(this.order.items)),
          h("dt", null, t("Created")),
          h("dd", null,
            h("smoothly-display-date-time", { datetime: this.order.created ? DateTime.localize(DateTime.parse(this.order.created)) : t("Not available") })),
          !this.order.customer || typeof this.order.customer == "string"
            ? ""
            : this.order.customer.phone
              ? [h("dt", null, t("Phone")), h("dd", null, PhoneNumbers.get(this.order.customer.phone))]
              : this.order.customer.email
                ? [h("dt", null, t("Email")), h("dd", null, EmailAddresses.get(this.order.customer.email))]
                : ""),
        h("h2", null, t("Thanks for your purchase!"))),
    ];
  }
  static get is() { return "ig-display-order"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "order": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string | Order",
        "resolved": "Order | string",
        "references": {
          "Order": {
            "location": "import",
            "path": "../model"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "order",
      "reflect": false
    }
  }; }
  static get states() { return {
    "t": {}
  }; }
  static get elementRef() { return "element"; }
}
