/*
 * 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 RULE_NAME="oj-tsx-slot-default";const DESCRIPT="A child component is defined in a component parent's default slot, but the parent does not support default slots.";const SHORT=DESCRIPT;const SLOT="slot";const TEMPLATE="template";const OJ_DEFER="oj-defer";const OJ_BIND_DASH="oj-bind-";const OJ_IF="oj-if";const OJ_REFRESHER="oj-refresher";const OJ_SWITCHER="oj-switcher";const _isExempt=tag=>{return tag===TEMPLATE||tag===OJ_DEFER||tag.startsWith(OJ_BIND_DASH)||tag===OJ_IF||tag===OJ_REFRESHER||tag===OJ_SWITCHER};function Rule(){};Rule.prototype.getName=function(){return RULE_NAME};Rule.prototype.getShortDescription=function(){return SHORT};Rule.prototype.getDescription=function(){return DESCRIPT};Rule.prototype.register=function(regCtx){this._metaLib=regCtx.utils.metaLib;this._tsxUtils=regCtx.utils.tsxUtils;return{"TsxWebComponent":this._onWebComp}};Rule.prototype._onWebComp=function(ruleCtx,tsxComp){var tagName=tsxComp.name;if(_isExempt(tagName)){return}if(!ruleCtx.utils.metaLib.hasTagDefaultSlot(tagName)){this._checkChildren(ruleCtx,tsxComp)}};Rule.prototype._checkChildren=function(ruleCtx,tsxComp){var childs,child,node;if((childs=tsxComp.children)&&childs.length){for(child of childs){node=null;if(!this._hasChildSlotAttrib(child)){if(child.name.startsWith(OJ_BIND_DASH)||child.name===TEMPLATE||child.name===OJ_DEFER){node=this._getFirstActiveChild(child)}else{node=child};if(node){if(this._metaLib.isWCTag(node.name)){this._emitIssue(ruleCtx,tsxComp.name,node)}}}}}};Rule.prototype._emitIssue=function(ruleCtx,tagName,child){let issue=new ruleCtx.Issue(`<${tagName}> does not define a default slot but it contains a child <${child.name}>`);issue.setPosition(null,null,child.startIndex,child.endIndex);ruleCtx.reporter.addIssue(issue,ruleCtx)};Rule.prototype._getFirstActiveChild=function(node){if(node.children&&node.children.length){let child;for(child of node.children){if(this._hasChildSlotAttrib(child)){break}if(child.name.startsWith(OJ_BIND_DASH)||child.name===TEMPLATE||child.name===OJ_DEFER){return this._getFirstActiveChild(child)}return child}}return null};Rule.prototype._hasChildSlotAttrib=function(child){var slotName=this._tsxUtils.getPropertyStringValue(child,SLOT);return typeof slotName==="string"&&slotName.length};module.exports=Rule;