import isPlainObject from '../utils/isPlainObject';
import isEqual from '../utils/isEqual';
import uniqueId from '../utils/uniqueId';
export function reviveSelectItem(reviver) {
    var reviverFn;
    if (typeof reviver === 'function') {
        reviverFn = reviver;
    }
    else if (isPlainObject(reviver)) {
        reviverFn = function (item) {
            return Object.keys(reviver).every(function (k) { return isEqual(reviver[k], item[k]); })
                ? item
                : null;
        };
    }
    else {
        reviverFn = function (item) { return (item.key === reviver ? item : null); };
    }
    return {
        key: uniqueId('select-item-reviver-'),
        text: null,
        type: 'reviver',
        reviver: reviverFn,
    };
}
export function filterReviver(value) {
    if (Array.isArray(value)) {
        var found = false;
        var val = [];
        for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
            var v = value_1[_i];
            if (v.type === 'reviver') {
                found = true;
            }
            else {
                val.push(v);
            }
        }
        return found ? val : value;
    }
    if (value) {
        return value.type === 'reviver' ? null : value;
    }
    return value;
}
