import { a as _asyncToGenerator, r as regenerator } from './asyncToGenerator-5ef104a7.js';
import './_commonjsHelpers-0c4b6f40.js';
import './core.get-iterator-method-ea258bb1.js';
import './web.dom.iterable-ab4dea5c.js';
import './_library-528f1934.js';
import './_iter-detect-98db3b07.js';

var _this = undefined;

var getRootDocGroup = function () {
  var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(id, client) {
    var query, result, checkPropExist;
    return regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            query = "*[_type == 'documentGroup' && _id == '" + id + "'][0]";
            _context.next = 3;
            return client.fetch(query);

          case 3:
            result = _context.sent;
            checkPropExist = result && result.parent && (result.parent._id ? result.parent._id : result.parent._ref);

            if (!(result && result.parent)) {
              _context.next = 11;
              break;
            }

            _context.next = 8;
            return getRootDocGroup(checkPropExist, client);

          case 8:
            return _context.abrupt("return", _context.sent);

          case 11:
            if (!(result && result.identifier && result.identifier.current)) {
              _context.next = 15;
              break;
            }

            return _context.abrupt("return", result.identifier.current);

          case 15:
            return _context.abrupt("return");

          case 16:
          case "end":
            return _context.stop();
        }
      }
    }, _callee, _this);
  }));

  return function getRootDocGroup(_x, _x2) {
    return _ref.apply(this, arguments);
  };
}();

export default getRootDocGroup;
