import { closest } from "../../../utils/dom-utils.js";
import { buildCustomEvent } from "../../../utils/event-utils.js";
import { MissingParentError } from "./context/item-context-controller.js";
const itemContextEventName = 'atomic/resolveResult';
function fetchItemContext(element, parentName) {
    return new Promise((resolve, reject)=>{
        const event = buildCustomEvent(itemContextEventName, (item)=>resolve(item));
        element.dispatchEvent(event);
        if (!closest(element, parentName)) reject(new MissingParentError(element.nodeName.toLowerCase(), parentName));
    });
}
export { fetchItemContext };
