import { defHttp } from '/@/utils/http/axios';
import { getMenuListResultModel } from './model/menuModel';
import { useUserStore } from '/@/store/modules/user';
import { RoleEnum } from '/@/enums/roleEnum';

enum Api {
  UpdateMenu = '/xld-2And3/updateMenu',
  UpdateLayer2d = '/xld-2And3/updateLayer2d',
  SaveOneLayer2d = '/xld-2And3/saveOneLayer2d',
  RemoveLayer2d = '/xld-2And3/removeLayer2d',
  UpdateLayer3d = '/xld-2And3/updateLayer3d',
  SaveOneLayer3d = '/xld-2And3/saveOneLayer3d',
  RemoveLayer3d = '/xld-2And3/removeLayer3d',
  GetMenuList = '/xld-2And3/findAllMenu',
  RemoveMenu = '/xld-2And3/removeMenu',
  SysAdminMenuList = '/admin/me/menus',
  GetMenuIdsByRoleId = '/menu/get_ids/',
}

const locationType = { mapToolsUrl: true };


/**
 * @description: 获取二三维一体化的菜单
 */

export const getMenuList = () => {
  let url = Api.GetMenuList;
  try {
    return new Promise<void>((resolve, reject) => {
      defHttp.post({
        url,
        ...locationType
      }).then(res => {
        if (res.code == 200 && res.data && res.data.length) {
          resolve(res.data);
        }
      })
    })
  } catch (e) {

  }
};

/**
 * @description: 跟新二维图层信息
 */
export function updateLayer2d(params, _id) {
  console.log(params);
  return defHttp.post({
    url: Api.UpdateLayer2d,
    ...locationType,
    data: {
      id: _id,
      data: params
    },
  });
}


/**
 * @description: 保存二维图层信息
 */
export function saveOneLayer2d(params) {
  return defHttp.post({
    url: Api.SaveOneLayer2d,
    ...locationType,
    data: {
      layer: params
    },
  });
}

/**
 * @description: 删除二维图层
 */
export function removeLayer2d(params) {
  return defHttp.post({
    url: Api.RemoveLayer2d,
    ...locationType,
    data: {
      id: params
    },
  });
}

/**
 * @description: 跟新三维图层信息
 */
export function updateLayer3d(params, _id) {
  console.log(params);
  return defHttp.post({
    url: Api.UpdateLayer3d,
    ...locationType,
    data: {
      id: _id,
      data: params
    },
  });
}


/**
 * @description: 保存三维图层信息
 */
export function saveOneLayer3d(params) {
  return defHttp.post({
    url: Api.SaveOneLayer3d,
    ...locationType,
    data: {
      layer: params
    },
  });
}

/**
 * @description: 删除三维图层
 */
export function removeLayer3d(params) {
  return defHttp.post({
    url: Api.RemoveLayer3d,
    ...locationType,
    data: {
      id: params
    },
  });
}

/**
 * @description: 跟新按钮状态
 */
export function saveMenuApi(params, mode = 'modal') {
  console.log(params);
  return defHttp.post({
    url: Api.UpdateMenu,
    ...locationType,
    data: {
      id: params.id,
      menu: params
    },
  });
}

export const delMenu = (id) => {
  const url = Api.RemoveMenu;
  return defHttp.post({
    url: url,
    ...locationType,
    data: {
      id: id[0],
      isRemove: true
    }
  });
};
export const getMenusIdsByRoleId = (roleId: string) => {
  const url = Api.GetMenuIdsByRoleId + roleId;
  return defHttp.get<Array<string>>({ url });
};
