<!--module/chats/pages/consultation-record/consultation-record.wxml-->
<t-navbar title="{{i18n.consultChat.title}}" left-arrow />
<scroll-view 
  id="scrollview" 
  class="page-scroll__container" 
  type="list" 
  scroll-y 
  enhanced="{{true}}" 
  enable-passive 
  style="height: calc(100vh - 180rpx);"
  bindscrolltolower="onScrollToLower"
  lower-threshold="{{50}}"
>
  <view class="consultation-container">
    <block wx:for="{{consultationList}}" wx:key="id">
      <!-- 开始咨询 -->
      <view class="consultation-session">
        <view class="timestamp">{{item.startTime}}</view>
        <view class="status-message">开始{{i18n.consultChat._}}</view>
        
        <!-- 消息列表 -->
        <view class="messages-list">
          <block wx:for="{{item.items}}" wx:key="id" wx:for-item="message">
            <!-- 系统消息 -->
            <view wx:if="{{message.sendType === '3'}}" class="message-item message-item--system">
              <view class="message-bubble message-bubble--system">
                  <view class="timestamp">{{item.startTime}}</view>
                <text class="message-text message-text--system">{{message.messageContent}}</text>
              </view>
            </view>
            
            <!-- 患者消息 (sendType === '1') - 右侧显示 -->
            <view wx:elif="{{message.sendType === '1'}}" class="message-item message-item--user">
              <view class="message-bubble {{message.messageType==='1'?'message-bubble--user':''}}">
                <!-- 文本消息 -->
                <block wx:if="{{message.messageType === '1'}}">
                  <text class="message-text message-text--user">{{message.messageContent}}</text>
                </block>
                <!-- 图片消息 -->
                <block wx:elif="{{message.messageType === '2'}}">
                  <image class="message-image" src="{{message.messageContent}}" mode="aspectFill" show-menu-by-longpress="true" bind:tap="previewImage" data-url="{{message.messageContent}}" />
                </block>
              </view>
              <t-avatar class="message-avatar" icon="user" size="40px" />
            </view>
            
            <!-- 医生/AI消息 (sendType === '2' 或 '4') - 左侧显示 -->
            <view wx:else class="message-item message-item--agent">
              <t-avatar class="message-avatar message-avatar--agent" icon="{{message.sendType === '2' ? 'user' : 'service'}}" size="40px" />
              <view class="message-bubble {{message.messageType==='1'?'message-bubble--agent':''}}">
                <!-- 文本消息 -->
                <block wx:if="{{message.messageType === '1'}}">
                  <text class="message-text">{{message.messageContent}}</text>
                </block>
                <!-- 图片消息 -->
                <block wx:elif="{{message.messageType === '2'}}">
                  <image class="message-image" src="{{message.messageContent}}" mode="aspectFill" show-menu-by-longpress="true" bind:tap="previewImage" data-url="{{message.messageContent}}" />
                </block>
              </view>
            </view>
          </block>
        </view>
        
        <!-- 咨询结束 -->
        <view class="timestamp">{{item.endTime}}</view>
        <view class="status-message">{{i18n.consultChat._}}结束</view>
      </view>
    </block>
    
    <!-- 加载更多/无更多数据提示 -->
    <view class="loading-container" style="text-align: center; padding: 20rpx; color: #999; font-size: 24rpx;" wx:if="{{isPage}}">
      <view wx:if="{{isLoading}}">加载中...</view>
      <view wx:elif="{{!hasMore}}">没有更多数据了</view>
    </view>
  </view>
</scroll-view>

  