<view class="container">
  <view class="hero fade-up">
    <view class="hero-badge">REAL-TIME CHECK</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="field">
      <text class="field-label">内容文本</text>
      <textarea class="textarea" placeholder="请输入要发布的文本信息" value="{{text}}" data-field="text" bindinput="onInput" />
      <view class="field-help">当前字数：{{text.length}}，建议不少于 2 个字符。</view>
    </view>

    <view class="field">
      <view class="row">
        <text class="field-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="field" wx:if="{{visibility === 'direct'}}">
      <text class="field-label">接收人用户名</text>
      <input class="input" placeholder="私信发送时必填" value="{{recipientUsername}}" data-field="recipientUsername" bindinput="onInput" />
    </view>

    <button class="btn btn-primary" loading="{{loading}}" bindtap="publish">提交发布</button>
  </view>

  <view class="card fade-up fade-up-delay-2">
    <view class="card-title">快捷示例</view>
    <view class="chip-group">
      <view class="chip" wx:for="{{quickTexts}}" wx:key="*this" data-text="{{item}}" bindtap="fillQuick">{{item}}</view>
    </view>
  </view>

  <view class="card fade-up fade-up-delay-3" wx:if="{{result}}">
    <view class="card-title">识别反馈</view>

    <view class="row">
      <text class="label">发布结果</text>
      <text class="{{result.publish_allowed ? 'status-ham' : 'status-spam'}}">{{result.publish_allowed ? '发布成功' : '已拦截，需申诉'}}</text>
    </view>

    <view class="row">
      <text class="label">模型判断</text>
      <text class="value">{{result.detect.prediction_text}}</text>
    </view>

    <view class="row">
      <text class="label">垃圾概率</text>
      <text class="value">{{result.detect_spam_probability_text}}</text>
    </view>
    <view class="progress-track">
      <view class="progress-fill" style="width: {{result.detect_spam_probability_text}};"></view>
    </view>

    <view class="row">
      <text class="label">检测置信度</text>
      <text class="value">{{result.detect.confidence_text}}</text>
    </view>
    <view class="progress-track">
      <view class="progress-fill-safe" style="width: {{result.detect.confidence_text}};"></view>
    </view>

    <view class="row">
      <text class="label">本次阈值</text>
      <text class="value">{{result.post_threshold_text}}</text>
    </view>

    <view class="field" wx:if="{{result.detect.reason_tokens && result.detect.reason_tokens.length}}">
      <text class="field-label">风险关键词</text>
      <view class="chip-group">
        <text class="tag tag-danger" wx:for="{{result.detect.reason_tokens}}" wx:key="token" data-token="{{item.token}}" data-weight="{{item.weight}}" bindtap="showTokenWeight">{{item.token}}</text>
      </view>
    </view>

    <button class="btn btn-ghost" bindtap="gotoHistory">查看发布历史</button>
  </view>
</view>
