/*
 * Copyright (c) 2018, 2025, 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 RULENAME="oj-tsx-ojtag-datacmd";const DESCRIPTION="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.";const SHORT_DESCRIPTION="JET web component property 'data-oj-command' can only be used if defined for the component";const DATA_OJ_CMD="data-oj-command";const OJ_MENU="oj-menu";const OJ_OPTION="oj-option";const OJ_DEFER="oj-defer";const OJ_BIND_IF="oj-bind-if";const OJ_BIND_FOR_EACH="oj-bind-for-each";const BODY="body";class Rule{getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(){return{"Tsx<data-oj-command=>":this._onDataCmd}}_onDataCmd(ruleCtx,tsxProp){var tsxComp=tsxProp.parent,tagName=tsxComp.name;if(tagName!==OJ_OPTION){this._emitIssue(ruleCtx,tagName,1);return}if(!ruleCtx.utils.tsxUtils.getAncestor(tsxComp,OJ_MENU)){this._emitIssue(ruleCtx,tagName,2);return}let node;if(!(node=this._findParentComponent(tsxComp))){this._emitIssue(ruleCtx,tagName,3);return}if(!ruleCtx.utils.metaLib.isTagAttr(node.name,DATA_OJ_CMD)){this._emitIssue(ruleCtx,node.name,0);return}}_emitIssue(ruleCtx,tagName,msgNum){var issue;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>")}if(issue){if(msgNum>0){issue.setMsgKey(`${RULENAME}_${msgNum}`)}ruleCtx.reporter.addIssue(issue,ruleCtx)}}_findParentComponent(node){var name,ret=null;while(node&&node.parent){if(name=node.parent.name){if(name===BODY){break}if(name===OJ_BIND_IF||name===OJ_BIND_FOR_EACH||name===OJ_DEFER||name===OJ_MENU){node=node.parent;continue}ret=node.parent;break}}return ret}};module.exports=Rule;