import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/weibocontentcapture/weiboContentCapture/listVoError',
  save='/weibocontentcapture/weiboContentCapture/add',
  edit='/weibocontentcapture/weiboContentCapture/edit',
  deleteOne = '/weibocontentcapture/weiboContentCapture/delete',
  deleteBatch = '/weibocontentcapture/weiboContentCapture/deleteBatch',
  importExcel = '/weibocontentcapture/weiboContentCapture/importExcel',
  exportXls = '/weibocontentcapture/weiboContentCapture/exportXls',
  batchHIgnoreHandle = '/weibocontentcapture/weiboContentCapture/batchHIgnoreHandle',
  batchHIgnoreHandleDelete = '/weibocontentcapture/weiboContentCapture/batchHIgnoreHandleDelete',
  batchHModifyTrue = '/weibocontentcapture/weiboContentCapture/batchHModifyTrue',
  batchHModifyFalse = '/weibocontentcapture/weiboContentCapture/batchHModifyFalse',
  ignoreAll = '/weibocontentcapture/weiboContentCapture/ignoreAll',
  ignoreAllCancell = '/weibocontentcapture/weiboContentCapture/ignoreAllCancell',
}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}

export const batchHIgnoreHandle = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认忽略',
    content: '是否忽略选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.batchHIgnoreHandle, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}


export const batchHIgnoreHandleDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '取消忽略',
    content: '是否取消忽略选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.batchHIgnoreHandleDelete, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}


export const batchHModifyTrue = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认修改',
    content: '是否修改选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.batchHModifyTrue, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}

export const batchHModifyFalse = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认取消修改',
    content: '是否取消修改选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.batchHModifyFalse, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}



export const ignoreBatchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认设置单词不扫描',
    content: '是否设置单词不扫描选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.ignoreAll, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}


export const ignoreAllCancellBatchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认取消设置单词不扫描',
    content: '是否取消设置单词不扫描选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.ignoreAllCancell, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
