<wxs src="../../utils/format.wxs" module="fmt" />
<!-- toast 加载浮层（fixed，不销毁内容，不白屏） -->
<view class="g-toast-loading" wx:if="{{pageState === 'loading'}}">
  <view class="g-toast-loading-inner">
    <t-loading theme="circular" size="40rpx" />
    <text class="g-toast-loading-text">加载中...</text>
  </view>
</view>

<!-- 错误态（全屏，仅在 error 时展示） -->
<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>

<!-- 主体内容（始终挂载，不随 loading 销毁） -->
<block wx:if="{{pageState !== 'error'}}">
  <!-- Banner 区域（复用助教详情样式） -->
  <view class="banner-section">
    <image class="banner-bg-img" src="/assets/images/banner-bg-coral-aurora.svg" mode="widthFix" />
    <view class="banner-overlay">
      <view class="coach-header">
        <view class="avatar-box">
          <image class="avatar-img" src="/assets/images/avatar-coach.png" mode="aspectFill" />
        </view>
        <view class="info-middle">
          <view class="name-row">
            <text class="coach-name">{{coachName}}</text>
            <coach-level-tag level="{{coachLevel}}" />
          </view>
          <view class="skill-row">
            <text class="store-name-text">{{storeName}}</text>
          </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">预估</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">收入</text>
      <text class="stat-value stat-success">{{totalIncomeLabel}}</text>
      <text class="stat-hint">预估</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>

  <!-- 记录列表 -->
  <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">{{item.date}}&nbsp;&nbsp;—</text>
          <text decode class="dd-stats" wx:if="{{item.totalHoursLabel}}">{{item.totalHoursLabel}}&nbsp;&nbsp;·&nbsp;&nbsp;预估 {{item.totalIncomeLabel}}&nbsp;&nbsp;&nbsp;&nbsp;</text>
          <view class="dd-line"></view>
        </view>

        <!-- 该日期下的记录 -->
        <view class="record-item" wx:for="{{item.records}}" wx:for-item="rec" wx:key="id"
          hover-class="record-item--hover">
          <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.customerName}}</text>
                <text class="record-time">{{rec.timeRange}}</text>
              </view>
              <view class="record-hours-wrap">
                <text class="record-hours">{{fmt.hours(rec.hours)}}</text>
                <text class="record-hours-deduct" wx:if="{{rec.hoursRaw}}">（折后 {{fmt.hours(rec.hoursRaw)}}）</text>
              </view>
            </view>
            <view class="record-bottom">
              <view class="record-tags">
                <text class="course-tag {{rec.courseTypeClass}}">{{rec.courseType}}</text>
                <text class="record-location">{{rec.location}}</text>
              </view>
              <text class="record-income">我的预估收入 <text class="record-income-val">{{fmt.money(rec.income)}}</text></text>
            </view>
          </view>
        </view>
      </block>

      <!-- 列表底部提示 -->
      <view class="list-end-hint">
        <text>— 已加载全部记录 —</text>
      </view>
    </view>
  </view>
</block>

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

<dev-fab />
