<!-- login.wxml - 登录页 -->
<view class="login-container">
  <!-- 检查登录状态时显示 loading -->
  <view class="loading-check" wx:if="{{loading}}">
    <view class="loading-spinner"></view>
    <view class="loading-text">检查登录状态...</view>
  </view>

  <!-- Logo / 标题区（loading 时不显示完整表单但保留 header） -->
  <view class="login-header" wx:if="{{!loading}}">
    <view class="logo">🅿️</view>
    <view class="title">停车激励</view>
    <view class="subtitle">邀请好友，赚取停车积点</view>
  </view>

  <!-- 登录表单（仅未登录或无车牌时显示） -->
  <view class="login-form card" wx:if="{{!loading && !skipToHome}}">
    <!-- 车牌号 - 方框输入 -->
    <view class="form-group">
      <view class="form-label">绑定车牌号码</view>
      <view class="plate-boxes" bindtap="onPlateAreaTap">
        <!-- 第1位：省份简称（汉字） -->
        <view class="plate-box {{plateIndex === 0 ? 'box-active' : ''}} {{plateChars[0] ? 'box-filled' : ''}}"
              data-index="0" bindtap="onBoxTap">
          <text>{{plateChars[0] || ''}}</text>
        </view>
        <!-- 分隔点 -->
        <view class="plate-sep">·</view>
        <!-- 第2位：城市字母 -->
        <view class="plate-box {{plateIndex === 1 ? 'box-active' : ''}} {{plateChars[1] ? 'box-filled' : ''}}"
              data-index="1" bindtap="onBoxTap">
          <text>{{plateChars[1] || ''}}</text>
        </view>
        <!-- 第3-7位 -->
        <view class="plate-box {{plateIndex === 2 ? 'box-active' : ''}} {{plateChars[2] ? 'box-filled' : ''}}"
              data-index="2" bindtap="onBoxTap">
          <text>{{plateChars[2] || ''}}</text>
        </view>
        <view class="plate-box {{plateIndex === 3 ? 'box-active' : ''}} {{plateChars[3] ? 'box-filled' : ''}}"
              data-index="3" bindtap="onBoxTap">
          <text>{{plateChars[3] || ''}}</text>
        </view>
        <view class="plate-box {{plateIndex === 4 ? 'box-active' : ''}} {{plateChars[4] ? 'box-filled' : ''}}"
              data-index="4" bindtap="onBoxTap">
          <text>{{plateChars[4] || ''}}</text>
        </view>
        <view class="plate-box {{plateIndex === 5 ? 'box-active' : ''}} {{plateChars[5] ? 'box-filled' : ''}}"
              data-index="5" bindtap="onBoxTap">
          <text>{{plateChars[5] || ''}}</text>
        </view>
        <view class="plate-box {{plateIndex === 6 ? 'box-active' : ''}} {{plateChars[6] ? 'box-filled' : ''}}"
              data-index="6" bindtap="onBoxTap">
          <text>{{plateChars[6] || ''}}</text>
        </view>
        <!-- 第8位：新能源车牌多一位 -->
        <view class="plate-box plate-box-extra {{plateIndex === 7 ? 'box-active' : ''}} {{plateChars[7] ? 'box-filled' : ''}}"
              data-index="7" bindtap="onBoxTap">
          <text>{{plateChars[7] || ''}}</text>
        </view>
      </view>
      <view class="plate-hint">
        <text class="text-hint">前2位：省份+城市 · 后5~6位：字母或数字 · 新能源8位</text>
      </view>

      <!-- 隐藏输入框：始终聚焦捕获键盘 -->
      <input
        class="plate-hidden-input"
        value="{{hiddenValue}}"
        type="text"
        adjust-position="{{false}}"
        focus="{{inputFocus}}"
        bindinput="onCharInput"
        bindfocus="onInputFocus"
        bindblur="onInputBlur"
      />
    </view>

    <!-- 邀请人信息（来自扫码） -->
    <view class="inviter-card" wx:if="{{referralCode}}">
      <view class="inviter-label">🎯 邀请人车牌号</view>
      <view class="inviter-plate">{{referralCode}}</view>
      <view class="inviter-tip">扫码自动识别，无需手动输入</view>
    </view>

    <button
      class="btn btn-primary btn-block mt-32"
      bindtap="handleLogin"
      loading="{{loading}}"
      disabled="{{!plateComplete || loading}}"
    >
      {{loading ? '登录中...' : '微信一键登录'}}
    </button>

    <view class="login-tips mt-24 text-center text-hint">
      <text>登录即表示同意《用户协议》和《隐私政策》</text>
    </view>
  </view>

  <!-- 说明 -->
  <view class="login-info card" wx:if="{{!loading && !skipToHome}}">
    <view class="info-title">💡 规则说明</view>
    <view class="info-item">🔗 <text>分享邀请海报给其他车主</text></view>
    <view class="info-item">💰 <text>每邀请一位车主，获得30积点</text></view>
    <view class="info-item">🎫 <text>积点可兑换停车优惠券</text></view>
    <view class="info-item">💸 <text>下家缴费时，20%实付金额转为您的积点</text></view>
  </view>
</view>
