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

import { getOaCronTaskList } from '#/views/system/oa-cron-task/api';

interface RowType {
  id: number;
  task_code: string;
  name: string;
  enabled: number;
  /** 1定时 2主动触发 */
  type: number;
  scene_code: string;
  card_image_url: string;
  jump_url: string;
  active_types_summary: string;
  robot_names: string;
  target_summary: string;
  remark: string;
  created_at: string;
  updated_at: string;
}

/**
 * OA 推送任务列表表格（定时 + 主动触发）
 * 启停用 Switch；消息配置/机器人/发送用户列可点击打开独立配置弹窗；卡片图缩略图展示
 */
export const gridOptions: VxeGridProps<RowType> = {
  columnConfig: {
    useKey: true,
  },
  rowConfig: {
    useKey: true,
  },
  columns: [
    { field: 'id', align: 'left', title: 'ID', width: 70 },
    { field: 'name', align: 'left', title: '任务名称', minWidth: 160 },
    { field: 'task_code', align: 'left', title: '任务编码', minWidth: 180 },
    {
      field: 'type',
      align: 'left',
      title: '触发方式',
      width: 110,
      slots: { default: 'task_type' },
    },
    {
      field: 'enabled',
      align: 'left',
      title: '启停',
      width: 100,
      slots: { default: 'enabled' },
    },
    { field: 'scene_code', align: 'left', title: '场景编码', minWidth: 160 },
    {
      field: 'card_image_url',
      align: 'left',
      title: '卡片图',
      width: 100,
      slots: { default: 'card_image' },
    },
    {
      field: 'active_types_summary',
      align: 'left',
      title: '消息配置',
      minWidth: 180,
      slots: { default: 'message_config' },
    },
    {
      field: 'robot_names',
      align: 'left',
      title: '机器人',
      minWidth: 140,
      slots: { default: 'robots' },
    },
    {
      field: 'target_summary',
      align: 'left',
      title: '发送用户',
      minWidth: 120,
      slots: { default: 'send_users' },
    },
    { field: 'remark', align: 'left', title: '备注', minWidth: 180 },
    { field: 'updated_at', align: 'left', title: '更新时间', width: 180 },
    {
      type: 'html',
      title: '操作',
      slots: { default: 'action' },
      width: 100,
      fixed: 'right',
    },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        return await getOaCronTaskList({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  height: 'auto',
  border: false,
  toolbarConfig: {
    search: true,
    refresh: true,
    print: false,
    export: false,
    zoom: true,
    custom: {
      icon: 'vxe-icon-menu',
    },
  },
  showOverflow: false,
};
