/*
 * 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-tsx-ojattr-value";const SHORT="Custom component attribute value must be a defined value";const LONG="Custom component attribute value must be a defined value for the component";const JSX_SPREAD_ATTRIBUTE="JSXSpreadAttribute";const DATABIND="data-bind";function Rule(){};Rule.prototype.getName=function(){return RULE_NAME};Rule.prototype.getShortDescription=function(){return SHORT};Rule.prototype.getDescription=function(){return LONG};Rule.prototype.register=function(regCtx){this._tsxUtils=regCtx.utils.tsxUtils;this._metaLib=regCtx.utils.metaLib;return{"TsxRenderComponent":this._onTsxRC}};Rule.prototype._onTsxRC=function(ruleCtx,tsxRC){this._tsxUtils.extractTsxProperties(ruleCtx,tsxRC,this._onProp.bind(this))};Rule.prototype._onProp=function(ruleCtx,tsxProp){var val;if(tsxProp===null||tsxProp.node.type===JSX_SPREAD_ATTRIBUTE){return}if(!(val=tsxProp.node.value)){return}if(val.type==="Literal"){val=val.value}else{val=tsxProp.valueRaw;val=val.startsWith("\"")?val.substring(1,val.length-1):val}if(val.startsWith("{{")||val.startsWith("[[")){return}this._checkAttr(ruleCtx,tsxProp.parent.name,tsxProp,val)};Rule.prototype._checkAttr=function(ruleCtx,tagName,tsxProp,val){var attrName,aVals,aVal,jsonChar,i;attrName=tsxProp.name;if(this._tsxUtils.isCommonAttr(attrName)||this._tsxUtils.isCommonEventAttr(attrName)||attrName===DATABIND||!this._metaLib.isTagAttr(tagName,attrName)){return}try{jsonChar=val.charAt(0);if(jsonChar==="{"){return}else if(val.charAt(0)==="["){aVals=JSON.parse(val)}else{aVals=[val]}}catch(e){}if(!aVals){return true}if(!this._metaLib.hasTagAttrValues(tagName,attrName)){return}for(i=0;i<aVals.length;i++){aVal=aVals[i];if(!this._metaLib.isTagAttrValue(tagName,attrName,aVal)){if(!this._checkSpecialCases(tagName,attrName,aVal)){let issue=new ruleCtx.Issue(`<${tagName}> attribute '${attrName}' refers to undefined value '${aVal}'`);this._tsxUtils.setIssuePosition(issue,tsxProp);ruleCtx.reporter.addIssue(issue,ruleCtx)}}}};Rule.prototype._checkSpecialCases=function(tagName,attrName,attrValue){if(tagName==="oj-led-gauge"&&attrName==="type"){return this._tsxUtils.isSvgPath(attrValue)}return false};module.exports=Rule;