const isSkip = o => Object.prototype.toString.call(o) === '[object Object]' && (o.name || o.reason);
export function getDescribe(config) {
  if (config) {
    if (config.skip === true) {
      return describe.skip;
    }
    if (config.only === true) {
      return describe.only;
    }
    if (Array.isArray(config.skip)) {
      const skipArr = config.skip;
      const _describe = (name, impl) => {
        const skip = skipArr.find(skip => {
          if (typeof skip === 'string') {
            return skip === name;
          }
          return skip.name === name;
        });
        if (skip) {
          return describe.skip(`${ name } (${ typeof skip === 'string' ? '\uD83E\uDD37' : skip.reason })`, impl);
        }
        describe(name, impl);
      };
      _describe.skip = describe.skip;
      _describe.only = describe.only;
      return _describe;
    } else if (isSkip(config.skip)) {
      const skip = config.skip;
      if (!skip.reason) {
        return describe.skip;
      }
      const _describe = (name, impl) => {
        describe.skip(`${ name } (${ skip.reason })`, impl);
      };
      _describe.skip = describe.skip;
      _describe.only = describe.only;
      return _describe;
    }
  }
  return describe;
}
export function getIt(config) {
  if (!config)
    return it;
  const _it = (name, impl) => {
    if (Array.isArray(config.skip)) {
      const skip = config.skip.map(s => isSkip(s) ? s : {
        name: s,
        reason: '\uD83E\uDD37'
      }).find(s => s.name === name);
      if (skip) {
        if (skip.reason)
          name = `${ name } (${ skip.reason })`;
        return it.skip(name, impl);
      }
    }
    if (Array.isArray(config.only)) {
      const only = config.only.map(o => isSkip(o) ? o : {
        name: o,
        reason: '\uD83E\uDD37'
      }).find(o => o.name === name);
      if (only) {
        if (only.reason)
          name = `${ name } (${ only.reason })`;
        return it.only(name, impl);
      }
    }
    it(name, impl);
  };
  _it.skip = it.skip;
  _it.only = it.only;
  return _it;
}