<!--pages/wiki/chat/history/index.wxml-->
<view class="history-page">
  <scroll-view 
    class="history-scroll" 
    scroll-y 
    bindscrolltolower="loadMore"
    enhanced
    show-scrollbar="{{false}}"
  >
    <!-- Header Actions -->
    <view class="header-bar" wx:if="{{list.length > 0}}">
      <text class="header-count">共 {{total}} 条记录</text>
      <view class="clear-btn" bindtap="onClearAll">
        <t-icon name="delete" size="32rpx" color="#EF4444" />
        <text>清空全部</text>
      </view>
    </view>

    <!-- History List -->
    <view wx:for="{{list}}" wx:key="id" class="history-card" bindtap="onTapItem" data-item="{{item}}">
      <view class="card-header">
        <text class="card-time">{{item.createdAtStr}}</text>
        <view class="card-del" catchtap="onDeleteItem" data-id="{{item.id}}">
          <t-icon name="close" size="28rpx" color="#9CA3AF" />
        </view>
      </view>
      <view class="card-question">
        <text class="q-label">Q</text>
        <text class="q-text">{{item.question}}</text>
      </view>
      <view class="card-answer">
        <text class="a-label">A</text>
        <text class="a-text">{{item.answerPreview}}</text>
        <view class="card-arrow">
          <t-icon name="chevron-right" size="28rpx" color="#CCC" />
        </view>
      </view>
    </view>

    <!-- States -->
    <view class="footer">
      <t-loading wx:if="{{loading}}" theme="circular" size="40rpx" text="加载中..." />
      <text wx:elif="{{!hasMore && list.length > 0}}" class="no-more">没有更多了</text>
    </view>

    <view wx:if="{{!loading && list.length === 0}}" class="empty-wrap">
      <view class="empty-icon">📝</view>
      <text class="empty-text">暂无问答记录</text>
      <text class="empty-sub">去和AI助手聊聊吧</text>
      <view class="empty-cta" bindtap="goToChat">
        <text>开始提问</text>
      </view>
    </view>

    <view style="height: 60rpx;"></view>
  </scroll-view>

  <t-dialog
    visible="{{showClearDialog}}"
    title="清空全部历史"
    content="确定要清空所有问答记录吗？此操作不可恢复。"
    confirm-btn="确定清空"
    cancel-btn="取消"
    bind:confirm="doClearAll"
    bind:cancel="closeClearDialog"
  />
</view>
