<script setup lang="ts">
import { computed } from 'vue';
import type { Component } from 'vue';
import { loginModuleRecord } from '@/constants/app';
import { useThemeStore } from '@/store/modules/theme';
import { $t } from '@/locales';
import PwdLogin from './modules/pwd-login.vue';
import CodeLogin from './modules/code-login.vue';
import Register from './modules/register.vue';
import ResetPwd from './modules/reset-pwd.vue';
import BindWechat from './modules/bind-wechat.vue';

interface Props {
  /** The login module */
  module?: UnionKey.LoginModule;
}

const props = defineProps<Props>();

const themeStore = useThemeStore();

interface LoginModule {
  label: string;
  component: Component;
}

const moduleMap: Record<UnionKey.LoginModule, LoginModule> = {
  'pwd-login': { label: loginModuleRecord['pwd-login'], component: PwdLogin },
  'code-login': { label: loginModuleRecord['code-login'], component: CodeLogin },
  register: { label: loginModuleRecord.register, component: Register },
  'reset-pwd': { label: loginModuleRecord['reset-pwd'], component: ResetPwd },
  'bind-wechat': { label: loginModuleRecord['bind-wechat'], component: BindWechat }
};

const activeModule = computed(() => moduleMap[props.module || 'pwd-login']);
</script>

<template>
  <div class="relative size-full flex-center overflow-hidden">
    <NCard :bordered="false" class="relative z-4 w-auto rd-12px">
      <div class="flex items-center">
        <div class="w-400px lt-sm:w-300px">
          <header class="flex-y-center justify-between">
            <SystemLogo class="text-64px text-primary lt-sm:text-48px" width="80" />
            <h3 class="text-28px text-primary font-500 lt-sm:text-22px">{{ $t('system.title') }}</h3>
            <div class="i-flex-col">
              <ThemeSchemaSwitch
                :theme-schema="themeStore.themeScheme"
                :show-tooltip="false"
                class="text-20px lt-sm:text-18px"
                @switch="themeStore.toggleThemeScheme"
              />
            </div>
          </header>
          <main class="pt-24px">
            <h3 class="text-18px text-primary font-medium">{{ $t(activeModule.label) }}</h3>
            <div class="pt-24px">
              <Transition :name="themeStore.page.animateMode" mode="out-in" appear>
                <component :is="activeModule.component" />
              </Transition>
            </div>
          </main>
        </div>
        <Transition name="fade-bottom" mode="out-in" appear>
          <SvgIcon local-icon="banner" class="text-400px text-primary max-md:hidden"></SvgIcon>
        </Transition>
      </div>
    </NCard>

    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 600" class="absolute bottom-0 left-0 right-0">
      <path
        fill="#9ED605"
        fill-opacity="1"
        d="M0,480L48,453.3C96,427,192,373,288,373.3C384,373,480,427,576,405.3C672,384,768,288,864,240C960,192,1056,192,1152,213.3C1248,235,1344,277,1392,298.7L1440,320L1440,600L1392,600C1344,600,1248,600,1152,600C1056,600,960,600,864,600C768,600,672,600,576,600C480,600,384,600,288,600C192,600,96,600,48,600L0,600Z"
      ></path>
    </svg>
  </div>
</template>

<style scoped></style>
