/* eslint-disable no-undef */

/**
 * @return {string}
 */

export default {
  onChange: ({ value, colInfo, getFieldValue, setFieldVisible, setFieldValue, setFieldEditable }) => {
    if (colInfo.FIELD_NAME == 'Nav_VarSup.TRANS_TYPE') {
      setFieldVisible('Nav_VarSup.FORMULA', false);
      setFieldVisible('Nav_VarSup.FUNCTION', false);
      if (value == 0) {
        setFieldVisible('Nav_VarSup.FORMULA', true);
      } else {
        setFieldVisible('Nav_VarSup.FUNCTION', true);
      }
    }

    if (colInfo.FIELD_NAME == 'CHANGE') {
      setFieldVisible('CHANGE_RATE', value);
    }
  },
  onBeforeEdit: ({ isNew, stateData, login, getFieldValue, setFieldValue, setFieldValueByBatch, setFieldEditable, setFieldVisible }) => {
    if (!isNew) {
      setFieldEditable('Nav_SrcTag.Nav_DataFrequency.NAME', false);
    }

    setFieldVisible('Nav_VarSup.FORMULA', false);
    setFieldVisible('Nav_VarSup.FUNCTION', false);
    if (stateData) {
      if (stateData.Nav_VarSup.TRANS_TYPE == 0) {
        setFieldVisible('Nav_VarSup.FORMULA', true);
      } else if (stateData.Nav_VarSup.TRANS_TYPE == 1) {
        setFieldVisible('Nav_VarSup.FUNCTION', true);
      }

      const val = stateData.CHANGE ? true : false;
      setFieldVisible('CHANGE_RATE', val);
    }
  }
}
