import qs from 'qs';
import axios from 'axios';
import { CITY_SERVICE, get, PUBLISH_SERVICE, post, postForm, PANDA_GIS } from '../index';

/**
 * 获取所有网站配置
 * @param {*} userMode
 */
export const getWebModuleTree = userMode =>
  get(
    `${PUBLISH_SERVICE}/PlatformCenter/WebModuleTree?${qs.stringify({
      userMode,
    })}`,
  );

/**
 *  获取主题下拉选项
 */
export const getWebThemes = () => get(`${CITY_SERVICE}/OMS.svc/W4_GetThemes`, { query: '' });

/**
 * 获取登录模板下拉选项
 */
export const getLoginPage = () => get(`${PUBLISH_SERVICE}/WebSite/GetLoginPage`, { query: '' });

/**
 * 获取地图配置下拉选项
 */
export const getMapCofigs = () =>
  get(`${CITY_SERVICE}/OMS.svc/GetAllConfigText?terminalType=scheme&isBaseMap=false`, {
    query: '',
  });

/**
 *  获取网站配置
 * @param {*} title 网站标题
 */
export const getWebconfig = title => get(`${PUBLISH_SERVICE}/WebSite/GetWebsite`, { title });

/**
 * 编辑或添加网站。默认编辑模式
 * @param {*} config 网站配置
 * @param {*} isAdd true：添加  false：编辑
 */
export const postEditWebConfig = (config, isAdd = false) => {
  const obj = { ...config };
  Object.keys(obj).forEach(k => {
    if (typeof obj[k] === 'string') {
      obj[k] = obj[k].trim();
    }
  });
  return post(
    `${PUBLISH_SERVICE}/WebSite/${isAdd ? 'AddWebsite' : 'EditWebsite'}?_version=9999`,
    obj,
  );
};

export const postAddWebSite = config => postEditWebConfig(config, true);

export const deleteWebsite = client =>
  get(`${PUBLISH_SERVICE}/WebSite/DeleteWebsite?_version=9999`, { client });

/**
 * 获取配置文件下拉选项
 */
export const getAllConfigName = () =>
  get(`${PUBLISH_SERVICE}/WebSite/GetAllConfigName?_version=9999`);

export const addWebMenu = param => {
  const defaultConfig = { pageUrl: '' };
  // eslint-disable-next-line no-return-assign
  Object.keys(param).forEach(k => (defaultConfig[k] = param[k]));
  return post(`${PUBLISH_SERVICE}/WebSite/AddMenu?_version=9999`, defaultConfig);
};

export const editWebMenu = param =>
  post(`${PUBLISH_SERVICE}/WebSite/EditMenu?_version=9999`, param);

export const pEditWebMenu = param => get(`${CITY_SERVICE}/OMS.svc/P_EditMenu?_version=9999`, param);

export const deleteWebMenu = param =>
  get(`${PUBLISH_SERVICE}/WebSite/DeleteMenu?_version=9999`, param);

export const getWebMenuInfo = param =>
  get(`${PUBLISH_SERVICE}/PlatformCenter/GetMenuInfo?_version=9999`, param);

export const saveConfigContent = (fileName, content) =>
  post(
    `${CITY_SERVICE}/OMS.svc/W4_SaveConfigContent?_version=9999&fileName=${fileName}`,
    qs.stringify({ web4ConfigContent: content }),
    {
      headers: {
        'content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
      },
    },
  );

export const getConfigContent = name =>
  get(`${CITY_SERVICE}/OMS.svc/W4_GetConfigContent?_version=9999`, {
    fileName: name,
  });

// 菜单拖拽
export const dragMenu = params => get(`${PUBLISH_SERVICE}/PlatformCenter/DragMenu`, params);

// 获取产品列表
export const getProductList = params => post(`${PUBLISH_SERVICE}/UserCenter/ProductList`, params);

// 新增或修改产品列表 Id为0时新增，Id大于0时修改
export const modifyProduct = params => post(`${PUBLISH_SERVICE}/UserCenter/ModifyProduct`, params);

// 删除产品列表
export const delProductList = params => get(`${PUBLISH_SERVICE}/UserCenter/DelProduct`, params);

/**
 * @新接口
 */
