import { first, last } from "lodash"

export const checkboxCheckedNone = (arg) => {
    let { value, length, noneValue, required } = arg
    if (length === undefined) length = 2
    if (noneValue === undefined) noneValue = ''
    if (required === undefined) required = false

    if (first(value) === noneValue && value.length > 1) {
        // 在'无'之后选中其他值
        value.shift()
    } else if (
        value.length >= length
        ||
        (last(value) === noneValue && value.length > 1)
        ||
        (!value.length && required)
    ) {
        // 在其他值之后选中'无'
        value = [noneValue]
    }
    return value
}