import { computed } from 'vue'
import type { FormItem } from '@/components/search-form/types'
import { SUPPRESSION_TYPE_OPTIONS } from '@/api/ops/suppression'
import type { PolicyOption } from '../types'

/**
 * 获取筛选表单项配置
 */
export const useFormItems = (policyOptions: PolicyOption[]) => {
  return computed<FormItem[]>(() => [
    {
      field: 'keyword',
      label: '关键字',
      type: 'input',
      span: 6,
      placeholder: '搜索名称/描述',
    },
    {
      field: 'type',
      label: '抑制类型',
      type: 'select',
      span: 6,
      placeholder: '请选择',
      options: [
        { value: '', label: '全部' },
        ...SUPPRESSION_TYPE_OPTIONS,
      ],
    },
    {
      field: 'policy_id',
      label: '关联策略',
      type: 'select',
      span: 6,
      placeholder: '请选择',
      options: [
        { value: '', label: '全部' },
        { value: '0', label: '仅全局规则' },
        ...policyOptions.map((p) => ({ value: String(p.id), label: p.name })),
      ],
    },
    {
      field: 'enabled',
      label: '启用状态',
      type: 'select',
      span: 6,
      placeholder: '请选择',
      options: [
        { value: '', label: '全部' },
        { value: 'true', label: '已启用' },
        { value: 'false', label: '已禁用' },
      ],
    },
  ])
}