/*
 * 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 RULENAME="oj-html-oj-ux-ico-slot";const DESCRIPTION="Menus and other action components that can be configured with an icon starting with "+"'oj-ux-ico-', should always have the icon applied via a span tag in the assigned "+"slot. Applying the icon class anywhere else will result in the component not "+"functioning as expected.";const SHORT_DESCRIPTION="Declare icon styles for <oj-button> and <oj-option> in a 'startIcon' or 'endIcon' slot.";const OJ_UX_ICO="oj-ux-ico-";class Rule{getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(){return{"<oj-button>":this._onTag,"<oj-option>":this._onTag}}_onTag(ruleCtx){var rawClazz;this._node=null;if(rawClazz=this._hasIconClasses(ruleCtx.tagNode.children)){let a;if(a=this._extractOjUxIco(rawClazz)){for(let i=0;i<a.length;i++){this._emitIssue(ruleCtx,a[i])}}}}_emitIssue(ruleCtx,clazz){let issue=new ruleCtx.Issue(`<${this._node.name}> class '${clazz}' should be used in a 'startIcon' or 'endIcon' slot.`);issue.setPosition(null,null,this._node.startIndex);ruleCtx.reporter.addIssue(issue,ruleCtx)}_hasIconClasses(childs){if(!childs){return}let child;if(child=this._findChildTag(childs)){let clazz,clazzVal,attribs;if(attribs=child.attribs){if((clazz=attribs["slot"])&&(clazz==="startIcon"||clazz==="endIcon")){return}if(clazzVal=this._hasClass(child)){return clazzVal}else if(child.children){return this._hasIconClasses(child.children)}}}}_findChildTag(childs){if(!childs){return}let child,i;for(i=0;i<childs.length;i++){child=childs[i];if(child.type==="tag"){if(child.name==="span"||child.name==="div"){return child}else if(child.name.startsWith("oj-bind-")||child.name.startsWith("template")){return this._findChildTag(child.children)}}}}_hasClass(node){var attribs,ret;if(attribs=node.attribs){let clazz;if(clazz=attribs[":class"]||attribs["class"]){ret=clazz;this._node=node}}return ret}_extractOjUxIco(rawClazz){var x,i,a;for(i=0;i<rawClazz.length;){if((x=rawClazz.indexOf(OJ_UX_ICO,i))>=0){if(!a){a=[]}a.push(x);i=x+OJ_UX_ICO.length}else{break}}if(a){let b;for(i=0;i<a.length;i++){let s=rawClazz.substring(a[i]);let ret="";let c;b=false;for(let j=OJ_UX_ICO.length;j<s.length;j++){c=s.charAt(j);if(c.toLowerCase()!==c.toUpperCase()||c==="-"||/\d/.test(c)){b=true;ret+=c}else{break}}if(b){a[i]=OJ_UX_ICO+ret}}}return a}}module.exports=Rule;