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

import { selectAllSysStation } from '#/api/system/infoEntry/stationInfo/stationInfo';

export const querySchema: FormSchemaGetter = () => [
  {
      component: 'ApiSelect',
      fieldName: 'stationId',
      label: '油站',
      componentProps: {
        placeholder: '请选择油站',
        clearable: true,
        api: async () => {
          const resp = await selectAllSysStation();
          const data = resp || [];
          return Array.isArray(data)
            ? data.map((item: any) => ({
                label: item.stationName,
                value: item.id.toString(),
              }))
            : [];
        },
        labelField: 'label',
        valueField: 'value',
      },
    },
  {
    component: 'DatePicker',
    componentProps: {
      type: 'daterange',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      startPlaceholder: '开始日期',
      endPlaceholder: '结束日期',
    },
    fieldName: 'processTime',
    label: '处理时间',
  },
];

/**
 * 映射表单字段到API字段
 */
export function mapFormToApi(formValues: any, page: any) {
  const apiParams = {
    pageNum: page.currentPage,
    pageSize: page.pageSize,
  };
  
  // 油站ID
  if (formValues.stationId) {
    apiParams.stationId = formValues.stationId;
  }
  
  // 处理时间
  if (formValues.processTime) {
    apiParams.processTimeStart = formValues.processTime[0];
    apiParams.processTimeEnd = formValues.processTime[1];
  }
  
  return apiParams;
}

/**
 * 映射API响应数据到页面显示字段
 */
export function mapApiToView(data: any[]) {
  return data.map(item => ({
    ...item,
    // 处理需要转换的字段
  }));
}

export const columns: VxeGridProps['columns'] = [
  {
    title: '油站',
    field: 'stationName',
    minWidth: 120,
  },
  {
    title: '处理时间',
    field: 'processTime',
    minWidth: 180,
  },
  {
    title: '本站策略',
    field: 'siteStrategy',
    minWidth: 150,
  },
  {
    title: '本站变化',
    field: 'siteChange',
    minWidth: 150,
  },
  {
    title: '竞对策略',
    field: 'competitorStrategy',
    minWidth: 150,
  },
  {
    title: '竞对变化',
    field: 'competitorChange',
    minWidth: 150,
  },
  {
    title: '商圈变化',
    field: 'businessDistrictChange',
    minWidth: 150,
  },
  {
    title: 'SWOT分析计划回顾',
    field: 'swotAnalysisReview',
    minWidth: 180,
  },
  {
    title: '业绩提升计划回顾',
    field: 'performanceImprovementReview',
    minWidth: 180,
  },
];

