/*
 * 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-html-binding-as-slot-child";const DESCRIPTION="JET binding components such as <oj-bind-if> are not present in the final browser "+"DOM at runtime, and as such will not function correctly when directly assigned to "+"a slot. They should either be relaced with <oj-if> which can be assigned to a slot, "+"or they should be wrapped in another element such as a <div> or <span> which has "+"the slot attribute applied.<br>";const SHORT_DESCRIPTION="The slot attribute should not be applied directly to JET binding components";const SLOT="slot";const TEMPLATE="template";const OJ_BIND="oj-bind";const OJ_BIND_IF="oj-bind-if";const OJ_IF="oj-if";const OJ_OPTION="oj-option";const BODY="body";const EXCEPTION_TAGS=["oj-accordion","oj-buttonset-many","oj-buttonset-one","oj-checkboxset","oj-combobox-many","oj-combobox-one","oj-film-strip","oj-form-layout","oj-c-form-layout","oj-list-item-layout","oj-masonry-layout","oj-menu","oj-menu-select-many","oj-optgroup","oj-radioset","oj-select-many","oj-select-single","oj-toolbar","oj-validation-group","template"];class Rule{getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(regCtx){this._metaLib=regCtx.utils.metaLib;return{bindingtag:this._onBind}}_onBind(ruleCtx,tag){var attribs,attrib,node,parent,name;node=ruleCtx.tagNode;if(attribs=node.attribs){for(attrib in attribs){if(attrib===SLOT){this._emitIssue(1,ruleCtx,tag);break}}}if(parent=this._getParentElem(node,ruleCtx)){name=parent.name;if(name===OJ_IF){return}if(name===OJ_OPTION){if(parent?.parent?.name===TEMPLATE){return}}if(EXCEPTION_TAGS.includes(name)){return}if(this._metaLib.isWCTag(name)&&this._metaLib.hasTagDefaultSlot(name)){this._emitIssue(2,ruleCtx,node.name,name)}}}_getParentElem(node,ruleCtx){var parent,name;if(node&&(parent=node.parent)){if(name=parent.name){if(name.startsWith(OJ_BIND)||name===TEMPLATE||ruleCtx.utils.DomUtils.isSelfClosingTag(name)){return this._getParentElem(parent,ruleCtx)}if(name===BODY){return null}}return parent}return null}_emitIssue(msgType,ruleCtx,tagName,parentName){var issue;if(msgType===1){let msg=`The slot attribute must not be applied directly on a <${tagName}> : `;msg+=tagName===OJ_BIND_IF?`either relace with <oj-if> which can be assigned to a slot, or wrap in a <div> or <span> and apply the slot attribute to that.`:`wrap it in a <div> or <span> and apply the slot attribute to that.`;issue=new ruleCtx.Issue(msg)}else if(msgType===2){issue=new ruleCtx.Issue(`If <${tagName}> is used as the direct DOM child of <${parentName}>, then <${parentName}> may not reflect updates to the bound value unless the <${tagName}> is enclosed in a DOM element such as <div> or <span>.`);issue.setMsgKey(RULENAME+"_1");issue.setSeverity("info")}ruleCtx.reporter.addIssue(issue,ruleCtx)}}module.exports=Rule;