/*
 * 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-css-style-bp-font-family";const DESCRIPT="For best practices, CSS properties 'font-family' should not be used. Use of JET typography classes is recommended.";const SHORT_DESCRIPT=DESCRIPT;const DECLARATION="Declaration";const FONT_FAMILY="font-family";const IDENTIFIER="Identifier";const VALUE="Value";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{"css-rule":this._onRule,"css-atrule":this._onAtRule}}_onRule(ruleCtx,rule){var block,decl,i;if(!(rule.prelude&&rule.prelude.children&&rule.prelude.children.length)){return}block=rule.block.children;for(i=0;i<block.length;i++){decl=block[i];if(decl.type===DECLARATION){if(decl.property===FONT_FAMILY){if(!_isCssVar(decl)){if(this._okProp(decl)){this._emitIssue(ruleCtx,decl)}}}}}}_onAtRule(ruleCtx,atrule){var block,decl,i;if(!(atrule.block&&atrule.block.children&&atrule.block.children.length)){return}block=atrule.block.children;for(i=0;i<block.length;i++){decl=block[i];if(decl.type===DECLARATION){if(decl.property===FONT_FAMILY){if(!_isCssVar(decl)){if(this._okProp(decl)){this._emitIssue(ruleCtx,decl)}}}}}}_emitIssue(ruleCtx,o){var issue;issue=new ruleCtx.Issue(`"CSS property '${o.property}: ${this._family}' - best practices: JET typography classes preferred`);issue.setPosition(ruleCtx.utils.CssUtils.getPosition(ruleCtx,o.loc));ruleCtx.reporter.addIssue(issue,ruleCtx)}_okProp(decl){var i;var i,ff;this._family=ff=_getFamily(decl);if(ff.charAt(0)==="\""){ff=ff.substring(1,ff.length-1)}if(ff&&this._checkList){for(i=0;i<this._checkList.length;i++){if(ff.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":"ignore"}' 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}}function _getFamily(decl){var family,ch,i;if(decl.value&&decl.value.type===VALUE){ch=decl.value.children;if(ch&&ch.length){for(i=0;i<ch.length;i++){family=ch[i];if(family.type===IDENTIFIER){family=family.name;break}else if(family.type==="String"){family=family.value;break}}}}return family};function _isCssVar(decl){var c,v;c=decl.value.children;v=c[0];return v.name==="var"};module.exports=Rule;