/*
 * 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-ns";const LONG="Web component namespaces prefixed by 'oj-' or 'ns-' must be registered via the Namespace Manager - "+"un-registered namespaces should not be used.\n"+"If a user/external component is flagged, the component is not known to JAF.  Review the confguration properties 'components' and 'nameSpaces'.";const SHORT="Web component namespaces starting with prefixes 'oj-' or 'ns-' must be registered.";class Rule{getName(){return RULENAME}getDescription(){return LONG}getShortDescription(){return SHORT}register(regCtx){if(this._nameSpaces=regCtx.config.nameSpaces){if(!this._nameSpaces.length){this._nameSpaces=null}}this._metaLib=regCtx.utils.metaLib;return{"TsxRenderComponent":this._onTsxRC}}_onTsxRC(ruleCtx,tsxRC){tsxRC.components.forEach(tsxComp=>{this._onTag(ruleCtx,tsxComp);if(tsxComp.children){tsxComp.children.forEach(child=>{this._onTag(ruleCtx,child)})}})}_onTag(ruleCtx,tsxComp){var tagName,a,prefix,msg,i;tagName=tsxComp.name;if(!tagName.includes("-")||tagName.startsWith("demo-")||tagName.startsWith("my-")||tagName==="oj-slot"||tsxComp.ojNS||tagName.charAt(0)===tagName.charAt(0).toUpperCase()){return}if(tagName.startsWith("oj-")||tagName.startsWith("ns-")){if(!ruleCtx.utils.metaLib.isNamespaceTag(tagName)){if(!ruleCtx.utils.metaLib.isJetTag(tagName)){msg=`<${tagName}> : unregistered use of '${tagName.substring(0,2)}' web component namespace`;this._emitIssue(ruleCtx,tsxComp,msg)}}return}if(this._nameSpaces){a=tagName.split("-");prefix=a[0]+"-"+a[1];for(i=0;i<this._nameSpaces.length;i++){if(this._nameSpaces[i].startsWith(prefix)){return}}}if(!ruleCtx.utils.metaLib.isComponentTag(tagName)){msg=`'${tagName}' : use of unknown web component namespace`;this._emitIssue(ruleCtx,tsxComp,msg,1)}}_emitIssue(ruleCtx,tsxComp,msg,id){var issue;issue=new ruleCtx.Issue(msg);if(id){issue.setMsgKey(`${RULENAME}_${id}`)}ruleCtx.utils.tsxUtils.setIssuePosition(issue,tsxComp);ruleCtx.reporter.addIssue(issue,ruleCtx)}}module.exports=Rule;