export default (function (_ref) {
  var intlPrefix = _ref.intlPrefix,
      formatMessage = _ref.formatMessage,
      projectOptionsDs = _ref.projectOptionsDs;

  function handleUpdate(_ref2) {
    var value = _ref2.value,
        record = _ref2.record,
        name = _ref2.name;

    if (name === 'projectId') {
      if (value) {
        var project = projectOptionsDs.find(function (projectRecord) {
          return projectRecord.get('id') === value;
        });

        var _ref3 = project ? project.toData() : {},
            projectName = _ref3.name,
            code = _ref3.code;

        record.set('name', projectName);
        record.set('code', code);
      } else {
        record.set('name', null);
        record.set('code', null);
      }
    }
  }

  return {
    autoCreate: false,
    autoQuery: false,
    selection: false,
    paging: false,
    transport: {},
    fields: [{
      name: 'name',
      type: 'string',
      label: formatMessage({
        id: "".concat(intlPrefix, ".project.name")
      })
    }, {
      name: 'code',
      type: 'string',
      label: formatMessage({
        id: "".concat(intlPrefix, ".project.code")
      })
    }, {
      name: 'projectId',
      textField: 'name',
      valueField: 'id',
      label: formatMessage({
        id: "".concat(intlPrefix, ".project")
      }),
      options: projectOptionsDs,
      required: true
    }],
    events: {
      update: handleUpdate
    }
  };
});