/*
 * 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 isValidAttr=require("./helpers/valid-attr");const RULE_NAME="oj-tsx-ojattr";const SHORT_DESCR="JET component property must be defined";const LONG_DESCR="JET component properties must be defined properties for the component. "+"Additionally, kebab-case attributes are discouraged, and use of assignments "+"\"[[  . . .]]\" or \"{{ . . .}\" (which are coerced to a string value) should be "+"replaced with their vdom property names for performance and to avoid coercion.";const OJ_EVENT_PREFIX="onOj";const EVENT_PREFIX="on";const SLOT="slot";const ARIA_DASH="aria-";const DATA_DASH="data-";const KEY="key";const REF="ref";function Rule(){}Rule.prototype.getName=function(){return RULE_NAME};Rule.prototype.getShortDescription=function(){return SHORT_DESCR};Rule.prototype.getDescription=function(){return LONG_DESCR};Rule.prototype.register=function(regCtx){this._metaLib=regCtx.utils.metaLib;this._tsxUtils=regCtx.utils.tsxUtils;return{TsxWebComponent:this._onWebComp}};Rule.prototype._onWebComp=function(ruleCtx,tsxComp){var props;if(props=tsxComp.properties){props.forEach(prop=>{this._checkProp(ruleCtx,tsxComp,prop)})}};Rule.prototype._checkProp=function(ruleCtx,tsxComp,tsxProp){let propName=tsxProp.name;let tagName=tsxComp.name;let origPropName,camelName;if(!propName||tsxProp.node.type==="JSXSpreadAttribute"){return}if(!isValidAttr(propName)){let issue=new ruleCtx.Issue(`<${tagName}> - invalid '${propName}' property`);this._tsxUtils.setIssuePosition(issue,tsxProp);issue.setMsgKey(RULE_NAME+"_1");ruleCtx.reporter.addIssue(issue,ruleCtx);return}if(_isPropAriaOrData(propName)){return}if(propName.includes("-")){camelName=this._tsxUtils.toCamelCase(propName);let issue=new ruleCtx.Issue(`For optimum performance, it is recommended that the <${tagName}> property '${camelName}' is set using that property name in vdom, rather than using the attribute form of the name '${propName}'`);this._tsxUtils.setIssuePosition(issue,tsxProp);issue.setSeverity("critical");issue.setMsgKey(RULE_NAME+"_2");ruleCtx.reporter.addIssue(issue,ruleCtx)}if(this._tsxUtils.isCommonAttr(propName)||this._tsxUtils.isCommonEventAttr(propName)||propName===SLOT||propName===KEY||propName===REF||propName.startsWith(OJ_EVENT_PREFIX)||propName.startsWith(EVENT_PREFIX)){return}origPropName=propName;propName=camelName?camelName:propName;if(!this._metaLib.isTagAttr(tagName,propName)){if(!this._metaLib.isTagEvent(tagName,propName)){let issue=new ruleCtx.Issue(`<${tagName}> property '${origPropName}' is unknown`);this._tsxUtils.setIssuePosition(issue,tsxProp);ruleCtx.reporter.addIssue(issue,ruleCtx)}}};function _isPropAriaOrData(s){return s.startsWith(ARIA_DASH)||s.startsWith(DATA_DASH)}module.exports=Rule;