import request from '@/config/axios';
import type { TableData } from './types';

/** 获取表格数据 */
export const getIndexCategoryListApi = (data: any) => {
  return request.postJson({ url: '/dataset/spi/dataset/IndexCategory/IndexCategoryQueryPage', data });
};

/** 批量删除 */
export const delIndexCategoryListApi = (list: string[] | number[]): Promise<IResponse> => {
  const _list = list.map(v => {
    return {
      id: v,
    };
  });
  return request.postJson({
    url: '/dataset/spi/dataset/IndexCategory/IndexCategoryBatchDelete',
    data: {
      list: _list,
    },
  });
};

/** 删除 */
export const delIndexCategoryApi = (id?: string | number): Promise<IResponse> => {
  return request.postJson({ url: '/dataset/spi/dataset/IndexCategory/IndexCategoryDelete', data: { id } });
};


/** 查询单条数据 */
export const queryIndexCategoryApi = (id?: string | number): Promise<IResponse> => {
  return request.postJson({ url: '/dataset/spi/dataset/IndexCategory/IndexCategoryQueryOne', data: { id } });
}


/** 菜单树,增加默认排序 */
export const getIndexCategoryTreeApi = async () => {
  const res = await request.post({
    url: '/dataset/spi/dataset/IndexCategory/IndexCategoryTree',
  });
  if (res?.body?.menutree?.length > 0) {
    const data = res.body.menutree
    return data.sort((a:AppCustomRouteRecordRaw, b:AppCustomRouteRecordRaw) => {
      return a?.props?.sort && b?.props?.sort ? a.props.sort - b.props.sort : 0
    });
  }
  return [];
};


