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

import { getOaSceneList } from '#/views/system/oa-scene/api';

interface RowType {
  id: number;
  scene_code: string;
  scene_name: string;
  scene_platforms: string[];
  platform_summaries: Array<{
    platform_code: string;
    platform_name: string;
    icon: string;
    message_type: string;
    channel: string;
  }>;
  message_config: Record<string, { message_type?: string; payload?: any }>;
  description: string;
  status: number;
  created_at: string;
}

/**
 * 场景列表表格配置
 * 启用平台 / 发送方式由 platform_summaries 驱动，点击平台 Tag 可预览消息
 */
export const gridOptions: VxeGridProps<RowType> = {
  checkboxConfig: {
    highlight: true,
    labelField: '',
  },
  columnConfig: {
    useKey: true,
  },
  rowConfig: {
    useKey: true,
  },
  columns: [
    { type: 'checkbox', width: 60 },
    { field: 'id', align: 'left', title: 'ID', width: 80 },
    { field: 'scene_code', align: 'left', title: '场景编码', width: 160 },
    { field: 'scene_name', align: 'left', title: '场景名称', minWidth: 140 },
    {
      field: 'platforms',
      align: 'left',
      title: '启用平台',
      minWidth: 200,
      slots: { default: 'platforms' },
    },
    {
      field: 'send_mode',
      align: 'left',
      title: '发送方式',
      minWidth: 220,
      slots: { default: 'send_mode' },
    },
    { field: 'description', align: 'left', title: '说明', minWidth: 120 },
    {
      field: 'status',
      align: 'left',
      title: '状态',
      width: 100,
      slots: { default: 'status' },
    },
    { field: 'created_at', align: 'left', title: '创建时间', width: 180 },
    {
      type: 'html',
      title: '操作',
      slots: { default: 'action' },
      width: 200,
      fixed: 'right',
    },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        return await getOaSceneList({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  height: 'auto',
  border: false,
  toolbarConfig: {
    search: true,
    refresh: true,
    print: false,
    export: false,
    zoom: true,
    slots: {
      buttons: 'toolbar-actions',
    },
    custom: {
      icon: 'vxe-icon-menu',
    },
  },
  showOverflow: false,
};
