/*
  <ContactList />组件通过data遍历渲染单个父节点递归结果(<TreeSelector />)生成组织树 - 支持多个父节点
  <TreeSelect />传递initLevel = 1表示父节点层级，递归渲染父节点下的同节点层级departList(同层级level不累加),子节点children(子节点level累加）
  抽成两个组件主要是因为一个组件的时候，data遍历递归的时候每次递归level都累加
*/
import React from 'react'
import TreeSelector from './TreeSelector'
import {Props, ContactListProps} from './interface'
import './index.less'

export const ContactList: React.FC<ContactListProps> = (props: ContactListProps) => {
  const {data} = props
  const contactListElements = data.map(itemNode => (
    <TreeSelector itemNode={itemNode} key={itemNode.value} {...props} />
  ))
  return <div>{contactListElements}</div>
}

const TreeSelect: React.FC<Props> = (props: Props) => {
  const initLevel = 1
  return <ContactList {...props} isShowFold level={initLevel} />
}

export default TreeSelect
