import { Unit } from "./types2";

export function findSelectTarget(unitList: Unit[], selectTargetId: string) {
  const newUnitList = [...unitList];
  const unit = newUnitList.find((i) => i.id === selectTargetId);
  if (unit) {
    return {
      list: newUnitList,
      item: unit,
    };
  } else {
    for (let i = 0; i < newUnitList.length; ++i) {
      const list = newUnitList[i].children;
      const u = list.find((i) => i.id === selectTargetId);
      if (u)
        return {
          list: newUnitList,
          item: u,
        };
    }
  }
  return {
    list: newUnitList,
    item: undefined,
  };
}
