/*
 * @Author: Mm
 * @Date: 2025-05-06 16:42:26
 * @LastEditors: Mm
 * @LastEditTime: 2025-05-07 09:41:51
 * 不写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: 'name',
    label: '群名',
  },

  {
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.IM_BOOL 便于维护
      options: getDictOptions('im_bool'),
    },
    fieldName: 'isBanned',
    label: '是否封禁',
  },

  {
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.IM_BOOL 便于维护
      options: getDictOptions('im_bool'),
    },
    fieldName: 'dissolve',
    label: '是否解散',
  },
  {
    component: 'RangePicker',
    fieldName: 'createdTime',
    label: '创建时间',
  },
];

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

  {
    title: '群名',
    field: 'name',
  },
  
  {
    title: '群头像',
    field: 'headImage',
    slots:{default:'headImage'}
  },
  
  {
    title: '群公告',
    field: 'notice',
  },
  {
    title: '是否被封禁',
    field: 'isBanned',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.IM_BOOL 便于维护
        return row.isBanned?renderDict(row.isBanned, 'im_bool'):'';
      },
    },
  },
  {
    title: '被封禁原因',
    field: 'reason',
  },
  {
    title: '是否已解散',
    field: 'dissolve',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.IM_BOOL 便于维护
        return row.dissolve?renderDict(row.dissolve, 'im_bool'):'';
      },
    },
  },
  {
    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: 'name',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '群主id',
    fieldName: 'ownerId',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '群头像',
    fieldName: 'headImage',
    component: 'ImageUpload',
    componentProps: {
      // accept: ['jpg'], // 不支持type/*的写法 支持拓展名(不带.) 文件头(image/png这种)
      // maxNumber: 1, // 最大上传文件数 默认为1 为1会绑定为string而非string[]类型
      // resultField: 'url', // 上传成功后返回的字段名 默认url 可选['ossId', 'url', 'fileName']
    },
    rules: 'required',
  },
  {
    label: '群头像缩略图',
    fieldName: 'headImageThumb',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '群公告',
    fieldName: 'notice',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '是否被封禁',
    fieldName: 'isBanned',
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.IM_BOOL 便于维护
      options: getDictOptions('im_bool'),
    },
    rules: 'selectRequired',
  },
  {
    label: '被封禁原因',
    fieldName: 'reason',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '是否已解散',
    fieldName: 'dissolve',
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.IM_BOOL 便于维护
      options: getDictOptions('im_bool'),
    },
    rules: 'selectRequired',
  },
  {
    label: '创建时间',
    fieldName: 'createdTime',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    rules: 'required',
  },
];
