import type { VbenFormProps } from '#/adapter/form';

import { STATUS_OPTIONS } from './constants';

/**
 * AI 密钥新增/编辑表单
 * 所属平台在弹窗外用卡片单选，不走下拉
 */
export const modalFormProps: VbenFormProps = {
  wrapperClass: 'grid-cols-12',
  commonConfig: {
    formItemClass: 'col-span-12',
    componentProps: { class: 'w-full' },
  },
  layout: 'horizontal',
  schema: [
    {
      component: 'VbenInput',
      fieldName: 'id',
      label: 'ID',
      dependencies: { show: false, triggerFields: ['id'] },
    },
    // platform_id 由上方卡片单选写入，隐藏字段仅用于提交
    {
      component: 'VbenInput',
      fieldName: 'platform_id',
      label: '所属平台',
      dependencies: { show: false, triggerFields: ['platform_id'] },
    },
    {
      component: 'VbenInput',
      fieldName: 'name',
      label: '密钥别名',
      rules: 'required',
      formItemClass: 'col-span-6',
      componentProps: { placeholder: '如：生产环境主密钥' },
    },
    {
      component: 'VbenInputPassword',
      fieldName: 'api_key',
      label: 'API Key',
      help: '新增必填；编辑留空表示不修改。库内 AES 加密，传输亦加密',
      componentProps: { placeholder: 'Bearer 用的密钥明文' },
      defaultValue: '',
    },
    {
      component: 'VbenSelect',
      fieldName: 'status',
      label: '状态',
      formItemClass: 'col-span-3',
      componentProps: { options: STATUS_OPTIONS },
      defaultValue: 1,
    },
    {
      component: 'InputNumber',
      fieldName: 'sort',
      label: '排序',
      formItemClass: 'col-span-3',
      componentProps: { min: 0 },
      defaultValue: 0,
    },
    {
      component: 'VbenSelect',
      fieldName: 'is_default',
      label: '设为默认',
      formItemClass: 'col-span-6',
      componentProps: {
        options: [
          { label: '否', value: 0 },
          { label: '是', value: 1 },
        ],
      },
      defaultValue: 0,
    },
    {
      component: 'VbenInput',
      fieldName: 'remark',
      label: '备注',
      componentProps: { type: 'textarea', rows: 2 },
      defaultValue: '',
    },
  ],
  showDefaultActions: false,
};
