import { Component, Element, h, Method, Prop, State } from "@stencil/core";
import { format as tidilyFormat } from "tidily";
import { PaymentOptionInvoiceIs, } from "../model";
import { paymentDetailsAdd } from "../payment/options/PaymentDetails";
import * as translation from "./translation";
export class IntergiroInvoiceDetails {
  async componentWillLoad() {
    this.t = translation.create(this.element);
  }
  async getPayment(order, apiKey) {
    let result;
    if (this.option && this.selected) {
      if (!order.items || !order.currency || !order.customer)
        console.log("Error: must have items, currency, customer");
      else {
        result = {
          type: this.option.type,
          terms: this.selected,
          verify: { mode: "iframe", parent: window.location.origin },
        };
      }
    }
    return result;
  }
  render() {
    const t = this.t;
    if (!this.selected && this.option)
      this.selected = this.option.terms[0];
    return [
      this.option
        ? this.option.terms.map(term => (h("smoothly-radio", { onSmoothlySelected: () => (this.selected = term), checked: this.selected == term, name: "invoice-terms", value: term.due.toString() }, typeof term.due == "number" ? t("Due within $0 days", term.due) : t("Due before $0.", term.due))))
        : [],
      this.selected ? (h("p", null, t("The selected invoice choice costs $0.", tidilyFormat(this.selected.fee, "price", this.currency)))) : ([]),
    ];
  }
  static get is() { return "ig-invoice-details"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "option": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "PaymentOptionInvoice",
        "resolved": "Invoice | undefined",
        "references": {
          "PaymentOptionInvoice": {
            "location": "import",
            "path": "../model"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "currency": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "Currency",
        "resolved": "\"AED\" | \"AFN\" | \"ALL\" | \"AMD\" | \"ANG\" | \"AOA\" | \"ARS\" | \"AUD\" | \"AWG\" | \"AZN\" | \"BAM\" | \"BBD\" | \"BDT\" | \"BGN\" | \"BHD\" | \"BIF\" | \"BMD\" | \"BND\" | \"BOB\" | \"BOV\" | \"BRL\" | \"BSD\" | \"BTN\" | \"BWP\" | \"BYN\" | \"BZD\" | \"CAD\" | \"CDF\" | \"CHE\" | \"CHF\" | \"CHW\" | \"CLF\" | \"CLP\" | \"CNY\" | \"COP\" | \"COU\" | \"CRC\" | \"CUC\" | \"CUP\" | \"CVE\" | \"CZK\" | \"DJF\" | \"DKK\" | \"DOP\" | \"DZD\" | \"EGP\" | \"ERN\" | \"ETB\" | \"EUR\" | \"FJD\" | \"FKP\" | \"GBP\" | \"GEL\" | \"GHS\" | \"GIP\" | \"GMD\" | \"GNF\" | \"GTQ\" | \"GYD\" | \"HKD\" | \"HNL\" | \"HRK\" | \"HTG\" | \"HUF\" | \"IDR\" | \"ILS\" | \"INR\" | \"IQD\" | \"IRR\" | \"ISK\" | \"JMD\" | \"JOD\" | \"JPY\" | \"KES\" | \"KGS\" | \"KHR\" | \"KMF\" | \"KPW\" | \"KRW\" | \"KWD\" | \"KYD\" | \"KZT\" | \"LAK\" | \"LBP\" | \"LKR\" | \"LRD\" | \"LSL\" | \"LYD\" | \"MAD\" | \"MDL\" | \"MGA\" | \"MKD\" | \"MMK\" | \"MNT\" | \"MOP\" | \"MRU\" | \"MUR\" | \"MVR\" | \"MWK\" | \"MXN\" | \"MXV\" | \"MYR\" | \"MZN\" | \"NAD\" | \"NGN\" | \"NIO\" | \"NOK\" | \"NPR\" | \"NZD\" | \"OMR\" | \"PAB\" | \"PEN\" | \"PGK\" | \"PHP\" | \"PKR\" | \"PLN\" | \"PYG\" | \"QAR\" | \"RON\" | \"RSD\" | \"RUB\" | \"RWF\" | \"SAR\" | \"SBD\" | \"SCR\" | \"SDG\" | \"SEK\" | \"SGD\" | \"SHP\" | \"SLL\" | \"SOS\" | \"SRD\" | \"SSP\" | \"STN\" | \"SVC\" | \"SYP\" | \"SZL\" | \"THB\" | \"TJS\" | \"TMT\" | \"TND\" | \"TOP\" | \"TRY\" | \"TTD\" | \"TWD\" | \"TZS\" | \"UAH\" | \"UGX\" | \"USD\" | \"USN\" | \"UYI\" | \"UYU\" | \"UYW\" | \"UZS\" | \"VES\" | \"VND\" | \"VUV\" | \"WST\" | \"XAF\" | \"XAG\" | \"XAU\" | \"XBA\" | \"XBB\" | \"XBC\" | \"XBD\" | \"XCD\" | \"XDR\" | \"XOF\" | \"XPD\" | \"XPF\" | \"XPT\" | \"XSU\" | \"XTS\" | \"XUA\" | \"XXX\" | \"YER\" | \"ZAR\" | \"ZMW\" | \"ZWL\"",
        "references": {
          "Currency": {
            "location": "import",
            "path": "isoly"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "currency",
      "reflect": false
    },
    "selected": {
      "type": "unknown",
      "mutable": true,
      "complexType": {
        "original": "PaymentInvoiceTerms",
        "resolved": "Terms",
        "references": {
          "PaymentInvoiceTerms": {
            "location": "import",
            "path": "../model"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "t": {}
  }; }
  static get methods() { return {
    "getPayment": {
      "complexType": {
        "signature": "(order: Order | Omit<Order.Creatable, \"payment\">, apiKey: string) => Promise<PaymentInvoiceCreatable | undefined>",
        "parameters": [{
            "tags": [],
            "text": ""
          }, {
            "tags": [],
            "text": ""
          }],
        "references": {
          "Promise": {
            "location": "global"
          },
          "PaymentInvoiceCreatable": {
            "location": "import",
            "path": "../model"
          },
          "Order": {
            "location": "import",
            "path": "../model"
          },
          "Omit": {
            "location": "global"
          }
        },
        "return": "Promise<PaymentInvoiceCreatable | undefined>"
      },
      "docs": {
        "text": "",
        "tags": []
      }
    }
  }; }
  static get elementRef() { return "element"; }
}
paymentDetailsAdd("invoice", (option) => {
  const result = {
    type: "invoice",
    name: "Invoice",
    brand: option.service,
    component: (h("ig-invoice-details", { option: PaymentOptionInvoiceIs(option) ? option : undefined, currency: option.currency, ref: (e) => (result.element = e) })),
  };
  return result;
});
