import { ref, watch } from 'vue';

// TODO: InstanceType<typeof Tree> 无法拿到 expose 的类型，这里暂时使用手动的写法

const useTreeFilter = _ref => {
  let {
    rootProps
  } = _ref;
  const treeRef = ref(null);
  const filterText = ref('');
  watch(filterText, text => {
    if (!treeRef.value) {
      return;
    }
    treeRef.value.filter(text);
  });
  const defaultFilterForTree = () => (filterText, treeNode) => {
    const transferOption = rootProps.options.find(_ref2 => {
      let {
        value
      } = _ref2;
      return value === treeNode.value;
    });
    if (!transferOption) {
      return false;
    }
    return transferOption.label.includes(filterText);
  };
  return {
    treeRef,
    filterText,
    defaultFilterForTree
  };
};

export { useTreeFilter };
