<template>
  <view class="login-page">
    <view class="header-hero" :style="{ paddingTop: (statusBarHeight + 16) + 'px' }">
      <view class="logo-section">
        <image class="login-logo" src="/static/logo_us.png" mode="aspectFit" />
        <text class="hero-sub">{{ t('login.employeePortal') }}</text>
      </view>
    </view>

    <view class="form-wrap">
      <view class="form-card">
        <view class="form-group">
          <text class="label">{{ t('login.email') }}</text>
          <input
            v-model="email"
            type="text"
            inputmode="email"
            class="input"
            :placeholder="t('login.emailPlaceholder')"
            placeholder-class="placeholder"
          />
        </view>
        <view class="form-group">
          <text class="label">{{ t('login.password') }}</text>
          <input
            v-model="password"
            type="password"
            class="input"
            :placeholder="t('login.passwordPlaceholder')"
            placeholder-class="placeholder"
          />
        </view>
        <view class="form-row">
          <view class="remember-row">
            <switch :checked="rememberMe" @change="rememberMe = $event.detail.value" :color="'#1F3A8A'" />
            <text class="remember-text">{{ t('login.rememberMe') }}</text>
          </view>
          <text class="forgot-link">{{ t('login.forgotPassword') }}</text>
        </view>
        <view
          class="submit-btn"
          :class="{ disabled: isLoading }"
          @click="handleLogin"
        >
          <text class="submit-btn-text">{{ isLoading ? t('login.signingIn') : t('login.signIn') }}</text>
        </view>
      </view>
      <text class="copyright">{{ t('login.copyright') }}</text>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { getStatusBarHeight } from '../../utils/statusBar'

const { t } = useI18n()
const statusBarHeight = getStatusBarHeight()
const email = ref('')
const password = ref('')
const rememberMe = ref(false)
const isLoading = ref(false)

const handleLogin = () => {
  isLoading.value = true
  setTimeout(() => {
    uni.setStorageSync('isLoggedIn', 'true')
    uni.setStorageSync('userName', 'John Smith')
    uni.showToast({ title: t('login.loginSuccess'), icon: 'success' })
    uni.redirectTo({ url: '/pages/store-select/store-select' })
    isLoading.value = false
  }, 1000)
}
</script>

<style scoped>
.login-page {
  min-height: 100vh;
  background: #f9fafb;
  padding-bottom: 48rpx;
}

.header-hero {
  background: linear-gradient(135deg, var(--theme-primary), var(--theme-primary-dark));
  padding: 0 48rpx 24rpx;
  text-align: center;
  flex-shrink: 0;
}

.logo-section {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.login-logo {
  width: 360rpx;
  height: 120rpx;
  margin-bottom: 12rpx;
  background: rgba(255,255,255,0.92);
  border-radius: 16rpx;
  padding: 16rpx;
}

.hero-sub {
  font-size: 28rpx;
  color: rgba(255,255,255,0.85);
}

.form-wrap {
  padding: 24rpx 48rpx 48rpx;
}

.form-card {
  background: #fff;
  padding: 48rpx;
  border-radius: 20rpx;
  box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.06);
}

.form-group {
  margin-bottom: 40rpx;
}

.label {
  font-size: 30rpx;
  font-weight: 500;
  color: #374151;
  display: block;
  margin-bottom: 16rpx;
}

.input {
  height: 96rpx;
  min-height: 48px;
  padding: 0 24rpx;
  background: #f3f4f6;
  border-radius: 16rpx;
  font-size: 32rpx;
  display: block;
  width: 100%;
  box-sizing: border-box;
}

.placeholder {
  color: #9ca3af;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 40rpx;
}

.remember-row {
  display: flex;
  align-items: center;
  gap: 16rpx;
}

.remember-text {
  font-size: 28rpx;
  color: #374151;
}

.forgot-link {
  font-size: 28rpx;
  color: var(--theme-primary);
  font-weight: 500;
}

.submit-btn {
  width: 100%;
  height: 96rpx;
  background: var(--theme-primary);
  border-radius: 16rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.submit-btn.disabled {
  opacity: 0.7;
}

.submit-btn-text {
  font-size: 32rpx;
  font-weight: 600;
  color: #ffffff;
  line-height: 1;
}

.copyright {
  display: block;
  text-align: center;
  font-size: 24rpx;
  color: #9ca3af;
  margin-top: 48rpx;
}
</style>
