/*
 * 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-cca-compjson-ns-reg";const SHORT="Web component namespaces starting with 'oj-' or 'ns-' must be registered.";const LONG="Web components namespaces starting with prefixes 'oj-' or 'ns-' must be registered. A component must not use an un-registered namespace.";class Rule{getName(){return RULENAME}getShortDescription(){return SHORT}getDescription(){return LONG}register(regCtx){this._nameSpaces=regCtx.config.nameSpaces;return{"compjson":this._onCompJson}}_onCompJson(ruleCtx,suppData){var name,o,compType,a,i,prefix,msg;o=suppData&&suppData.obj?suppData.obj:null;name=o?o.name:null;if(!name){return}if(name.startsWith("demo-")||name.startsWith("my-")){return}name=(o.pack?o.pack+"-":"")+name;compType=o.type||"composite";if(typeof compType!=="string"||typeof name!=="string"){return}a=name.split("-");if(name.startsWith("oj-")||name.startsWith("ns-")){if(a.length>=2){prefix=a[0]+"-"+a[1];if(!ruleCtx.utils.metaLib.isNSRegistered(prefix)){if(!ruleCtx.utils.metaLib.isJetTag(name)){msg=`'${name}' : unregistered use of '${name.substring(0,2)}' namespace`;_emitIssue(ruleCtx,suppData,msg)}}}}}}function _emitIssue(ruleCtx,suppData,msg,id){var issue,pos;issue=new ruleCtx.Issue(msg);pos=_getNamePos(suppData.ast);if(pos){issue.setPosition(pos)}if(id){issue.setMsgKey(RULENAME+"_"+id)}ruleCtx.reporter.addIssue(issue,ruleCtx)};function _getNamePos(ast){var props,name,pos,ret=null,i;if(ast&&ast.members){props=ast.members;for(i=0;i<props.length;i++){name=props[i];if(name.name==="name"){pos=name.pos;ret={line:pos.row,col:pos.col,startIndex:pos.index,endIndex:pos.index+5};break}}}return ret};module.exports=Rule;