import { Form } from "antd";
import _ from "lodash";
import moment from "moment";

function helper(v, verify = _.identity, mapper = _.identity) {
  if (!v) {
    return undefined;
  } else if (!verify(v)) {
    return undefined;
  } else {
    return Form.createFormField({
      value: mapper(v),
    });
  }
}

export function mapPropsToFields(props) {
  return {
    name: helper(props.name),
    sex: helper(props.sex),
    birth_on: helper(props.birth_on, _.identity, (v) =>
      moment(v)
    ),
    logo_url: helper(props.logo_url),
    job_year: helper(props.job_year, _.identity, (v) => moment(v)),
    job_position: helper(props.job_position, (v) => v.size != 0),
    city: helper(props.city, (v) => v.size != 0),
    salary: helper(props.salary),
    job_category: helper(props.job_category, (v) => v.size != 0),
    evaluate: helper(props.evaluate),
    mobile: helper(props.mobile),
    attachment_id: helper(props.attachment_id)
  };
}
