/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const RULE_NAME="oj-html-ojtag-datacmd";const DATA_OJ_CMD="data-oj-command";const OJ_MENU="oj-menu";const OJ_OPTION="oj-option";const OJ_PREFIX="oj-";const OJ_DEFER="oj-defer";const OJ_BIND_IF="oj-bind-if";const OJ_BIND_FOR_EACH="oj-bind-for-each";const BODY="body";function getName(){return RULE_NAME};function getShortDescription(){return"JET web component property 'data-oj-command' can only be used if defined for the component"};function getDescription(){return"Attribute 'data-oj-command' should not be used on JET web component elements if the component does not have a list of "+"values defined for it - refer to the JET API documentation for the component."};function register(){return{"<data-oj-command=>":_onAttr}};function _onAttr(ruleCtx){var node;if(ruleCtx.tag!==OJ_OPTION){_emitIssue(ruleCtx,ruleCtx.tag,1);return}if(!ruleCtx.utils.DomUtils.isChildOfElem(OJ_MENU,ruleCtx.tagNode)){_emitIssue(ruleCtx,ruleCtx.tag,2);return}node=_findParentComponent(ruleCtx.tagNode);if(!node){_emitIssue(ruleCtx,ruleCtx.tag,3);return}if(!ruleCtx.utils.metaLib.isTagAttr(node.name,DATA_OJ_CMD)){_emitIssue(ruleCtx,node.name,0);return}};function _emitIssue(ruleCtx,tagName,msgNum){var issue,attrPos;if(msgNum===0){issue=new ruleCtx.Issue("Attribute 'data-oj-command' has no defined values for <"+tagName+">")}else if(msgNum===1){issue=new ruleCtx.Issue("Attribute 'data-oj-command' must appear on <oj-option> not <"+tagName+">")}else if(msgNum===2){issue=new ruleCtx.Issue("Attribute 'data-oj-command' - containing <oj-option> is not a child of <oj-menu>")}else if(msgNum===3){issue=new ruleCtx.Issue("Attribute 'data-oj-command' - unable to locate containing component of the associated <oj-menu>")}if(msgNum){issue.setMsgKey(RULE_NAME+"_"+msgNum)}attrPos=ruleCtx.utils.DomUtils.getAttribPosition(ruleCtx.data,ruleCtx.tagNode,DATA_OJ_CMD);issue.setPosition(attrPos.row,attrPos.col,attrPos.start,attrPos.end);ruleCtx.reporter.addIssue(issue,ruleCtx)};function _findParentComponent(node){var name,ret=null;while(node&&node.parent){if(name=node.parent.name){if(name===BODY){break}if(name.startsWith(OJ_PREFIX)){if(name!==OJ_BIND_IF&&name!==OJ_BIND_FOR_EACH&&name!==OJ_MENU&&name!==OJ_DEFER){ret=node.parent;break}}}node=node.parent}return ret};module.exports={getName,getDescription,getShortDescription,register};