import ContextMapper from "./ContextMapper";
import Rule from "./Rule";

export default class XPathContextMapper extends ContextMapper {
    constructor(context : string) {
        super(context);
    }

    buildElementToRuleMap() : Map<Element, Rule[]> {
        const xpathQueryResult = document.evaluate(this._context, document, null, XPathResult.ANY_TYPE, null);
        const context = xpathQueryResult.iterateNext();
        if (context instanceof Element) {
            return this.buildElementToRuleMapForSelectors(context);
        } else {
            return new Map();
        }
    }

}