/*
 * 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-tsx-cca-tagname";const SHORT_DESCRIPT="Web component element names must be defined";const LONG_DESCRIPT="The web component is unknown to JAF. Check the spelling, or review the associated component.json "+"metadata. This may also occur because the web component's metadata has not been declared to "+"JAF via the configuration property 'components', or because the element name makes use of "+"an unregistered \"oj-\"  namespace.  For JET core pack components, check that the configuration "+"property 'jetCorePack', if specified, is correct.";const IGNORE_LIST=["oj-slot","oj-dynamic-form"];function Rule(){this._ignoreList=null}Rule.prototype.getName=function(){return RULE_NAME};Rule.prototype.getShortDescription=function(){return SHORT_DESCRIPT};Rule.prototype.getDescription=function(){return LONG_DESCRIPT};Rule.prototype.register=function(regCtx){if(!this._getIgnoreOverrides(regCtx)){return false}this._tsxUtils=regCtx.utils.tsxUtils;return{"TsxRenderComponent":this._onTsxRC}};Rule.prototype._onTsxRC=function(ruleCtx,tsxRC){tsxRC.components.forEach(tsxComp=>{this._checkComp(ruleCtx,tsxComp)})};Rule.prototype._checkComp=function(ruleCtx,tsxComp){var tagName=tsxComp.name;if(tagName.includes("-")){if(!(this._tsxUtils.isCommonElem(tagName)||this._tsxUtils.isHtml5ObsoleteElem(tagName)||tagName==="template"||this._isSvg(ruleCtx,tagName))){if(!ruleCtx.utils.metaLib.isWCTag(tagName)&&!IGNORE_LIST.includes(tagName)&&!this._checkOverrides(tagName)){this._emitIssue(ruleCtx,tsxComp)}}}if(tsxComp.children){tsxComp.children.forEach(child=>{this._checkComp(ruleCtx,child)})}};Rule.prototype._emitIssue=function(ruleCtx,tsxComp){var tagName=tsxComp.name;var b=tagName.includes("-");var s=b?"web component":"tag";var issue=new ruleCtx.Issue(`<${tagName}> is not a known ${s}`);if(b){issue.setMsgKey(RULE_NAME+"_1")}this._tsxUtils.setIssuePosition(issue,tsxComp);ruleCtx.reporter.addIssue(issue,ruleCtx)};Rule.prototype._checkOverrides=function(tagName){if(this._ignoreList){for(let i=0;i<this._ignoreList.length;i++){if(this._ignoreList[i].test(tagName)){return true}}}return false};Rule.prototype._getIgnoreOverrides=function(regCtx){var ignore,customOpts;if(!(customOpts=regCtx.ruleOpts.customOpts)){return true}if(ignore=customOpts.ignore){if(!Array.isArray(ignore)){regCtx.utils.msgLib.error(`Rule ${RULE_NAME} :  config option 'ignore' is not an array`);return false}this._ignoreList=[];for(let i=0;i<ignore.length;i++){if(typeof ignore[i]==="string"){try{this._ignoreList[i]=new RegExp(ignore[i].trim())}catch(e){regCtx.utils.msgLib.error(`Config 'ruleMods' ${RULE_NAME} 'ignore' entry [${i}]: ${e.message}`);return false}}}}return true};Rule.prototype._isSvg=function(ruleCtx,elem){var ret=false,n;if(elem==="svg"){return true}if(this._tsxUtils.isSvgElem(elem)){n=ruleCtx.tagNode;while(n){n=n.parent;if(!n){break}if(n.name&&n.name==="svg"){ret=true;break}}}return ret};module.exports=Rule;