import axios from "axios";
import moment from "moment";
 
export function processValue(v) {
  const education = [];
  const experience = [];
  const birth_on = v.birth_on.format("YYYY-MM-DD");
  const job_year = !v.job_year
    ? undefined
    : v.job_year.format("YYYY-MM-DD");
  for (const key in v.education) {
    const obj = { ...v.education[key] };
    obj.begin_on = obj.begin_on.format("YYYY-MM-DD");
    obj.end_on = obj.end_on.format("YYYY-MM-DD");
    obj.major=obj.major.trim();
    obj.school=obj.school.trim();
    education.push(obj);
  }
  for (const key in v.experience) {
    const obj = { ...v.experience[key] };
    obj.begin_on = obj.begin_on.format("YYYY-MM-DD");
    obj.end_on = obj.end_on.format("YYYY-MM-DD");
    obj.company = obj.company.trim();
    obj.desc = obj.desc.trim();
    experience.push(obj);
  }
  const name = !v.name
  ? undefined
  : v.name.trim();  
  const evaluate = !v.evaluate
  ? undefined
  : v.evaluate.trim();
  return {
    resume: { ...v,evaluate, name,education, experience, birth_on, job_year },
  };
}

export async function sumitResume(v) {
  const json = processValue(v);
  await axios.post(`/resumes.json`, json);
  return;
}
