class FocusResolver {
  static resolveFocus(element, selectText = true) {
    var _a;
    if (!element)
      return;
    (_a = element.focus) === null || _a === void 0 ? void 0 : _a.call(element);
    if (element.setFocus) {
      element.setFocus({ selectText });
      return;
    }
    this.resolveFocusOnChild(element, selectText);
  }
  static resolveFocusOnChild(element, selectText = true) {
    var _a, _b;
    if (this.isGridCell(element) && element.firstElementChild) {
      this.resolveFocusOnChild(element.firstElementChild);
      return;
    }
    if (!element || !element.classList.contains('hydrated'))
      return;
    const firstChild = element.firstElementChild;
    if (!(firstChild === null || firstChild === void 0 ? void 0 : firstChild.focus) && !(firstChild === null || firstChild === void 0 ? void 0 : firstChild.setFocus))
      return;
    (_a = firstChild === null || firstChild === void 0 ? void 0 : firstChild.focus) === null || _a === void 0 ? void 0 : _a.call(firstChild);
    (_b = firstChild === null || firstChild === void 0 ? void 0 : firstChild.setFocus) === null || _b === void 0 ? void 0 : _b.call(firstChild, { selectText });
  }
  static isGridCell(element) {
    var _a;
    return ((_a = element === null || element === void 0 ? void 0 : element.getAttribute) === null || _a === void 0 ? void 0 : _a.call(element, "role")) === 'gridcell';
  }
}

export { FocusResolver as F };
