import { r as registerInstance, h } from './index-08b73e9e.js';
import { d as dist } from './index-3cf720d3.js';
import { a as Token } from './Token-ba2c5d5c.js';
import { p as paymentOptionCardIs } from './model-ebf2a54b.js';
import { p as paymentDetailsAdd } from './PaymentDetails-c0a6f6c4.js';

const styleCss = ":host{display:block}:host[hidden]{display:none}:host{display:-ms-flexbox;display:flex;-ms-flex-flow:row;flex-flow:row;-ms-flex-wrap:wrap;flex-wrap:wrap}";

const IntergiroCardDetails = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.created = false;
  }
  async getPayment(order, apiKey) {
    var _a, _b;
    let result;
    if (this.option && order.items && order.currency) {
      const response = await this.cardInput.submit((_b = (_a = order.payment) === null || _a === void 0 ? void 0 : _a.card) !== null && _b !== void 0 ? _b : undefined);
      if (!this.created)
        this.created = Token.is(response);
      result = Token.is(response) ? { type: "card", card: response, client: this.getClientData() } : undefined;
    }
    return result;
  }
  async confirmPayment(order, payment, apiKey, error) {
    let result;
    if (order.items && order.currency) {
      const response = await this.cardInput.submit("card" in payment ? payment.card : undefined, error);
      result = Token.is(response) ? { type: "card", card: response, client: this.getClientData() } : undefined;
    }
    return result;
  }
  getClientData() {
    return {
      browser: {
        colorDepth: screen.colorDepth,
        resolution: [screen.width, screen.height],
        java: navigator.javaEnabled(),
        javascript: true,
        locale: dist.Locale.is(navigator.language) ? navigator.language : "en-GB",
        timezone: new Date().getTimezoneOffset(),
        parent: window.location.origin,
      },
    };
  }
  render() {
    return this.option ? (h("intergiro-card-input", { "api-key": this.option.apiKey, ref: (element) => (this.cardInput = element), cosmetic: this.cosmetic })) : ([]);
  }
};
paymentDetailsAdd("card", (option, cosmetic) => {
  const result = {
    type: "card",
    name: "Card",
    brand: option.service,
    component: (h("ig-card-details", { option: paymentOptionCardIs(option) ? option : undefined, cosmetic: cosmetic, ref: (e) => (result.element = e) })),
  };
  return result;
});
IntergiroCardDetails.style = styleCss;

export { IntergiroCardDetails as I };
