import { BaseRuleVisitor, forEachAttribute } from "./rule-utils.js";
class NoDuplicateAttributesVisitor extends BaseRuleVisitor {
    visitHTMLOpenTagNode(node) {
        this.checkDuplicateAttributes(node);
        super.visitHTMLOpenTagNode(node);
    }
    visitHTMLSelfCloseTagNode(node) {
        this.checkDuplicateAttributes(node);
        super.visitHTMLSelfCloseTagNode(node);
    }
    checkDuplicateAttributes(node) {
        const attributeNames = new Map();
        forEachAttribute(node, (attributeNode) => {
            if (attributeNode.name?.type !== "AST_HTML_ATTRIBUTE_NAME_NODE")
                return;
            const nameNode = attributeNode.name;
            if (!nameNode.name)
                return;
            const attributeName = nameNode.name.value.toLowerCase(); // HTML attributes are case-insensitive
            if (!attributeNames.has(attributeName)) {
                attributeNames.set(attributeName, []);
            }
            attributeNames.get(attributeName).push(nameNode);
        });
        for (const [attributeName, nameNodes] of attributeNames) {
            if (nameNodes.length > 1) {
                for (let i = 1; i < nameNodes.length; i++) {
                    const nameNode = nameNodes[i];
                    this.addOffense(`Duplicate attribute \`${attributeName}\` found on tag. Remove the duplicate occurrence.`, nameNode.location, "error");
                }
            }
        }
    }
}
export class HTMLNoDuplicateAttributesRule {
    name = "html-no-duplicate-attributes";
    check(node) {
        const visitor = new NoDuplicateAttributesVisitor(this.name);
        visitor.visit(node);
        return visitor.offenses;
    }
}
//# sourceMappingURL=html-no-duplicate-attributes.js.map