"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findNextOption = findNextOption;
exports.findPrevOption = findPrevOption;
function findNextOption(currentOption) {
    var _a;
    const nextElement = currentOption.nextElementSibling;
    if (nextElement) {
        if (nextElement.role === "group") {
            return nextElement.querySelector('[role="option"]');
        }
        if (nextElement.role === "option") {
            return nextElement;
        }
    }
    // No next element: Current element might be inside a group.
    // Check if the parent has a next sibling
    const parentNextElement = (_a = currentOption.parentElement) === null || _a === void 0 ? void 0 : _a.nextElementSibling;
    if (parentNextElement) {
        if (parentNextElement.role === "group") {
            return parentNextElement.querySelector('[role="option"]');
        }
        if (parentNextElement.role === "option") {
            return parentNextElement;
        }
    }
    return null;
}
function findPrevOption(currentOption) {
    var _a;
    const prevElement = currentOption.previousElementSibling;
    if (prevElement) {
        if (prevElement.role === "group") {
            return prevElement.querySelector('[role="option"]:last-of-type');
        }
        if (prevElement.role === "option") {
            return prevElement;
        }
    }
    // No previous element: Current element might be inside a group.
    // Check if the parent has a previous sibling.
    const parentPrevElement = (_a = currentOption.parentElement) === null || _a === void 0 ? void 0 : _a.previousElementSibling;
    if (parentPrevElement) {
        if (parentPrevElement.role === "group") {
            return parentPrevElement.querySelector('[role="option"]:last-of-type');
        }
        if (parentPrevElement.role === "option") {
            return parentPrevElement;
        }
    }
    return null;
}
//# sourceMappingURL=domHelpers.js.map