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

const { createConfirm } = useMessage();

enum Api {
  list = '/pagecontentcapture/pageContentCapture/listVoError',
  save='/pagecontentcapture/pageContentCapture/add',
  edit='/pagecontentcapture/pageContentCapture/edit',
  deleteOne = '/pagecontentcapture/pageContentCapture/delete',
  deleteBatch = '/pagecontentcapture/pageContentCapture/deleteBatch',
  ignoreAll = '/pagecontentcapture/pageContentCapture/ignoreAll',
  ignoreAllCancell = '/pagecontentcapture/pageContentCapture/ignoreAllCancell',
  ModifyTrueBatchDelete = '/pagecontentcapture/pageContentCapture/ModifyTrueBatchDelete',
  ModifyFalseBatchDelete = '/pagecontentcapture/pageContentCapture/ModifyFalseBatchDelete',
  importExcel = '/pagecontentcapture/pageContentCapture/importExcel',
  exportXls = '/pagecontentcapture/pageContentCapture/exportXlsError',
  whetherIgnoreAll = '/pagecontentcapture/pageContentCapture/whetherIgnoreAll',
  whetherIgnoreAllCancell = '/pagecontentcapture/pageContentCapture/whetherIgnoreAllCancell',
}

/**
 * 导出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();
      });
    }
  });
}

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();
      });
    }
  });
}

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

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

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


export const ignoreWhetherBatchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认忽略',
    content: '是否忽略选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.whetherIgnoreAllCancell, 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 });
}
