/*
 * 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-tsx-prop-anti-pattern";const DESCRIPTION="Some components, or component features, may be present but are not applicable for "+"use in all design systems and as such may be flagged as anti-patterns in the content "+"of a particular theme. In these cases, the feature should not be used if targeting the "+"design system in question.";const SHORT_DESCRIPTION="A component property is an anti pattern for code written for the designated theme.";const ANTIPATTERN="antiPattern";class Rule{getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(regCtx){this._metaLib=regCtx.utils.metaLib;this._tsxUtils=regCtx.utils.tsxUtils;this._theme=regCtx.config.theme;return{"TsxRenderComponent":this._onTsxRC}}_onTsxRC(ruleCtx,tsxRC){tsxRC.components.forEach(tsxComp=>{this._checkComp(ruleCtx,tsxComp)})}_checkComp(ruleCtx,tsxComp){var tagName=tsxComp.name;if(tagName.includes("-")&&ruleCtx.utils.metaLib.isWCTag(tagName)){let props,tsxProp,aStat,i;if(props=tsxComp.properties){for(i=0;i<props.length;i++){tsxProp=props[i];if(tsxProp.node.type==="JSXSpreadAttribute"){continue}if(aStat=this._metaLib.getPropStatus(tagName,tsxProp.name,ANTIPATTERN)){let stat,themes,i;for(i=0;i<aStat.length;i++){stat=aStat[i];if(!(themes=stat.themes)){continue}if(!stat.hasOwnProperty("target")){if(themes.includes(this._theme)){this._emitIssue(1,ruleCtx,tagName,tsxProp,stat)}}else if(stat.target==="propertyValue"){let propValue;if(propValue=this._tsxUtils.getPropertyStringValue(tsxProp)){if(!_isExpr(propValue)&&!propValue.startsWith("{")){if(stat.value&&stat.value.includes(propValue)){this._emitIssue(2,ruleCtx,tagName,tsxProp,stat,propValue)}}}}}}}}}if(tsxComp.children)tsxComp.children.forEach(child=>{this._checkComp(ruleCtx,child)})}_emitIssue(issueType,ruleCtx,tagName,tsxProp,stat,propValue){var issue,since,descript,themes,multi;since=stat.since?` (since ${stat.since})`:"";descript=stat.description;descript=descript?` ${descript}`:"";descript=descript&&!descript.endsWith(".")?descript+".":descript;themes="'"+stat.themes.join("', '")+"'";if(multi=stat.themes.length>1){let x;if((x=themes.lastIndexOf(","))>=0){themes=themes.substring(0,x)+" and"+themes.substring(x+1)}}themes=`${multi?"s":""} ${themes}`;if(issueType===1){issue=new ruleCtx.Issue(`<${tagName}> property '${tsxProp.name}' is an antipattern in theme${themes}${since}.${descript} `)}else{issue=new ruleCtx.Issue(`<${tagName}> property '${tsxProp.name}' value '${propValue}' is an antipattern in theme ${themes}${since}.${descript} `);issue.setMsgKey(RULENAME+"_1")}this._tsxUtils.setIssuePosition(issue,tsxProp);ruleCtx.reporter.addIssue(issue,ruleCtx)}}function _isExpr(s){return /[(}{}+*\/]/.test(s)};module.exports=Rule;