import React from 'react';
import { inject, observer } from 'mobx-react';
import './index.less';

function ReqAction({ requestIds = [], req, children }) {
  let isOk = false;
  if (!Array.isArray(requestIds) || requestIds.length === 0) {
    isOk = true;
  }
  const flags = new Array(requestIds.length).fill(false);
  requestIds.forEach((id, index) => {
    flags[index] = !req.reqStatusMap[id] ? true : req.reqStatusMap[id].status !== 'padding';
  });
  isOk = flags.filter(v => !v).length === 0;
  return React.Children.map(children, item => React.cloneElement(item, { reqIsOk: isOk }));
}

export default inject('req')(observer(ReqAction));
