/*
 * 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-css-style-deprecated";const SHORT="Deprecated JET CSS style class selectors should not be used";const LONG="Deprecated JET CSS style class selectors should not be used";const OJ="oj-";const EXCEPTION_LIST=["oj-tabbar-stack-icon-label"];function Rule(){this._checkList=null;this._isAccept=false};Rule.prototype.getName=function(){return RULE_NAME};Rule.prototype.getShortDescription=function(){return SHORT};Rule.prototype.getDescription=function(){return LONG};Rule.prototype.register=function(regCtx){if(!this._checkAcceptReject(regCtx)){return false}return{"css-rule":this._onRule}};Rule.prototype._onRule=function(ruleCtx,rule){var sels,sel,dep,descr,issue,i;sels=_getOjClassSelectors(rule);if(!sels.length){return}for(i=0;i<sels.length;i+=2){sel=sels[i];if(this._OkSel(sel)){dep=ruleCtx.utils.metaLib.isStyleDeprecated(sel);if(dep){descr=dep.description?dep.description.trim():null;if(descr&&!descr.endsWith(".")){descr+="."}issue=new ruleCtx.Issue("JET CSS class selector '"+sel+"' is deprecated"+(dep.since?" (since "+dep.since+")":"")+"."+(descr?" "+descr:""));issue.setPosition(ruleCtx.utils.CssUtils.getPosition(ruleCtx,sels[i+1]));ruleCtx.reporter.addIssue(issue,ruleCtx)}}}};function _getOjClassSelectors(rule){var sels,sel,a,c,i,j,ret=[];if(!(rule.prelude&&rule.prelude.children)||rule.prelude.type!=="SelectorList"){return ret}a=rule.prelude.children;for(i=0;i<a.length;i++){sels=a[i];if(sels.type==="Selector"){c=sels.children;for(j=0;j<c.length;j++){sel=c[j];if(sel.type==="ClassSelector"&&sel.name.startsWith(OJ)){ret.push(sel.name);ret.push(sel.loc)}}}}return ret};Rule.prototype._OkSel=function(sel){if(EXCEPTION_LIST.includes(sel)){return false}if(this._checkList){for(let i=0;i<this._checkList.length;i++){if(this._checkList[i].test(sel)){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]=new RegExp(this._checkList[i].trim())}}}return true};module.exports=Rule;