/*
 * 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 getParentNodeForSlot=require("./helpers/has-slot-name");const RULENAME="oj-html-button-size-chroming";const DESCRIPTION="The Redwood input designs require the use of small buttons. Please update the "+"button attributes in the 'start' or 'end' slot:<br>"+"&nbsp;1) For <oj-button>, use class=\"oj-button-sm\"<br>"+"&nbsp;2) For <oj-c-button>, set size=\"sm\" and chroming=\"ghost\"";const SHORT_DESCRIPTION="Redwood input design spec -small buttons required.";const OJ_INPUT_TEXT="oj-input-text";const OJ_C_INPUT_TEXT="oj-c-input-text";const OJ_BUTTON="oj-button";const OJ_C_BUTTON="oj-c-button";const CLASS="class";const START="start";const END="end";class Rule{getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(){return{"<oj-button slot=>":this._onBtn,"<oj-c-button slot=>":this._onBtn}}_onBtn(ruleCtx,attrName,slotName){if(slotName!==START&&slotName!==END){return}let tagName,parentName,node;if(!(node=getParentNodeForSlot(ruleCtx,slotName))){return}tagName=ruleCtx.tag;parentName=node.name;if(tagName!==OJ_BUTTON&&tagName!==OJ_C_BUTTON||parentName!==OJ_INPUT_TEXT&&parentName!==OJ_C_INPUT_TEXT){return}if(tagName===OJ_BUTTON){if(!this._hasAttr(ruleCtx,"class","oj-button-sm")){this._emitIssue(ruleCtx,true)}}else{if(!this._hasAttr(ruleCtx,"chroming","ghost")||!this._hasAttr(ruleCtx,"size","sm")){this._emitIssue(ruleCtx,false)}}}_emitIssue(ruleCtx,legacy){var msg=legacy?"<oj-button> in the 'start' or 'end' slot should use class=\"oj-button-sm\"":"<oj-c-button> in the 'start' or 'end' slot should use chroming=\"ghost\" and size=\"sm\"";var issue=new ruleCtx.Issue("Redwood input specs: "+msg);if(!legacy){issue.setMsgKey(RULENAME+"_1")}ruleCtx.reporter.addIssue(issue,ruleCtx)}_hasAttr(ruleCtx,attr,value){var attribs,attrib,ret=false;if(attribs=ruleCtx.tagNode.attribs){if(attrib=attribs[attr]){if(attr===CLASS){let clsName,i;let a=attrib.split(" ");for(i=0;i<a.length;i++){if(clsName=a[i]){if(clsName===value){ret=true;break}}}}else if(attrib===value){ret=true}}}return ret}}module.exports=Rule;