<view class="container">
  <view class="hero fade-up">
    <view class="hero-badge">PUBLISH HISTORY</view>
    <view class="hero-title">个人发布历史</view>
    <view class="hero-sub">查看公开/私有/私信发布结果，被拦截内容可在线提交申诉。</view>
  </view>

  <view class="card fade-up fade-up-delay-1">
    <view class="card-title">筛选条件</view>

    <view class="row">
      <text class="label">发布状态</text>
      <picker mode="selector" range="{{statusOptions}}" range-key="label" value="{{statusIndex}}" bindchange="onStatusChange">
        <view class="picker-value">{{statusOptions[statusIndex].label}}</view>
      </picker>
    </view>

    <view class="row">
      <text class="label">发布类型</text>
      <picker mode="selector" range="{{visibilityOptions}}" range-key="label" value="{{visibilityIndex}}" bindchange="onVisibilityChange">
        <view class="picker-value">{{visibilityOptions[visibilityIndex].label}}</view>
      </picker>
    </view>
  </view>

  <view class="card fade-up fade-up-delay-2" wx:if="{{list.length}}">
    <view class="card-title">历史记录</view>

    <view class="list-item" wx:for="{{list}}" wx:key="id">
      <view class="item-title">{{item.text}}</view>
      <view class="item-sub">类型：{{item.visibility_text}} · 时间：{{item.created_text}}</view>

      <view class="row">
        <text class="label">发布状态</text>
        <text class="{{item.status === 'blocked' ? 'status-spam' : 'status-ham'}}">{{item.status === 'blocked' ? '已拦截' : '已发布'}}</text>
      </view>

      <view class="row">
        <text class="label">垃圾概率</text>
        <text class="value">{{item.spam_probability_text}}</text>
      </view>

      <view class="progress-track">
        <view class="progress-fill" style="width: {{item.spam_probability_text}};"></view>
      </view>

      <view class="row">
        <text class="label">申诉状态</text>
        <text class="value">{{item.appeal_status_text}}</text>
      </view>

      <view class="field" wx:if="{{item.reason_tokens && item.reason_tokens.length}}">
        <text class="field-label">风险关键词</text>
        <view class="chip-group">
          <text class="tag" wx:for="{{item.reason_tokens}}" wx:key="*this">{{item}}</text>
        </view>
      </view>

      <view wx:if="{{item.status === 'blocked' && item.appeal_status !== 'pending' && appealPostId !== item.id}}">
        <button class="btn btn-accent" data-id="{{item.id}}" bindtap="startAppeal">发起申诉</button>
      </view>

      <view wx:if="{{appealPostId === item.id}}">
        <view class="field">
          <text class="field-label">申诉理由类型</text>
          <picker mode="selector" range="{{appealReasonTypeOptions}}" range-key="label" value="{{appealReasonTypeIndex}}" bindchange="onReasonTypeChange">
            <view class="picker-value">{{appealReasonTypeOptions[appealReasonTypeIndex].label}}</view>
          </picker>
        </view>
        <textarea class="textarea" placeholder="可补充申诉理由（选择快捷理由后可省略）" value="{{appealReason}}" bindinput="onAppealInput" />
        <view class="field">
          <text class="field-label">证据截图（最多3张）</text>
          <view class="evidence-grid">
            <view class="evidence-item" wx:for="{{appealEvidenceFiles}}" wx:key="index">
              <image class="evidence-thumb" src="{{item}}" mode="aspectFill" />
              <view class="evidence-remove" data-index="{{index}}" bindtap="removeEvidence">×</view>
            </view>
            <view class="evidence-add" wx:if="{{appealEvidenceFiles.length < 3}}" bindtap="chooseEvidence">
              <text class="evidence-add-icon">+</text>
            </view>
          </view>
        </view>
        <view class="btn-row">
          <button class="btn btn-primary" bindtap="submitAppeal">提交申诉</button>
          <button class="btn btn-ghost" bindtap="cancelAppeal">取消</button>
        </view>
      </view>

      <button class="btn btn-ghost" data-id="{{item.id}}" bindtap="removeItem">删除记录</button>
    </view>
  </view>

  <view class="card fade-up fade-up-delay-2" wx:if="{{!list.length}}">
    <view class="empty">暂无发布记录，先去“信息发布”页面提交文本。</view>
  </view>
</view>
