/*
 * 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 RULE="oj-html-wctag-maintenance";const DESCRIPTION="A notification that the component is in 'maintenance' status. This indicates "+"that the component is fully supported, but will be deprecated in a future release "+"and has no new features planned for it.";const SHORT_DESCRIPTION="The component is in 'maintenance' status and will be deprecated in a future release.";const MSG="<%c> is in 'maintenance' status%s.%d";const MAINTENANCE="maintenance";class Rule{getName(){return RULE}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(regCtx){if(!this._getOverrides(regCtx)){return false}this._metaLib=regCtx.utils.metaLib;return{ojtag:this._onTag}}_onTag(ruleCtx,tag){var stats,status,repl,msgObj;if(this._isIgnoreFile(ruleCtx.filepath)){return}if((stats=this._metaLib.getTagStatus(tag,MAINTENANCE))&&stats.length){let msg=MSG.replace("%c",tag);status=stats[0];if(status.since){msg=msg.replace("%s",` (since ${status.since})`)}if(status.description){msg=msg.replace("%d",` ${status.description}`);if(!msg.endsWith(".")){msg+="."}}else{msg=msg.replace("%d","")}if(status.value?.length){repl="<"+status.value.join(">, <")+">";msg+=` Superseded by ${repl}.`}let issue=new ruleCtx.Issue(msg);msgObj={tag:tag};if(repl){msgObj.supersededBy=status.value}issue.setMsgEx(msgObj);ruleCtx.reporter.addIssue(issue,ruleCtx)}}_isIgnoreFile(file){if(this._ignoreFiles){for(let i=0;i<this._ignoreFiles.length;i++){if(this._ignoreFiles[i].test(file)){return true}}}return false}_getOverrides(regCtx){var files,custOpts,files;if(!(custOpts=regCtx.ruleOpts.customOpts)){return true}if(!(files=custOpts.files)){return true}if(!Array.isArray(files)){regCtx.utils.msgLib.error(`Rule ${RULE} :  config option 'files' is not an array`);return false}let ignoreFiles=[];for(let i=0;i<files.length;i++){if(typeof files[i]==="string"){try{ignoreFiles[i]=new RegExp(files[i].trim())}catch(e){regCtx.utils.msgLib.error(`Config 'ruleMods' ${RULE} 'files' entry [${i}]: ${e.message}`);return false}}}if(ignoreFiles.length){this._ignoreFiles=ignoreFiles}return true}}module.exports=Rule;