import axios from "axios";

function transf(json, history) {
  return {
    id: json.id,
    name: json.user_name,
    job: json.job_name,
    sex: json.sex,
    age: json.age,
    exp: json.work_year,
    edu_1: json.last_edu_1,
    edu_2: json.last_edu_2,
    dlFunc: json.attachment_url
      ? () => {
          window.open(json.attachment_url);
        }
      : null,
    time: json.created_at,
    pfFunc: () => {
      history.push(`/recruitment/resumedetails?id=${json.id}`);
    },
  };
}

export async function getAppliers(jobID, page, history) {
  const res = await axios.get(`/jobs/${jobID}/applyed_users.json`, {
    params: {
      page,
      per_page: 10,
    },
  });
  return [res.data.data.map((json) => transf(json, history)),res.data.count];
}

const applier = {
  id: 1,
  name: "张三",
  job: "开发",
  sex: "男",
  age: 20,
  exp: "1",
  edu_1: "硕士",
  edu_2: "统招全日制",
  dlFunc: () => {
    window.open("/api/attachments/392664");
  },
  time: "2020-01-10",
  pfFunc: () => {},
};

export const mock = [applier, applier, applier, applier, applier, applier];
