/**
 * 日志列表通用：search_time → start_time/end_time
 */
import dayjs from 'dayjs';

export function normalizeLogTimeFilters(formValues: Record<string, any> = {}) {
  const params: Record<string, any> = { ...formValues };
  const range = params.search_time;
  delete params.search_time;
  if (Array.isArray(range) && range.length === 2 && range[0] && range[1]) {
    params.start_time = dayjs(range[0]).startOf('day').unix();
    params.end_time = dayjs(range[1]).endOf('day').unix();
  }
  Object.keys(params).forEach((k) => {
    if (params[k] === '' || params[k] === undefined || params[k] === null) {
      delete params[k];
    }
  });
  return params;
}

export const logTimeRangeSchema = {
  component: 'RangePicker' as const,
  componentProps: {
    format: 'YYYY-MM-DD',
    valueFormat: 'YYYY-MM-DD',
  },
  fieldName: 'search_time',
  label: '时间范围',
};
