import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemUserApi } from '#/api/system/user';

import { z } from '#/adapter/form';
import { $t } from '#/locales';

/**
 * 获取表格列配置
 * @description 使用函数的形式返回列数据而不是直接export一个Array常量，是为了响应语言切换时重新翻译表头
 * @param onActionClick 表格操作按钮点击事件
 */
export const useColumns =
  (): VxeTableGridOptions<SystemUserApi.SystemUser>['columns'] => {
    return [
      {
        field: 'device_id',
        title: '设备ID',
        width: 150,
      },
      {
        field: 'device_name',
        title: '设备名称',
      },
      {
        field: 'type',
        title: '事件类型',
      },
      {
        field: 'device_key',
        title: '设备唯一标识符',
      },
      {
        field: 'timestamp',
        title: '操作时间',
      },
    ];
  };

export function useSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'Name',
      label: $t('system.user.userName'),
      rules: z
        .string()
        .min(2, $t('ui.formRules.minLength', [$t('system.user.userName'), 2]))
        .max(
          20,
          $t('ui.formRules.maxLength', [$t('system.user.userName'), 20]),
        ),
    },
    {
      component: 'Input',
      fieldName: 'Nickname',
      label: $t('system.user.nickName'),
      rules: z
        .string()
        .min(2, $t('ui.formRules.minLength', [$t('system.user.nickName'), 2]))
        .max(
          20,
          $t('ui.formRules.maxLength', [$t('system.user.nickName'), 20]),
        ),
    },
    {
      component: 'Input',
      fieldName: 'Password',
      label: $t('system.user.password'),
      rules: z
        .string()
        .min(6, $t('ui.formRules.minLength', [$t('system.user.password'), 6]))
        .max(
          20,
          $t('ui.formRules.maxLength', [$t('system.user.password'), 20]),
        ),
    },
    {
      component: 'Input',
      fieldName: 'Email',
      label: $t('system.user.email'),
    },
  ];
}
