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

import { getDoctorScheduleLogList } from '../api';
import { normalizeScheduleLogFilters } from './search';

/**
 * 排班变更日志列定义：谁（操作人）在哪（门店）把谁（医生）的哪些天改成了什么（动作/模板）
 */
export const gridOptions: VxeGridProps<any> = {
  columns: [
    { field: 'id', title: 'ID', width: 70 },
    { field: 'operator_name', title: '操作人', minWidth: 90 },
    {
      field: 'user_type_txt',
      title: '端',
      width: 70,
      slots: { default: 'user_type' },
    },
    { field: 'store_name', title: '门店', minWidth: 130 },
    { field: 'doctor_name', title: '医生', minWidth: 90 },
    {
      field: 'action_txt',
      title: '变更动作',
      width: 120,
      slots: { default: 'action_type' },
    },
    { field: 'template_name', title: '班次模板', minWidth: 100 },
    {
      field: 'dates_count',
      title: '涉及天数',
      width: 90,
      slots: { default: 'dates_count' },
    },
    { field: 'batch_no', title: '批次号', minWidth: 150 },
    { field: 'created_at', title: '操作时间', width: 170 },
    {
      title: '操作',
      width: 80,
      fixed: 'right',
      slots: { default: 'action' },
    },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        return await getDoctorScheduleLogList({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...normalizeScheduleLogFilters(formValues || {}),
        });
      },
    },
  },
  height: 'auto',
  toolbarConfig: {
    search: true,
    refresh: true,
    zoom: true,
    slots: {
      buttons: 'toolbar-actions',
    },
  },
};