// 根据title获取网站配置
export const getWebSite = title => get(`${PUBLISH_SERVICE}/WebSite/GetWebsite`, { title });
// 添加网站配置
export const addWebsite = params => {
  const obj = { ...params };
  Object.keys(obj).forEach(k => {
    if (typeof obj[k] === 'string') {
      obj[k] = obj[k].trim();
    }
  });
  return post(`${PUBLISH_SERVICE}/WebSite/AddWebsite`, obj);
};

export const editWebsite = params => {
  const obj = { ...params };
  Object.keys(obj).forEach(k => {
    if (typeof obj[k] === 'string') {
      obj[k] = obj[k].trim();
    }
  });
  return post(`${PUBLISH_SERVICE}/WebSite/EditWebsite`, obj);
};

// 删除网站
export const omsDeleteWebsite = client =>
  get(`${PUBLISH_SERVICE}/WebSite/DeleteWebsite`, { client });

// 获取全部
export const GetMaplayerByTerminalType = query =>
  get(`${PANDA_GIS}/Maplayer/GetMaplayerByTerminalType`, query);

// 获取全部
export const GettMaplayer = query => get(`${PANDA_GIS}/Maplayer/GetMaplayer`, query);

// 添加底图方案
export const SetBaseMapschemeName = param =>
  post(`${PANDA_GIS}/Maplayer/SetBaseMapschemeName`, param);

// 设置底图数据
export const SetServiceConfig = query => post(`${PANDA_GIS}/Maplayer/SetServiceConfig`, query);

// 获取方矢量数据列表
export const GetVectorService = () =>
  get(`${PUBLISH_SERVICE}/Maplayer/GetVectorService`, { _version: 9999 });

// 获取元数据的工作空间列表
export const GetGISServerMapList = query =>
  get(`${PUBLISH_SERVICE}/Maplayer/GetGISServerMapList`, query);

// 发布原数据
export const publisService = (query, timeout) =>
  get(`${PANDA_GIS}/MetaData/D_Publish_GS_Service`, query, timeout);

// 解决方案名称
export const getSolutionList = query =>
  get(`${PUBLISH_SERVICE}/PlatformCenter/GetSolutionList`, query);

// 删除元数据
export const deleteVectorService = query =>
  get(`${PANDA_GIS}/MetaData/D_DeleteVectorService`, query);

// 更新元数据
export const updatePublishedMetaData = query =>
  get(`${PANDA_GIS}/MetaData/D_UpdatePublishedMetaData`, query);

// 删除配置
export const deleteConfig = query => get(`${PANDA_GIS}/MapLayer/DeleteMapLayer`, query);

// 增加瓦片
export const bindSchemeBaseMap = query => get(`${PANDA_GIS}/Maplayer/BindSchemeBaseMap`, query);

// 删除瓦片
export const unbindSchemeBaseMap = query => get(`${PANDA_GIS}/Maplayer/UnBindSchemeBaseMap`, query);
// 删除底图分级显示方案
export const DeletMapServicename = query =>
  get(`${PANDA_GIS}/MapLayer/DeleteMapServiceName`, query);

// 获取底图分级显示方案名
export const GetbaseMapschemeName = query =>
  get(`${PANDA_GIS}/Maplayer/GetbaseMapschemeName`, query);
// 设置web状态
export const setServiceType = query => get(`${PANDA_GIS}/MetaData/SetServiceType`, query);

// 设置web的默认方案
export const SetDefaultsSchemeName = param =>
  post(`${PANDA_GIS}/Maplayer/SetDefaultsSchemeName`, param);
// 获取角色
export const getUserRelationList = query =>
  get(`${CITY_SERVICE}/OMS.svc/WebGIS_GetUserRelationList`, query);

// 获取瓦片数据列表
export const GetBaseMapList = query => get(`${PUBLISH_SERVICE}/Maplayer/GetBaseMapList`, query);

// 新增瓦片服务
export const AddBaseMap = data => post(`${PUBLISH_SERVICE}/Maplayer/AddBaseMap`, data);

// 编辑瓦片数据
export const EditBaseMap = data => post(`${PUBLISH_SERVICE}/Maplayer/EditBaseMap`, data);

// 根据瓦片类型删除瓦片数据
export const DeleteBaseMap = query => get(`${PUBLISH_SERVICE}/Maplayer/DeleteBaseMap`, query);

// 获取矢量列表服务
export const GetVectorDataList = query =>
  get(`${PUBLISH_SERVICE}/Maplayer/GetVectorDataList`, query);

// 删除矢量数据
export const DeleteVectorData = id => post(`${PUBLISH_SERVICE}/Maplayer/DeleteVectorData?id=${id}`);

