import { AppUrlParamContext as S } from "./accelbyte-widgets574.mjs";
import { PaymentAlert as A } from "./accelbyte-widgets493.mjs";
import { PaymentProvider as l } from "./accelbyte-widgets494.mjs";
import { sendMessageToParentWindow as h, PAYMENT_STATION_ACTION as C } from "./accelbyte-widgets496.mjs";
import { Ctx as N } from "./accelbyte-widgets33.mjs";
import { AlertType as T } from "./accelbyte-widgets128.mjs";
import { Platform as v } from "@accelbyte/sdk-platform";
import t, { useContext as E, useState as c, useEffect as m } from "react";
import r from "./accelbyte-widgets704.mjs";
const u = 30, Y = ({ paymentUrl: d }) => {
  const p = N.getAppState().getSdk(), { paymentOrderNo: y } = E(S), [e, o] = c({
    value: null,
    isLoading: !1,
    error: null
  }), [a, s] = c(u), i = async () => {
    if (!e.isLoading) {
      o({ value: null, isLoading: !0, error: null });
      try {
        const n = await v.PaymentStationApi(p).getStatusPayment_ByPaymentOrderNo(y);
        o({ value: n, isLoading: !1, error: null });
      } catch (n) {
        console.error(n), o({ error: n, value: null, isLoading: !1 });
      }
    }
  }, f = () => {
    switch (d.paymentProvider) {
      case l.enum.WXPAY:
        return "Scan with WeChat to continue payment";
      case l.enum.ALIPAY:
        return "Scan with mobile Alipay to continue payment";
      default:
        return "Scan barcode above to continue the payment";
    }
  };
  m(() => {
    a > 0 ? setTimeout(() => {
      s(a - 1);
    }, 1e3) : i();
  }, [a]), m(() => {
    e.isLoading || (e.value && e.value.success ? h({ message: { action: C.enum.complete } }) : e.error || s(u));
  }, [e]);
  const g = new Intl.PluralRules("en-US").select(a) === "other", P = e.isLoading ? "(checking payment status...)" : `in ${a} second${g ? "s" : ""}`;
  return /* @__PURE__ */ t.createElement("div", { className: r.qrCodeHandler }, /* @__PURE__ */ t.createElement("div", { className: r.qrCodeWrapper }, /* @__PURE__ */ t.createElement("div", { className: r.qrCodeBox }, /* @__PURE__ */ t.createElement(
    "img",
    {
      src: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTgfVKYYpzDWBkDUZkozpBr7Stphkj-GKTaZg&usqp=CAU",
      alt: "QR code"
    }
  ), /* @__PURE__ */ t.createElement("div", { className: r.description }, f())), /* @__PURE__ */ t.createElement("div", { className: r.statusCheck }, !e.error && `Automatically check payment status ${P}`, !!e.error && /* @__PURE__ */ t.createElement(
    A,
    {
      type: T.warning,
      message: "Failed to get payment status, Please retry or reload the page if the problem persist",
      onRetry: i
    }
  ))));
};
export {
  Y as default
};
