/*
 * 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 RULE_NAME="oj-html-style-bp-font";const DESCRIPT="For best practices, CSS 'font-size' and 'font-weight' should not be used. Use of JET typography classes is recommended.";const SHORT_DESCRIPT=DESCRIPT;const FONT_PROPS=["font-size","font-weight"];const FONT_PROPS_MEMBERS=["fontSize","fontWeight"];function Rule(){this._checkList=null;this._isAccept=false};Rule.prototype.getName=function(){return RULE_NAME};Rule.prototype.getShortDescription=function(){return SHORT_DESCRIPT};Rule.prototype.getDescription=function(){return DESCRIPT};Rule.prototype.register=function(regCtx){if(!this._checkAcceptReject(regCtx)){return false}return{"style":this._onStyle,"stylemember":this._onStyle}};Rule.prototype._onStyle=function(ruleCtx,attr,value,raw){var prop,s,x,i;if(ruleCtx.type==="stylemember"){i=attr.charAt(0)===":"?7:6;prop=attr.substring(i);this._checkPropAndValue(ruleCtx,prop,value,true)}else{let val;for(i=0;i<value.length;i++){s=value[i];x=s.indexOf(":");if(x>=0){prop=s.substring(0,x).trimEnd();val=s.substring(x+1).trimStart();this._checkPropAndValue(ruleCtx,prop,val,false)}}}};Rule.prototype._checkPropAndValue=function(ruleCtx,prop,value,stylemember){if(stylemember&&FONT_PROPS_MEMBERS.includes(prop)||!stylemember&&FONT_PROPS.includes(prop)){if(this._okProp(prop)){this._emitIssue(ruleCtx,prop,stylemember)}}};Rule.prototype._emitIssue=function(ruleCtx,prop,submember){var issue;issue=new ruleCtx.Issue(`style '${prop}' - best practices: use the JET Typography classes`);ruleCtx.reporter.addIssue(issue,ruleCtx)};Rule.prototype._okProp=function(prop){var i;if(this._checkList){for(i=0;i<this._checkList.length;i++){if(this._checkList[i]===prop){return this._isAccept}}return!this._isAccept}return true};Rule.prototype._checkAcceptReject=function(regCtx){var customOpts,accept,reject;if(!(customOpts=regCtx.ruleOpts.customOpts)){return true}accept=customOpts.accept;reject=customOpts.reject;if(accept||reject){if(accept&&reject){regCtx.utils.msgLib.error("Rule "+RULE_NAME+":  options 'accept' and 'reject' are mutually exclusive");return false}if(accept){this._checkList=accept;this._isAccept=true}else{this._checkList=reject}if(!Array.isArray(this._checkList)){regCtx.utils.msgLib.error("Rule "+RULE_NAME+":  option '"+(accept?"accept":"reject")+"' is not an array");return false}for(let i=0;i<this._checkList.length;i++){if(typeof this._checkList[i]==="string"){this._checkList[i]=this._checkList[i].trim()}}}return true};module.exports=Rule;