// 添加矢量数据配置服务
export const AddVectorData = data => post(`${PUBLISH_SERVICE}/Maplayer/AddVectorData`, data);

// 刷新矢量数据
export const RefreshVectorData = query =>
  get(`${PUBLISH_SERVICE}/Maplayer/RefreshVectorData`, query);
// 根据IP地址和端口号获取
export const GetProjectNames = query => get(`${PUBLISH_SERVICE}/Maplayer/GetProjectNames`, query);

// 查询方案列表
export const GetSchemaInfoList = query =>
  get(`${PUBLISH_SERVICE}/Maplayer/GetSchemaInfoList`, query);

// 增加方案
export const AddSchema = data => post(`${PUBLISH_SERVICE}/Maplayer/AddSchema`, data);

// 删除方案
export const DeleteSchema = query => get(`${PUBLISH_SERVICE}/Maplayer/DeleteSchema`, query);

// 编辑方案
export const EditSchema = data => post(`${PUBLISH_SERVICE}/Maplayer/EditSchema`, data);

// 方案管理设置地图范围
export const SchemaMapSettings = data =>
  post(`${PUBLISH_SERVICE}/Maplayer/SchemaMapSettings`, data);

// 方案管理添加方案瓦片
export const AddSchemaBaseMap = query => get(`${PUBLISH_SERVICE}/Maplayer/AddSchemaBaseMap`, query);

// 方案管理删除方案瓦片
export const DeleteSchemaBaseMap = query =>
  get(`${PUBLISH_SERVICE}/Maplayer/DeleteSchemaBaseMap`, query);

// 设置底图激活
export const SchemaSettingIsActive = query =>
  get(`${PUBLISH_SERVICE}/Maplayer/SchemaSettingIsActive`, query);

// 获取Web方案配置列表
export const GetWebSchemaList = query => get(`${PUBLISH_SERVICE}/Maplayer/GetWebSchemaList`, query);

// 添加Web方案
export const AddWebSchema = query => post(`${PUBLISH_SERVICE}/Maplayer/AddWebSchema`, query);

// 删除Web方案
export const DeleteWebSchema = schemaname =>
  get(`${PUBLISH_SERVICE}/Maplayer/DeleteWebSchema?schemaname=${schemaname}`);

// 设置web方案是否默认
export const IsActionWebSchema = query =>
  get(`${PUBLISH_SERVICE}/Maplayer/IsActionWebSchema`, query);

// 根据方案名称设置角色
export const SettingRoleWebSchema = query =>
  get(`${PUBLISH_SERVICE}/Maplayer/SettingRoleWebSchema`, query);

// 根据底图判断是否是方案最后底图
export const GetSchemaBaseMapIsLast = query =>
  get(`${PUBLISH_SERVICE}/Maplayer/GetSchemaBaseMapIsLast`, query);
// 上传菜单
export const UpLoadWebModuleTree = query =>
  post(`${PUBLISH_SERVICE}/PlatformCenter/UpLoadWebModuleTree`, query, {
    headers: {
      'Content-Type': 'multipart/form-data;charset=UTF-8',
    },
  });
export const DownLoadWebModuleTree = query =>
  `${PUBLISH_SERVICE}/PlatformCenter/DownLoadWebModuleTree?nodeId=${query.nodeId}&sysName=${
    query.sysName
  }`;

export const GetCustomBaseMapList = param =>
  get(`${CITY_SERVICE}/MapServer.svc/GetCustomBaseMapList?_version=9999`, param);

export const GetGridSetList = param =>
  get(`${CITY_SERVICE}/MapServer.svc/GetGridSetList?_version=9999`, param);

export const GetCustomBaseMapByName = param =>
  get(`${CITY_SERVICE}/MapServer.svc/GetCustomBaseMapByName?_version=9999`, param);

export const DragSingleWebsite = param =>
  get(`${CITY_SERVICE}/OMS.svc/Web4_DragSingleWebsite?_version=9999&_dc=1653360044919`, param);

export const UpdateSchemPipeNetwork = param =>
  get(`${PANDA_GIS}/MapLayer/UpdateSchemPipeNetwork`, param);

export const GetSpriteSheet = param => get(`${PANDA_GIS}/MultiMedia/GetSpriteSheet`, param);

// 同步地图组件
export const SyncMapComponent = query => get(`${PUBLISH_SERVICE}/WebSite/SyncMapComponent`, query);
