<wxs module="_">
  module.exports.isUser = function (sender) {
    return sender === 'user'
  }
  module.exports.isHuman = function (sender) {
    return sender === 'human'
  }
  module.exports.isSystem = function (sender) {
    return sender === 'system'
  }
  module.exports.isAgent = function (sender) {
    return sender === 'agent'
  }
  // 判断是否需要 Markdown 渲染（AI 和医生的消息）
  module.exports.needMarkdown = function (sender) {
    return sender === 'agent' || sender === 'human'
  }
</wxs>
<!--module/chats/components/message-consult/message-consult.wxml-->
<view class="consult-wrapper {{consultEnded ? 'consult-ended' : ''}}">
  <block wx:for="{{messages}}" wx:key="id">
    <!-- 系统消息样式 -->
    <view wx:if="{{_.isSystem(item.sender)}}" class="system-wrapper">
      <view class="date">{{item.sendTime}}</view>
      <view class="title">{{item.messageContent}}</view>
    </view>
    <!-- 普通消息 -->
    <view wx:else class="chat-card {{_.isUser(item.sender) ? 'right' : 'left'}}">
      <view class="chat-card__avatar ">
        <user-avatar wx:if="{{_.isUser(item.sender)}}"></user-avatar>
        <user-avatar wx:elif="{{_.isHuman(item.sender)}}"></user-avatar>
        <image wx:else src="../../assets/robot.png" mode="aspectFill" />
      </view>
      <view class="{{item.messageType === '2' ? 'image-message' : 'text-message'}}">
        <block wx:if="{{item.messageType === '1'}}">
          <t-cell t-class="cell-border-gradient" bordered="{{false}}" class="chat-box">
            <view slot="title" class="message-content">
              <!-- 如果是 AI 或医生的消息，使用 towxml 直接渲染 Markdown -->
              <block wx:if="{{_.needMarkdown(item.sender)}}">
                <towxml markdown="{{item.messageContent}}" theme="light" />
              </block>
              <!-- 其他消息使用普通文本显示 -->
              <text wx:else>{{item.messageContent}}</text>
            </view>
          </t-cell>
        </block>
        <block wx:elif="{{item.messageType === '2'}}">
          <image class="message-image" src="{{item.messageContent}}"
           mode="aspectFill" show-menu-by-longpress="true"
           bind:tap="previewImage" 
           data-url="{{item.messageContent}}" />
        </block>
      </view>
    </view>
  </block>
</view>

<view class="input-panel" style="bottom: {{inputBoxBottom}}rpx;" bind:tap="tapPanel" wx:if="{{!consultEnded}}">
  <view class="action-bar">
    <view class="action-btn danger" bind:tap="endConsult">结束{{i18n.consultChat._}}</view>
  </view>
  <view class="input-row">
    <textarea
      class="text-input"
      placeholder="请输入内容"
      bind:input="handleInput"
      bind:linechange="onLineChange"
      value="{{inputText}}"
      confirm-type="send"
      bindconfirm="sendText"
      adjust-position="{{false}}"
      bind:focus="onInputFocus"
      bind:blur="onInputBlur"
      focus="{{inputFocus}}"
      maxlength="{{2000}}"
      show-confirm-bar="{{false}}"
      style="height: {{textareaHeight}}rpx;"
    />
    <view class="media-btn" bind:tap="chooseImage">
      <t-icon name="camera" size="44rpx" color="#1D6FF6" />
      <text class="media-text">图片</text>
    </view>
    <view class="send-btn" bind:tap="sendText">发送</view>
  </view>
</view>

