import { COMPONENT_CLASS } from './const';

const cls = appendClass => `${COMPONENT_CLASS}-${appendClass}`;
const defaultFilter = (filterText, option) => option.label.includes(filterText);
const isTree = options => options.some(o => Array.isArray(o.children) && o.children.length > 0);
const flattenTree = options => {
  const result = [];
  options.forEach(o => {
    result.push(o);
    if (Array.isArray(o.children) && o.children.length > 0) {
      result.push(...flattenTree(o.children));
    }
  });
  return result;
};

export { cls, defaultFilter, flattenTree, isTree };
