import { func } from "prop-types";
export default function generateState(children) {
  let orderIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  let data = [];
  children && children.map(child => {
    // let orderIndexSub = orderIndex ? orderIndex : [];
    // orderIndexSub.push(child.props.id);
    let isValidChild = Array.isArray(child.props.children) || typeof child.props.children === "object" ? true : false;

    if (isValidChild) {
      let childData = Array.isArray(child.props.children) ? child.props.children : [child.props.children];
      let obj = {
        id: child.props.id,
        status: false,
        child: generateState(childData) // orderIndex: orderIndexSub

      };
      data.push(obj);
    } else {
      let obj = {
        id: child.props.id,
        status: false // orderIndex: [child.props.id]

      };
      data.push(obj);
    }
  });
  return data;
}
export function onIteratedState(id, status) {
  let state = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  return state.map(obj => {
    if (obj.id == id) {
      obj.status = status;
    } else {
      obj.child && onIteratedState(id, status, obj.child);
    }

    return obj;
  });
}
let status;
export function onGetStatus(id) {
  let state = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  state.forEach(obj => {
    if (obj.id === id) {
      status = obj.status;
    } else {
      obj.child && onGetStatus(id, obj.child);
    }
  });
  return status;
}
export function onExpandToggle(status) {
  let state = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  return state.map(obj => {
    obj.status = status;
    obj.child && onExpandToggle(status, obj.child);
    return obj;
  });
}