<wxs src="../../utils/format.wxs" module="fmt" />
<!-- 错误态 -->
<view class="page-error" wx:if="{{pageState === 'error'}}">
  <t-icon name="close-circle" size="120rpx" color="#e34d59" />
  <text class="error-text">加载失败，请点击重试</text>
  <view class="retry-btn" hover-class="retry-btn--hover" bindtap="onRetry">
    <text>重试</text>
  </view>
</view>

<!-- 主体内容 -->
<block wx:if="{{pageState !== 'error'}}">
  <!-- Banner 区域（对齐 performance 页面） -->
  <view class="banner-section">
    <image class="banner-bg-img" src="/assets/images/banner-bg-coral-aurora.svg" mode="widthFix" />
    <view class="banner-content">
      <view class="user-info-section">
        <view class="user-info-row">
          <view class="avatar-wrap">
            <image src="{{avatarUrl || '/assets/images/avatar-coach.png'}}" class="avatar-img" mode="aspectFill" />
          </view>
          <view class="user-detail">
            <view class="user-name-row">
              <text class="user-name">{{fmt.safe(coachName)}}</text>
              <text class="user-role-tag">{{fmt.safe(coachRole)}}</text>
            </view>
            <view class="user-store-row">
              <text class="user-store">{{fmt.safe(storeName)}}</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>

  <!-- 月份切换 -->
  <view class="month-switcher">
    <view class="month-btn {{canGoPrev ? '' : 'month-btn-disabled'}}" hover-class="month-btn--hover" data-direction="prev" bindtap="switchMonth">
      <t-icon name="chevron-left" size="32rpx" />
    </view>
    <text class="month-label">{{monthLabel}}</text>
    <view class="month-btn {{canGoNext ? '' : 'month-btn-disabled'}}" hover-class="month-btn--hover" data-direction="next" bindtap="switchMonth">
      <t-icon name="chevron-right" size="32rpx" />
    </view>
  </view>

  <!-- 统计概览 -->
  <view class="stats-overview">
    <view class="stat-item">
      <text class="stat-label">总记录</text>
      <text class="stat-value">{{totalCountLabel}}</text>
    </view>
    <view class="stat-divider"></view>
    <view class="stat-item">
      <text class="stat-label">总业绩时长</text>
      <text class="stat-value stat-primary">{{totalHoursLabel}}</text>
      <text class="stat-hint" wx:if="{{isCurrentMonth}}">预估</text>
      <text class="stat-hours-raw" wx:if="{{totalHoursRawLabel}}">折前 {{totalHoursRawLabel}}</text>
    </view>
    <view class="stat-divider"></view>
    <view class="stat-item">
      <text class="stat-label">{{isCurrentMonth ? '预估收入' : '收入'}}</text>
      <text class="stat-value stat-success">{{totalIncomeLabel}}</text>
      <text class="stat-hint" wx:if="{{isCurrentMonth}}">预估</text>
    </view>
  </view>

  <!-- 空态 -->
  <view class="page-empty" wx:if="{{pageState === 'empty'}}">
    <t-icon name="chart-bar" size="120rpx" color="#dcdcdc" />
    <text class="empty-text">暂无数据</text>
  </view>

  <!-- 记录列表（复用 performance 页面服务记录明细样式） -->
  <view class="records-container" wx:elif="{{pageState === 'normal' || pageState === 'loading'}}">
    <view class="records-card">
      <block wx:for="{{dateGroups}}" wx:key="date">
        <!-- 日期分隔线 -->
        <view class="date-divider">
          <text decode class="dd-date">{{fmt.safe(item.date)}}&nbsp;&nbsp;—</text>
          <text decode class="dd-stats" wx:if="{{item.totalHours}}">{{fmt.safe(item.totalHours)}}小时&nbsp;·&nbsp;{{isCurrentMonth ? '预估 ' : ''}}¥{{fmt.safe(item.totalIncome)}}&nbsp;&nbsp;</text>
          <view class="dd-line"></view>
        </view>

        <!-- 该日期下的记录（与 performance 页面卡片一致） -->
        <view class="record-item" wx:for="{{item.records}}" wx:for-item="rec" wx:key="customerName"
          hover-class="record-item--hover" bindtap="onRecordTap"
          data-member-id="{{rec.memberId}}">
          <view class="record-avatar avatar-{{rec.avatarColor}}">
            <text>{{rec.avatarChar}}</text>
          </view>
          <view class="record-content">
            <view class="record-top">
              <view class="record-name-time">
                <text class="record-name {{rec.isScattered ? 'record-name--scattered' : ''}}">{{fmt.safe(rec.customerName)}}</text>
                <heart-icon score="{{rec.heartScore}}" size="small" />
                <text class="record-time">{{fmt.safe(rec.timeRange)}}</text>
              </view>
              <text class="record-hours">{{fmt.safe(rec.hours)}}小时</text>
            </view>
            <view class="record-bottom">
              <view class="record-tags">
                <text class="course-tag course-tag--{{rec.courseTagClass}}">{{fmt.safe(rec.courseType)}}</text>
                <text class="record-location">{{fmt.safe(rec.location)}}</text>
              </view>
              <text class="record-income">{{isCurrentMonth ? '我的预估收入' : '我的收入'}} <text class="record-income-val">¥{{fmt.safe(rec.income)}}</text></text>
            </view>
          </view>
        </view>
      </block>

      <!-- 列表底部提示 -->
      <view class="list-end-hint" wx:if="{{!hasMore && dateGroups.length > 0}}">
        <text>— 已加载全部记录 —</text>
      </view>
    </view>
  </view>
</block>

<!-- AI 悬浮按钮 -->
<ai-float-button />

<dev-fab />
