/*
 * 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-html-alta-deprecated";const DESCRIPTION="Starting in JET 10.0, the Alta theme is deprecated, and the use of this theme, or of "+"a custom theme such as the <i>ApplicationsCloudUI</i> theme which extends it, should be "+"replaced with either the Redwood theme, or a custom theme that extends the Redwood "+"or Stable theme.<p>All Alta CSS and SCSS files will be removed in JET "+"21.0 (August 2026). Please discontinue use of Alta ASAP.<p>(Product Management warned "+"on February 13 2025 that this deadline will NOT be extended beyond August 2026!)";const SHORT_DESCRIPTION="Detect the use of the deprecated Alta theme";const VB_INJECT="vb:inject";const RE_ALTA_MIN=/.*\/alta\/(oj-alta-min.css|oj-alta.css)/;const RE_APP_CLOUD=/.*\/web\/ApplicationsCloudUI.css/;const RE_THEME_APPSUI=/\s*[a-zA-Z0-9\.\/]*ApplicationsCloudUI.css\s*.*/;const RE_THEME_ALTA=/\s*\/?[Aa]lta\/?\s*.*/;const RE_THEME_ALTA_MIN=/\s*\/?alta\/(oj-alta-min.css|oj-alta.css\s*.*)/;const STYLESHEET="stylesheet";const VER_12_0_0="12.0.0";const HREF="href";class Rule{_idAttribOnly;_idHeadContent;_theme;_jetVerGte12;getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(regCtx){let jetVer=regCtx.utils.metaLib.getMetaVers().runver;let semver=regCtx.utils.semVerUtils;this._jetVerGte12=semver.gte(jetVer,VER_12_0_0);return{link:this._onLink,comment:this._onComment}}_onLink(ruleCtx){var href;if(!_isStyleSheetLink(ruleCtx)||!(href=ruleCtx.tagNode.attribs.href)){return}if(RE_ALTA_MIN.test(href)||RE_APP_CLOUD.test(href)){this._emitIssue(ruleCtx,1)}}_onComment(ruleCtx,comment){var emit;if(!(_inHeadSection(ruleCtx.elemStack)&&comment.startsWith(VB_INJECT))){return}this._processComment(comment);if(!this._idHeadContent){return}if(!(emit=this._idAttribOnly)){if(!(emit=RE_THEME_APPSUI.test(this._theme))){emit=RE_THEME_ALTA_MIN.test(this._theme)||RE_THEME_ALTA.test(this._theme)}}if(emit){this._emitIssue(ruleCtx,2,comment)}}_emitIssue(ruleCtx,type,comment){var issue,msg,node;msg=type===1?"Stylesheet <link> refers to deprecated Alta theme or a theme that extends it. ":"vb:inject theme : Alta theme is deprecated. ";msg+="All Alta CSS and SCSS will be removed in JET 21.0 (August 2026). Migrate to the Redwood or Stable based theme ASAP.";issue=new ruleCtx.Issue(msg);if(type===1){issue.setPosition(ruleCtx.utils.DomUtils.getAttribValuePosition(ruleCtx.data,ruleCtx.node,HREF))}else{node=ruleCtx.node;let x=comment.indexOf("theme=");if(x>=0){x+=node.startIndex;issue.setPosition(null,null,node.startIndex+5,node.endIndex)}else{issue.setPosition(null,null,node.startIndex,node.endIndex)}}ruleCtx.reporter.addIssue(issue,ruleCtx)}_processComment(comment){var a,x,attrib;this._idAttribOnly=this._idHeadContent=false;this._theme="";a=comment.replace("vb:inject","").replace(/['"]/g,"").trim().split("=");for(let i=0;i<a.length-1;i++){attrib=(x=a[i].indexOf(" "))>=0?attrib=a[i].substring(x+1):attrib=a[i];if(attrib==="id"){this._idAttribOnly=true;this._idHeadContent=a[i+1].split(" ")[0]==="headContent"}else{this._idAttribOnly=false;if(attrib==="theme"){this._theme=a[i+1].split(" ")[0]}break}}}}function _hasIdAttribOnly(comment){var a,x,attrib;var hasIdOnly;a=comment.replace("vb:inject","").replace(/['"]/g,"").trim().split("=");for(let i=0;i<a.length-1;i++){attrib=(x=a[i].indexOf(" "))>=0?attrib=a[i].substring(x+1):attrib=a[i];if(attrib==="id"){hasIdOnly=true}else{hasIdOnly=false;break}}return hasIdOnly};function _isStyleSheetLink(ruleCtx){var attribs,ret;if(attribs=ruleCtx.tagNode.attribs){ret=attribs.rel===STYLESHEET}return ret?ret:false};function _inHeadSection(stack){var node,ret=false;if(stack&&stack.length){for(let i=stack.length-1;i>=0;i--){node=stack[i];if(node.type==="tag"){if(node.name==="head"){ret=true;break}if(node.name==="body"){break}}}}return ret};module.exports=Rule;