/*
 * 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-redwood-bp-endslot";const DESCRIPTION="<oj-button> supports the 'startIcon' and 'endIcon' slots. \uFFFDHowever, in Redwood, it is best practice to use "+"only one icon, and the 'startIcon' slot should be used for this unless the icon is intended to communicate a "+"directional action to the right, in which case 'endIcon' can be used together with a suitable Redwood icon.";const SHORT="Use the startIcon (not the endIcon) slot in <oj-button> unless the icon communicates a direction action to the right";const TAG="tag";const SLOT="slot";const COLON_SLOT=":slot";const END_ICON="endIcon";const DIV="div";const SPAN="span";const COLON_CLASS=":class";const SPACE=" ";const ALLOWLIST=["oj-ux-ico-arrow-alt-right","oj-ux-ico-arrow-right-alt","oj-ux-ico-caret-right","oj-ux-ico-chevron-circle-right","oj-ux-ico-chevron-right","oj-ux-ico-nav-right","oj-ux-ico-triangle-right-s","oj-ux-ico-arrow-circle-right","oj-ux-ico-arrow-right","oj-ux-ico-chevron-double-right","oj-ux-ico-triangle-right","oj-ux-ico-arrow-alt-left","oj-ux-ico-arrow-left-alt","oj-ux-ico-caret-left","oj-ux-ico-chevron-circle-left","oj-ux-ico-chevron-left","oj-ux-ico-nav-left","oj-ux-ico-triangle-left-s","oj-ux-ico-arrow-circle-left","oj-ux-ico-arrow-left","oj-ux-ico-chevron-double-left","oj-ux-ico-triangle-left"];class Rule{getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT}register(){return{"<oj-button>":this._onBtn,"<oj-c-button>":this._onBtn}}_onBtn(ruleCtx){if(this._slots){this._slots.length=0}this._getSlots(ruleCtx.tagNode);if(this._slots){this._checkIconUsage(ruleCtx)}}_emit(ruleCtx,tagNode){var issue,pos,attr;issue=new ruleCtx.Issue("Redwood best practices - use slot 'startIcon' only");attr=tagNode.attribs.hasOwnProperty(SLOT)?SLOT:COLON_SLOT;if(pos=ruleCtx.utils.DomUtils.getAttribValuePosition(ruleCtx.data,tagNode,attr)){issue.setPosition(pos)}ruleCtx.reporter.addIssue(issue,ruleCtx)}_getSlots(tagNode){var childs,ch,attrs,attr,i;attrs=tagNode.attribs;if(attr=attrs.slot||attrs[COLON_SLOT]){if(attr===END_ICON){if(!this._slots){this._slots=[]}this._slots.push(tagNode)}}childs=tagNode.children;for(i=0;i<childs.length;i++){ch=childs[i];if(ch.type===TAG){this._getSlots(ch)}}}_checkIconUsage(ruleCtx){var i,node,clazz;for(i=0;i<this._slots.length;i++){node=this._slots[i];if(node.name===DIV||node.name===SPAN){if(_isEmpty(node)){if(clazz=node.attribs.class||node.attribs[COLON_CLASS]){clazz=clazz.trim();if(_isExpr(clazz)||_isClassAllowListed(clazz)){continue}}}}this._emit(ruleCtx,node)}}}function _isClassAllowListed(clazz){var a,cl,i;if(clazz.indexOf(SPACE)){clazz=clazz.replace(/ +(?= )/g,"").trim();a=clazz.split(SPACE);for(i=0;i<a.length;i++){if(ALLOWLIST.includes(a[i])){cl=a[i];break}}}else if(ALLOWLIST.includes(clazz)){cl=clazz}return!!cl};function _isEmpty(node){var childs,ch,i,ret=false;if((childs=node.children)&&childs.length){for(i=0;i<childs.length;i++){ch=childs[i];if(ch.type==="text"){if(!ret){ret=ch.data&&ch.data.trim().length===0;continue}}if(ch.type==="tag"){ret=false;break}}}else{ret=true}return ret};function _isExpr(s){s=s.trimLeft();return s.startsWith("{{")||s.startsWith("[[")};module.exports=Rule;