<scroll-view class="page" scroll-y>
  <view class="shell">
    <view class="hero">
      <view class="hero__eyebrow">Prepare</view>
      <view class="hero__title">{{titleText}}</view>
      <view class="hero__desc">{{summaryText}}</view>
    </view>

    <view class="panel">
      <view class="panel__title">活动与发布</view>
      <view class="summary">Release：{{releaseText}}</view>
      <view class="summary">主动作：{{actionText}}</view>
      <view class="summary">状态：{{statusText}}</view>
      <view class="summary">赛道模式：{{variantModeText}}</view>
      <view class="summary">赛道摘要：{{variantSummaryText}}</view>
      <view class="summary">当前选择：{{selectedVariantText}}</view>
    </view>

    <view class="panel">
      <view class="panel__title">活动运营摘要</view>
      <view class="summary">当前阶段先展示当前发布 release 绑定的活动运营对象摘要，不展开复杂 schema。</view>
      <view class="row">
        <view class="row__label">当前发布展示版本</view>
        <view class="row__value">{{presentationText}}</view>
      </view>
      <view class="row">
        <view class="row__label">当前发布内容包版本</view>
        <view class="row__value">{{contentBundleText}}</view>
      </view>
    </view>

    <view class="panel">
      <view class="panel__title">运行对象摘要</view>
      <view class="summary">当前阶段以前端已知信息预览，最终绑定以后端 `launch.runtime` 为准。</view>
      <view class="row">
        <view class="row__label">地点</view>
        <view class="row__value">{{runtimePlaceText}}</view>
      </view>
      <view class="row">
        <view class="row__label">地图</view>
        <view class="row__value">{{runtimeMapText}}</view>
      </view>
      <view class="row">
        <view class="row__label">赛道</view>
        <view class="row__value">{{runtimeVariantText}}</view>
      </view>
      <view class="row">
        <view class="row__label">RouteCode</view>
        <view class="row__value">{{runtimeRouteCodeText}}</view>
      </view>
    </view>

    <view class="panel" wx:if="{{showVariantSelector}}">
      <view class="panel__title">赛道选择</view>
      <view class="summary">当前活动要求手动指定赛道。这里的选择会随 launch 一起带给后端，最终绑定以后端返回为准。</view>
      <view wx:if="{{!selectableVariants.length}}" class="summary">{{variantSelectorEmptyText}}</view>
      <view wx:if="{{selectableVariants.length}}" class="variant-list">
        <view wx:for="{{selectableVariants}}" wx:key="id" class="variant-card {{item.selected ? 'variant-card--active' : ''}}" data-variant-id="{{item.id}}" bindtap="handleSelectVariant">
          <view class="variant-card__main">
            <view class="variant-card__title-row">
              <text class="variant-card__name">{{item.name}}</text>
              <text class="variant-card__badge" wx:if="{{item.selected}}">已选中</text>
            </view>
            <text class="variant-card__meta">{{item.routeCodeText}}</text>
            <text class="variant-card__meta">{{item.descriptionText}}</text>
          </view>
        </view>
      </view>
    </view>

    <view class="panel">
      <view class="panel__title">设备准备</view>
      <view class="summary">这一页现在负责局前设备准备。定位权限先在这里确认，心率带支持先连后进图，地图内仍保留局中快速重连入口。</view>
      <view class="row">
        <view class="row__label">定位状态</view>
        <view class="row__value">{{locationStatusText}}</view>
      </view>
      <view class="summary" wx:if="{{locationPermissionGranted && !locationBackgroundPermissionGranted}}">已完成前台定位授权；如果后续需要后台持续定位，请在系统设置中补齐后台权限。</view>
      <view class="actions">
        <button class="btn btn--secondary" bindtap="handleRequestLocationPermission">申请定位权限</button>
        <button class="btn btn--ghost" bindtap="handleOpenLocationSettings">打开系统设置</button>
      </view>
      <view class="row">
        <view class="row__label">心率带</view>
        <view class="row__value">{{heartRateStatusText}}</view>
      </view>
      <view class="row">
        <view class="row__label">当前设备</view>
        <view class="row__value">{{heartRateDeviceText}}</view>
      </view>
      <view class="row">
        <view class="row__label">扫描状态</view>
        <view class="row__value">{{heartRateScanText}}</view>
      </view>
      <view class="row">
        <view class="row__label">模拟源</view>
        <view class="row__value">{{mockSourceStatusText}}</view>
      </view>
      <view class="actions">
        <button class="btn btn--secondary" bindtap="handleOpenHeartRateDevicePicker">选择设备</button>
        <button class="btn btn--ghost" bindtap="handlePrepareHeartRateConnect">重新扫描</button>
        <button class="btn btn--ghost" bindtap="handlePrepareHeartRateDisconnect">断开连接</button>
        <button class="btn btn--ghost" bindtap="handlePrepareHeartRateClearPreferred">清除首选</button>
      </view>
    </view>

    <view class="panel">
      <view class="panel__title">开始比赛</view>
      <view class="summary">这一页先承担局前准备壳子，后面会继续接定位权限、心率带局前连接和设备检查。</view>
      <view class="actions">
        <button class="btn btn--secondary" bindtap="handleBack">返回活动页</button>
        <button class="btn btn--ghost" bindtap="handleRefresh">刷新</button>
        <button class="btn btn--primary" bindtap="handleLaunch" disabled="{{!canLaunch}}">进入地图</button>
      </view>
    </view>
  </view>

  <view wx:if="{{showHeartRateDevicePicker}}" class="picker-mask" bindtap="handleCloseHeartRateDevicePicker"></view>
  <view wx:if="{{showHeartRateDevicePicker}}" class="picker-sheet">
    <view class="picker-sheet__header">
      <view class="picker-sheet__title">选择心率带设备</view>
      <button class="picker-sheet__close" bindtap="handleCloseHeartRateDevicePicker">关闭</button>
    </view>
    <view class="summary">扫描状态：{{heartRateScanText}}</view>
    <view wx:if="{{!heartRateDiscoveredDevices.length}}" class="summary">当前还没有发现设备，可先点“重新扫描”。</view>
    <view wx:if="{{heartRateDiscoveredDevices.length}}" class="device-list">
      <view wx:for="{{heartRateDiscoveredDevices}}" wx:key="deviceId" class="device-card">
        <view class="device-card__main">
          <view class="device-card__title-row">
            <text class="device-card__name">{{item.name}}</text>
            <text class="device-card__badge" wx:if="{{item.preferred}}">首选</text>
            <text class="device-card__badge device-card__badge--active" wx:if="{{item.connected}}">已连接</text>
          </view>
          <text class="device-card__meta">{{item.rssiText}}</text>
        </view>
        <button class="btn {{item.connected ? 'btn--ghost' : 'btn--secondary'}} device-card__action" data-device-id="{{item.deviceId}}" bindtap="handlePrepareHeartRateDeviceConnect">{{item.connected ? '已连接' : '连接'}}</button>
      </view>
    </view>
  </view>
</scroll-view>
