/*
 * 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 path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-slots"};ruleDef.prototype.getShortDescription=function(){return"Verify slots are declared"};ruleDef.prototype.getDescription=function(){return"This rule checks that any slots used are declared in the metadata"};ruleDef.prototype.register=function(context){return{"<oj-bind-slot>":this._doAudit}};ruleDef.prototype._doAudit=function(context){let issue;const componentName=Utils.matchComponentPath(context,path.dirname(context.filepath));if(componentName){const slotName=context.tagNode.attribs.name;if(!slotName||!context.utils.DomUtils.isExpression(slotName)){const componentSlots=Utils.componentInfo(context,componentName).slots;if(!componentSlots||slotName&&!componentSlots.hasOwnProperty(slotName)||!slotName&&!componentSlots.hasOwnProperty("")){issue=new context.Issue(`Slot '${slotName?slotName:"default"}' for component ${componentName} has not been declared in the component metadata`);issue.setMsgKey(context.ruleName+"_1");context.reporter.addIssue(issue,context)}else{const slotDetail=componentSlots[slotName?slotName:""];if(slotDetail.data){issue=new context.Issue(`Slot '${slotName?slotName:"default"}' for component ${componentName} has been declared with a data attribute in the component metadata. The data attribute only applies for template slots`);issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context,"minor")}}}}};module.exports=ruleDef;