import { isNullES } from 'js-fast-way'
import { formulaArrayToString } from './formulaArrayToString'

export const rangeToString = (processFormula, eleMap) => {
    let text = ''
    if (isNullES(processFormula.arguments1) && isNullES(processFormula.arguments2)) {
        text = ''
    } else if (processFormula.symbol === '【min,max】') {
        text = '[' + getArg(processFormula.arguments1, eleMap) + ',' + getArg(processFormula.arguments2, eleMap) + ']'
    } else if (processFormula.symbol === '>') {
        text = '(' + getArg(processFormula.arguments1, eleMap) + ',' + '100000' + ')'
    } else if (processFormula.symbol === '<') {
        text = '(' + '0' + ',' + getArg(processFormula.arguments2, eleMap) + ')'
    } else if (processFormula.symbol === '≥') {
        text = '[' + getArg(processFormula.arguments1, eleMap) + ',' + '100000' + ']'
    } else if (processFormula.symbol === '≤') {
        text = '[' + '0' + ',' + getArg(processFormula.arguments2, eleMap) + ']'
    }
    return text
}

function getArg(arg, eleMap) {
    let text = ''
    if (Array.isArray(arg)) {
        let { text:argtext, eleMap:argeleMap } = formulaArrayToString(arg, [{ children:[] }])
        text = argtext
        for (let key in argeleMap) {
            eleMap[key] = argeleMap[key]
        }
    } else if (typeof arg == 'string') {
        text = arg
    }
    return text
}
