/*
 * 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-html-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 COLON_SLOT=":slot";const DEFAULT_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_REFRESHER||tag===OJ_IF||tag===OJ_SWITCHER};const SPECIAL_CASES=["oj-label","demo-tabs"];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._utils=regCtx.utils.utils;return{"webcomp":this._onWebComp}};Rule.prototype._onWebComp=function(ruleCtx,tagName){if(_isExempt(tagName)){return}if(_isSpecialCase(tagName)){return}if(!ruleCtx.utils.metaLib.hasTagDefaultSlot(tagName)){this._checkChildren(ruleCtx)}};Rule.prototype._checkChildren=function(ruleCtx){var childs,child,node;if((childs=ruleCtx.tagNode.children)&&childs.length){for(child of childs){node=null;if(child.type!=="tag"){continue}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){this._emitIssue(ruleCtx,node)}}}}};Rule.prototype._emitIssue=function(ruleCtx,child){let issue=new ruleCtx.Issue(`<${ruleCtx.tag}> 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(child.type==="tag"){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 ret=false;var attribs=child.attribs;if(this._utils.hasAnyProps(attribs)){let slotx=attribs[SLOT]||attribs[COLON_SLOT];if(slotx&&slotx!==DEFAULT_SLOT){ret=true}}return ret};function _isSpecialCase(tagName){return SPECIAL_CASES.includes(tagName)};module.exports=Rule;