import { readonly } from 'vue';
/*
 * @Author: Mm
 * @Date: 2025-05-06 16:20:51
 * @LastEditors: Mm
 * @LastEditTime: 2025-05-07 10:06:43
 * 不写bug的程序员不是一个好程序员!
 */
import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'userName',
    label: '用户账号',
  },
  {
    component: 'Input',
    fieldName: 'nickName',
    label: '用户昵称',
  },
  
  
  {
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.IM_BOOL 便于维护
      options: getDictOptions('im_bool'),
    },
    fieldName: 'isBanned',
    label: '是否封禁',
  },
  {
    component: 'Input',
    fieldName: 'reason',
    label: '被封禁原因',
  },
 
  {
    component: 'RangePicker',
    fieldName: 'createdTime',
    label: '创建时间',
  },
];

// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },

  {
    title: '名称',
    field: 'userName',
  },
  {
    title: '昵称',
    field: 'nickName',
  },
  {
    title: '头像',
    field: 'headImage',
    slots: { default: 'headImage' },
  },

  {
    title: '性别',
    field: 'sex',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.SYS_USER_SEX 便于维护
        return  renderDict(row.sex, 'sys_user_sex') ;
      },
    },
  },
  {
    title: '是否被封禁',
    field: 'isBanned',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.IM_BOOL 便于维护
        return row.isBanned ? renderDict(row.isBanned, 'im_bool') : '';
      },
    },
  },
  // {
  //   title: '被封禁原因',
  //   field: 'reason',
  // },

  {
    title: '最后登录时间',
    field: 'lastLoginTime',
  },
  {
    title: '创建时间',
    field: 'createdTime',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

export const modalSchema: FormSchemaGetter = () => [
  {
    label: 'id',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '用户头像',
    fieldName: 'headImage',
    component: 'ImageUpload',
    formItemClass: 'col-span-2',
  },
  {
    label: '用户账号',
    fieldName: 'userName',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    label: '用户昵称',
    fieldName: 'nickName',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },

  {
    label: '用户性别',
    fieldName: 'sex',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    label: '是否封禁',
    fieldName: 'isBanned',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    label: '封禁原因',
    fieldName: 'reason',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },

  {
    label: '个性签名',
    fieldName: 'signature',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },

  {
    label: '最后登录时间',
    fieldName: 'lastLoginTime',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    label: '创建时间',
    fieldName: 'createdTime',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
];

export const modalBanSchema: FormSchemaGetter = () => [
  {
    label: 'id',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  
  {
    label: '封禁原因',
    fieldName: 'reason',
    component: 'Textarea',
    componentProps:{
      placeholder:'请输入封禁原因'
    }
    
  },

];
