<wxs src="../common/utils.wxs" module="_" />

<view class="class {{chatItemClass}}" style="{{_._style([style, customStyle])}}" bindlongpress="handleLongPress">
  <view class="{{classPrefix}}__avatar">
    <!-- 头像插槽 -->
    <slot name="avatar" />
    <block wx:if="{{avatar}}">
      <image src="{{avatar}}" class="{{classPrefix}}__avatar-image"></image>
    </block>
  </view>
  <view class="{{contentClasses}}">
    <view class="{{classPrefix}}__base">
      <!-- 昵称插槽 -->
      <slot name="name" />
      <text wx:if="{{showName}}" class="{{classPrefix}}__name">{{name}}</text>
      <text wx:if="{{datetime}}" class="{{classPrefix}}__time">{{datetime}}</text>
    </view>
    <block wx:if="{{status === 'pending'}}">
      <view style="width: 100%">
        <chat-loading animation="{{animation}}"></chat-loading>
      </view>
    </block>
    <block wx:else>
      <view class="{{classPrefix}}__detail">
        <!-- 属性传值优先级高于content插槽 -->
        <block wx:if="{{content.length > 0}}">
          <block wx:for="{{content}}" wx:key="index">
            <attachments
              wx:if="{{item.type === 'attachment' && role === 'user'}}"
              items="{{item.data}}"
              removable="{{false}}"
              inChat="{{true}}"
            >
            </attachments>
            <chat-thinking
              wx:if="{{item.type === 'thinking'}}"
              content="{{item.data}}"
              role="{{role}}"
              status="{{status}}"
              layout="{{chatContentProps.thinking.layout}}"
              max-height="{{chatContentProps.thinking.maxHeight}}"
              animation="{{chatContentProps.thinking.animation}}"
              collapsed="{{chatContentProps.thinking.collapsed}}"
            ></chat-thinking>
            <chat-content
              wx:elif="{{item.type === 'text' || item.type === 'markdown'}}"
              content="{{item}}"
              role="{{role}}"
              status="{{status}}"
              catchclick="onContentClick"
            ></chat-content>
          </block>
        </block>
        <block wx:else>
          <slot name="content" />
        </block>
      </view>
    </block>
    <view wx:if="{{role === 'assistant'}}" class="{{classPrefix}}__actionbar">
      <slot name="actionbar"></slot>
    </view>
  </view>
</view>
