import type { VxeGridProps } from '#/adapter/vxe-table';

import { computed } from 'vue';

import { z } from '@vben/common-ui';

import { $t } from '#/locales';

export const querySchema = computed(() => [
  {
    component: 'Input',
    fieldName: 'phoneNumber',
    label: $t('abp.OneNETManagement.PhoneNumber'),
  },
]);

export const tableSchema: any = computed((): VxeGridProps['columns'] => [
  { title: $t('common.seq'), type: 'seq', width: 50 },
  {
    field: 'oneNETAccountId',
    title: $t('abp.OneNETManagement.OneNETAccountId'),
    minWidth: '150',
  },
  {
    field: 'accountName',
    title: $t('abp.OneNETManagement.AccountName'),
    minWidth: '150',
  },
  {
    field: 'phoneNumber',
    title: $t('abp.OneNETManagement.PhoneNumber'),
    minWidth: '150',
  },
  {
    field: 'accountAccesskey',
    title: $t('abp.OneNETManagement.AccountAccesskey'),
    minWidth: '150',
  },
  {
    field: 'productCount',
    title: $t('abp.OneNETManagement.ProductCount'),
    minWidth: '150',
  },
  {
    title: $t('common.action'),
    field: 'action',
    fixed: 'right',
    width: '150',
    slots: { default: 'action' },
  },
]);

export const addAccountFormSchema: any = computed(() => [
  {
    component: 'Input',
    fieldName: 'oneNETAccountId',
    label: $t('abp.OneNETManagement.OneNETAccountId'),
    rules: z.string().min(1, {
      message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.OneNETAccountId')}`,
    }),
  },
  {
    component: 'Input',
    fieldName: 'accountName',
    label: $t('abp.OneNETManagement.AccountName'),
    rules: z.string().min(1, {
      message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.AccountName')}`,
    }),
  },
  {
    component: 'Input',
    fieldName: 'accountAccesskey',
    label: $t('abp.OneNETManagement.AccountAccesskey'),
    rules: z.string().min(1, {
      message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.AccountAccesskey')}`,
    }),
  },
  {
    component: 'Input',
    fieldName: 'phoneNumber',
    label: $t('abp.OneNETManagement.PhoneNumber'),
    rules: z
      .string()
      .min(1, {
        message: `${$t('common.pleaseInput')}${$t('abp.OneNETManagement.PhoneNumber')}`,
      })
      .refine((value) => /^1[3-9]\d{9}$/.test(value), {
        message: $t('common.PhoneNumberFormatError'),
      }),
  },
]);

export const editAccountFormSchemaEdit: any = computed(() => [
  {
    component: 'Input',
    fieldName: 'oneNETAccountId',
    label: $t('abp.OneNETManagement.OneNETAccountId'),
    disabled: true,
  },
  {
    component: 'Input',
    fieldName: 'accountName',
    label: $t('abp.OneNETManagement.AccountName'),
    rules: z.string().min(1, {
      message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.AccountName')}`,
    }),
  },
  {
    component: 'Input',
    fieldName: 'accountAccesskey',
    label: $t('abp.OneNETManagement.AccountAccesskey'),
    rules: z.string().min(1, {
      message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.AccountAccesskey')}`,
    }),
  },
  {
    component: 'Input',
    fieldName: 'phoneNumber',
    label: $t('abp.OneNETManagement.PhoneNumber'),
    rules: z
      .string()
      .min(1, {
        message: `${$t('common.pleaseInput')}${$t('abp.OneNETManagement.PhoneNumber')}`,
      })
      .refine((value) => /^1[3-9]\d{9}$/.test(value), {
        message: $t('common.PhoneNumberFormatError'),
      }),
  },
]);
