import request from "@/utils/request";
function customParamsSerializer(params) {
  let result = '';
  for (let key in params) {
    if(key=='filter'){
      if (params.hasOwnProperty(key)) {
        if (Array.isArray(params[key])) {
          params[key].forEach((item,index) => {
            result += `${key}[${index}][key]=${item.key}&${key}[${index}][op]=${item.op}&${key}[${index}][value]=${item.value}&`;
          });
        } else {
          result += `${key}=${params[key]}&`;
        }
      }

    }else{
      result += `${key}=${params[key]}&`;
    }

  }
  return result.slice(0, -1);
}
export function index(params,isLoading = false) {
  return request({
    method: "get",
    url: "/api/admin/base-form/index",
    params,
    paramsSerializer: customParamsSerializer,
    isLoading
  })
}

export function show(params, isLoading = true) {
  return request({
    method: "get",
    url: "/api/admin/base-form/show",
    params,
    isLoading
  })
}

export function save(data) {
  return request({
    method: "post",
    url: "/api/admin/base-form/save",
    data
  })
}

export function destroy(params) {
  return request({
    method: "get",
    url: "/api/admin/base-form/destroy",
    params
  })
}

export function imports(data) {
  return request({
    method: "post",
    url: "/api/admin/base-form/import",
    data
  })
}
