import { FormSchema } from '@/components/Table';
import { loadTableRecordInfo } from '@/api/database/index';
import { getGeomTableList } from '@/api/application/index';

export const columns: BasicColumn[] = [
  {
    title: '编号',
    dataIndex: 'name',
  },
  {
    title: '名称',
    dataIndex: 'name',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'key',
    label: '关键字',
    component: 'Input',
    colProps: { span: 8 },
  },
];
const isLayer = (type: string) => type === 2;
export const formSchema: FormSchema[] = [
  {
    field: 'type',
    label: '类型',
    component: 'RadioButtonGroup',
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '分组', value: 1 },
        { label: '图层', value: 2 },
      ],
    },
    colProps: { lg: 24, md: 24 },
  },
  {
    field: 'id',
    label: '名称',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'applicationName',
    label: '名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'pid',
    label: '上级',
    component: 'TreeSelect',
    required: true,
    componentProps: {
      fieldNames: {
        label: 'applicationName',
        key: 'id',
        value: 'id',
        children: 'child',
      },
      getPopupContainer: () => document.body,
    },
  },
  {
    field: 'serverId',
    component: 'ApiSelect',
    label: '空间数据表',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: getGeomTableList,
        params: { page: 1, limit: 9999 },
        // 接口参数
        resultField: 'result',
        labelField: 'table_comment',
        valueField: 'table_name',
      };
    },
    ifShow: ({ values }) => isLayer(values.type),
  },
];
