/*
 * 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-style-bp-font-family";const DESCRIPT="For best practices, the CSS 'font-family' property should not be used. Use of JET typography classes is recommended.";const SHORT_DESCRIPT=DESCRIPT;const FONT_FAMILY="font-family";const FONT_FAMILY_MEMBER="fontFamily";class Rule{constructor(){this._checkList=null;this._isAccept=false}getName(){return RULENAME}getDescription(){return DESCRIPT}getShortDescription(){return SHORT_DESCRIPT}register(regCtx){if(!this._checkRuleOverrides(regCtx)){return false}return{"style":this._onStyle,"stylemember":this._onStyle}}_onStyle(ruleCtx,attr,value){var prop,i;if(ruleCtx.type==="stylemember"){i=attr.charAt(0)===":"?7:6;prop=attr.substring(i);this._checkProp(ruleCtx,prop,value,true)}else{let val,s,x;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).trim();this._checkProp(ruleCtx,prop,val,false)}}}}_checkProp(ruleCtx,prop,value,submember){if(submember&&prop===FONT_FAMILY_MEMBER||!submember&&prop===FONT_FAMILY){if(this._okProp(value)){this._emitIssue(ruleCtx,prop,value)}}}_emitIssue(ruleCtx,prop,value){var issue=new ruleCtx.Issue(`style '${prop}: ${value}' - best practices: JET Typography classes preferred`);ruleCtx.reporter.addIssue(issue,ruleCtx)}_okProp(prop){var i;if(this._checkList){for(i=0;i<this._checkList.length;i++){if(prop.match(this._checkList[i])){return this._isAccept}}return!this._isAccept}return true}_checkRuleOverrides(regCtx){var customOpts,accept,ignore;if(!(customOpts=regCtx.ruleOpts.customOpts)){return true}accept=customOpts.accept;ignore=customOpts.ignore;if(accept||ignore){if(accept&&ignore){regCtx.utils.msgLib.error(`Rule ${RULENAME} :  options 'accept' and 'ignore' are mutually exclusive`);return false}if(accept){this._checkList=accept;this._isAccept=true}else{this._checkList=ignore}if(!Array.isArray(this._checkList)){regCtx.utils.msgLib.error(`Rule ${RULENAME} :  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]=new RegExp(this._checkList[i].trim())}}}return true}}module.exports=Rule;