'use strict';

const index = require('./index-140bcbcd.js');
const index$1 = require('./index-bddf9814.js');
const Token = require('./Token-8c5ba5d9.js');
const model = require('./model-7ac3bb05.js');
const PaymentDetails = require('./PaymentDetails-ea590e93.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) {
    index.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.Token.is(response);
      result = Token.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.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: index$1.dist.Locale.is(navigator.language) ? navigator.language : "en-GB",
        timezone: new Date().getTimezoneOffset(),
        parent: window.location.origin,
      },
    };
  }
  render() {
    return this.option ? (index.h("intergiro-card-input", { "api-key": this.option.apiKey, ref: (element) => (this.cardInput = element), cosmetic: this.cosmetic })) : ([]);
  }
};
PaymentDetails.paymentDetailsAdd("card", (option, cosmetic) => {
  const result = {
    type: "card",
    name: "Card",
    brand: option.service,
    component: (index.h("ig-card-details", { option: model.paymentOptionCardIs(option) ? option : undefined, cosmetic: cosmetic, ref: (e) => (result.element = e) })),
  };
  return result;
});
IntergiroCardDetails.style = styleCss;

exports.IntergiroCardDetails = IntergiroCardDetails;
