<view class="page">
  <navigation-bar title="{{editId ? '编辑药品' : '添加药品'}}" back="{{true}}" color="black" background="#ffffff" />

  <view class="form-section">
    <view class="form-group">
      <view class="form-label">药品名称 <text class="required">*</text></view>
      <input class="form-input" placeholder="请输入药品名称" value="{{form.name}}" bindinput="onFieldChange" data-field="name" />
    </view>

    <view class="form-group">
      <view class="form-label">药品分类</view>
      <picker mode="selector" range="{{categories}}" value="{{categoryIndex}}" bindchange="onCategoryChange">
        <view class="form-picker {{form.category ? '' : 'placeholder'}}">
          {{form.category || '请选择分类'}}
          <text class="picker-arrow">▼</text>
        </view>
      </picker>
    </view>

    <view class="form-row">
      <view class="form-group half">
        <view class="form-label">单次用量</view>
        <input class="form-input" placeholder="如：1片" value="{{form.dosage}}" bindinput="onFieldChange" data-field="dosage" />
      </view>
      <view class="form-group half">
        <view class="form-label">服用频次</view>
        <picker mode="selector" range="{{frequencies}}" value="{{freqIndex}}" bindchange="onFreqChange">
          <view class="form-picker {{form.frequency ? '' : 'placeholder'}}">
            {{form.frequency || '请选择'}}
            <text class="picker-arrow">▼</text>
          </view>
        </picker>
      </view>
    </view>

    <view class="form-group">
      <view class="form-label">服用时段</view>
      <view class="slot-group">
        <view wx:for="{{timeSlots}}" wx:key="*this" class="slot-chip {{form.slots.indexOf(item) > -1 ? 'active' : ''}}" data-slot="{{item}}" bindtap="toggleSlot">{{item}}</view>
      </view>
    </view>

    <view class="form-row">
      <view class="form-group half">
        <view class="form-label">库存数量</view>
        <input class="form-input" type="number" placeholder="数量" value="{{form.quantity}}" bindinput="onFieldChange" data-field="quantity" />
      </view>
      <view class="form-group half">
        <view class="form-label">单位</view>
        <picker mode="selector" range="{{units}}" value="{{unitIndex}}" bindchange="onUnitChange">
          <view class="form-picker {{form.unit ? '' : 'placeholder'}}">
            {{form.unit || '请选择'}}
            <text class="picker-arrow">▼</text>
          </view>
        </picker>
      </view>
    </view>

    <view class="form-group">
      <view class="form-label">有效期至</view>
      <picker mode="date" value="{{form.expiryDate}}" start="{{today}}" bindchange="onDateChange">
        <view class="form-picker {{form.expiryDate ? '' : 'placeholder'}}">
          {{form.expiryDate || '请选择有效期'}}
          <text class="picker-arrow">📅</text>
        </view>
      </picker>
    </view>

    <view class="form-group">
      <view class="form-label">备注</view>
      <textarea class="form-textarea" placeholder="添加备注信息..." value="{{form.notes}}" bindinput="onFieldChange" data-field="notes" />
    </view>
  </view>

  <view class="btn-area">
    <button class="save-btn" bindtap="save">保存药品</button>
    <button class="cancel-btn" bindtap="cancel" wx:if="{{editId}}">删除此药品</button>
  </view>
</view>
