<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const username = ref('admin')
const password = ref('admin')
const rememberMe = ref(true)
const router = useRouter()

const handleLogin = () => {
  if (username.value && password.value) {
    router.push('/dashboard')
  }
}

const handleKeyDown = (e: KeyboardEvent) => {
  if (e.key === 'Enter') {
    const target = e.target as HTMLElement
    if (target.tagName === 'INPUT' && target.getAttribute('id') === 'username') {
      e.preventDefault()
      document.getElementById('password')?.focus()
    }
  }
}
</script>

<template>
  <div style="background-color: #2C3E50; display: flex; align-items: center; justify-content: center; height: 100vh; width: 100vw;">
    <div style="width: 100%; max-width: 420px; background: #FFFFFF; border-radius: 6px; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3); overflow: hidden;">
      <div style="background-color: #34495E; color: #FFFFFF; padding: 24px; text-align: center; border-bottom: 3px solid #1A252F;">
        <h2 style="margin: 0 0 6px 0; font-size: 22px;">QuantEngine Vue 3 SPA</h2>
        <p style="margin: 0; font-size: 12px; color: #BDC3C7;">은퇴자산 포트폴리오 투자 관리 시스템</p>
      </div>

      <div style="padding: 28px;">
        <form @submit.prevent="handleLogin" @keydown="handleKeyDown">
          <div style="margin-bottom: 18px;">
            <label for="username" style="display: block; font-weight: bold; font-size: 12px; margin-bottom: 6px; color: #2C3E50;">관리자 아이디</label>
            <input
              id="username"
              v-model="username"
              type="text"
              style="width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid #CBD5E1; border-radius: 4px; font-size: 13px;"
              placeholder="아이디 입력 (Enter 이동)"
              required
              autofocus />
          </div>

          <div style="margin-bottom: 18px;">
            <label for="password" style="display: block; font-weight: bold; font-size: 12px; margin-bottom: 6px; color: #2C3E50;">비밀번호</label>
            <input
              id="password"
              v-model="password"
              type="password"
              style="width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid #CBD5E1; border-radius: 4px; font-size: 13px;"
              placeholder="비밀번호 입력"
              required />
          </div>

          <div style="display: flex; align-items: center; gap: 8px; margin-bottom: 20px;">
            <input id="rememberUsername" v-model="rememberMe" type="checkbox" />
            <label for="rememberUsername" style="font-size: 13px; color: #34495E; cursor: pointer;">아이디 자동 저장</label>
          </div>

          <button
            type="submit"
            style="width: 100%; background-color: #2C3E50; color: #FFFFFF; font-weight: bold; font-size: 14px; padding: 10px; border: none; border-radius: 4px; cursor: pointer;">
            로그인 (Enter)
          </button>
        </form>
      </div>

      <div style="background-color: #ECF0F1; padding: 10px; text-align: center; font-size: 11px; color: #7F8C8D; border-top: 1px solid #BDC3C7;">
        <span><span class="hotkey-badge">Enter</span> 다음 필드 이동</span>
        <span style="margin-left: 12px;">© 2026 QuantEngine Vue 3 + Vite 8</span>
      </div>
    </div>
  </div>
</template>
