<view class="container">
  <view class="hero fade-up">
    <view class="hero-badge">SAMPLE LAB</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>
      <input class="input" placeholder="输入关键词" value="{{keyword}}" data-field="keyword" bindinput="onInput" />
    </view>

    <radio-group class="row" bindchange="onLabelChange">
      <label class="label"><radio value="" checked="{{label === ''}}" />全部</label>
      <label class="label"><radio value="spam" checked="{{label === 'spam'}}" />垃圾</label>
      <label class="label"><radio value="ham" checked="{{label === 'ham'}}" />正常</label>
    </radio-group>

    <button class="btn btn-primary" loading="{{loading}}" bindtap="fetchSamples">查询</button>
  </view>

  <view class="card fade-up fade-up-delay-1">
    <view class="card-title">新增样本</view>

    <textarea class="textarea" placeholder="输入样本文本" value="{{form.text}}" data-field="text" bindinput="onFormInput" />

    <radio-group class="row" bindchange="onFormLabelChange">
      <label class="label"><radio value="spam" checked="{{form.label === 'spam'}}" />垃圾</label>
      <label class="label"><radio value="ham" checked="{{form.label === 'ham'}}" />正常</label>
    </radio-group>

    <button class="btn btn-accent" bindtap="createSample">提交样本</button>
  </view>

  <view class="card fade-up fade-up-delay-2">
    <view class="card-title">批量导入</view>
    <view class="card-desc">支持 JSON 数组导入。导入后可直接重训模型。</view>
    <textarea class="textarea" value="{{importText}}" data-field="importText" bindinput="onInput" />

    <view class="btn-row">
      <button class="btn btn-primary" bindtap="importSamples">执行导入</button>
      <button class="btn btn-ghost" bindtap="retrain">一键重训模型</button>
    </view>
  </view>

  <view class="card fade-up fade-up-delay-3" wx:if="{{samples.length}}">
    <view class="card-title">样本列表</view>

    <view class="list-item" wx:for="{{samples}}" wx:key="id">
      <view class="item-title">{{item.text}}</view>
      <view class="item-sub">标签：{{item.label === 'spam' ? '垃圾' : '正常'}} · 来源：{{item.source}} · ID：{{item.id}}</view>

      <view class="row">
        <text class="label">参与训练</text>
        <switch data-id="{{item.id}}" checked="{{item.is_active}}" bindchange="toggleActive" />
      </view>

      <button class="btn btn-ghost" data-id="{{item.id}}" bindtap="deleteSample">删除样本</button>
    </view>
  </view>
</view>
