<template>
  <div class="login">
    <div class="glow glow-one"></div>
    <div class="glow glow-two"></div>
    <section class="hero">
      <div class="badge">Urban Lighting Management Platform</div>
      <h1>城市照明综合网管平台<br />多租户运营中心</h1>
      <p>面向全国、省、市、区县的路灯资产监控、报警处理与区域权限管控。</p>
      <div class="stats">
        <div>
          <strong>4</strong>
          <span>级区域权限</span>
        </div>
        <div>
          <strong>24h</strong>
          <span>报警监控</span>
        </div>
        <div>
          <strong>API</strong>
          <span>外部接入</span>
        </div>
      </div>
    </section>
    <el-card class="login-card" shadow="never">
      <div class="card-title">
        <span>租户登录</span>
        <small>Tenant Console</small>
      </div>
      <el-form :model="form" label-position="top" @keyup.enter="submit">
        <el-form-item label="租户编码">
          <el-input v-model="form.tenantCode" size="large" placeholder="请输入租户编码" />
        </el-form-item>
        <el-form-item label="账号">
          <el-input v-model="form.username" size="large" placeholder="请输入账号" />
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password" size="large" type="password" show-password placeholder="请输入密码" />
        </el-form-item>
        <el-button type="primary" :loading="loading" class="login-button" size="large" @click="submit">进入运营中心</el-button>
      </el-form>
      <div class="hint">请输入租户编码、账号和密码登录。</div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue';
import { useRouter } from 'vue-router';
import { firstPermittedPath } from '../router';
import { useAuthStore } from '../stores/auth';

const router = useRouter();
const authStore = useAuthStore();
const loading = ref(false);
// const form = reactive({ tenantCode: 'default', username: 'admin', password: 'admin123456' });
const form = reactive({ tenantCode: '', username: '', password: '' });

async function submit() {
  loading.value = true;
  try {
    await authStore.login(form.tenantCode, form.username, form.password);
    await router.push(firstPermittedPath(authStore.permissions));
  } finally {
    loading.value = false;
  }
}
</script>

<style scoped>
.login {
  min-height: 100vh;
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 460px;
  gap: 72px;
  align-items: center;
  padding: 0 9vw;
  background:
    linear-gradient(rgba(10, 18, 36, 0.82) 1px, transparent 1px),
    linear-gradient(90deg, rgba(10, 18, 36, 0.82) 1px, transparent 1px),
    radial-gradient(circle at 18% 20%, rgba(56, 189, 248, 0.35), transparent 30%),
    radial-gradient(circle at 80% 10%, rgba(99, 102, 241, 0.35), transparent 28%),
    #030712;
  background-size: 48px 48px, 48px 48px, auto, auto, auto;
  color: #f8fafc;
}

.glow {
  position: absolute;
  width: 420px;
  height: 420px;
  border-radius: 999px;
  filter: blur(40px);
  opacity: 0.34;
}

.glow-one {
  right: 8%;
  top: 12%;
  background: #0ea5e9;
}

.glow-two {
  left: 12%;
  bottom: 8%;
  background: #6366f1;
}

.hero,
.login-card {
  position: relative;
  z-index: 1;
}

.badge {
  display: inline-flex;
  padding: 8px 14px;
  border: 1px solid rgba(125, 211, 252, 0.45);
  border-radius: 999px;
  color: #bae6fd;
  background: rgba(14, 165, 233, 0.12);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 12px;
}

.hero h1 {
  margin: 24px 0 18px;
  font-size: clamp(42px, 6vw, 72px);
  line-height: 1.06;
  letter-spacing: -0.05em;
}

.hero p {
  max-width: 640px;
  margin: 0;
  color: #cbd5e1;
  font-size: 18px;
  line-height: 1.8;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 140px));
  gap: 16px;
  margin-top: 44px;
}

.stats div {
  padding: 18px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(16px);
}

.stats strong {
  display: block;
  font-size: 28px;
  color: #67e8f9;
}

.stats span {
  color: #94a3b8;
  font-size: 13px;
}

.login-card {
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 28px;
  background: rgba(15, 23, 42, 0.78);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(24px);
}

.card-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 26px;
  color: #f8fafc;
  font-size: 28px;
  font-weight: 700;
}

.card-title small {
  color: #38bdf8;
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.login-button {
  width: 100%;
  margin-top: 6px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  border: none;
}

.hint {
  margin-top: 16px;
  color: #94a3b8;
  font-size: 13px;
}

:deep(.el-form-item__label) {
  color: #cbd5e1;
}

:deep(.el-input__wrapper) {
  background: rgba(2, 6, 23, 0.68);
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: none;
}

:deep(.el-input__inner) {
  color: #f8fafc;
}

@media (max-width: 980px) {
  .login {
    grid-template-columns: 1fr;
    gap: 32px;
    padding: 40px 20px;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
  }
}
</style>
