<template>
  <UiContainer v-if="!userStore.vCodeVerify" class="flex py-20 sm:py-14">
    <div class="hidden xl:block rounded-2xl min-w-[60%] h-[830px]" :style="{
      backgroundImage: `url('/api/public/file/${component.img[0]}_l.webp')`,
      backgroundSize: 'cover',
      backgroundPosition: 'center',
    }" />
    <div class="w-full sm:w-[80%] mx-auto my-auto xl:w-full xl:px-12">
      <div class="space-25-55">
        <div class="flex flex-wrap-reverse gap-y-4 justify-between">
          <h2 class="h2-bold-bounded">
            {{ $t("login") }}
          </h2>
          <button
            class="h-[40px] sm:h-[43px] px-[10px] sm:px-[17px] border border-gray dark:border-button-disabled text-gray dark:text-button-disabled hover:bg-gray transition-all hover:text-white rounded-[8px] cursor-pointer"
            @click="menuStore.navigateToItem()">
            {{ $t("back_to_home") }}
          </button>
        </div>
        <div class="space-y-[15px]">
          <p class="pl-6">
            {{ $t("email") }}
          </p>
          <input v-model="userStore.email" :placeholder="$t('email')" type="text"
                 class="border-2 border-block placeholder:text-gray dark:placeholder:text-button-disabled text-bg-dark dark:text-bg-light rounded-lg px-6 h-[50px] sm:h-[67px] w-full focus:outline-none focus:ring-0 focus:border-2">
        </div>
        <div class="space-y-[15px]">
          <p class="pl-6">
            {{ $t("password") }}
          </p>
          <input v-model="userStore.password" :placeholder="$t('placeholder_password')" type="text"
                 class="border-2 border-block placeholder:text-gray dark:placeholder:text-button-disabled text-bg-dark dark:text-bg-light rounded-lg px-6 h-[50px] sm:h-[67px] w-full focus:outline-none focus:ring-0 focus:border-2">
        </div>
      </div>
      <p class="text-button hover:text-button-hover transition-all font-medium mt-[30px] cursor-pointer">
        {{ $t("forgot_password_question") }}
      </p>
      <div class="py-[25px] sm:py-12 border-b border-gray flex justify-center w-full">
        <UiButtonArrow type="fill" :arrow="true" @click="userStore.logIn()">
          {{
            $t("login")
          }}
        </UiButtonArrow>
      </div>
      <div class="mt-[25px] sm:mt-[30px] w-full flex justify-center gap-3">
        <p>
          {{ $t("no_account") }}
        </p>
        <nuxt-link
          :to="{ name: `id-slug___${$i18n.locale}`, params: { id: menuStore.getPreRegistrationMenu()?.id, slug: menuStore.getPreRegistrationMenu()?.front_menu_lang.at(0)?.link_rewrite } }">
          <p class="text-button cursor-pointer hover:text-button-hover">
            {{ $t("sign_up_now") }}
          </p>
        </nuxt-link>
      </div>
    </div>
  </UiContainer>

  <UiContainer v-if="userStore.vCodeVerify" class="flex py-20 sm:py-14">
    <div class="hidden xl:block rounded-2xl min-w-[60%] h-[830px]" :style="{
      backgroundImage: `url('/api/public/file/${component.img[0]}_l.webp')`,
      backgroundSize: 'cover',
      backgroundPosition: 'center',
    }" />
    <div class="w-full sm:w-[80%] mx-auto my-auto xl:w-full xl:px-12">
      <div class="space-25-55">
        <div class="flex flex-wrap-reverse gap-y-4 justify-between">
          <h2 class="h2-bold-bounded">
            {{ $t("verify_login") }}
          </h2>
          <button
            class="h-[40px] sm:h-[43px] px-[10px] sm:px-[17px] border border-gray dark:border-button-disabled text-gray dark:text-button-disabled hover:bg-gray transition-all hover:text-white rounded-[8px] cursor-pointer"
            @click="menuStore.navigateToItem()">
            {{ $t("back_to_home") }}
          </button>
        </div>
        <div class="space-y-[30px]">
          <p>
            {{ $t("send_code") }}
            <span class="text-button font-semibold">{{ userStore.email }}</span>
            {{ $t("by_email") }}
          </p>
          <div class="space-y-[15px]">
            <p class="pl-6">
              {{ $t("code") }}
            </p>
            <input v-model="userStore.vCode" :placeholder="$t('code')" type="text"
                   class="border-2 border-block placeholder:text-gray dark:placeholder:text-button-disabled text-bg-dark dark:text-bg-light rounded-lg px-6 h-[50px] sm:h-[67px] w-full focus:outline-none focus:ring-0 focus:border-2">
          </div>
        </div>
      </div>
      <div class="py-[25px] sm:py-12 flex justify-center w-full">
        <UiButtonArrow type="fill" :arrow="true" @click="userStore.sendFormCode(true)">
          {{ $t("confirm") }}
        </UiButtonArrow>
      </div>
    </div>
  </UiContainer>
</template>

<script lang="ts" setup>
defineProps<{
  component: {
    id: number
    name: string
    img: string[]
    component_name: string
    is_no_lang: boolean
    page_name: string
    front_section_lang: {
      id_front_section: number
      id_lang: number
    }[]
  }
}>()
const userStore = useUserStore()
const menuStore = useMenuStore()
</script>
